From 455b98b46bb4b1cecde71221d9eeab7ebba2d435 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Wed, 3 Feb 2021 12:42:35 -1000 Subject: [PATCH 1/3] Allow changing labels description The GitHub API allows to change labels description: https://docs.github.com/en/rest/reference/issues#update-a-label --- lib/github_api/client/issues/labels.rb | 2 +- spec/fixtures/issues/label.json | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/github_api/client/issues/labels.rb b/lib/github_api/client/issues/labels.rb index 53844c89..9de05c8d 100644 --- a/lib/github_api/client/issues/labels.rb +++ b/lib/github_api/client/issues/labels.rb @@ -5,7 +5,7 @@ module Github class Client::Issues::Labels < API - VALID_LABEL_INPUTS = %w[ name color ].freeze + VALID_LABEL_INPUTS = %w[ name color description ].freeze # List all labels for a repository # diff --git a/spec/fixtures/issues/label.json b/spec/fixtures/issues/label.json index 8fe5d68e..10470f46 100644 --- a/spec/fixtures/issues/label.json +++ b/spec/fixtures/issues/label.json @@ -1,5 +1,6 @@ { "url": "https://api.github.com/repos/octocat/Hello-World/labels/bug", "name": "bug", - "color": "f29513" + "color": "f29513", + "description": "Something isn't working" } From e23bcf68c83b033da2df81ba9eaa2c060fb771c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Wed, 3 Feb 2021 12:53:49 -1000 Subject: [PATCH 2/3] Fix label parameters validation No parameter are mandatory for updating an existing label, but when creating one, a name is required. https://docs.github.com/en/rest/reference/issues#create-a-label --- lib/github_api/client/issues/labels.rb | 3 +-- spec/github/client/issues/labels/update_spec.rb | 12 ------------ 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/lib/github_api/client/issues/labels.rb b/lib/github_api/client/issues/labels.rb index 9de05c8d..f9b98407 100644 --- a/lib/github_api/client/issues/labels.rb +++ b/lib/github_api/client/issues/labels.rb @@ -80,7 +80,7 @@ def get(*args) def create(*args) arguments(args, required: [:user, :repo]) do permit VALID_LABEL_INPUTS - assert_required VALID_LABEL_INPUTS + assert_required %w[ name color ] end post_request("/repos/#{arguments.user}/#{arguments.repo}/labels", arguments.params) @@ -103,7 +103,6 @@ def create(*args) def update(*args) arguments(args, required: [:user, :repo, :label_name]) do permit VALID_LABEL_INPUTS - assert_required VALID_LABEL_INPUTS end patch_request("/repos/#{arguments.user}/#{arguments.repo}/labels/#{arguments.label_name}", arguments.params) diff --git a/spec/github/client/issues/labels/update_spec.rb b/spec/github/client/issues/labels/update_spec.rb index ca0043ae..2854e3c4 100644 --- a/spec/github/client/issues/labels/update_spec.rb +++ b/spec/github/client/issues/labels/update_spec.rb @@ -26,18 +26,6 @@ let(:body) { fixture('issues/label.json') } let(:status) { 200 } - it "should fail to create resource if 'name' input is missing" do - expect { - subject.update user, repo, label_id, inputs.except('name') - }.to raise_error(Github::Error::RequiredParams) - end - - it "should fail to create resource if 'color' input is missing" do - expect { - subject.update user, repo, label_id, inputs.except('color') - }.to raise_error(Github::Error::RequiredParams) - end - it "should update resource successfully" do subject.update user, repo, label_id, inputs expect(a_patch(request_path).with(body: inputs)).to have_been_made From 540826fc49d89a3f84bd1027044def9a28cfd47b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Wed, 3 Feb 2021 12:53:37 -1000 Subject: [PATCH 3/3] Allow renaming a label When renaming a label, the new name must be passed as `new_name`: https://docs.github.com/en/rest/reference/issues#update-a-label --- lib/github_api/client/issues/labels.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/github_api/client/issues/labels.rb b/lib/github_api/client/issues/labels.rb index f9b98407..d759c97e 100644 --- a/lib/github_api/client/issues/labels.rb +++ b/lib/github_api/client/issues/labels.rb @@ -5,7 +5,7 @@ module Github class Client::Issues::Labels < API - VALID_LABEL_INPUTS = %w[ name color description ].freeze + VALID_LABEL_INPUTS = %w[ name color description new_name ].freeze # List all labels for a repository #