octopolo 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f9347171f8e40371369adff2ff3182e3f5feae9c
4
- data.tar.gz: 5b8cc4f765258a60c3402c55d7fd98e8c31802c1
3
+ metadata.gz: ce85f0e7584c097f6057eb0f0290419beadbb7c0
4
+ data.tar.gz: 2aa223c174ba9b35fb2a2c91fc3bb9c951d9d29e
5
5
  SHA512:
6
- metadata.gz: 4bad6818445d9e8bae0f600cbc7ae136eb997de6b2848e76bc122039d458cdb4df347dec16c66235a0265298a4b91922f7181de146cd5e27eabdba1ca1d644df
7
- data.tar.gz: 0514539626222b2effd7efa5a61c2672f0a4f02c9bde6a67ff9c1384e338911263ba7a829194bb46c16fb6802be632f591c29afa7130b3fd1e6da52247da7d4a
6
+ metadata.gz: 685c5bc181c5cf915e86b8359ea8edd1224c84a03da2847cd5f3c17d594186d602ae34bb9d52bee20ac49fb5aae528acbd75390b1ec8fa9858d4c885f9b27a30
7
+ data.tar.gz: 88a1262406cae5fb72644cbbc1354820fa7f0a1b7917c6593cab6618a2221f6ee5ed3e4053d353d9ae5ef701e14d66eb2e64bf0e430d0df2ac10044e6a2bc3ad
data/CHANGELOG.markdown CHANGED
@@ -1,3 +1,12 @@
1
+ #### v1.1.0
2
+ * Auto pull request
3
+
4
+ > Scott Trenda, Brian Bergstrom: Chris Arcand: https://github.com/sportngin/octopolo/pull/70
5
+
6
+ * issue64 - improve git if_clean check
7
+
8
+ > newzac: Scott Trenda, Brian Bergstrom: https://github.com/sportngin/octopolo/pull/69
9
+
1
10
  #### v1.0.2
2
11
  * Fix Rake Depenency Issues
3
12
 
data/lib/octopolo/git.rb CHANGED
@@ -5,6 +5,7 @@ module Octopolo
5
5
  class Git
6
6
  NO_BRANCH = "(no branch)"
7
7
  DEFAULT_DIRTY_MESSAGE = "Your Git index is not clean. Commit, stash, or otherwise clean up the index before continuing."
8
+ DIRTY_CONFIRM_MESSAGE = "Your Git index is not clean. Do you want to continue?"
8
9
  # we use date-based tags, so look for anything starting with a 4-digit year
9
10
  RELEASE_TAG_FILTER = /^\d{4}.*/
10
11
  RECENT_TAG_LIMIT = 9
@@ -109,7 +110,7 @@ module Octopolo
109
110
 
110
111
  # Public: Perform the block if the Git index is clean
111
112
  def self.if_clean(message=DEFAULT_DIRTY_MESSAGE)
112
- if clean?
113
+ if clean? || cli.ask_boolean(DIRTY_CONFIRM_MESSAGE)
113
114
  yield
114
115
  else
115
116
  alert_dirty_index message
@@ -122,6 +123,7 @@ module Octopolo
122
123
  cli.say message
123
124
  cli.say " "
124
125
  perform "status"
126
+ raise DirtyIndex
125
127
  end
126
128
 
127
129
  # Public: Merge the given remote branch into the current branch
@@ -276,5 +278,6 @@ module Octopolo
276
278
  CheckoutFailed = Class.new(StandardError)
277
279
  MergeFailed = Class.new(StandardError)
278
280
  NoBranchOfType = Class.new(StandardError)
281
+ DirtyIndex = Class.new(StandardError)
279
282
  end
280
283
  end
@@ -6,6 +6,10 @@ module Octopolo
6
6
  module GitHub
7
7
  class PullRequest < Issue
8
8
 
9
+ extend CLIWrapper
10
+ extend ConfigWrapper
11
+ extend UserConfigWrapper
12
+
9
13
  # Public: All closed pull requests for a given repo
10
14
  #
11
15
  # repo_name - Full name ("account/repo") of the repo in question
@@ -65,6 +69,24 @@ module Octopolo
65
69
  @commits ||= Commit.for_pull_request self
66
70
  end
67
71
 
72
+ def self.current
73
+ current_branch = Git.current_branch
74
+ query = "repo:#{config.github_repo} type:pr is:open head:#{current_branch}"
75
+ pulls = GitHub.search_issues(query)
76
+ if pulls.total_count!= 1
77
+ cli.say "Multiple pull requests found for branch #{current_branch}" if pulls.total_count > 1
78
+ cli.say "No pull request found for branch #{current_branch}" if pulls.total_count < 1
79
+ return nil
80
+ else
81
+ cli.say "Pull request for current branch is number #{pulls.items.first.number}"
82
+ pulls.items.first
83
+
84
+ end
85
+ rescue => e
86
+ cli.say "An error occurred while getting the current branch: #{e.message}"
87
+ return nil
88
+ end
89
+
68
90
  end
69
91
  end
