gh-pr-backport 0.1.0.alpha2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +14 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +6 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +72 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/gh-pr-backport +6 -0
- data/gh-pr-backport.gemspec +30 -0
- data/lib/gh_pr_backport/backporter.rb +105 -0
- data/lib/gh_pr_backport/version.rb +3 -0
- data/lib/gh_pr_backport.rb +11 -0
- metadata +158 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5d1c05225c80e6b714a85021a0918e18c050a5cde87251b1c6818b0f80e26ef0
|
4
|
+
data.tar.gz: 940d33dba73c8c043604a868bcea44269f4f19d14c11474c64650bf2acd61721
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d3be7947fd595a682d309db9b1c236df2ec94239ca238db3f06aec9b0fae93173941191960362b8ffaa1fa0dfad1b1ae703b32d3cb1215bf044f6a99b268c1af
|
7
|
+
data.tar.gz: 307f651897173c79379ba41aa4b8b64043aec1127c7e76f3592f0e310e39a43806c45e919ea55b8cc13fb0383025fcad6e50b537284c5f722e7145560d81d20b
|
data/.editorconfig
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
gh-pr-backport (0.1.0.alpha2)
|
5
|
+
hashie (~> 3.5, >= 3.5.7)
|
6
|
+
octokit (~> 4.8, >= 4.8.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.5.2)
|
12
|
+
public_suffix (>= 2.0.2, < 4.0)
|
13
|
+
ast (2.4.0)
|
14
|
+
diff-lcs (1.3)
|
15
|
+
faraday (0.14.0)
|
16
|
+
multipart-post (>= 1.2, < 3)
|
17
|
+
hashie (3.5.7)
|
18
|
+
multipart-post (2.0.0)
|
19
|
+
octokit (4.8.0)
|
20
|
+
sawyer (~> 0.8.0, >= 0.5.3)
|
21
|
+
onkcop (0.52.1.1)
|
22
|
+
rubocop (~> 0.52.1)
|
23
|
+
rubocop-rspec (>= 1.22.0)
|
24
|
+
parallel (1.12.1)
|
25
|
+
parser (2.5.1.0)
|
26
|
+
ast (~> 2.4.0)
|
27
|
+
powerpack (0.1.1)
|
28
|
+
public_suffix (3.0.2)
|
29
|
+
rainbow (3.0.0)
|
30
|
+
rake (10.5.0)
|
31
|
+
rspec (3.7.0)
|
32
|
+
rspec-core (~> 3.7.0)
|
33
|
+
rspec-expectations (~> 3.7.0)
|
34
|
+
rspec-mocks (~> 3.7.0)
|
35
|
+
rspec-core (3.7.1)
|
36
|
+
rspec-support (~> 3.7.0)
|
37
|
+
rspec-expectations (3.7.0)
|
38
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
+
rspec-support (~> 3.7.0)
|
40
|
+
rspec-mocks (3.7.0)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.7.0)
|
43
|
+
rspec-support (3.7.1)
|
44
|
+
rubocop (0.52.1)
|
45
|
+
parallel (~> 1.10)
|
46
|
+
parser (>= 2.4.0.2, < 3.0)
|
47
|
+
powerpack (~> 0.1)
|
48
|
+
rainbow (>= 2.2.2, < 4.0)
|
49
|
+
ruby-progressbar (~> 1.7)
|
50
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
51
|
+
rubocop-codetakt (0.8.2)
|
52
|
+
onkcop (= 0.52.1.1)
|
53
|
+
rubocop-rspec (1.23.0)
|
54
|
+
rubocop (>= 0.52.1)
|
55
|
+
ruby-progressbar (1.9.0)
|
56
|
+
sawyer (0.8.1)
|
57
|
+
addressable (>= 2.3.5, < 2.6)
|
58
|
+
faraday (~> 0.8, < 1.0)
|
59
|
+
unicode-display_width (1.3.0)
|
60
|
+
|
61
|
+
PLATFORMS
|
62
|
+
ruby
|
63
|
+
|
64
|
+
DEPENDENCIES
|
65
|
+
bundler (~> 1.16)
|
66
|
+
gh-pr-backport!
|
67
|
+
rake (~> 10.0)
|
68
|
+
rspec (~> 3.0)
|
69
|
+
rubocop-codetakt (~> 0.8.2)
|
70
|
+
|
71
|
+
BUNDLED WITH
|
72
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Takeru Naito
|
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,39 @@
|
|
1
|
+
# gh-pr-backport
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gh-pr-backport`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'gh-pr-backport'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install gh-pr-backport
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at <https://github.com/elim/gh-pr-backport>.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://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 'gh_pr_backport'
|
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
data/exe/gh-pr-backport
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gh_pr_backport/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'gh-pr-backport'
|
8
|
+
spec.version = GhPrBackport::VERSION
|
9
|
+
spec.authors = ['Takeru Naito']
|
10
|
+
spec.email = ['takeru.naito@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Create a backport Pull Request.'
|
13
|
+
spec.description = 'Create a backport PR from existing PR to a specific branch.'
|
14
|
+
spec.homepage = 'https://github.com/elim/gh-pr-backport'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
27
|
+
spec.add_development_dependency 'rubocop-codetakt', '~> 0.8.2'
|
28
|
+
spec.add_runtime_dependency 'hashie', '~> 3.5', '>= 3.5.7'
|
29
|
+
spec.add_runtime_dependency 'octokit', '~> 4.8', '>= 4.8.0'
|
30
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
require 'hashie'
|
4
|
+
require 'octokit'
|
5
|
+
|
6
|
+
module GhPrBackport
|
7
|
+
class Backporter
|
8
|
+
def initialize(original_pr_number:, staging_branch: nil)
|
9
|
+
@client = client
|
10
|
+
@repo = repo
|
11
|
+
@original = original(original_pr_number)
|
12
|
+
|
13
|
+
@backport_branch = backport_branch
|
14
|
+
@staging_branch = staging_branch || read_staging_branch_from_config
|
15
|
+
end
|
16
|
+
|
17
|
+
def backport
|
18
|
+
raise GhPrBackport::DirectoryIsMessy unless clean?
|
19
|
+
checkout_backport_branch
|
20
|
+
cherry_pick
|
21
|
+
push
|
22
|
+
create_backport_pull_request
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def backport_branch
|
28
|
+
"bp/#{@original.branch}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def checkout_backport_branch
|
32
|
+
system!("git checkout -b #{@backport_branch} origin/#{@staging_branch}",
|
33
|
+
GhPrBackport::BranchCheckoutFailed)
|
34
|
+
end
|
35
|
+
|
36
|
+
def cherry_pick
|
37
|
+
@original.commits.each do |commit|
|
38
|
+
system!("git cherry-pick -x #{commit}", GhPrBackport::CherryPickFailed)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def client
|
43
|
+
client = Octokit::Client.new(access_token: `git config backport.token`.chomp)
|
44
|
+
client.scopes # Validate token. If the token is invalid, then raise an error.
|
45
|
+
client
|
46
|
+
end
|
47
|
+
|
48
|
+
def clean?
|
49
|
+
`git status --porcelain`.chomp.empty?
|
50
|
+
end
|
51
|
+
|
52
|
+
def create_backport_pull_request
|
53
|
+
body = "##{@original.number} のバックポートです\r\n\r\n" +
|
54
|
+
@original.body.lines.map { |l| "> #{l}" }.join
|
55
|
+
pr = client.create_pull_request(@repo,
|
56
|
+
@staging_branch,
|
57
|
+
@backport_branch,
|
58
|
+
@original.title, body)
|
59
|
+
client.add_assignees(repo, pr.number, [@original.user])
|
60
|
+
client.add_labels_to_an_issue(repo, pr.number, @original.labels)
|
61
|
+
end
|
62
|
+
|
63
|
+
def fetch
|
64
|
+
system!('git fetch', GhPrBackport::FetchFailed)
|
65
|
+
end
|
66
|
+
|
67
|
+
def original(number)
|
68
|
+
original = client.pull_request(@repo, number)
|
69
|
+
|
70
|
+
Hashie::Mash.new({
|
71
|
+
number: original.number,
|
72
|
+
branch: original.head.ref,
|
73
|
+
user: original.user.login,
|
74
|
+
title: original.title,
|
75
|
+
body: original.body,
|
76
|
+
labels: original.labels.map(&:name),
|
77
|
+
commits: client.pull_request_commits(@repo, original.number).map(&:sha)
|
78
|
+
})
|
79
|
+
end
|
80
|
+
|
81
|
+
def push
|
82
|
+
system!('git push origin HEAD', GhPrBackport::PushFailed)
|
83
|
+
end
|
84
|
+
|
85
|
+
def read_staging_branch_from_config
|
86
|
+
path = './' + `git rev-parse --show-cdup`.chomp
|
87
|
+
`git config -f #{path}/.git-pr-release pr-release.branch.staging`.chomp
|
88
|
+
end
|
89
|
+
|
90
|
+
def repo
|
91
|
+
remote = `git config remote.origin.url`.chomp
|
92
|
+
repo_name = if remote.start_with?('git@github.com:')
|
93
|
+
remote.split(':', 2)[1].sub(/.git$/, '')
|
94
|
+
else
|
95
|
+
URI.parse(remote).path.sub(%r{^\/}, '').sub(/.git$/, '')
|
96
|
+
end
|
97
|
+
Octokit::Repository.new(repo_name)
|
98
|
+
end
|
99
|
+
|
100
|
+
def system!(program, *args, error_class)
|
101
|
+
raise error_class unless system(program, *args)
|
102
|
+
true
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'gh_pr_backport/version'
|
2
|
+
|
3
|
+
module GhPrBackport
|
4
|
+
class BranchCheckoutFailed < StandardError; end
|
5
|
+
class CherryPickFailed < StandardError; end
|
6
|
+
class DirectoryIsMessy < StandardError; end
|
7
|
+
class FetchFailed < StandardError; end
|
8
|
+
class PushFailed < StandardError; end
|
9
|
+
|
10
|
+
autoload :Backporter, 'gh_pr_backport/backporter'
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gh-pr-backport
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.alpha2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Takeru Naito
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-16 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.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
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: rubocop-codetakt
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.8.2
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.8.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: hashie
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.5'
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 3.5.7
|
79
|
+
type: :runtime
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - "~>"
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '3.5'
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 3.5.7
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: octokit
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '4.8'
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: 4.8.0
|
99
|
+
type: :runtime
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - "~>"
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '4.8'
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 4.8.0
|
109
|
+
description: Create a backport PR from existing PR to a specific branch.
|
110
|
+
email:
|
111
|
+
- takeru.naito@gmail.com
|
112
|
+
executables:
|
113
|
+
- gh-pr-backport
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files: []
|
116
|
+
files:
|
117
|
+
- ".editorconfig"
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".rubocop.yml"
|
121
|
+
- ".travis.yml"
|
122
|
+
- Gemfile
|
123
|
+
- Gemfile.lock
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- bin/console
|
128
|
+
- bin/setup
|
129
|
+
- exe/gh-pr-backport
|
130
|
+
- gh-pr-backport.gemspec
|
131
|
+
- lib/gh_pr_backport.rb
|
132
|
+
- lib/gh_pr_backport/backporter.rb
|
133
|
+
- lib/gh_pr_backport/version.rb
|
134
|
+
homepage: https://github.com/elim/gh-pr-backport
|
135
|
+
licenses:
|
136
|
+
- MIT
|
137
|
+
metadata: {}
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">"
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: 1.3.1
|
152
|
+
requirements: []
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 2.7.3
|
155
|
+
signing_key:
|
156
|
+
specification_version: 4
|
157
|
+
summary: Create a backport Pull Request.
|
158
|
+
test_files: []
|