changelogerator 0.0.2 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/changelogerator.rb +56 -24
- metadata +19 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d7e604fe48a69c44b84032971ca11723132e4570f558fb501205947f31e5b26
|
4
|
+
data.tar.gz: fd9f8601e21a0d927e00cb4887656664b40f2d7b22ef48af9e93bbcada39d29e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcf89c2dbf2dc1ad2d43664a97b54a802f65b92056643f2ae6fb4ae5c5224470783faf26b268acc2d3db748691d241ca7ac46a8c35c6d69933645a33c8765a41
|
7
|
+
data.tar.gz: d9d256e73a61f8de59d077f390715522ea4a944f97f595b24a30be713aca77278a3c298f86dbfe5a6dd7bd01f99a4291fbe78b46551dfa83a87eec604d77f773
|
data/lib/changelogerator.rb
CHANGED
@@ -7,7 +7,8 @@
|
|
7
7
|
# on how we classify the importance of PRs in the paritytech/polkadot project.
|
8
8
|
# Probably not tremendously useful to other projects.
|
9
9
|
class Changelog
|
10
|
-
require '
|
10
|
+
require 'octokit'
|
11
|
+
require 'git_diff_parser'
|
11
12
|
|
12
13
|
attr_accessor :changes
|
13
14
|
attr_reader :priority
|
@@ -51,10 +52,19 @@ class Changelog
|
|
51
52
|
|
52
53
|
def self.changes_with_label(changes, label)
|
53
54
|
changes.select do |change|
|
54
|
-
change
|
55
|
+
change[:labels].any? { |c| c[:name] == label } == true
|
55
56
|
end
|
56
57
|
end
|
57
58
|
|
59
|
+
def self.changes_files_in_paths?(change, paths)
|
60
|
+
changed_files = GitDiffParser.parse(Octokit.get(change.diff_url)).files
|
61
|
+
paths = [paths] unless paths.is_a? Array
|
62
|
+
paths.each do |path|
|
63
|
+
return true if changed_files.find { |l| l.match path }
|
64
|
+
end
|
65
|
+
nil
|
66
|
+
end
|
67
|
+
|
58
68
|
## End of class methods
|
59
69
|
|
60
70
|
# github_repo: 'paritytech/polkadot'
|
@@ -65,15 +75,13 @@ class Changelog
|
|
65
75
|
# token: a Github personal access token
|
66
76
|
# prefix: whether or not to prefix PR numbers with their repo in the changelog
|
67
77
|
def initialize(github_repo, from, to, token: '', prefix: nil)
|
68
|
-
|
69
|
-
@ghr = github_repo
|
78
|
+
@repo = github_repo
|
70
79
|
@priorities = self.class.priorities
|
71
|
-
@gh =
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
@changes = prs_from_ids(pr_ids_from_git_diff(from, to), prefix)
|
80
|
+
@gh = Octokit::Client.new(
|
81
|
+
access_token: token
|
82
|
+
)
|
83
|
+
@prefix = prefix
|
84
|
+
@changes = prs_from_ids(pr_ids_from_git_diff(from, to)).map(&:to_hash)
|
77
85
|
# add priority to each change
|
78
86
|
@changes.map { |c| apply_priority_to_change(c) }
|
79
87
|
end
|
@@ -82,35 +90,59 @@ class Changelog
|
|
82
90
|
self.class.changes_with_label(@changes, label)
|
83
91
|
end
|
84
92
|
|
93
|
+
def runtime_changes?
|
94
|
+
nil
|
95
|
+
end
|
96
|
+
|
97
|
+
def add(change)
|
98
|
+
changes.prepend(apply_priority_to_change(change))
|
99
|
+
end
|
100
|
+
|
101
|
+
def add_from_id(id)
|
102
|
+
pull = @gh.pull_request(@repo, id)
|
103
|
+
add(prettify_title(pull))
|
104
|
+
end
|
105
|
+
|
85
106
|
private
|
86
107
|
|
87
108
|
def apply_priority_to_change(change)
|
88
109
|
@priorities.each do |p|
|
89
|
-
change[:priority] = p if change
|
110
|
+
change[:priority] = p if change[:labels].any? { |l| l[:name] == p[:label] }
|
90
111
|
end
|
91
112
|
change
|
92
113
|
end
|
93
114
|
|
115
|
+
def prettify_title(pull)
|
116
|
+
pull[:pretty_title] = if @prefix
|
117
|
+
"#{pull[:title]} (#{@repo}##{pull[:number]})"
|
118
|
+
else
|
119
|
+
"#{pull[:title]} (##{pull[:number]})"
|
120
|
+
end
|
121
|
+
pull
|
122
|
+
end
|
123
|
+
|
94
124
|
def pr_ids_from_git_diff(from, to)
|
95
|
-
@gh.
|
96
|
-
title =
|
125
|
+
@gh.compare(@repo, from, to).commits.map do |c|
|
126
|
+
title = c.commit.message.split("\n\n").first
|
97
127
|
next unless title =~ /\(#[0-9]+\)$/
|
98
128
|
|
99
129
|
title.gsub(/.*#([0-9]+)\)$/, '\1')
|
100
|
-
end.compact
|
130
|
+
end.compact.map(&:to_i)
|
101
131
|
end
|
102
132
|
|
103
|
-
def prs_from_ids(ids
|
133
|
+
def prs_from_ids(ids)
|
134
|
+
batch_size = 100
|
104
135
|
prs = []
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
136
|
+
@gh.pulls(@repo, state: 'closed', per_page: batch_size)
|
137
|
+
cur_batch = @gh.last_response
|
138
|
+
until ids.empty?
|
139
|
+
prs += cur_batch.data.select { |pr| ids.include? pr.number }
|
140
|
+
ids -= cur_batch.data.map(&:number)
|
141
|
+
break if cur_batch.rels[:last].nil?
|
142
|
+
|
143
|
+
cur_batch = cur_batch.rels[:next].get
|
113
144
|
end
|
114
|
-
prs
|
145
|
+
prs.flatten
|
146
|
+
prs.map { |pr| prettify_title(pr) }
|
115
147
|
end
|
116
148
|
end
|
metadata
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: changelogerator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Pugh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: git_diff_parser
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '3'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: octokit
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4'
|
27
41
|
description: Simple helper class for paritytech/polkadot changelogs
|
28
42
|
email:
|
29
43
|
executables: []
|