loca 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/loca +31 -2
- data/lib/loca.rb +5 -9
- data/lib/loca/cli.rb +59 -33
- data/lib/loca/error.rb +7 -14
- data/lib/loca/git/branch_creator.rb +55 -0
- data/lib/loca/git/branch_deleter.rb +32 -0
- data/lib/loca/git/common.rb +42 -0
- data/lib/loca/url/parser.rb +61 -0
- data/lib/loca/url/validator.rb +45 -0
- data/lib/loca/utils.rb +12 -0
- data/lib/loca/version.rb +1 -1
- data/spec/loca/cli_spec.rb +33 -55
- data/spec/loca/git/branch_creator_spec.rb +18 -0
- data/spec/loca/git/common_spec.rb +46 -0
- data/spec/loca/url/parser_spec.rb +88 -0
- data/spec/loca/url/validator_spec.rb +26 -0
- data/spec/loca/utils_spec.rb +40 -0
- data/spec/spec_helper.rb +13 -59
- data/spec/support/matchers/terminate.rb +37 -0
- metadata +63 -41
- data/lib/loca/git.rb +0 -117
- data/lib/loca/url.rb +0 -37
- data/spec/e2e/github_spec.rb +0 -43
- data/spec/loca/git_spec.rb +0 -152
- data/spec/loca/url_spec.rb +0 -47
- data/spec/support/features/github_helper.rb +0 -55
data/spec/loca/url_spec.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
describe Loca::URL do
|
2
|
-
let(:pid) { 1 } # Pull request ID
|
3
|
-
let(:url) { "https://github.com/smoll/loca/pull/#{pid}" }
|
4
|
-
subject { described_class.new(url) }
|
5
|
-
|
6
|
-
let(:expected_branch_name) { "PULL_#{pid}" }
|
7
|
-
let(:expected_pr_num) { pid.to_s }
|
8
|
-
|
9
|
-
describe '#initialize' do
|
10
|
-
it 'does not raise an error for a valid URL' do
|
11
|
-
expect { Loca::URL.new(url) }.to_not raise_error
|
12
|
-
end
|
13
|
-
# it 'does not raise an error for a GitHub PR URL with additional segments' do
|
14
|
-
# expect { Loca::URL.new("#{url}/something/something") }.to_not raise_error # TODO: technical improvement
|
15
|
-
# end
|
16
|
-
it 'raises an error for a non-URL' do
|
17
|
-
expect { silence(:stderr) { Loca::URL.new('not a URL') } }.to raise_error
|
18
|
-
end
|
19
|
-
it 'raises an error for a non-GitHub URL' do
|
20
|
-
expect { silence(:stderr) { Loca::URL.new('http://bad-url-here.com') } }.to raise_error
|
21
|
-
end
|
22
|
-
it 'raises an error for a GitHub non-PR URL' do
|
23
|
-
expect { silence(:stderr) { Loca::URL.new('https://github.com/smoll/loca/something/something') } }.to raise_error
|
24
|
-
end
|
25
|
-
it 'raises an error for a GitHub URL without an integer in the PID location' do
|
26
|
-
expect { silence(:stderr) { Loca::URL.new('https://github.com/smoll/loca/pull/NaN') } }.to raise_error
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe '#to_s' do
|
31
|
-
it 'returns the url passed to the constructor' do
|
32
|
-
expect(subject.to_s).to eq url
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe '#extract_branch_name' do # private method
|
37
|
-
it 'returns the expected branch name' do
|
38
|
-
expect(subject.send(:extract_branch_name)).to eq expected_branch_name
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe '#extract_pr_num' do # private method
|
43
|
-
it 'returns the expected branch name' do
|
44
|
-
expect(subject.send(:extract_pr_num)).to eq "#{pid}"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'mixlib/shellout'
|
2
|
-
require 'fileutils'
|
3
|
-
|
4
|
-
module Features
|
5
|
-
module GitHubHelper
|
6
|
-
def teardown
|
7
|
-
return_to_original_wd
|
8
|
-
FileUtils.rm_rf absolute_path
|
9
|
-
end
|
10
|
-
|
11
|
-
def cd_to_cloned_dir
|
12
|
-
@original_wd = Dir.pwd
|
13
|
-
Dir.chdir(absolute_path)
|
14
|
-
end
|
15
|
-
|
16
|
-
def return_to_original_wd
|
17
|
-
Dir.chdir(@original_wd)
|
18
|
-
end
|
19
|
-
|
20
|
-
def clone_test_repo
|
21
|
-
shellout! "git clone https://github.com/smoll/Spoon-Knife ./#{rel_path}"
|
22
|
-
end
|
23
|
-
|
24
|
-
def set_upstream
|
25
|
-
shellout! 'git remote add upstream https://github.com/octocat/Spoon-Knife.git'
|
26
|
-
end
|
27
|
-
|
28
|
-
def current_branch
|
29
|
-
shellout! 'git rev-parse --abbrev-ref HEAD'
|
30
|
-
end
|
31
|
-
|
32
|
-
def shellout!(cmd, opts = {})
|
33
|
-
opts = {
|
34
|
-
input: nil
|
35
|
-
}.merge(opts)
|
36
|
-
sh = opts[:input].nil? ? Mixlib::ShellOut.new(cmd.to_s) : Mixlib::ShellOut.new(cmd.to_s, input: opts[:input].to_s)
|
37
|
-
sh.run_command
|
38
|
-
|
39
|
-
sh.error! if opts[:input].nil? # NOTE: CLI exits non-zero if waiting on user input
|
40
|
-
sh.stdout
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
def rel_path
|
46
|
-
absolute_path.split(Dir.pwd.to_s)[1].sub('/', '')
|
47
|
-
end
|
48
|
-
|
49
|
-
def absolute_path
|
50
|
-
path = File.expand_path('../../../tmp/cloned', __FILE__)
|
51
|
-
FileUtils.mkdir_p path
|
52
|
-
path
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|