aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/github/export.go
diff options
context:
space:
mode:
authorAmine Hilaly <hilalyamine@gmail.com>2019-06-23 13:50:45 +0200
committerAmine Hilaly <hilalyamine@gmail.com>2019-06-24 21:33:29 +0200
commit0dea0f6a7673865b16e71f1998c3b0db33a54514 (patch)
tree02124e2f3cc0871a849bdb2af68a8d012ba01572 /bridge/github/export.go
parentfc09f2a492348f3b6013308697cbc86e15e8ab47 (diff)
downloadgit-bug-0dea0f6a7673865b16e71f1998c3b0db33a54514.tar.gz
[bridge/github] simplify export operation hashs
[bridge/github] exporter tests: add more test cases and global tests [bridge/github] rename export_query to export_mutation [bridge/github] exporter: Log number of exported issues and labels [bridge/github] Improve comments
Diffstat (limited to 'bridge/github/export.go')
-rw-r--r--bridge/github/export.go38
1 files changed, 12 insertions, 26 deletions
diff --git a/bridge/github/export.go b/bridge/github/export.go
index 947d5aca..1ab6ebca 100644
--- a/bridge/github/export.go
+++ b/bridge/github/export.go
@@ -29,6 +29,9 @@ type githubExporter struct {
// number of exported bugs
exportedBugs int
+ // number of exported labels
+ exportedLabels int
+
// export only bugs taged with one of these origins
onlyOrigins []string
@@ -146,6 +149,7 @@ bugLoop:
}
}
+ fmt.Printf("Successfully exported %d issues and %d labels to Github\n", ge.exportedBugs, ge.exportedLabels)
return nil
}
@@ -272,10 +276,8 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time) error {
return errors.Wrap(err, "adding comment")
}
- hash, err = opr.Hash()
- if err != nil {
- return errors.Wrap(err, "comment hash")
- }
+ // cache comment id
+ ge.cachedIDs[hash.String()] = id
case *bug.EditCommentOperation:
@@ -311,22 +313,12 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time) error {
url = eurl
}
- hash, err = opr.Hash()
- if err != nil {
- return errors.Wrap(err, "comment hash")
- }
-
case *bug.SetStatusOperation:
opr := op.(*bug.SetStatusOperation)
if err := updateGithubIssueStatus(client, bugGithubID, opr.Status); err != nil {
return errors.Wrap(err, "editing status")
}
- hash, err = opr.Hash()
- if err != nil {
- return errors.Wrap(err, "set status operation hash")
- }
-
id = bugGithubID
url = bugGithubURL
@@ -336,11 +328,6 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time) error {
return errors.Wrap(err, "editing title")
}
- hash, err = opr.Hash()
- if err != nil {
- return errors.Wrap(err, "set title operation hash")
- }
-
id = bugGithubID
url = bugGithubURL
@@ -350,11 +337,6 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time) error {
return errors.Wrap(err, "updating labels")
}
- hash, err = opr.Hash()
- if err != nil {
- return errors.Wrap(err, "label change operation hash")
- }
-
id = bugGithubID
url = bugGithubURL
@@ -367,6 +349,7 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time) error {
return errors.Wrap(err, "marking operation as exported")
}
+ // commit at each operation export to avoid exporting same events multiple times
if err := b.CommitAsNeeded(); err != nil {
return errors.Wrap(err, "bug commit")
}
@@ -451,7 +434,7 @@ func (ge *githubExporter) getGithubLabelID(gc *githubv4.Client, label string) (s
return q.Repository.Label.ID, nil
}
-func (ge *githubExporter) createGithubLabel(gc *githubv4.Client, label, labelColor string) (string, error) {
+func (ge *githubExporter) createGithubLabel(label, labelColor string) (string, error) {
url := fmt.Sprintf("%s/repos/%s/%s/labels", githubV3Url, ge.conf[keyOwner], ge.conf[keyProject])
client := &http.Client{
@@ -538,11 +521,14 @@ func (ge *githubExporter) getOrCreateGithubLabelID(gc *githubv4.Client, reposito
hexColor := fmt.Sprintf("%.2x%.2x%.2x", rgba.R, rgba.G, rgba.B)
// create label and return id
- labelID, err = ge.createGithubLabel(gc, string(label), hexColor)
+ // NOTE: since createLabel mutation is still in preview mode we use github api v4 to create labels
+ // see https://developer.github.com/v4/mutation/createlabel/ and https://developer.github.com/v4/previews/#labels-preview
+ labelID, err = ge.createGithubLabel(string(label), hexColor)
if err != nil {
return "", err
}
+ ge.exportedLabels++
return labelID, nil
}