straight_line 0.1.1.0 → 0.1.2.0

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: 771987714afd7987ff53d38e65f7b02005c60f9f
4
- data.tar.gz: 73a315adf6ef9e36123f910055fe8570b2ad712c
3
+ metadata.gz: dee8f1abb4db6de0c401f3f4008943ddb3f58e5b
4
+ data.tar.gz: 6a1914f27db3929a0bd3a7c7eff9fb7e65633e4f
5
5
  SHA512:
6
- metadata.gz: 9dcbe95744cb5d7d18605d4b52b17dd168c6f0e2d929a1e82314257db14b055554749034e0a35f6e906b022b489840aea388f75d2b930742268fd6cd4a6ffb6d
7
- data.tar.gz: 9268dd80b853369d362889cbb5689ed7281dd154af6040d74e56a66ebb176e594c7e8406a1dd1af0498ea579734f979d4319f229dbf686d87bf044779305af99
6
+ metadata.gz: 83a0e5616ab2d8bf7c57a1cd8072565e4157d581d9a5891f4aa1814d4425037979a81b5ea1edbb584833415fb2073afb693b277ef54178f90db9754a9e0b39b2
7
+ data.tar.gz: 1626f216dcdcbedfd054e40e5139af55a622dd65c2d064d07e49aa4f33296fb7bac07e3b2b4a07ad10ceee858f663658ed4d205e6a2223b63aa2d5a712e8e780
data/.rubocop.yml CHANGED
@@ -4,3 +4,9 @@ AllCops:
4
4
 
5
5
  Metrics/LineLength:
6
6
  Max: 85
7
+
8
+ Metrics/MethodLength:
9
+ Max: 15
10
+
11
+ Metrics/AbcSize:
12
+ Max: 16
data/Gemfile CHANGED
@@ -4,7 +4,7 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  gem 'rubocop', require: false
7
+ gem 'simplecov'
7
8
  gem 'vcr'
8
9
  gem 'version_bumper'
9
10
  gem 'webmock'
10
- gem 'simplecov'
data/README.md CHANGED
@@ -31,6 +31,13 @@ machine api.github.com
31
31
  login <Your Github username>
32
32
  password <Github API token>
33
33
  ```
34
+
35
+ Note `~/.netrc` needs to have `600` permissions. Do this with the following command:
36
+
37
+ ```bash
38
+ chmod 600 ~/.netrc
39
+ ```
40
+
34
41
  ## Usage
35
42
 
36
43
  The basic workflow of StraightLine is:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1.0
1
+ 0.1.2.0
@@ -16,6 +16,8 @@ class Command
16
16
  self
17
17
  end
18
18
 
19
+ def self.from_file(_file_name); end
20
+
19
21
  def run(return_stderr = false)
20
22
  Dir.chdir working_dir do
21
23
  command_with_params = "#{@command} #{@args.join ' '}"
@@ -25,21 +27,28 @@ class Command
25
27
  else
26
28
  res, stderr, status = Open3.capture3(command_with_params)
27
29
  end
28
- unless status.exitstatus == 0
30
+ unless status.exitstatus.zero?
29
31
  output = return_stderr ? res : "#{res}\n#{stderr}"
30
32
  raise ShellError, %(Command `#{command_with_params}` exited with
31
33
  status code: #{status.exitstatus}. Command outputted:\n #{output})
32
34
  end
33
35
 
34
- sub_res = ''
35
- sub_res = @sub_commands.map do |sub_command|
36
- sub_command.run return_stderr
37
- end.join("\n") unless @sub_commands.empty?
36
+ sub_res = run_sub_commands return_stderr
38
37
 
39
38
  res + "\n" + sub_res
40
39
  end
41
40
  end
42
41
 
42
+ def run_sub_commands(return_stderr)
43
+ sub_res = ''
44
+ unless @sub_commands.empty?
45
+ sub_res = @sub_commands.map do |sub_command|
46
+ sub_command.run return_stderr
47
+ end.join("\n")
48
+ end
49
+ sub_res
50
+ end
51
+
43
52
  def sub_command(command)
44
53
  unless command.is_a? Command
45
54
  raise ArgumentError, 'command must be of type straight_line/common/command'
