aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/github/export.go
diff options
context:
space:
mode:
authorAmine Hilaly <hilalyamine@gmail.com>2019-07-05 20:55:24 +0200
committerAmine Hilaly <hilalyamine@gmail.com>2019-07-05 22:03:00 +0200
commit3e181168eadb1d6a13e67583c16219200d052fcc (patch)
tree74fdc5e4e6c511e457919f53d9d51c75e505de3c /bridge/github/export.go
parent93e731fd0d365c0cf49dbb7aea371e48f46e1f11 (diff)
downloadgit-bug-3e181168eadb1d6a13e67583c16219200d052fcc.tar.gz
[bridge/github] improve export label change function
[bridge/core] rename `EventStatus` to `ExportEvent`
Diffstat (limited to 'bridge/github/export.go')
-rw-r--r--bridge/github/export.go91
1 files changed, 57 insertions, 34 deletions
diff --git a/bridge/github/export.go b/bridge/github/export.go
index 5e5b1a21..c4ca42da 100644
--- a/bridge/github/export.go
+++ b/bridge/github/export.go
@@ -7,6 +7,8 @@ import (
"fmt"
"io/ioutil"
"net/http"
+ "strings"
+ "sync"
"time"
"github.com/pkg/errors"
@@ -671,7 +673,7 @@ func updateGithubIssueStatus(gc *githubv4.Client, id string, status bug.Status)
case bug.OpenStatus:
state = githubv4.IssueStateOpen
case bug.ClosedStatus:
- state = githubv4.IssueStateOpen
+ state = githubv4.IssueStateClosed
default:
panic("unknown bug state")
}
@@ -730,49 +732,70 @@ func updateGithubIssueTitle(gc *githubv4.Client, id, title string) error {
// update github issue labels
func (ge *githubExporter) updateGithubIssueLabels(gc *githubv4.Client, labelableID string, added, removed []bug.Label) error {
- addedIDs, err := ge.getLabelsIDs(gc, labelableID, added)
- if err != nil {
- return errors.Wrap(err, "getting added labels ids")
- }
-
- m := &addLabelsToLabelableMutation{}
- inputAdd := githubv4.AddLabelsToLabelableInput{
- LabelableID: labelableID,
- LabelIDs: addedIDs,
- }
+ var errs []string
+ var wg sync.WaitGroup
parentCtx := context.Background()
- ctx, cancel := context.WithTimeout(parentCtx, defaultTimeout)
- // add labels
- if err := gc.Mutate(ctx, m, inputAdd, nil); err != nil {
- cancel()
- return err
- }
- cancel()
+ if len(added) > 0 {
+ wg.Add(1)
+ go func() {
+ defer wg.Done()
- if len(removed) == 0 {
- return nil
- }
+ addedIDs, err := ge.getLabelsIDs(gc, labelableID, added)
+ if err != nil {
+ errs = append(errs, errors.Wrap(err, "getting added labels ids").Error())
+ return
+ }
- removedIDs, err := ge.getLabelsIDs(gc, labelableID, removed)
- if err != nil {
- return errors.Wrap(err, "getting added labels ids")
+ m := &addLabelsToLabelableMutation{}
+ inputAdd := githubv4.AddLabelsToLabelableInput{
+ LabelableID: labelableID,
+ LabelIDs: addedIDs,
+ }
+
+ ctx, cancel := context.WithTimeout(parentCtx, defaultTimeout)
+ defer cancel()
+
+ // add labels
+ if err := gc.Mutate(ctx, m, inputAdd, nil); err != nil {
+ errs = append(errs, err.Error())
+ }
+ }()
}
- m2 := &removeLabelsFromLabelableMutation{}
- inputRemove := githubv4.RemoveLabelsFromLabelableInput{
- LabelableID: labelableID,
- LabelIDs: removedIDs,
+ if len(removed) > 0 {
+ wg.Add(1)
+ go func() {
+ defer wg.Done()
+
+ removedIDs, err := ge.getLabelsIDs(gc, labelableID, removed)
+ if err != nil {
+ errs = append(errs, errors.Wrap(err, "getting added labels ids").Error())
+ return
+ }
+
+ m2 := &removeLabelsFromLabelableMutation{}
+ inputRemove := githubv4.RemoveLabelsFromLabelableInput{
+ LabelableID: labelableID,
+ LabelIDs: removedIDs,
+ }
+
+ ctx, cancel := context.WithTimeout(parentCtx, defaultTimeout)
+ defer cancel()
+
+ // remove label labels
+ if err := gc.Mutate(ctx, m2, inputRemove, nil); err != nil {
+ errs = append(errs, err.Error())
+ }
+ }()
}
- ctx, cancel = context.WithTimeout(parentCtx, defaultTimeout)
- defer cancel()
+ wg.Wait()
- // remove label labels
- if err := gc.Mutate(ctx, m2, inputRemove, nil); err != nil {
- return err
+ if len(errs) == 0 {
+ return nil
}
- return nil
+ return fmt.Errorf("label change error: %v", strings.Join(errs, "\n"))
}