atlassian-stash 0.1.8 → 0.1.9

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d28ba066e1e70f765042c3fc2387e87d30cce8db
4
+ data.tar.gz: 0a5704ce8f49dbe7d6a94a71eb0c2b7ac95f9330
5
+ SHA512:
6
+ metadata.gz: 6d5bdc31894cd70d496ffe4de1992c3b276683dda42c9d40aaded6994444fbfeac938456bf88f0baf09a5cc45da0436c3521330c32f11f14aa90cea1a1215361
7
+ data.tar.gz: 921109a45341bd763ca3ec3872162e8d16f26c73d1b662307955f96a92b0de178259bd3b00e666b761ad2bf0f1fcc415c0f519b0cc0c588438698a609e2fbf39
data/Gemfile CHANGED
@@ -14,7 +14,7 @@ group :development do
14
14
  gem "shoulda", ">= 0"
15
15
  gem "rdoc", "~> 3.12"
16
16
  gem "bundler", ">= 1.2.0"
17
- gem "jeweler", "~> 1.8.4"
17
+ gem "jeweler", "~> 2.0.0"
18
18
  gem "rcov", ">= 0", :platforms => :ruby_18
19
19
  gem "simplecov", ">= 0", :platforms => :ruby_19, :require => "false"
20
20
  end
data/README.md CHANGED
@@ -3,7 +3,8 @@
3
3
  ## Installing this tool
