atlassian-stash 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/bin/stash +30 -0
- data/lib/atlassian/stash/git.rb +10 -0
- data/lib/atlassian/stash/pull_request.rb +16 -9
- data/test/test_stash-git.rb +17 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f542f9e4f0ec7a27fc9a7a24ba23946f1e498aec
|
4
|
+
data.tar.gz: b842b2d4caaa4f6ccbe06174ab626d27521fbe4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2dc56d9a2571ffd9fd5cb65cbccb741ac979f8fb29fa1dfbe408eb6591652e5d2334412a2ed1708b05edaa10a751c684ff82c1d4825090bb034c35e92cec7f7a
|
7
|
+
data.tar.gz: dc1b2b8fc10e8d86c8a8137a303505487cce431be380a4d4f51d61e921a06b76742df541acb6260278cc6180b4ed541e0e137f63be6523dd530bd4bcf907d308
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/bin/stash
CHANGED
@@ -86,6 +86,8 @@ command 'pull-request' do |c|
|
|
86
86
|
c.example 'stash pull-request topicBranch master @michael', "Create a pull request from branch 'topicBranch' into 'master' with 'michael' added as a reviewer"
|
87
87
|
c.example 'stash pull-request master', "Create a pull request from the current git branch into 'master'"
|
88
88
|
c.example 'stash pull-request master -T "JIRA-1234 new feature" -d "Adds new feature as described in JIRA-1234"', "Create a pull request from the current git branch into 'master' with the title 'JIRA-1234 new feature' and description 'Adds new feature as described in JIRA-1234'"
|
89
|
+
c.example 'stash pull-request topicBranch upstream/master', "Create a pull request from branch 'topicBranch' into branch 'master' on the remote named 'upstream'"
|
90
|
+
c.example 'stash pull-request remotes/upstream/master', "Create a pull request from the current branch into branch 'master' on the remote named 'upstream'"
|
89
91
|
c.action do |args, options|
|
90
92
|
if args.length == 0
|
91
93
|
command(:help).run('pull-request')
|
@@ -102,6 +104,34 @@ command 'pull-request' do |c|
|
|
102
104
|
reviewers = extract_reviewers args
|
103
105
|
end
|
104
106
|
|
107
|
+
# Strip out any starting 'remotes/' from branch name for matching
|
108
|
+
if source.index('remotes/') == 0
|
109
|
+
source = source['remotes/'.size..-1]
|
110
|
+
end
|
111
|
+
if target.index('remotes/') == 0
|
112
|
+
target = target['remotes/'.size..-1]
|
113
|
+
end
|
114
|
+
|
115
|
+
options.src_remote = options.remote
|
116
|
+
if not is_branch?(source)
|
117
|
+
if not is_branch?("remotes/" + source)
|
118
|
+
raise "fatal: unrecogonized source branch"
|
119
|
+
end
|
120
|
+
# If a remote matches, split the remote out of the refspec
|
121
|
+
options.src_remote = source.split('/')[0]
|
122
|
+
source = source.split('/')[1..-1].join('/')
|
123
|
+
end
|
124
|
+
|
125
|
+
options.target_remote = options.remote
|
126
|
+
if not is_branch?(target)
|
127
|
+
if not is_branch?("remotes/" + target)
|
128
|
+
raise "fatal: unrecognized target branch"
|
129
|
+
end
|
130
|
+
# If a remote matches, split the remote out of the refspec
|
131
|
+
options.target_remote = target.split('/')[0]
|
132
|
+
target = target.split('/')[1..-1].join('/')
|
133
|
+
end
|
134
|
+
|
105
135
|
ensure_within_git! do
|
106
136
|
cpr = CreatePullRequest.new(load_config)
|
107
137
|
cpr.create_pull_request source, target, reviewers, options
|
data/lib/atlassian/stash/git.rb
CHANGED
@@ -10,6 +10,16 @@ module Atlassian
|
|
10
10
|
%x(git symbolic-ref HEAD)[/refs\/heads\/(.*)/, 1]
|
11
11
|
end
|
12
12
|
|
13
|
+
def get_branches()
|
14
|
+
all = %x{git branch -a}.gsub("*","").gsub(" ", "").split("\n")
|
15
|
+
all.select{|x| not x.include? "->"}
|
16
|
+
end
|
17
|
+
|
18
|
+
def is_branch?(match)
|
19
|
+
all = get_branches
|
20
|
+
not all.select{|x| x == match}.empty?
|
21
|
+
end
|
22
|
+
|
13
23
|
def is_in_git_repository?
|
14
24
|
system('git rev-parse')
|
15
25
|
end
|
@@ -11,20 +11,26 @@ module Atlassian
|
|
11
11
|
class CreatePullRequestResource
|
12
12
|
attr_accessor :resource
|
13
13
|
|
14
|
-
def initialize(
|
15
|
-
|
16
|
-
'slug' => slug,
|
14
|
+
def initialize(sourceRepoInfo, targetRepoInfo, title, description, reviewers, source, target)
|
15
|
+
src_repository = {
|
16
|
+
'slug' => sourceRepoInfo.slug,
|
17
17
|
'project' => {
|
18
|
-
'key' => projectKey
|
18
|
+
'key' => sourceRepoInfo.projectKey
|
19
|
+
}
|
20
|
+
}
|
21
|
+
target_repository = {
|
22
|
+
'slug' => targetRepoInfo.slug,
|
23
|
+
'project' => {
|
24
|
+
'key' => targetRepoInfo.projectKey
|
19
25
|
}
|
20
26
|
}
|
21
27
|
fromRef = {
|
22
28
|
'id' => source,
|
23
|
-
'repository' =>
|
29
|
+
'repository' => src_repository
|
24
30
|
}
|
25
31
|
toRef = {
|
26
32
|
'id' => target,
|
27
|
-
'repository' =>
|
33
|
+
'repository' => target_repository
|
28
34
|
}
|
29
35
|
@resource = {
|
30
36
|
'title' => title,
|
@@ -56,11 +62,12 @@ module Atlassian
|
|
56
62
|
@source = source
|
57
63
|
@target = target
|
58
64
|
|
59
|
-
|
65
|
+
srcRepoInfo = RepoInfo.create(@config, options.src_remote)
|
66
|
+
targetRepoInfo = RepoInfo.create(@config, options.target_remote)
|
60
67
|
|
61
68
|
title, description = title_and_description(options)
|
62
69
|
|
63
|
-
resource = CreatePullRequestResource.new(
|
70
|
+
resource = CreatePullRequestResource.new(srcRepoInfo, targetRepoInfo, title, description, reviewers, @source, @target).resource
|
64
71
|
|
65
72
|
username = @config["username"]
|
66
73
|
password = @config["password"]
|
@@ -70,7 +77,7 @@ module Atlassian
|
|
70
77
|
password = ask("Password: ") { |q| q.echo = '*' } unless @config["password"]
|
71
78
|
|
72
79
|
uri = URI.parse(@config["stash_url"])
|
73
|
-
prPath =
|
80
|
+
prPath = targetRepoInfo.repoPath + '/pull-requests'
|
74
81
|
|
75
82
|
req = Net::HTTP::Post.new(uri.query.nil? ? "#{prPath}" : "#{prPath}?#{uri.query}", {'Content-Type' => 'application/json', 'Accept' => 'application/json'})
|
76
83
|
req.basic_auth username, password
|
data/test/test_stash-git.rb
CHANGED
@@ -77,4 +77,20 @@ class TestGit < Minitest::Test
|
|
77
77
|
)
|
78
78
|
assert_equal nil, Atlassian::Stash::Git.get_remote_url('origin')
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
|
+
should "branches are matched" do
|
82
|
+
Atlassian::Stash::Git.stubs(:get_branches).returns(
|
83
|
+
" feature
|
84
|
+
temp
|
85
|
+
* master
|
86
|
+
remotes/origin/master
|
87
|
+
remotes/origin/release/v1.0
|
88
|
+
remotes/origin/feature/awesome
|
89
|
+
remotes/upstream/master
|
90
|
+
remotes/upstream/release/v1.0
|
91
|
+
remotes/upstream/feature/Issue7")
|
92
|
+
assert_equal true, Atlassian::Stash::Git.is_branch?('master')
|
93
|
+
assert_equal true, Atlassian::Stash::Git.is_branch?('remotes/upstream/master')
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: atlassian-stash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Seb Ruiz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: git
|
@@ -226,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
226
226
|
version: '0'
|
227
227
|
requirements: []
|
228
228
|
rubyforge_project:
|
229
|
-
rubygems_version: 2.2
|
229
|
+
rubygems_version: 2.4.2
|
230
230
|
signing_key:
|
231
231
|
specification_version: 4
|
232
232
|
summary: Command line tools for Atlassian Stash
|