octopolo 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- M2Q4NWI4ZGY4Y2M3NmNmNTc1MjU0YTcwYjM3YjkyMmU5ZmFjMmViNA==
4
+ N2RmMDI0OTU2NDAyZGU3MTIzYWUzNGQxNTU3OTg3NDkyZjdmOWJmYQ==
5
5
  data.tar.gz: !binary |-
6
- NjFiZjgyMmZiODM0M2ZlZDM4ODVlY2E2M2QxMzMyMmRjMzcwMjkwNg==
6
+ ZWRhMTJiMGE5YjRlZmRlYjk4MzEzMmIxMjE1MzNjMWU2OGZjODlkOQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MGNmMTYzMmI5ZjM1YTk0M2Q3NTY3MGFmMTFlNmEzZDAwNTlhZDkxMDg1ZWU4
10
- ODk0NDFjMDI4YmFiOThkMDU3NWYzOGQ3MDcyOTZiMDcyN2RhMzUxNzlkMTk1
11
- YWQxYWY3OWM2NjlhZmJkMDMyN2ViYTIyYzUyMmUxYWQ1NzM3OWY=
9
+ NjQ0ZTRiMjEwYTZhNjQzNjhmOTcyMjZkODE1NjBlNWI0YTJkNmI5NzkzOWE4
10
+ YTllOWE0NGYwMjY5YjczYTZlZjRiOTg3ZmU1ZDM4MTY1ZjdjNmRkZDY0MGIy
11
+ OWY1YWU5M2ExMjRiZDE3NGU2MDhhMDE0ZDVhMDg3MWI1Zjk3NzM=
12
12
  data.tar.gz: !binary |-
13
- OWU3MzBjNWJlMTc4NjRmMjNiZmQ3ZmEwZmQ1NmQxZDE4Njk5YTc5NWQyY2Y1
14
- ODVjODVlYmMxYWFjNDdhNDRiZGMxYjAzODdmZDRmNzM1ZGNkZTVmYTYzZGJi
15
- ZGUwZGFiZjlmZWZhMzJhZjZkZjkwNzA1YTI5N2UxMWJiYTUwMzI=
13
+ NTVlMTZhNGY0OTdmMjU3NDJmMTRmNDFjODA1NGNhZDhjYzhjNjZlYTJlZTEz
14
+ MjA1NjI2NDJkYmUxNzgzNjViMzg1OGNhZTVhOGRmOGEzMjE5MjMxOGI3NWVm
15
+ MGE1MTcyNTk0Yjc3NTE1OTc1OTg1NTgyNGEwZWMxM2Q0MWRhNmE=
@@ -1,3 +1,13 @@
1
+ #### v0.1.1
2
+
3
+ * Fix dependancy issues
4
+
5
+ > Nick LaMuro: Elliot Hursh: https://github.com/sportngin/octopolo/pull/27
6
+
7
+ * Label support for pull requests
8
+
9
+ > Elliot Hursh: Andy Fleener: https://github.com/sportngin/octopolo/pull/23
10
+
1
11
  #### v0.1.0
2
12
 
3
13
  * Add Label for deployable
@@ -1,6 +1,9 @@
1
1
  require "octokit"
2
- # TODO this needs to get moved out of scripts and into its own new module
3
- require_relative "scripts/github_auth"
2
+ require_relative "github/commit"
3
+ require_relative "github/label"
4
+ require_relative "github/pull_request"
5
+ require_relative "github/pull_request_creator"
6
+ require_relative "github/user"
4
7
 
5
8
  module Octopolo
6
9
  module GitHub
@@ -93,11 +96,17 @@ module Octopolo
93
96
  def self.add_label *args
94
97
  client.add_label *args
95
98
  end
96
-
99
+
100
+ def self.remove_label *args
101
+ client.remove_label *args
102
+ end
103
+
97
104
  def self.add_labels_to_pull *args
98
105
  client.add_labels_to_an_issue *args
99
106
  end
100
-
107
+
108
+
109
+
101
110
  # now that you've set up your credentials, try again
