aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/github
diff options
context:
space:
mode:
Diffstat (limited to 'bridge/github')
-rw-r--r--bridge/github/export.go60
-rw-r--r--bridge/github/export_query.go38
-rw-r--r--bridge/github/import_query.go2
3 files changed, 58 insertions, 42 deletions
diff --git a/bridge/github/export.go b/bridge/github/export.go
index df8400da..393146d6 100644
--- a/bridge/github/export.go
+++ b/bridge/github/export.go
@@ -426,17 +426,25 @@ func markOperationAsExported(b *cache.BugCache, target git.Hash, githubID, githu
// get label from github
func (ge *githubExporter) getGithubLabelID(gc *githubv4.Client, label string) (string, error) {
- q := labelQuery{}
- variables := map[string]interface{}{"name": label}
+ q := &labelQuery{}
+ variables := map[string]interface{}{
+ "label": githubv4.String(label),
+ "owner": githubv4.String(ge.conf[keyOwner]),
+ "name": githubv4.String(ge.conf[keyProject]),
+ }
parentCtx := context.Background()
ctx, cancel := context.WithTimeout(parentCtx, defaultTimeout)
defer cancel()
- if err := gc.Query(ctx, &q, variables); err != nil {
+ if err := gc.Query(ctx, q, variables); err != nil {
return "", err
}
+ if q.Repository.Label.ID == "" {
+ return "", fmt.Errorf("label not found")
+ }
+
return q.Repository.Label.ID, nil
}
@@ -475,8 +483,6 @@ func (ge *githubExporter) createGithubLabel(gc *githubv4.Client, label, labelCol
}
if resp.StatusCode != http.StatusCreated {
- //d, _ := ioutil.ReadAll(resp.Body)
- //fmt.Println(string(d))
return "", fmt.Errorf("error creating label: response status %v", resp.StatusCode)
}
@@ -494,13 +500,12 @@ func (ge *githubExporter) createGithubLabel(gc *githubv4.Client, label, labelCol
return "", err
}
- fmt.Println("ezzz", aux.NodeID)
return aux.NodeID, nil
}
// create github label using api v4
func (ge *githubExporter) createGithubLabelV4(gc *githubv4.Client, label, labelColor string) (string, error) {
- m := &createLabelMutation{}
+ m := createLabelMutation{}
input := createLabelInput{
RepositoryID: ge.repositoryID,
Name: githubv4.String(label),
@@ -511,7 +516,7 @@ func (ge *githubExporter) createGithubLabelV4(gc *githubv4.Client, label, labelC
ctx, cancel := context.WithTimeout(parentCtx, defaultTimeout)
defer cancel()
- if err := gc.Mutate(ctx, m, input, nil); err != nil {
+ if err := gc.Mutate(ctx, &m, input, nil); err != nil {
return "", err
}
@@ -529,8 +534,6 @@ func (ge *githubExporter) getOrCreateGithubLabelID(gc *githubv4.Client, reposito
rgba := label.RGBA()
hexColor := fmt.Sprintf("%.2x%.2x%.2x", rgba.R, rgba.G, rgba.B)
- fmt.Println("creating color", label, hexColor)
-
// create label and return id
labelID, err = ge.createGithubLabel(gc, string(label), hexColor)
if err != nil {
@@ -620,8 +623,7 @@ func editCommentGithubIssue(gc *githubv4.Client, commentID, body string) (string
return "", "", err
}
- comment := m.IssueComment
- return commentID, comment.URL, nil
+ return commentID, m.UpdateIssueComment.IssueComment.URL, nil
}
func updateGithubIssueStatus(gc *githubv4.Client, id string, status bug.Status) error {
@@ -687,7 +689,6 @@ 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")
@@ -707,25 +708,28 @@ func (ge *githubExporter) updateGithubIssueLabels(gc *githubv4.Client, labelable
cancel()
return err
}
-
cancel()
- removedIDs, err := ge.getLabelsIDs(gc, labelableID, added)
- if err != nil {
- return errors.Wrap(err, "getting added labels ids")
- }
- m2 := &removeLabelsFromLabelableMutation{}
- inputRemove := githubv4.RemoveLabelsFromLabelableInput{
- LabelableID: labelableID,
- LabelIDs: removedIDs,
- }
+ if len(removed) > 0 {
+ removedIDs, err := ge.getLabelsIDs(gc, labelableID, removed)
+ if err != nil {
+ return errors.Wrap(err, "getting added labels ids")
+ }
+
+ m2 := &removeLabelsFromLabelableMutation{}
+ inputRemove := githubv4.RemoveLabelsFromLabelableInput{
+ LabelableID: labelableID,
+ LabelIDs: removedIDs,
+ }
- ctx2, cancel2 := context.WithTimeout(parentCtx, defaultTimeout)
- defer cancel2()
+ ctx, cancel := context.WithTimeout(parentCtx, defaultTimeout)
+ defer cancel()
+
+ // remove label labels
+ if err := gc.Mutate(ctx, m2, inputRemove, nil); err != nil {
+ return err
+ }
- // remove label labels
- if err := gc.Mutate(ctx2, m2, inputRemove, nil); err != nil {
- return err
}
return nil
diff --git a/bridge/github/export_query.go b/bridge/github/export_query.go
index 006d2511..95d4e6a9 100644
--- a/bridge/github/export_query.go
+++ b/bridge/github/export_query.go
@@ -32,31 +32,43 @@ type addCommentToIssueMutation struct {
}
type updateIssueCommentMutation struct {
- IssueComment struct {
- ID string `graphql:"id"`
- URL string `graphql:"url"`
+ UpdateIssueComment struct {
+ IssueComment struct {
+ ID string `graphql:"id"`
+ URL string `graphql:"url"`
+ } `graphql:"issueComment"`
} `graphql:"updateIssueComment(input:$input)"`
}
+type removeLabelsFromLabelableMutation struct {
+ AddLabels struct {
+ Labelable struct {
+ Typename string `graphql:"__typename"`
+ }
+ } `graphql:"removeLabelsFromLabelable(input:$input)"`
+}
+
+type addLabelsToLabelableMutation struct {
+ RemoveLabels struct {
+ Labelable struct {
+ Typename string `graphql:"__typename"`
+ }
+ } `graphql:"addLabelsToLabelable(input:$input)"`
+}
+
type createLabelMutation struct {
CreateLabel struct {
Label struct {
ID string `graphql:"id"`
} `graphql:"label"`
- } `graphql:"createLabel(input:{repositoryId: $repositoryId, name: $name, color: $color})"`
-}
-
-type removeLabelsFromLabelableMutation struct {
- AddLabels struct{} `graphql:"removeLabelsFromLabelable(input:$input)"`
-}
-
-type addLabelsToLabelableMutation struct {
- RemoveLabels struct{} `graphql:"addLabelsToLabelable(input:$input)"`
+ } `graphql:"createLabel(input: $input)"`
}
type createLabelInput struct {
Color githubv4.String `json:"color"`
- Description *githubv4.String `json:"description"`
+ Description *githubv4.String `json:"description,omitempty"`
Name githubv4.String `json:"name"`
RepositoryID githubv4.ID `json:"repositoryId"`
+
+ ClientMutationID *githubv4.String `json:"clientMutationId,omitempty"`
}
diff --git a/bridge/github/import_query.go b/bridge/github/import_query.go
index 6c0db5e1..34931c7d 100644
--- a/bridge/github/import_query.go
+++ b/bridge/github/import_query.go
@@ -173,6 +173,6 @@ type labelQuery struct {
Repository struct {
Label struct {
ID string `graphql:"id"`
- } `graphql:"label(name: $name)"`
+ } `graphql:"label(name: $label)"`
} `graphql:"repository(owner: $owner, name: $name)"`
}