github_changes 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/changelog_generator/cli.rb +3 -2
- data/lib/changelog_generator/generator.rb +51 -8
- data/lib/changelog_generator/issue.rb +13 -0
- data/lib/changelog_generator/pull_request.rb +14 -0
- data/lib/changelog_generator/text_formatter.rb +17 -0
- data/lib/changelog_generator/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75ac8bcd7b3ee239aebce82f31481cc00a72efcd
|
4
|
+
data.tar.gz: 2b1540aeead7cf03802d5799243f4660b82df3d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc177035d2ebfa2983711dde40650a77556482cfbfab681cf09f437ddb28b78d92a4aa41df8255e9c7805e3ac57002082d14367dfe5e754a60c005976c599899
|
7
|
+
data.tar.gz: 5ae84bb820bd71bd89c85071b2b0f5687051014f119a6d183a9299ea1368df94c402642bc288704c2bb8179bfa0aa26d89a4d223a64adcf1ffda581c6d0331ad
|
@@ -30,8 +30,9 @@ module ChangelogGenerator
|
|
30
30
|
method_option :label_filter, :aliases => "-l", :type => :string
|
31
31
|
method_option :include_pr_links, :type => :boolean
|
32
32
|
method_option :include_issue_links, :type => :boolean
|
33
|
+
method_option :formatting_style, :aliases => "-s", :type => :string, :default => "slack"
|
33
34
|
def generate()
|
34
|
-
generator = Generator.new(options[:user], options[:repo], options[:from_ref], options[:to_ref], options[:label_filter], options.include_pr_links?, options.include_issue_links
|
35
|
+
generator = Generator.new(options[:user], options[:repo], options[:from_ref], options[:to_ref], options[:label_filter], options.include_pr_links?, options.include_issue_links?, options[:formatting_style])
|
35
36
|
begin
|
36
37
|
output = generator.description + "\n\n"
|
37
38
|
output << generator.changelog
|
@@ -44,4 +45,4 @@ module ChangelogGenerator
|
|
44
45
|
end
|
45
46
|
end
|
46
47
|
end
|
47
|
-
end
|
48
|
+
end
|
@@ -2,6 +2,7 @@ require 'github_api'
|
|
2
2
|
require 'chronic'
|
3
3
|
require 'changelog_generator/pull_request'
|
4
4
|
require 'changelog_generator/issue'
|
5
|
+
require 'changelog_generator/text_formatter'
|
5
6
|
|
6
7
|
module ChangelogGenerator
|
7
8
|
class Generator
|
@@ -12,8 +13,9 @@ module ChangelogGenerator
|
|
12
13
|
attr_accessor :label_filter
|
13
14
|
attr_accessor :include_pr_links
|
14
15
|
attr_accessor :include_issue_links
|
16
|
+
attr_accessor :formatting
|
15
17
|
|
16
|
-
def initialize(user, repo, from_ref, to_ref, label_filter = nil, include_pr_links = false, include_issue_links = false)
|
18
|
+
def initialize(user, repo, from_ref, to_ref, label_filter = nil, include_pr_links = false, include_issue_links = false, formatting = "slack")
|
17
19
|
self.user = user
|
18
20
|
self.repo_name = repo
|
19
21
|
self.from_ref = from_ref
|
@@ -21,6 +23,7 @@ module ChangelogGenerator
|
|
21
23
|
self.label_filter = label_filter
|
22
24
|
self.include_pr_links = include_pr_links
|
23
25
|
self.include_issue_links = include_issue_links
|
26
|
+
self.formatting = TextFormatter.text_formatter(formatting)
|
24
27
|
end
|
25
28
|
|
26
29
|
def description
|
@@ -39,7 +42,7 @@ module ChangelogGenerator
|
|
39
42
|
|
40
43
|
def generate_changelog(user, repo, start_ref, end_ref, label_filter = nil)
|
41
44
|
unless check_github_response() { github.repos.get(user, repo) }
|
42
|
-
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
|
45
|
+
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 oauth token."
|
43
46
|
end
|
44
47
|
|
45
48
|
start_sha, start_time, end_sha = parse_references(start_ref, end_ref)
|
@@ -49,6 +52,7 @@ module ChangelogGenerator
|
|
49
52
|
|
50
53
|
pulls = pull_nums.map { |p| github.pull_requests.get(user, repo, p) }
|
51
54
|
pulls = pulls.map { |p| PullRequest.from_github_pr(p) }
|
55
|
+
pulls.reverse!
|
52
56
|
# puts JSON.pretty_generate(pulls.first.body.to_hash)
|
53
57
|
|
54
58
|
pulls.each do |pull|
|
@@ -59,19 +63,19 @@ module ChangelogGenerator
|
|
59
63
|
end
|
60
64
|
|
61
65
|
string = pulls.reduce("") do |memo, pull|
|
62
|
-
memo <<
|
66
|
+
memo << pull.link_text(user, repo, self.formatting) if include_pr_links
|
63
67
|
memo << pull.changelog_text
|
64
68
|
|
65
69
|
if include_issue_links
|
66
70
|
pull.issues.each do |issue|
|
67
|
-
memo <<
|
71
|
+
memo << issue.link_text(user, repo, self.formatting)
|
68
72
|
end
|
69
73
|
end
|
70
74
|
|
71
75
|
memo << "\n"
|
72
76
|
end
|
73
77
|
|
74
|
-
string << "\n
|
78
|
+
string << "\n"
|
75
79
|
|
76
80
|
commits = pulls.map { |p| p.head_sha[0..7] }
|
77
81
|
connected_issue_nums = pulls.map(&:issues).flatten.map(&:number)
|
@@ -79,13 +83,52 @@ module ChangelogGenerator
|
|
79
83
|
show_issues = show_prs && (connected_issue_nums.count > 0)
|
80
84
|
show_both = show_prs && show_issues && (commits.count + connected_issue_nums.count <= 20)
|
81
85
|
|
82
|
-
|
83
|
-
|
84
|
-
|
86
|
+
link_summaries = Array.new
|
87
|
+
if show_prs
|
88
|
+
link_summaries.push(summary_link(user, repo, commits, connected_issue_nums, :pr))
|
89
|
+
end
|
90
|
+
if show_issues
|
91
|
+
link_summaries.push(summary_link(user, repo, commits, connected_issue_nums, :issue))
|
92
|
+
end
|
93
|
+
if show_both
|
94
|
+
link_summaries.push(summary_link(user, repo, commits, connected_issue_nums, :both))
|
95
|
+
end
|
96
|
+
|
97
|
+
string << link_summaries.join(" | ")
|
85
98
|
|
86
99
|
string
|
87
100
|
end
|
88
101
|
|
102
|
+
# Generates a github search query link for PRs, issues, or both, formatted
|
103
|
+
# for the style which this generator was initialized with
|
104
|
+
# Params:
|
105
|
+
# +user+:: The username of the repo owner
|
106
|
+
# +repo+:: The name of the github repository
|
107
|
+
# +commits+:: The collection of commits hashes for relevant PRs
|
108
|
+
# +connected_issue_nums+:: The collection of issue numbers
|
109
|
+
# +link_type+:: The type of link we want (eg. PRs, issues, or both)
|
110
|
+
def summary_link(user, repo, commits, connected_issue_nums, link_type)
|
111
|
+
link_title = ""
|
112
|
+
path = ""
|
113
|
+
if link_type == :pr
|
114
|
+
link_title = "PRs"
|
115
|
+
path = "pulls?q=is%3Apr+#{commits.join("+")}"
|
116
|
+
elsif link_type == :issue
|
117
|
+
link_title = "Issues"
|
118
|
+
path = "issues?q=is%3Aissue+#{connected_issue_nums.join("+")}"
|
119
|
+
elsif link_type == :both
|
120
|
+
link_title = "Both"
|
121
|
+
path = "issues?q=#{commits.join("+")}+#{connected_issue_nums.join("+")}"
|
122
|
+
end
|
123
|
+
|
124
|
+
if self.formatting == :slack
|
125
|
+
return "<https://github.com/#{user}/#{repo}/#{path}|#{link_title}>"
|
126
|
+
elsif self.formatting == :markdown
|
127
|
+
return "[#{link_title}](https://github.com/#{user}/#{repo}/#{path})"
|
128
|
+
end
|
129
|
+
return ""
|
130
|
+
end
|
131
|
+
|
89
132
|
def github
|
90
133
|
@github ||= Github.new({ oauth_token: ENV['GITHUB_TOKEN'] })
|
91
134
|
end
|
@@ -16,5 +16,18 @@ module ChangelogGenerator
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
# Generates a link snippet for this issue with desired text formatting
|
20
|
+
# Params:
|
21
|
+
# +user+:: The username of the repo owner
|
22
|
+
# +repo+:: The name of the github repository
|
23
|
+
# +formatting_style+:: The text formatting style symbol
|
24
|
+
def link_text(user, repo, formatting_style)
|
25
|
+
if formatting_style == :slack
|
26
|
+
return " <https://github.com/#{user}/#{repo}/issues/#{self.number}|##{self.number}>"
|
27
|
+
elsif formatting_style == :markdown
|
28
|
+
return " [##{self.number}](https://github.com/#{user}/#{repo}/issues/#{self.number})"
|
29
|
+
end
|
30
|
+
return ""
|
31
|
+
end
|
19
32
|
end
|
20
33
|
end
|
@@ -25,6 +25,20 @@ module ChangelogGenerator
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
+
# Generates a link snippet for this PR with desired text formatting
|
29
|
+
# Params:
|
30
|
+
# +user+:: The username of the repo owner
|
31
|
+
# +repo+:: The name of the github repository
|
32
|
+
# +formatting_style+:: The text formatting style symbol
|
33
|
+
def link_text(user, repo, formatting_style)
|
34
|
+
if formatting_style == :slack
|
35
|
+
return "<https://github.com/#{user}/#{repo}/pull/#{self.number}|##{self.number}> "
|
36
|
+
elsif formatting_style == :markdown
|
37
|
+
return "[##{self.number}](https://github.com/#{user}/#{repo}/pull/#{self.number}) "
|
38
|
+
end
|
39
|
+
return ""
|
40
|
+
end
|
41
|
+
|
28
42
|
private
|
29
43
|
|
30
44
|
def self.changelog_from_pr(pr)
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module ChangelogGenerator
|
2
|
+
class TextFormatter
|
3
|
+
# Determines the type of text formatting wanted from the provided parameter
|
4
|
+
# string for formatting
|
5
|
+
# Params:
|
6
|
+
# +string+:: The string representation of the text formatting desired
|
7
|
+
def self.text_formatter(string)
|
8
|
+
if string.casecmp("slack") == 0
|
9
|
+
return :slack
|
10
|
+
elsif string.casecmp("markdown") == 0 or string.casecmp("md") == 0 or string.casecmp("mkd") == 0 or string.casecmp("mdown") == 0
|
11
|
+
return :markdown
|
12
|
+
else
|
13
|
+
abort "Invalid formatting style provided. Available formatting options are: Slack, or Markdown"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
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.8
|
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-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- lib/changelog_generator/generator.rb
|
118
118
|
- lib/changelog_generator/issue.rb
|
119
119
|
- lib/changelog_generator/pull_request.rb
|
120
|
+
- lib/changelog_generator/text_formatter.rb
|
120
121
|
- lib/changelog_generator/version.rb
|
121
122
|
homepage:
|
122
123
|
licenses: []
|
@@ -137,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
138
|
version: '0'
|
138
139
|
requirements: []
|
139
140
|
rubyforge_project:
|
140
|
-
rubygems_version: 2.
|
141
|
+
rubygems_version: 2.4.5
|
141
142
|
signing_key:
|
142
143
|
specification_version: 4
|
143
144
|
summary: Generate Release Notes
|