assisted_workflow 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- assisted_workflow (0.2.0)
4
+ assisted_workflow (0.2.1)
5
5
  hashie (~> 2.0.5)
6
6
  octokit (~> 2.0)
7
7
  pivotal-tracker (~> 0.5.12)
@@ -26,6 +26,7 @@ module AssistedWorkflow::Addons
26
26
 
27
27
  # run all the git steps required for a clean pull request
28
28
  def rebase_and_push
29
+ log "preparing local branch"
29
30
  check_everything_commited!
30
31
  branch = current_branch
31
32
  git "checkout master"
@@ -53,18 +54,22 @@ module AssistedWorkflow::Addons
53
54
  end
54
55
 
55
56
  # check if current branch is merged into master
56
- def is_merged?
57
+ def check_merged!
57
58
  check_everything_commited!
58
59
  branch = current_branch
59
60
  git "checkout master"
60
61
  git "pull --rebase"
61
62
  merged = git("branch --merged").include?(branch)
62
63
  git "checkout #{branch}"
64
+ unless merged
65
+ raise AssistedWorkflow::Error, "this branch is not merged into master"
66
+ end
63
67
  merged
64
68
  end
65
69
 
66
70
  # removes current branch and its remote version
67
71
  def remove_branch
72
+ log "removing local and remote feature branches"
68
73
  branch = current_branch
69
74
  git "push origin :#{branch}", :raise_error => false
70
75
  git "checkout master"
@@ -1,3 +1,3 @@
1
1
  module AssistedWorkflow
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -50,7 +50,7 @@ describe AssistedWorkflow::Addons::Git do
50
50
  @git.repository.must_equal "flaviogranero/assisted_workflow"
51
51
  end
52
52
 
53
- describe "#is_merged?" do
53
+ describe "#check_merged!" do
54
54
 
55
55
  before do
56
56
  mock(@git).system("git status --porcelain"){ "" }
@@ -61,12 +61,13 @@ describe AssistedWorkflow::Addons::Git do
61
61
 
62
62
  it "returns true if current branch is merged into master" do
63
63
  mock(@git).system("git branch --merged"){ "flavio.00001.new_feature" }
64
- @git.is_merged?.must_equal true
64
+ @git.check_merged!.must_equal true
65
65
  end
66
66
 
67
67
  it "returns false if current branch is not merged into master" do
68
68
  mock(@git).system("git branch --merged"){ "flavio.00002.other_feature" }
69
- @git.is_merged?.must_equal false
69
+ proc { @git.check_merged! }.must_raise AssistedWorkflow::Error, "this branch is not merged into master"
70
+
70
71
  end
71
72
  end
72
73
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: assisted_workflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -151,7 +151,6 @@ files:
151
151
  - lib/assisted_workflow/cli.rb
152
152
  - lib/assisted_workflow/config_file.rb
153
153
  - lib/assisted_workflow/exceptions.rb
154
- - lib/assisted_workflow/git.rb
155
154
  - lib/assisted_workflow/output.rb
156
155
  - lib/assisted_workflow/templates/awconfig.global.tt
157
156
  - lib/assisted_workflow/templates/awconfig.local.tt
@@ -219,7 +218,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
219
218
  version: '0'
220
219
  segments:
221
220
  - 0
222
- hash: -50568132931744746
221
+ hash: 4272922658484443950
223
222
  required_rubygems_version: !ruby/object:Gem::Requirement
224
223
  none: false
225
224
  requirements:
@@ -228,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
228
227
  version: '0'
229
228
  segments:
230
229
  - 0
231
- hash: -50568132931744746
230
+ hash: 4272922658484443950
232
231
  requirements: []
233
232
  rubyforge_project:
234
233
  rubygems_version: 1.8.24
@@ -1,111 +0,0 @@
1
- require "assisted_workflow/exceptions"
2
-
3
- module AssistedWorkflow
4
-
5
- class GitError < Error; end
6
-
7
- class Git
8
-
9
- DESCRIPTION_LIMIT = 30
10
-
11
- def initialize(output, options = {})
12
- super
13
- @command_options = {:raise_error => true}.merge(options)
14
- end
15
-
16
- # creates a new git branch based on story attributes
17
- # the branch name format is:
18
- # => story_onwer_username.story_id.story_name
19
- def create_story_branch(story)
20
- log "creating the new branch"
21
- branch = branch_name(story)
22
- git "checkout -b #{branch}"
23
- # git "push --set-upstream origin #{branch}"
24
- end
25
-
26
- # run all the git steps required for a clean pull request
27
- def rebase_and_push
28
- log "preparing local branch"
29
- check_everything_commited!
30
- branch = current_branch
31
- git "checkout master"
32
- git "pull --rebase"
33
- git "checkout #{branch}"
34
- git "rebase master"
35
- git "push -u -f origin #{branch}"
36
- end
37
-
38
- # returns the current story id based on branch name
39
- def current_story_id
40
- current_branch.split(".")[1]
41
- end
42
-
43
- # returns the current local branch name
44
- def current_branch
45
- git("rev-parse --abbrev-ref HEAD", :silent => true)
46
- end
47
-
48
- # returns the repository name assigned to origin following the format:
49
- # owner/project
50
- def repository
51
- url = git("config --get remote.origin.url", :error => "cannot find 'origin' remote repository url")
52
- url.gsub("git@github.com:", "").gsub("https://github.com/", "").gsub(/\.git$/, "").chomp
53
- end
54
-
55
- # check if current branch is merged into master
56
- def check_merged!
57
- check_everything_commited!
58
- branch = current_branch
59
- git "checkout master"
60
- git "pull --rebase"
61
- merged = git("branch --merged").include?(branch)
62
- git "checkout #{branch}"
63
- unless merged
64
- raise AssistedWorkflow::Error, "this branch is not merged into master"
65
- end
66
- end
67
-
68
- # removes current branch and its remote version
69
- def remove_branch
70
- log "removing local and remote feature branches"
71
- branch = current_branch
72
- git "push origin :#{branch}", :raise_error => false
73
- git "checkout master"
74
- git "branch -D #{branch}"
75
- end
76
-
77
- private
78
-
79
- def git(command, options = {})
80
- options = @command_options.merge(options)
81
- # log("git #{command}", :step => true) unless options[:silent] == true
82
- result = system("git #{command}")
83
- if system_error? && options[:raise_error]
84
- msg = ["git command error", options[:error]].compact.join(": ")
85
- raise GitError, msg
86
- end
87
- result
88
- end
89
-
90
- def system(command)
91
- %x{#{command}}.chomp
92
- end
93
-
94
- def system_error?
95
- $? != 0
96
- end
97
-
98
- def branch_name(story)
99
- description = story.name.to_s.downcase.gsub(/\W/, "_").slice(0, DESCRIPTION_LIMIT)
100
- [story.other_id, story.id, description].join(".").downcase
101
- end
102
-
103
- def not_commited_changes
104
- git("status --porcelain", :silent => true).split("\n")
105
- end
106
-
107
- def check_everything_commited!
108
- raise AssistedWorkflow::Error, "git: there are not commited changes" unless not_commited_changes.empty?
109
- end
110
- end
111
- end