From 758baf5e9ffb7fc2bcbd0fe8934414b8387d2335 Mon Sep 17 00:00:00 2001 From: Surya Teja <94suryateja@gmail.com> Date: Mon, 30 Mar 2020 17:24:33 +0530 Subject: [PATCH] Make checking for duplicate msg optional --- README.md | 3 ++- action.yml | 7 ++++++- entrypoint.sh | 16 ++++++++++------ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 058bcba..b0496fc 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ A GitHub action to comment on the relevant open PR when a commit is pushed. ### Sample workflow -``` +```yaml name: comment-on-pr example on: pull_request jobs: @@ -24,4 +24,5 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: msg: "Check out this message!" + check_for_duplicate_msg: false # OPTIONAL ``` diff --git a/action.yml b/action.yml index 6ddd907..19c0218 100644 --- a/action.yml +++ b/action.yml @@ -8,8 +8,13 @@ inputs: msg: description: Comment's message required: true + check_for_duplicate_msg: + description: If false, action doesn't check for duplicate msg. + required: false + default: true runs: using: 'docker' image: 'Dockerfile' args: - - ${{ inputs.msg }} \ No newline at end of file + - ${{ inputs.msg }} + - ${{ inputs.check_for_duplicate_msg }} diff --git a/entrypoint.sh b/entrypoint.sh index d429cb7..be6188c 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -13,11 +13,13 @@ if !ENV["GITHUB_TOKEN"] exit(1) end -if ARGV.empty? +if ARGV[0].empty? puts "Missing message argument." exit(1) end +message = ARGV[0] +check_duplicate_msg = ARGV[1] repo = event["repository"]["full_name"] if ENV.fetch("GITHUB_EVENT_NAME") == "pull_request" @@ -34,14 +36,16 @@ else end pr_number = pr["number"] end -message = ARGV.join(' ') coms = github.issue_comments(repo, pr_number) -duplicate = coms.find { |c| c["user"]["login"] == "github-actions[bot]" && c["body"] == message } -if duplicate - puts "The PR already contains this message" - exit(0) +if check_duplicate_msg == "true" + duplicate = coms.find { |c| c["user"]["login"] == "github-actions[bot]" && c["body"] == message } + + if duplicate + puts "The PR already contains this message" + exit(0) + end end github.add_comment(repo, pr_number, message)