diff --git a/action.yml b/action.yml index d8537d5..d6544e6 100644 --- a/action.yml +++ b/action.yml @@ -1,6 +1,6 @@ -name: PR Comment from File -author: Alexander Matheson -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 Ethan Graf +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' @@ -8,8 +8,12 @@ inputs: path: description: file path required: true + prefix: + description: comment prefix + required: true runs: using: 'docker' image: 'Dockerfile' args: - - ${{ inputs.path }} \ No newline at end of file + - ${{ inputs.path }} + - ${{ inputs.prefix }} \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh index eadd404..497a900 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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 @@ -35,6 +35,7 @@ else pr_number = pr["number"] end file_path = ARGV[0] +prefix = ARGV[1] puts Dir.entries(".") @@ -42,4 +43,9 @@ 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