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 API获得的repo版本?_Github_Github Api - Fatal编程技术网

我怎样才能抓住最新的;“稳定”;从Github API获得的repo版本?

我怎样才能抓住最新的;“稳定”;从Github API获得的repo版本?,github,github-api,Github,Github Api,Github返回推送到回购协议的所有标签的列表,最新标签列在顶部。下面是一个示例调用:它生成以下json对象 [{ name: "rbp-folder-rename", zipball_url: "https://api.github.com/repos/ff0000/rosy/zipball/rbp-folder-rename", tarball_url: "https://api.github.com/repos/ff0000/rosy/tarball/rbp-fol

Github返回推送到回购协议的所有标签的列表,最新标签列在顶部。下面是一个示例调用:它生成以下json对象

[{
    name: "rbp-folder-rename",
    zipball_url: "https://api.github.com/repos/ff0000/rosy/zipball/rbp-folder-rename",
    tarball_url: "https://api.github.com/repos/ff0000/rosy/tarball/rbp-folder-rename",
    commit: {
        sha: "09ebda2678d932a005fc86ab78f6c04eebdcd50d",
        url: "https://api.github.com/repos/ff0000/rosy/commits/09ebda2678d932a005fc86ab78f6c04eebdcd50d"
    }
},
{
    name: "2.0.10",
    zipball_url: "https://api.github.com/repos/ff0000/rosy/zipball/2.0.10",
    tarball_url: "https://api.github.com/repos/ff0000/rosy/tarball/2.0.10",
    commit: {
        sha: "fe284c7d461107d9d08d2d4dcb676759f9485fc1",
        url: "https://api.github.com/repos/ff0000/rosy/commits/fe284c7d461107d9d08d2d4dcb676759f9485fc1"
    }
},

// ....

{
    name: "2.1.5",
    zipball_url: "https://api.github.com/repos/ff0000/rosy/zipball/2.1.5",
    tarball_url: "https://api.github.com/repos/ff0000/rosy/tarball/2.1.5",
    commit: {
        sha: "db92baa49657b3c3d27b1475c415c19525cb2118",
        url: "https://api.github.com/repos/ff0000/rosy/commits/db92baa49657b3c3d27b1475c415c19525cb2118"
    }
}]
问题
  • 此列表的顶部似乎有最新的标记,后面是以前标记的历史记录,按相反的时间顺序列出。为什么?第一个结果的顺序与其他结果不同,这似乎很奇怪,也许我看错了
  • 是否有任何方法可以通过编程方式仅检索应用于
    主分支的最新版本?我想通过编程检索最新稳定版本的回购协议

  • 如有任何帮助/见解,我们将不胜感激。

    您只需将标签替换为分支名称即可:

    https://api.github.com/repos/ff0000/rosy/zipball/master
    
    请参阅“”中该查询的更一般形式(针对给定分支)

    但这假设回购协议的最新稳定版本在
    master
    中(可能是最新的“开发”,在编译并通过基本单元测试后可能不太稳定):每个项目都可以有自己的约定

    不管它值多少钱,
    https://api.github.com/repos/ff0000/rosy/branches
    将列出同一回购的分支机构

    此列表的顶部似乎有最新的标记,后面是以前标记的历史记录,按相反的时间顺序列出

    您不应该依赖GitHub API返回标记的顺序,因为没有时间戳,并且repo参与者可能使用了不一致的标记名,例如
    v1.9.0
    2.5.14
    。在该特定示例中,
    v1.9.0
    将首先显示-请参阅

    您应该让维护人员使用一致性标记(),并根据规则对GitHub的输出进行排序。由于这些规则非常重要(请参见该链接的第11点),因此最好使用()

    var gitHubPath='ff0000/rosy';//你的回购例子
    var url='1〕https://api.github.com/repos/“+gitHubPath+”/tags”;
    $.get(url).done(函数(数据){
    var versions=data.sort(函数(v1、v2){
    返回semver.compare(v2.name,v1.name)
    });
    $('#result').html(版本[0].name);
    });
    
    
    
    最新标签:

    获取最新版本号:

    https://api.github.com/repos/user/repo/releases/latest
    
    例如,对于此repo(),您可以使用以下url:

    https://api.github.com/repos/pyidm/pyidm/releases/latest
    
    您将得到一个带有tag_name=最新版本的json文件