1package github
2
3import (
4 "context"
5 "fmt"
6
7 "github.com/MichaelMure/git-bug/bridge/core"
8 "github.com/MichaelMure/git-bug/cache"
9 "github.com/shurcooL/githubv4"
10)
11
12type githubImporter struct{}
13
14func (*githubImporter) ImportAll(repo *cache.RepoCache, conf core.Configuration) error {
15 client := buildClient(conf)
16
17 type Event struct {
18 CreatedAt githubv4.DateTime
19 Actor struct {
20 Login githubv4.String
21 AvatarUrl githubv4.String
22 }
23 }
24
25 var q struct {
26 Repository struct {
27 Issues struct {
28 Nodes []struct {
29 Title string
30 Timeline struct {
31 Nodes []struct {
32 Typename githubv4.String `graphql:"__typename"`
33
34 // Issue
35 IssueComment struct {
36 Author struct {
37 Login githubv4.String
38 AvatarUrl githubv4.String
39 }
40 BodyText githubv4.String
41 CreatedAt githubv4.DateTime
42
43 // TODO: edition
44 } `graphql:"... on IssueComment"`
45
46 // Label
47 LabeledEvent struct {
48 Event
49 Label struct {
50 Color githubv4.String
51 Name githubv4.String
52 }
53 } `graphql:"... on LabeledEvent"`
54 UnlabeledEvent struct {
55 Event
56 Label struct {
57 Color githubv4.String
58 Name githubv4.String
59 }
60 } `graphql:"... on UnlabeledEvent"`
61
62 // Status
63 ClosedEvent struct {
64 Event
65 } `graphql:"... on ClosedEvent"`
66 ReopenedEvent struct {
67 Event
68 } `graphql:"... on ReopenedEvent"`
69
70 // Title
71 RenamedTitleEvent struct {
72 Event
73 CurrentTitle githubv4.String
74 PreviousTitle githubv4.String
75 } `graphql:"... on RenamedTitleEvent"`
76 }
77 PageInfo struct {
78 EndCursor githubv4.String
79 HasNextPage bool
80 }
81 } `graphql:"timeline(first: $timelineFirst, after: $timelineAfter)"`
82 }
83 PageInfo struct {
84 EndCursor githubv4.String
85 HasNextPage bool
86 }
87 } `graphql:"issues(first: $issueFirst, after: $issueAfter)"`
88 } `graphql:"repository(owner: $owner, name: $name)"`
89 }
90
91 variables := map[string]interface{}{
92 "owner": githubv4.String(conf[keyUser]),
93 "name": githubv4.String(conf[keyProject]),
94 "issueFirst": githubv4.Int(1),
95 "issueAfter": (*githubv4.String)(nil),
96 "timelineFirst": githubv4.Int(10),
97 "timelineAfter": (*githubv4.String)(nil),
98 }
99
100 for {
101 err := client.Query(context.TODO(), &q, variables)
102 if err != nil {
103 return err
104 }
105
106 for _, event := range q.Repository.Issues.Nodes[0].Timeline.Nodes {
107 fmt.Println(event)
108 }
109
110 if !q.Repository.Issues.Nodes[0].Timeline.PageInfo.HasNextPage {
111 break
112 }
113 variables["timelineAfter"] = githubv4.NewString(q.Repository.Issues.Nodes[0].Timeline.PageInfo.EndCursor)
114 }
115
116 return nil
117}
118
119func (*githubImporter) Import(repo *cache.RepoCache, conf core.Configuration, id string) error {
120 fmt.Println(conf)
121 fmt.Println("IMPORT")
122
123 return nil
124}