atlassian-stash 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1d0009ed8acaad9711ee3e29dbe108de0b0d2f75
4
- data.tar.gz: 2bf41f992cf2678e4c2ef53c9f2a9253e14af500
3
+ metadata.gz: e6f81d9c053732742249900feca5fddb74f3a461
4
+ data.tar.gz: 27493f645b3d5bf6e773b6764fb0c9770c9c8339
5
5
  SHA512:
6
- metadata.gz: 0ac4b1f8d5130864804dc8188ad38091fd2855ad7d8fc0d853967bdbba83f74beadb328e9c1525f88789318e9f9f90ef474cee7d7a6cdecb3a0949b199282470
7
- data.tar.gz: 176a1f547d3102e85f3034e79dfee1ccb3cdb18754b1058a3efcd07e9d534d248e51348ac28c600f65e522b7a667513b8f265ef04813250a4d5d502f8ffd55a6
6
+ metadata.gz: 295a94d7eccbf34b67c98fb480c5d2a6c865728e7318b8f369d05baee1084614c4fe7d3e15cdf418370d95d1834bfe23928852bd4bb1459ee4117cbb7327a61e
7
+ data.tar.gz: 66bb5e44dd120ddaee257622a3f319aea8c75886ac306bd0ba60ae881ae007ed5bbba531c72390a2e4d9d06d0f1da7f944175d2b68069ebca4e120a5f2fc42ac
data/Gemfile CHANGED
@@ -3,8 +3,8 @@ source "http://rubygems.org"
3
3
  # Example:
4
4
  # gem "activesupport", ">= 2.3.5"
5
5
 
6
- gem "git", "~> 1.2.5"
7
- gem "json", "~> 1.7.5"
6
+ gem "git", ">= 1.2.5"
7
+ gem "json", ">= 1.7.5"
8
8
  gem "commander", "~> 4.1.2"
9
9
  gem "launchy", "~> 2.4.2"
10
10
 
@@ -17,4 +17,5 @@ group :development do
17
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
+ gem "minitest", ">= 0", :platforms => :ruby_19
20
21
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
data/bin/stash CHANGED
@@ -5,6 +5,7 @@ require File.dirname(__FILE__) + "/../lib/stash_cli"
5
5
  require 'commander/import'
6
6
  require 'yaml'
7
7
  require 'launchy'
8
+ require 'pathname'
8
9
 
9
10
  program :name, "Atlassian Stash CLI"
10
11
  program :version, Atlassian::Stash::Version::STRING
@@ -19,9 +20,18 @@ def load_config
19
20
  raise "No Stash configuration found; please run configure" unless File.exists? $configFile
20
21
  config = YAML.load_file($configFile)
21
22
  raise "Stash configuration file is incomplete, please re-run configure" unless config['username'] and config['stash_url']
23
+ config.merge! repo_config
22
24
  config
23
25
  end
24
26
 
27
+ def repo_config
28
+ return @repo_config if @repo_config
29
+ ascender = Pathname.pwd.to_enum(:ascend)
30
+ config_path = ascender.detect { |path| (path + '.stash').exist? }
31
+ @repo_config = YAML.load_file(path + '.stash')
32
+ @repo_config
33
+ end
34
+
25
35
  command 'configure' do |c|
26
36
  c.syntax = 'configure'
27
37
  c.description = 'Setup configuration details to your Stash instance'
@@ -29,10 +39,12 @@ command 'configure' do |c|
29
39
  c.option '--username user', String, 'Writes your Stash username to the configuration file'
30
40
  c.option '--password password', String, 'Writes your Stash user password to the configuration file. If omitted, password will be prompted to be entered'
31
41
  c.option '--stashUrl', String, 'Writes the Stash server url to the configuration file'
42
+ c.option '--remote', String, 'Pull requests will be created in the Stash repository specified by the given remote'
32
43
  c.action do |args, options|
33
44
  username = options.username ? options.username : ask("Stash Username: ")
34
45
  password = options.password ? options.password : ask("Stash Password (optional): ") { |q| q.echo = "*" }
