From d6bcac7cb52262ae155488a748bcbc7a61111f21 Mon Sep 17 00:00:00 2001 From: Yonatan Kiron Date: Thu, 7 Jun 2018 16:00:38 +0300 Subject: [PATCH] Add delete label parameter --- README.md | 2 ++ assets/lib/commands/out.rb | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/README.md b/README.md index 92460fe..4b9c864 100644 --- a/README.md +++ b/README.md @@ -187,6 +187,8 @@ Set the status message for `concourse-ci` context on specified pull request. * `label`: *Optional.* A label to add to the pull request. +* `delete_label`: *Optional.* A label to remove from the pull request. + ## Example pipeline Please see this repo's [pipeline](https://github.com/jtarchie/pullrequest-resource/blob/master/.concourse.yml) for a perfect example. diff --git a/assets/lib/commands/out.rb b/assets/lib/commands/out.rb index 547a581..c88b043 100755 --- a/assets/lib/commands/out.rb +++ b/assets/lib/commands/out.rb @@ -71,6 +71,17 @@ def output metadata << { 'name' => 'label', 'value' => params.label } end + if params.delete_label + label_exists = Octokit.labels_for_issue(input.source.repo, id).select do |hash| + hash.to_hash[:name] == params.delete_label + end + + if label_exists.any? + Octokit.remove_label(input.source.repo, id, params.delete_label) + end + metadata << { 'name' => 'delete_label', 'value' => params.delete_label } + end + if params.merge.method commit_msg = if params.merge.commit_msg commit_path = File.join(destination, params.merge.commit_msg)