linterbot 0.1.0 → 0.2.0

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: dde45db3e73e3ec689bc1ef9aad6df01df8c763e
4
- data.tar.gz: aa351f4a7146f00b5cb26c32dc3b9287fd0ba888
3
+ metadata.gz: a2f26a60af3c2daf0fd41d3de2bba31227e106c9
4
+ data.tar.gz: dd5127dee945ad434f69d3a1d8be4568b6fe6f3c
5
5
  SHA512:
6
- metadata.gz: c022b7291ea41e832744c4980a1f920b2b4bd6b4dbdba4c203794e469bb636cb963354f0f61007d8ccf478c1d2c5ca6d793a0fb2d3496139bf4012dc955a0b07
7
- data.tar.gz: 7a271ee4ef5a10dbfa63882b45b24b6fceaed72792ae3157293512fa34a0837e9b8dedffd348a3b24899e79795e5eda85d693b2f6b23492b1051ba49f2524db0
6
+ metadata.gz: fc79ca148abf04b7e64aef79bee6f13799c6636adc58112358d04cab86ce51e433f6d2ad69bb89ded7ed9d4ad68e94cfc37e4fed3b9b6d46e2444b4c0f44e1d7
7
+ data.tar.gz: 2789de7abf885410d298011b490af03ea10dce24d1034e81af058b6f9d53acea3c8704e9a11b5338c97f452dec5277de68fadf811b0c7199e2d134e47d7c9a66
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # Linterbot
2
2
 