70
92
  end
@@ -113,6 +113,10 @@ module Octopolo
113
113
  client.add_labels_to_an_issue *args
114
114
  end
115
115
 
116
+ def self.search_issues *args
117
+ client.search_issues *args
118
+ end
119
+
116
120
 
117
121
  # now that you've set up your credentials, try again
118
122
  TryAgain = Class.new(StandardError)
@@ -24,6 +24,10 @@ module Octopolo
24
24
 
25
25
  # Public: Perform the script
26
26
  def execute
27
+ if (!self.pull_request_id)
28
+ current = GitHub::PullRequest.current
29
+ self.pull_request_id = current.number if current
30
+ end
27
31
  self.pull_request_id ||= cli.prompt("Pull Request ID: ")
28
32
  GitHub.connect do
29
33
  if config.deployable_label
@@ -18,6 +18,10 @@ module Octopolo
18
18
 
19
19
  # Public: Perform the script
20
20
  def execute
21
+ if (!self.pull_request_id)
22
+ current = GitHub::PullRequest.current
23
+ self.pull_request_id = current.number if current
24
+ end
21
25
  self.pull_request_id ||= cli.prompt("Pull Request ID: ")
22
26
  PullRequestMerger.perform Git::STAGING_PREFIX, Integer(pull_request_id)
23
27
  end
@@ -1,3 +1,3 @@
1
1
  module Octopolo
2
- VERSION = "1.0.2"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -125,6 +125,8 @@ module Octopolo
125
125
  context ".if_clean" do
126
126
  let(:custom_message) { "Some other message" }
127
127
 
128
+ before { Git.cli = cli }
129
+
128
130
  it "performs the block if the git index is clean" do
129
131
  Git.should_receive(:clean?) { true }
130
132
  Math.should_receive(:log).with(1)
@@ -134,18 +136,31 @@ module Octopolo
134
136
  end
135
137
  end
136
138
 
137
- it "does not perform the block if the git index is not clean" do
139
+ it "performs the block if the git index is not clean and user responds yes" do
138
140
  Git.should_receive(:clean?) { false }
141
+ cli.should_receive(:ask_boolean).with(Git::DIRTY_CONFIRM_MESSAGE) { true }
142
+ Math.should_receive(:log).with(1)
143
+
144
+ Git.if_clean do
145
+ Math.log 1
146
+ end
147
+ end
148
+
149
+ it "does not perform the block if the git index is not clean and user responds no" do
150
+ Git.should_receive(:clean?) { false }
151
+ cli.should_receive(:ask_boolean).with(Git::DIRTY_CONFIRM_MESSAGE) { false}
139
152
  Math.should_not_receive(:log)
140
153
  Git.should_receive(:alert_dirty_index).with(Git::DEFAULT_DIRTY_MESSAGE)
141
154
 
155
+
142
156
  Git.if_clean do
143
157
  Math.log 1
144
158
  end
145
159
  end
146
160
 
147
- it "prints a custom message if git index is not clean" do
161
+ it "prints a custom message if git index is not clean and user responds no" do
148
162
  Git.should_receive(:clean?) { false }
163
+ cli.should_receive(:ask_boolean).with(Git::DIRTY_CONFIRM_MESSAGE) { false }
149
164
  Math.should_not_receive(:log)
150
165
  Git.should_receive(:alert_dirty_index).with(custom_message)
151
166
 
@@ -166,7 +181,7 @@ module Octopolo
166
181
  cli.should_receive(:say).with(" ")
167
182
  Git.should_receive(:perform).with("status")
168
183
 
169
- Git.alert_dirty_index message
184
+ expect{Git.alert_dirty_index message}.to raise_error
170
185
  end
171
186
  end
172
187
 
@@ -287,6 +287,50 @@ module Octopolo
287
287
  end
288
288
  end
289
289
 
290
+ context ".current" do
291
+ let(:branch_name) { "branch-name" }
292
+ let(:error_message) { "some error message" }
293
+ let(:pull) { PullRequest.new repo_name, pr_number }
294
+
295
+ before do
296
+ Octopolo.config.stub(:github_repo) { repo_name }
297
+ end
298
+
299
+ it "calls GitHub.pull_requests with the current repo/branch and return a single pull request" do
300
+ Git.should_receive(:current_branch) { branch_name }
301
+ GitHub.should_receive(:search_issues) { double(total_count: 1, items: [pull]) }
302
+ PullRequest.current.should == pull
303
+ end
304
+
305
+ it "returns nil when Git.current_branch fails" do
306
+ Git.should_receive(:current_branch) { raise error_message }
307
+ CLI.should_receive(:say).with("An error occurred while getting the current branch: #{error_message}")
308
+ PullRequest.current.should == nil
309
+ end
310
+
311
+ it "returns nil when GitHub.pull_requests fails" do
312
+ Git.should_receive(:current_branch) { branch_name }
313
+ GitHub.should_receive(:search_issues) { raise error_message }
314
+ CLI.should_receive(:say).with("An error occurred while getting the current branch: #{error_message}")
315
+ PullRequest.current.should == nil
316
+ end
317
+
318
+ it "returns nil when more than one PR exists" do
319
+ Git.should_receive(:current_branch) { branch_name }
320
+ GitHub.should_receive(:search_issues) { double(total_count: 2, items: [pull, pull]) }
321
+ CLI.should_receive(:say).with("Multiple pull requests found for branch #{branch_name}")
322
+ PullRequest.current.should == nil
323
+ end
324
+
325
+ it "returns nil when no PR exists" do
326
+ Git.should_receive(:current_branch) { branch_name }
327
+ GitHub.should_receive(:search_issues) { double(total_count: 0, items: []) }
328
+ CLI.should_receive(:say).with("No pull request found for branch #{branch_name}")
329
+ PullRequest.current.should == nil
330
+ end
331
+
332
+ end
333
+
290
334
  context "labeling" do
