Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2016-04-18 08:55:15 -0700 using RuboCop version 0.33.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

LineLength:
Max: 200

Expand All @@ -7,6 +15,30 @@ Documentation:
StringLiterals:
EnforcedStyle: single_quotes

# Offense count: 7
Metrics/AbcSize:
Max: 25

# Offense count: 2
Metrics/CyclomaticComplexity:
Max: 7

# Offense count: 5
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 19

# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 123

# Offense count: 3
Style/RescueModifier:
Exclude:
- 'lib/gitx/cli/integrate_command.rb'
- 'lib/gitx/cli/nuke_command.rb'

FileName:
Exclude:
- bin/*
4 changes: 4 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new('spec')
task default: :spec

require 'rubocop/rake_task'
RuboCop::RakeTask.new
task default: :rubocop
4 changes: 2 additions & 2 deletions lib/gitx/cli/base_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ def current_branch
end

def assert_aggregate_branch!(target_branch)
fail "Invalid aggregate branch: #{target_branch} must be one of supported aggregate branches #{config.aggregate_branches}" unless config.aggregate_branch?(target_branch)
raise "Invalid aggregate branch: #{target_branch} must be one of supported aggregate branches #{config.aggregate_branches}" unless config.aggregate_branch?(target_branch)
end

def assert_not_protected_branch!(branch, action)
fail "Cannot #{action} reserved branch" if config.reserved_branch?(branch) || config.aggregate_branch?(branch)
raise "Cannot #{action} reserved branch" if config.reserved_branch?(branch) || config.aggregate_branch?(branch)
end

def config
Expand Down
2 changes: 1 addition & 1 deletion lib/gitx/cli/buildtag_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class BuildtagCommand < BaseCommand
method_option :branch, type: :string, aliases: '-b', desc: 'branch name for build tag'
method_option :message, type: :string, aliases: '-m', desc: 'message to attach to the buildtag'
def buildtag
fail "Branch must be one of the supported taggable branches: #{config.taggable_branches}" unless config.taggable_branch?(branch_name)
raise "Branch must be one of the supported taggable branches: #{config.taggable_branches}" unless config.taggable_branch?(branch_name)
run_git_cmd 'tag', git_tag, '--annotate', '--message', label
run_git_cmd 'push', 'origin', git_tag
end
Expand Down
47 changes: 28 additions & 19 deletions lib/gitx/cli/cleanup_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,47 @@ module Cli
class CleanupCommand < BaseCommand
desc 'cleanup', 'Cleanup branches that have been merged into master from the repo'
def cleanup
checkout_branch config.base_branch
run_git_cmd 'pull'
run_git_cmd 'remote', 'prune', 'origin'

update_base_branch
say 'Deleting local and remote branches that have been merged into '
say config.base_branch, :green
merged_branches(remote: true).each do |branch|
filtered_merged_branches(:remote).each do |branch|
run_git_cmd 'push', 'origin', '--delete', branch
end
merged_branches(remote: false).each do |branch|
filtered_merged_branches(:local).each do |branch|
run_git_cmd 'branch', '--delete', branch
end
end

private

def update_base_branch
checkout_branch config.base_branch
run_git_cmd 'pull'
run_git_cmd 'remote', 'prune', 'origin'
end

# @return list of branches that have been merged
def merged_branches(options = {})
args = []
args << '--remote' if options[:remote]
args << '--merged'
output = run_git_cmd('branch', *args).split("\n")
branches = output.map do |branch|
branch = branch.gsub(/\*/, '').strip.split(' ').first
branch = branch.gsub('origin/', '') if options[:remote]
branch
# filter out reserved and aggregate branches
def filtered_merged_branches(source)
merged_branches(source).reject do |branch|
config.reserved_branches.include?(branch) || config.aggregate_branch?(branch)
end
branches.uniq!
branches -= config.reserved_branches
branches.reject! { |b| config.aggregate_branch?(b) }
end