102
111
  TryAgain = Class.new(StandardError)
103
112
  # the credentials you've entered are bad
@@ -1,6 +1,3 @@
1
- require_relative "../github"
2
- require_relative "user"
3
-
4
1
  module Octopolo
5
2
  module GitHub
6
3
  class Commit
@@ -1,4 +1,3 @@
1
- require_relative "../github"
2
1
  require "yaml"
3
2
  require "octokit"
4
3
 
@@ -10,9 +9,9 @@ module Octopolo
10
9
  attr_accessor :name
11
10
  attr_accessor :color
12
11
 
13
- def initialize(name, color)
14
- self.name = name
15
- self.color = color
12
+ def initialize(args)
13
+ self.name = args[:name]
14
+ self.color = args[:color]
16
15
  end
17
16
 
18
17
  def == (obj)
@@ -21,8 +20,8 @@ module Octopolo
21
20
 
22
21
  # Public: Grabs all labels from either file or github
23
22
  # This is the method to override for labels from files
24
- def self.all_labels
25
- from_github
23
+ def self.all
24
+ all_from_repo
26
25
  end
27
26
 
28
27
  # Public: Gets the names of labels
@@ -38,49 +37,29 @@ module Octopolo
38
37
  #
39
38
  # label - a label object
40
39
  def self.first_or_create(label)
41
- unless all_labels.include?(label)
40
+ unless all.include?(label)
42
41
  GitHub.add_label(config.github_repo, label.name, label.color)
43
42
  end
44
43
  end
45
44
 
46
- # Public: Adds labels to a pull-request
45
+ # Public: Finds or creates each of the passed in labels
47
46
  #
48
- # labels - an array of labels
49
- # pull_number - number of the pull_request to add label to
50
- def self.add_to_pull(pull_number, *labels)
51
- built_labels = build_label_array(labels)
52
- GitHub.add_labels_to_pull(config.github_repo, pull_number, get_names(built_labels) )
53
- end
54
-
55
- # Private: takes in a hash, out puts a label
56
- #
57
- # label_hash - a hashed label
47
+ # labels - label objects, can be a single label, an array of labels,
48
+ # or a list of labels
58
49
  #
59
- # returns - a label
60
- def self.to_label(label_hash)
61
- Label.new(label_hash[:name], label_hash[:color])
50
+ # returns - an array of labels.
51
+ def self.build_label_array(*labels)
52
+ Array(labels).flatten.each {|label| first_or_create(label)}
62
53
  end
63
- private_class_method :to_label
64
54
 
65
55
  # Private: Gets all the labels from given repository on github
66
56
  #
67
57
  # returns - an array of labels
68
- def self.from_github
69
- GitHub.labels(config.github_repo).map{ |label_hash| to_label(label_hash) }
70
- end
71
- private_class_method :from_github
72
-
73
- # Private: Finds or creates each of the passed in labels
74
- #
75
- # labels - label objects, can be a single label, an array of labels,
76
- # or a list of labels
77
- #
78
- # returns - an array of labels.
79
- def self.build_label_array(*labels)
80
- Array(labels).flatten.each {|label| first_or_create(label)}
58
+ def self.all_from_repo
59
+ GitHub.labels(config.github_repo).map{ |label_hash| new(label_hash) }
81
60
  end
82
- private_class_method :build_label_array
61
+ private_class_method :all_from_repo
83
62
 
84
63
  end
85
64
  end
86
- end
65
+ end
@@ -1,7 +1,3 @@
1
- require_relative "../github"
2
- require_relative "commit"
3
- require_relative "pull_request_creator"
4
- require_relative "user"
5
1
  require_relative "../week"
6
2
  require "octokit"
7
3
 
@@ -118,6 +114,25 @@ module Octopolo
118
114
  raise CommentFailed, "Unable to write the comment: '#{error.message}'"
119
115
  end
120
116
 
