php editor Youzi will introduce to you how to build a specific version of Github APIv4 Golang query. Github APIv4 is a powerful query tool that can help developers obtain and process various data on Github. However, sometimes we may need to obtain a specific version of data, and the official API does not directly provide such a function. In this article, we will explore how to write custom queries using Golang to get a specific version of data.
Using https://github.com/shurcooL/githubv4, I'm really having trouble pulling back a specific version for the gh repository.
When there is a v3 version, the following code block always returns nothing:
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)
I have successfully obtained the following two code blocks for the repository description and issue reaction:
var repoDescriptionQ struct { Repository struct { Description string } `graphql:"repository(owner: \"jacobtomlinson\", name: \"gha-find-replace\")"` }
This success returns the repository description ^
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)"` }
This successfully got the response^
Found that the author field is not a string, but of type "User". Change the requested field to "Description" which is a string and it is pulling back the posting information. If you really need an author, you need to define the user:
var releaseQ struct { Repository struct { Release struct { Description githubv4.String } `graphql:"release(tagName:$tagName)"` } `graphql:"repository(owner:$repositoryOwner,name:$repositoryName)"` }
The above is the detailed content of How to build a Github APIv4 Golang query for a specific version. For more information, please follow other related articles on the PHP Chinese website!