@@ -0,0 +1,29 @@
1
+ require 'rake'
2
+ require 'straight_line/common/command'
3
+
4
+ # Configuration class to add tasks to the straightline rake config
5
+ class Configure
6
+ def add(name, type, command, opts = {})
7
+ Rake.application.in_namespace StraightLine::TASK_NAMESPACE do
8
+ Rake::Task.define_task name => opts[:before] do
9
+ if type == :shell
10
+ cmd = Command.new command
11
+ cmd.run
12
+ elsif !name.nil?
13
+ Rake::Task[command].invoke
14
+ end
15
+ run_after_commands(opts)
16
+ end
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def run_after_commands(opts)
23
+ after = opts[:after]
24
+ return if after.nil?
25
+ after.each do |task|
26
+ Rake::Task[task].invoke
27
+ end
28
+ end
29
+ end
@@ -6,7 +6,7 @@ module Feature
6
6
  class Create
7
7
  def initialize(feature_name)
8
8
  raise UserError, 'Feature name required' unless feature_name
9
- raise UserError, "Feature name can't have spaces" if feature_name.match %r[\s]
9
+ raise UserError, "Feature name can't have spaces" if feature_name =~ /\s/
10
10
  @feature_name = feature_name
11
11
  end
12
12
 
@@ -42,9 +42,7 @@ module Feature
42
42
  begin
43
43
  GitCommands::Commit.new(title, body).run
44
44
  rescue StandardError => e
45
- unless e.message.match %r[nothing to commit]
46
- raise e
47
- end
45
+ raise e unless e.message =~ /nothing to commit/
48
46
  end
49
47
  GitCommands::Push.new(feature_name).run
50
48
  end
@@ -68,10 +66,10 @@ module Feature
68
66
  def extract_params(params, keys)
69
67
  keys.map do |key|
70
68
  case key
71
- when :title
72
- params[:title] || last_commit_message
73
- else
74
- params[key]
69
+ when :title
70
+ params[:title] || last_commit_message
71
+ else
72
+ params[key]
75
73
  end
76
74
  end
77
75
  end
@@ -22,28 +22,33 @@ module Feature
22
22
 
23
23
  def land(_args = {})
24
24
  feature_name = current_feature
25
- pull_cmd = GitCommands::Pull.new('master')
26
- pull_cmd.run
27
- GitCommands::Merge.new(feature_name, 'master').run
28
-
29
- begin
30
- GitCommands::Commit.new("Merge master into #{feature_name}", '').run
31
- rescue StandardError => e
32
- unless e.message.match %r[nothing to commit]
33
- raise e
34
- end
35
- end
25
+ merge_master_to_feature(feature_name)
36
26
  GitCommands::Push.new(feature_name).run
27
+ merge_feature_to_master(feature_name)
28
+ GitCommands::Push.new(feature_name, delete: true).run
29
+ Command.new('git checkout master').run
30
+ Util.logger.info 'Changes landed to master, on master branch now.'
31
+ end
32
+
33
+ def merge_feature_to_master(feature_name)
37
34
  if pull_request_closed?(feature_name)