117
+ # Public: Adds labels to a pull-request
118
+ #
119
+ # labels - label objects, can be a single label, an array of labels,
120
+ # or a list of labels
121
+ def add_labels(*labels)
122
+ built_labels = Label.build_label_array(labels)
123
+ GitHub.add_labels_to_pull(repo_name, number, built_labels.map(&:name) )
124
+ end
125
+
126
+ # Public: Removes labels from a pull-request,
127
+ #
128
+ # labels - label objects, can be a single label, an array of labels,
129
+ # or a list of labels
130
+ def remove_labels(*labels)
131
+ Label.build_label_array(labels).each do |built_label|
132
+ GitHub.remove_label(repo_name, number, built_label.name)
133
+ end
134
+ end
135
+
121
136
  MissingParameter = Class.new StandardError
122
137
  NotFound = Class.new StandardError
123
138
  CommentFailed = Class.new StandardError
@@ -1,6 +1,6 @@
1
1
  require_relative "scripts"
2
2
  require_relative "git"
3
- require_relative "github/pull_request"
3
+ require_relative "github"
4
4
  require_relative "dated_branch_creator"
5
5
 
6
6
  module Octopolo
@@ -42,14 +42,20 @@ module Octopolo
42
42
  merge_pull_request
43
43
  comment_about_merge
44
44
  end
45
- rescue GitHub::PullRequest::NotFound
46
- cli.say "Unable to find pull request #{pull_request_id}. Please retry with a valid ID."
47
- rescue Git::MergeFailed
48
- cli.say "Merge failed. Please identify the source of this merge conflict resolve this conflict in your pull request's branch. NOTE: Merge conflicts resolved in the #{branch_type} branch are NOT used when deploying."
49
- rescue Git::CheckoutFailed
50
- cli.say "Checkout of #{branch_to_merge_into} failed. Please contact Infrastructure to determine the cause."
51
- rescue GitHub::PullRequest::CommentFailed
52
- cli.say "Unable to write comment. Please navigate to #{pull_request.url} and add the comment, '#{comment_body}'"
45
+ rescue => e
46
+ case e
47
+ when GitHub::PullRequest::NotFound
48
+ cli.say "Unable to find pull request #{pull_request_id}. Please retry with a valid ID."
49
+ when Git::MergeFailed
50
+ cli.say "Merge failed. Please identify the source of this merge conflict resolve this conflict in your pull request's branch. NOTE: Merge conflicts resolved in the #{branch_type} branch are NOT used when deploying."
51
+ when Git::CheckoutFailed
52
+ cli.say "Checkout of #{branch_to_merge_into} failed. Please contact Infrastructure to determine the cause."
53
+ when GitHub::PullRequest::CommentFailed
54
+ cli.say "Unable to write comment. Please navigate to #{pull_request.url} and add the comment, '#{comment_body}'"
55
+ else
56
+ cli.say "An uknown error occured: #{e.class.to_s}"
57
+ end
58
+ false
53
59
  end
54
60
 
55
61
  # Public: Check out the branch
@@ -96,4 +102,3 @@ module Octopolo
96
102
  end
97
103
  end
98
104
  end
99
-
@@ -15,9 +15,3 @@ module Octopolo
15
15
  end
16
16
  end
17
17
  end
18
-
19
- # Mostly used for tests
20
- unless defined?(GLI)
21
- require 'gli'
22
- include GLI::App
23
- end
@@ -1,6 +1,5 @@
1
1
  require_relative "../git"
2
2
  require_relative "../github"
3
- require_relative "../github/pull_request"
4
3
  require_relative "../scripts"
5
4
  require_relative "../changelog"
6
5
 
@@ -1,6 +1,6 @@
1
1
  require_relative "../scripts"
2
2
  require_relative "../pull_request_merger"
3
- require_relative "../github/label"
3
+ require_relative "../github"
4
4
 
5
5
  module Octopolo
6
6
  module Scripts
@@ -15,7 +15,7 @@ module Octopolo
15
15
  end
16
16
 
17
17
  def self.deployable_label
18
- Octopolo::GitHub::Label.new("deployable", "428BCA")
18
+ Octopolo::GitHub::Label.new(name: "deployable", color: "428BCA")
19
19
  end
