octopolo 0.3.0 → 0.3.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
- YWJiMDZmMWJkMWE1YjhkOWY2YzY3MDY4YWI3M2E0MDRmZDUxNDg3Mg==
4
+ ODRlOGY4MDgyY2EwZDQ0NDQ3NmZkNjgxMjNlNmRmOWMzYjg1YTNmYg==
5
5
  data.tar.gz: !binary |-
6
- YjFhNGU3NzdkODFiYmM4YjBlYjIzNjc2ZWI5Y2E2YzVmOWM0OGViMQ==
6
+ ZGU2ZGQ4ZWYxZTIzNGY0MTA2NDk2YTY2ZTliMDllYTg0MzUwNWM0Mw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Njk1YjE0Mjk0ZjRhZThhZGE4OGU2YTE0ZmI3MjM3ZjEzYTEzOGI0NmZiN2E5
10
- NjcxZWMxYzQ5ZTg3Y2VlMDMzMzA2NDFjZTQ5NDUzMTdkNGNmNjcyZmEwZTBj
11
- YTY3YzNiNTE2OTEyOGFlZTQ4OTIwYjgzNDdkMmZiN2VlNDQxODY=
9
+ MmQwZmFjY2ZjMzZmNzBmMzllMTY5OTc0YjZmMTk3NzEzYWFjNDRkZjUwZmQz
10
+ OTY3NWRlMzNkYTBlM2UwMzgzMDg2MmJjNTBmMjYxMTE3M2Q5OTc4YzNkMDdi
11
+ NDlhMDNkYWY4ODVmMDIyYmFhMDZlZjNmYjFiYzllOGNlNDljMjM=
12
12
  data.tar.gz: !binary |-
13
- NDA2OTA3ODIyNTk5NWQxOTU1ZTdkZDBhNWE0ODkxNGUzNjgwMDJhYWQwNDkw
14
- MGJmYzgxZjFhZDgxZDYxMDQwMzQ3NmNlOTliNTM1ZGQzODg2OGJmNDI4NzFl
15
- OTk5ODQyZjliMTNjYjE3YmIzYjQ4ZWYyNjZlZDM3YjBkZTA1NmY=
13
+ MmY5ZmM5ZTVmZmM0YjBiOWE0NzA1ZjdhNjk1MTNmODgyMmMyMTM3ZmJiYTA0
14
+ MTUwM2NhY2JmNzc0YjFlYzJkYzA5NWZjYWY1N2FlYmY0NDY3YTJiMTc0ZTVk
15
+ MDI3YTQ4ZDg5YmQ2ZDBhNWVmNTE3Y2E1Y2M2M2I5MGVlZjZiMzg=
@@ -1,3 +1,4 @@
1
+ #### v0.3.1
1
2
  #### v0.3.0
2
3
  #### v0.2.1
3
4
  #### v0.1.4
@@ -35,7 +35,7 @@ module Octopolo
35
35
  def self.client(options = {})
36
36
  Octokit::Client.new(options.merge(login: user_config.github_user, access_token: user_config.github_token))
37
37
  rescue UserConfig::MissingGitHubAuth
38
- raise TryAgain, "No GitHub API token stored. Please run `bundle exec github-auth` to generate your token."
38
+ raise TryAgain, "No GitHub API token stored. Please run `op github-auth` to generate your token."
39
39
  end
40
40
 
41
41
  # Public: A GitHub client configured to crawl through pages
@@ -48,7 +48,7 @@ module Octopolo
48
48
  # we don't care about the output, just try to hit the API
49
49
  client.user && nil
50
50
  rescue Octokit::Unauthorized
51
- raise BadCredentials, "Your stored credentials were rejected by GitHub. Run `bundle exec github-auth` to generate a new token."
51
+ raise BadCredentials, "Your stored credentials were rejected by GitHub. Run `op github-auth` to generate a new token."
52
52
  end
53
53
 
54
54
  def self.pull_request *args
@@ -53,7 +53,7 @@ module Octopolo
53
53
  when GitHub::PullRequest::CommentFailed
54
54
  cli.say "Unable to write comment. Please navigate to #{pull_request.url} and add the comment, '#{comment_body}'"
55
55
  else
56
- cli.say "An uknown error occured: #{e.class.to_s}"
56
+ cli.say "An unknown error occurred: #{e.class.to_s}"
57
57
  end
58
58
  false
59
59
  end
@@ -25,30 +25,30 @@ module Octopolo
25
25
  # Public: Perform the script
26
26
  def execute
27
27
  self.pull_request_id ||= cli.prompt("Pull Request ID: ")
28
- merge_and_label
28
+ GitHub.connect do
29
+ if config.deployable_label
30
+ with_labelling do
31
+ merge
32
+ end
33
+ else
34
+ merge
35
+ end
36
+ end
29
37
  end
30
38
 
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
39
+ def merge
40
+ PullRequestMerger.perform Git::DEPLOYABLE_PREFIX, Integer(@pull_request_id), :user_notifications => config.user_notifications
37
41
  end
42
+ private :merge
38
43
 
39
- def ensure_label_was_created
44
+ def with_labelling(&block)
40
45
  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")
46
+ pull_request.add_labels(Deployable.deployable_label)
47
+ unless yield
48
+ pull_request.remove_labels(Deployable.deployable_label)
49
49
  end
50
50
  end
51
-
51
+ private :with_labelling
52
52
  end
53
53
  end
54
54
  end
