gplan 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/gplan +6 -37
- data/lib/github.rb +38 -21
- data/lib/printer.rb +62 -0
- metadata +4 -3
data/bin/gplan
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
#
|
3
3
|
# This script is used to find all of the planbox story numbers from the git log
|
4
|
-
# For lesson-player it is dependent on lesson-player being in the directory name for the repo
|
5
4
|
|
5
|
+
# This is just a neat way to require everything in the lib path
|
6
6
|
require 'pathname'
|
7
7
|
bin_path = Pathname.new(__FILE__).realpath
|
8
8
|
$:.unshift File.expand_path('../../lib', bin_path)
|
9
|
-
|
10
|
-
|
9
|
+
Dir[bin_path + '../../lib/*.rb'].each {|file| require file }
|
10
|
+
|
11
|
+
include Printer
|
11
12
|
|
12
13
|
PB_STORY_REGEX=/\[(?:fixes)? *#*([0-9]*)\]/i
|
13
14
|
GH_PR_REGEX=/Merge pull request #(\d*)/i
|
@@ -62,38 +63,6 @@ def pull_dependency(story)
|
|
62
63
|
return nil
|
63
64
|
end
|
64
65
|
|
65
|
-
def print
|
66
|
-
end_of_pbs = false
|
67
|
-
release_notes = "ID:STATUS:TITLE:PROJECT_NAME:PROJECT_ALIAS:PR:TITLE\n"
|
68
|
-
dependencies = []
|
69
|
-
@combined.each do |story|
|
70
|
-
if !end_of_pbs and story['name'].nil?
|
71
|
-
end_of_pbs = true
|
72
|
-
release_notes += "\n---- Unmatched PRs ----\n\n"
|
73
|
-
release_notes += "PR:TITLE\n"
|
74
|
-
end
|
75
|
-
|
76
|
-
dependency = pull_dependency(story)
|
77
|
-
dependencies << dependency unless dependency.nil?
|
78
|
-
|
79
|
-
line = ""
|
80
|
-
line += "#{story['id']}:#{story['status']}:#{story['name']}:#{story['project_name']}:#{story['project_alias']}" unless end_of_pbs
|
81
|
-
line += ":#{story['number']}:#{story['title']}" unless story['number'].nil?
|
82
|
-
release_notes += line + "\n"
|
83
|
-
end
|
84
|
-
|
85
|
-
# print dependency blocks
|
86
|
-
unless dependencies.empty?
|
87
|
-
release_notes += "\n---- Dependencies ----\n\n"
|
88
|
-
dependencies.each do |dependency|
|
89
|
-
release_notes += dependency
|
90
|
-
release_notes += "\n"
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
puts release_notes
|
95
|
-
end
|
96
|
-
|
97
66
|
def setup_repository
|
98
67
|
if ARGV[0] # allow you to pass in a SHA or remote/branch to target against. This can be useful when generating release notes after a deployment
|
99
68
|
@target = ARGV[0]
|
@@ -124,9 +93,9 @@ list= `git log #{@target}..`
|
|
124
93
|
pb_story_ids = list.scan(PB_STORY_REGEX).flatten.uniq
|
125
94
|
gh_pr_ids = list.scan(GH_PR_REGEX).flatten.uniq
|
126
95
|
|
127
|
-
@gh_release_array = Github.get_release_notes_array gh_pr_ids
|
96
|
+
@gh_release_array = Github.new.get_release_notes_array gh_pr_ids
|
128
97
|
@pb_release_array = Planbox.get_release_notes_array pb_story_ids
|
129
98
|
|
130
99
|
pull_pb_numbers_from_prs
|
131
100
|
combine_results
|
132
|
-
print
|
101
|
+
Printer.print @combined
|
data/lib/github.rb
CHANGED
@@ -1,62 +1,65 @@
|
|
1
1
|
require 'httparty'
|
2
|
+
require 'pry'
|
2
3
|
|
3
4
|
GITHUB_USERNAME=ENV['GITHUB_USERNAME']
|
4
5
|
GITHUB_TOKEN=ENV['GITHUB_TOKEN']
|
5
6
|
GITHUB_BASE_URL="https://api.github.com"
|
6
7
|
HEADERS = {:headers => { 'User-Agent' => GITHUB_USERNAME, 'Content-Type' => 'application/json', 'Accept' => 'application/json'}}
|
7
8
|
|
8
|
-
|
9
|
-
include HTTParty
|
9
|
+
class Github
|
10
10
|
|
11
|
-
|
12
|
-
@app_name
|
13
|
-
|
14
|
-
def self.check_environment
|
11
|
+
def check_environment
|
15
12
|
if GITHUB_USERNAME == nil || GITHUB_TOKEN == nil
|
16
13
|
raise "environment variables not set. Please check that you have the following set...\
|
17
14
|
\nGITHUB_USERNAME\nGITHUB_TOKEN"
|
18
15
|
end
|
19
16
|
end
|
20
17
|
|
21
|
-
def
|
18
|
+
def get_repo_name
|
22
19
|
cmd = "git remote -v |grep origin"
|
23
20
|
repo_info = `#{cmd}`
|
24
|
-
|
25
|
-
@app_name = repo_info.scan(/\/(.*)\.git/).uniq.flatten.first
|
21
|
+
repo_info.scan(/\:(.*\/.*)\.git/).uniq.flatten.first
|
26
22
|
end
|
27
23
|
|
28
|
-
def
|
24
|
+
def get_release_notes gh_pr_ids
|
29
25
|
stories = get_release_notes_array gh_pr_ids
|
30
26
|
result_string = format stories
|
31
27
|
end
|
32
28
|
|
33
|
-
def
|
29
|
+
def get_release_notes_array gh_pr_ids
|
34
30
|
check_environment
|
35
|
-
|
36
|
-
get_stories gh_pr_ids
|
31
|
+
repo_name = get_repo_name
|
32
|
+
get_stories repo_name, gh_pr_ids
|
37
33
|
end
|
38
34
|
|
39
|
-
def
|
40
|
-
"#{GITHUB_BASE_URL}/repos/#{
|
35
|
+
def pulls_url(repo_name, pr_id)
|
36
|
+
"#{GITHUB_BASE_URL}/repos/#{repo_name}/issues/#{pr_id}?access_token=#{GITHUB_TOKEN}"
|
41
37
|
end
|
42
38
|
|
43
|
-
def
|
44
|
-
|
39
|
+
def get_story(repo_name, pr_id = false)
|
40
|
+
# if story url like "user/repo_name#123"
|
41
|
+
unless pr_id
|
42
|
+
story = repo_name.split '#'
|
43
|
+
repo_name = story[0]
|
44
|
+
pr_id = story[1]
|
45
|
+
end
|
46
|
+
pr = HTTParty.get( pulls_url(repo_name, pr_id), HEADERS ).parsed_response
|
45
47
|
return {"id" => story_id, "name" => "PR not found in github"} if pr.nil? || pr["code"] == "error"
|
48
|
+
pr = extract_linked_issues pr
|
46
49
|
pr = extract_blocks pr
|
47
50
|
end
|
48
51
|
|
49
|
-
def
|
52
|
+
def get_stories(repo_name, array_of_pr_ids)
|
50
53
|
stories = []
|
51
54
|
return [] unless array_of_pr_ids
|
52
55
|
array_of_pr_ids.each do |id|
|
53
|
-
stories<< get_story(id)
|
56
|
+
stories<< get_story(repo_name, id)
|
54
57
|
end
|
55
58
|
stories
|
56
59
|
end
|
57
60
|
|
58
61
|
# used to extract blocks of information from a PR body
|
59
|
-
def
|
62
|
+
def extract_blocks(pr)
|
60
63
|
body = pr['body']
|
61
64
|
blocks = body.scan(/## ?((?:(?!##).)*)/m)
|
62
65
|
return if blocks.nil?
|
@@ -68,8 +71,22 @@ module Github
|
|
68
71
|
pr
|
69
72
|
end
|
70
73
|
|
74
|
+
# used to extract linked issues from the description follow githubs linking issue linking matchers
|
75
|
+
def extract_linked_issues(pr)
|
76
|
+
body = pr['body']
|
77
|
+
regex = /(close|close|closes|closed|fix|fixes|fixed|resolve|resolves|resolved)(\s)+((\w*\/\w*)?#(\d+))/im
|
78
|
+
linked_issues = body.scan(regex)
|
79
|
+
return if linked_issues.nil?
|
80
|
+
|
81
|
+
pr['linked_issues'] = []
|
82
|
+
linked_issues.each do |linked_issue|
|
83
|
+
pr['linked_issues'] << get_story(linked_issue[2]) unless linked_issue[2].nil?
|
84
|
+
end
|
85
|
+
pr
|
86
|
+
end
|
87
|
+
|
71
88
|
# formats the output of stories
|
72
|
-
def
|
89
|
+
def format(stories)
|
73
90
|
result_string = ""
|
74
91
|
stories.each do |story|
|
75
92
|
result_string += "#{story['number']}:"
|
data/lib/printer.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
module Printer
|
2
|
+
def print stories
|
3
|
+
end_of_pbs = false
|
4
|
+
release_notes = "ID:STATUS:TITLE:PROJECT_NAME:PROJECT_ALIAS:PR:TITLE\n"
|
5
|
+
dependencies = []
|
6
|
+
stories.each do |story|
|
7
|
+
if !end_of_pbs and story['name'].nil?
|
8
|
+
end_of_pbs = true
|
9
|
+
release_notes += title "Unmatched PRs"
|
10
|
+
release_notes += "PR:TITLE\n"
|
11
|
+
end
|
12
|
+
|
13
|
+
dependency = pull_dependency(story)
|
14
|
+
dependencies << dependency unless dependency.nil?
|
15
|
+
|
16
|
+
line = ""
|
17
|
+
line += planbox_info story unless end_of_pbs
|
18
|
+
line += github_pr_info story unless story['number'].nil?
|
19
|
+
|
20
|
+
release_notes += line + "\n"
|
21
|
+
end
|
22
|
+
|
23
|
+
# print dependency blocks
|
24
|
+
unless dependencies.empty?
|
25
|
+
release_notes += include_dependencies dependencies
|
26
|
+
end
|
27
|
+
|
28
|
+
puts release_notes
|
29
|
+
end
|
30
|
+
|
31
|
+
def planbox_info story
|
32
|
+
"#{story['id']}:#{story['status']}:#{story['name']}:#{story['project_name']}:#{story['project_alias']}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def github_pr_info story
|
36
|
+
line = ":#{story['number']}:#{story['title']}"
|
37
|
+
line += github_issue_info story if story['linked_issues']
|
38
|
+
line
|
39
|
+
end
|
40
|
+
|
41
|
+
def github_issue_info story
|
42
|
+
line = ""
|
43
|
+
story['linked_issues'].each do |issue|
|
44
|
+
line += ":ISSUE##{issue['number']}"
|
45
|
+
line +=":Milestone #{issue['milestone']['title']}" if issue['milestone']['title']
|
46
|
+
end
|
47
|
+
line
|
48
|
+
end
|
49
|
+
|
50
|
+
def include_dependencies dependencies
|
51
|
+
release_notes = title "Dependencies"
|
52
|
+
dependencies.each do |dependency|
|
53
|
+
release_notes += dependency
|
54
|
+
release_notes += "\n"
|
55
|
+
end
|
56
|
+
release_notes
|
57
|
+
end
|
58
|
+
|
59
|
+
def title text
|
60
|
+
"\n---- #{text} ----\n\n"
|
61
|
+
end
|
62
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gplan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-02-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
@@ -37,7 +37,8 @@ files:
|
|
37
37
|
- bin/gplan
|
38
38
|
- lib/github.rb
|
39
39
|
- lib/planbox.rb
|
40
|
-
|
40
|
+
- lib/printer.rb
|
41
|
+
homepage: https://github.com/el-jefe-/gplan
|
41
42
|
licenses: []
|
42
43
|
post_install_message:
|
43
44
|
rdoc_options: []
|