This repository has been archived by the owner on Jul 4, 2018. It is now read-only.
forked from flaviogranero/assisted_workflow
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add --force flag to submit command in order to create a PR from a bra…
…nch without task
- Loading branch information
Showing
5 changed files
with
106 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,18 +2,18 @@ | |
require "assisted_workflow/addons/base" | ||
|
||
module AssistedWorkflow::Addons | ||
|
||
class GitError < AssistedWorkflow::Error; end | ||
|
||
class Git < Base | ||
|
||
DESCRIPTION_LIMIT = 30 | ||
|
||
def initialize(output, options = {}) | ||
super | ||
@command_options = {:raise_error => true}.merge(options) | ||
end | ||
|
||
# creates a new git branch based on story attributes | ||
# the branch name format is: | ||
# => story_onwer_username.story_id.story_name | ||
|
@@ -23,7 +23,7 @@ def create_story_branch(story, username) | |
git "checkout -b #{branch}" | ||
# git "push --set-upstream origin #{branch}" | ||
end | ||
|
||
# run all the git steps required for a clean pull request | ||
def rebase_and_push | ||
log "preparing local branch" | ||
|
@@ -35,24 +35,24 @@ def rebase_and_push | |
git "rebase master" | ||
git "push -u -f origin #{branch}" | ||
end | ||
|
||
# returns the current story id based on branch name | ||
def current_story_id | ||
current_branch.split(".")[1] | ||
end | ||
|
||
# returns the current local branch name | ||
def current_branch | ||
git("rev-parse --abbrev-ref HEAD", :silent => true) | ||
end | ||
|
||
# returns the repository name assigned to origin following the format: | ||
# owner/project | ||
def repository | ||
url = git("config --get remote.origin.url", :error => "cannot find 'origin' remote repository url") | ||
url.gsub("[email protected]:", "").gsub("https://github.com/", "").gsub(/\.git$/, "").chomp | ||
end | ||
|
||
# check if current branch is merged into master | ||
def check_merged! | ||
check_everything_commited! | ||
|
@@ -66,7 +66,7 @@ def check_merged! | |
end | ||
merged | ||
end | ||
|
||
# removes current branch and its remote version | ||
def remove_branch | ||
log "removing local and remote feature branches" | ||
|
@@ -75,9 +75,16 @@ def remove_branch | |
git "checkout master" | ||
git "branch -D #{branch}" | ||
end | ||
|
||
|
||
def current_feature_name | ||
branch = current_branch | ||
branch = branch[branch.index(".") + 1, branch.length].gsub(/[\W_]/, " ") | ||
branch[0] = branch[0].upcase | ||
branch | ||
end | ||
|
||
private #================================================================= | ||
|
||
def git(command, options = {}) | ||
options = @command_options.merge(options) | ||
puts "git #{command}" unless options[:silent] == true | ||
|
@@ -88,24 +95,24 @@ def git(command, options = {}) | |
end | ||
result | ||
end | ||
|
||
def system(command) | ||
%x{#{command}}.chomp | ||
end | ||
|
||
def system_error? | ||
$? != 0 | ||
end | ||
|
||
def branch_name(story, username) | ||
description = story.name.to_s.downcase.gsub(/\W/, "_").slice(0, DESCRIPTION_LIMIT) | ||
[username, story.id, description].join(".").downcase | ||
end | ||
|
||
def not_commited_changes | ||
git("status --porcelain", :silent => true).split("\n") | ||
end | ||
|
||
def check_everything_commited! | ||
raise AssistedWorkflow::Error, "git: there are not commited changes" unless not_commited_changes.empty? | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,19 +7,19 @@ | |
stub(@git).system_error?{ false } | ||
stub(@git).system("git rev-parse --abbrev-ref HEAD"){ "flavio.1234.new_feature"} | ||
end | ||
|
||
it "creates a story branch" do | ||
mock(@git).system("git checkout -b flavio.1234.new_feature") | ||
@git.create_story_branch(story, "flavio") | ||
end | ||
|
||
it "raises a git error when git command does not exit with success" do | ||
mock(@git).system_error?{ true } | ||
mock(@git).system("git checkout -b flavio.1234.new_feature") | ||
proc { @git.create_story_branch(story, "flavio") }.must_raise AssistedWorkflow::Addons::GitError, "git command error" | ||
end | ||
|
||
|
||
it "rebases and push a feature branch" do | ||
mock(@git).system("git status --porcelain"){ "" } | ||
mock(@git).system("git checkout master") | ||
|
@@ -29,57 +29,62 @@ | |
mock(@git).system("git push -u -f origin flavio.1234.new_feature") | ||
@git.rebase_and_push | ||
end | ||
|
||
it "raises when rebasing if there are not commited changes" do | ||
mock(@git).system("git status --porcelain"){ "changed_file.rb" } | ||
proc { | ||
proc { | ||
@git.rebase_and_push | ||
}.must_raise AssistedWorkflow::Error, "git: there are not commited changes" | ||
end | ||
|
||
it "returns the story_id from branch name" do | ||
@git.current_story_id.must_equal "1234" | ||
end | ||
|
||
it "return the current branch name" do | ||
@git.current_branch.must_equal "flavio.1234.new_feature" | ||
end | ||
|
||
it "returns the repository name assigned to origin" do | ||
mock(@git).system("git config --get remote.origin.url"){ "[email protected]:flaviogranero/assisted_workflow.git"} | ||
@git.repository.must_equal "flaviogranero/assisted_workflow" | ||
end | ||
|
||
|
||
it "returns the feature name" do | ||
stub(@git).system("git rev-parse --abbrev-ref HEAD"){ "marcioj.some-amazing_feature.that.i-did" } | ||
@git.current_feature_name.must_equal "Some amazing feature that i did" | ||
end | ||
|
||
describe "#check_merged!" do | ||
|
||
before do | ||
mock(@git).system("git status --porcelain"){ "" } | ||
mock(@git).system("git checkout flavio.1234.new_feature") | ||
mock(@git).system("git checkout master") | ||
mock(@git).system("git pull --rebase") | ||
end | ||
|
||
it "returns true if current branch is merged into master" do | ||
mock(@git).system("git branch --merged"){ "flavio.1234.new_feature" } | ||
@git.check_merged!.must_equal true | ||
end | ||
|
||
it "returns false if current branch is not merged into master" do | ||
mock(@git).system("git branch --merged"){ "flavio.1234.other_feature" } | ||
proc { @git.check_merged! }.must_raise AssistedWorkflow::Error, "this branch is not merged into master" | ||
|
||
end | ||
end | ||
|
||
it "removes current branch and its remote version" do | ||
mock(@git).system("git push origin :flavio.1234.new_feature") | ||
mock(@git).system("git checkout master") | ||
mock(@git).system("git branch -D flavio.1234.new_feature") | ||
@git.remove_branch | ||
end | ||
|
||
private #================================================================== | ||
|
||
def story | ||
# stubs | ||
@client = TrackerApi::Client.new(token: "mypivotaltoken") | ||
|
Oops, something went wrong.