Skip to content

Commit

Permalink
Update entrypoint.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
tselmegbaasan authored Feb 5, 2021
1 parent d3971ec commit 6231541
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion actions-a/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,52 @@
#!/bin/sh -l

#!/usr/bin/env ruby

require "json"
require "octokit"

json = File.read(ENV.fetch("GITHUB_EVENT_PATH"))
event = JSON.parse(json)

github = Octokit::Client.new(access_token: ENV["GITHUB_TOKEN"])

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

if ARGV[0].empty?
puts "Missing message argument."
exit(1)
end

message = ARGV[0]
check_duplicate_msg = ARGV[1]
repo = event["repository"]["full_name"]

if ENV.fetch("GITHUB_EVENT_NAME") == "pull_request"
pr_number = event["number"]
else
pulls = github.pull_requests(repo, state: "open")

push_head = event["after"]
pr = pulls.find { |pr| pr["head"]["sha"] == push_head }

if !pr
puts "Couldn't find an open pull request for branch with head at #{push_head}."
exit(1)
end
pr_number = pr["number"]
end

coms = github.issue_comments(repo, pr_number)

if check_duplicate_msg == "true"
duplicate = coms.find { |c| c["body"] == message }

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

github.add_comment(repo, pr_number, message)

0 comments on commit 6231541

Please sign in to comment.