changelogerator 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/changelogerator.rb +116 -0
- metadata +43 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 168c71f208452944f40001c41d2902d879c19b2f01e9a0a523d9d9a5b37def22
|
4
|
+
data.tar.gz: bd5d94e6d95e19eab2cb6b115ad286c6f8dd7e343f72646b79f6936e454978ef
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6b2ab20548258e78d78ac99deed1bc509f5bbf8bbbd062b141a92f86990d6e7d8261d108bc4a51091b9998808aefbed7388eb21b4da0045d3ecea430b7508865
|
7
|
+
data.tar.gz: 360a16cd39c8e224a3c0e66d6ad1d9b1d454cc1605b576acc91dd30c941ea2a23adbe4c653f70e3b02a58d73b4ba8d83891f30d5f5db20e6de2d74b6b95bc520
|
@@ -0,0 +1,116 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# A small wrapper class for more easily generating and manipulating Github/Git
|
4
|
+
# changelogs. Given two different git objects (sha, tag, whatever), it will
|
5
|
+
# find all PRs that made up that diff and store them as a list. Also allows
|
6
|
+
# for filtering by label, and the importance of that change (priorities), based
|
7
|
+
# on how we classify the importance of PRs in the paritytech/polkadot project.
|
8
|
+
# Probably not tremendously useful to other projects.
|
9
|
+
class Changelog
|
10
|
+
require 'github_api'
|
11
|
+
|
12
|
+
attr_accessor :changes
|
13
|
+
attr_reader :priority
|
14
|
+
|
15
|
+
@priorities = [
|
16
|
+
{
|
17
|
+
priority: 1,
|
18
|
+
label: 'C1-low',
|
19
|
+
text: 'Upgrade priority: **Low** (upgrade at your convenience)'
|
20
|
+
},
|
21
|
+
{
|
22
|
+
priority: 3,
|
23
|
+
label: 'C3-medium',
|
24
|
+
text: 'Upgrade priority: **Medium** (timely upgrade recommended)'
|
25
|
+
},
|
26
|
+
{
|
27
|
+
priority: 7,
|
28
|
+
label: 'C7-high',
|
29
|
+
text: 'Upgrade priority:❗ **HIGH** ❗ Please upgrade your node as soon as possible'
|
30
|
+
},
|
31
|
+
{
|
32
|
+
priority: 9,
|
33
|
+
label: 'C9-critical',
|
34
|
+
text: 'Upgrade priority: ❗❗ **URGENT** ❗❗ PLEASE UPGRADE IMMEDIATELY'
|
35
|
+
}
|
36
|
+
]
|
37
|
+
|
38
|
+
class << self
|
39
|
+
attr_reader :priorities
|
40
|
+
end
|
41
|
+
|
42
|
+
# Return highest priority from an array of changes (NOT the actual Changelog
|
43
|
+
# object)
|
44
|
+
def self.highest_priority_for_changes(changes)
|
45
|
+
@priorities.find do |p|
|
46
|
+
p[:priority] == changes.map do |change|
|
47
|
+
change[:priority][:priority]
|
48
|
+
end.max
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.changes_with_label(changes, label)
|
53
|
+
changes.select do |change|
|
54
|
+
change.labels.any? { |c| c[:name] == label } == true
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
## End of class methods
|
59
|
+
|
60
|
+
# github_repo: 'paritytech/polkadot'
|
61
|
+
# from: some git ref e.g., 7e30258, v1.2.3
|
62
|
+
# to: some git ref e.g., 7e30258, v1.2.3
|
63
|
+
#
|
64
|
+
# Optional named parameters:
|
65
|
+
# token: a Github personal access token
|
66
|
+
# prefix: whether or not to prefix PR numbers with their repo in the changelog
|
67
|
+
def initialize(github_repo, from, to, token: '', prefix: nil)
|
68
|
+
org, repo = github_repo.split('/')
|
69
|
+
@ghr = github_repo
|
70
|
+
@priorities = self.class.priorities
|
71
|
+
@gh = Github.new do |c|
|
72
|
+
c.oauth_token = token
|
73
|
+
c.org = org
|
74
|
+
c.repo = repo
|
75
|
+
end
|
76
|
+
@changes = prs_from_ids(pr_ids_from_git_diff(from, to), prefix)
|
77
|
+
# add priority to each change
|
78
|
+
@changes.map { |c| apply_priority_to_change(c) }
|
79
|
+
end
|
80
|
+
|
81
|
+
def changes_with_label(label)
|
82
|
+
self.class.changes_with_label(@changes, label)
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def apply_priority_to_change(change)
|
88
|
+
@priorities.each do |p|
|
89
|
+
change[:priority] = p if change.labels.any? { |l| l[:name] == p[:label] }
|
90
|
+
end
|
91
|
+
change
|
92
|
+
end
|
93
|
+
|
94
|
+
def pr_ids_from_git_diff(from, to)
|
95
|
+
@gh.repos.commits.compare(@gh.org, @gh.repo, from, to).body.commits.map do |l|
|
96
|
+
title = l.commit.message.split("\n\n").first
|
97
|
+
next unless title =~ /\(#[0-9]+\)$/
|
98
|
+
|
99
|
+
title.gsub(/.*#([0-9]+)\)$/, '\1')
|
100
|
+
end.compact
|
101
|
+
end
|
102
|
+
|
103
|
+
def prs_from_ids(ids, prefix)
|
104
|
+
prs = []
|
105
|
+
ids.each do |pr|
|
106
|
+
pull = @gh.pull_requests.get(@gh.org, @gh.repo, pr).body
|
107
|
+
pull[:pretty_title] = if prefix
|
108
|
+
"#{pull[:title]} (#{@ghr}##{pull[:number]})"
|
109
|
+
else
|
110
|
+
"#{pull[:title]} (##{pull[:number]})"
|
111
|
+
end
|
112
|
+
prs.push pull
|
113
|
+
end
|
114
|
+
prs
|
115
|
+
end
|
116
|
+
end
|
metadata
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: changelogerator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Martin Pugh
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-07-28 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Simple helper class for paritytech/polkadot changelogs
|
14
|
+
email:
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/changelogerator.rb
|
20
|
+
homepage: https://github.com/s3krit/changelogerator
|
21
|
+
licenses:
|
22
|
+
- AGPL-3.0
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubygems_version: 3.0.3
|
40
|
+
signing_key:
|
41
|
+
specification_version: 4
|
42
|
+
summary: Changelog generation/management
|
43
|
+
test_files: []
|