@@ -1,3 +1,3 @@
1
1
  module Octopolo
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -24,7 +24,7 @@ module Octopolo
24
24
  it "properly handles if the github authentication isn't configured" do
25
25
  user_config.should_receive(:github_user).and_raise(UserConfig::MissingGitHubAuth)
26
26
  Scripts::GithubAuth.should_not_receive(:invoke)
27
- expect { GitHub.client }.to raise_error(GitHub::TryAgain, "No GitHub API token stored. Please run `bundle exec github-auth` to generate your token.")
27
+ expect { GitHub.client }.to raise_error(GitHub::TryAgain, "No GitHub API token stored. Please run `op github-auth` to generate your token.")
28
28
  end
29
29
  end
30
30
 
@@ -4,92 +4,84 @@ require "octopolo/scripts/deployable"
4
4
  module Octopolo
5
5
  module Scripts
6
6
  describe Deployable do
7
- let(:cli) { stub(:Cli) }
8
- let(:config) { stub(:user_notifications => ['NickLaMuro'], :github_repo => 'foo', :deployable_label => true) }
9
- before { Deployable.any_instance.stub(:cli => cli, :config => config) }
7
+ subject { described_class.new 42 }
8
+
9
+ let(:cli) { stub(prompt: 42) }
10
+ let(:config) { stub(user_notifications: ['NickLaMuro'],
11
+ github_repo: 'grumpy_cat',
12
+ deployable_label: true) }
13
+ let(:pull_request) { stub(add_labels: true, remove_labels: true) }
14
+ before do
15
+ allow(subject).to receive(:cli) { cli }
16
+ allow(subject).to receive(:config) { config }
17
+ allow(Octopolo::GitHub::PullRequest).to receive(:new) { pull_request }
18
+ allow(PullRequestMerger).to receive(:perform) { true }
19
+ allow(Octopolo::GitHub).to receive(:check_connection) { true }
20
+ end
10
21
 
11
22
  context "#execute" do
12
- subject { Deployable.new 42}
13
- it "calls merge_and_label" do
14
- expect(subject).to receive(:merge_and_label)
23
+ after do
15
24
  subject.execute
16
25
  end
17
26
 
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
27
+ context "with a PR ID passed in with the command" do
28
+ it "doesn't prompt for a PR ID" do
29
+ cli.should_not_receive(:prompt)
36
30
  end
37
31
  end
38
- end
39
32
 
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
33
+ context "without a PR ID passed in with the command" do
34
+ subject { described_class.new }
46
35
 
47
- context "with a PR passed in via the command args" do
48
- it "delegates the work to PullRequestMerger" do
49
- expect(PullRequestMerger).to receive(:perform).with(Git::DEPLOYABLE_PREFIX, 42, :user_notifications => ["NickLaMuro"]) {true}
50
- subject.ensure_label_was_created
36
+ it "prompts for a PR ID" do
37
+ cli.should_receive(:prompt)
38
+ .with("Pull Request ID: ")
39
+ .and_return("42")
51
40
  end
52
41
  end
53
42
 
54
- context "with no PR passed in from the command args" do
55
- subject { Deployable.new }
43
+ context "with labelling enabled" do
44
+ it "adds the deployable label" do
45
+ pull_request.should_receive(:add_labels)
46
+ end
56
47
 
57
- context "with a PR passed in through the cli" do
48
+ context "when merge to deployable fails" do
58
49
  before do
59
- cli.should_receive(:prompt)
60
- .with("Pull Request ID: ")
61
- .and_return("42")
50
+ allow(PullRequestMerger).to receive(:perform) { false }
62
51
  end
63
52
 
64
- it "delegates the work to PullRequestMerger" do
65
- expect(PullRequestMerger).to receive(:perform).with(Git::DEPLOYABLE_PREFIX, 42, :user_notifications => ["NickLaMuro"]) {true}
66
- subject.execute
53
+ it "removes the deployable label" do
54
+ pull_request.should_receive(:remove_labels)
55
+ end
56
+ end
57
+
58
+ context "when the merge to deployable succeeds" do
59
+ it "doesn't remove the deployable label" do
60
+ pull_request.should_not_receive(:remove_labels)
67
61
  end
68
62
  end
69
63
 
70
- context "with no PR passed in from the cli" do
64
+ context "with an invalid auth token" do
71
65
  before do
72
- cli.should_receive(:prompt)
73
- .with("Pull Request ID: ")
74
- .and_return("foo")
66
+ Octopolo::GitHub.stub(:check_connection) { raise GitHub::BadCredentials, "Your stored credentials were rejected by GitHub. Run `op github-auth` to generate a new token." }
75
67
  end
76
68
 
77
- it "delegates the work to PullRequestMerger" do
78
- expect{ subject.execute }.to raise_error(ArgumentError)
69
+ it "should give a helpful error message saying your token is invalid" do
70
+ expect(CLI).to receive(:say).with("Your stored credentials were rejected by GitHub. Run `op github-auth` to generate a new token.")
79
71
  end
80
72
  end
81
73
  end
82
74
 
83
- context "when it creates a label successfully" do
75
+ context "with labelling disabled" do
76
+ let(:config) { stub(user_notifications: ['NickLaMuro'],
77
+ github_repo: 'grumpy_cat',
78
+ deployable_label: false) }
84
79
 
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
80
+ it "doesn't add the deployable label" do
81
+ pull_request.should_not_receive(:add_labels)
89
82
  end
90
83
  end
91
84
  end
92
-
93
85
  end
94
86
  end
95
87
  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: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Byrne