Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pattern based options #44

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ inputs:
required: false
default: true
delete_prev_regex_msg:
description: If not empty, all messages matching the given regex will be deleted.
description: If provided, all messages matching the given regex will be deleted.
required: false
default: nil
default: ~
duplicate_msg_pattern:
description: Optional pattern to use when checking for duplicate message.
description: If provided, the regex pattern will be used when checking for duplicate messages.
required: false
default: ~

runs:
using: 'docker'
Expand Down
32 changes: 17 additions & 15 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,27 @@ else
pr_number = pr["number"]
end

comments = github.issue_comments(repo, pr_number)
if !duplicate_msg_pattern.empty? || !delete_prev_regex_msg.empty?
comments = github.issue_comments(repo, pr_number)

if check_duplicate_msg == "true"
duplicate = if duplicate_msg_pattern
comments.find { |c| c["body"] =~ Regexp.new(duplicate_msg_pattern) }
else
comments.find { |c| c["body"] == message }
end
if check_duplicate_msg == "true"
duplicate = if !duplicate_msg_pattern.empty?
comments.find { |c| c["body"].match(/#{duplicate_msg_pattern}/) }
else
comments.find { |c| c["body"] == message }
end

if duplicate
puts "The PR already contains this message"
exit(0)
if duplicate
puts "The PR already contains this message"
exit(0)
end
end
end

if delete_prev_regex_msg
comments.each do |comment|
if comment["body"].match(/#{delete_prev_regex_msg}/)
github.delete_comment(repo, comment["id"])
if !delete_prev_regex_msg.empty?
comments.each do |comment|
if comment["body"].match(/#{delete_prev_regex_msg}/)
github.delete_comment(repo, comment["id"])
end
end
end
end
Expand Down