stash_cli 0.1.5 → 0.1.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: da8c1066129b0faf86a427e81d3350db5e41c95d
4
- data.tar.gz: 35f494b920588f3bd0956f89cbeae7a9dd3016a0
3
+ metadata.gz: 85972d5793f307d24064947ea8bb06d761f3454b
4
+ data.tar.gz: a4f27190b20c818a5444179c4ad96797c93fff96
5
5
  SHA512:
6
- metadata.gz: 2f7a11fdb2ad5e1af04b85bdf51706c2d84c342c30c2560378f958bab529663fb96f92cd8057e026915e9ecdb077d4d6319cc775f322fa873394308927f64940
7
- data.tar.gz: b2704403d36f246e0c918ac5a74aa6b31df073fed4df38409114fadef9f4d232482f639360c675dc0aee91e4a756e69ca27cc5226b3cb429b62a749a3220b314
6
+ metadata.gz: bbb32178046b6588656ccd6b93d072f1c382eebf7720aed4caffa144290a7adb38374a3078803bb75e23808cb3f1bb9d29900eb5ff49ed94c152a9c61b81ca21
7
+ data.tar.gz: a598cf00ec8de8851c0584d43fe3a558d4daf28411d3e9baa0538ff46848232833680e94cb9550a65160ae32593b489af1e5b2e17e957e4012910ea02947beed
data/lib/stash_cli/cli.rb CHANGED
@@ -5,11 +5,14 @@ require 'base64'
5
5
 
6
6
  require 'stash_cli/client'
7
7
  require 'stash_cli/git_utils'
8
+ require 'stash_cli/project'
8
9
 
9
10
  module StashCLI
10
11
  class CLI < Thor
11
12
  include Thor::Actions
12
13
 
14
+ attr_reader :project
15
+
13
16
  def self.source_root
14
17
  File.dirname(__FILE__)
15
18
  end
@@ -65,7 +68,7 @@ module StashCLI
65
68
  def branches
66
69
  configure
67
70
  client = Client.new(configatron.server, configatron.auth_token)
68
- resp = client.branches(configatron.defaults.project, configatron.defaults.source_slug)
71
+ resp = client.branches(project.project, project.source_slug)
69
72
  resp['values'].each do |value|
70
73
  say value['displayId']
71
74
  end
@@ -237,16 +240,16 @@ module StashCLI
237
240
  def default_pr(title)
238
241
  reviewers = initial_reviewers
239
242
 
240
- target_branch = configatron.defaults.target_branch
243
+ target_branch = project.target_branch
241
244
  target_branch = options[:branch] if options[:branch]
242
245
 
243
246
  opts = {
244
247
  title: title,
245
- project: configatron.defaults.project,
248
+ project: project.project,
246
249
  from_branch: GitUtils.current_branch,
247
- from_slug: configatron.defaults.source_slug,
250
+ from_slug: project.source_slug,
248
251
  target_branch: target_branch,
249
- target_slug: configatron.defaults.target_slug,
252
+ target_slug: project.target_slug,
250
253
  reviewers: reviewers
251
254
  }
252
255
 
@@ -260,11 +263,11 @@ module StashCLI
260
263
  def interactive_pr(title)
261
264
 
262
265
  target_branch =
263
- ask("target branch [#{configatron.defaults.target_branch}]:").strip
266
+ ask("target branch [#{project.target_branch}]:").strip
264
267
 
265
268
  description = get_description(target_branch)
266
269
 
267
- target_branch = configatron.defaults.target_branch if target_branch.empty?
270
+ target_branch = project.target_branch if target_branch.empty?
268
271
 
269
272
  reviewers = initial_reviewers
270
273
 
@@ -281,11 +284,11 @@ module StashCLI
281
284
 
282
285
  opts = {
283
286
  title: title,
284
- project: configatron.defaults.project,
287
+ project: project.project,
285
288
  from_branch: GitUtils.current_branch,
286
- from_slug: configatron.defaults.source_slug,
289
+ from_slug: project.source_slug,
287
290
  target_branch: target_branch,
288
- target_slug: configatron.defaults.target_slug,
291
+ target_slug: project.target_slug,
289
292
  reviewers: reviewers
290
293
  }