38
- Util.logger.info %{#{feature_name} was merged in github.
39
- You're repo is up-to-date with remote}
35
+ Util.logger.info %(#{feature_name} was merged in github.
36
+ You're repo is up-to-date with remote)
40
37
  else
41
38
  GitCommands::Merge.new('master', feature_name).run
42
39
  GitCommands::Push.new('master').run
43
40
  end
44
- GitCommands::Push.new(feature_name, delete: true).run
45
- Command.new('git checkout master').run
46
- Util.logger.info 'Changes landed to master, on master branch now.'
41
+ end
42
+
43
+ def merge_master_to_feature(feature_name)
44
+ GitCommands::Pull.new('master').run
45
+ GitCommands::Merge.new(feature_name, 'master').run
46
+
47
+ begin
48
+ GitCommands::Commit.new("Merge master into #{feature_name}", '').run
49
+ rescue StandardError => e
50
+ raise e unless e.message =~ /nothing to commit/
51
+ end
47
52
  end
48
53
 
49
54
  def pull_request_closed?(feature_name)
@@ -3,12 +3,12 @@ require 'straight_line/common/command'
3
3
  module Feature
4
4
  def current_feature
5
5
  res = Command.new('git')
6
- .arg('branch')
7
- .run
8
- .match(/^\*\s+(.*)/)[1].strip
9
- if res.match(/no branch/)
10
- raise UserError, %q(A rebase is in process.
11
- Finish the rebase, then run the command again)
6
+ .arg('branch')
7
+ .run
8
+ .match(/^\*\s+(.*)/)[1].strip
9
+ if res =~ /no branch/
10
+ raise UserError, 'A rebase is in process.
11
+ Finish the rebase, then run the command again'
12
12
  else
13
13
  res
14
14
  end
@@ -16,7 +16,7 @@ module GitCommands
16
16
  sub_command merge_command
17
17
  end
18
18
 
19
- def run(*args)
19
+ def run(*_args)
20
20
  super true
21
21
 
22
22
  rescue ShellError => e
@@ -21,9 +21,9 @@ module GitCommands
21
21
 
22
22
  if opts[:delete]
23
23
  push_command
24
- .arg('origin')
25
- .arg('--delete')
26
- .arg(branch)
24
+ .arg('origin')
25
+ .arg('--delete')
26
+ .arg(branch)
27
27
  elsif !remote_exists
28
28
  push_command
29
29
  .arg('--set-upstream')
@@ -13,7 +13,7 @@ module GitCommands
13
13
  arg branch
14
14
  end
15
15
 
16
- def run(*args)
16
+ def run(*_args)
17
17
  super true
18
18
  rescue ShellError => e
19
19
  handle_merge_conflict(e)
@@ -1,9 +1,12 @@
1
1
  require 'straight_line/common/util'
2
+
3
+ # Util class for common git related actions
2
4
  module GitCommands
3
5
  def handle_merge_conflict(e)
4
- if e.message.match %r[Merge conflict in]
5
- Util.logger.error %q(***** Hint: this looks like a merge conflict.
6
- Try fixing the conflicts, then run `git add .` and then run the previous command again.)
6
+ if e.message =~ /Merge conflict in/
7
+ Util.logger.error '***** Hint: this looks like a merge conflict.
8
+ Try fixing the conflicts, then run `git add .` and then run the
9
+ previous command again.'
7
10
  end
8
11
  raise e
9
12
  end
@@ -68,8 +68,8 @@ class Github
68
68
  prs = pull_requests
69
69
  prs.find do |p|
70
70
  p.head.ref == feature &&
71
- p.head.user.login == Github.github_login &&
72
- p.base.ref == 'master'
71
+ p.head.user.login == Github.github_login &&
72
+ p.base.ref == 'master'
73
73
  end
74
74
  end
75
75
  make_class :pull_request_for_feature
@@ -1,4 +1,3 @@
1
1
 
2
2
  class ShellError < StandardError
3
-
4
- end
3
+ end
@@ -1,7 +1,8 @@
1
1
  require 'logger'
2
2
 
3
+ # Class for global utility methods
3
4
  class Util
4
5
  def self.logger
5
6
  @logger ||= Logger.new STDOUT
6
7
  end
7
- end
8
+ end
data/lib/straight_line.rb CHANGED
@@ -1,8 +1,14 @@
1
+ require 'straight_line/common/configure'
2
+ require 'rake'
1
3
 
2
4
  # Base module definition
3
5
  module StraightLine
4
- # Your code goes here...
5
- def self.foo
6
- puts 'la'
6
+ TASK_NAMESPACE = 'sl'.freeze
7
+ def self.configure
8
+ yield Configure.new
9
+ end
10
+
11
+ def self.task_namespace
12
+ Rake::DSL
7
13
  end
8
14
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: straight_line
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1.0
4
+ version: 0.1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Usick
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-10 00:00:00.000000000 Z
11
+ date: 2017-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,6 +122,7 @@ files:
122
122
  - lib/straight_line/cli/application.rb
123
123
  - lib/straight_line/cli/feature.rb
124
124
  - lib/straight_line/common/command.rb
125
+ - lib/straight_line/common/configure.rb
125
126
  - lib/straight_line/common/feature.rb
126
127
  - lib/straight_line/common/feature/create.rb
127
128
  - lib/straight_line/common/feature/diff.rb