Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何以编程方式检测GitHub存储库中的非活动分支?_Git_Github_Git Branch_Github Api - Fatal编程技术网

如何以编程方式检测GitHub存储库中的非活动分支?

如何以编程方式检测GitHub存储库中的非活动分支?,git,github,git-branch,github-api,Git,Github,Git Branch,Github Api,我在GitHub存储库中有十几个存储库。存储库结构如下所示: + project1 +------- trunk +------- tags +------- branches + ------- releases + project2 .... 我们的政策要求在30天不活动后删除任何活动分支。但是,没有自动的方法来检测这样一个不活动的分支。偶尔,我会有一些不活跃的分支在30天之后存活下来 是否有脚本列出所有G

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

   + project1 
       +------- trunk
       +------- tags
       +------- branches
       + ------- releases
   + project2
       ....
我们的政策要求在30天不活动后删除任何活动分支。但是,没有自动的方法来检测这样一个不活动的分支。偶尔,我会有一些不活跃的分支在30天之后存活下来

是否有脚本列出所有GitHub存储库中的分支及其最后提交日期

Edit1——还有什么方法可以通过API获得多少个组织以及他们拥有哪些项目?应该能够帮助您做到这一点

上市分行
  • 语法:
    GET/repos/:owner/:repo/branchs
  • 示例:
获取分支机构的详细信息
  • 语法:
    GET/repos/:owner/:repo/branchs/:branch
  • 示例:
此调用方法公开分支的提示(即最新提交),您可以从中检索提交日期。基于此,您可以评估每个分支的“活动”

下面是分支详细信息的示例输出

{
  "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",

[...]

如果您不介意的话,下面是一段代码片段,列出了裸存储库的非活动分支:

#/垃圾箱/环境蟒蛇3
导入pygit2、os、datetime
repo=pygit2.Repository(pygit2.discover_Repository(os.getcwd()))
time\u now=datetime.datetime.now()
对于中的分支(repo.lookup_branch(b)for b in repo.listall_branchs()):
last\u commit=branch.get\u object()
提交时间=datetime.datetime.fromtimestamp(上次提交时间)
年龄=时间\u现在-提交\u时间
如果年龄>datetime.timedelta(天数=30):
打印(“{}{}}”。格式(last_commit.author.email,branch.branch_name,commit_time))
或删除超过100天的分支的shell脚本版本:

git for-each-ref --sort=committerdate refs/ --format='%(committerdate:raw) %(refname:short)' | awk "\$1 < $(date -d "-100 day" "+%s") {print(\$3)}" | xargs git branch -D

git for each ref--sort=committerdate refs/--format='%(committerdate:raw)%%(refname:short)| awk“\$1<$(date-d“-100天”+%s”){print(\$3)}”| xargs git branch-d

为什么您的git存储库的布局方式像subversion存储库一样?为什么您不将每个项目“主干”作为单独的存储库,然后标记和分支成为一级git公民。您写
我在GitHub存储库中有十几个项目
。你需要澄清这一点。你是说你把所有的项目都放在一个存储库中吗?@Jubobs对不起,它们的布局就像git结构,在一个组织中有多个repo。每个回购协议都有一个主干(master),然后是多个分支和发行版,这些分支和发行版会将代码提交给它们repos@KuberKaul我认为您添加的Edit1看起来是一个完全不同的主题,应该有自己的问题。