Merge pull request #20 from suryasr007/master

Make checking for duplicate msg optional
This commit is contained in:
Aaron Klaassen 2020-03-31 14:03:06 -05:00 committed by GitHub
commit 182ec73bcf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 8 deletions

View file

@ -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
```

View file

@ -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 }}
- ${{ inputs.msg }}
- ${{ inputs.check_for_duplicate_msg }}

View file

@ -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)