diff options
author | Michael Muré <batolettre@gmail.com> | 2018-09-24 19:22:32 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2018-09-24 19:22:32 +0200 |
commit | c4a207622a894ba9839f1a3c47c9d78beff9b861 (patch) | |
tree | 009d80b363b5392e6eba4bec85b0ae74b3942995 /bridge/github | |
parent | c86e7231b223d532e26ab5449715c65b6b4e3fde (diff) | |
download | git-bug-c4a207622a894ba9839f1a3c47c9d78beff9b861.tar.gz |
github: query most of the data
Diffstat (limited to 'bridge/github')
-rw-r--r-- | bridge/github/github.go | 24 | ||||
-rw-r--r-- | bridge/github/import.go | 124 |
2 files changed, 133 insertions, 15 deletions
diff --git a/bridge/github/github.go b/bridge/github/github.go index 4f7a3b94..a8371637 100644 --- a/bridge/github/github.go +++ b/bridge/github/github.go @@ -1,10 +1,11 @@ package github import ( - "fmt" + "context" "github.com/MichaelMure/git-bug/bridge/core" - "github.com/MichaelMure/git-bug/cache" + "github.com/shurcooL/githubv4" + "golang.org/x/oauth2" ) func init() { @@ -25,18 +26,11 @@ func (*Github) Exporter() core.Exporter { return nil } -type githubImporter struct{} +func buildClient(conf core.Configuration) *githubv4.Client { + src := oauth2.StaticTokenSource( + &oauth2.Token{AccessToken: conf[keyToken]}, + ) + httpClient := oauth2.NewClient(context.TODO(), src) -func (*githubImporter) ImportAll(repo *cache.RepoCache, conf core.Configuration) error { - fmt.Println(conf) - fmt.Println("IMPORT ALL") - - return nil -} - -func (*githubImporter) Import(repo *cache.RepoCache, conf core.Configuration, id string) error { - fmt.Println(conf) - fmt.Println("IMPORT") - - return nil + return githubv4.NewClient(httpClient) } diff --git a/bridge/github/import.go b/bridge/github/import.go new file mode 100644 index 00000000..0e6b03d2 --- /dev/null +++ b/bridge/github/import.go @@ -0,0 +1,124 @@ +package github + +import ( + "context" + "fmt" + + "github.com/MichaelMure/git-bug/bridge/core" + "github.com/MichaelMure/git-bug/cache" + "github.com/shurcooL/githubv4" +) + +type githubImporter struct{} + +func (*githubImporter) ImportAll(repo *cache.RepoCache, conf core.Configuration) error { + client := buildClient(conf) + + type Event struct { + CreatedAt githubv4.DateTime + Actor struct { + Login githubv4.String + AvatarUrl githubv4.String + } + } + + var q struct { + Repository struct { + Issues struct { + Nodes []struct { + Title string + Timeline struct { + Nodes []struct { + Typename githubv4.String `graphql:"__typename"` + + // Issue + IssueComment struct { + Author struct { + Login githubv4.String + AvatarUrl githubv4.String + } + BodyText githubv4.String + CreatedAt githubv4.DateTime + + // TODO: edition + } `graphql:"... on IssueComment"` + + // Label + LabeledEvent struct { + Event + Label struct { + Color githubv4.String + Name githubv4.String + } + } `graphql:"... on LabeledEvent"` + UnlabeledEvent struct { + Event + Label struct { + Color githubv4.String + Name githubv4.String + } + } `graphql:"... on UnlabeledEvent"` + + // Status + ClosedEvent struct { + Event + } `graphql:"... on ClosedEvent"` + ReopenedEvent struct { + Event + } `graphql:"... on ReopenedEvent"` + + // Title + RenamedTitleEvent struct { + Event + CurrentTitle githubv4.String + PreviousTitle githubv4.String + } `graphql:"... on RenamedTitleEvent"` + } + PageInfo struct { + EndCursor githubv4.String + HasNextPage bool + } + } `graphql:"timeline(first: $timelineFirst, after: $timelineAfter)"` + } + PageInfo struct { + EndCursor githubv4.String + HasNextPage bool + } + } `graphql:"issues(first: $issueFirst, after: $issueAfter)"` + } `graphql:"repository(owner: $owner, name: $name)"` + } + + variables := map[string]interface{}{ + "owner": githubv4.String(conf[keyUser]), + "name": githubv4.String(conf[keyProject]), + "issueFirst": githubv4.Int(1), + "issueAfter": (*githubv4.String)(nil), + "timelineFirst": githubv4.Int(10), + "timelineAfter": (*githubv4.String)(nil), + } + + for { + err := client.Query(context.TODO(), &q, variables) + if err != nil { + return err + } + + for _, event := range q.Repository.Issues.Nodes[0].Timeline.Nodes { + fmt.Println(event) + } + + if !q.Repository.Issues.Nodes[0].Timeline.PageInfo.HasNextPage { + break + } + variables["timelineAfter"] = githubv4.NewString(q.Repository.Issues.Nodes[0].Timeline.PageInfo.EndCursor) + } + + return nil +} + +func (*githubImporter) Import(repo *cache.RepoCache, conf core.Configuration, id string) error { + fmt.Println(conf) + fmt.Println("IMPORT") + + return nil +} |