atlassian-stash 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/VERSION +1 -1
- data/bin/stash +3 -5
- data/lib/atlassian/stash/git.rb +11 -2
- data/lib/atlassian/stash/pull_request.rb +1 -2
- data/lib/atlassian/stash/repo_info.rb +17 -3
- data/test/helper.rb +1 -0
- data/test/test_stash-git.rb +23 -22
- data/test/test_stash-repo-info.rb +15 -14
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d378f61db7522c5d9871c7b62c11417d4d36f1fd
|
4
|
+
data.tar.gz: 962a88dee48cc89db7d571a6ea26b19f0780c295
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb4c15d5dd4222fee274a182d788daaa480a6eaa5ca0d9a708f138febc610a984ab29e2c8a2a366e0ecf899fe81f67267a903e45c1df5e2cb4f75846ed6c950e
|
7
|
+
data.tar.gz: f6cb1f5021840101f9675b49f9ebebf12b98457372994e2459e86ecfc8d35833eee7a945cf89b4405af842d4d4677348069957cac96245bd584fee5f71463e55
|
data/Gemfile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.2
|
data/bin/stash
CHANGED
@@ -34,7 +34,7 @@ def repo_config
|
|
34
34
|
if (stash_config.exist? && stash_config.file?)
|
35
35
|
@repo_config = YAML.load_file(stash_config)
|
36
36
|
end
|
37
|
-
|
37
|
+
Hash.new
|
38
38
|
end
|
39
39
|
|
40
40
|
command 'configure' do |c|
|
@@ -71,7 +71,7 @@ end
|
|
71
71
|
|
72
72
|
command 'pull-request' do |c|
|
73
73
|
def extract_reviewers(args = [])
|
74
|
-
default_reviewers = repo_config.nil? ?
|
74
|
+
default_reviewers = repo_config.nil? ? Array.new : Array(repo_config[:reviewers])
|
75
75
|
default_reviewers.concat args.collect { |user|
|
76
76
|
user[1..-1] if user.start_with?("@")
|
77
77
|
}.compact
|
@@ -122,10 +122,8 @@ command 'browse' do |c|
|
|
122
122
|
tab = args.shift unless args.empty?
|
123
123
|
|
124
124
|
config = load_config
|
125
|
-
remote = options.remote || config['remote']
|
126
|
-
remote_url = get_remote_url(remote)
|
127
125
|
|
128
|
-
repoInfo = RepoInfo.create(config,
|
126
|
+
repoInfo = RepoInfo.create(config, options.remote)
|
129
127
|
|
130
128
|
branch = options.branch || get_current_branch
|
131
129
|
|
data/lib/atlassian/stash/git.rb
CHANGED
@@ -3,6 +3,9 @@
|
|
3
3
|
module Atlassian
|
4
4
|
module Stash
|
5
5
|
module Git
|
6
|
+
|
7
|
+
DEFAULT_REMOTE="origin"
|
8
|
+
|
6
9
|
def get_current_branch
|
7
10
|
%x(git symbolic-ref HEAD)[/refs\/heads\/(.*)/, 1]
|
8
11
|
end
|
@@ -15,8 +18,14 @@ module Atlassian
|
|
15
18
|
%x(git remote -v)
|
16
19
|
end
|
17
20
|
|
18
|
-
def get_remote_url(remote
|
19
|
-
|
21
|
+
def get_remote_url(remote=nil)
|
22
|
+
remotes = get_remotes
|
23
|
+
return nil if remotes.empty?
|
24
|
+
|
25
|
+
remote = DEFAULT_REMOTE if remote.nil? || remote.empty?
|
26
|
+
|
27
|
+
origin = remotes.split("\n").collect { |r| r.strip }.grep(/^#{remote}.*\(push\)$/).first
|
28
|
+
return nil if origin.nil?
|
20
29
|
URI.extract(origin).first
|
21
30
|
end
|
22
31
|
|
@@ -56,8 +56,7 @@ module Atlassian
|
|
56
56
|
@source = source
|
57
57
|
@target = target
|
58
58
|
|
59
|
-
|
60
|
-
repoInfo = RepoInfo.create(@config, remote)
|
59
|
+
repoInfo = RepoInfo.create(@config, options.remote)
|
61
60
|
|
62
61
|
title, description = title_and_description(options)
|
63
62
|
|
@@ -37,11 +37,25 @@ module Atlassian
|
|
37
37
|
uri.to_s
|
38
38
|
end
|
39
39
|
|
40
|
-
def self.create (config,
|
41
|
-
|
40
|
+
def self.create (config, remote=nil)
|
41
|
+
config = Hash.new if config.nil?
|
42
|
+
remote = config["remote"] if (remote.nil? || remote.empty?)
|
43
|
+
remoteUrl = Atlassian::Stash::Git.get_remote_url(remote)
|
44
|
+
|
45
|
+
if remoteUrl.nil?
|
46
|
+
remotes = Atlassian::Stash::Git.get_remotes
|
47
|
+
if remotes.empty?
|
48
|
+
raise "No git remotes found, could not determine Stash project URL"
|
49
|
+
else
|
50
|
+
remote = Atlassian::Stash::Git::DEFAULT_REMOTE if (remote.nil? || remote.empty?)
|
51
|
+
raise "Could not find requested git remote '#{remote}'. Remotes found: \r\n" + remotes
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
if m = remoteUrl.match(/\/([a-zA-Z~][a-zA-Z0-9_\-]*)\/([[:alnum:]][\w\-\.]*).git$/)
|
42
56
|
return RepoInfo.new(config, m[1], m[2])
|
43
57
|
end
|
44
|
-
raise "Repository does not seem to be hosted in Stash; Remote url: " +
|
58
|
+
raise "Repository does not seem to be hosted in Stash; Remote url: " + remoteUrl
|
45
59
|
end
|
46
60
|
end
|
47
61
|
end
|
data/test/helper.rb
CHANGED
data/test/test_stash-git.rb
CHANGED
@@ -6,38 +6,31 @@ include Atlassian::Stash::Git
|
|
6
6
|
class TestGit < Minitest::Test
|
7
7
|
|
8
8
|
should "extract remote with ssh remote" do
|
9
|
-
Atlassian::Stash::Git.
|
10
|
-
def get_remotes
|
9
|
+
Atlassian::Stash::Git.stubs(:get_remotes).returns(
|
11
10
|
"origin ssh://git@stash.atlassian.com:7999/STASH/stash.git (fetch)
|
12
11
|
origin ssh://git@stash.atlassian.com:7999/STASH/stash.git (push)"
|
13
|
-
|
14
|
-
end
|
12
|
+
)
|
15
13
|
assert_equal 'ssh://git@stash.atlassian.com:7999/STASH/stash.git', Atlassian::Stash::Git.get_remote_url
|
16
14
|
end
|
17
15
|
|
18
16
|
should "extract push remote with different fetch and push urls" do
|
19
|
-
Atlassian::Stash::Git.
|
20
|
-
def get_remotes
|
17
|
+
Atlassian::Stash::Git.stubs(:get_remotes).returns(
|
21
18
|
"origin ssh://git@github.com/~sebr/stash.git (fetch)
|
22
19
|
origin ssh://git@stash.atlassian.com:7999/STASH/stash.git (push)"
|
23
|
-
|
24
|
-
end
|
20
|
+
)
|
25
21
|
assert_equal 'ssh://git@stash.atlassian.com:7999/STASH/stash.git', Atlassian::Stash::Git.get_remote_url
|
26
22
|
end
|
27
23
|
|
28
24
|
should "extract remote with http remote" do
|
29
|
-
Atlassian::Stash::Git.
|
30
|
-
def get_remotes
|
25
|
+
Atlassian::Stash::Git.stubs(:get_remotes).returns(
|
31
26
|
"origin http://adam@sonoma:7990/stash/scm/QA/stash.git (fetch)
|
32
27
|
origin http://adam@sonoma:7990/stash/scm/QA/stash.git (push)"
|
33
|
-
|
34
|
-
end
|
28
|
+
)
|
35
29
|
assert_equal 'http://adam@sonoma:7990/stash/scm/QA/stash.git', Atlassian::Stash::Git.get_remote_url
|
36
30
|
end
|
37
31
|
|
38
32
|
should "extract remote with multiple remote urls" do
|
39
|
-
Atlassian::Stash::Git.
|
40
|
-
def get_remotes
|
33
|
+
Atlassian::Stash::Git.stubs(:get_remotes).returns(
|
41
34
|
"bitbucket git@bitbucket.org:atlassian/stash-command-line-tools.git (fetch)
|
42
35
|
bitbucket git@bitbucket.org:atlassian/stash-command-line-tools.git (push)
|
43
36
|
kostya http://admin@kostya:7990/scm/CA/cylon.git (fetch)
|
@@ -49,15 +42,12 @@ class TestGit < Minitest::Test
|
|
49
42
|
seb http://adam@sonoma:7990/stash/scm/QA/stash.git (fetch)
|
50
43
|
seb http://adam@sonoma:7990/stash/scm/QA/stash.git (push)
|
51
44
|
upstream http://github-enterprise-11-10/stash/stash.git (fetch)
|
52
|
-
upstream http://github-enterprise-11-10/stash/stash.git (push)"
|
53
|
-
end
|
54
|
-
end
|
45
|
+
upstream http://github-enterprise-11-10/stash/stash.git (push)")
|
55
46
|
assert_equal 'ssh://git@stash.atlassian.com:7999/STASH/stash.git', Atlassian::Stash::Git.get_remote_url
|
56
47
|
end
|
57
48
|
|
58
49
|
should "extract custom remote with multiple remote urls" do
|
59
|
-
Atlassian::Stash::Git.
|
60
|
-
def get_remotes
|
50
|
+
Atlassian::Stash::Git.stubs(:get_remotes).returns(
|
61
51
|
"bitbucket git@bitbucket.org:atlassian/stash-command-line-tools.git (fetch)
|
62
52
|
bitbucket git@bitbucket.org:atlassian/stash-command-line-tools.git (push)
|
63
53
|
kostya http://admin@kostya:7990/scm/CA/cylon.git (fetch)
|
@@ -71,9 +61,20 @@ class TestGit < Minitest::Test
|
|
71
61
|
seb http://adam@sonoma:7990/stash/scm/QA/stash.git (fetch)
|
72
62
|
seb http://adam@sonoma:7990/stash/scm/QA/stash.git (push)
|
73
63
|
upstream http://github-enterprise-11-10/stash/stash.git (fetch)
|
74
|
-
upstream http://github-enterprise-11-10/stash/stash.git (push)"
|
75
|
-
end
|
76
|
-
end
|
64
|
+
upstream http://github-enterprise-11-10/stash/stash.git (push)")
|
77
65
|
assert_equal 'ssh://git@stash.atlassian.com:7999/ATLASSIAN/stash.git', Atlassian::Stash::Git.get_remote_url('upstream')
|
78
66
|
end
|
67
|
+
|
68
|
+
should "repo with no remotes returns nil" do
|
69
|
+
Atlassian::Stash::Git.stubs(:get_remotes).returns("")
|
70
|
+
assert_equal nil, Atlassian::Stash::Git.get_remote_url
|
71
|
+
end
|
72
|
+
|
73
|
+
should "repo with unfound remote returns nil" do
|
74
|
+
Atlassian::Stash::Git.stubs(:get_remotes).returns(
|
75
|
+
"bitbucket git@bitbucket.org:atlassian/stash-command-line-tools.git (fetch)
|
76
|
+
bitbucket git@bitbucket.org:atlassian/stash-command-line-tools.git (push)"
|
77
|
+
)
|
78
|
+
assert_equal nil, Atlassian::Stash::Git.get_remote_url('origin')
|
79
|
+
end
|
79
80
|
end
|
@@ -7,20 +7,21 @@ class TestStashRepoInfo < Minitest::Test
|
|
7
7
|
|
8
8
|
context "Extract repository info" do
|
9
9
|
should "extract project key and repo slug from Stash remote" do
|
10
|
-
|
11
|
-
|
10
|
+
Atlassian::Stash::Git.stubs(:get_remotes).returns("origin https://sruiz@stash-dev.atlassian.com/scm/STASH/stash.git (push)")
|
11
|
+
|
12
|
+
ri = RepoInfo.create({})
|
12
13
|
assert_equal 'STASH', ri.projectKey
|
13
14
|
assert_equal 'stash', ri.slug
|
14
15
|
end
|
15
16
|
|
16
17
|
should "extracting project key and repo slug from non stash url raises exception" do
|
17
|
-
|
18
|
-
assert_raises(RuntimeError) { RepoInfo.create
|
18
|
+
Atlassian::Stash::Git.stubs(:get_remotes).returns("origin git@bitbucket.org:sebr/atlassian-stash-rubygem.git (push)")
|
19
|
+
assert_raises(RuntimeError) { RepoInfo.create({}) }
|
19
20
|
end
|
20
21
|
|
21
22
|
should "repo with hyphes" do
|
22
|
-
|
23
|
-
ri = RepoInfo.create
|
23
|
+
Atlassian::Stash::Git.stubs(:get_remotes).returns("origin https://sruiz@stash-dev.atlassian.com/scm/s745h/stash-repository.git (push)")
|
24
|
+
ri = RepoInfo.create({})
|
24
25
|
assert_equal 's745h', ri.projectKey
|
25
26
|
assert_equal 'stash-repository', ri.slug
|
26
27
|
end
|
@@ -28,14 +29,14 @@ class TestStashRepoInfo < Minitest::Test
|
|
28
29
|
|
29
30
|
context "Create repo url" do
|
30
31
|
setup do
|
31
|
-
|
32
|
+
Atlassian::Stash::Git.stubs(:get_remotes).returns("origin https://sruiz@stash-dev.atlassian.com/scm/STASH/stash.git (push)")
|
32
33
|
end
|
33
34
|
|
34
35
|
should "create expected repo path" do
|
35
36
|
config = {
|
36
37
|
'stash_url' => 'https://www.stash.com'
|
37
38
|
}
|
38
|
-
ri = RepoInfo.create config
|
39
|
+
ri = RepoInfo.create config
|
39
40
|
assert_equal '/projects/STASH/repos/stash', ri.repoPath
|
40
41
|
end
|
41
42
|
|
@@ -43,7 +44,7 @@ class TestStashRepoInfo < Minitest::Test
|
|
43
44
|
config = {
|
44
45
|
'stash_url' => 'https://www.stash.com/foo'
|
45
46
|
}
|
46
|
-
ri = RepoInfo.create config
|
47
|
+
ri = RepoInfo.create config
|
47
48
|
assert_equal '/foo/projects/STASH/repos/stash', ri.repoPath
|
48
49
|
end
|
49
50
|
|
@@ -51,7 +52,7 @@ class TestStashRepoInfo < Minitest::Test
|
|
51
52
|
config = {
|
52
53
|
'stash_url' => 'https://www.stash.com/foo'
|
53
54
|
}
|
54
|
-
ri = RepoInfo.create config
|
55
|
+
ri = RepoInfo.create config
|
55
56
|
assert_equal '/foo/projects/STASH/repos/stash', ri.repoPath
|
56
57
|
end
|
57
58
|
|
@@ -59,7 +60,7 @@ class TestStashRepoInfo < Minitest::Test
|
|
59
60
|
config = {
|
60
61
|
'stash_url' => 'https://www.stash.com'
|
61
62
|
}
|
62
|
-
ri = RepoInfo.create config
|
63
|
+
ri = RepoInfo.create config
|
63
64
|
assert_equal 'https://www.stash.com/projects/STASH/repos/stash', ri.repoUrl(nil, nil)
|
64
65
|
end
|
65
66
|
|
@@ -67,7 +68,7 @@ class TestStashRepoInfo < Minitest::Test
|
|
67
68
|
config = {
|
68
69
|
'stash_url' => 'https://www.stash.com/foo'
|
69
70
|
}
|
70
|
-
ri = RepoInfo.create config
|
71
|
+
ri = RepoInfo.create config
|
71
72
|
assert_equal 'https://www.stash.com/foo/projects/STASH/repos/stash', ri.repoUrl(nil, nil)
|
72
73
|
end
|
73
74
|
|
@@ -75,7 +76,7 @@ class TestStashRepoInfo < Minitest::Test
|
|
75
76
|
config = {
|
76
77
|
'stash_url' => 'https://www.stash.com/foo'
|
77
78
|
}
|
78
|
-
ri = RepoInfo.create config
|
79
|
+
ri = RepoInfo.create config
|
79
80
|
assert_equal 'https://www.stash.com/foo/projects/STASH/repos/stash/commits?at=develop', ri.repoUrl('commits', 'develop')
|
80
81
|
end
|
81
82
|
|
@@ -83,7 +84,7 @@ class TestStashRepoInfo < Minitest::Test
|
|
83
84
|
config = {
|
84
85
|
'stash_url' => 'https://www.stash.com/foo?git=ftw'
|
85
86
|
}
|
86
|
-
ri = RepoInfo.create config
|
87
|
+
ri = RepoInfo.create config
|
87
88
|
assert_equal 'https://www.stash.com/foo/projects/STASH/repos/stash/commits?git=ftw&at=develop', ri.repoUrl('commits', 'develop')
|
88
89
|
end
|
89
90
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: atlassian-stash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Seb Ruiz
|
@@ -164,6 +164,20 @@ dependencies:
|
|
164
164
|
- - '>='
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: mocha
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - '>='
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
167
181
|
description: Provides convenient functions for interacting with Atlassian Stash through
|
168
182
|
the command line
|
169
183
|
email: sruiz@atlassian.com
|