git-diff-prs 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 371a4f1e2c5841d1b945f4162e611b272eab1394
4
+ data.tar.gz: 0d2f67520497d9be7c5d5106cbe625d91308d03a
5
+ SHA512:
6
+ metadata.gz: 0f5f9db8284f5eded8e5ee991d5b50ad3aea9e98e90a3966010977c135ee1e368684cf741c3ed5e6bd35c84d439ed5b91ca2f1dcd264b091b60b7a93cbdf43ac
7
+ data.tar.gz: 94c83124d9b970ddc5f60e7eda62a73c200c0b90d27582a406df2cbb917bdff4b3367eb3e0706704071ce8c39562777cbd9ff7ea211139cf7a19fd8c2a40a0fb
@@ -0,0 +1,53 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
51
+
52
+ # IntelliJ
53
+ .idea
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 mitene
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,8 @@
1
+ # git-diff-prs
2
+ A tool to list all the PRs between commits
3
+
4
+ ## Usage
5
+ ```bash
6
+ $ gem install -g git-diff-prs
7
+ $ GITHUB_DIFF_PRS_TOKEN=<token> git-diff-prs v1.0.0..v2.0.0
8
+ ```
@@ -0,0 +1,119 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'open3'
5
+ require 'octokit'
6
+
7
+ # This class represents an item in the list
8
+ class ListItem
9
+ attr_reader :pr # Octokit PR
10
+
11
+ def initialize(pull_request)
12
+ @pr = pull_request
13
+ end
14
+
15
+ def to_checklist
16
+ "- [ ] ##{pr.number} #{pr.title}" + mention
17
+ end
18
+
19
+ def html_link
20
+ pr.rels[:html].href
21
+ end
22
+
23
+ def mention
24
+ mention = if pr.assignee
25
+ "@#{pr.assignee.login}"
26
+ elsif pr.user
27
+ "@#{pr.user.login}"
28
+ end
29
+
30
+ mention ? " #{mention}" : ''
31
+ end
32
+ end
33
+
34
+ def git(*command)
35
+ command = ['git', *command.map(&:to_s)]
36
+ out, status = Open3.capture2(*command)
37
+ unless status.success?
38
+ raise "Failed to execute `#{command.join(' ')}`: #{status}"
39
+ end
40
+
41
+ out.each_line
42
+ end
43
+
44
+ def repository
45
+ @repository ||= begin
46
+ remote = git(:config, 'remote.origin.url').first.chomp
47
+
48
+ remote_url = URI.parse(remote)
49
+ remote_url.path.sub(%r{^/}, '').sub(/\.git$/, '')
50
+ end
51
+ end
52
+
53
+ def obtain_token!
54
+ ENV.fetch('GITHUB_DIFF_PRS_TOKEN')
55
+ end
56
+
57
+ def parse_args!
58
+ if ARGV.empty? || ARGV.size > 1
59
+ puts 'Usage: git-diff-prs old_commit..new_commit'
60
+ exit 1
61
+ end
62
+
63
+ diff = ARGV[0]
64
+
65
+ verify_diff!(diff)
66
+
67
+ diff
68
+ end
69
+
70
+ def verify_diff!(diff)
71
+ diffs = diff.split('..')
72
+ raise 'Usage: git-diff-prs old_commit..new_commit' unless diffs.size == 2
73
+
74
+ diffs.each { |ref| raise "Invalid ref: #{ref}" unless verify_ref(ref) }
75
+ rescue StandardError => e
76
+ puts e
77
+ exit 1
78
+ end
79
+
80
+ def verify_ref(ref)
81
+ git(:show, ref)
82
+ true
83
+ rescue StandardError
84
+ false
85
+ end
86
+
87
+ def fetch_merge_commits(diff)
88
+ git(:log, '--merges', '--pretty=format:%P', diff.to_s).map do |l|
89
+ _, sha1 = l.chomp.split(/\s+/)
90
+ sha1
91
+ end
92
+ end
93
+
94
+ def fetch_pr_numbers(merge_sha1s)
95
+ git('ls-remote', 'origin', 'refs/pull/*/head').map do |l|
96
+ sha1, ref = l.chomp.split(/\s+/)
97
+ next unless merge_sha1s.include? sha1
98
+
99
+ m = ref.match(%r{^refs/pull/(?<pr_num>\d+)/head$})
100
+ m && m[:pr_num]
101
+ end.compact
102
+ end
103
+
104
+ def main
105
+ diff = parse_args!
106
+ client = Octokit::Client.new access_token: obtain_token!
107
+
108
+ merge_sha1s = fetch_merge_commits(diff)
109
+
110
+ merge_pr_numbers = fetch_pr_numbers(merge_sha1s)
111
+
112
+ checklists = merge_pr_numbers
113
+ .map { |prn| client.pull_request(repository, prn) }
114
+ .map { |pr| ListItem.new(pr).to_checklist }
115
+
116
+ puts checklists
117
+ end
118
+
119
+ main
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'git-diff-prs'
8
+ spec.version = '0.0.1'
9
+ spec.authors = ['hkurokawa']
10
+ spec.email = ['hirosh.kurokawa@gmail.com']
11
+ spec.summary = 'List up pull requests between the commits'
12
+ spec.description = 'git-diff-prs lists up all the pull requests between the specified commits'
13
+ spec.homepage = 'https://github.com/mitene/git-diff-prs'
14
+
15
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_dependency 'octokit', '~> 0'
21
+
22
+ spec.license = 'MIT'
23
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git-diff-prs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - hkurokawa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-01-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: octokit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: git-diff-prs lists up all the pull requests between the specified commits
28
+ email:
29
+ - hirosh.kurokawa@gmail.com
30
+ executables:
31
+ - git-diff-prs
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - LICENSE
37
+ - README.md
38
+ - bin/git-diff-prs
39
+ - git-diff-prs.gemspec
40
+ homepage: https://github.com/mitene/git-diff-prs
41
+ licenses:
42
+ - MIT
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.5.2.3
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: List up pull requests between the commits
64
+ test_files: []