3
- A bot that parses swiftlint output and analyzes a GitHub pull request. Then for each linter violation it will make comment in the pull request diff on the line where the violation was made.
3
+ [![Gem Version](https://badge.fury.io/rb/linterbot.svg)](https://badge.fury.io/rb/linterbot)
4
+
5
+ A bot that parses [SwiftLint](https://github.com/realm/SwiftLint) output and analyzes a GitHub pull request. Then for each linter violation it will make comment in the pull request diff on the line where the violation was made.
6
+
7
+ ![linterbot commenting on pull request](./docs/assets/linterbot-comment-pull-request.png)
4
8
 
5
9
  ## Installation
6
10
 
@@ -20,18 +24,74 @@ Or install it yourself as:
20
24
 
21
25
  ## Usage
22
26
 
23
- Locally
27
+ ### Locally
28
+
29
+ If you want to try it locally:
24
30
 
25
31
  ```
26
32
  swiftlint --reporter json | linterbot REPOSITORY PULL_REQUEST_NUMBER
27
33
  ```
28
34
 
29
- In TravisCI
35
+ ### TravisCI
30
36
 
37
+ If you want to run it in TravisCI for every pull request triggered build you can create a script (with execution permission) called `linter` with the following content:
38
+
39
+ ```bash
40
+ #!/bin/bash
41
+
42
+ if [ "$TRAVIS_PULL_REQUEST" != "false" ]
43
+ then
44
+ swiftlint --reporter json > switlint-report.json || false
45
+ linterbot $TRAVIS_REPO_SLUG $TRAVIS_PULL_REQUEST < swiftlint-report
46
+ fi
31
47
  ```
32
- swiftlint --reporter json | linterbot $TRAVIS_REPO_SLUG $TRAVIS_PULL_REQUEST
48
+ *`|| false` avoids a build fail if there are severe lint error*
49
+
50
+ Finally in your `.travis.yml` file:
51
+
52
+ ```yml
53
+ language: objective-c
54
+ osx_image: xcode7.2
55
+ before_install:
56
+ - gem install bundler
57
+ - gem install linterbot
58
+ - brew install swiftlint
59
+ script:
60
+ - linter
61
+ - xcodebuild clean build test -project YourProject.xcodeproj -scheme YourProject
33
62
  ```
34
63
 
64
+ For more help run:
65
+
66
+ ```
67
+ linterbot -h
68
+ ```
69
+
70
+ and if you want to check all the available options for the `run` command (which is the default command to be run if none is provided) then run:
71
+
72
+ ```
73
+ linterbot help run
74
+ ```
75
+
76
+ ### GitHub access
77
+
78
+ In order for linterbot to be able to comment on your pull request it needs write access to the specified repository. You can provided an access token by either using the environmental variable `GITHUB_ACCESS_TOKEN` or using the `.linterbot.yml` (which should not be committed to your git repository).
79
+
80
+ ### Configuration file
81
+
82
+ You can define some configuration parameters in configuration file. By default `linterbot` will try to load `.linterbot.yml` from the current working directory. You can change it using the `--config-file-path` option.
83
+
84
+ The following are the supported parameters you can configure in the `.linterbot.yml` file:
85
+
86
+ ```yml
87
+ github_access_token: 'YOUR_GITHUB_ACCESS_TOKEN'
88
+ linter_report_file: 'PATH/TO/SWIFTLINT/JSON/OUTPUT/FILE'
89
+ project_base_path: 'BASE/PROJECT/PATH'
90
+ ```
91
+
92
+ By default `linterbot` will read from the standard input the JSON output of the `swiftlint lint --reporter json` command. You can tell `linterbot` to read the `swiftlint` output from a specific file either using the `--linter-report-file-path` option or through the `.linterbot.yml` file.
93
+
94
+ The base path of project must be provided. By default the current working directory where `linterbot` was executed is used. You can change it either using the `--project-base-path` or through the `.linterbot.yml` file.
35
95
 
36
96
  ## Development
37
97
 
@@ -12,8 +12,8 @@ module Linterbot
12
12
  github_client.create_status(repository, sha, "success", context: context, description: approve_description)
13
13
  end
14
14
 
15
- def reject(repository, sha)
16
- github_client.create_status(repository, sha, "failure", context: context, description: reject_description)
15
+ def reject(repository, sha, serious_violations_count)
16
+ github_client.create_status(repository, sha, "failure", context: context, description: reject_description(serious_violations_count))
17
17
  end
18
18
 
19
19
  def pending(repository, sha)
@@ -34,8 +34,8 @@ module Linterbot
34
34
  "The pull request passed the linter validations!"
35
35
  end
36
36
 
37
- def reject_description
38
- "There are linter violations that must be fixed!"
37
+ def reject_description(serious_violations_count)
38
+ "There are #{serious_violations_count} serious linter violations that must be fixed!"
39
39
  end
40
40
 
41
41
  end
@@ -24,7 +24,11 @@ module Linterbot
24
24
  end
25
25
 
26
26
  def publish_summary(summary)
27
- github_client.add_comment(repository, pull_request_number, summary)
27
+ if same_as_last_summary?(summary)
28
+ puts "Summary was not published because it's the same as the last result summary:\n #{summary}"
29
+ else
30
+ github_client.add_comment(repository, pull_request_number, summary)
31
+ end
28
32
  end
29
33
 
30
34
  private
@@ -42,17 +46,33 @@ module Linterbot
42
46
  end
43
47
 
44
48
  def comment_exist?(message)
45
- existing_comments.find { |comment| comment.body == message && comment.user.id == bot_github_id }
49
+ existing_comments.find { |comment| same_comment?(comment, message) }
50
+ end
51
+
52
+ def existing_summaries
53
+ @existing_summaries ||= fetch_existing_comments("issue")
54
+ end
55
+
56
+ def latest_existing_comment
57
+ @latest_existing_comment ||= existing_summaries.sort { |a, b| b.created_at <=> a.created_at }.first
58
+ end
59
+
60
+ def same_as_last_summary?(summary)
61
+ latest_existing_comment && same_comment?(latest_existing_comment, summary)
62
+ end
63
+
64
+ def same_comment?(comment, message)
65
+ comment.body == message && comment.user.id == bot_github_id
46
66
  end
47
67
 
48
68
  def existing_comments
49
- @existing_comments ||= fetch_existing_comments
69
+ @existing_comments ||= fetch_existing_comments("pull_request")
50
70
  end
51
71
 
52
- def fetch_existing_comments
53
- github_client.pull_request_comments(repository, pull_request_number).map do |comment|
72
+ def fetch_existing_comments(source)
73
+ github_client.send("#{source}_comments", repository, pull_request_number).map do |comment|
54
74
  user = OpenStruct.new(comment[:user].to_h)
55
- OpenStruct.new(comment.to_h.merge(:user => user))
75
+ OpenStruct.new(comment.to_h.merge(user: user))
56
76
  end
57
77
  end
58
78
 
@@ -12,18 +12,30 @@ module Linterbot
12
12
  comments.empty?
13
13
  end
14
14
 
15
+ def violations?
16
+ comments.count > 0
17
+ end
18
+
15
19
  def violations_count
16
20
  comments.count
17
21
  end
18
22
 
19
23
  def summary
20
- "Total linter violations in pull request: #{comments.count}\n" +
21
- "Serious: #{serious_violations.count}\n" +
22
- "Warnings: #{warning_violations.count}"
24
+ if violations?
25
+ "Total linter violations in pull request: #{comments.count}\n" +
26
+ "Serious: #{serious_violations.count}\n" +
27
+ "Warnings: #{warning_violations.count}"
28
+ else
29
+ ":+1: There are no linter violations."
30
+ end
31
+ end
32
+
33
+ def serious_violations_count
34
+ serious_violations.count
23
35
  end
24
36
 
25
37
  def serious_violations?
26
- serious_violations.count > 0
38
+ serious_violations_count > 0
27
39
  end
28
40
 
29
41
  private
@@ -17,7 +17,7 @@ module Linterbot
17
17
  result.comments.each { |comment| commenter.publish_comment(comment) }
18
18
  commenter.publish_summary(result.summary)
19
19
  if result.serious_violations?
20
- reject_pull_request
20
+ reject_pull_request(result.serious_violations_count)
21
21
  else
22
22
  approve_pull_request
23
23
  end
@@ -9,8 +9,8 @@ module Linterbot
9
9
  puts approve_description
10
10
  end
11
11
 
12
- def reject(repository, sha)
13
- puts reject_description
12
+ def reject(repository, sha, serious_violations_count)
13
+ puts reject_description(serious_violations_count)
14
14
  end
15
15
 
16
16
  def pending(repository, sha)
@@ -25,8 +25,8 @@ module Linterbot
25
25
  "The pull request passed the linter validations!"
26
26
  end
27
27
 
28
- def reject_description
29
- "There are linter violations that must be fixed!"
28
+ def reject_description(serious_violations_count)
29
+ "There are #{serious_violations_count} serious linter violations that must be fixed!"
30
30
  end
31
31
 
32
32
  end
@@ -1,3 +1,3 @@
1
1
  module Linterbot
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linterbot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guido Marucci Blas
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-20 00:00:00.000000000 Z
11
+ date: 2016-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -114,6 +114,7 @@ files:
114
114
  - Rakefile
115
115
  - bin/console
116
116
  - bin/setup
117
+ - docs/assets/linterbot-comment-pull-request.png
117
118
  - exe/linterbot
118
119
  - lib/linterbot.rb
119
120
  - lib/linterbot/comment.rb