github_changes 0.1.3 → 0.1.4
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 +4 -4
- data/lib/changelog_generator/generator.rb +71 -102
- data/lib/changelog_generator/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94912ce0c80830df446d4c1f4f208cd95fbce796
|
4
|
+
data.tar.gz: f042745d4af0080470e14265c2054c3e1838817c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52f0250a50a59ae3ddf098e08627bf1b124b09fb00807011588b7279e2ddd295d648d6f0f0832d5c64b6563403db6e53b338be25bc11582822e6a9043c1d03e2
|
7
|
+
data.tar.gz: 1e5fe29d5ea2b09e16673fe20d64fa5e0ed8a9f045b4da89f7e2b1f37a26a5126b425e821cacc26090dd78ff170fcdce1509842515ba408875f1572589ba3dd3
|
@@ -28,47 +28,91 @@ module ChangelogGenerator
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def changelog
|
31
|
-
generate_changelog(user, repo_name, from_ref, to_ref, label_filter
|
31
|
+
generate_changelog(user, repo_name, from_ref, to_ref, label_filter)
|
32
32
|
end
|
33
33
|
|
34
34
|
private
|
35
35
|
|
36
|
-
def
|
37
|
-
|
36
|
+
def run(cmd)
|
37
|
+
# puts "Running: #{cmd}"
|
38
|
+
`#{cmd}`
|
39
|
+
end
|
40
|
+
|
41
|
+
def clone_or_fetch_repo(user, repo, path)
|
42
|
+
output = nil
|
43
|
+
|
44
|
+
if Dir.exist? path
|
45
|
+
output = run "cd #{path} && git fetch"
|
46
|
+
else
|
47
|
+
output = run "git clone --bare \"https://#{ENV['GITHUB_TOKEN']}@github.com/#{user}/#{repo}.git\" \"#{path}\""
|
48
|
+
end
|
49
|
+
|
50
|
+
unless $?.exitstatus == 0
|
38
51
|
abort "Unable to access repo `#{user}/#{repo}`. Please ensure correct spelling. If this repo is private you must ensure to configure me with a suitable GitHub oath token."
|
39
52
|
end
|
40
|
-
|
41
|
-
|
42
|
-
|
53
|
+
|
54
|
+
output
|
55
|
+
end
|
56
|
+
|
57
|
+
def is_ref?(ref)
|
58
|
+
return false unless ref !~ /^\s*$/
|
59
|
+
run "git show \"#{ref}\""
|
60
|
+
$?.exitstatus == 0
|
61
|
+
end
|
62
|
+
|
63
|
+
def ref_before(date_string)
|
64
|
+
output = run("git rev-list -1 --all --before=\"#{date_string}\"").chomp
|
65
|
+
$?.exitstatus == 0 ? output : nil
|
66
|
+
end
|
67
|
+
|
68
|
+
def ref_after(date_string)
|
69
|
+
output = run("git rev-list --all --after=\"#{date_string}\" | tail -1").chomp
|
70
|
+
$?.exitstatus == 0 ? output : nil
|
71
|
+
end
|
72
|
+
|
73
|
+
def find_ref(string)
|
74
|
+
return string if is_ref? string
|
75
|
+
string = yield(string)
|
76
|
+
is_ref?(string) ? string : nil
|
77
|
+
end
|
78
|
+
|
79
|
+
def find_shas_or_abort(start_ref, end_ref)
|
80
|
+
start_sha = find_ref(start_ref) { |s| ref_after(s) }
|
81
|
+
end_sha = find_ref(end_ref) { |s| ref_before(s) }
|
82
|
+
|
83
|
+
unless start_sha
|
43
84
|
abort "Unable to parse `#{start_ref}` as a reference or date. Please specify a git tag, branch, or SHA. You can also specify a date like `last week` or `5 days ago`"
|
44
85
|
end
|
45
|
-
unless
|
86
|
+
unless end_sha
|
46
87
|
abort "Unable to parse `#{end_ref}` as a reference or date. Please specify a git tag, branch, or SHA. You can also specify a date like `last week` or `5 days ago` or `January 1, 1999`"
|
47
88
|
end
|
48
|
-
pulls = pull_requests_for_date_range(start_date, end_date)
|
49
|
-
pull_nums = pulls.map { |p| p['number'] }
|
50
89
|
|
51
|
-
|
52
|
-
|
53
|
-
else
|
54
|
-
# puts " PRs: #{pull_nums}"
|
55
|
-
# puts
|
56
|
-
end
|
90
|
+
return start_sha, end_sha
|
91
|
+
end
|
57
92
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
label_names.include?(label_filter)
|
64
|
-
end
|
65
|
-
# puts " PRs: #{pull_nums}"
|
66
|
-
# puts
|
67
|
-
end
|
93
|
+
def pull_request_numbers(start_sha, end_sha)
|
94
|
+
log_command = "git log #{start_sha}..#{end_sha}"
|
95
|
+
log = `#{log_command} --grep "Merge pull" --reverse | grep "Merge pull request #"`
|
96
|
+
pull_nums = log.split("\n").map { |p| p.match(/.*#(\d+) .*/)[1].to_i }
|
97
|
+
end
|
68
98
|
|
69
|
-
|
70
|
-
|
99
|
+
def filter_prs_by_label(github, user, repo, pull_nums, label_filter)
|
100
|
+
pull_nums.select do |n|
|
101
|
+
issue = github.issues.get user, repo, n
|
102
|
+
label_names = issue.labels.map { |l| l.name }
|
103
|
+
label_names.include?(label_filter)
|
71
104
|
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def generate_changelog(user, repo, start_ref, end_ref, label_filter = nil)
|
108
|
+
path = Dir.tmpdir + "/#{user}/#{repo}.git"
|
109
|
+
|
110
|
+
clone_or_fetch_repo(user, repo, path)
|
111
|
+
FileUtils.cd(path) # Below methods assuming we are in git repo
|
112
|
+
start_sha, end_sha = find_shas_or_abort(start_ref, end_ref)
|
113
|
+
pull_nums = pull_request_numbers(start_sha, end_sha)
|
114
|
+
pull_nums = filter_prs_by_label(github, user, repo, pull_nums, label_filter) if label_filter
|
115
|
+
abort "No PRs found matching criteria" if pull_nums.empty?
|
72
116
|
|
73
117
|
pulls = pull_nums.map { |p| github.pull_requests.get(user, repo, p) }
|
74
118
|
pulls = pulls.map { |p| PullRequest.from_github_pr(p) }
|
@@ -137,80 +181,5 @@ module ChangelogGenerator
|
|
137
181
|
|
138
182
|
body.scan(/((connect|connects|fix|fixes|address|addresses):?\s*(to)?:?\s*#(?<number>\d+))/im).reject(&:nil?).map(&:last).flatten
|
139
183
|
end
|
140
|
-
|
141
|
-
def date_from_commit(commit)
|
142
|
-
return nil unless commit
|
143
|
-
date = commit["committer"]["date"]
|
144
|
-
date = Chronic.parse(date)
|
145
|
-
end
|
146
|
-
|
147
|
-
def find_commit_for_reference(ref)
|
148
|
-
return nil unless ref && ref["object"] && ref["object"]["sha"]
|
149
|
-
sha = ref["object"]["sha"]
|
150
|
-
commit = check_github_response() { github.git_data.commits.get user, repo_name, URI::encode(sha) }
|
151
|
-
unless commit
|
152
|
-
tag = check_github_response() { github.git_data.tags.get user, repo_name, URI::encode(sha) }
|
153
|
-
sha = (tag && tag.object) ? tag.object.sha : nil
|
154
|
-
commit = check_github_response() { github.git_data.commits.get user, repo_name, URI::encode(sha) } if sha
|
155
|
-
end
|
156
|
-
commit
|
157
|
-
end
|
158
|
-
|
159
|
-
def find_reference_for_string(ref)
|
160
|
-
reference = check_github_response() { github.git_data.references.get user, repo_name, URI::encode("heads/#{ref}") }
|
161
|
-
reference ||= check_github_response() { github.git_data.references.get user, repo_name, URI::encode("tags/#{ref}") }
|
162
|
-
reference
|
163
|
-
end
|
164
|
-
|
165
|
-
def find_commit_for_string(string)
|
166
|
-
reference = find_reference_for_string(string)
|
167
|
-
return find_commit_for_reference(reference) if reference
|
168
|
-
check_github_response() { github.git_data.commits.get user, repo_name, URI::encode(string) }
|
169
|
-
end
|
170
|
-
|
171
|
-
def date_range_for_references(ref_one, ref_two)
|
172
|
-
return [date_for_string(ref_one), date_for_string(ref_two)]
|
173
|
-
end
|
174
|
-
|
175
|
-
def date_for_string(string)
|
176
|
-
date_from_commit(find_commit_for_string(string)) || parse_string_as_date(string)
|
177
|
-
end
|
178
|
-
|
179
|
-
def parse_string_as_date(string)
|
180
|
-
Chronic.parse(string)
|
181
|
-
end
|
182
|
-
|
183
|
-
# Page through all pulls grabbing only those merged in date range
|
184
|
-
def pull_requests_for_date_range(start_date, end_date)
|
185
|
-
page = 1
|
186
|
-
pulls = []
|
187
|
-
|
188
|
-
# There is a chance that the commit is created slightly earlier than the PR is merged.
|
189
|
-
# Example: merged_at: 2015-11-25T17:31:24+00:00, commit_date: 2015-11-25T17:31:23+00:00
|
190
|
-
end_date += 5
|
191
|
-
start_date += 5
|
192
|
-
|
193
|
-
loop do
|
194
|
-
response_wrapper = check_github_response() { github.pull_requests.list user, repo_name, state: 'closed', sort: 'updated', direction: 'desc', base: 'master', page: page }
|
195
|
-
found_pulls = response_wrapper.to_a
|
196
|
-
found_pulls.select! { |p| p['merged_at'] }
|
197
|
-
break if found_pulls.count == 0
|
198
|
-
stop = false
|
199
|
-
found_pulls.each do |pull|
|
200
|
-
date = Chronic.parse(pull['merged_at'])
|
201
|
-
# puts "PR: #{pull.number} Date: #{date}, Start Date: #{start_date}, End Date: #{end_date}"
|
202
|
-
next if date > end_date
|
203
|
-
if date <= start_date
|
204
|
-
stop = true
|
205
|
-
break
|
206
|
-
end
|
207
|
-
pulls << pull
|
208
|
-
end
|
209
|
-
break if stop
|
210
|
-
page += 1
|
211
|
-
end
|
212
|
-
|
213
|
-
pulls
|
214
|
-
end
|
215
184
|
end
|
216
185
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: github_changes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cody Rayment
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|