Last active
March 27, 2022 04:55
-
-
Save syossan27/5df243b9724f09b779e29ebfb595cdca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
type item struct { | |
Title string | |
FieldValues struct { | |
Nodes []struct { | |
Value string | |
ProjectField struct { | |
Name string | |
} | |
} | |
} `graphql:"fieldValues(first: 10)"` | |
} | |
var query struct { | |
Node struct { | |
ProjectNext struct { | |
Items struct { | |
Nodes []item | |
PageInfo struct { | |
EndCursor githubv4.String | |
HasNextPage bool | |
} | |
} `graphql:"items(first: 100, after: $itemsCursor)"` | |
} `graphql:"... on ProjectNext"` | |
} `graphql:"node(id: \"[GitHub ProjectのノードID]\")"` | |
} | |
variables := map[string]interface{}{ | |
"itemsCursor": (*githubv4.String)(nil), | |
} | |
// 認証 | |
src := oauth2.StaticTokenSource( | |
&oauth2.Token{AccessToken: "[GITHUB_ACCESS_TOKEN]"}, | |
) | |
httpClient := oauth2.NewClient(context.Background(), src) | |
client := githubv4.NewClient(httpClient) | |
// Queryの実行 | |
// 100個までしか一度に取得できないので、まだタスクがあるなら次のページを取得 | |
var items []item | |
for { | |
err := client.Query(context.Background(), &query, variables) | |
if err != nil { | |
fmt.Println(err) | |
return | |
} | |
items = append(items, query.Node.ProjectNext.Items.Nodes...) | |
if !query.Node.ProjectNext.Items.PageInfo.HasNextPage { | |
break | |
} | |
variables["itemsCursor"] = githubv4.NewString(query.Node.ProjectNext.Items.PageInfo.EndCursor) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment