git-story-workflow 1.3.0 → 1.5.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
  SHA256:
3
- metadata.gz: 63e47013d8d5c62bf7f3b02c334ab8a6cfb6e200d54506042a8552005fabcd03
4
- data.tar.gz: 23b3d417eb765ec8d842a06c927c14c3bc79c9e45a488bb1be395ed35ff856e3
3
+ metadata.gz: a3ca228230e6df3b78a7666b097cdfb126a3c304f58e437ea5f65cac3341eb1b
4
+ data.tar.gz: 24ec3369789ef343dfd3040ba834ca7726605eab327cb9a0f7d4bad7d772d5fe
5
5
  SHA512:
6
- metadata.gz: fe79a45d3ba9663fa4b7240fc13e6379b4847282669333ee89c44012226fce6179064152b5c6b345ed57a89fc85e6d1c3fc55e6e561e5a81ef8543be1203bb47
7
- data.tar.gz: f710599f822a1711c4fc5f7c7731db03b9fbed0e298e3f15fdf4304654c4f5ac20bbf955f51a5c2984eae49db6150f960a3fb43b479272253e5c36141b368ad3
6
+ metadata.gz: 5081071d98fd353fd9a9a6b6c14339b398d367eafb55509deaf9569871c58892c7d942ecef6eb7a8b989c58909e8dbf9c7c91c09a83bbe137845b52bfd135438
7
+ data.tar.gz: b3358fddfce2f7233972397e9bc72091f99d5adb08f6a07bd519cca613103995d06a0fe9099939b9a584c60063c6a9659d0eb94a09701e8d7e3714358983ce99
data/Rakefile CHANGED
@@ -27,6 +27,7 @@ GemHadar do
27
27
  development_dependency 'rake'
28
28
  development_dependency 'simplecov'
29
29
  development_dependency 'rspec'
30
+ development_dependency 'byebug'
30
31
  licenses << 'Apache-2.0'
31
32
  end
32
33
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.0
1
+ 1.5.0
data/config/story.yml CHANGED
@@ -1,4 +1,8 @@
1
1
  ---
2
- pivotal_token: <%= ENV['PIVOTAL_TOKEN'] %>
2
+ pivotal_token: <%= ENV['PIVOTAL_TOKEN'] %>
3
3
  pivotal_project: 123456789
4
+ pivotal_reference_prefix: pivotal
4
5
  deploy_tag_prefix: production_deploy_
6
+ semaphore_auth_token: <%= ENV['SEMAPHORE_AUTH_TOKEN'] %>
7
+ semaphore_project_url: https://betterplace.semaphoreci.com/projects/betterplace
8
+ todo_nudging: <%= ENV['TODO_NUDGING'].to_i == 1 %>
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: git-story-workflow 1.3.0 ruby lib
2
+ # stub: git-story-workflow 1.5.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "git-story-workflow".freeze
6
- s.version = "1.3.0"
6
+ s.version = "1.5.0"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
10
10
  s.authors = ["Florian Frank".freeze]
11
- s.date = "2021-05-21"
11
+ s.date = "2021-10-21"
12
12
  s.description = "Gem abstracting a git workflow\u2026".freeze
13
13
  s.email = "flori@ping.de".freeze
14
14
  s.executables = ["git-story".freeze]
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
30
30
  s.add_development_dependency(%q<rake>.freeze, [">= 0"])
31
31
  s.add_development_dependency(%q<simplecov>.freeze, [">= 0"])
32
32
  s.add_development_dependency(%q<rspec>.freeze, [">= 0"])
33
+ s.add_development_dependency(%q<byebug>.freeze, [">= 0"])
33
34
  s.add_runtime_dependency(%q<infobar>.freeze, [">= 0"])
34
35
  s.add_runtime_dependency(%q<tins>.freeze, [">= 0"])
35
36
  s.add_runtime_dependency(%q<mize>.freeze, [">= 0"])
@@ -41,6 +42,7 @@ Gem::Specification.new do |s|
41
42
  s.add_dependency(%q<rake>.freeze, [">= 0"])
42
43
  s.add_dependency(%q<simplecov>.freeze, [">= 0"])
43
44
  s.add_dependency(%q<rspec>.freeze, [">= 0"])
45
+ s.add_dependency(%q<byebug>.freeze, [">= 0"])
44
46
  s.add_dependency(%q<infobar>.freeze, [">= 0"])
45
47
  s.add_dependency(%q<tins>.freeze, [">= 0"])
46
48
  s.add_dependency(%q<mize>.freeze, [">= 0"])
data/lib/git/story/app.rb CHANGED
@@ -39,7 +39,13 @@ class Git::Story::App
39
39
  @opts = go 'n:', @argv
40
40
  @debug = debug
41
41
  determine_command
42
- Git::Story::Setup.perform
42
+ if !cc.story? && @command != :setup
43
+ warn "git story configuration file " +
44
+ "config/story.yml".bold + " is missing.\n\nCall " +
45
+ "git story setup".bold + " to create an initial one, inspect and " +
46
+ "edit it yourself, and also set the appropriate env vars.\n\n"
47
+ @command, @argv = :help, []
48
+ end
43
49
  end
44
50
 
45
51
  def run
@@ -72,6 +78,15 @@ class Git::Story::App
72
78
  )
73
79
  end
74
80
 
81
+ command doc: 'initialize git story config file if missing'
82
+ def setup
83
+ if cc.config?
84
+ red("config/story.yml configration already exists!")
85
+ else
86
+ Git::Story::Setup.perform
87
+ end
88
+ end
89
+
75
90
  command doc: 'output the current story branch if it is checked out'
76
91
  def current(check: true)
77
92
  if check
@@ -466,7 +481,12 @@ class Git::Story::App
466
481
  def pivotal_get(path)
467
482
  path = path.sub(/\A\/*/, '')
468
483
  url = "https://www.pivotaltracker.com/services/v5/#{path}"
469
- @debug and STDERR.puts "Fetching #{url.inspect}"
484
+ if pivotal_token
485
+ @debug and STDERR.puts "Fetching #{url.inspect}"
486
+ else
487
+ STDERR.puts "Cannot fetch #{url.inspect} without PIVOTAL_TOKEN set as env var"
488
+ return
489
+ end
470
490
  URI.open(url,
471
491
  'X-TrackerToken' => pivotal_token,
472
492
  'Content-Type' => 'application/xml',
@@ -2,11 +2,14 @@
2
2
  # Installed by the git-story gem
3
3
 
4
4
  require 'tempfile'
5
+ require 'complex_config/rude'
6
+ include ComplexConfig::Provider::Shortcuts
5
7
 
6
8
  class CommitMesssageParser
7
9
  def initialize
8
10
  @line_index = 0
9
11
  @story_number_found = false
12
+ @story_number_done = false
10
13
  @message_data = []
11
14
  end
12
15
 
@@ -16,10 +19,20 @@ class CommitMesssageParser
16
19
  @story_number_found
17
20
  end
18
21
 
22
+ def story_number_done?
23
+ @story_number_done
24
+ end
25
+
19
26
  def parse(template)
20
27
  @message_data = template.readlines
21
28
  @message_data.each do |line|
22
- line =~ /\[.*#\d+.*\]/ and @story_number_found = true
29
+ if /^\s*\[.*(?:#\d+|TODO|(?<done>DONE)).*\]/i =~ line
30
+ @story_number_found = true
31
+ if @story_number_done = !!done
32
+ @message_data.slice!(@line_index)
33
+ next
34
+ end
35
+ end
23
36
  if line =~ /^\s*#/
24
37
  break
25
38
  else
@@ -49,21 +62,31 @@ story_numbers =
49
62
  break $1.split(/_/)
50
63
  } || []
51
64
  story_numbers.map!(&:chomp)
52
- unless story_numbers.empty?
53
- Tempfile.open('commit') do |output|
54
- File.open(ARGV.first) do |template|
55
- message_parsed = CommitMesssageParser.new.parse(template)
56
- if message_parsed.story_number_found?
57
- output.puts message_parsed.total
58
- else
59
- output.puts message_parsed.data, "",
60
- "[#{story_numbers.map { |story_number| "##{story_number}" } * ' '}]",
61
- "", message_parsed.footer
62
- end
63
- output.rewind
64
- File.open(ARGV.first, 'w') do |message|
65
- message.write output.read
65
+ Tempfile.open('commit') do |output|
66
+ File.open(ARGV.first) do |template|
67
+ message_parsed = CommitMesssageParser.new.parse(template)
68
+ if message_parsed.story_number_found?
69
+ output.puts message_parsed.total
70
+ elsif complex_config.story.todo_nudging? && story_numbers.empty? && !message_parsed.story_number_done?
71
+ output.puts message_parsed.data, "", "[TODO]", "", message_parsed.footer
72
+ else
73
+ full_message = [ message_parsed.data, "", ]
74
+ if prefix = complex_config.story.pivotal_reference_prefix?
75
+ pivotal_reference = -> number { "%s-%u" % [ prefix, number ] }
76
+ full_message.concat(
77
+ story_numbers.each_with_index.map { |story_number, i| "#{i + 1}. " + pivotal_reference.(story_number) }
78
+ )
79
+ full_message << ""
66
80
  end
81
+ full_message <<
82
+ "[#{story_numbers.map { |story_number| "##{story_number}" } * ' '}]" <<
83
+ "" <<
84
+ message_parsed.footer
85
+ output.puts full_message
86
+ end
87
+ output.rewind
88
+ File.open(ARGV.first, 'w') do |message|
89
+ message.write output.read
67
90
  end
68
91
  end
69
92
  end
@@ -8,15 +8,35 @@ module Git::Story::Setup
8
8
  PREPARE_COMMIT_MESSAGE_SRC = File.join(__dir__, 'prepare-commit-msg')
9
9
  PREPARE_COMMIT_MESSAGE_DST = File.join(HOOKS_DIR, 'prepare-commit-msg')
10
10
 
11
+ CONFIG_TEMPLATE = <<~end
12
+ ---
13
+ pivotal_token: <%= ENV['PIVOTAL_TOKEN'] %>
14
+ pivotal_project: 123456789
15
+ pivotal_reference_prefix: pivotal
16
+ deploy_tag_prefix: production_deploy_
17
+ semaphore_auth_token: <%= ENV['SEMAPHORE_AUTH_TOKEN'] %>
18
+ semaphore_project_url: https://betterplace.semaphoreci.com/projects/betterplace
19
+ todo_nudging: <%= ENV['TODO_NUDGING'].to_i == 1 %>
20
+ end
21
+
22
+
11
23
  module_function
12
24
 
13
25
  def perform(force: false)
26
+ unless File.directory?('.git')
27
+ puts "No directory .git found, you need an initialized git repo for this to work"
28
+ return
29
+ end
30
+ install_config('config/story.yml', force: force)
31
+ install_hooks(force: force)
32
+ "Setup was performed."
33
+ end
34
+
35
+ def install_hooks(force: false)
14
36
  for filename in %w[ prepare-commit-msg pre-push ]
15
37
  if path = file_installed?(filename)
16
- if force
38
+ if force || File.read(path).match?(MARKER)
17
39
  install_file filename
18
- elsif File.read(path).match?(MARKER)
19
- ;
20
40
  else
21
41
  ask(
22
42
  prompt: "File #{path.inspect} not created by git-story."\
@@ -43,6 +63,28 @@ module Git::Story::Setup
43
63
 
44
64
  def install_file(filename)
45
65
  File.exist?(HOOKS_DIR) or mkdir_p(HOOKS_DIR)
46
- cp File.join(__dir__, filename), File.join(HOOKS_DIR, filename)
66
+ cp File.join(__dir__, filename), dest = File.join(HOOKS_DIR, filename)
67
+ puts "#{filename.to_s.inspect} was installed to #{dest.to_s.inspect}."
68
+ end
69
+
70
+ def install_config(filename, force: false)
71
+ filename = File.expand_path(filename)
72
+ if !force && File.exist?(filename)
73
+ ask(
74
+ prompt: "File #{filename.to_s.inspect} exists."\
75
+ " Overwrite? (y/n, default is %s) ",
76
+ default: ?n,
77
+ ) do |response|
78
+ if response != ?y
79
+ puts "Skipping creation of #{filename.to_s.inspect}."
80
+ return
81
+ end
82
+ end
83
+ end
84
+ mkdir_p File.dirname(filename)
85
+ File.secure_write(filename) do |io|
86
+ io.puts CONFIG_TEMPLATE
87
+ end
88
+ puts "#{filename.to_s.inspect} was created."
47
89
  end
48
90
  end
@@ -1,6 +1,6 @@
1
1
  module Git::Story
2
2
  # Git::Story version
3
- VERSION = '1.3.0'
3
+ VERSION = '1.5.0'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-story-workflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-21 00:00:00.000000000 Z
11
+ date: 2021-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_hadar
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: infobar
71
85
  requirement: !ruby/object:Gem::Requirement