如何以编程方式检测GitHub存储库中的非活动分支? [英] How can I programmatically detect inactive branches in GitHub repositories?

查看:129
本文介绍了如何以编程方式检测GitHub存储库中的非活动分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在GitHub存储库中有十几个存储库。存储库结构如下所示:

I have a dozen repositories in the GitHub repository. The repository structure looks like below:

   + project1 
       +------- trunk
       +------- tags
       +------- branches
       + ------- releases
   + project2
       ....

我们的政策要求任何活动分支在闲置30天后被删除。但是,没有自动检测这种非活动分支的方法。偶尔,我有一些不活跃的分支在30天的标记中生存。

Our policy requires any active branch to be deleted after 30 days of inactivity. However, there is no automatic way of detecting such an inactive branch. Occasionally, I have some inactive branch that survive past the 30-day mark.

是否有脚本可以列出分支,以及所有GitHub存储库中的最后一次提交日期?

Is there a script to list branches, as well as their last commit date in all GitHub repositories?

Edit1 - 还有一种方法可以通过API获取多少组织和他们的项目?

推荐答案

GitHub Repository API 应该可以帮助您。

The GitHub Repository API should be able to help you with that.

  • Syntax: GET /repos/:owner/:repo/branches
  • Sample: https://api.github.com/repos/libgit2/libgit2sharp/branches
  • Syntax: GET /repos/:owner/:repo/branches/:branch
  • Sample: https://api.github.com/repos/libgit2/libgit2sharp/branches/coverity

这个调用方法暴露了分支的顶端(即,最新的提交),您可以从中检索提交日期。基于此,您可以评估每个分支的活动。

This call method exposes the tip of the branch (ie. the latest commit), from which you can retrieve the commit date. Based on that, you may be able to evaluate the "activity" of each branch.

在分支详细信息的输出示例之下

Below a sample output of a branch detail

{
  "name": "coverity",
  "commit": {
    "sha": "f341f3a1276cbec3f6ee9d02264bd4453ca20835",
    "commit": {
      "author": {
        "name": "nulltoken",
        "email": "email@gmail.com",
        "date": "2014-05-03T21:28:26Z"
      },
      "committer": {
        "name": "nulltoken",
        "email": "email@gmail.com",
        "date": "2014-05-09T11:10:01Z"
      },
      "message": "Configure Coverity Scan hook for Travis",
      "tree": {
        "sha": "a5092e975145b96356df6b57cbf50e2d8c6140f8",
        "url": "https://api.github.com/repos/libgit2/libgit2sharp/git/trees/a5092e975145b96356df6b57cbf50e2d8c6140f8"
      },
      "url": "https://api.github.com/repos/libgit2/libgit2sharp/git/commits/f341f3a1276cbec3f6ee9d02264bd4453ca20835",
      "comment_count": 0
    },
    "url": "https://api.github.com/repos/libgit2/libgit2sharp/commits/f341f3a1276cbec3f6ee9d02264bd4453ca20835",

[...]

这篇关于如何以编程方式检测GitHub存储库中的非活动分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