policial 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +40 -34
- data/lib/policial.rb +3 -2
- data/lib/policial/commenter.rb +1 -1
- data/lib/policial/commit.rb +1 -1
- data/lib/policial/octokit_client.rb +10 -0
- data/lib/policial/pull_request.rb +4 -2
- data/lib/policial/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0bd45df38f9f7a34cf66c40c590f6303f5da2ce9
|
4
|
+
data.tar.gz: 0b8b8e18e4d78f0af05fd3b7c9397e97bfb256fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
+
[](http://badge.fury.io/rb/policial)
|
3
4
|
[](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
|
-
|
31
|
-
this
|
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.
|
35
|
-
|
36
|
-
|
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
|
-
|
43
|
-
|
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
|
-
|
51
|
-
|
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
|
-
|
54
|
-
|
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
|
-
|
55
|
+
```ruby
|
56
|
+
event = Policial::PullRequestEvent.new(webhook_payload)
|
57
|
+
pull_request = event.pull_request
|
58
|
+
```
|
59
59
|
|
60
|
-
|
61
|
-
investigation = Policial::Investigation.new(pull_request)
|
60
|
+
3. Now you can run the investigation:
|
62
61
|
|
63
|
-
|
64
|
-
investigation.
|
62
|
+
```ruby
|
63
|
+
investigation = Policial::Investigation.new(pull_request)
|
65
64
|
|
66
|
-
#
|
67
|
-
investigation.
|
65
|
+
# Let's investigate this pull request...
|
66
|
+
investigation.run
|
68
67
|
|
69
|
-
#
|
70
|
-
investigation.
|
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
|
+

|
72
78
|
|
73
79
|
## Contributing
|
74
80
|
|
75
|
-
1. Fork it
|
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
|
-
|
26
|
+
extend OctokitClient
|
26
27
|
|
27
|
-
|
28
|
+
STYLE_GUIDES = [Policial::StyleGuides::Ruby]
|
28
29
|
end
|
data/lib/policial/commenter.rb
CHANGED
data/lib/policial/commit.rb
CHANGED
@@ -9,7 +9,7 @@ module Policial
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def file_content(filename)
|
12
|
-
contents =
|
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')
|
@@ -15,7 +15,9 @@ module Policial
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def files
|
18
|
-
@files ||=
|
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
|
-
|
37
|
+
Policial.octokit.pull_request_comments(
|
36
38
|
@repo,
|
37
39
|
@number,
|
38
40
|
page: page
|
data/lib/policial/version.rb
CHANGED
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.
|
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-
|
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
|