20
20
 
21
21
  def initialize(pull_request_id=nil)
@@ -25,8 +25,28 @@ module Octopolo
25
25
  # Public: Perform the script
26
26
  def execute
27
27
  self.pull_request_id ||= cli.prompt("Pull Request ID: ")
28
- PullRequestMerger.perform Git::DEPLOYABLE_PREFIX, Integer(@pull_request_id), :user_notifications => config.user_notifications
29
- Octopolo::GitHub::Label.add_to_pull(Integer(@pull_request_id), Deployable.deployable_label) if config.deployable_label
28
+ merge_and_label
29
+ end
30
+
31
+ def merge_and_label
32
+ if config.deployable_label
33
+ ensure_label_was_created
34
+ else
35
+ PullRequestMerger.perform Git::DEPLOYABLE_PREFIX, Integer(@pull_request_id), :user_notifications => config.user_notifications
36
+ end
37
+ end
38
+
39
+ def ensure_label_was_created
40
+ pull_request = Octopolo::GitHub::PullRequest.new(config.github_repo, @pull_request_id)
41
+ begin
42
+ pull_request.add_labels(Deployable.deployable_label)
43
+ unless PullRequestMerger.perform Git::DEPLOYABLE_PREFIX, Integer(@pull_request_id), :user_notifications => config.user_notifications
44
+ pull_request.remove_labels(Deployable.deployable_label)
45
+ end
46
+ rescue Octokit::Error
47
+
48
+ cli.say("Unable to mark as deployable, please try command again")
49
+ end
30
50
  end
31
51
 
32
52
  end
@@ -1,5 +1,5 @@
1
1
  require_relative "../scripts"
2
- require_relative "../github/pull_request"
2
+ require_relative "../github"
3
3
  require_relative "../pivotal/story_commenter"
4
4
  require_relative "../jira/story_commenter"
5
5
 
@@ -15,6 +15,7 @@ module Octopolo
15
15
  attr_accessor :pivotal_ids
16
16
  attr_accessor :jira_ids
17
17
  attr_accessor :destination_branch
18
+ attr_accessor :label
18
19
 
19
20
  def self.execute(destination_branch=nil)
20
21
  new(destination_branch).execute
@@ -34,6 +35,7 @@ module Octopolo
34
35
  create_pull_request
35
36
  update_pivotal
36
37
  update_jira
38
+ update_label
37
39
  open_pull_request
38
40
  end
39
41
  end
@@ -43,6 +45,7 @@ module Octopolo
43
45
  alert_reserved_and_exit if git.reserved_branch?
44
46
  announce
45
47
  ask_title
48
+ ask_label
46
49
  ask_pivotal_ids if config.use_pivotal_tracker
47
50
  ask_jira_ids if config.use_jira
48
51
  end
@@ -67,6 +70,14 @@ module Octopolo
67
70
  end
68
71
  private :ask_title
69
72
 
73
+ # Private: Ask for a label for the pull request
74
+ def ask_label
75
+ labels = Octopolo::GitHub::Label.all
76
+ response = cli.ask("Label:", Octopolo::GitHub::Label.get_names(labels).unshift("Don't know yet"))
77
+ self.label = Hash[labels.map{|l| [l.name,l]}][response]
78
+ end
79
+ private :ask_label
80
+
70
81
  # Private: Ask for a Pivotal Tracker story IDs
71
82
  def ask_pivotal_ids
72
83
  self.pivotal_ids = cli.prompt("Pivotal Tracker story ID(s):").split(/[\s,]+/)
@@ -122,6 +133,11 @@ module Octopolo
122
133
  end
123
134
  private :update_jira
124
135
 
136
+ def update_label
137
+ pull_request.add_labels(label) if label
138
+ end
139
+ private :update_label
140
+
125
141
  end
126
142
  end
127
143
  end
@@ -1,5 +1,5 @@
1
1
  require_relative "../scripts"
2
- require_relative "../github/pull_request"
2
+ require_relative "../github"
3
3
 
