ImportAll iterate over all the configured repository issues and ensure the creation of the missing issues / timeline items / edits / label events ...
(ctx context.Context, repo *cache.RepoCache, since time.Time)
| 51 | // ImportAll iterate over all the configured repository issues and ensure the creation of the |
| 52 | // missing issues / timeline items / edits / label events ... |
| 53 | func (gi *githubImporter) ImportAll(ctx context.Context, repo *cache.RepoCache, since time.Time) (<-chan core.ImportResult, error) { |
| 54 | gi.mediator = NewImportMediator(ctx, gi.client, gi.conf[confKeyOwner], gi.conf[confKeyProject], since) |
| 55 | out := make(chan core.ImportResult) |
| 56 | gi.out = out |
| 57 | |
| 58 | go func() { |
| 59 | defer close(gi.out) |
| 60 | var currBug *cache.BugCache |
| 61 | var currEvent ImportEvent |
| 62 | var nextEvent ImportEvent |
| 63 | var err error |
| 64 | for { |
| 65 | // An IssueEvent contains the issue in its most recent state. If an issue |
| 66 | // has at least one issue edit, then the history of the issue edits is |
| 67 | // represented by IssueEditEvents. That is, the unedited (original) issue |
| 68 | // might be saved only in the IssueEditEvent following the IssueEvent. |
| 69 | // Since we replicate the edit history we need to either use the IssueEvent |
| 70 | // (if there are no edits) or the IssueEvent together with its first |
| 71 | // IssueEditEvent (if there are edits). |
| 72 | // Exactly the same is true for comments and comment edits. |
| 73 | // As a consequence we need to look at the current event and one look ahead |
| 74 | // event. |
| 75 | |
| 76 | currEvent = nextEvent |
| 77 | if currEvent == nil { |
| 78 | currEvent = gi.getEventHandleMsgs() |
| 79 | } |
| 80 | if currEvent == nil { |
| 81 | break |
| 82 | } |
| 83 | nextEvent = gi.getEventHandleMsgs() |
| 84 | |
| 85 | switch event := currEvent.(type) { |
| 86 | case RateLimitingEvent: |
| 87 | out <- core.NewImportRateLimiting(event.msg) |
| 88 | case IssueEvent: |
| 89 | // first: commit what is being held in currBug |
| 90 | if err = gi.commit(currBug, out); err != nil { |
| 91 | out <- core.NewImportError(err, "") |
| 92 | return |
| 93 | } |
| 94 | // second: create new issue |
| 95 | switch next := nextEvent.(type) { |
| 96 | case IssueEditEvent: |
| 97 | // consuming and using next event |
| 98 | nextEvent = nil |
| 99 | currBug, err = gi.ensureIssue(ctx, repo, &event.issue, &next.userContentEdit) |
| 100 | default: |
| 101 | currBug, err = gi.ensureIssue(ctx, repo, &event.issue, nil) |
| 102 | } |
| 103 | if err != nil { |
| 104 | err := fmt.Errorf("issue creation: %v", err) |
| 105 | out <- core.NewImportError(err, "") |
| 106 | return |
| 107 | } |
| 108 | case IssueEditEvent: |
| 109 | err = gi.ensureIssueEdit(ctx, repo, currBug, event.issueId, &event.userContentEdit) |
| 110 | if err != nil { |