Skip to content

Commit

Permalink
add entrypoint script and dockerfile (#1)
Browse files Browse the repository at this point in the history
* add entrypoint script and dockerfile

Signed-off-by: Ramiro <[email protected]>
  • Loading branch information
rberrelleza authored Mar 17, 2021
1 parent 89b0597 commit 1372ddd
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM ruby:3-slim-buster
RUN gem install octokit
ADD entrypoint.sh /entrypoint.sh
ENTRYPOINT [ "/entrypoint.sh" ]
15 changes: 15 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: "Notify PR"
description: "Send a message to the pull request"
inputs:
message:
description: 'The message'
default: 'Your preview environment is ready'
required: true
runs:
using: "docker"
image: "Dockerfile"
args:
- ${{ inputs.message }}
branding:
color: 'green'
icon: book-open
31 changes: 31 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env ruby
require "octokit"
require "json"

if !ENV["GITHUB_TOKEN"]
puts "Missing GITHUB_TOKEN"
exit(1)
end

if ENV["GITHUB_EVENT_NAME"] != "pull_request"
puts "This action only supports pull_request events."
exit(1)
end

message = ARGV[0]
repo = ENV["GITHUB_REPOSITORY"]

json = File.read(ENV.fetch("GITHUB_EVENT_PATH"))
event = JSON.parse(json)
pr = event["number"]

github = Octokit::Client.new(access_token: ENV["GITHUB_TOKEN"])
comments = github.issue_comments(repo, pr)
exists = comments.find { |c| c["body"] == message }

if exists
puts "Message already exists in the PR"
exit(0)
end

github.add_comment(repo, pr, message)

0 comments on commit 1372ddd

Please sign in to comment.