4
4
  module Octopolo
5
5
  module Scripts
@@ -1,3 +1,3 @@
1
1
  module Octopolo
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -1,5 +1,5 @@
1
1
  require "spec_helper"
2
- require_relative "../../../lib/octopolo/github/commit"
2
+ require_relative "../../../lib/octopolo/github"
3
3
 
4
4
  module Octopolo
5
5
  module GitHub
@@ -1,5 +1,5 @@
1
1
  require "spec_helper"
2
- require_relative "../../../lib/octopolo/github/label"
2
+ require_relative "../../../lib/octopolo/github"
3
3
 
4
4
  module Octopolo
5
5
  module GitHub
@@ -8,8 +8,8 @@ module Octopolo
8
8
  let(:label_hash_1) { {name: "low-risk", url: "github.com", color: "343434"} }
9
9
  let(:label_hash_2) { {name: "high-risk", url: "github.com", color: "565656"} }
10
10
  let(:labels_hash) { [label_hash_1,label_hash_2] }
11
- let(:label1) { Label.new("low-risk", "343434") }
12
- let(:label2) { Label.new("high-risk", '565656') }
11
+ let(:label1) { Label.new(name: "low-risk", color: "343434") }
12
+ let(:label2) { Label.new(name: "high-risk", color: '565656') }
13
13
  let(:config) { stub(:config, github_repo: "foo") }
14
14
 
15
15
  subject { Label }
@@ -18,37 +18,37 @@ module Octopolo
18
18
  subject.config = config
19
19
  end
20
20
 
21
+ context "#initialize" do
22
+ it "creates a label from a hash" do
23
+ expect(Label.new(name: "low", color: "151515").name).to eq('low')
24
+ end
25
+ end
26
+
27
+
21
28
  context "#all_labels" do
22
29
  it "gets and returns all labels belonging to a repository" do
23
30
  allow(GitHub).to receive(:labels).and_return(labels_hash)
24
- expect(Label.all_labels).to eq([label1,label2])
31
+ expect(Label.all).to eq([label1,label2])
25
32
  end
26
33
  end
27
34
 
28
35
  context "#first_or_create" do
29
36
  it "finds the existing label and doesn't do anything" do
30
- allow(Label).to receive(:all_labels).and_return([label1,label2])
37
+ allow(Label).to receive(:all).and_return([label1,label2])
31
38
  expect(GitHub).not_to receive(:add_label)
32
39
  Label.first_or_create(label1)
33
40
  end
34
41
 
35
42
  it "doesn't find a label and creates one" do
36
- allow(Label).to receive(:all_labels).and_return([label1,label2])
43
+ allow(Label).to receive(:all).and_return([label1,label2])
37
44
  expect(GitHub).to receive(:add_label).with(config.github_repo, "medium-risk", "454545")
38
- Label.first_or_create(Label.new("medium-risk","454545"))
39
- end
40
- end
41
-
42
- context "#to_label" do
43
- it "returns a label object" do
44
- expect(Label).to receive(:new)
45
- Label.send(:to_label, label_hash_1)
45
+ Label.first_or_create(Label.new(name: "medium-risk", color: "454545"))
46
46
  end
47
47
  end
48
48
 
49
49
  context "#==" do
50
50
  it "returns true if names are same ignoring color" do
51
- expect(label1 == Label.new("low-risk","121212")).to eq(true)
51
+ expect(label1 == Label.new(name: "low-risk",color: "121212")).to eq(true)
52
52
  end
53
53
 
54
54
  it "returns true if names are same ignoring color" do
@@ -56,22 +56,8 @@ module Octopolo
56
56
  end
57
57
  end
58
58
 
