From 3ab56f59b5c90d5c1ab0bbb82d942b59312a168e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 8 Sep 2016 23:27:32 +0200 Subject: [PATCH] Fix assigning labels/assignees without the other The GitHub API doesn't seem to like receiving `"assignees": null`. Fixes #1240 --- commands/issue.go | 14 ++++++++++---- commands/pull_request.go | 21 +++++++++++---------- features/issue.feature | 10 +++++----- features/pull_request.feature | 4 ++-- features/support/local_server.rb | 9 ++++++++- 5 files changed, 36 insertions(+), 22 deletions(-) diff --git a/commands/issue.go b/commands/issue.go index 7cc8f157..8e990f55 100644 --- a/commands/issue.go +++ b/commands/issue.go @@ -366,10 +366,16 @@ func createIssue(cmd *Command, args *Args) { } params := map[string]interface{}{ - "title": title, - "body": body, - "labels": flagIssueLabels, - "assignees": flagIssueAssignees, + "title": title, + "body": body, + } + + if len(flagIssueLabels) > 0 { + params["labels"] = flagIssueLabels + } + + if len(flagIssueAssignees) > 0 { + params["assignees"] = flagIssueAssignees } if flagIssueMilestone > 0 { diff --git a/commands/pull_request.go b/commands/pull_request.go index cb389a3f..aa44f99a 100644 --- a/commands/pull_request.go +++ b/commands/pull_request.go @@ -245,17 +245,18 @@ func pullRequest(cmd *Command, args *Args) { pullRequestURL = pr.HtmlUrl - if len(flagPullRequestAssignees) > 0 || flagPullRequestMilestone > 0 || - len(flagPullRequestLabels) > 0 { - - params := map[string]interface{}{ - "labels": flagPullRequestLabels, - "assignees": flagPullRequestAssignees, - } - if flagPullRequestMilestone > 0 { - params["milestone"] = flagPullRequestMilestone - } + params = map[string]interface{}{} + if len(flagPullRequestLabels) > 0 { + params["labels"] = flagPullRequestLabels + } + if len(flagPullRequestAssignees) > 0 { + params["assignees"] = flagPullRequestAssignees + } + if flagPullRequestMilestone > 0 { + params["milestone"] = flagPullRequestMilestone + } + if len(params) > 0 { err = client.UpdateIssue(baseProject, pr.Number, params) utils.Check(err) } diff --git a/features/issue.feature b/features/issue.feature index 218fcaa0..c2c6b86f 100644 --- a/features/issue.feature +++ b/features/issue.feature @@ -84,7 +84,7 @@ Feature: hub issue Given the GitHub API server: """ get('/repos/github/hub/issues') { - assert :per_page => "100", :page => nil + assert :per_page => "100", :page => :no response.headers["Link"] = %(; rel="next") json [ { :number => 102, @@ -197,7 +197,7 @@ Feature: hub issue post('/repos/github/hub/issues') { assert :title => "Not workie, pls fix", :body => "", - :labels => nil + :labels => :no status 201 json :html_url => "https://github.com/github/hub/issues/1337" @@ -227,8 +227,8 @@ Feature: hub issue post('/repos/github/hub/issues') { assert :title => "hello", :body => "", - :milestone => nil, - :assignees => nil, + :milestone => :no, + :assignees => :no, :labels => ["wont fix", "docs", "nope"] status 201 @@ -249,7 +249,7 @@ Feature: hub issue :body => "", :milestone => 12, :assignees => ["mislav", "josh", "pcorpet"], - :labels => nil + :labels => :no status 201 json :html_url => "https://github.com/github/hub/issues/1337" diff --git a/features/pull_request.feature b/features/pull_request.feature index 55c078d5..f97cbde2 100644 --- a/features/pull_request.feature +++ b/features/pull_request.feature @@ -695,7 +695,7 @@ BODY json :html_url => "the://url", :number => 1234 } patch('/repos/mislav/coral/issues/1234') { - assert :assignees => ["mislav", "josh", "pcorpet"], :labels => nil + assert :assignees => ["mislav", "josh", "pcorpet"], :labels => :no json :html_url => "the://url" } """ @@ -729,7 +729,7 @@ BODY json :html_url => "the://url", :number => 1234 } patch('/repos/mislav/coral/issues/1234') { - assert :labels => ["feature", "release", "docs"] + assert :labels => ["feature", "release", "docs"], :assignees => :no json :html_url => "the://url" } """ diff --git a/features/support/local_server.rb b/features/support/local_server.rb index 7c3b67fa..2b8ca9bf 100644 --- a/features/support/local_server.rb +++ b/features/support/local_server.rb @@ -69,7 +69,14 @@ module Hub def assert(expected) expected.each do |key, value| - if params[key] != value + if :no == value + halt 422, json( + :message => "expected %s not to be passed; got %s" % [ + key.inspect, + params[key].inspect + ] + ) if params.key?(key.to_s) + elsif params[key] != value halt 422, json( :message => "expected %s to be %s; got %s" % [ key.inspect, -- GitLab