简体   繁体   English

GitHub GraphQL API:获取提交的标签

[英]GitHub GraphQL API: Get tags for a commit

I don't know if it's just hard to form a useful search for this problem or if there is no solution, but I've been trying to figure out how to use the GitHub GraphQL API to fetch all tags associated with a given commit.我不知道是否很难对这个问题进行有用的搜索,或者是否没有解决方案,但我一直在尝试弄清楚如何使用 GitHub GraphQL API 来获取与给定提交相关的所有标签。

I'm new to GraphQL and the GitHub API, so I'm just using GitHub's explorer to try to find the mechanism to do this.我是 GraphQL 和 GitHub API 的新手,所以我只是使用GitHub 的资源管理器来尝试找到执行此操作的机制。

Here's what I've tried, where there is a commit with hash bfa0635104bc9a559254b5007646942ff269ae11 and message 1.0.0 , tagged with v1.0.0 .这是我尝试过的,其中有一个带有哈希bfa0635104bc9a559254b5007646942ff269ae11和消息1.0.0的提交,标记为v1.0.0 I'm trying to get that tag, given the commit hash.鉴于提交哈希,我正在尝试获取该标签。

{
  repository(owner: "bscotch", name: "stitch") {
    createdAt
    description
    name
    object(expression: "bfa0635104bc9a559254b5007646942ff269ae11") {
      ... on Commit {
        message
        oid
      }
      ... on Tag {
        tagId: id
        target {
          oid
        }
      }
    }
    ref(qualifiedName: "bfa0635104bc9a559254b5007646942ff269ae11") {
      name
    }
    refs(first: 10, refPrefix: "refs/tags/", orderBy: {field: TAG_COMMIT_DATE, direction: DESC}, query: "bfa0635104bc9a559254b5007646942ff269ae11") {
      nodes {
        name
      }
    }
  }
}

The output of the above only returns data for the ... on Commit content.上面的输出只返回... on Commit内容的数据。 Everything else is completely absent:其他一切都完全不存在:

{
  "data": {
    "repository": {
      "createdAt": "2020-09-18T18:47:33Z",
      "description": "A Gamemaker Studio 2 Pipeline Development Kit. A CLI and Node.JS API for creating GMS2 asset pipelines.",
      "name": "stitch",
      "object": {
        "message": "1.0.0",
        "oid": "bfa0635104bc9a559254b5007646942ff269ae11"
      },
      "ref": null,
      "refs": {
        "nodes": []
      }
    }
  }
}

Is there a way to do this via the API?有没有办法通过 API 做到这一点? My best guess is that, if there is, it's via the refs field.我最好的猜测是,如果有的话,它是通过refs字段。

I've also been struggling and this isn't the best answer, but it at least works at minimum.我也一直在挣扎,这不是最好的答案,但至少它至少有效。

Query refs/tags/ to get all tags, then filter manually in whatever language you're using for the matching OID.查询refs/tags/以获取所有标签,然后以您用于匹配 OID 的任何语言手动过滤。 You're not guaranteed to fetch all the tags in one call so that you for sure have the OID in it, but I was trying to match against what was likely a recent tag, so it worked fine.您不能保证在一次调用中获取所有标签,因此您肯定在其中包含 OID,但我试图与可能是最近的标签进行匹配,因此它运行良好。

{
  repository(name: "dg", owner: "dgattey") {
    refs(refPrefix: "refs/tags/", last: 100) {
      nodes {
        name
        target {
          oid
        }
      }
    }
  }
}

This gets me a giant list, but in it, I have这给了我一个巨大的清单,但在其中,我有

        {
          "node": {
            "name": "v2.0.1",
            "target": {
              "oid": "85fe69df20062aafeea7593c45c1785f44208252"
            }
          }
        }

And I can use other code to check "85fe69df20062aafeea7593c45c1785f44208252" against the OID I was searching for.我可以使用其他代码根据我正在搜索的 OID 检查“85fe69df20062aafeea7593c45c1785f44208252”。 Not ideal!不理想!

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

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