有没有办法使用github API v3获取给定仓库的最新标签 [英] Is there a way to get the latest tag of a given repo using github API v3

查看:166
本文介绍了有没有办法使用github API v3获取给定仓库的最新标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对github api比较陌生,而且我正在努力获得给定回购的最新标签。



问:为什么我需要这个?

答: 作为QA,我负责测试并发布到LIVE,我们的团队拥有大约40个文物(github中的回购)。我想建立一个工具,列出在最新标签之后提交的项目。这样我就可以更有效地管理版本。



即将到来。

根据Github api获取所有给定回购标签

  GET / repos /:owner /:repo / tags 

但是,这给出了完整的标签列表回购有。



有没有一种简单的方法可以找到最新的标签,而无需重复上述api调用中的所有可用标签?

如果我遍历每个标签以便找到最新的标签(基于每个标签的时间戳),随着时间的推移,这显然不是实现此目的的有效方式,标签数量将增加,并且由于我想要重复同样的过程至少10回购。



任何帮助将不胜感激。



很多预先感谢

解决方案

GitHub没有API来检索最新的标签,因为它具有检索最新版本。这可能是因为标签可能是任意字符串,不一定是semvers,但它不是一个真正的借口,因为标签有时间戳,并且GitHub在通过它的 Tags API

无论如何,要获得最新的代码,您需要调用API,然后根据 semver 规则对标签进行排序。由于这些规则是非平凡的(参见该链接的第11点),最好使用 semver库移植到浏览器)。

< pre class =snippet-code-js lang-js prettyprint-override> var gitHubPath ='iDoRecall / selection-menu'; //示例repovar url ='https://api.github.com/repos/'+ gitHubPath +'/tags';$.get(url).done(function(data){var versions = data.sort(function (v1,v2){return semver.compare(v2.name,v1.name)}); $('#result')。html(versions [0] .name);});

< script src =https://ajax.googleapis.com/ajax/libs /jquery/2.1.1/jquery.min.js\"></script><script src =https://rawgit.com/hippich/bower-semver/master/semver.min.js> < / script>< p>最新标记:< span id =result>< / span>< / p>


I am relatively new to the github api and I am struggling to get the latest tag of a given repo.

Q: Why I need that ?

A: As a QA I am responsible for testing and releasing to LIVE and our team owns around 40 artefacts(repos in github). I want to build a tool which lists the projects which have commits after that latest tag. So that I can manage releases more efficiently.

Coming to the point.

According to Github api to get all tags of a give repo is

GET /repos/:owner/:repo/tags

But this gives the full list of tags the repo has.

Is there an easy way to find the latest tag without iterating through the all available tags from the above api call?

If I have iterate through each tag in order to find the latest tag (based on timestamp of each tag)thats clearly going to be not the efficient way of doing this as the time goes the number of tags will increase and since I want to repeat the same process for at least more than 10 repos.

Any help will be highly appreciated.

Many thanks in advance

解决方案

GitHub doesn't have an API to retrieve the latest tag, as it has for retrieving the latest release. That might be because tags could be arbitrary strings, no necessarily semvers, but it's not really an excuse, since tags have timestamps, and GitHub does sort tags lexicographically when returning them via its Tags API.

Anyway, to get the latest tag, you need to call that API, then sort the tags according to semver rules. Since these rules are non-trivial (see point 11 at that link), it's better to use the semver library (ported for the browser).

var gitHubPath = 'iDoRecall/selection-menu';  // example repo
var url = 'https://api.github.com/repos/' + gitHubPath + '/tags';

$.get(url).done(function (data) {
  var versions = data.sort(function (v1, v2) {
    return semver.compare(v2.name, v1.name)
  });
  $('#result').html(versions[0].name);
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://rawgit.com/hippich/bower-semver/master/semver.min.js"></script>
<p>Latest tag: <span id="result"></span></p>

这篇关于有没有办法使用github API v3获取给定仓库的最新标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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