在我们的GitHub repos中,我们有一组标签和一组分配给标签的版本。
现在我们要删除未分配给版本的标签。
知道如何使用git命令执行此操作吗?
感谢您的提示。
最好的问候
答案 0 :(得分:2)
您可以使用Github ref API& Github releases API与jq JSON parser:
/git/refs/tags
脚本:
REPO=remotestorage/remotestorage.js
TAG_LIST=$(curl -s "https://api.github.com/repos/$REPO/git/refs/tags?per_page=100" | \
jq '[ .[] | .ref ]')
RELEASE_LIST=$(curl -s "https://api.github.com/repos/$REPO/releases?per_page=100" | \
jq '[ .[] | "refs/tags/" + .tag_name ]')
NOT_IN_RELEASE=$(echo $TAG_LIST | jq --argjson releases "$RELEASE_LIST" '. - $releases' | jq -r '.[]')
echo "$NOT_IN_RELEASE"
# when you are ready
# echo $NOT_IN_RELEASE | xargs git tag -d
请注意,如果您有超过100个版本或标记,则必须traverse pagination
使用Github Graphql API v4,您可以将上述2个请求合并为一个。在the explorer:
{
repository(owner: "remotestorage", name: "remotestorage.js") {
releases(first: 100) {
nodes {
tag {
name
}
}
}
refs(first: 100, refPrefix: "refs/tags/") {
nodes {
name
}
}
}
}
脚本将是:
NOT_IN_RELEASE=$(curl -s -H "Authorization: bearer YOUR_ACCESS_TOKEN" -d '
{
"query": "query { repository(owner: \"remotestorage\", name: \"remotestorage.js\") { releases(first: 100) { nodes { tag { name } } } refs(first: 100, refPrefix: \"refs/tags/\") {nodes { name } } } }"
}
' https://api.github.com/graphql | \
jq -r '.data.repository | [.refs.nodes[].name] - [.releases.nodes[].tag.name] | .[]')
echo "$NOT_IN_RELEASE"
# when you are ready
# echo $NOT_IN_RELEASE | xargs git tag -d