4
4
  This command line helper for Stash is written in Ruby and is deployed as a [Ruby Gem](https://rubygems.org/gems/atlassian-stash/). Installation is easy, simply run the following command
5
5
 
6
- $> gem install atlassian-stash
6
+ :::text
7
+ $> gem install atlassian-stash
7
8
 
8
9
  (Protip: you might need to `sudo`)
9
10
 
@@ -15,18 +16,33 @@ Run `stash configure`. This will prompt for details about your Stash instance. I
15
16
  ### Creating a pull request
16
17
  Use the `pull-request` command to create a pull request in Stash. E.g:
17
18
 
18
- $> stash pull-request topicBranch master @michael
19
- Create a pull request from branch 'topicBranch' into 'master' with 'michael' added as a reviewer
19
+ :::text
20
+ $> stash pull-request topicBranch master @michael
21
+ Create a pull request from branch 'topicBranch' into 'master' with 'michael' added as a reviewer
20
22
 
21
23
  See the usage for command details
22
24
 
23
- stash help
25
+ :::text
26
+ stash help pull-request
27
+
28
+ ### Opening the Stash web UI
29
+ Use the `browse` command to open the Stash UI for your repository in the browser.
30
+
31
+ :::text
32
+ $> stash browse -b develop
33
+ Open the browser at the Stash repository page for the branch 'develop'
34
+
35
+ For more options, see the help
36
+
37
+ :::text
38
+ stash help browse
24
39
 
25
40
  ## Troubleshooting
26
41
  Q: I installed the gem, but the `stash` command doesn't work.
27
42
  A: Do you have another command called `stash` or do you have an alias? Have a look where the command maps to
28
43
 
29
- $> which -a stash
44
+ :::text
45
+ $> which -a stash
30
46
 
31
47
  Then check the value of your $PATH
32
48
 
@@ -36,7 +52,8 @@ Thanks! Please [fork this project](https://bitbucket.org/atlassian/stash-command
36
52
  ### Build instructions
37
53
  Building this gem is easy. To get started, run the following commands:
38
54
 
39
- $> gem install bundler
40
- $> bundle install
55
+ :::text
56
+ $> gem install bundler
57
+ $> bundle install
41
58
 
42
59
  Now start hacking, and run the stash command by invoking `./bin/stash command`
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.8
1
+ 0.1.9
data/bin/stash CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  require 'rubygems'
4
4
  require File.dirname(__FILE__) + "/../lib/stash_cli"
5
- #require 'stash_cli'
6
5
  require 'commander/import'
7
6
  require 'yaml'
7
+ require 'launchy'
8
8
 
9
9
  program :name, "Atlassian Stash CLI"
10
10
  program :version, Atlassian::Stash::Version::STRING
@@ -86,9 +86,28 @@ command 'pull-request' do |c|
86
86
  end
87
87
  end
88
88
 
89
+ command 'browse' do |c|
90
+ c.syntax = 'browse [browse|commits|pull-requests]'
91
+ c.description = 'Open the Stash web ui for this repository'
92
+ c.option '-b branch', '--branch branch', String, 'Open the Stash web ui at the specified branch, tag or commit hash. Defaults to the current branch'
93
+ c.example 'stash browse -b master', 'Open the files view for this repository at the current branch'
94
+
95
+ c.action do |args, options|
96
+
97
+ tab = args.shift unless args.empty?
98
+
99
+ repoInfo = RepoInfo.create(load_config)
100
+
101
+ branch = options.branch || get_current_branch
102
+
103
+ Launchy.open repoInfo.repoUrl(tab, branch)
104
+ end
105
+ end
106
+
107
+
89
108
  default_command :help
90
109
  program :help_formatter, :compact
91
- program :help, 'Authors', 'Seb Ruiz <sruiz@atlassian.com> with others'
110
+ program :help, 'Authors', 'Seb Ruiz <sruiz@atlassian.com>'
92
111
  program :help, 'Website', 'https://bitbucket.org/atlassian/stash-command-line-tools'
93
112
 
94
113
 
@@ -45,26 +45,17 @@ module Atlassian
45
45
 
46
46
  class CreatePullRequest
47
47
 
48
- RepoInfo = Struct.new(:projectKey, :slug)
49
-
50
48
  def initialize(config)
51
49
  @config = config
52
50
  end
53
51
 
54
- def extract_repository_info (url = get_remote_url)
55
- if m = url.match(/\/([a-zA-Z~][a-zA-Z0-9_]*)\/([[:alnum:]][\w\-\.]*).git$/)
56
- return RepoInfo.new(m[1], m[2])
57
- end
58
- raise "Repository does not seem to be hosted in Stash"
59
- end
60
-
61
52
  def create_pull_request(source, target, reviewers, options)
62
53
  Process.exit if not target or not source
63
54
 
64
55
  @source = source
65
56
  @target = target
66
57
 
67
- repoInfo = extract_repository_info
58
+ repoInfo = RepoInfo.create(@config)
68
59
 
69
60
  resource = CreatePullRequestResource.new(repoInfo.projectKey, repoInfo.slug, title, description, reviewers, @source, @target).resource
70
61
 
@@ -76,10 +67,9 @@ module Atlassian
76
67
  password = ask("Password: ") { |q| q.echo = '*' } unless @config["password"]
77
68
 
78
69
  uri = URI.parse(@config["stash_url"])
79
- prPath = uri.path + '/projects/' + repoInfo.projectKey + '/repos/' + repoInfo.slug + '/pull-requests'
80
- prPath = uri.query.nil? ? "#{prPath}" : "#{prPath}?#{uri.query}"
81
-
82
- req = Net::HTTP::Post.new(prPath, {'Content-Type' => 'application/json', 'Accept' => 'application/json'})
70
+ prPath = repoInfo.repoPath + '/pull-requests'
71
+
72
+ req = Net::HTTP::Post.new(uri.query.nil? ? "#{prPath}" : "#{prPath}?#{uri.query}", {'Content-Type' => 'application/json', 'Accept' => 'application/json'})
83
73
  req.basic_auth username, password
84
74
  req.body = resource.to_json
85
75
  http = Net::HTTP.new(uri.host, uri.port, proxy_addr, proxy_port)
@@ -110,6 +100,7 @@ module Atlassian
110
100
  responseBody = JSON.parse(response.body)
111
101
  prUri = uri.clone
112
102
  prUri.path = prPath + '/' + responseBody['id'].to_s
103
+ prUri.query = uri.query
113
104
  puts prUri.to_s
114
105
 
115
106
  if @config["open"] || options.open
@@ -0,0 +1,48 @@
1
+ require 'git'
2
+
3
+ module Atlassian
4
+ module Stash
5
+ class RepoInfo
6
+ def initialize(config, projectKey, slug)
7
+ @config = config
8
+ @projectKey = projectKey
9
+ @slug = slug
10
+ end
11
+
12
+ def projectKey
13
+ @projectKey
14
+ end
15
+
16
+ def slug
17
+ @slug
18
+ end
19
+
20
+ def repoPath
21
+ uri = URI.parse(@config["stash_url"])
22
+ repoPath = uri.path + '/projects/' + @projectKey + '/repos/' + @slug
23
+ repoPath
24
+ end
25
+
26
+ def repoUrl(suffix, branch)
27
+ uri = URI.parse(@config["stash_url"])
28
+ path = repoPath + (suffix.nil? ? '' : '/' + suffix)
29
+ uri.path = path
30
+
31
+ if (!branch.nil? and !branch.empty?)
32
+ q = uri.query || ''
33
+ q = q + (q.empty? ? '' : '&') + 'at=' + branch unless branch.nil?
34
+ uri.query = q
35
+ end
36
+
37
+ uri.to_s
38
+ end
39
+
40
+ def self.create (config, url = get_remote_url)
41
+ if m = url.match(/\/([a-zA-Z~][a-zA-Z0-9_]*)\/([[:alnum:]][\w\-\.]*).git$/)
42
+ return RepoInfo.new(config, m[1], m[2])
43
+ end
44
+ raise "Repository does not seem to be hosted in Stash; Remote url: " + url
45
+ end
46
+ end
47
+ end
48
+ end
@@ -5,30 +5,6 @@ include Atlassian::Stash::Git
5
5
 
6
6
  class TestStashCreatePullRequest < Test::Unit::TestCase
7
7
 
8
- context "Extract repository info" do
9
- should "extract project key and repo slug from Stash remote" do
10
- remote = "https://sruiz@stash-dev.atlassian.com/scm/STASH/stash.git"
11
- cpr = CreatePullRequest.new nil
12
- ri = cpr.extract_repository_info remote
13
- assert_equal 'STASH', ri.projectKey
14
- assert_equal 'stash', ri.slug
15
- end
16
-
17
- should "extracting project key and repo slug from non stash url raises exception" do
18
- remote = "git@bitbucket.org:sebr/atlassian-stash-rubygem.git"
19
- cpr = CreatePullRequest.new nil
20
- assert_raise(RuntimeError) { cpr.extract_repository_info remote }
21
- end
22
-
23
- should "repo with hyphes" do
24
- remote = "https://sruiz@stash-dev.atlassian.com/scm/s745h/stash-repository.git"
25
- cpr = CreatePullRequest.new nil
26
- ri = cpr.extract_repository_info remote
27
- assert_equal 's745h', ri.projectKey
28
- assert_equal 'stash-repository', ri.slug
29
- end
30
- end
31
-
32
8
  context "#parse_proxy" do
33
9
  setup do
34
10
  @cpr = CreatePullRequest.new nil
@@ -0,0 +1,90 @@
1
+ require 'helper'
2
+
3
+ include Atlassian::Stash
4
+ include Atlassian::Stash::Git
5
+
6
+ class TestStashRepoInfo < Test::Unit::TestCase
7
+
8
+ context "Extract repository info" do
9
+ should "extract project key and repo slug from Stash remote" do
10
+ remote = "https://sruiz@stash-dev.atlassian.com/scm/STASH/stash.git"
11
+ ri = RepoInfo.create nil, remote
12
+ assert_equal 'STASH', ri.projectKey
13
+ assert_equal 'stash', ri.slug
14
+ end
15
+
16
+ should "extracting project key and repo slug from non stash url raises exception" do
17
+ remote = "git@bitbucket.org:sebr/atlassian-stash-rubygem.git"
18
+ assert_raise(RuntimeError) { RepoInfo.create nil, remote }
19
+ end
20
+
21
+ should "repo with hyphes" do
22
+ remote = "https://sruiz@stash-dev.atlassian.com/scm/s745h/stash-repository.git"
23
+ ri = RepoInfo.create nil, remote
24
+ assert_equal 's745h', ri.projectKey
25
+ assert_equal 'stash-repository', ri.slug
26
+ end
27
+ end
28
+
29
+ context "Create repo url" do
30
+ setup do
31
+ @remote = "https://sruiz@stash-dev.atlassian.com/scm/STASH/stash.git"
32
+ end
33
+
34
+ should "create expected repo path" do
35
+ config = {
36
+ 'stash_url' => 'https://www.stash.com'
37
+ }
38
+ ri = RepoInfo.create config, @remote
39
+ assert_equal '/projects/STASH/repos/stash', ri.repoPath
40
+ end
41
+
42
+ should "create expected repo path with context" do
43
+ config = {
44
+ 'stash_url' => 'https://www.stash.com/foo'
45
+ }
46
+ ri = RepoInfo.create config, @remote
47
+ assert_equal '/foo/projects/STASH/repos/stash', ri.repoPath
48
+ end
49
+
50
+ should "create expected repo path with context and query" do
51
+ config = {
52
+ 'stash_url' => 'https://www.stash.com/foo'
53
+ }
54
+ ri = RepoInfo.create config, @remote
55
+ assert_equal '/foo/projects/STASH/repos/stash', ri.repoPath
56
+ end
57
+
58
+ should "create expected repo url with no suffix or branch" do
59
+ config = {
60
+ 'stash_url' => 'https://www.stash.com'
61
+ }
62
+ ri = RepoInfo.create config, @remote
63
+ assert_equal 'https://www.stash.com/projects/STASH/repos/stash', ri.repoUrl(nil, nil)
64
+ end
65
+
66
+ should "create expected repo url with context" do
67
+ config = {
68
+ 'stash_url' => 'https://www.stash.com/foo'
69
+ }
70
+ ri = RepoInfo.create config, @remote
71
+ assert_equal 'https://www.stash.com/foo/projects/STASH/repos/stash', ri.repoUrl(nil, nil)
72
+ end
73
+
74
+ should "create expected repo url with path and branch" do
75
+ config = {
76
+ 'stash_url' => 'https://www.stash.com/foo'
77
+ }
78
+ ri = RepoInfo.create config, @remote
79
+ assert_equal 'https://www.stash.com/foo/projects/STASH/repos/stash/commits?at=develop', ri.repoUrl('commits', 'develop')
80
+ end
81
+
82
+ should "create expected repo url with context, query, path and branch" do
83
+ config = {
84
+ 'stash_url' => 'https://www.stash.com/foo?git=ftw'
85
+ }
86
+ ri = RepoInfo.create config, @remote
87
+ assert_equal 'https://www.stash.com/foo/projects/STASH/repos/stash/commits?git=ftw&at=develop', ri.repoUrl('commits', 'develop')
88
+ end
89
+ end
90
+ end
metadata CHANGED
@@ -1,100 +1,88 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atlassian-stash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
5
- prerelease:
4
+ version: 0.1.9
6
5
  platform: ruby
7
6
  authors:
8
7
  - Seb Ruiz
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-11-13 00:00:00.000000000 Z
11
+ date: 2014-01-15 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: git
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: json
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: commander
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: launchy
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :runtime
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: shoulda
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: rdoc
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
87
  - - ~>
100
88
  - !ruby/object:Gem::Version
@@ -102,7 +90,6 @@ dependencies:
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
94
  - - ~>
108
95
  - !ruby/object:Gem::Version
@@ -110,65 +97,57 @@ dependencies:
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: bundler
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
- - - ! '>='
101
+ - - '>='
116
102
  - !ruby/object:Gem::Version
117
103
  version: 1.2.0
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
- - - ! '>='
108
+ - - '>='
124
109
  - !ruby/object:Gem::Version
125
110
  version: 1.2.0
126
111
  - !ruby/object:Gem::Dependency
127
112
  name: jeweler
128
113
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
114
  requirements:
131
115
  - - ~>
132
116
  - !ruby/object:Gem::Version
133
- version: 1.8.4
117
+ version: 2.0.0
134
118
  type: :development
135
119
  prerelease: false
136
120
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
121
  requirements:
139
122
  - - ~>
140
123
  - !ruby/object:Gem::Version
141
- version: 1.8.4
124
+ version: 2.0.0
142
125
  - !ruby/object:Gem::Dependency
143
126
  name: rcov
144
127
  requirement: !ruby/object:Gem::Requirement
145
- none: false
146
128
  requirements:
147
- - - ! '>='
129
+ - - '>='
148
130
  - !ruby/object:Gem::Version
149
131
  version: '0'
150
132
  type: :development
151
133
  prerelease: false
152
134
  version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
135
  requirements:
155
- - - ! '>='
136
+ - - '>='
156
137
  - !ruby/object:Gem::Version
157
138
  version: '0'
158
139
  - !ruby/object:Gem::Dependency
159
140
  name: simplecov
160
141
  requirement: !ruby/object:Gem::Requirement
161
- none: false
162
142
  requirements:
163
- - - ! '>='
143
+ - - '>='
164
144
  - !ruby/object:Gem::Version
165
145
  version: '0'
166
146
  type: :development
167
147
  prerelease: false
168
148
  version_requirements: !ruby/object:Gem::Requirement
169
- none: false
170
149
  requirements:
171
- - - ! '>='
150
+ - - '>='
172
151
  - !ruby/object:Gem::Version
173
152
  version: '0'
174
153
  description: Provides convenient functions for interacting with Atlassian Stash through
@@ -189,40 +168,38 @@ files:
189
168
  - VERSION
190
169
  - bin/stash
191
170
  - lib/atlassian/stash/git.rb
192
- - lib/atlassian/stash/pullrequest.rb
171
+ - lib/atlassian/stash/pull_request.rb
172
+ - lib/atlassian/stash/repo_info.rb
193
173
  - lib/atlassian/stash/version.rb
194
174
  - lib/atlassian/util/text_util.rb
195
175
  - lib/stash_cli.rb
196
176
  - test/helper.rb
197
177
  - test/test_stash-create-pull-request.rb
198
178
  - test/test_stash-git.rb
179
+ - test/test_stash-repo-info.rb
199
180
  - test/test_text-util.rb
200
181
  homepage: https://bitbucket.org/atlassian/stash-command-line-tools
201
182
  licenses:
202
183
  - MIT
184
+ metadata: {}
203
185
  post_install_message:
204
186
  rdoc_options: []
205
187
  require_paths:
206
188
  - lib
207
189
  required_ruby_version: !ruby/object:Gem::Requirement
208
- none: false
209
190
  requirements:
210
- - - ! '>='
191
+ - - '>='
211
192
  - !ruby/object:Gem::Version
212
193
  version: '0'
213
- segments:
214
- - 0
215
- hash: 4305375427045807658
216
194
  required_rubygems_version: !ruby/object:Gem::Requirement
217
- none: false
218
195
  requirements:
219
- - - ! '>='
196
+ - - '>='
220
197
  - !ruby/object:Gem::Version
221
198
  version: '0'
222
199
  requirements: []
223
200
  rubyforge_project:
224
- rubygems_version: 1.8.25
201
+ rubygems_version: 2.2.1
225
202
  signing_key:
226
- specification_version: 3
203
+ specification_version: 4
227
204
  summary: Command line tools for Atlassian Stash
228
205
  test_files: []