forked from jtarchie/github-pullrequest-resource
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathout.rb
executable file
·42 lines (32 loc) · 1.2 KB
/
out.rb
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env ruby
# encoding: utf-8
destination = ARGV.shift
require 'rubygems'
require 'json'
require_relative 'common'
require 'octokit'
raise %(`status` "#{input['params']['status']}" is not supported -- only success, failure, error, or pending) unless %w(success failure error pending).include?(input['params']['status'])
raise '`path` required in `params`' unless input['params'].key?('path')
path = File.join(destination, input['params']['path'])
raise %(`path` "#{input['params']['path']}" does not exist) unless File.exist?(path)
id = Dir.chdir(path) { `git config --get pullrequest.id`.chomp }
sha = Dir.chdir(path) { `git rev-parse HEAD`.chomp }
repo = Repository.new(name: input['source']['repo'])
metadata = [{ name: 'status', value: input['params']['status'] }]
if id.empty?
version = { ref: sha }
else
pr = repo.pull_request(id: id)
metadata << { name: 'url', value: pr.url }
version = { pr: id, ref: sha }
end
atc_url = input['source']['base_url'] || ENV['ATC_EXTERNAL_URL']
context = input['params']['context'] || 'status'
Status.new(
state: input['params']['status'],
atc_url: atc_url,
sha: sha,
repo: repo,
context: context
).create!
json!(version: version, metadata: metadata)