gplan 0.0.5 → 0.0.6

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.
Files changed (3) hide show
  1. data/bin/gplan +27 -0
  2. data/lib/github.rb +22 -7
  3. metadata +1 -1
data/bin/gplan CHANGED
@@ -45,20 +45,45 @@ def pull_pb_numbers_from_prs
45
45
  end
46
46
  end
47
47
 
48
+ def pull_dependency(story)
49
+ return if story['blocks'].nil?
50
+ story['blocks'].each do |block|
51
+ if block.match(/(dependenc(y|ies|ys))/i)
52
+ return "PR: ##{story[i'id']}: " + block
53
+ end
54
+ end
55
+ return nil
56
+ end
57
+
48
58
  def print
49
59
  end_of_pbs = false
50
60
  release_notes = "ID:STATUS:TITLE:PROJECT_NAME:PROJECT_ALIAS:PR:TITLE\n"
61
+ dependencies = []
51
62
  @combined.each do |story|
52
63
  if !end_of_pbs and story['name'].nil?
53
64
  end_of_pbs = true
54
65
  release_notes += "\n---- Unmatched PRs ----\n\n"
55
66
  release_notes += "PR:TITLE\n"
56
67
  end
68
+
69
+ dependency = pull_dependency(story)
70
+ dependencies << dependency unless dependency.nil?
71
+
57
72
  line = ""
58
73
  line += "#{story['id']}:#{story['status']}:#{story['name']}:#{story['project_name']}:#{story['project_alias']}" unless end_of_pbs
59
74
  line += ":#{story['number']}:#{story['title']}" unless story['number'].nil?
60
75
  release_notes += line + "\n"
61
76
  end
77
+
78
+ # print dependency blocks
79
+ unless dependencies.empty?
80
+ release_notes += "\n---- Dependencies ----\n\n"
81
+ dependencies.each do |dependency|
82
+ release_notes += dependency
83
+ release_notes += "\n"
84
+ end
85
+ end
86
+
62
87
  puts release_notes
63
88
  end
64
89
 
@@ -91,8 +116,10 @@ list= `git log #{@target}..`
91
116
 
92
117
  pb_story_ids = list.scan(PB_STORY_REGEX).flatten.uniq
93
118
  gh_pr_ids = list.scan(GH_PR_REGEX).flatten.uniq
119
+
94
120
  @gh_release_array = Github.get_release_notes_array gh_pr_ids
95
121
  @pb_release_array = Planbox.get_release_notes_array pb_story_ids
122
+
96
123
  pull_pb_numbers_from_prs
97
124
  combine_results
98
125
  print
@@ -3,6 +3,7 @@ require 'httparty'
3
3
  GITHUB_USERNAME=ENV['GITHUB_USERNAME']
4
4
  GITHUB_TOKEN=ENV['GITHUB_TOKEN']
5
5
  GITHUB_BASE_URL="https://api.github.com"
6
+ HEADERS = {:headers => { 'User-Agent' => GITHUB_USERNAME, 'Content-Type' => 'application/json', 'Accept' => 'application/json'}}
6
7
 
7
8
  module Github
8
9
  include HTTParty
@@ -31,17 +32,18 @@ module Github
31
32
 
32
33
  def self.get_release_notes_array gh_pr_ids
33
34
  check_environment
35
+ set_repo_info
34
36
  get_stories gh_pr_ids
35
37
  end
36
38
 
39
+ def self.pulls_url(pr_id)
40
+ "#{GITHUB_BASE_URL}/repos/#{@repo_name}/#{@app_name}/pulls/#{pr_id}?access_token=#{GITHUB_TOKEN}"
41
+ end
42
+
37
43
  def self.get_story(pr_id)
38
- set_repo_info
39
- story_response = self.get("#{GITHUB_BASE_URL}/repos/#{@repo_name}/#{@app_name}/pulls/#{pr_id}?access_token=#{GITHUB_TOKEN}",
40
- {
41
- :headers => { 'User-Agent' => GITHUB_USERNAME, 'Content-Type' => 'application/json', 'Accept' => 'application/json'}
42
- })
43
- return story_response.parsed_response unless story_response.parsed_response.nil? || story_response.parsed_response["code"] == "error"
44
- {"id" => story_id, "name" => "PR not found in github"}
44
+ pr = self.get( pulls_url(pr_id), HEADERS ).parsed_response
45
+ return {"id" => story_id, "name" => "PR not found in github"} if pr.nil? || pr["code"] == "error"
46
+ pr = extract_blocks pr
45
47
  end
46
48
 
47
49
  def self.get_stories(array_of_pr_ids)
@@ -53,6 +55,19 @@ module Github
53
55
  stories
54
56
  end
55
57
 
58
+ # used to extract blocks of information from a PR body
59
+ def self.extract_blocks(pr)
60
+ body = pr['body']
61
+ blocks = body.scan(/## ?((?:(?!##).)*)/m)
62
+ return if blocks.nil?
63
+
64
+ pr['blocks'] = []
65
+ blocks.each do |block|
66
+ pr['blocks'] << block.first unless block.first.empty?
67
+ end
68
+ pr
69
+ end
70
+
56
71
  # formats the output of stories
57
72
  def self.format(stories)
58
73
  result_string = ""
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.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: