gitx 2.13.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 +7 -0
- data/.gitignore +28 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +6 -0
- data/CONTRIBUTING.md +67 -0
- data/Gemfile +4 -0
- data/Guardfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +87 -0
- data/Rakefile +5 -0
- data/bin/git-buildtag +6 -0
- data/bin/git-cleanup +7 -0
- data/bin/git-integrate +6 -0
- data/bin/git-nuke +6 -0
- data/bin/git-release +6 -0
- data/bin/git-review +6 -0
- data/bin/git-share +6 -0
- data/bin/git-start +6 -0
- data/bin/git-track +6 -0
- data/bin/git-update +6 -0
- data/gitx.gemspec +37 -0
- data/lib/gitx.rb +8 -0
- data/lib/gitx/cli/base_command.rb +56 -0
- data/lib/gitx/cli/buildtag_command.rb +39 -0
- data/lib/gitx/cli/cleanup_command.rb +45 -0
- data/lib/gitx/cli/integrate_command.rb +94 -0
- data/lib/gitx/cli/nuke_command.rb +62 -0
- data/lib/gitx/cli/release_command.rb +40 -0
- data/lib/gitx/cli/review_command.rb +93 -0
- data/lib/gitx/cli/share_command.rb +15 -0
- data/lib/gitx/cli/start_command.rb +37 -0
- data/lib/gitx/cli/track_command.rb +14 -0
- data/lib/gitx/cli/update_command.rb +35 -0
- data/lib/gitx/configuration.rb +44 -0
- data/lib/gitx/extensions/string.rb +12 -0
- data/lib/gitx/extensions/thor.rb +39 -0
- data/lib/gitx/github.rb +178 -0
- data/lib/gitx/version.rb +3 -0
- data/spec/fixtures/vcr_cassettes/pull_request_does_exist_with_failure_status.yml +135 -0
- data/spec/fixtures/vcr_cassettes/pull_request_does_exist_with_success_status.yml +149 -0
- data/spec/fixtures/vcr_cassettes/pull_request_does_not_exist.yml +133 -0
- data/spec/gitx/cli/base_command_spec.rb +41 -0
- data/spec/gitx/cli/buildtag_command_spec.rb +70 -0
- data/spec/gitx/cli/cleanup_command_spec.rb +37 -0
- data/spec/gitx/cli/integrate_command_spec.rb +290 -0
- data/spec/gitx/cli/nuke_command_spec.rb +165 -0
- data/spec/gitx/cli/release_command_spec.rb +172 -0
- data/spec/gitx/cli/review_command_spec.rb +356 -0
- data/spec/gitx/cli/share_command_spec.rb +32 -0
- data/spec/gitx/cli/start_command_spec.rb +96 -0
- data/spec/gitx/cli/track_command_spec.rb +31 -0
- data/spec/gitx/cli/update_command_spec.rb +79 -0
- data/spec/spec_helper.rb +86 -0
- data/spec/support/global_config.rb +26 -0
- data/spec/support/home_env.rb +11 -0
- data/spec/support/matchers/meet_expectations_matcher.rb +7 -0
- data/spec/support/pry.rb +1 -0
- data/spec/support/stub_execution.rb +14 -0
- data/spec/support/timecop.rb +9 -0
- data/spec/support/vcr.rb +6 -0
- data/spec/support/webmock.rb +1 -0
- metadata +348 -0
@@ -0,0 +1,133 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.github.com/repos/wireframe/gitx/pulls?head=wireframe:feature-branch&state=open
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- application/vnd.github.v3+json
|
12
|
+
User-Agent:
|
13
|
+
- Octokit Ruby Gem 3.2.0
|
14
|
+
Authorization:
|
15
|
+
- token 123123
|
16
|
+
Accept-Encoding:
|
17
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 200
|
21
|
+
message: OK
|
22
|
+
headers:
|
23
|
+
Server:
|
24
|
+
- GitHub.com
|
25
|
+
Date:
|
26
|
+
- Tue, 05 Aug 2014 17:14:02 GMT
|
27
|
+
Content-Type:
|
28
|
+
- application/json; charset=utf-8
|
29
|
+
Status:
|
30
|
+
- 401 Unauthorized
|
31
|
+
X-Github-Media-Type:
|
32
|
+
- github.v3; format=json
|
33
|
+
X-Ratelimit-Limit:
|
34
|
+
- '60'
|
35
|
+
X-Ratelimit-Remaining:
|
36
|
+
- '59'
|
37
|
+
X-Ratelimit-Reset:
|
38
|
+
- '1407262442'
|
39
|
+
X-Xss-Protection:
|
40
|
+
- 1; mode=block
|
41
|
+
X-Frame-Options:
|
42
|
+
- deny
|
43
|
+
Content-Security-Policy:
|
44
|
+
- default-src 'none'
|
45
|
+
Content-Length:
|
46
|
+
- '83'
|
47
|
+
Access-Control-Allow-Credentials:
|
48
|
+
- 'true'
|
49
|
+
Access-Control-Expose-Headers:
|
50
|
+
- ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset,
|
51
|
+
X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
|
52
|
+
Access-Control-Allow-Origin:
|
53
|
+
- "*"
|
54
|
+
X-Github-Request-Id:
|
55
|
+
- 46C5E25C:552F:1BC5411:53E110DA
|
56
|
+
Strict-Transport-Security:
|
57
|
+
- max-age=31536000; includeSubdomains
|
58
|
+
X-Content-Type-Options:
|
59
|
+
- nosniff
|
60
|
+
body:
|
61
|
+
encoding: UTF-8
|
62
|
+
string: '[]'
|
63
|
+
http_version:
|
64
|
+
recorded_at: Tue, 05 Aug 2014 17:14:02 GMT
|
65
|
+
- request:
|
66
|
+
method: get
|
67
|
+
uri: https://api.github.com/repos/wireframe/gitx/commits/feature-branch/status
|
68
|
+
body:
|
69
|
+
encoding: US-ASCII
|
70
|
+
string: ''
|
71
|
+
headers:
|
72
|
+
Accept:
|
73
|
+
- application/vnd.github.v3+json
|
74
|
+
User-Agent:
|
75
|
+
- Octokit Ruby Gem 3.4.0
|
76
|
+
Content-Type:
|
77
|
+
- application/json
|
78
|
+
Authorization:
|
79
|
+
- token 123123
|
80
|
+
Accept-Encoding:
|
81
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
82
|
+
response:
|
83
|
+
status:
|
84
|
+
code: 200
|
85
|
+
message: OK
|
86
|
+
headers:
|
87
|
+
Server:
|
88
|
+
- GitHub.com
|
89
|
+
Date:
|
90
|
+
- Wed, 10 Dec 2014 19:01:27 GMT
|
91
|
+
Content-Type:
|
92
|
+
- application/json; charset=utf-8
|
93
|
+
Transfer-Encoding:
|
94
|
+
- chunked
|
95
|
+
Status:
|
96
|
+
- 200 OK
|
97
|
+
X-Ratelimit-Limit:
|
98
|
+
- '5000'
|
99
|
+
X-Ratelimit-Remaining:
|
100
|
+
- '4993'
|
101
|
+
X-Ratelimit-Reset:
|
102
|
+
- '1418241620'
|
103
|
+
X-Oauth-Scopes:
|
104
|
+
- repo
|
105
|
+
X-Accepted-Oauth-Scopes:
|
106
|
+
- repo, repo:status
|
107
|
+
X-Github-Media-Type:
|
108
|
+
- github.v3; format=json
|
109
|
+
X-Xss-Protection:
|
110
|
+
- 1; mode=block
|
111
|
+
X-Frame-Options:
|
112
|
+
- deny
|
113
|
+
Content-Security-Policy:
|
114
|
+
- default-src 'none'
|
115
|
+
Access-Control-Allow-Credentials:
|
116
|
+
- 'true'
|
117
|
+
Access-Control-Expose-Headers:
|
118
|
+
- ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset,
|
119
|
+
X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
|
120
|
+
Access-Control-Allow-Origin:
|
121
|
+
- "*"
|
122
|
+
X-Github-Request-Id:
|
123
|
+
- C6CBAFAF:141D:2F27072:54889887
|
124
|
+
Strict-Transport-Security:
|
125
|
+
- max-age=31536000; includeSubdomains; preload
|
126
|
+
X-Content-Type-Options:
|
127
|
+
- nosniff
|
128
|
+
body:
|
129
|
+
encoding: UTF-8
|
130
|
+
string: '{"state":"pending"}'
|
131
|
+
http_version:
|
132
|
+
recorded_at: Wed, 10 Dec 2014 19:14:11 GMT
|
133
|
+
recorded_with: VCR 2.9.2
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'gitx/cli/base_command'
|
3
|
+
|
4
|
+
describe Gitx::Cli::BaseCommand do
|
5
|
+
let(:args) { [] }
|
6
|
+
let(:options) { {} }
|
7
|
+
let(:config) do
|
8
|
+
{
|
9
|
+
pretend: true
|
10
|
+
}
|
11
|
+
end
|
12
|
+
let(:cli) { described_class.new(args, options, config) }
|
13
|
+
let(:repo) { cli.send(:repo) }
|
14
|
+
|
15
|
+
describe 'without custom .gitx.yml config file' do
|
16
|
+
it 'provides default options' do
|
17
|
+
expect(cli.send(:config).config).to eq Gitx::Configuration::DEFAULT_CONFIG
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'with custom .gitx.yml config file' do
|
22
|
+
let(:config) do
|
23
|
+
{
|
24
|
+
'aggregate_branches' => %w( foo bar ),
|
25
|
+
'reserved_branches' => %w( baz qux ),
|
26
|
+
'taggable_branches' => %w( quux corge )
|
27
|
+
}
|
28
|
+
end
|
29
|
+
before do
|
30
|
+
expect(repo).to receive(:workdir).and_return(temp_dir)
|
31
|
+
File.open(File.join(temp_dir, '.gitx.yml'), 'w') do |f|
|
32
|
+
f.puts config.to_yaml
|
33
|
+
end
|
34
|
+
end
|
35
|
+
it 'overrides default options' do
|
36
|
+
expect(cli.send(:config).aggregate_branches).to eq(%w( foo bar ))
|
37
|
+
expect(cli.send(:config).reserved_branches).to eq(%w( baz qux ))
|
38
|
+
expect(cli.send(:config).taggable_branches).to eq(%w( quux corge ))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'gitx/cli/buildtag_command'
|
3
|
+
|
4
|
+
describe Gitx::Cli::BuildtagCommand do
|
5
|
+
let(:args) { [] }
|
6
|
+
let(:options) { {} }
|
7
|
+
let(:config) do
|
8
|
+
{
|
9
|
+
pretend: true
|
10
|
+
}
|
11
|
+
end
|
12
|
+
let(:cli) { Gitx::Cli::BuildtagCommand.new(args, options, config) }
|
13
|
+
let(:branch) { double('fake branch', name: 'feature-branch') }
|
14
|
+
|
15
|
+
before do
|
16
|
+
allow(cli).to receive(:current_branch).and_return(branch)
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#buildtag' do
|
20
|
+
let(:env_travis_branch) { nil }
|
21
|
+
let(:env_travis_build_number) { nil }
|
22
|
+
let(:env_ci_branch) { nil }
|
23
|
+
let(:env_ci_build_number) { nil }
|
24
|
+
before do
|
25
|
+
ENV['TRAVIS_BRANCH'] = env_travis_branch
|
26
|
+
ENV['TRAVIS_BUILD_NUMBER'] = env_travis_build_number
|
27
|
+
ENV['CI_BRANCH'] = env_ci_branch
|
28
|
+
ENV['CI_BUILD_NUMBER'] = env_ci_build_number
|
29
|
+
end
|
30
|
+
context 'when TRAVIS_BRANCH is nil' do
|
31
|
+
it 'raises Unknown Branch error' do
|
32
|
+
expect { cli.buildtag }.to raise_error(/Unknown branch/)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
context 'when TRAVIS_BRANCH is NOT master or staging' do
|
36
|
+
let(:env_travis_branch) { 'random-branch' }
|
37
|
+
it 'raises unsupported branch error' do
|
38
|
+
expect { cli.buildtag }.to raise_error(/Branch must be one of the supported taggable branches/)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
context 'when TRAVIS_BRANCH is master' do
|
42
|
+
let(:env_travis_branch) { 'master' }
|
43
|
+
let(:env_travis_build_number) { '24' }
|
44
|
+
before do
|
45
|
+
Timecop.freeze(Time.utc(2013, 10, 30, 10, 21, 28)) do
|
46
|
+
expect(cli).to receive(:run_cmd).with("git tag build-master-2013-10-30-10-21-28 -a -m 'buildtag generated by build 24'").ordered
|
47
|
+
expect(cli).to receive(:run_cmd).with('git push origin build-master-2013-10-30-10-21-28').ordered
|
48
|
+
cli.buildtag
|
49
|
+
end
|
50
|
+
end
|
51
|
+
it 'creates a tag for the branch and push it to github' do
|
52
|
+
should meet_expectations
|
53
|
+
end
|
54
|
+
end
|
55
|
+
context 'when CI_BRANCH is master' do
|
56
|
+
let(:env_ci_branch) { 'master' }
|
57
|
+
let(:env_ci_build_number) { '24' }
|
58
|
+
before do
|
59
|
+
Timecop.freeze(Time.utc(2013, 10, 30, 10, 21, 28)) do
|
60
|
+
expect(cli).to receive(:run_cmd).with("git tag build-master-2013-10-30-10-21-28 -a -m 'buildtag generated by build 24'").ordered
|
61
|
+
expect(cli).to receive(:run_cmd).with('git push origin build-master-2013-10-30-10-21-28').ordered
|
62
|
+
cli.buildtag
|
63
|
+
end
|
64
|
+
end
|
65
|
+
it 'creates a tag for the branch and push it to github' do
|
66
|
+
should meet_expectations
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'gitx/cli/cleanup_command'
|
3
|
+
|
4
|
+
describe Gitx::Cli::CleanupCommand do
|
5
|
+
let(:args) { [] }
|
6
|
+
let(:options) { {} }
|
7
|
+
let(:config) do
|
8
|
+
{
|
9
|
+
pretend: true
|
10
|
+
}
|
11
|
+
end
|
12
|
+
let(:cli) { Gitx::Cli::CleanupCommand.new(args, options, config) }
|
13
|
+
let(:branch) { double('fake branch', name: 'feature-branch') }
|
14
|
+
|
15
|
+
before do
|
16
|
+
allow(cli).to receive(:current_branch).and_return(branch)
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#cleanup' do
|
20
|
+
before do
|
21
|
+
allow(cli).to receive(:say)
|
22
|
+
|
23
|
+
expect(cli).to receive(:run_cmd).with('git checkout master').ordered
|
24
|
+
expect(cli).to receive(:run_cmd).with('git pull').ordered
|
25
|
+
expect(cli).to receive(:run_cmd).with('git remote prune origin').ordered
|
26
|
+
expect(cli).to receive(:run_cmd).with('git branch -r --merged').and_return('merged-remote-feature').ordered
|
27
|
+
expect(cli).to receive(:run_cmd).with('git push origin --delete merged-remote-feature').ordered
|
28
|
+
expect(cli).to receive(:run_cmd).with('git branch --merged').and_return('merged-local-feature').ordered
|
29
|
+
expect(cli).to receive(:run_cmd).with('git branch -d merged-local-feature').ordered
|
30
|
+
|
31
|
+
cli.cleanup
|
32
|
+
end
|
33
|
+
it 'runs expected commands' do
|
34
|
+
should meet_expectations
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,290 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'gitx/cli/integrate_command'
|
3
|
+
|
4
|
+
describe Gitx::Cli::IntegrateCommand do
|
5
|
+
let(:args) { [] }
|
6
|
+
let(:options) { {} }
|
7
|
+
let(:config) do
|
8
|
+
{
|
9
|
+
pretend: true
|
10
|
+
}
|
11
|
+
end
|
12
|
+
let(:cli) { Gitx::Cli::IntegrateCommand.new(args, options, config) }
|
13
|
+
let(:current_branch) { double('fake branch', name: 'feature-branch', head?: true) }
|
14
|
+
let(:repo) { cli.send(:repo) }
|
15
|
+
let(:remote_branch_names) { ['origin/staging', 'origin/prototype'] }
|
16
|
+
let(:local_branch_names) { ['feature-branch'] }
|
17
|
+
|
18
|
+
before do
|
19
|
+
allow(cli).to receive(:current_branch).and_return(current_branch)
|
20
|
+
branches = double('fake branches')
|
21
|
+
allow(branches).to receive(:each_name).with(:local).and_return(local_branch_names)
|
22
|
+
allow(branches).to receive(:each_name).with(:remote).and_return(remote_branch_names)
|
23
|
+
allow(repo).to receive(:branches).and_return(branches)
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#integrate' do
|
27
|
+
context 'when integration branch is ommitted and remote branch exists' do
|
28
|
+
let(:authorization_token) { '123123' }
|
29
|
+
let(:remote_branch_names) { ['origin/staging'] }
|
30
|
+
before do
|
31
|
+
allow(cli).to receive(:authorization_token).and_return(authorization_token)
|
32
|
+
expect(cli).to receive(:execute_command).with(Gitx::Cli::UpdateCommand, :update)
|
33
|
+
|
34
|
+
expect(cli).to receive(:run_cmd).with('git fetch origin').ordered
|
35
|
+
expect(cli).to receive(:run_cmd).with('git branch -D staging', allow_failure: true).ordered
|
36
|
+
expect(cli).to receive(:run_cmd).with('git checkout staging').ordered
|
37
|
+
expect(cli).to receive(:run_cmd).with('git merge feature-branch').ordered
|
38
|
+
expect(cli).to receive(:run_cmd).with('git push origin HEAD').ordered
|
39
|
+
expect(cli).to receive(:run_cmd).with('git checkout feature-branch').ordered
|
40
|
+
|
41
|
+
stub_request(:post, /.*api.github.com.*/).to_return(:status => 201)
|
42
|
+
|
43
|
+
VCR.use_cassette('pull_request_does_exist_with_success_status') do
|
44
|
+
cli.integrate
|
45
|
+
end
|
46
|
+
end
|
47
|
+
it 'defaults to staging branch' do
|
48
|
+
should meet_expectations
|
49
|
+
end
|
50
|
+
it 'does not post comment to pull request' do
|
51
|
+
expect(WebMock).to_not have_requested(:post, 'https://api.github.com/repos/wireframe/gitx/issues/10/comments')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
context 'when current_branch == master' do
|
55
|
+
let(:current_branch) { double('fake branch', name: 'master', head?: true) }
|
56
|
+
let(:local_branch_names) { ['master'] }
|
57
|
+
let(:authorization_token) { '123123' }
|
58
|
+
let(:remote_branch_names) { ['origin/staging'] }
|
59
|
+
before do
|
60
|
+
allow(cli).to receive(:authorization_token).and_return(authorization_token)
|
61
|
+
expect(cli).to receive(:execute_command).with(Gitx::Cli::UpdateCommand, :update)
|
62
|
+
|
63
|
+
expect(cli).to receive(:run_cmd).with('git fetch origin').ordered
|
64
|
+
expect(cli).to receive(:run_cmd).with('git branch -D staging', allow_failure: true).ordered
|
65
|
+
expect(cli).to receive(:run_cmd).with('git checkout staging').ordered
|
66
|
+
expect(cli).to receive(:run_cmd).with('git merge master').ordered
|
67
|
+
expect(cli).to receive(:run_cmd).with('git push origin HEAD').ordered
|
68
|
+
expect(cli).to receive(:run_cmd).with('git checkout master').ordered
|
69
|
+
|
70
|
+
cli.integrate
|
71
|
+
end
|
72
|
+
it 'does not create pull request' do
|
73
|
+
expect(WebMock).to_not have_requested(:post, 'https://api.github.com/repos/wireframe/gitx/pulls')
|
74
|
+
end
|
75
|
+
end
|
76
|
+
context 'when staging branch does not exist remotely' do
|
77
|
+
let(:authorization_token) { '123123' }
|
78
|
+
let(:remote_branch_names) { [] }
|
79
|
+
before do
|
80
|
+
allow(cli).to receive(:authorization_token).and_return(authorization_token)
|
81
|
+
expect(cli).to receive(:execute_command).with(Gitx::Cli::UpdateCommand, :update)
|
82
|
+
|
83
|
+
expect(repo).to receive(:create_branch).with('staging', 'master')
|
84
|
+
|
85
|
+
expect(cli).to receive(:run_cmd).with('git push origin staging:staging').ordered
|
86
|
+
|
87
|
+
expect(cli).to receive(:run_cmd).with('git fetch origin').ordered
|
88
|
+
expect(cli).to receive(:run_cmd).with('git branch -D staging', allow_failure: true).ordered
|
89
|
+
expect(cli).to receive(:run_cmd).with('git checkout staging').ordered
|
90
|
+
expect(cli).to receive(:run_cmd).with('git merge feature-branch').ordered
|
91
|
+
expect(cli).to receive(:run_cmd).with('git push origin HEAD').ordered
|
92
|
+
expect(cli).to receive(:run_cmd).with('git checkout feature-branch').ordered
|
93
|
+
|
94
|
+
stub_request(:post, /.*api.github.com.*/).to_return(:status => 201)
|
95
|
+
|
96
|
+
VCR.use_cassette('pull_request_does_exist_with_success_status') do
|
97
|
+
cli.integrate
|
98
|
+
end
|
99
|
+
end
|
100
|
+
it 'creates remote aggregate branch' do
|
101
|
+
should meet_expectations
|
102
|
+
end
|
103
|
+
end
|
104
|
+
context 'when integration branch == prototype and remote branch exists' do
|
105
|
+
let(:authorization_token) { '123123' }
|
106
|
+
let(:remote_branch_names) { ['origin/prototype'] }
|
107
|
+
before do
|
108
|
+
allow(cli).to receive(:authorization_token).and_return(authorization_token)
|
109
|
+
expect(cli).to receive(:execute_command).with(Gitx::Cli::UpdateCommand, :update)
|
110
|
+
|
111
|
+
expect(cli).to receive(:run_cmd).with('git fetch origin').ordered
|
112
|
+
expect(cli).to receive(:run_cmd).with('git branch -D prototype', allow_failure: true).ordered
|
113
|
+
expect(cli).to receive(:run_cmd).with('git checkout prototype').ordered
|
114
|
+
expect(cli).to receive(:run_cmd).with('git merge feature-branch').ordered
|
115
|
+
expect(cli).to receive(:run_cmd).with('git push origin HEAD').ordered
|
116
|
+
expect(cli).to receive(:run_cmd).with('git checkout feature-branch').ordered
|
117
|
+
|
118
|
+
stub_request(:post, /.*api.github.com.*/).to_return(:status => 201)
|
119
|
+
|
120
|
+
VCR.use_cassette('pull_request_does_exist_with_success_status') do
|
121
|
+
cli.integrate 'prototype'
|
122
|
+
end
|
123
|
+
end
|
124
|
+
it 'runs expected commands' do
|
125
|
+
should meet_expectations
|
126
|
+
end
|
127
|
+
end
|
128
|
+
context 'when integration branch is not an aggregate branch' do
|
129
|
+
it 'raises an error' do
|
130
|
+
expect { cli.integrate('some-other-branch') }.to raise_error(/Invalid aggregate branch: some-other-branch must be one of supported aggregate branches/)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
context 'when merge conflicts occur during the Gitx::Cli::UpdateCommand execution' do
|
134
|
+
let(:remote_branch_names) { ['origin/staging'] }
|
135
|
+
before do
|
136
|
+
expect(cli).to receive(:execute_command).with(Gitx::Cli::UpdateCommand, :update).and_raise(Gitx::Cli::BaseCommand::MergeError)
|
137
|
+
|
138
|
+
expect { cli.integrate }.to raise_error(Gitx::Cli::BaseCommand::MergeError, 'Merge Conflict Occurred. Please Merge Conflict Occurred. Please fix merge conflict and rerun the integrate command')
|
139
|
+
end
|
140
|
+
it 'raises a helpful error' do
|
141
|
+
should meet_expectations
|
142
|
+
end
|
143
|
+
end
|
144
|
+
context 'when merge conflicts occur with the integrate command' do
|
145
|
+
let(:remote_branch_names) { ['origin/staging'] }
|
146
|
+
before do
|
147
|
+
expect(cli).to receive(:execute_command).with(Gitx::Cli::UpdateCommand, :update)
|
148
|
+
|
149
|
+
expect(cli).to receive(:run_cmd).with('git fetch origin').ordered
|
150
|
+
expect(cli).to receive(:run_cmd).with('git branch -D staging', allow_failure: true).ordered
|
151
|
+
expect(cli).to receive(:run_cmd).with('git checkout staging').ordered
|
152
|
+
expect(cli).to receive(:run_cmd).with('git merge feature-branch').and_raise('git merge feature-branch failed').ordered
|
153
|
+
|
154
|
+
expect { cli.integrate }.to raise_error(/Merge Conflict Occurred. Please fix merge conflict and rerun command with --resume feature-branch flag/)
|
155
|
+
end
|
156
|
+
it 'raises a helpful error' do
|
157
|
+
should meet_expectations
|
158
|
+
end
|
159
|
+
end
|
160
|
+
context 'with --resume "feature-branch" flag when feature-branch exists' do
|
161
|
+
let(:options) do
|
162
|
+
{
|
163
|
+
resume: 'feature-branch'
|
164
|
+
}
|
165
|
+
end
|
166
|
+
let(:repo) { cli.send(:repo) }
|
167
|
+
let(:authorization_token) { '123123' }
|
168
|
+
before do
|
169
|
+
allow(cli).to receive(:authorization_token).and_return(authorization_token)
|
170
|
+
|
171
|
+
expect(cli).to receive(:execute_command).with(Gitx::Cli::UpdateCommand, :update)
|
172
|
+
|
173
|
+
expect(cli).not_to receive(:run_cmd).with('git branch -D staging')
|
174
|
+
expect(cli).not_to receive(:run_cmd).with('git push origin HEAD')
|
175
|
+
expect(cli).to receive(:run_cmd).with('git checkout feature-branch')
|
176
|
+
|
177
|
+
stub_request(:post, /.*api.github.com.*/).to_return(:status => 201)
|
178
|
+
|
179
|
+
VCR.use_cassette('pull_request_does_exist_with_success_status') do
|
180
|
+
cli.integrate
|
181
|
+
end
|
182
|
+
end
|
183
|
+
it 'does not delete local staging branch' do
|
184
|
+
should meet_expectations
|
185
|
+
end
|
186
|
+
end
|
187
|
+
context 'with --resume "feature-branch" flag when feature-branch does not exist' do
|
188
|
+
let(:options) do
|
189
|
+
{
|
190
|
+
resume: 'invalid-feature-branch'
|
191
|
+
}
|
192
|
+
end
|
193
|
+
let(:local_branch_names) { ['feature-branch'] }
|
194
|
+
let(:authorization_token) { '123123' }
|
195
|
+
before do
|
196
|
+
allow(cli).to receive(:authorization_token).and_return(authorization_token)
|
197
|
+
expect(cli).to receive(:execute_command).with(Gitx::Cli::UpdateCommand, :update)
|
198
|
+
expect(cli).to receive(:ask).and_return('feature-branch')
|
199
|
+
|
200
|
+
expect(cli).not_to receive(:run_cmd).with('git branch -D staging')
|
201
|
+
expect(cli).not_to receive(:run_cmd).with('git push origin HEAD')
|
202
|
+
expect(cli).to receive(:run_cmd).with('git checkout feature-branch').ordered
|
203
|
+
|
204
|
+
stub_request(:post, /.*api.github.com.*/).to_return(:status => 201)
|
205
|
+
VCR.use_cassette('pull_request_does_exist_with_success_status') do
|
206
|
+
cli.integrate
|
207
|
+
end
|
208
|
+
end
|
209
|
+
it 'asks user for feature-branch name' do
|
210
|
+
should meet_expectations
|
211
|
+
end
|
212
|
+
end
|
213
|
+
context 'for default integration (to staging) with --comment flag' do
|
214
|
+
let(:options) do
|
215
|
+
{ comment: true }
|
216
|
+
end
|
217
|
+
let(:authorization_token) { '123123' }
|
218
|
+
let(:remote_branch_names) { ['origin/staging'] }
|
219
|
+
before do
|
220
|
+
allow(cli).to receive(:authorization_token).and_return(authorization_token)
|
221
|
+
expect(cli).to receive(:execute_command).with(Gitx::Cli::UpdateCommand, :update)
|
222
|
+
|
223
|
+
expect(cli).to receive(:run_cmd).with('git fetch origin').ordered
|
224
|
+
expect(cli).to receive(:run_cmd).with('git branch -D staging', allow_failure: true).ordered
|
225
|
+
expect(cli).to receive(:run_cmd).with('git checkout staging').ordered
|
226
|
+
expect(cli).to receive(:run_cmd).with('git merge feature-branch').ordered
|
227
|
+
expect(cli).to receive(:run_cmd).with('git push origin HEAD').ordered
|
228
|
+
expect(cli).to receive(:run_cmd).with('git checkout feature-branch').ordered
|
229
|
+
|
230
|
+
stub_request(:post, /.*api.github.com.*/).to_return(:status => 201)
|
231
|
+
|
232
|
+
VCR.use_cassette('pull_request_does_exist_with_success_status') do
|
233
|
+
cli.integrate
|
234
|
+
end
|
235
|
+
end
|
236
|
+
it 'defaults to staging branch' do
|
237
|
+
should meet_expectations
|
238
|
+
end
|
239
|
+
it 'posts comment to pull request' do
|
240
|
+
expect(WebMock).to have_requested(:post, 'https://api.github.com/repos/wireframe/gitx/issues/10/comments').
|
241
|
+
with(body: {body: '[gitx] integrated into staging :twisted_rightwards_arrows:'})
|
242
|
+
end
|
243
|
+
end
|
244
|
+
context 'with --comment flag when a pull request doesn\'t exist for the feature-branch' do
|
245
|
+
let(:options) do
|
246
|
+
{ comment: true }
|
247
|
+
end
|
248
|
+
let(:authorization_token) { '123123' }
|
249
|
+
let(:changelog) { '* made some fixes' }
|
250
|
+
let(:new_pull_request) do
|
251
|
+
{
|
252
|
+
html_url: 'https://path/to/html/pull/request',
|
253
|
+
issue_url: 'https://api/path/to/issue/url',
|
254
|
+
number: 10,
|
255
|
+
head: {
|
256
|
+
ref: 'branch_name'
|
257
|
+
}
|
258
|
+
}
|
259
|
+
end
|
260
|
+
before do
|
261
|
+
allow(cli).to receive(:ask_editor).and_return('description')
|
262
|
+
allow(cli).to receive(:authorization_token).and_return(authorization_token)
|
263
|
+
expect(cli).to receive(:execute_command).with(Gitx::Cli::UpdateCommand, :update).twice
|
264
|
+
|
265
|
+
expect(cli).to receive(:run_cmd).with('git fetch origin').ordered
|
266
|
+
expect(cli).to receive(:run_cmd).with('git branch -D staging', allow_failure: true).ordered
|
267
|
+
expect(cli).to receive(:run_cmd).with('git checkout staging').ordered
|
268
|
+
expect(cli).to receive(:run_cmd).with('git merge feature-branch').ordered
|
269
|
+
expect(cli).to receive(:run_cmd).with('git push origin HEAD').ordered
|
270
|
+
expect(cli).to receive(:run_cmd).with('git checkout feature-branch').ordered
|
271
|
+
expect(cli).to receive(:run_cmd).with('git checkout feature-branch').ordered
|
272
|
+
expect(cli).to receive(:run_cmd).with("git log master...feature-branch --reverse --no-merges --pretty=format:'* %s%n%b'").and_return('2013-01-01 did some stuff').ordered
|
273
|
+
|
274
|
+
stub_request(:post, 'https://api.github.com/repos/wireframe/gitx/pulls').to_return(:status => 201, :body => new_pull_request.to_json, :headers => {'Content-Type' => 'application/json'})
|
275
|
+
stub_request(:post, 'https://api.github.com/repos/wireframe/gitx/issues/10/comments').to_return(:status => 201)
|
276
|
+
|
277
|
+
VCR.use_cassette('pull_request_does_not_exist') do
|
278
|
+
cli.integrate
|
279
|
+
end
|
280
|
+
end
|
281
|
+
it 'creates github pull request' do
|
282
|
+
should meet_expectations
|
283
|
+
end
|
284
|
+
it 'creates github comment for integration' do
|
285
|
+
expect(WebMock).to have_requested(:post, 'https://api.github.com/repos/wireframe/gitx/issues/10/comments').
|
286
|
+
with(body: {body: '[gitx] integrated into staging :twisted_rightwards_arrows:'})
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|