如何为特定版本构建Github APIv4 Golang Query

iezvtpos  于 5个月前  发布在  Go
关注(0)|答案(1)|浏览(76)

使用https://github.com/shurcooL/githubv4,我真的很难为gh repo拉回一个特定的版本。
下面的代码块在有v3版本时保持不返回任何内容:

var releaseQ struct {
  Repository struct {
    Release struct {
        Author githubv4.String
    } `graphql:"release(tagName:$tagName)"`
  } `graphql:"repository(owner:$repositoryOwner,name:$repositoryName)"`
}
variables = map[string]interface{}{
    "repositoryOwner": githubv4.String("jacobtomlinson"),
    "repositoryName":  githubv4.String("gha-find-replace"),
    "tagName":         githubv4.String("v3"),
}
err = client.Query(context.Background(), &releaseQ, variables)
if err != nil {
    fmt.Println("Query returned nothing")
}
fmt.Println("author:", releaseQ.Repository.Release.Author)

字符串
我已经成功地让以下两个代码块用于repo描述和问题React:

var repoDescriptionQ struct {
  Repository struct {
    Description string
  } `graphql:"repository(owner: \"jacobtomlinson\", name: \"gha-find-replace\")"`
}


此成功返回的存储库描述^

variables := map[string]interface{}{
  "repositoryOwner": githubv4.String("jacobtomlinson"),
  "repositoryName":  githubv4.String("gha-find-replace"),
  "issueNumber":     githubv4.Int(55),
  "reactionContent": githubv4.ReactionContentThumbsDown,
}
var reactionQ struct {
Repository struct {
    Issue struct {
        ID        githubv4.ID
        Reactions struct {
            ViewerHasReacted githubv4.Boolean
        } `graphql:"reactions(content:$reactionContent)"`
    } `graphql:"issue(number:$issueNumber)"`
} `graphql:"repository(owner:$repositoryOwner,name:$repositoryName)"`
}


这成功地得到了React^

35g0bw71

35g0bw711#

首先,Author字段不是字符串,而是“User”类型。将请求的字段更改为Description,这是一个字符串,它正在拉回发布信息。如果您确实想要Author,则需要定义User:

var releaseQ struct {
    Repository struct {
        Release struct {
            Description githubv4.String
        } `graphql:"release(tagName:$tagName)"`
    } `graphql:"repository(owner:$repositoryOwner,name:$repositoryName)"`
}

字符串

相关问题