policial 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f9ea96661ceb59f07846827daf7ccf1d9f1ed2c6
4
- data.tar.gz: 26d33c00ee9d4dfa3e65196f3faa6d8c4bfad416
3
+ metadata.gz: 0bd45df38f9f7a34cf66c40c590f6303f5da2ce9
4
+ data.tar.gz: 0b8b8e18e4d78f0af05fd3b7c9397e97bfb256fe
5
5
  SHA512:
6
- metadata.gz: 59ea217f976c38a00fb0a80bac2fd23c73f592622efcef1e8689db454ced0e54365da3e9a459f0b0a1a26d6e34ae5c4e5a4105d748f90ccb16e98a20b7e1bf8e
7
- data.tar.gz: 58be1670722255f6886aae39685cf7357406e4b1e74d97b752752faa682574b8d5914bd233ad9c32f8683197e33e79e38220062faf4144deb34a85ccd729ddd0
6
+ metadata.gz: d0fba5b32b0d423d8a087fd94748dc01ed583f0058dd23d76432521f6ad4c72f36e9ecef1a894f0af660800838fbf8f0a027b0bfe83410905b0b341359fa763b
7
+ data.tar.gz: d88ae791f713457b4bbc61a0b2ea8d99fc8f8f8872aeae4972d5ff8c9cc5f71392bc18519175d675f9b19ea9bb8ddfd25b167ecab62f50c05cb11af53dd717a9
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
- # Policial
1
+ # Policial :cop:
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/policial.svg)](http://badge.fury.io/rb/policial)
3
4
  [![Build Status](https://travis-ci.org/volmer/policial.svg)](https://travis-ci.org/volmer/policial)
4
5
 
5
6
  *Policial* is a gem that investigates pull requests and accuses style guide
@@ -27,52 +28,57 @@ Or install it yourself as:
27
28
 
28
29
  ## Usage
29
30
 
30
- First, you need to set your GitHub credentials. For more information on
31
- this, please check [Octokit README](https://github.com/octokit/octokit.rb).
31
+ 1. You might need to instantiate an Octokit client with your GitHub
32
+ credentials. For more information on this please check the
33
+ [Octokit README](https://github.com/octokit/octokit.rb).
32
34
 
33
- ```ruby
34
- Octokit.configure do |c|
35
- c.access_tokein = 'mygithubtoken666'
36
- end
37
- ```
35
+ ```ruby
36
+ Policial.octokit = Octokit::Client.new(access_token: 'mygithubtoken666')
37
+ ```
38
+ Ignore this step if you want Policial to use the global Octokit configuration.
38
39
 
39
- You start with a pull request which Policial will run an investigation
40
- against. You can setup a pull request manually:
41
40
 
42
- ```ruby
43
- pull_request = Policial::PullRequest.new(
44
- repo: 'volmer/my_repo',
45
- number: 3,
46
- head_sha: 'headsha'
47
- )
48
- ```
41
+ 2. Let's investigate! Start with a pull request which Policial will run an
42
+ investigation against. You can setup a pull request manually:
49
43
 
50
- Or you can extract a pull request from a
51
- [GitHub `pull_request` webhook](https://developer.github.com/webhooks):
44
+ ```ruby
45
+ pull_request = Policial::PullRequest.new(
46
+ repo: 'volmer/my_repo',
47
+ number: 3,
48
+ head_sha: 'headsha'
49
+ )
50
+ ```
52
51
 
53
- ```ruby
54
- event = Policial::PullRequestEvent.new(webhook_payload)
55
- pull_request = event.pull_request
56
- ```
52
+ Or you can extract a pull request from a
53
+ [GitHub `pull_request` webhook](https://developer.github.com/webhooks):
57
54
 
58
- Now you can start an investigation:
55
+ ```ruby
56
+ event = Policial::PullRequestEvent.new(webhook_payload)
57
+ pull_request = event.pull_request
58
+ ```
59
59
 
60
- ```ruby
61
- investigation = Policial::Investigation.new(pull_request)
60
+ 3. Now you can run the investigation:
62
61
 
63
- # Let's investigate this pull request...
64
- investigation.run
62
+ ```ruby
63
+ investigation = Policial::Investigation.new(pull_request)
65
64
 
66
- # Want to know the violations found?
67
- investigation.violations
65
+ # Let's investigate this pull request...
66
+ investigation.run
68
67
 
69
- # Hurry, post comments about those violations on the pull request!
70
- investigation.accuse
71
- ```
68
+ # Want to know the violations found?
69
+ investigation.violations
70
+ ```
71
+
72
+ 4. Hurry, post comments about those violations on the pull request!
73
+ ```ruby
74
+ investigation.accuse
75
+ ```
76
+ The result are comments like this on each line that contains violations:
77
+ ![image](https://cloud.githubusercontent.com/assets/301187/5545861/d5c3da76-8afe-11e4-8c15-341b01f3b820.png)
72
78
 
73
79
  ## Contributing
74
80
 
75
- 1. Fork it ( https://github.com/volmer/policial/fork )
81
+ 1. Fork it
76
82
  2. Create your feature branch (`git checkout -b my-new-feature`)
77
83
  3. Commit your changes (`git commit -am 'Add some feature'`)
78
84
  4. Push to the branch (`git push origin my-new-feature`)
data/lib/policial.rb CHANGED
@@ -4,6 +4,7 @@ require 'policial/accusation_policy'
4
4
  require 'policial/commenter'
5
5
  require 'policial/commit'
6
6
  require 'policial/commit_file'
7
+ require 'policial/octokit_client'
7
8
  require 'policial/investigation'
8
9
  require 'policial/line'
9
10
  require 'policial/patch'
@@ -22,7 +23,7 @@ require 'policial/violation'
22
23
  # so you can configure GitHub credentials, enable/disable style guides
23
24
  # and more.
24
25
  module Policial
25
- STYLE_GUIDES = [Policial::StyleGuides::Ruby]
26
+ extend OctokitClient
26
27
 
27
- Octokit.auto_paginate = true
28
+ STYLE_GUIDES = [Policial::StyleGuides::Ruby]
28
29
  end
@@ -6,7 +6,7 @@ module Policial
6
6
  end
7
7
 
8
8
  def comment_violation(violation)
9
- Octokit.create_pull_request_comment(
9
+ Policial.octokit.create_pull_request_comment(
10
10
  @pull_request.repo,
11
11
  @pull_request.number,
12
12
  comment_body(violation),
@@ -9,7 +9,7 @@ module Policial
9
9
  end
10
10
 
11
11
  def file_content(filename)
12
- contents = Octokit.contents(@repo, path: filename, ref: @sha)
12
+ contents = Policial.octokit.contents(@repo, path: filename, ref: @sha)
13
13
 
14
14
  if contents && contents.content
15
15
  Base64.decode64(contents.content).force_encoding('UTF-8')
@@ -0,0 +1,10 @@
1
+ module Policial
2
+ # Private: wraps accessors for the inner Octokit client.
3
+ module OctokitClient
4
+ attr_writer :octokit
5
+
6
+ def octokit
7
+ @octokit || Octokit
8
+ end
9
+ end
10
+ end
@@ -15,7 +15,9 @@ module Policial
15
15
  end
16
16
 
17
17
  def files
18
- @files ||= Octokit.pull_request_files(@repo, @number).map do |file|
18
+ @files ||= Policial.octokit.pull_request_files(
19
+ @repo, @number
20
+ ).map do |file|
19
21
  build_commit_file(file)
20
22
  end
21
23
  end
@@ -32,7 +34,7 @@ module Policial
32
34
 
33
35
  def fetch_comments
34
36
  paginate do |page|
35
- Octokit.pull_request_comments(
37
+ Policial.octokit.pull_request_comments(
36
38
  @repo,
37
39
  @number,
38
40
  page: page
@@ -1,4 +1,4 @@
1
1
  # Public: The gem version.
2
2
  module Policial
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: policial
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Volmer Soares
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-21 00:00:00.000000000 Z
11
+ date: 2014-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit
@@ -55,6 +55,7 @@ files:
55
55
  - lib/policial/commit_file.rb
56
56
  - lib/policial/investigation.rb
57
57
  - lib/policial/line.rb
58
+ - lib/policial/octokit_client.rb
58
59
  - lib/policial/patch.rb
59
60
  - lib/policial/pull_request.rb
60
61
  - lib/policial/pull_request_event.rb