291
335
  let(:label1) { Label.new(name: "low-risk", color: "343434") }
292
336
  let(:label2) { Label.new(name: "high-risk", color: '565656') }
@@ -10,7 +10,7 @@ module Octopolo
10
10
  let(:config) { stub(user_notifications: ['NickLaMuro'],
11
11
  github_repo: 'grumpy_cat',
12
12
  deployable_label: true) }
13
- let(:pull_request) { stub(add_labels: true, remove_labels: true) }
13
+ let(:pull_request) { stub(add_labels: true, remove_labels: true, number: 7) }
14
14
  before do
15
15
  allow(subject).to receive(:cli) { cli }
16
16
  allow(subject).to receive(:config) { config }
@@ -33,10 +33,26 @@ module Octopolo
33
33
  context "without a PR ID passed in with the command" do
34
34
  subject { described_class.new }
35
35
 
36
- it "prompts for a PR ID" do
37
- cli.should_receive(:prompt)
38
- .with("Pull Request ID: ")
39
- .and_return("42")
36
+ context "with an existing PR for the current branch" do
37
+ before do
38
+ GitHub::PullRequest.should_receive(:current) { pull_request }
39
+ end
40
+
41
+ it "takes the pull requests ID from the current branch" do
42
+ PullRequestMerger.should_receive(:perform).with(Git::DEPLOYABLE_PREFIX, pull_request.number, :user_notifications => config.user_notifications)
43
+ end
44
+ end
45
+
46
+ context "without an existing PR for the current branch" do
47
+ before do
48
+ GitHub::PullRequest.should_receive(:current) { nil }
49
+ end
50
+
51
+ it "prompts for a PR ID" do
52
+ cli.should_receive(:prompt)
53
+ .with("Pull Request ID: ")
54
+ .and_return("42")
55
+ end
40
56
  end
41
57
  end
42
58
 
@@ -20,28 +20,45 @@ module Octopolo
20
20
  context "with no PR passed in from the command args" do
21
21
  subject { StageUp.new }
22
22
 
23
- context "with a PR passed in through the cli" do
23
+ context "with an existing PR for the current branch" do
24
24
  before do
25
- cli.should_receive(:prompt)
26
- .with("Pull Request ID: ")
27
- .and_return("42")
25
+ GitHub::PullRequest.should_receive(:current) { GitHub::PullRequest.new("account/repo", 7) }
28
26
  end
29
27
 
30
- it "delegates the work to PullRequestMerger" do
31
- PullRequestMerger.should_receive(:perform).with(Git::STAGING_PREFIX, 42)
28
+ it "takes the pull requests ID from the current branch" do
29
+ PullRequestMerger.should_receive(:perform).with(Git::STAGING_PREFIX, 7)
32
30
  subject.execute
33
31
  end
34
32
  end
35
33
 
36
- context "with no PR passed in from the cli" do
34
+ context "without an existing PR for the current branch" do
37
35
  before do
38
- cli.should_receive(:prompt)
39
- .with("Pull Request ID: ")
40
- .and_return("foo")
36
+ GitHub::PullRequest.should_receive(:current) { nil }
41
37
  end
42
38
 
43
- it "delegates the work to PullRequestMerger" do
44
- expect{ subject.execute }.to raise_error(ArgumentError)
39
+ context "with a PR passed in through the cli" do
40
+ before do
41
+ cli.should_receive(:prompt)
42
+ .with("Pull Request ID: ")
43
+ .and_return("42")
44
+ end
45
+
46
+ it "delegates the work to PullRequestMerger" do
47
+ PullRequestMerger.should_receive(:perform).with(Git::STAGING_PREFIX, 42)
48
+ subject.execute
49
+ end
50
+ end
51
+
52
+ context "with no PR passed in from the cli" do
53
+ before do
54
+ cli.should_receive(:prompt)
55
+ .with("Pull Request ID: ")
56
+ .and_return("foo")
57
+ end
58
+
59
+ it "delegates the work to PullRequestMerger" do
60
+ expect{ subject.execute }.to raise_error(ArgumentError)
61
+ end
45
62
  end
46
63
  end
47
64
  end
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: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Byrne