35
46
  stashUrl = options.stashUrl ? options.stashUrl : ask("Stash URL: ")
47
+ remote = options.remote ? options.remote : ask("Remote (optional): ")
36
48
 
37
49
  c = {
38
50
  'stash_url' => stashUrl.to_s
@@ -40,6 +52,7 @@ command 'configure' do |c|
40
52
 
41
53
  c['username'] = username.to_s unless username.empty?
42
54
  c['password'] = password.to_s unless password.empty?
55
+ c['remote'] = remote.to_s unless remote.empty?
43
56
 
44
57
  File.open($configFile, 'w') do |out|
45
58
  YAML.dump(c, out)
@@ -53,16 +66,21 @@ end
53
66
 
54
67
  command 'pull-request' do |c|
55
68
  def extract_reviewers(args = [])
56
- args.collect { |user|
69
+ default_reviewers = Array(repo_config[:reviewers])
70
+ default_reviewers.concat args.collect { |user|
57
71
  user[1..-1] if user.start_with?("@")
58
72
  }.compact
59
73
  end
60
74
 
61
75
  c.syntax = 'pull-request [sourceBranch] targetBranch [@reviewer1 @reviewer2] [options]'
62
76
  c.description = 'Create a pull request in Stash'
77
+ c.option '-d DESCRIPTION', '--description DESCRIPTION', String, 'Use the following description when creating the pull request'
78
+ c.option '-T TITLE', '--title TITLE', String, 'Use the following title when creating the pull request'
79
+ c.option '-r remote', '--remote remote', String, 'Creates the pull request in the Stash repository specified by the given remote'
63
80
  c.option '-o', '--open', 'Open the created pull request page in a web browser'
64
81
  c.example 'stash pull-request topicBranch master @michael', "Create a pull request from branch 'topicBranch' into 'master' with 'michael' added as a reviewer"
65
82
  c.example 'stash pull-request master', "Create a pull request from the current git branch into 'master'"
83
+ 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'"
66
84
  c.action do |args, options|
67
85
  if args.length == 0
68
86
  command(:help).run('pull-request')
@@ -90,13 +108,19 @@ command 'browse' do |c|
90
108
  c.syntax = 'browse [browse|commits|pull-requests]'
91
109
  c.description = 'Open the Stash web ui for this repository'
92
110
  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'
111
+ c.option '-r remote', '--remote remote', String, 'Creates the pull request in the Stash repository specified by the given remote'
93
112
  c.example 'stash browse -b master', 'Open the files view for this repository at the current branch'
113
+ c.example 'stash browse -r upstream', 'Open the files view for the "upstream" remote repository'
94
114
 
95
115
  c.action do |args, options|
96
116
 
97
117
  tab = args.shift unless args.empty?
98
118
 
99
- repoInfo = RepoInfo.create(load_config)
119
+ config = load_config
120
+ remote = options.remote || config['remote']
121
+ remote_url = get_remote_url(remote)
122
+
123
+ repoInfo = RepoInfo.create(config, remote_url)
100
124
 
101
125
  branch = options.branch || get_current_branch
102
126
 
@@ -15,8 +15,8 @@ module Atlassian
15
15
  %x(git remote -v)
16
16
  end
17
17
 
18
- def get_remote_url
19
- origin = get_remotes.split("\n").collect { |r| r.strip }.grep(/^origin.*\(push\)$/).first
18
+ def get_remote_url(remote = 'origin')
19
+ origin = get_remotes.split("\n").collect { |r| r.strip }.grep(/^#{remote}.*\(push\)$/).first
20
20
  URI.extract(origin).first
21
21
  end
22
22
 
@@ -56,7 +56,10 @@ module Atlassian
56
56
  @source = source
57
57
  @target = target
58
58
 
59
- repoInfo = RepoInfo.create(@config)
59
+ remote = get_remote_url(options.remote || @config["remote"])
60
+ repoInfo = RepoInfo.create(@config, remote)
61
+
62
+ title, description = title_and_description(options)
60
63
 
61
64
  resource = CreatePullRequestResource.new(repoInfo.projectKey, repoInfo.slug, title, description, reviewers, @source, @target).resource
62
65
 
@@ -112,14 +115,10 @@ module Atlassian
112
115
 
113
116
  private
114
117
 
115
- def title
118
+ def title_from_branch
116
119
  convert_branch_name_to_sentence(@source) || "Merge '#{@source}' into '#{@target}'"
117
120
  end
118
121
 
119
- def description
120
- git_commit_messages
121
- end
122
-
123
122
  def git_commit_messages
124
123
  @commit_messages ||= `git log --reverse --format=%s #{@target}..#{@source}`
125
124
  end
@@ -135,6 +134,13 @@ module Atlassian
135
134
  end
136
135
  [addr, port]
137
136
  end
137
+
138
+ def title_and_description(options)
139
+ descr = (options.description or git_commit_messages)
140
+ title = (options.title or title_from_branch)
141
+
142
+ [title, descr]
143
+ end
138
144
  end
139
145
  end
140
146
  end
@@ -38,7 +38,7 @@ module Atlassian
38
38
  end
39
39
 
40
40
  def self.create (config, url = get_remote_url)
41
- if m = url.match(/\/([a-zA-Z~][a-zA-Z0-9_]*)\/([[:alnum:]][\w\-\.]*).git$/)
41
+ if m = url.match(/\/([a-zA-Z~][a-zA-Z0-9_\-]*)\/([[:alnum:]][\w\-\.]*).git$/)
42
42
  return RepoInfo.new(config, m[1], m[2])
43
43
  end
44
44
  raise "Repository does not seem to be hosted in Stash; Remote url: " + url
data/test/helper.rb CHANGED
@@ -15,7 +15,7 @@ rescue Bundler::BundlerError => e
15
15
  $stderr.puts "Run `bundle install` to install missing gems"
16
16
  exit e.status_code
17
17
  end
18
- require 'test/unit'
18
+ require 'minitest/autorun'
19
19
  require 'shoulda'
20
20
 
21
21
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
@@ -24,5 +24,5 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
24
24
  require File.dirname(__FILE__) + "/../lib/stash_cli"
25
25
 
26
26
 
27
- class Test::Unit::TestCase
27
+ class Minitest::Test
28
28
  end
@@ -3,7 +3,7 @@ require 'helper'
3
3
  include Atlassian::Stash
4
4
  include Atlassian::Stash::Git
5
5
 
6
- class TestStashCreatePullRequest < Test::Unit::TestCase
6
+ class TestStashCreatePullRequest < Minitest::Test
7
7
 
8
8
  context "#parse_proxy" do
9
9
  setup do
@@ -40,4 +40,45 @@ class TestStashCreatePullRequest < Test::Unit::TestCase
40
40
  end
41
41
  end
42
42
  end
43
+
44
+ context '#title_and_description' do
45
+ setup do
46
+ @cpr = CreatePullRequest.new nil
47
+ def @cpr.title_from_branch; 'title_from_branch'; end
48
+ def @cpr.git_commit_messages; 'git_commit_messages'; end
49
+ @options = Struct.new(:title, :description)
50
+ end
51
+
52
+ context 'with no options' do
53
+ should 'sets default title and description' do
54
+ title, descr = @cpr.send(:title_and_description, @options.new(nil, nil))
55
+ assert_equal title, 'title_from_branch'
56
+ assert_equal descr, 'git_commit_messages'
57
+ end
58
+ end
59
+
60
+ context 'with title option' do
61
+ should 'sets custom title and default description' do
62
+ title, descr = @cpr.send(:title_and_description, @options.new('custom title', nil))
63
+ assert_equal title, 'custom title'
64
+ assert_equal descr, 'git_commit_messages'
65
+ end
66
+ end
67
+
68
+ context 'with description option' do
69
+ should 'sets default title and custom description' do
70
+ title, descr = @cpr.send(:title_and_description, @options.new(nil, 'custom description'))
71
+ assert_equal title, 'title_from_branch'
72
+ assert_equal descr, 'custom description'
73
+ end
74
+ end
75
+
76
+ context 'with both title and description options' do
77
+ should 'sets custom title and description' do
78
+ title, descr = @cpr.send(:title_and_description, @options.new('custom title', 'custom description'))
79
+ assert_equal title, 'custom title'
80
+ assert_equal descr, 'custom description'
81
+ end
82
+ end
83
+ end
43
84
  end
@@ -3,7 +3,7 @@ require 'helper'
3
3
  include Atlassian::Stash
4
4
  include Atlassian::Stash::Git
5
5
 
6
- class TestGit < Test::Unit::TestCase
6
+ class TestGit < Minitest::Test
7
7
 
8
8
  should "extract remote with ssh remote" do
9
9
  Atlassian::Stash::Git.instance_eval do
@@ -54,4 +54,26 @@ class TestGit < Test::Unit::TestCase
54
54
  end
55
55
  assert_equal 'ssh://git@stash.atlassian.com:7999/STASH/stash.git', Atlassian::Stash::Git.get_remote_url
56
56
  end
57
+
58
+ should "extract custom remote with multiple remote urls" do
59
+ Atlassian::Stash::Git.instance_eval do
60
+ def get_remotes
61
+ "bitbucket git@bitbucket.org:atlassian/stash-command-line-tools.git (fetch)
62
+ bitbucket git@bitbucket.org:atlassian/stash-command-line-tools.git (push)
63
+ kostya http://admin@kostya:7990/scm/CA/cylon.git (fetch)
64
+ kostya http://admin@kostya:7990/scm/CA/cylon.git (push)
65
+ local http://delirium:7990/git/STASH/stash.git (fetch)
66
+ local http://delirium:7990/git/STASH/stash.git (push)
67
+ origin ssh://git@stash.atlassian.com:7999/STASH/stash.git (fetch)
68
+ origin ssh://git@stash.atlassian.com:7999/STASH/stash.git (push)
69
+ upstream ssh://git@stash.atlassian.com:7999/ATLASSIAN/stash.git (fetch)
70
+ upstream ssh://git@stash.atlassian.com:7999/ATLASSIAN/stash.git (push)
71
+ seb http://adam@sonoma:7990/stash/scm/QA/stash.git (fetch)
72
+ seb http://adam@sonoma:7990/stash/scm/QA/stash.git (push)
73
+ 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
77
+ assert_equal 'ssh://git@stash.atlassian.com:7999/ATLASSIAN/stash.git', Atlassian::Stash::Git.get_remote_url('upstream')
78
+ end
57
79
  end
@@ -3,7 +3,7 @@ require 'helper'
3
3
  include Atlassian::Stash
4
4
  include Atlassian::Stash::Git
5
5
 
6
- class TestStashRepoInfo < Test::Unit::TestCase
6
+ 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
@@ -15,7 +15,7 @@ class TestStashRepoInfo < Test::Unit::TestCase
15
15
 
16
16
  should "extracting project key and repo slug from non stash url raises exception" do
17
17
  remote = "git@bitbucket.org:sebr/atlassian-stash-rubygem.git"
18
- assert_raise(RuntimeError) { RepoInfo.create nil, remote }
18
+ assert_raises(RuntimeError) { RepoInfo.create nil, remote }
19
19
  end
20
20
 
21
21
  should "repo with hyphes" do
@@ -1,7 +1,7 @@
1
1
 
2
2
  include Atlassian::Util::TextUtil
3
3
 
4
- class TextUtilTest < Test::Unit::TestCase
4
+ class TextUtilTest < Minitest::Test
5
5
 
6
6
  context "to_sentence_case" do
7
7
  should "work with an empty string" do
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atlassian-stash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.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-04-30 00:00:00.000000000 Z
11
+ date: 2014-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.2.5
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.2.5
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: json
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: 1.7.5
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.7.5
41
41
  - !ruby/object:Gem::Dependency
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - '>='
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: minitest
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
153
167
  description: Provides convenient functions for interacting with Atlassian Stash through
154
168
  the command line
155
169
  email: sruiz@atlassian.com