59
- context "#add_to_pull" do
60
- let (:pull_number) {007}
61
- it "sends the correct arguments to add_labels_to_pull for multiple labels" do
62
- allow(Label).to receive(:first_or_create)
63
- expect(GitHub).to receive(:add_labels_to_pull).with(config.github_repo, pull_number, ["low-risk","high-risk"])
64
- Label.add_to_pull(pull_number,[label1, label2])
65
- end
66
-
67
- it "sends the correct arguments to add_labels_to_pull for a single label" do
68
- allow(Label).to receive(:first_or_create)
69
- expect(GitHub).to receive(:add_labels_to_pull).with(config.github_repo, pull_number, ["low-risk"])
70
- Label.add_to_pull(pull_number,label1)
71
- end
72
- end
73
59
 
74
- context "#build_labels" do
60
+ context "#build_label_array" do
75
61
  it "returns an array of label when given a label" do
76
62
  allow(Label).to receive(:first_or_create)
77
63
  expect(Label.send(:build_label_array,label1)).to eq([label1])
@@ -1,5 +1,5 @@
1
1
  require "spec_helper"
2
- require_relative "../../../lib/octopolo/github/pull_request_creator"
2
+ require_relative "../../../lib/octopolo/github"
3
3
 
4
4
  module Octopolo
5
5
  module GitHub
@@ -1,5 +1,5 @@
1
1
  require "spec_helper"
2
- require_relative "../../../lib/octopolo/github/pull_request"
2
+ require_relative "../../../lib/octopolo/github"
3
3
 
4
4
  module Octopolo
5
5
  module GitHub
@@ -286,6 +286,47 @@ module Octopolo
286
286
  PullRequest.create(repo_name, options).should == pull_request
287
287
  end
288
288
  end
289
+
290
+ context "labeling" do
291
+ let(:label1) { Label.new(name: "low-risk", color: "343434") }
292
+ let(:label2) { Label.new(name: "high-risk", color: '565656') }
293
+ let(:pull_request) { PullRequest.new repo_name, pr_number }
294
+
295
+ context "#add_labels" do
296
+ it "sends the correct arguments to add_labels_to_pull for multiple labels" do
297
+ allow(Label).to receive(:build_label_array) {[label1,label2]}
298
+ expect(GitHub).to receive(:add_labels_to_pull).with(repo_name, pr_number, ["low-risk","high-risk"])
299
+ pull_request.add_labels([label1, label2])
300
+ end
301
+
302
+ it "sends the correct arguments to add_labels_to_pull for a single label" do
303
+ allow(Label).to receive(:build_label_array) {[label1]}
304
+ expect(GitHub).to receive(:add_labels_to_pull).with(repo_name, pr_number, ["low-risk"])
305
+ pull_request.add_labels(label1)
306
+ end
307
+ end
308
+
309
+ context "#remove_from_pull" do
310
+
311
+ it "sends the correct arguments to remove_label" do
312
+ allow(Label).to receive(:build_label_array) {[label1]}
313
+ expect(GitHub).to receive(:remove_label).with(repo_name, pr_number, "low-risk")
314
+ pull_request.remove_labels(label1)
315
+ end
316
+
317
+ it "calls remove_label only once" do
318
+ allow(Label).to receive(:build_label_array) {[label1]}
319
+ expect(GitHub).to receive(:remove_label).once
320
+ pull_request.remove_labels(label1)
321
+ end
322
+
323
+ it "calls remove_label twice" do
324
+ allow(Label).to receive(:build_label_array) {[label1, label2]}
325
+ expect(GitHub).to receive(:remove_label).twice
326
+ pull_request.remove_labels([label1,label2])
327
+ end
328
+ end
329
+ end
289
330
  end
290
331
  end
291
332
  end
@@ -1,5 +1,5 @@
1
1
  require "spec_helper"
2
- require_relative "../../../lib/octopolo/github/user"
2
+ require_relative "../../../lib/octopolo/github"
3
3
 
4
4
  module Octopolo
5
5
  module GitHub
@@ -9,13 +9,45 @@ module Octopolo
9
9
  before { Deployable.any_instance.stub(:cli => cli, :config => config) }
10
10
 
11
11
  context "#execute" do
