diff options
author | Alexander Scharinger <rng.dynamics@gmail.com> | 2020-12-12 23:57:46 +0100 |
---|---|---|
committer | Alexander Scharinger <rng.dynamics@gmail.com> | 2020-12-12 23:57:46 +0100 |
commit | 0baf65cd6404219881fb6767b0fde2bf1bb12b75 (patch) | |
tree | c1dc981dd963556a575dcf98c16bb001ce7568b0 | |
parent | 61bfc51ebe4420982aa40e6b9d56d8ca114151c4 (diff) | |
download | git-bug-0baf65cd6404219881fb6767b0fde2bf1bb12b75.tar.gz |
WIP: Pinpoint some of the reasons for bug #385
Work in progress. The github bridge contains a bug documented in issue #385.
This commit shows what is the problem. There might be more problems. I have
changed the GraphQL query for timeline items and there are much less wrong
imports now. (Are there any malformed imports left?) I would like to rework the
entire bridge/github/iterator in the near future in order to create a reliable
fix for this bug.
-rw-r--r-- | bridge/github/import_query.go | 22 | ||||
-rw-r--r-- | bridge/github/iterator.go | 31 |
2 files changed, 48 insertions, 5 deletions
diff --git a/bridge/github/import_query.go b/bridge/github/import_query.go index 58f6d95e..264f5c22 100644 --- a/bridge/github/import_query.go +++ b/bridge/github/import_query.go @@ -98,9 +98,10 @@ type timelineItem struct { type issueTimeline struct { authorEvent - Title string - Body githubv4.String - Url githubv4.URI + Title string + Number githubv4.Int + Body githubv4.String + Url githubv4.URI TimelineItems struct { Edges []struct { @@ -116,6 +117,21 @@ type issueTimeline struct { } `graphql:"userContentEdits(last: $issueEditLast, before: $issueEditBefore)"` } +// Alex +type timelineItemsQuery struct { + Repository struct { + Issue struct { + TimelineItems struct { + Edges []struct { + Cursor githubv4.String + Node timelineItem + } + PageInfo pageInfo + } `graphql:"timelineItems(first: $timelineFirst, after: $timelineAfter)"` + } `graphql:"issue(number: $issueNumber)"` + } `graphql:"repository(owner: $owner, name: $name)"` +} + type issueEdit struct { UserContentEdits struct { Nodes []userContentEdit diff --git a/bridge/github/iterator.go b/bridge/github/iterator.go index 40b00292..a9f4bd59 100644 --- a/bridge/github/iterator.go +++ b/bridge/github/iterator.go @@ -2,6 +2,7 @@ package github import ( "context" + "fmt" "time" "github.com/shurcooL/githubv4" @@ -29,6 +30,7 @@ type timelineIterator struct { issueEdit indexer commentEdit indexer + // Alex: It would be really help clearity to get rid of this variable. // lastEndCursor cache the timeline end cursor for one iteration lastEndCursor githubv4.String } @@ -100,7 +102,7 @@ func NewIterator(ctx context.Context, client *githubv4.Client, capacity int, own // init issue timeline variables func (i *iterator) initTimelineQueryVariables() { - i.timeline.variables["issueFirst"] = githubv4.Int(1) + i.timeline.variables["issueFirst"] = githubv4.Int(1) // each query one single issue only i.timeline.variables["issueAfter"] = (*githubv4.String)(nil) i.timeline.variables["issueSince"] = githubv4.DateTime{Time: i.since} i.timeline.variables["timelineFirst"] = githubv4.Int(i.capacity) @@ -175,6 +177,10 @@ func (i *iterator) NextIssue() bool { return false } + if i.ctx.Err() != nil { + return false + } + // if $issueAfter variable is nil we can directly make the first query if i.timeline.variables["issueAfter"] == (*githubv4.String)(nil) { nextIssue := i.queryIssue() @@ -223,6 +229,7 @@ func (i *iterator) NextTimelineItem() bool { timelineItems := i.timeline.query.Repository.Issues.Nodes[0].TimelineItems // after NextIssue call it's good to check wether we have some timelineItems items or not + // Alex: Correct? if len(timelineItems.Edges) == 0 { return false } @@ -240,14 +247,34 @@ func (i *iterator) NextTimelineItem() bool { // more timelines, query them i.timeline.variables["timelineAfter"] = timelineItems.PageInfo.EndCursor + // HACK + var query timelineItemsQuery + // var variables map[string]interface{} + variables := make(map[string]interface{}) + variables["owner"] = i.timeline.variables["owner"] + variables["name"] = i.timeline.variables["name"] + variables["issueNumber"] = i.timeline.query.Repository.Issues.Nodes[0].Number + fmt.Println("### Alex using issue number ", i.timeline.query.Repository.Issues.Nodes[0].Number) + variables["timelineFirst"] = i.timeline.variables["timelineFirst"] + variables["timelineAfter"] = i.timeline.variables["timelineAfter"] + variables["commentEditLast"] = i.timeline.variables["commentEditLast"] + variables["commentEditBefore"] = i.timeline.variables["commentEditBefore"] ctx, cancel := context.WithTimeout(i.ctx, defaultTimeout) defer cancel() - if err := i.gc.Query(ctx, &i.timeline.query, i.timeline.variables); err != nil { + // if err := i.gc.Query(ctx, &i.timeline.query, i.timeline.variables); err != nil { + if err := i.gc.Query(ctx, &query, variables); err != nil { i.err = err return false } + // HACK + fmt.Println("### Alex after the query") + i.timeline.variables["timelineFirst"] = variables["timelineFirst"] + i.timeline.variables["timelineAfter"] = variables["timelineAfter"] + i.timeline.variables["commentEditLast"] = variables["commentEditLast"] + i.timeline.variables["commentEditBefore"] = variables["commentEditBefore"] + i.timeline.query.Repository.Issues.Nodes[0].TimelineItems = query.Repository.Issue.TimelineItems timelineItems = i.timeline.query.Repository.Issues.Nodes[0].TimelineItems // (in case github returns something weird) just for safety: better return a false than a panic |