forked from unnitallman/pr-auto-merge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto_merge_pr.rb
More file actions
27 lines (21 loc) · 860 Bytes
/
auto_merge_pr.rb
File metadata and controls
27 lines (21 loc) · 860 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
require 'octokit'
require_relative 'src/github_graphql'
require_relative 'src/pull_request'
require_relative 'src/enable_pr_auto_merge'
client = Octokit::Client.new(access_token: ENV["GITHUB_TOKEN"])
owner,repo = ENV["GITHUB_REPOSITORY"].split("/")
pr_number = ENV["GITHUB_REF"].split("/")[2].to_i
checks_status = client.status(ENV["GITHUB_REPOSITORY"], ENV["GITHUB_HEAD_REF"])[:state]
# if status checks are still pending
if checks_status == "pending"
pr_id = GithubGraphql::PullRequest.find(owner, repo, pr_number).id
GithubGraphql::EnablePRAutoMerge.mark! pr_id
exit(0)
end
# if status checks have already completed and is successs
if checks_status == "success"
client.merge_pull_request(ENV["GITHUB_REPOSITORY"], pr_number, "", {merge_method: "squash"})
exit(0)
end
puts "Automerge stopped. Please make sure all checks have passed"
exit(1)