github_merge_sign 0.1.0.test1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +14 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +52 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/github_merge_sign +16 -0
- data/github_merge_sign.gemspec +27 -0
- data/lib/github_merge_sign.rb +155 -0
- data/lib/github_merge_sign/version.rb +3 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 965d192be559837d1c33bf0446c061fe8710c7de
|
4
|
+
data.tar.gz: c2e14563d0dcfc71f026778f1034d8dc5f07ece0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8cec48d6c868020d8ddfcdfa10fc17e027cab32a6b9d6a2b856ba41c662f2bae5a1f132079026a634c91522e9707b544a7d82ce3ef567b3d05a54cec54927f90
|
7
|
+
data.tar.gz: '05848c40cb6c49357222826c808200d342f4d1643240818cb6db03c51c91af0feff794bb8be22a76cc2500c34af8a4c72323d2e465c8dcf8fbb3fa2a64933bb0'
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
sudo: false
|
2
|
+
language: ruby
|
3
|
+
rvm:
|
4
|
+
- "2.3"
|
5
|
+
- "2.4"
|
6
|
+
deploy:
|
7
|
+
provider: rubygems
|
8
|
+
api_key:
|
9
|
+
secure: L/mmeonwxNIiMqHs1o2gw47jJOXHFChTbBxfy3anW/TFi5EipybyBXrT7dikUqgzYpzVdiomLEvJjIeR0hlt3oBGaCddpGaXF/2keEeSpOB2xhpCZIIFnUN+5g3VgVHiU5yC1SeKZzxyoA1UocHl+q0wXAcmeHhKgNpVjp98MxwLGos85BkLbqiIx8PG5nM3QWF//uVm8tO0ISkGT0inuPfNa/OThHDyHdZ1a6AqpbZHecZm1yd9FE3KkwGTQMftKrrMh/Ttv6ACCS8b6fu2x9gO+JyslJNX0D+o3rirjEgfdJqXKNmEl4vCPrzx4mpuKSamvWVNtE4ZgCoM7c8f+qHbvSCC5FyXUqPYWqsGfYma1eqsV/yMtWZCCbrUHysWoMs6F5f3+JdBWajEM8BqkvGgCJTtGQLOj6HfbvXXfDyXkMiFU/kTuDaZRD4BAKy870THLpj51jDG0fpWGdUNJVUloF6o1tOqRARBNPXmrKMWCP1fjz5irXvX9wyZpaAwOTBkQLlLUHdDRcXcRiwY5dkxUhzBXB6OcOqRLYUuP/okrgaQghK7cGv7SD/0T3+Zwie6uFgkSn7kAxfWwUHGb74yO+MbIXvDxxhKHKBvPMKOraSDUrL8Uu98UD79Jdlgn70GD/xZS5hSe9Sbmg/Irn3BNu2fBA0eEyd0LwejG6w=
|
10
|
+
gem: github_merge_sign
|
11
|
+
on:
|
12
|
+
tags: true
|
13
|
+
# pin to a ruby version to prevent multiple publish attempts.
|
14
|
+
ruby: "2.4"
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Crown Copyright (Government Digital Service)
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Github Merge & Sign
|
2
|
+
|
3
|
+
This is a tool to merge and GPG sign a github pull-request. This replicates the
|
4
|
+
functionality of the Github merge button, adding GPG signing.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'github_merge_sign'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install github_merge_sign
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
To merge a github PR first change directory to a local checkout of the repo,
|
25
|
+
and then run (where N is the github PR number):
|
26
|
+
|
27
|
+
$ bundle exec github_merge_sign --pr N
|
28
|
+
|
29
|
+
## Development
|
30
|
+
|
31
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
32
|
+
|
33
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
34
|
+
|
35
|
+
This gem is versioned following [Semantic Versioning](http://semver.org/) as
|
36
|
+
described in the [GDS rubygems
|
37
|
+
styleguide](https://github.com/alphagov/styleguides/blob/master/rubygems.md#versioning).
|
38
|
+
To release a new version, update the version number in
|
39
|
+
`lib/github_merge_sign/version.rb`, update `CHANGELOG.md` and create a PR for
|
40
|
+
this version change.
|
41
|
+
|
42
|
+
Once this PR is merged, tag the merge commit with the version number, and push
|
43
|
+
the tag. This will cause Travis to build and publish the gem to
|
44
|
+
[rubygems.org](https://rubygems.org).
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/alphagov/paas-github_merge_sign.
|
49
|
+
|
50
|
+
## License
|
51
|
+
|
52
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "github_merge_sign"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "optparse"
|
4
|
+
require "github_merge_sign"
|
5
|
+
|
6
|
+
pr_number = 0
|
7
|
+
option_parser = OptionParser.new do |opts|
|
8
|
+
opts.on('--pr number', Integer) do |value|
|
9
|
+
pr_number = value
|
10
|
+
end
|
11
|
+
end
|
12
|
+
option_parser.parse!
|
13
|
+
|
14
|
+
abort "Must specify PR number" unless pr_number > 0
|
15
|
+
|
16
|
+
GithubMergeSign::PullRequest.new(pr_number).merge!
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'github_merge_sign/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "github_merge_sign"
|
8
|
+
spec.version = GithubMergeSign::VERSION
|
9
|
+
spec.authors = ["Government Digital Service"]
|
10
|
+
|
11
|
+
spec.summary = %q{Tool to merge and GPG sign a github PR.}
|
12
|
+
spec.description = %q{Tool to merge and GPG sign a github PR. This replicates the functionality of the Github merge button, adding GPG signing.}
|
13
|
+
spec.homepage = "https://github.com/alphagov/paas-github_merge_sign"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
spec.add_development_dependency "webmock", "~> 3.0"
|
27
|
+
end
|
@@ -0,0 +1,155 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
require "github_merge_sign/version"
|
6
|
+
|
7
|
+
module GithubMergeSign
|
8
|
+
class PullRequest
|
9
|
+
BASE_URL = 'https://api.github.com/repos'.freeze
|
10
|
+
|
11
|
+
def initialize(pr_number)
|
12
|
+
@pr_number = pr_number
|
13
|
+
end
|
14
|
+
|
15
|
+
def repo
|
16
|
+
@repo ||= read_repo_from_git
|
17
|
+
end
|
18
|
+
|
19
|
+
def open?
|
20
|
+
details.fetch("state") == "open"
|
21
|
+
end
|
22
|
+
|
23
|
+
def mergeable?
|
24
|
+
!! details.fetch("mergeable")
|
25
|
+
end
|
26
|
+
|
27
|
+
def status_checks_passed?
|
28
|
+
status.fetch("state") == "success" || status.fetch("statuses").empty?
|
29
|
+
end
|
30
|
+
|
31
|
+
def external_pr?
|
32
|
+
details.fetch("base").fetch("repo").fetch("full_name") !=
|
33
|
+
details.fetch("head").fetch("repo").fetch("full_name")
|
34
|
+
end
|
35
|
+
|
36
|
+
def target_branch
|
37
|
+
details.fetch("base").fetch("ref")
|
38
|
+
end
|
39
|
+
|
40
|
+
def head_commit_id
|
41
|
+
details.fetch("head").fetch("sha")
|
42
|
+
end
|
43
|
+
|
44
|
+
def head_ref
|
45
|
+
details.fetch("head").fetch("ref")
|
46
|
+
end
|
47
|
+
|
48
|
+
def commit_message
|
49
|
+
<<-EOT
|
50
|
+
Merge pull request ##{@pr_number} from #{details.fetch('head').fetch('user').fetch('login')}/#{head_ref}
|
51
|
+
|
52
|
+
#{details.fetch('title')}
|
53
|
+
EOT
|
54
|
+
end
|
55
|
+
|
56
|
+
def merge!
|
57
|
+
raise "PR is not open" unless open?
|
58
|
+
raise "PR is not mergeable" unless mergeable?
|
59
|
+
raise "PR has not passed all status checks" unless status_checks_passed?
|
60
|
+
|
61
|
+
# Check working directorty is clean
|
62
|
+
unless Kernel.system('git diff --quiet --exit-code HEAD')
|
63
|
+
raise "Working directory is not clean. Aborting..."
|
64
|
+
end
|
65
|
+
|
66
|
+
info "Checking out and updating #{target_branch}"
|
67
|
+
execute_command("git checkout #{target_branch}")
|
68
|
+
execute_command("git pull --ff-only origin #{target_branch}")
|
69
|
+
|
70
|
+
if external_pr?
|
71
|
+
info "Fetching commits from PR #{@pr_number}"
|
72
|
+
execute_command("git fetch origin refs/pull/#{@pr_number}/head")
|
73
|
+
end
|
74
|
+
|
75
|
+
info "Merging PR with commit message:\n#{commit_message}"
|
76
|
+
execute_command('git', 'merge', '--no-ff', '-S', '-m', commit_message, head_commit_id)
|
77
|
+
|
78
|
+
info "Pushing to origin"
|
79
|
+
execute_command("git push origin #{target_branch}")
|
80
|
+
|
81
|
+
unless external_pr?
|
82
|
+
info "Deleting remote branch #{head_ref}"
|
83
|
+
execute_command("git push origin :#{head_ref}")
|
84
|
+
end
|
85
|
+
|
86
|
+
info "Done."
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
def read_repo_from_git
|
92
|
+
details = `git remote -v`
|
93
|
+
unless $?.success?
|
94
|
+
raise "Error reading git remotes: exit status #{$?.exitstatus}."
|
95
|
+
end
|
96
|
+
details.each_line do |line|
|
97
|
+
line.strip!
|
98
|
+
if line =~ /\Aorigin\t(\S+)\s+\(fetch\)\z/
|
99
|
+
url = $1
|
100
|
+
if url =~ /\A(?:https:\/\/|git@)github\.com[\/:](\S+?)(?:\.git)?\z/
|
101
|
+
return $1
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
raise "origin is not a Github URL"
|
106
|
+
end
|
107
|
+
|
108
|
+
def execute_command(*args)
|
109
|
+
unless Kernel.system(*args)
|
110
|
+
raise "Error: command '#{args.join(' ')}' exited #{$?.exitstatus}."
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def details
|
115
|
+
@_details ||= get_json("#{BASE_URL}/#{repo}/pulls/#{@pr_number}")
|
116
|
+
end
|
117
|
+
|
118
|
+
def status
|
119
|
+
url = "#{BASE_URL}/#{repo}/commits/#{head_commit_id}/status"
|
120
|
+
@_status ||= get_json(url)
|
121
|
+
end
|
122
|
+
|
123
|
+
def get_json(url)
|
124
|
+
response = http_get(url)
|
125
|
+
if response.is_a?(Net::HTTPForbidden) && response.body =~ /API rate limit exceeded for/
|
126
|
+
raise "Github rate-limit exceeded. To avoid this create a Github API token with public access and put it in GITHUB_API_TOKEN env var."
|
127
|
+
end
|
128
|
+
|
129
|
+
unless response.is_a?(Net::HTTPSuccess)
|
130
|
+
raise "Failed to fetch PR details.\nGot #{response.code} fetching '#{url}':\n#{response.body}"
|
131
|
+
end
|
132
|
+
|
133
|
+
JSON.parse(response.body)
|
134
|
+
end
|
135
|
+
|
136
|
+
def http_get(url)
|
137
|
+
uri = URI.parse(url)
|
138
|
+
if ENV["GITHUB_API_TOKEN"]
|
139
|
+
uri.query = [uri.query, "access_token=#{ENV['GITHUB_API_TOKEN']}"].compact.join('&')
|
140
|
+
end
|
141
|
+
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
|
142
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
143
|
+
return http.request(request)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def info(message)
|
148
|
+
if $stdout.isatty
|
149
|
+
puts "\e[36m#{message}\e[0m"
|
150
|
+
else
|
151
|
+
puts message
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: github_merge_sign
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.test1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Government Digital Service
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-06-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: Tool to merge and GPG sign a github PR. This replicates the functionality
|
70
|
+
of the Github merge button, adding GPG signing.
|
71
|
+
email:
|
72
|
+
executables:
|
73
|
+
- github_merge_sign
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".travis.yml"
|
80
|
+
- CHANGELOG.md
|
81
|
+
- Gemfile
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- bin/console
|
86
|
+
- bin/setup
|
87
|
+
- exe/github_merge_sign
|
88
|
+
- github_merge_sign.gemspec
|
89
|
+
- lib/github_merge_sign.rb
|
90
|
+
- lib/github_merge_sign/version.rb
|
91
|
+
homepage: https://github.com/alphagov/paas-github_merge_sign
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">"
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 1.3.1
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.5.2
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Tool to merge and GPG sign a github PR.
|
115
|
+
test_files: []
|