如何使用 API 检查我的 GitHub 存储库中是否存在标签问题?

How do I check if an issue with a tag exists on my GitHub repo using the API?

所以我下面的这段代码每小时自动运行一次,但问题是每当有合并冲突时,它都会产生一个问题,不管它是否存在,所以我最终遇到了一堆重复的问题在回购协议中。如何检查 "Merge Conflict" 标签是否存在问题,以免产生重复问题?

这只是重要代码的一部分:

CONFLICTS=$(git ls-files -u | wc -l)
if [ "$CONFLICTS" -gt 0 ] ; then
    echo "There is a merge conflict. Aborting"
    git merge --abort
    curl -u $GITHUB_USER:$GITHUB_SECRET_TOKEN -H "Content-Type: application/json" -X POST -d '{"title": "Merge conflict detected", "body": "Heroku could not update your repo. Please check for merge conflicts and update manually!","labels": ["merge conflict"]}' https://api.github.com/repos/$GITHUB_REPO/issues
    exit 1
fi

您可以使用 Search issues API 使用以下搜索参数:

  • 回购:username/repo
  • 状态:打开
  • 标签:"merge conflict"(勾选this

在 UI 中:https://github.com/search?q=repo%3AMacley-Kun%2Favaire+state%3Aopen+label%3A%22merge+conflict%22

使用 Github API 休息 v3

https://api.github.com/search/issues?q=repo%3AMacley-Kun%2Favaire%20state%3Aopen%20label%3A%22merge%20conflict%22

使用 with & 检查此 repo 是否至少有一个标记为 "merge conflict" 的问题(不区分大小写)

query='repo:Macley-Kun/avaire state:open label:"merge conflict"'

merge_conflicts=$(curl -G -s "https://api.github.com/search/issues" \
     --data-urlencode "q=$query" | jq '.items | length')

if [ "$merge_conflicts" -eq 0 ]; then
    echo "no opened merge conflicts issue detected"
else
    echo "one or many merge conflicts issues already exist"
fi

使用 Github API Graphql v4

{
  search(query: "repo:Macley-Kun/avaire state:open label:\"merge conflict\"", type: ISSUE, first: 0) {
    issueCount
  }
}

Try it from the explorer

使用 with &

repo=Macley-Kun/avaire

merge_conflicts=$(curl -s -H "Authorization: token $YOUR_TOKEN" \
     -H  "Content-Type:application/json" \
     -d '{ 
          "query": "{search(query: \"repo:'"$REPO"' state:open label:\\"merge conflict\\"\", type: ISSUE, first: 0) {issueCount}}"
      }' https://api.github.com/graphql | jq '.data.search.issueCount')

if [ "$merge_conflicts" -eq 0 ]; then
    echo "no opened merge conflicts issue detected"
else
    echo "one or many merge conflicts issues already exist"
fi