Skip to content

Commit

Permalink
Rubocop: fix a bunch of todos (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
mockdeep authored Jun 20, 2022
1 parent bdd2d8d commit 27a705a
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 164 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Style/ClassAndModuleChildren: { EnforcedStyle: compact }

Style/MethodCallWithArgsParentheses:
IgnoredMethods:
- abort
- describe
- not_to
- raise
Expand Down
117 changes: 0 additions & 117 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,72 +6,12 @@
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines
Layout/EmptyLinesAroundModuleBody:
Exclude:
- 'lib/baes/git.rb'

# Offense count: 3
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns.
# URISchemes: http, https
Layout/LineLength:
Exclude:
- 'baes.gemspec'
- 'lib/baes/tree_builder.rb'

# Offense count: 3
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedTypes: block, case, class, if, kwbegin, module
# SupportedStyles: same_line, new_line
Layout/MultilineAssignmentLayout:
Exclude:
- 'baes.gemspec'
- 'lib/baes/branch.rb'
- 'lib/baes/rebaser.rb'

# Offense count: 36
# Configuration parameters: Only, Ignore.
Lint/ConstantResolution:
Exclude:
- 'Rakefile'
- 'baes.gemspec'
- 'bin/console'
- 'exe/baes'
- 'lib/baes/branch.rb'
- 'lib/baes/configuration.rb'
- 'lib/baes/git.rb'
- 'lib/baes/rebaser.rb'
- 'lib/baes/tree_builder.rb'
- 'spec/baes_spec.rb'
- 'spec/spec_helper.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: IgnoredMethods, IgnoredClasses.
# IgnoredClasses: Time, DateTime
Lint/NumberConversion:
Exclude:
- 'lib/baes/tree_builder.rb'

# Offense count: 1
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes, Max.
Metrics/AbcSize:
Exclude:
- 'lib/baes/branch.rb'

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: separated, grouped
Style/AccessorGrouping:
Exclude:
- 'lib/baes/branch.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
Expand All @@ -80,15 +20,6 @@ Style/ClassAndModuleChildren:
Exclude:
- 'lib/baes.rb'

# Offense count: 3
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: PreferredMethods, MethodsAcceptingSymbol.
# MethodsAcceptingSymbol: inject, reduce
Style/CollectionMethods:
Exclude:
- 'lib/baes/rebaser.rb'
- 'lib/baes/tree_builder.rb'

# Offense count: 1
# Configuration parameters: IgnoreModules.
Style/ConstantVisibility:
Expand Down Expand Up @@ -119,59 +50,11 @@ Style/DocumentationMethod:
- 'lib/baes/rebaser.rb'
- 'lib/baes/tree_builder.rb'

# Offense count: 5
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, always_true, never
Style/FrozenStringLiteralComment:
Exclude:
- 'exe/baes'
- 'lib/baes/branch.rb'
- 'lib/baes/git.rb'
- 'lib/baes/rebaser.rb'
- 'lib/baes/tree_builder.rb'

# Offense count: 2
Style/ImplicitRuntimeError:
Exclude:
- 'lib/baes/git.rb'

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: .
# SupportedStyles: call, braces
Style/LambdaCall:
EnforcedStyle: braces

# Offense count: 18
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: IgnoreMacros, IgnoredMethods, AllowedPatterns, IgnoredPatterns, IncludedMacros, AllowParenthesesInMultilineCall, AllowParenthesesInChaining, AllowParenthesesInCamelCaseMethod, AllowParenthesesInStringInterpolation, EnforcedStyle.
# SupportedStyles: require_parentheses, omit_parentheses
Style/MethodCallWithArgsParentheses:
Exclude:
- 'lib/baes/branch.rb'
- 'lib/baes/git.rb'
- 'lib/baes/rebaser.rb'
- 'spec/baes_spec.rb'
- 'spec/spec_helper.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: literals, strict
Style/MutableConstant:
Exclude:
- 'lib/baes/tree_builder.rb'

# Offense count: 8
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: both, prefix, postfix
Style/NegatedIf:
Exclude:
- 'lib/baes/branch.rb'
- 'lib/baes/git.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: Mode.
Expand Down
15 changes: 9 additions & 6 deletions baes.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ Gem::Specification.new do |spec|

spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = "https://github.com/mockdeep/baes"
spec.metadata["changelog_uri"] = "https://github.com/mockdeep/baes/blob/main/CHANGELOG.md"
spec.metadata["changelog_uri"] =
"https://github.com/mockdeep/baes/blob/main/CHANGELOG.md"
spec.metadata["rubygems_mfa_required"] = "true"

# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
spec.files = Dir.chdir(File.expand_path(__dir__)) do
`git ls-files -z`.split("\x0").reject do |f|
(f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
# The `git ls-files -z` loads the files in the RubyGem that have been added
# into git.
spec.files =
Dir.chdir(File.expand_path(__dir__)) do
`git ls-files -z`.split("\x0").reject do |f|
(f == __FILE__) || f.match(%r{\A(?:(?:spec)/|\.(?:git|circleci))})
end
end
end
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
Expand Down
3 changes: 2 additions & 1 deletion exe/baes
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require_relative "../lib/baes"

Baes::Rebaser.new.(ARGV)
Baes::Rebaser.new.call(ARGV)
21 changes: 12 additions & 9 deletions lib/baes/branch.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

class Baes::Branch
attr_accessor :name
attr_accessor :children
attr_accessor :name, :children

include Baes::Configuration

Expand All @@ -14,28 +15,30 @@ def rebase(other_branch)

result = git.rebase(other_branch.name)

skip_through(other_branch) if !result.success?
skip_through(other_branch) unless result.success?
end

def inspect(indentation = '')
children_strings = children.map do |child|
"\n#{child.inspect(indentation + ' ')}"
end
children_strings =
children.map do |child|
"\n#{child.inspect(indentation + ' ')}"
end

"#{indentation}#{name}#{children_strings.join}"
end

private

def skip_through(other_branch)
output.puts "conflict rebasing branch #{name} on #{other_branch.name}"
output.print skip_rebase_message
output.puts("conflict rebasing branch #{name} on #{other_branch.name}")
output.print(skip_rebase_message)
answer = input.gets.chomp
output.puts

if answer == 'y'
result = git.rebase_skip

skip_through(other_branch) if !result.success?
skip_through(other_branch) unless result.success?
else
abort 'failed to rebase, please resolve manually and then re-run baes'
end
Expand Down
21 changes: 11 additions & 10 deletions lib/baes/git.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'open3'
require 'English'

Expand All @@ -7,36 +9,36 @@ module Baes::Git
def self.checkout(branch_name)
stdout, stderr, status = Open3.capture3("git checkout #{branch_name}")

output.puts stdout
output.puts stderr if !stderr.empty?
output.puts(stdout)
output.puts(stderr) unless stderr.empty?

raise "failed to rebase on '#{branch_name}'" if !status.success?
raise "failed to rebase on '#{branch_name}'" unless status.success?
end

def self.rebase(branch_name)
stdout, stderr, status = Open3.capture3("git rebase #{branch_name}")

output.puts stdout
output.puts stderr if !stderr.empty?
output.puts(stdout)
output.puts(stderr) unless stderr.empty?

status
end

def self.branch_names
stdout, stderr, status = Open3.capture3("git branch")

output.puts stderr if !stderr.empty?
output.puts(stderr) unless stderr.empty?

raise "failed to get branches" if !status.success?
raise "failed to get branches" unless status.success?

stdout.lines.map { |line| line.sub(/^\*/, '').strip }
end

def self.rebase_skip
stdout, stderr, status = Open3.capture3("git rebase --skip")

output.puts stdout
output.puts stderr if !stderr.empty?
output.puts(stdout)
output.puts(stderr) unless stderr.empty?

status
end
Expand All @@ -48,5 +50,4 @@ def self.next_rebase_step
def self.last_rebase_step
File.read('./.git/rebase-apply/last').strip
end

end
16 changes: 9 additions & 7 deletions lib/baes/rebaser.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# frozen_string_literal: true

class Baes::Rebaser
include Baes::Configuration

def call(options)
root_name =
options.detect { |option| option != '--dry' } || detect_root_name
root_branch = Baes::TreeBuilder.new.(branches, root_name: root_name)
root_name = options.find { |option| option != '--dry' } || detect_root_name
root_branch = Baes::TreeBuilder.new.call(branches, root_name: root_name)

if options.any? { |option| option == '--dry' }
output.puts root_branch.inspect
output.puts(root_branch.inspect)
else
rebase_children(root_branch)
end
Expand All @@ -16,9 +17,10 @@ def call(options)
end

def branches
@branches ||= git.branch_names.map do |branch_name|
Baes::Branch.new(branch_name)
end
@branches ||=
git.branch_names.map do |branch_name|
Baes::Branch.new(branch_name)
end
end

def detect_root_name
Expand Down
14 changes: 10 additions & 4 deletions lib/baes/tree_builder.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
SKIP_BRANCHES = ["staging", "main", "master"]
# frozen_string_literal: true

SKIP_BRANCHES = ["staging", "main", "master"].freeze

class Baes::TreeBuilder
def initialize
Expand Down Expand Up @@ -26,12 +28,16 @@ def link_branch_to_parent(branch, branches, root_name:)
def parent_name(branch, root_name:)
_, name, number = branch.name.match(/(\A[a-zA-Z_-]+)(\d+)/).to_a

number ? "#{name}#{(number.to_i - 1).to_s.rjust(number.length, '0')}" : root_name
if number
"#{name}#{(Integer(number, 10) - 1).to_s.rjust(number.length, '0')}"
else
root_name
end
end

def find_branch(branches, name)
@branch_cache[name] ||=
branches.detect { |branch| branch.name == name } ||
branches.detect { |branch| branch.name.end_with?(name) }
branches.find { |branch| branch.name == name } ||
branches.find { |branch| branch.name.end_with?(name) }
end
end
Loading

0 comments on commit 27a705a

Please sign in to comment.