# @return list of branches that have been merged
# see http://stackoverflow.com/questions/26804024/git-branch-merged-sha-via-rugged-libgit2-bindings
def merged_branches(source)
merged_branches = repo.branches.each(source).select do |branch|
target = branch.resolve.target
repo.merge_base(base_branch_merge_target, target) == target.oid
end
merged_branches.map do |branch|
branch.name.gsub('origin/', '')
end
end

branches
def base_branch_merge_target
repo.head.target
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/gitx/cli/nuke_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class NukeCommand < BaseCommand
method_option :destination, type: :string, aliases: '-d', desc: 'destination branch to reset to'
def nuke(bad_branch)
good_branch = options[:destination] || ask("What branch do you want to reset #{bad_branch} to? (default: #{bad_branch})")
good_branch = bad_branch if good_branch.length == 0
good_branch = bad_branch if good_branch.empty?

last_known_good_tag = current_build_tag(good_branch)
return unless yes?("Reset #{bad_branch} to #{last_known_good_tag}? (y/n)", :green)
Expand Down Expand Up @@ -47,7 +47,7 @@ def migrations_need_to_be_reverted?(bad_branch, last_known_good_tag)

def current_build_tag(branch)
last_build_tag = build_tags_for_branch(branch).last
fail "No known good tag found for branch: #{branch}. Verify tag exists via `git tag -l 'build-#{branch}-*'`" unless last_build_tag
raise "No known good tag found for branch: #{branch}. Verify tag exists via `git tag -l 'build-#{branch}-*'`" unless last_build_tag
last_build_tag
end

Expand Down
8 changes: 4 additions & 4 deletions lib/gitx/cli/review_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ module Cli
class ReviewCommand < BaseCommand
include Gitx::Github

BUMP_COMMENT_PREFIX = '[gitx] review bump :tada:'
BUMP_COMMENT_PREFIX = '[gitx] review bump :tada:'.freeze
BUMP_COMMENT_FOOTER = <<-EOS.dedent
# Bump comments should include:
# * Summary of what changed
#
# This footer will automatically be stripped from the created comment
EOS
APPROVAL_COMMENT_PREFIX = '[gitx] review approved :shipit:'
APPROVAL_COMMENT_PREFIX = '[gitx] review approved :shipit:'.freeze
APPROVAL_COMMENT_FOOTER = <<-EOS.dedent
# Approval comments can include:
# * Feedback
# * Follow-up items for after release
#
# This footer will automatically be stripped from the created comment
EOS
REJECTION_COMMENT_PREFIX = '[gitx] review rejected'
REJECTION_COMMENT_PREFIX = '[gitx] review rejected'.freeze
REJECTION_COMMENT_FOOTER = <<-EOS.dedent
# Rejection comments should include:
# * Feedback
Expand All @@ -42,7 +42,7 @@ class ReviewCommand < BaseCommand
method_option :reject, type: :boolean, desc: 'reject the pull request an post comment on pull request'
# @see http://developer.github.com/v3/pulls/
def review(branch = nil)
fail 'Github authorization token not found' unless authorization_token
raise 'Github authorization token not found' unless authorization_token

branch ||= current_branch.name
pull_request = find_or_create_pull_request(branch)
Expand Down
2 changes: 1 addition & 1 deletion lib/gitx/cli/start_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module Gitx
module Cli
class StartCommand < BaseCommand
EXAMPLE_BRANCH_NAMES = %w( api-fix-invalid-auth desktop-cleanup-avatar-markup share-form-add-edit-link )
EXAMPLE_BRANCH_NAMES = %w( api-fix-invalid-auth desktop-cleanup-avatar-markup share-form-add-edit-link ).freeze
VALID_BRANCH_NAME_REGEX = /^[A-Za-z0-9\-_]+$/

desc 'start', 'start a new git branch with latest changes from master'
Expand Down
2 changes: 1 addition & 1 deletion lib/gitx/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

module Gitx
class Configuration
CONFIG_FILE = '.gitx.yml'
CONFIG_FILE = '.gitx.yml'.freeze

attr_reader :config

Expand Down
8 changes: 5 additions & 3 deletions lib/gitx/executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ def execute(*cmd)
yield "$ #{cmd.join(' ')}" if block_given?
output = ''

