Skip to content

Commit

Permalink
Basic comment updating with prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
eagraf committed Nov 16, 2020
1 parent c09148a commit bda7b75
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
12 changes: 8 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
name: PR Comment from File
author: Alexander Matheson <[email protected]>
description: Leaves a comment on an open PR based on the contents of a file.
name: PR Comment and Update from File
author: Alexander Matheson <[email protected]> Ethan Graf <[email protected]>
description: Leaves a comment on an open PR based on the contents of a file. If a comment with the right prefix exists, update instead.
branding:
icon: 'message-square'
color: 'black'
inputs:
path:
description: file path
required: true
prefix:
description: comment prefix
required: true
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.path }}
- ${{ inputs.path }}
- ${{ inputs.prefix }}
12 changes: 9 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ if !ENV["GITHUB_TOKEN"]
exit(1)
end

if ARGV.empty?
puts "Missing file path argument."
if ARGV.length < 2
puts "Missing arguments."
exit(1)
end

Expand All @@ -35,11 +35,17 @@ else
pr_number = pr["number"]
end
file_path = ARGV[0]
prefix = ARGV[1]

puts Dir.entries(".")

message = File.read(file_path)

coms = github.issue_comments(repo, pr_number)

github.add_comment(repo, pr_number, message)
com = coms.find { |com| com["body"].start_with?(prefix) }
if com == nil
github.add_comment(repo, pr_number, prefix + "\n\n" + message)
else
com = github.update_comment(repo, com["id"], com["body"] + "\n\n" + message)
end

0 comments on commit bda7b75

Please sign in to comment.