pt-flow 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -12,6 +12,7 @@ Install the gem:
12
12
 
13
13
  - flow start
14
14
  - flow finish
15
+ - flow review
15
16
  - flow deliver
16
17
 
17
18
  ### Committer
@@ -28,8 +29,8 @@ $ flow finish
28
29
  ### Reviewer
29
30
 
30
31
  ```bash
31
- $ git fetch
32
- $ git checkout master-325325
32
+ $ flow review
33
+ # checks out branch and opens github page
33
34
  # run tests, review code etc...
34
35
 
35
36
  $ flow deliver
data/lib/pt-flow.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require "pt"
2
2
  require "pt-flow/version"
3
+ require "pt-flow/repo"
4
+ require "pt-flow/pull_requests_table"
3
5
  require "pt-flow/ui"
4
6
 
5
7
  module PT
@@ -0,0 +1,7 @@
1
+ module PT::Flow
2
+ class PullRequestsTable < PT::DataTable
3
+ def self.fields
4
+ [:title]
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,33 @@
1
+ module PT::Flow
2
+ class Repo
3
+ require "github_api"
4
+ CONFIG_PATH = ENV['HUB_CONFIG'] || ENV['HOME'] + '/.config/hub'
5
+
6
+ def pull_requests
7
+ client.pull_requests.all(user, name)
8
+ end
9
+
10
+ def user
11
+ path.split('/').first
12
+ end
13
+
14
+ def name
15
+ path.split('/').last
16
+ end
17
+
18
+ private
19
+
20
+ def path
21
+ @path ||= `git config --get remote.origin.url`.strip.match(/:(\S+\/\S+)\.git/)[1]
22
+ end
23
+
24
+ def client
25
+ @client ||= Github.new(oauth_token: oauth_token)
26
+ end
27
+
28
+ def oauth_token
29
+ @oauth_token ||= YAML.load(File.read(CONFIG_PATH)).values.flatten.first['oauth_token']
30
+ end
31
+
32
+ end
33
+ end
data/lib/pt-flow/ui.rb CHANGED
@@ -1,109 +1,114 @@
1
- class PT::Flow::UI < PT::UI
2
- def my_work #default command
3
- help
4
- end
1
+ module PT::Flow
2
+ class UI < PT::UI
5
3
 
6
- def start
7
- tasks = @client.get_work(@project)
8
- table = PT::TasksTable.new(tasks)
9
- title("Available tasks in #{project_to_s}")
10
- task = select("Please select a task to start working on", table)
4
+ def my_work #default command
5
+ help
6
+ end
11
7
 
12
- estimate_task(task, ask("How many points do you estimate for it? (#{@project.point_scale})")) if task.estimate && task.estimate < 0
13
- assign_task(task, @local_config[:user_name])
14
- start_task(task)
15
- run("git checkout -B #{current_target}-#{task.id}")
16
- end
8
+ def start
9
+ tasks = @client.get_work(@project)
10
+ table = PT::TasksTable.new(tasks)
11
+ title("Available tasks in #{project_to_s}")
12
+ task = select("Please select a task to start working on", table)
13
+ estimate_task(task, ask("How many points do you estimate for it? (#{@project.point_scale})")) if task.estimate && task.estimate < 0
14
+ assign_task(task, @local_config[:user_name])
15
+ start_task(task)
16
+ run("git checkout -b #{current_target}-#{task.id}")
17
+ end
17
18
 
18
- def finish
19
- run("git push origin #{current_branch}")
20
- task = PivotalTracker::Story.find(current_task_id, @project.id)
21
- title = task.name.gsub('"',"'") + " [##{task.id}]"
22
- run("hub pull-request -b #{github_user}:#{current_target} \"#{title}\"")
23
- finish_task(task)
24
- end
19
+ def finish
20
+ run("git push origin #{current_branch}")
21
+ task = PivotalTracker::Story.find(current_task_id, @project.id)
22
+ title = task.name.gsub('"',"'") + " [##{task.id}]"
23
+ run("hub pull-request -b #{repo.user}:#{current_target} \"#{title}\"")
24
+ finish_task(task)
25
+ end
25
26
 
26
- def deliver
27
- run('git fetch')
28
- run("git checkout #{current_target}")
29
- run("git pull --rebase origin #{current_target}")
30
- run("git merge #{current_branch}")
31
- run("git push origin #{current_target}")
32
- run("git push origin :#{current_branch}")
33
- run("git branch -d #{current_branch}")
34
- task = PivotalTracker::Story.find(current_task_id, @project.id)
35
- deliver_task(task)
36
- end
27
+ def deliver
28
+ run('git fetch')
29
+ run("git checkout #{current_target}")
30
+ run("git pull --rebase origin #{current_target}")
31
+ run("git merge #{current_branch}")
32
+ run("git push origin #{current_target}")
33
+ run("git push origin :#{current_branch}")
34
+ run("git branch -d #{current_branch}")
35
+ task = PivotalTracker::Story.find(current_task_id, @project.id)
36
+ deliver_task(task)
37
+ end
37
38
 
38
- def cleanup
39
- # Update our list of remotes
40
- run("git fetch")
41
- run("git remote prune origin")
39
+ def review
40
+ table = PullRequestsTable.new(repo.pull_requests)
41
+ pull_request = select("Please select a pull request to review", table)
42
+ run("git fetch")
43
+ run("git checkout #{pull_request.head.ref}")
44
+ run("open #{pull_request.html_url}")
45
+ rescue Github::Error::Unauthorized => e
46
+ error("Error from github: #{e.message}")
47
+ end
42
48
 
43
- # Remove local branches fully merged with origin/master
44
- run("git branch --merged origin/master | grep -v 'master$' | xargs git branch -D")
49
+ def cleanup
50
+ # Update our list of remotes
51
+ run("git fetch")
52
+ run("git remote prune origin")
45
53
 
46
- # Remove remote branches fully merged with origin/master
47
- run("git branch -r --merged origin/master | sed 's/ *origin\\///' | grep -v 'master$' | xargs -I% git push origin :%")
54
+ # Remove local branches fully merged with origin/master
55
+ run("git branch --merged origin/master | grep -v 'master$' | xargs git branch -D")
48
56
 
49
- congrats('All clean!')
50
- end
57
+ # Remove remote branches fully merged with origin/master
58
+ run("git branch -r --merged origin/master | sed 's/ *origin\\///' | grep -v 'master$' | xargs -I% git push origin :%")
51
59
 
52
- def help
53
- if ARGV[0] && ARGV[0] != 'help'
54
- message("Command #{ARGV[0]} not recognized. Showing help.")
60
+ congrats('All clean!')
55
61
  end
56
62
 
57
- title("Command line usage")
58
- puts("flow start # start working on a story")
59
- puts("flow finish # finish a story and create a pull request")
60
- puts("flow deliver # merge current story branch and clean up")
61
- puts("flow cleanup # deleted merged local branches and prune origin")
62
- end
63
+ def help
64
+ if ARGV[0] && ARGV[0] != 'help'
65
+ message("Command #{ARGV[0]} not recognized. Showing help.")
66
+ end
67
+
68
+ title("Command line usage")
69
+ puts("flow start # start working on a story")
70
+ puts("flow finish # finish a story and create a pull request")
71
+ puts("flow review # review a pull request")
72
+ puts("flow deliver # merge current branch and clean up")
73
+ puts("flow cleanup # deleted merged local/remote branches and prune origin")
74
+ end
63
75
 
64
- private
76
+ private
65
77
 
66
- def assign_task(task, owner)
67
- result = @client.assign_task(@project, task, owner)
68
- if result.errors.any?
69
- error(result.errors.errors)
70
- else
71
- congrats("Task assigned to #{owner}")
78
+ def repo
79
+ Repo.new
72
80
  end
73
- end
74
-
75
- def github_user
76
- github_stub.split('/').first
77
- end
78
81
 
79
- def github_repo
80
- github_stub.split('/').last
81
- end
82
+ def assign_task(task, owner)
83
+ result = @client.assign_task(@project, task, owner)
84
+ if result.errors.any?
85
+ error(result.errors.errors)
86
+ else
87
+ congrats("Task assigned to #{owner}")
88
+ end
89
+ end
82
90
 
83
- def github_stub
84
- @github_stub ||= `git config --get remote.origin.url`.strip.match(/:(\S+\/\S+)\.git/)[1]
85
- end
91
+ def current_branch
92
+ @current_branch ||= `git rev-parse --abbrev-ref HEAD`.strip
93
+ end
86
94
 
87
- def current_branch
88
- @current_branch ||= `git rev-parse --abbrev-ref HEAD`.strip
89
- end
95
+ def current_target
96
+ current_branch.sub(current_task_id, '').chomp('-')
97
+ end
90
98
 
91
- def current_target
92
- current_branch.sub(current_task_id, '').chomp('-')
93
- end
99
+ def current_task_id
100
+ current_branch[/\d+$/] || ''
101
+ end
94
102
 
95
- def current_task_id
96
- current_branch[/\d+$/] || ''
97
- end
103
+ def run(command)
104
+ title(command)
105
+ error("Error running: #{command}") unless system(command)
106
+ end
98
107
 
99
- def run(command)
100
- title(command)
101
- error("Error running: #{command}") unless system(command)
102
- end
108
+ def error(*msg)
109
+ super
110
+ exit(false)
111
+ end
103
112
 
104
- def error(*msg)
105
- super
106
- exit(false)
107
113
  end
108
-
109
114
  end
@@ -1,5 +1,5 @@
1
1
  module PT
2
2
  module Flow
3
- VERSION = "0.4.2"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
data/pt-flow.gemspec CHANGED
@@ -17,6 +17,7 @@ Gem::Specification.new do |gem|
17
17
 
18
18
  gem.add_dependency 'pt'
19
19
  gem.add_dependency 'hub'
20
+ gem.add_dependency 'github_api'
20
21
 
21
22
  gem.add_development_dependency 'rspec', '~> 2.9'
22
23
  gem.add_development_dependency 'webmock'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pt-flow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-10-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pt
16
- requirement: &70298092537360 !ruby/object:Gem::Requirement
16
+ requirement: &70252617038720 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70298092537360
24
+ version_requirements: *70252617038720
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: hub
27
- requirement: &70298092535820 !ruby/object:Gem::Requirement
27
+ requirement: &70252617038040 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,21 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70298092535820
35
+ version_requirements: *70252617038040
36
+ - !ruby/object:Gem::Dependency
37
+ name: github_api
38
+ requirement: &70252617037360 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70252617037360
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: rspec
38
- requirement: &70298084709260 !ruby/object:Gem::Requirement
49
+ requirement: &70252617036160 !ruby/object:Gem::Requirement
39
50
  none: false
40
51
  requirements:
41
52
  - - ~>
@@ -43,10 +54,10 @@ dependencies:
43
54
  version: '2.9'
44
55
  type: :development
45
56
  prerelease: false
46
- version_requirements: *70298084709260
57
+ version_requirements: *70252617036160
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: webmock
49
- requirement: &70298084708300 !ruby/object:Gem::Requirement
60
+ requirement: &70252613503660 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ! '>='
@@ -54,10 +65,10 @@ dependencies:
54
65
  version: '0'
55
66
  type: :development
56
67
  prerelease: false
57
- version_requirements: *70298084708300
68
+ version_requirements: *70252613503660
58
69
  - !ruby/object:Gem::Dependency
59
70
  name: guard
60
- requirement: &70298084707000 !ruby/object:Gem::Requirement
71
+ requirement: &70252613502320 !ruby/object:Gem::Requirement
61
72
  none: false
62
73
  requirements:
63
74
  - - ! '>='
@@ -65,10 +76,10 @@ dependencies:
65
76
  version: '0'
66
77
  type: :development
67
78
  prerelease: false
68
- version_requirements: *70298084707000
79
+ version_requirements: *70252613502320
69
80
  - !ruby/object:Gem::Dependency
70
81
  name: guard-rspec
71
- requirement: &70298084704300 !ruby/object:Gem::Requirement
82
+ requirement: &70252613501500 !ruby/object:Gem::Requirement
72
83
  none: false
73
84
  requirements:
74
85
  - - ! '>='
@@ -76,7 +87,7 @@ dependencies:
76
87
  version: '0'
77
88
  type: :development
78
89
  prerelease: false
79
- version_requirements: *70298084704300
90
+ version_requirements: *70252613501500
80
91
  description: Some extra methods for the pt gem to use in our dev flow.
81
92
  email:
82
93
  - jens@balvig.com
@@ -93,6 +104,8 @@ files:
93
104
  - Rakefile
94
105
  - bin/flow
95
106
  - lib/pt-flow.rb
107
+ - lib/pt-flow/pull_requests_table.rb
108
+ - lib/pt-flow/repo.rb
96
109
  - lib/pt-flow/ui.rb
97
110
  - lib/pt-flow/version.rb
98
111
  - pt-flow.gemspec
@@ -128,7 +141,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
128
141
  version: '0'
129
142
  segments:
130
143
  - 0
131
- hash: 1681167446225851053
144
+ hash: -1163730068901382619
132
145
  required_rubygems_version: !ruby/object:Gem::Requirement
133
146
  none: false
134
147
  requirements:
@@ -137,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
150
  version: '0'
138
151
  segments:
139
152
  - 0
140
- hash: 1681167446225851053
153
+ hash: -1163730068901382619
141
154
  requirements: []
142
155
  rubyforge_project:
143
156
  rubygems_version: 1.8.11