Open3.popen2e(*cmd) do |stdin, stdout_err, wait_thread|
while line = stdout_err.gets
Open3.popen2e(*cmd) do |_stdin, stdout_err, wait_thread|
loop do
line = stdout_err.gets
break unless line
output << line
yield line if block_given?
end

exit_status = wait_thread.value
fail ExecutionError, "#{cmd.join(' ')} failed" unless exit_status.success?
raise ExecutionError, "#{cmd.join(' ')} failed" unless exit_status.success?
end
output
end
Expand Down
2 changes: 1 addition & 1 deletion lib/gitx/extensions/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def undent
indent = scan(/^[ \t]*(?=\S)/).min.size || 0
gsub(/^[ \t]{#{indent}}/, '')
end
alias_method :dedent, :undent
alias dedent undent

def blank?
to_s == ''
Expand Down
14 changes: 7 additions & 7 deletions lib/gitx/extensions/thor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ def ask_editor(initial_text = '', editor: nil, footer: nil)
f.flush

flags = case editor
when 'mate', 'emacs', 'subl'
'-w'
when 'mvim'
'-f'
else
''
end
when 'mate', 'emacs', 'subl'
'-w'
when 'mvim'
'-f'
else
''
end
pid = fork { exec([editor, flags, f.path].join(' ')) }
Process.waitpid(pid)
File.read(f.path)
Expand Down
16 changes: 8 additions & 8 deletions lib/gitx/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

module Gitx
module Github
GLOBAL_CONFIG_FILE = '~/.config/gitx/github.yml'
REVIEW_CONTEXT = 'peer_review'
CLIENT_URL = 'https://github.com/wireframe/gitx'
GLOBAL_CONFIG_FILE = '~/.config/gitx/github.yml'.freeze
REVIEW_CONTEXT = 'peer_review'.freeze
CLIENT_URL = 'https://github.com/wireframe/gitx'.freeze
PULL_REQUEST_FOOTER = <<-EOS.dedent
# Pull Request Protips(tm):
# * Describe how this change accomplishes the task at hand
Expand Down Expand Up @@ -72,14 +72,14 @@ def create_pull_request(branch)
end

def pull_request_body(branch)
changelog = run_git_cmd('log', "origin/#{config.base_branch}...#{branch}", '--reverse', '--no-merges', "--pretty=format:* %B")
changelog = run_git_cmd('log', "origin/#{config.base_branch}...#{branch}", '--reverse', '--no-merges', '--pretty=format:* %B')
description = options[:description]

description_template = []
description_template << "#{description}\n" if description
description_template << changelog

body = ask_editor(description_template.join("\n"), editor: repo.config['core.editor'], footer: PULL_REQUEST_FOOTER)
ask_editor(description_template.join("\n"), editor: repo.config['core.editor'], footer: PULL_REQUEST_FOOTER)
end

def pull_request_title(branch)
Expand Down Expand Up @@ -120,7 +120,7 @@ def create_authorization

def github_client_name
timestamp = Time.now.utc.strftime('%FT%R:%S%z')
client_name = "Git eXtensions #{timestamp}"
"Git eXtensions #{timestamp}"
end

def github_client
Expand All @@ -131,7 +131,7 @@ def github_client
# @raise error if github.user is not configured
def username
username = repo.config['github.user']
fail "Github user not configured. Run: `git config --global github.user 'me@email.com'`" unless username
raise "Github user not configured. Run: `git config --global github.user 'me@email.com'`" unless username
username
end

Expand All @@ -142,7 +142,7 @@ def username
# https://github.com/wireframe/gitx.git #=> wireframe/gitx
def github_slug
remote = repo.config['remote.origin.url']
remote.to_s.gsub(/\.git$/, '').split(/[:\/]/).last(2).join('/')
remote.to_s.gsub(/\.git$/, '').split(%r{[:\/]}).last(2).join('/')
end

def github_organization
Expand Down
2 changes: 1 addition & 1 deletion lib/gitx/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Gitx
VERSION = '2.23.0'
VERSION = '2.23.1'.freeze
end
Loading