aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/github/iterator.go
diff options
context:
space:
mode:
authorAmine Hilaly <hilalyamine@gmail.com>2019-05-14 01:46:07 +0200
committerAmine Hilaly <hilalyamine@gmail.com>2019-05-23 14:21:44 +0200
commit2a9705612478bfae4515616d9649ddfb140b54cf (patch)
tree4b46b7f4a0872ab9e41768e43abbc6c80ee7d50d /bridge/github/iterator.go
parent12f6fd61be835ca37e6a4e8a17abd4b8175e6ba0 (diff)
downloadgit-bug-2a9705612478bfae4515616d9649ddfb140b54cf.tar.gz
introduce `nextValidIssueEdit` and `nextValidCommentEdit` to escape empty `Diff`objects
calling nextValidEdit functions directly after a new query (Fixing a bug where capacity=2)
Diffstat (limited to 'bridge/github/iterator.go')
-rw-r--r--bridge/github/iterator.go40
1 files changed, 21 insertions, 19 deletions
diff --git a/bridge/github/iterator.go b/bridge/github/iterator.go
index f39dc31b..2aa15034 100644
--- a/bridge/github/iterator.go
+++ b/bridge/github/iterator.go
@@ -247,6 +247,15 @@ func (i *iterator) queryIssueEdit() bool {
i.issueEdit.index = 0
i.timeline.issueEdit.index = -2
+ return i.nextValidIssueEdit()
+}
+
+func (i *iterator) nextValidIssueEdit() bool {
+ // issueEdit.Diff == nil happen if the event is older than early 2018, Github doesn't have the data before that.
+ // Best we can do is to ignore the event.
+ if issueEdit := i.IssueEditValue(); issueEdit.Diff == nil || string(*issueEdit.Diff) == "" {
+ return i.NextIssueEdit()
+ }
return true
}
@@ -260,10 +269,7 @@ func (i *iterator) NextIssueEdit() bool {
if i.timeline.issueEdit.index == -2 {
if i.issueEdit.index < min(i.capacity, len(i.issueEdit.query.Repository.Issues.Nodes[0].UserContentEdits.Nodes))-1 {
i.issueEdit.index++
- if issueEdit := i.IssueEditValue(); issueEdit.Diff == nil || string(*issueEdit.Diff) == "" {
- return i.NextIssueEdit()
- }
- return true
+ return i.nextValidIssueEdit()
}
if !i.issueEdit.query.Repository.Issues.Nodes[0].UserContentEdits.PageInfo.HasPreviousPage {
@@ -294,12 +300,7 @@ func (i *iterator) NextIssueEdit() bool {
// loop over them timeline comment edits
if i.timeline.issueEdit.index < min(i.capacity, len(i.timeline.query.Repository.Issues.Nodes[0].UserContentEdits.Nodes))-1 {
i.timeline.issueEdit.index++
- // issueEdit.Diff == nil happen if the event is older than early 2018, Github doesn't have the data before that.
- // Best we can do is to ignore the event.
- if issueEdit := i.IssueEditValue(); issueEdit.Diff == nil || string(*issueEdit.Diff) == "" {
- return i.NextIssueEdit()
- }
- return true
+ return i.nextValidIssueEdit()
}
if !i.timeline.query.Repository.Issues.Nodes[0].UserContentEdits.PageInfo.HasPreviousPage {
@@ -339,6 +340,14 @@ func (i *iterator) queryCommentEdit() bool {
i.commentEdit.index = 0
i.timeline.commentEdit.index = -2
+ return i.nextValidCommentEdit()
+}
+
+func (i *iterator) nextValidCommentEdit() bool {
+ // if comment edit diff is a nil pointer or points to an empty string look for next value
+ if commentEdit := i.CommentEditValue(); commentEdit.Diff == nil || string(*commentEdit.Diff) == "" {
+ return i.NextCommentEdit()
+ }
return true
}
@@ -352,10 +361,7 @@ func (i *iterator) NextCommentEdit() bool {
if i.commentEdit.index < min(i.capacity, len(i.commentEdit.query.Repository.Issues.Nodes[0].Timeline.Nodes[0].IssueComment.UserContentEdits.Nodes))-1 {
i.commentEdit.index++
- if commentEdit := i.CommentEditValue(); commentEdit.Diff == nil || string(*commentEdit.Diff) == "" {
- return i.NextCommentEdit()
- }
- return true
+ return i.nextValidCommentEdit()
}
if !i.commentEdit.query.Repository.Issues.Nodes[0].Timeline.Nodes[0].IssueComment.UserContentEdits.PageInfo.HasPreviousPage {
@@ -377,11 +383,7 @@ func (i *iterator) NextCommentEdit() bool {
// loop over them timeline comment edits
if i.timeline.commentEdit.index < min(i.capacity, len(i.timeline.query.Repository.Issues.Nodes[0].Timeline.Edges[i.timeline.index].Node.IssueComment.UserContentEdits.Nodes))-1 {
i.timeline.commentEdit.index++
- // if comment edit diff is nil or point to an empty string look for next value
- if commentEdit := i.CommentEditValue(); commentEdit.Diff == nil || string(*commentEdit.Diff) == "" {
- return i.NextCommentEdit()
- }
- return true
+ return i.nextValidCommentEdit()
}
if !i.timeline.query.Repository.Issues.Nodes[0].Timeline.Edges[i.timeline.index].Node.IssueComment.UserContentEdits.PageInfo.HasPreviousPage {