12
- context "with a PR passed in via the command args" do
13
- subject { Deployable.new 42 }
12
+ subject { Deployable.new 42}
13
+ it "calls merge_and_label" do
14
+ expect(subject).to receive(:merge_and_label)
15
+ subject.execute
16
+ end
17
+
18
+ context "#merge_and_label" do
19
+ before do
20
+ allow(PullRequestMerger).to receive(:perform)
21
+ end
22
+
23
+ context "deployable_label is set to true" do
24
+ it "calls ensure_label_was_created" do
25
+ expect(subject).to receive(:ensure_label_was_created)
26
+ subject.execute
27
+ end
28
+ end
29
+
30
+ context "deployable_label is set to false " do
31
+ let(:config) { stub(:user_notifications => ['NickLaMuro'], :github_repo => 'foo', :deployable_label => false) }
32
+ it "skips add_to_pull when deployable_label is false" do
33
+ expect(subject).to_not receive(:ensure_label_was_created)
34
+ subject.execute
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ context "#ensure_label_was_created" do
41
+ subject { Deployable.new 42}
42
+ let(:pull_request) {Octopolo::GitHub::PullRequest.new('foo', subject.pull_request_id, nil)}
43
+ before do
44
+ allow_any_instance_of(Octopolo::GitHub::PullRequest).to receive(:add_labels)
45
+ end
14
46
 
47
+ context "with a PR passed in via the command args" do
15
48
  it "delegates the work to PullRequestMerger" do
16
- allow(Octopolo::GitHub::Label).to receive(:add_to_pull)
17
- PullRequestMerger.should_receive(:perform).with(Git::DEPLOYABLE_PREFIX, 42, :user_notifications => ["NickLaMuro"])
18
- subject.execute
49
+ expect(PullRequestMerger).to receive(:perform).with(Git::DEPLOYABLE_PREFIX, 42, :user_notifications => ["NickLaMuro"]) {true}
50
+ subject.ensure_label_was_created
19
51
  end
20
52
  end
21
53
 
@@ -30,8 +62,7 @@ module Octopolo
30
62
  end
31
63
 
32
64
  it "delegates the work to PullRequestMerger" do
33
- allow(Octopolo::GitHub::Label).to receive(:add_to_pull)
34
- PullRequestMerger.should_receive(:perform).with(Git::DEPLOYABLE_PREFIX, 42, :user_notifications => ["NickLaMuro"])
65
+ expect(PullRequestMerger).to receive(:perform).with(Git::DEPLOYABLE_PREFIX, 42, :user_notifications => ["NickLaMuro"]) {true}
35
66
  subject.execute
36
67
  end
37
68
  end
@@ -49,27 +80,16 @@ module Octopolo
49
80
  end
50
81
  end
51
82
 
52
- context "with various values for deployable_label" do
53
- let(:deployable_label) {Octopolo::GitHub::Label.new("deployable", "428BCA")}
54
- subject { Deployable.new 42 }
55
- before do
56
- allow(PullRequestMerger).to receive(:perform)
57
- end
58
-
59
- it "calls add_to_pull when deployable_label is true" do
60
- expect(Octopolo::GitHub::Label).to receive(:add_to_pull).with(42,deployable_label)
61
- subject.execute
62
- end
83
+ context "when it creates a label successfully" do
63
84
 
64
- context "deployable_label is set to false " do
65
- let(:config) { stub(:user_notifications => ['NickLaMuro'], :github_repo => 'foo', :deployable_label => false) }
66
- it "skips add_to_pull when deployable_label is false" do
67
- expect(Octopolo::GitHub::Label).to_not receive(:add_to_pull).with(42,deployable_label)
68
- subject.execute
69
- end
85
+ it "calls remove_label when pull_request_merge fails" do
86
+ allow(PullRequestMerger).to receive(:perform) {nil}
87
+ expect_any_instance_of(Octopolo::GitHub::PullRequest).to receive(:remove_labels)
88
+ subject.ensure_label_was_created
70
89
  end
71
90
  end
72
91
  end
92
+
73
93
  end
74
94
  end
75
95
  end
@@ -40,11 +40,12 @@ module Octopolo
40
40
  context "#execute" do
