aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/github/export.go
diff options
context:
space:
mode:
authorAmine Hilaly <hilalyamine@gmail.com>2019-06-22 19:46:42 +0200
committerAmine Hilaly <hilalyamine@gmail.com>2019-06-24 21:32:38 +0200
commit4ad3d336c69922a7e34c782e995db9f1adcbc403 (patch)
treec82ea3e48460adc6c8852908f8eae8150eb45a17 /bridge/github/export.go
parentf70c279c1e8dc7f73e08679f8789c35c1dfdd59d (diff)
downloadgit-bug-4ad3d336c69922a7e34c782e995db9f1adcbc403.tar.gz
[bridge/github] use context.WithTimeout on all graphql queries
Diffstat (limited to 'bridge/github/export.go')
-rw-r--r--bridge/github/export.go62
1 files changed, 52 insertions, 10 deletions
diff --git a/bridge/github/export.go b/bridge/github/export.go
index a41efc99..e76e95f0 100644
--- a/bridge/github/export.go
+++ b/bridge/github/export.go
@@ -429,7 +429,12 @@ func markOperationAsExported(b *cache.BugCache, target git.Hash, githubID, githu
func (ge *githubExporter) getGithubLabelID(gc *githubv4.Client, label string) (string, error) {
q := labelQuery{}
variables := map[string]interface{}{"name": label}
- if err := gc.Query(context.TODO(), &q, variables); err != nil {
+
+ parentCtx := context.Background()
+ ctx, cancel := context.WithTimeout(parentCtx, defaultTimeout)
+ defer cancel()
+
+ if err := gc.Query(ctx, &q, variables); err != nil {
return "", err
}
@@ -486,7 +491,11 @@ func (ge *githubExporter) createGithubLabelV4(gc *githubv4.Client, label, labelC
Color: githubv4.String(labelColor),
}
- if err := gc.Mutate(context.TODO(), m, input, nil); err != nil {
+ parentCtx := context.Background()
+ ctx, cancel := context.WithTimeout(parentCtx, defaultTimeout)
+ defer cancel()
+
+ if err := gc.Mutate(ctx, m, input, nil); err != nil {
return "", err
}
@@ -558,7 +567,11 @@ func createGithubIssue(gc *githubv4.Client, repositoryID, title, body string) (s
Body: (*githubv4.String)(&body),
}
- if err := gc.Mutate(context.TODO(), m, input, nil); err != nil {
+ parentCtx := context.Background()
+ ctx, cancel := context.WithTimeout(parentCtx, defaultTimeout)
+ defer cancel()
+
+ if err := gc.Mutate(ctx, m, input, nil); err != nil {
return "", "", err
}
@@ -574,7 +587,11 @@ func addCommentGithubIssue(gc *githubv4.Client, subjectID string, body string) (
Body: githubv4.String(body),
}
- if err := gc.Mutate(context.TODO(), m, input, nil); err != nil {
+ parentCtx := context.Background()
+ ctx, cancel := context.WithTimeout(parentCtx, defaultTimeout)
+ defer cancel()
+
+ if err := gc.Mutate(ctx, m, input, nil); err != nil {
return "", "", err
}
@@ -589,7 +606,11 @@ func editCommentGithubIssue(gc *githubv4.Client, commentID, body string) (string
Body: githubv4.String(body),
}
- if err := gc.Mutate(context.TODO(), m, input, nil); err != nil {
+ parentCtx := context.Background()
+ ctx, cancel := context.WithTimeout(parentCtx, defaultTimeout)
+ defer cancel()
+
+ if err := gc.Mutate(ctx, m, input, nil); err != nil {
return "", "", err
}
@@ -611,7 +632,11 @@ func updateGithubIssueStatus(gc *githubv4.Client, id string, status bug.Status)
State: &state,
}
- if err := gc.Mutate(context.TODO(), m, input, nil); err != nil {
+ parentCtx := context.Background()
+ ctx, cancel := context.WithTimeout(parentCtx, defaultTimeout)
+ defer cancel()
+
+ if err := gc.Mutate(ctx, m, input, nil); err != nil {
return err
}
@@ -625,7 +650,11 @@ func updateGithubIssueBody(gc *githubv4.Client, id string, body string) error {
Body: (*githubv4.String)(&body),
}
- if err := gc.Mutate(context.TODO(), m, input, nil); err != nil {
+ parentCtx := context.Background()
+ ctx, cancel := context.WithTimeout(parentCtx, defaultTimeout)
+ defer cancel()
+
+ if err := gc.Mutate(ctx, m, input, nil); err != nil {
return err
}
@@ -639,7 +668,11 @@ func updateGithubIssueTitle(gc *githubv4.Client, id, title string) error {
Title: (*githubv4.String)(&title),
}
- if err := gc.Mutate(context.TODO(), m, input, nil); err != nil {
+ parentCtx := context.Background()
+ ctx, cancel := context.WithTimeout(parentCtx, defaultTimeout)
+ defer cancel()
+
+ if err := gc.Mutate(ctx, m, input, nil); err != nil {
return err
}
@@ -648,6 +681,7 @@ 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")
@@ -659,11 +693,16 @@ func (ge *githubExporter) updateGithubIssueLabels(gc *githubv4.Client, labelable
LabelIDs: addedIDs,
}
+ parentCtx := context.Background()
+ ctx, cancel := context.WithTimeout(parentCtx, defaultTimeout)
+
// add labels
- if err := gc.Mutate(context.TODO(), m, inputAdd, nil); err != nil {
+ if err := gc.Mutate(ctx, m, inputAdd, nil); err != nil {
+ cancel()
return err
}
+ cancel()
removedIDs, err := ge.getLabelsIDs(gc, labelableID, added)
if err != nil {
return errors.Wrap(err, "getting added labels ids")
@@ -675,8 +714,11 @@ func (ge *githubExporter) updateGithubIssueLabels(gc *githubv4.Client, labelable
LabelIDs: removedIDs,
}
+ ctx2, cancel2 := context.WithTimeout(parentCtx, defaultTimeout)
+ defer cancel2()
+
// remove label labels
- if err := gc.Mutate(context.TODO(), m2, inputRemove, nil); err != nil {
+ if err := gc.Mutate(ctx2, m2, inputRemove, nil); err != nil {
return err
}