mirror of
https://github.com/unsplash/comment-on-pr.git
synced 2024-09-20 07:36:02 +08:00
Merge branch 'master' into master
This commit is contained in:
commit
fc87dc5b3d
|
@ -1,4 +1,4 @@
|
|||
FROM ruby:2.7-alpine
|
||||
FROM ruby:3-alpine3.13
|
||||
|
||||
LABEL "com.github.actions.name"="Comment on PR"
|
||||
LABEL "com.github.actions.description"="Leaves a comment on an open PR matching a push event."
|
||||
|
|
|
@ -24,5 +24,6 @@ jobs:
|
|||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
msg: "Check out this message!"
|
||||
check_for_duplicate_msg: false # OPTIONAL
|
||||
check_for_duplicate_msg: false # OPTIONAL
|
||||
delete_prev_regex_msg: "[0-9]" # OPTIONAL
|
||||
```
|
||||
|
|
13
action.yml
13
action.yml
|
@ -9,12 +9,23 @@ inputs:
|
|||
description: Comment's message
|
||||
required: true
|
||||
check_for_duplicate_msg:
|
||||
description: If false, action doesn't check for duplicate msg.
|
||||
description: If false, action doesn't check for duplicate message.
|
||||
required: false
|
||||
default: true
|
||||
delete_prev_regex_msg:
|
||||
description: If not empty, all messages matching the given regex will be deleted.
|
||||
required: false
|
||||
default: nil
|
||||
duplicate_msg_pattern:
|
||||
description: Optional pattern to use when checking for duplicate message.
|
||||
required: false
|
||||
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'Dockerfile'
|
||||
args:
|
||||
- ${{ inputs.msg }}
|
||||
- ${{ inputs.check_for_duplicate_msg }}
|
||||
- ${{ inputs.delete_prev_regex_msg }}
|
||||
- ${{ inputs.duplicate_msg_pattern }}
|
||||
|
||||
|
|
|
@ -20,6 +20,9 @@ end
|
|||
|
||||
message = ARGV[0]
|
||||
check_duplicate_msg = ARGV[1]
|
||||
delete_prev_regex_msg = ARGV[2]
|
||||
duplicate_msg_pattern = ARGV[3]
|
||||
|
||||
repo = event["repository"]["full_name"]
|
||||
|
||||
if ENV.fetch("GITHUB_EVENT_NAME") == "pull_request"
|
||||
|
@ -39,7 +42,13 @@ end
|
|||
|
||||
if check_duplicate_msg == "true"
|
||||
coms = github.issue_comments(repo, pr_number)
|
||||
duplicate = coms.find { |c| c["body"] == message }
|
||||
|
||||
duplicate = if duplicate_msg_pattern
|
||||
coms.find { |c| (c["body"] =~ Regexp.new duplicate_msg_pattern) }
|
||||
else
|
||||
coms.find { |c| c["body"] == message }
|
||||
end
|
||||
|
||||
|
||||
if duplicate
|
||||
puts "The PR already contains this message"
|
||||
|
@ -47,4 +56,12 @@ if check_duplicate_msg == "true"
|
|||
end
|
||||
end
|
||||
|
||||
if delete_prev_regex_msg != nil
|
||||
coms.each do |n|
|
||||
if n["body"].match(/#{delete_prev_regex_msg}/)
|
||||
github.delete_comment(repo, n["id"], opt = {})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
github.add_comment(repo, pr_number, message)
|
||||
|
|
Loading…
Reference in a new issue