41
41
  it "if connected to GitHub, asks some questions, creates the pull request, and opens it" do
42
42
  GitHub.should_receive(:connect).and_yield
43
- subject.should_receive(:ask_questionaire)
44
- subject.should_receive(:create_pull_request)
45
- subject.should_receive(:update_pivotal)
46
- subject.should_receive(:update_jira)
47
- subject.should_receive(:open_pull_request)
43
+ expect(subject).to receive(:ask_questionaire)
44
+ expect(subject).to receive(:create_pull_request)
45
+ expect(subject).to receive(:update_pivotal)
46
+ expect(subject).to receive(:update_jira)
47
+ expect(subject).to receive(:update_label)
48
+ expect(subject).to receive(:open_pull_request)
48
49
 
49
50
  subject.execute
50
51
  end
@@ -57,10 +58,11 @@ module Octopolo
57
58
 
58
59
  context "#ask_questionaire" do
59
60
  it "asks appropriate questions to create a pull request" do
60
- subject.should_receive(:announce)
61
- subject.should_receive(:ask_title)
62
- subject.should_receive(:ask_pivotal_ids)
63
- subject.should_receive(:ask_jira_ids)
61
+ expect(subject).to receive(:announce)
62
+ expect(subject).to receive(:ask_title)
63
+ expect(subject).to receive(:ask_pivotal_ids)
64
+ expect(subject).to receive(:ask_jira_ids)
65
+ expect(subject).to receive(:ask_label)
64
66
 
65
67
  subject.send(:ask_questionaire)
66
68
  end
@@ -71,6 +73,7 @@ module Octopolo
71
73
  subject.stub(:ask_title)
72
74
  subject.stub(:ask_pivotal_ids)
73
75
  subject.stub(:ask_jira_ids)
76
+ subject.stub(:ask_label)
74
77
  end
75
78
  it "exits when branch name is reserved" do
76
79
  subject.git.stub(:reserved_branch?).and_return true
@@ -111,6 +114,18 @@ module Octopolo
111
114
  end
112
115
  end
113
116
 
117
+ context "#ask_label" do
118
+ let(:label1) {Octopolo::GitHub::Label.new(name: "low-risk", color: '151515')}
119
+ let(:label2) {Octopolo::GitHub::Label.new(name: "high-risk", color: '151515')}
120
+ let(:choices) {["Don't know yet", "low-risk","high-risk"]}
121
+ it "asks for and capture a label" do
122
+ allow(Octopolo::GitHub::Label).to receive(:all) {[label1,label2]}
123
+ allow(Octopolo::GitHub::Label).to receive(:get_names) {choices}
124
+ expect(cli).to receive(:ask).with("Label:",choices)
125
+ subject.send(:ask_label)
126
+ end
127
+ end
128
+
114
129
  context "#ask_pivotal_ids" do
115
130
  let(:ids_with_whitespace) { "123 456" }
116
131
  let(:ids_with_commas) { "234, 567" }
@@ -197,6 +212,27 @@ module Octopolo
197
212
  Jira::StoryCommenter.should_receive(:new).with("234", "test") { story_commenter }
198
213
  subject.send(:update_jira)
199
214
  end
215
+ end
216
+
217
+ context "#update_label" do
218
+ before do
219
+ subject.label = "high-risk"
220
+ subject.pull_request = stub()
221
+ end
222
+ it "calls update_label with proper arguments" do
223
+ expect(subject.pull_request).to receive(:add_labels).with('high-risk')
224
+ subject.send(:update_label)
225
+ end
226
+
227
+ context "doesn't know yet label" do
228
+ before do
229
+ subject.label = nil
230
+ end
231
+ it "doesn't call update_label when label is don't know yet" do
232
+ expect(subject.pull_request).to_not receive(:add_labels)
233
+ subject.send(:update_label)
234
+ end
235
+ end
200
236
 
201
237
  end
202
238
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octopolo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Byrne
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-23 00:00:00.000000000 Z
12
+ date: 2014-07-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake