socialcast-git-extensions 3.1.2 → 3.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -21,6 +21,19 @@ integrate the current feature branch into an aggregate branch (ex: prototype, st
21
21
 
22
22
  create a pull request on github for peer review of the current branch.
23
23
 
24
+ === Optional:
25
+ Specify a Review Buddy mapping that will reference the local Github username and @mention a pre-assigned review buddy in the Socialcast Review Request message. Specify the mapping by creating a Configuration YML file relative to the Repo Root: config/scgitx.yml with the following format:
26
+
27
+ review_buddies:
28
+ emilyjames: # Github Username "emilyjames"
29
+ socialcast_username: "EmilyJames" # Socialcast UserName
30
+ buddy: bobdavis # Buddy's Github username
31
+ bobdavis:
32
+ socialcast_username: "BobDavis"
33
+ buddy: emilyjames
34
+
35
+ In this example, when Emily runs `git reviewrequest` from her local machine, @BobDavis will receive an @mention in Socialcast notifying him to review her branch. If Bob runs the command, Emily will receive a notice in Socialcast.
36
+
24
37
  == git release
25
38
 
26
39
  release the current feature branch to master
data/config/scgitx.yml ADDED
@@ -0,0 +1,8 @@
1
+ # Map github usernames to Socialcast usernames and assign review buddies
2
+ review_buddies:
3
+ vanm:
4
+ socialcast_username: VanMiranda
5
+ buddy: wireframe
6
+ wireframe:
7
+ socialcast_username: RyanSonnek
8
+ buddy: vanm
@@ -32,6 +32,10 @@ module Socialcast
32
32
 
33
33
  update
34
34
 
35
+ review_mention = if buddy = socialcast_review_buddy(current_user)
36
+ "Assigned to @#{buddy}"
37
+ end
38
+
35
39
  description = options[:description] || editor_input(PULL_REQUEST_DESCRIPTION)
36
40
  branch = current_branch
37
41
  repo = current_repo
@@ -39,7 +43,7 @@ module Socialcast
39
43
  say "Pull request created: #{url}"
40
44
 
41
45
  short_description = description.split("\n").first(5).join("\n")
42
- review_message = ["#reviewrequest for #{branch} #scgitx", "/cc @SocialcastDevelopers", short_description, changelog_summary(branch)].join("\n\n")
46
+ review_message = ["#reviewrequest for #{branch} #scgitx", "/cc @SocialcastDevelopers", review_mention, short_description, changelog_summary(branch)].compact.join("\n\n")
43
47
  post review_message, :url => url, :message_type => 'review_request'
44
48
  end
45
49
 
@@ -24,6 +24,12 @@ module Socialcast
24
24
  repo.gsub(/\.git$/,'').split(/[:\/]/).last(2).join('/')
25
25
  end
26
26
 
27
+ # @returns [String] github username (ex: 'wireframe') of the current github.user
28
+ # @returns empty [String] when no github.user is set on the system
29
+ def current_user
30
+ `git config -z --global --get github.user`.strip
31
+ end
32
+
27
33
  # retrieve a list of branches
28
34
  def branches(options = {})
29
35
  branches = []
@@ -138,6 +144,30 @@ module Socialcast
138
144
  description.gsub(/^\#.*/, '').chomp.strip
139
145
  end
140
146
  end
147
+
148
+ # load SC Git Extensions Config YAML
149
+ # @returns [Hash] of configuration options from YAML file (if it exists)
150
+ def config
151
+ @config ||= begin
152
+ if config_file.exist?
153
+ YAML.load_file(config_file)
154
+ else
155
+ {}
156
+ end
157
+ end
158
+ end
159
+
160
+ # @returns a [Pathname] for the scgitx.yml Config File
161
+ # from either ENV['SCGITX_CONFIG_PATH'] or default $PWD/config/scgitx.yml
162
+ def config_file
163
+ Pathname((ENV['SCGITX_CONFIG_PATH'] || ([Dir.pwd, '/config/scgitx.yml']).join))
164
+ end
165
+
166
+ # load Review buddies from the SCGITX Configuration YML
167
+ # @returns [Hash] of review buddy mapping from Config YML (ex: {'wireframe' => {'socialcast_username' => 'RyanSonnek', 'buddy' => 'vanm'}})
168
+ def review_buddies
169
+ config['review_buddies'] || {}
170
+ end
141
171
  end
142
172
  end
143
173
  end
@@ -13,7 +13,7 @@ module Socialcast
13
13
  credentials = Socialcast.credentials
14
14
  return credentials[:scgitx_token] if credentials[:scgitx_token]
15
15
 
16
- username = `git config -z --global --get github.user`.strip
16
+ username = current_user
17
17
  raise "Github user not configured. Run: `git config --global github.user 'me@email.com'`" if username.empty?
18
18
  password = ask("Github password for #{username}: ") { |q| q.echo = false }
19
19
 
@@ -51,6 +51,16 @@ module Socialcast
51
51
  data = JSON.parse e.http_body
52
52
  say "Failed to create pull request: #{data['message']}", :red
53
53
  end
54
+
55
+ # @returns [String] socialcast username to assign the review to
56
+ # @returns [nil] when no buddy system configured or user not found
57
+ def socialcast_review_buddy(current_user)
58
+ review_requestor = review_buddies[current_user]
59
+
60
+ if review_requestor && review_buddies[review_requestor['buddy']]
61
+ review_buddies[review_requestor['buddy']]['socialcast_username']
62
+ end
63
+ end
54
64
  end
55
65
  end
56
66
  end
@@ -1,5 +1,5 @@
1
1
  module Socialcast
2
2
  module Gitx
3
- VERSION = "3.1.2"
3
+ VERSION = "3.1.3"
4
4
  end
5
5
  end
data/spec/cli_spec.rb CHANGED
@@ -16,6 +16,7 @@ describe Socialcast::Gitx::CLI do
16
16
  before do
17
17
  Socialcast::Gitx::CLI.stubbed_executed_commands = []
18
18
  Socialcast::Gitx::CLI.any_instance.stub(:current_branch).and_return('FOO')
19
+ Socialcast::Gitx::CLI.any_instance.stub(:current_user).and_return('wireframe')
19
20
  Socialcast::Gitx::CLI.any_instance.stub(:post)
20
21
  end
21
22
 
@@ -268,12 +269,37 @@ describe Socialcast::Gitx::CLI do
268
269
  end
269
270
 
270
271
  describe '#reviewrequest' do
271
- context 'when description != null' do
272
+ context 'when there are no review_buddies specified' do
273
+ before do
274
+ Socialcast::Gitx::CLI.any_instance.stub(:config_file).and_return(Pathname(''))
275
+ end
276
+ context 'when description != null' do
277
+ before do
278
+ stub_request(:post, "https://api.github.com/repos/socialcast/socialcast-git-extensions/pulls").
279
+ to_return(:status => 200, :body => %q({"html_url": "http://github.com/repo/project/pulls/1"}), :headers => {})
280
+
281
+ Socialcast::Gitx::CLI.any_instance.should_receive(:post).with("#reviewrequest for FOO #scgitx\n\n/cc @SocialcastDevelopers\n\ntesting\n\n", :url => 'http://github.com/repo/project/pulls/1', :message_type => 'review_request')
282
+ Socialcast::Gitx::CLI.start ['reviewrequest', '--description', 'testing']
283
+ end
284
+ it 'should create github pull request' do end # see expectations
285
+ it 'should post socialcast message' do end # see expectations
286
+ it 'should run expected commands' do
287
+ Socialcast::Gitx::CLI.stubbed_executed_commands.should == [
288
+ "git pull origin FOO",
289
+ "git pull origin master",
290
+ "git push origin HEAD"
291
+ ]
292
+ end
293
+ end
294
+ end
295
+
296
+ context 'when review_buddies are specified via a /config YML file' do
272
297
  before do
273
298
  stub_request(:post, "https://api.github.com/repos/socialcast/socialcast-git-extensions/pulls").
274
299
  to_return(:status => 200, :body => %q({"html_url": "http://github.com/repo/project/pulls/1"}), :headers => {})
275
300
 
276
- Socialcast::Gitx::CLI.any_instance.should_receive(:post).with("#reviewrequest for FOO #scgitx\n\n/cc @SocialcastDevelopers\n\ntesting\n\n", :url => 'http://github.com/repo/project/pulls/1', :message_type => 'review_request')
301
+ # The Review Buddy should be @mentioned in the message
302
+ Socialcast::Gitx::CLI.any_instance.should_receive(:post).with("#reviewrequest for FOO #scgitx\n\n/cc @SocialcastDevelopers\n\nAssigned to @VanMiranda\n\ntesting\n\n", :url => 'http://github.com/repo/project/pulls/1', :message_type => 'review_request')
277
303
  Socialcast::Gitx::CLI.start ['reviewrequest', '--description', 'testing']
278
304
  end
279
305
  it 'should create github pull request' do end # see expectations
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: socialcast-git-extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.2
4
+ version: 3.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-23 00:00:00.000000000 Z
12
+ date: 2012-11-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: grit
@@ -191,6 +191,7 @@ files:
191
191
  - bin/git-track
192
192
  - bin/git-update
193
193
  - bin/git-wtf
194
+ - config/scgitx.yml
194
195
  - lib/socialcast-git-extensions.rb
195
196
  - lib/socialcast-git-extensions/cli.rb
196
197
  - lib/socialcast-git-extensions/git.rb
@@ -214,7 +215,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
214
215
  version: '0'
215
216
  segments:
216
217
  - 0
217
- hash: -3432850963659879185
218
+ hash: 735880262416414370
218
219
  required_rubygems_version: !ruby/object:Gem::Requirement
219
220
  none: false
220
221
  requirements:
@@ -223,7 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
224
  version: '0'
224
225
  segments:
225
226
  - 0
226
- hash: -3432850963659879185
227
+ hash: 735880262416414370
227
228
  requirements: []
228
229
  rubyforge_project: socialcast-git-extensions
229
230
  rubygems_version: 1.8.24