mirror of
https://github.com/unsplash/comment-on-pr.git
synced 2024-09-20 07:36:02 +08:00
Merge pull request #20 from suryasr007/master
Make checking for duplicate msg optional
This commit is contained in:
commit
182ec73bcf
|
@ -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
|
||||
```
|
||||
|
|
|
@ -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 }}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue