startling 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-gemset +1 -1
- data/README.md +15 -3
- data/lib/generators/startling/configuration_generator.rb +3 -0
- data/lib/startling/commands/create_branch.rb +23 -2
- data/lib/startling/commands/create_pull_request.rb +5 -1
- data/lib/startling/configuration.rb +4 -2
- data/lib/startling/git_local.rb +10 -1
- data/lib/startling/version.rb +1 -1
- data/spec/startling/commands/create_branch_spec.rb +105 -0
- data/spec/startling/commands/create_pull_request_spec.rb +45 -0
- data/spec/startling_spec.rb +3 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17935770cd88048b4d21b0e6a1228dbc893f1e10
|
4
|
+
data.tar.gz: 2daa700a446e7b6296dcfd24153e4ffc0e385f7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3e44fe9f1b40cbc973ff5dd67eced7c15373ff87953ebe089214b7ac9928a3bf0ed0eda0f29df7b410e57916848c6e78ca3618cc51669527b3aeff134672602
|
7
|
+
data.tar.gz: a997e6be44acc04f2ec241f9c98c6222930d79244d4a004a94018b8eaa35aef79592490d88c2b131edd63c9ab1ccd385b84f6f0734a8f77b48fc949f14d80734
|
data/.ruby-gemset
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
startling
|
data/README.md
CHANGED
@@ -25,13 +25,13 @@ Startlingfile.rb or startlingfile.rb should be defined in the root of the projec
|
|
25
25
|
|
26
26
|
```ruby
|
27
27
|
Startling.configure do |config|
|
28
|
-
# WIP Limit
|
28
|
+
# WIP Limit
|
29
29
|
# config.wip_limit = 4
|
30
30
|
|
31
31
|
# Repos to check against for WIP limit
|
32
32
|
# config.repos << 'substantial/startling-dev'
|
33
33
|
|
34
|
-
# Valid story estimations
|
34
|
+
# Valid story estimations
|
35
35
|
# config.valid_estimates = [1, 2, 4, 8, 16, 32, 64, 128]
|
36
36
|
|
37
37
|
# Commands to be run before a story is stared
|
@@ -47,11 +47,17 @@ Startling.configure do |config|
|
|
47
47
|
# config.hook_commands.after_pull_request = []
|
48
48
|
|
49
49
|
# Handler used to start a provider specific story related to the pull request
|
50
|
-
config.story_handler = :pivotal_start
|
50
|
+
# config.story_handler = :pivotal_start
|
51
|
+
|
52
|
+
# Validate branch name with a Proc that returns a boolean
|
53
|
+
# config.validate_branch_name = -> (branch_name) { /feature\/.*/ =~ branch_name }
|
51
54
|
|
52
55
|
# Message for pull request commit
|
53
56
|
# config.pull_request_commit_message = "Startling"
|
54
57
|
|
58
|
+
# Message for pull request body
|
59
|
+
# config.pull_request_body = "Startling Body"
|
60
|
+
|
55
61
|
# Labels for a pull request
|
56
62
|
# config.pull_request_labels = [WIP, REVIEW, HOLD]
|
57
63
|
|
@@ -76,3 +82,9 @@ TODO: Write usage instructions here
|
|
76
82
|
|
77
83
|
1. Create `.env` from the Secure Note `startling .env` in
|
78
84
|
LastPass.
|
85
|
+
1. `gem install bundler`
|
86
|
+
1. `bundle install`
|
87
|
+
|
88
|
+
### Running tests
|
89
|
+
|
90
|
+
`rake`
|
@@ -46,6 +46,9 @@ Startling.configure do |config|
|
|
46
46
|
# Handler used to start a provider specific story related to the pull request
|
47
47
|
# config.story_handler = :pivotal_start
|
48
48
|
|
49
|
+
# Validate branch name with a Proc that returns a boolean
|
50
|
+
# config.validate_branch_name = -> (branch_name) { /feature\\/.*/ =~ branch_name }
|
51
|
+
|
49
52
|
# Message for pull request commit
|
50
53
|
# config.pull_request_commit_message = "Startling"
|
51
54
|
|
@@ -1,9 +1,13 @@
|
|
1
|
+
require 'highline/import'
|
2
|
+
require 'octokit'
|
1
3
|
require_relative "base"
|
2
4
|
|
3
5
|
module Startling
|
4
6
|
module Commands
|
5
7
|
class CreateBranch < Base
|
6
8
|
def execute
|
9
|
+
abort "Branch name, #{branch_name}, is not valid" unless valid_branch_name?
|
10
|
+
|
7
11
|
create_branch if branch_name != git.current_branch
|
8
12
|
branch_name
|
9
13
|
end
|
@@ -22,12 +26,29 @@ module Startling
|
|
22
26
|
end
|
23
27
|
|
24
28
|
def branch_name
|
25
|
-
|
26
|
-
|
29
|
+
@branch_name ||= get_branch_name
|
30
|
+
end
|
31
|
+
|
32
|
+
def valid_branch_name?
|
33
|
+
(branch_name != default_branch) && custom_validate_branch_name
|
27
34
|
end
|
28
35
|
|
29
36
|
private
|
30
37
|
|
38
|
+
def get_branch_name
|
39
|
+
if branch.empty?
|
40
|
+
git.current_branch
|
41
|
+
else
|
42
|
+
"#{branch}".gsub(/\s+/, '-')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def custom_validate_branch_name
|
47
|
+
return true if Startling.validate_branch_name.nil?
|
48
|
+
|
49
|
+
Startling.validate_branch_name.call(branch_name)
|
50
|
+
end
|
51
|
+
|
31
52
|
def branch
|
32
53
|
@branch ||=
|
33
54
|
if args.length > 1
|
@@ -15,7 +15,11 @@ module Startling
|
|
15
15
|
|
16
16
|
def open_pull_request
|
17
17
|
puts "Opening pull request..."
|
18
|
-
|
18
|
+
|
19
|
+
if git.current_branch_has_no_commits?
|
20
|
+
git.create_empty_commit(pull_request_handler.commit_message)
|
21
|
+
end
|
22
|
+
|
19
23
|
git.push_origin_head
|
20
24
|
|
21
25
|
repo.open_pull_request title: pull_request_handler.title,
|
@@ -17,8 +17,9 @@ module Startling
|
|
17
17
|
'Startlingfile.rb'
|
18
18
|
].freeze
|
19
19
|
|
20
|
-
attr_accessor :cache_dir, :root_dir, :wip_limit, :repos, :story_handler,
|
21
|
-
:
|
20
|
+
attr_accessor :cache_dir, :root_dir, :wip_limit, :repos, :story_handler,
|
21
|
+
:validate_branch_name, :pull_request_body, :pull_request_handler,
|
22
|
+
:pull_request_labels, :pull_request_commit_message, :cli_options
|
22
23
|
|
23
24
|
def initialize
|
24
25
|
@cache_dir = Dir.pwd
|
@@ -26,6 +27,7 @@ module Startling
|
|
26
27
|
@wip_limit = DEFAULT_WIP_LIMIT
|
27
28
|
@repos = []
|
28
29
|
@story_handler = nil
|
30
|
+
@validate_branch_name = nil
|
29
31
|
@pull_request_handler = nil
|
30
32
|
@pull_request_body = DEFAULT_BODY
|
31
33
|
@pull_request_commit_message = DEFAULT_COMMIT_MESSAGE
|
data/lib/startling/git_local.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'shellwords'
|
1
2
|
require_relative 'shell'
|
2
3
|
|
3
4
|
module Startling
|
@@ -23,7 +24,7 @@ module Startling
|
|
23
24
|
end
|
24
25
|
|
25
26
|
def create_empty_commit(message)
|
26
|
-
Shell.run "git commit --allow-empty -m #{message}"
|
27
|
+
Shell.run "git commit --allow-empty -m #{Shellwords.escape(message)}"
|
27
28
|
end
|
28
29
|
|
29
30
|
def create_remote_branch(branch_name, base_branch: 'origin/master')
|
@@ -48,10 +49,18 @@ module Startling
|
|
48
49
|
`git rev-parse --show-toplevel`.strip
|
49
50
|
end
|
50
51
|
|
52
|
+
def current_branch_has_no_commits?(base_branch: 'origin/master')
|
53
|
+
revision_sha(base_branch) == revision_sha('HEAD')
|
54
|
+
end
|
55
|
+
|
51
56
|
private
|
52
57
|
|
53
58
|
def remote_url
|
54
59
|
`git config --get remote.origin.url`.strip
|
55
60
|
end
|
61
|
+
|
62
|
+
def revision_sha(revision)
|
63
|
+
Shell.run "git rev-parse #{revision}"
|
64
|
+
end
|
56
65
|
end
|
57
66
|
end
|
data/lib/startling/version.rb
CHANGED
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'startling/commands/create_branch'
|
4
|
+
|
5
|
+
describe Startling::Commands::CreateBranch do
|
6
|
+
let(:git) { double('GitLocal') }
|
7
|
+
let(:attrs) { { args: [], git: git } }
|
8
|
+
let(:create_branch) { Startling::Commands::CreateBranch.new(attrs) }
|
9
|
+
|
10
|
+
describe '#execute' do
|
11
|
+
let(:branch_name) { 'my-branch' }
|
12
|
+
let(:attrs) { { args: [1, branch_name], git: git } }
|
13
|
+
|
14
|
+
before do
|
15
|
+
allow(create_branch).to receive(:valid_branch_name?) { true }
|
16
|
+
allow(git).to receive(:current_branch) { 'current-branch' }
|
17
|
+
allow(create_branch).to receive(:create_branch)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'returns an error if the branch name is invalid' do
|
21
|
+
allow(create_branch).to receive(:valid_branch_name?) { false }
|
22
|
+
|
23
|
+
expect { create_branch.execute }.to raise_exception(SystemExit)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'creates the branch if it is not the current branch' do
|
27
|
+
allow(git).to receive(:current_branch) { 'current-branch' }
|
28
|
+
|
29
|
+
expect(create_branch).to receive(:create_branch)
|
30
|
+
create_branch.execute
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'does not create the branch if it is the current branch' do
|
34
|
+
allow(git).to receive(:current_branch) { branch_name }
|
35
|
+
|
36
|
+
expect(create_branch).not_to receive(:create_branch)
|
37
|
+
create_branch.execute
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'returns the branch name' do
|
41
|
+
expect(create_branch.execute).to eq(branch_name)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#branch_name' do
|
46
|
+
subject { create_branch.branch_name }
|
47
|
+
|
48
|
+
context 'when branch command line option is set' do
|
49
|
+
let(:attrs) { { args: [1, 'test everything'] } }
|
50
|
+
|
51
|
+
it 'returns the command line option' do
|
52
|
+
expect(subject).to eq('test-everything')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'when branch command line option is not set' do
|
57
|
+
let(:default_branch) { 'master' }
|
58
|
+
|
59
|
+
before do
|
60
|
+
allow(create_branch).to receive(:default_branch) { default_branch }
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'returns the branch entered through the prompt' do
|
64
|
+
allow($terminal).to receive(:ask) { 'entered branch' }
|
65
|
+
|
66
|
+
expect(subject).to eq('entered-branch')
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'returns the current branch when no branch is entered through the prompt' do
|
70
|
+
allow($terminal).to receive(:ask) { '' }
|
71
|
+
allow(git).to receive(:current_branch) { 'current-branch' }
|
72
|
+
|
73
|
+
expect(subject).to eq('current-branch')
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe '#valid_branch_name?' do
|
79
|
+
let(:branch_name) { 'validate-me' }
|
80
|
+
let(:attrs) { { args: [1, branch_name] } }
|
81
|
+
|
82
|
+
subject { create_branch.valid_branch_name? }
|
83
|
+
|
84
|
+
before do
|
85
|
+
allow(create_branch).to receive(:default_branch) { 'master' }
|
86
|
+
allow(Startling).to receive(:validate_branch_name) { nil }
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'succeeds if branch passes validation' do
|
90
|
+
expect(subject).to be_truthy
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'fails if the branch is the default branch' do
|
94
|
+
allow(create_branch).to receive(:default_branch) { branch_name }
|
95
|
+
|
96
|
+
expect(subject).to be_falsey
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'fails if the custom validation Proc fails' do
|
100
|
+
allow(Startling).to receive(:validate_branch_name) { -> (branch_name) { /feature\/.*/ =~ branch_name } }
|
101
|
+
|
102
|
+
expect(subject).to be_falsey
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'startling/commands/create_pull_request'
|
4
|
+
|
5
|
+
describe Startling::Commands::CreatePullRequest do
|
6
|
+
let(:git) { double('GitLocal') }
|
7
|
+
let(:attrs) { { git: git } }
|
8
|
+
let(:create_pull_request) { Startling::Commands::CreatePullRequest.new(attrs) }
|
9
|
+
|
10
|
+
describe '#open_pull_request' do
|
11
|
+
let(:commit_message) { 'test' }
|
12
|
+
let(:pull_request_handler) do
|
13
|
+
double(:pull_request_handler,
|
14
|
+
commit_message: commit_message,
|
15
|
+
title: 'title',
|
16
|
+
body: 'body'
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:repo) { double(:repo, open_pull_request: true) }
|
21
|
+
|
22
|
+
before do
|
23
|
+
allow(create_pull_request).to receive(:pull_request_handler) { pull_request_handler }
|
24
|
+
allow(create_pull_request).to receive(:repo) { repo }
|
25
|
+
|
26
|
+
allow(git).to receive(:current_branch_has_no_commits?) { false }
|
27
|
+
allow(git).to receive(:create_empty_commit)
|
28
|
+
allow(git).to receive(:push_origin_head)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should create an empty commit when the branch has no commits' do
|
32
|
+
allow(git).to receive(:current_branch_has_no_commits?) { true }
|
33
|
+
|
34
|
+
expect(git).to receive(:create_empty_commit).with(commit_message)
|
35
|
+
create_pull_request.open_pull_request
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should not create an empty commit when the branch has commits' do
|
39
|
+
allow(git).to receive(:current_branch_has_no_commits?) { false }
|
40
|
+
|
41
|
+
expect(git).not_to receive(:create_empty_commit)
|
42
|
+
create_pull_request.open_pull_request
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/spec/startling_spec.rb
CHANGED
@@ -39,6 +39,9 @@ Startling.configure do |config|
|
|
39
39
|
# Handler used to start a provider specific story related to the pull request
|
40
40
|
# config.story_handler = :pivotal_start
|
41
41
|
|
42
|
+
# Validate branch name with a Proc that returns a boolean
|
43
|
+
# config.validate_branch_name = -> (branch_name) { /feature\\/.*/ =~ branch_name }
|
44
|
+
|
42
45
|
# Message for pull request commit
|
43
46
|
# config.pull_request_commit_message = "Startling"
|
44
47
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: startling
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Jensen
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-
|
13
|
+
date: 2016-02-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -247,6 +247,8 @@ files:
|
|
247
247
|
- lib/startling/version.rb
|
248
248
|
- spec/spec_helper.rb
|
249
249
|
- spec/startling/commands/base_spec.rb
|
250
|
+
- spec/startling/commands/create_branch_spec.rb
|
251
|
+
- spec/startling/commands/create_pull_request_spec.rb
|
250
252
|
- spec/startling/configuration_spec.rb
|
251
253
|
- spec/startling/git_local_spec.rb
|
252
254
|
- spec/startling/github/pull_request_spec.rb
|
@@ -278,13 +280,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
278
280
|
version: '0'
|
279
281
|
requirements: []
|
280
282
|
rubyforge_project:
|
281
|
-
rubygems_version: 2.
|
283
|
+
rubygems_version: 2.5.1
|
282
284
|
signing_key:
|
283
285
|
specification_version: 4
|
284
286
|
summary: script for startling a story
|
285
287
|
test_files:
|
286
288
|
- spec/spec_helper.rb
|
287
289
|
- spec/startling/commands/base_spec.rb
|
290
|
+
- spec/startling/commands/create_branch_spec.rb
|
291
|
+
- spec/startling/commands/create_pull_request_spec.rb
|
288
292
|
- spec/startling/configuration_spec.rb
|
289
293
|
- spec/startling/git_local_spec.rb
|
290
294
|
- spec/startling/github/pull_request_spec.rb
|