291
294
 
@@ -303,6 +306,39 @@ module StashCLI
303
306
  say 'generate a basic config with "stash init"'
304
307
  exit 1
305
308
  end
309
+
310
+ repo_dir = GitUtils.repo_dir
311
+ proj_file = File.join(repo_dir, '.stash-proj')
312
+
313
+ if File.exist?(proj_file)
314
+ say 'using project from .stash-proj file'
315
+ project_name = File.read('.stash-proj').strip
316
+
317
+ # If you're declaring the project it had better exist
318
+ unless configatron.projects.has_key?(project_name)
319
+ say "!! project: #{project_name} requested but not defined !!"
320
+ say 'add this project to your .stash_cli.yml or remove the .stash-proj file'
321
+ exit 1
322
+ end
323
+ else
324
+ project_name = File.basename(repo_dir)
325
+ end
326
+
327
+ if configatron.projects.has_key?(project_name)
328
+ say "using defined project: #{project_name}"
329
+ @project = Project.new(
330
+ configatron.projects[project_name].project,
331
+ configatron.projects[project_name].source_slug,
332
+ configatron.projects[project_name].target_slug,
333
+ configatron.projects[project_name].target_branch)
334
+
335
+ else
336
+ @project = Project.new(
337
+ configatron.defaults.project,
338
+ configatron.defaults.source_slug,
339
+ configatron.defaults.target_slug,
340
+ configatron.defaults.target_branch)
341
+ end
306
342
  end
307
343
 
308
344
  def ask_required(statement, *args)
@@ -1,5 +1,9 @@
1
1
  module StashCLI
2
2
  module GitUtils
3
+ def self.repo_dir
4
+ `git rev-parse --show-toplevel`.strip
5
+ end
6
+
3
7
  def self.current_branch
4
8
  `git rev-parse --abbrev-ref HEAD`.strip
5
9
  end
@@ -0,0 +1,12 @@
1
+ module StashCLI
2
+ class Project
3
+ attr_reader :project, :source_slug, :target_slug, :target_branch
4
+
5
+ def initialize(project, source_slug, target_slug, target_branch)
6
+ @project = project
7
+ @source_slug = source_slug
8
+ @target_slug = target_slug
9
+ @target_branch = target_branch
10
+ end
11
+ end
12
+ end
@@ -4,7 +4,7 @@ module StashCLI
4
4
 
5
5
  def self.from_response(response, base_url)
6
6
  id = response['id']
7
- url = File.join(base_url, response['link']['url'])
7
+ url = response['links']['self'].first['href']
8
8
  PullRequest.new(id, url)
9
9
  end
10
10
 
@@ -12,6 +12,16 @@ defaults:
12
12
  target_slug: <%= @target %>
13
13
  target_branch: <%= @target_branch %>
14
14
 
15
+ # You can specify a list of projects here. Projects are detected via the
16
+ # basename of the git repo directory or via a .stash-proj file at
17
+ # <git repo basename>/.stash-proj. The must contain one line: the project name
18
+ # projects:
19
+ # my-proj:
20
+ # project: FOO
21
+ # source_slug: bar
22
+ # target_slug: baz
23
+ # target_branch: master
24
+
15
25
  # You can always specify reviewers in interactive mode, but these are here to
16
26
  # provide convenient sets of frequently-included reviewers. The names here are
17
27
  # the "names" for the desired set of stash users. You can get a (limit 1000)
@@ -1,3 +1,3 @@
1
1
  module StashCli
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stash_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Chun-Lum
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-26 00:00:00.000000000 Z
11
+ date: 2016-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: configatron
@@ -144,6 +144,7 @@ files:
144
144
  - lib/stash_cli/cli.rb
145
145
  - lib/stash_cli/client.rb
146
146
  - lib/stash_cli/git_utils.rb
147
+ - lib/stash_cli/project.rb
147
148
  - lib/stash_cli/pull_request.rb
148
149
  - lib/stash_cli/templates/stash_cli.yml.erb
149
150
  - lib/stash_cli/version.rb