使用 https://github.com/shurcooL/githubv4,我真的很难为 gh 存储库拉回特定版本。
当有 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)
我已成功获得以下两个代码块,用于存储库描述和问题反应:
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)"`
}
这成功地得到了反应^
发现了,Author 字段不是字符串,而是“User”类型。将请求的字段更改为“描述”,这是一个字符串,它正在拉回发布信息。如果您确实需要作者,您需要定义用户:
var releaseQ struct {
Repository struct {
Release struct {
Description githubv4.String
} `graphql:"release(tagName:$tagName)"`
} `graphql:"repository(owner:$repositoryOwner,name:$repositoryName)"`
}