Skip to content

Commit

Permalink
Merge pull request #44 from jeffreyguenther/jeff/fix-conditional-args
Browse files Browse the repository at this point in the history
Fix pattern based options
  • Loading branch information
aaronklaassen authored Oct 15, 2021
2 parents ffe8f97 + 9aac0ab commit 4111836
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
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

0 comments on commit 4111836

Please sign in to comment.