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 +8 -8
- data/CHANGELOG.markdown +1 -0
- data/lib/octopolo/github.rb +2 -2
- data/lib/octopolo/pull_request_merger.rb +1 -1
- data/lib/octopolo/scripts/deployable.rb +17 -17
- data/lib/octopolo/version.rb +1 -1
- data/spec/octopolo/github_spec.rb +1 -1
- data/spec/octopolo/scripts/deployable_spec.rb +48 -56
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ODRlOGY4MDgyY2EwZDQ0NDQ3NmZkNjgxMjNlNmRmOWMzYjg1YTNmYg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZGU2ZGQ4ZWYxZTIzNGY0MTA2NDk2YTY2ZTliMDllYTg0MzUwNWM0Mw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MmQwZmFjY2ZjMzZmNzBmMzllMTY5OTc0YjZmMTk3NzEzYWFjNDRkZjUwZmQz
|
10
|
+
OTY3NWRlMzNkYTBlM2UwMzgzMDg2MmJjNTBmMjYxMTE3M2Q5OTc4YzNkMDdi
|
11
|
+
NDlhMDNkYWY4ODVmMDIyYmFhMDZlZjNmYjFiYzllOGNlNDljMjM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MmY5ZmM5ZTVmZmM0YjBiOWE0NzA1ZjdhNjk1MTNmODgyMmMyMTM3ZmJiYTA0
|
14
|
+
MTUwM2NhY2JmNzc0YjFlYzJkYzA5NWZjYWY1N2FlYmY0NDY3YTJiMTc0ZTVk
|
15
|
+
MDI3YTQ4ZDg5YmQ2ZDBhNWVmNTE3Y2E1Y2M2M2I5MGVlZjZiMzg=
|
data/CHANGELOG.markdown
CHANGED
data/lib/octopolo/github.rb
CHANGED
@@ -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 `
|
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 `
|
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
|
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
|
-
|
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
|
32
|
-
|
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
|
44
|
+
def with_labelling(&block)
|
40
45
|
pull_request = Octopolo::GitHub::PullRequest.new(config.github_repo, @pull_request_id)
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
data/lib/octopolo/version.rb
CHANGED
@@ -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 `
|
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
|
-
|
8
|
-
|
9
|
-
|
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
|
-
|
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 "
|
19
|
-
|
20
|
-
|
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
|
-
|
41
|
-
|
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
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
55
|
-
|
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 "
|
48
|
+
context "when merge to deployable fails" do
|
58
49
|
before do
|
59
|
-
|
60
|
-
.with("Pull Request ID: ")
|
61
|
-
.and_return("42")
|
50
|
+
allow(PullRequestMerger).to receive(:perform) { false }
|
62
51
|
end
|
63
52
|
|
64
|
-
it "
|
65
|
-
|
66
|
-
|
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
|
64
|
+
context "with an invalid auth token" do
|
71
65
|
before do
|
72
|
-
|
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 "
|
78
|
-
expect
|
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 "
|
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 "
|
86
|
-
|
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
|