简体   繁体   English

按名称链接到 GitHub 里程碑

[英]Link to a GitHub milestone by its name

I'd like to link to GitHub milestones by their name.我想通过他们的名字链接到 GitHub 里程碑。 We have milestones named by version numbers, eg 0.1.0 , 0.1.1 , 0.2.0 ... but milestones URLs have internal numbers ( https://github.com/owner/project/milestone/1 , https://github.com/owner/project/milestone/2 , ...).我们有按版本号命名的里程碑,例如0.1.00.1.10.2.0 ...但里程碑 URL 具有内部编号( https://github.com/owner/project/milestone/1https:// github.com/owner/project/milestone/2 , ...)。 How can I automatically generate a link to the corresponding milestone URL given only its milestone name?如何仅根据里程碑名称自动生成指向相应里程碑 URL 的链接?

There seems to be no official way or third-party service to link to a GitHub milestone by its name but it would be easy to build such service based on GitHub API.似乎没有官方方式或第三方服务可以通过其名称链接到 GitHub 里程碑,但基于 GitHub API 构建此类服务会很容易。 As indicated by jonrsharpe , the milestones API can be used to query all milestones and then find a corresponding link.正如jonrsharpe所指出的,里程碑 API可用于查询所有里程碑,然后找到相应的链接。 Given user $USER , repository name $REPO and milestone name $VERSION , this one-line gets the milestone URL (requires curl and jq ):给定用户$USER ,存储库名称$REPO和里程碑名称$VERSION ,这一行获取里程碑 URL(需要curljq ):

curl -s 'https://api.github.com/repos/$USER/$REPO/milestones?per_page=100' \
  | jq -r ".[]|select(.title==\"$VERSION\").html_url"

This only works for up to 100 milestones because of API response pagination.由于 API 响应分页,这仅适用于最多 100 个里程碑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM