prpr-lgtm 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/prpr/action/lgtm/comment.rb +99 -0
- data/lib/prpr/handler/lgtm.rb +9 -0
- data/lib/prpr/lgtm.rb +3 -0
- data/lib/prpr/lgtm/version.rb +5 -0
- data/prpr-lgtm.gemspec +25 -0
- data/screenshot.jpg +0 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7a9d492ce7bd310327ab1337e6c7023751edd335
|
4
|
+
data.tar.gz: 4083da661e0f0a824f4de4f921b1d0e3d4909775
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3ffef0418d30133b0a37605bd1f0312553e66d32709431fe664972c2b7d8c4625f6c535bcefe36f5c746fbac4c628e6e27e5b91323e7184e35a555b24a16c038
|
7
|
+
data.tar.gz: 74571a65834202db128c07034e4971f59a483ee4c66e745edbf4d8e73c552436d9feafa4168770508eaa297a20966abc8b9001b94ef1fe78b6d090c7952c4e3a
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 mzp
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Prpr::Lgtm
|
2
|
+
|
3
|
+
[Prpr](https://github.com/mzp/prpr) plugin to show review status as label.
|
4
|
+
|
5
|
+
![](https://raw.githubusercontent.com/mzp/prpr-lgtm/master/screenshot.jpg)
|
6
|
+
|
7
|
+
|
8
|
+
## Install
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'prpr-lgtm'
|
14
|
+
```
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
TODO: Write usage instructions here
|
19
|
+
|
20
|
+
## Env
|
21
|
+
|
22
|
+
* LGTM_LABEL_ONE: label name when one approve is added
|
23
|
+
* LlGTM_LABEL_OVER_2: label name two approve is added
|
24
|
+
* LGTM_BODY: comment message when two approval is added
|
25
|
+
|
26
|
+
## License
|
27
|
+
|
28
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
29
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "prpr/lgtm"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
module Prpr
|
2
|
+
module Action
|
3
|
+
module Lgtm
|
4
|
+
class Comment < Prpr::Action::Base
|
5
|
+
def call
|
6
|
+
if count == 1
|
7
|
+
add_label label(:one)
|
8
|
+
elsif count >= 2
|
9
|
+
unless already_labeled?(label(:over_2))
|
10
|
+
remove_label label(:one)
|
11
|
+
add_label label(:over_2)
|
12
|
+
add_comment
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def count
|
20
|
+
last_state.map(&method(:point)).reduce(:+)
|
21
|
+
end
|
22
|
+
|
23
|
+
def last_state
|
24
|
+
last_state = {}
|
25
|
+
reviews.each do|review|
|
26
|
+
if review[:state] != 'COMMENTED'
|
27
|
+
last_state[review[:user][:login]] = review[:state]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
last_state.values
|
31
|
+
end
|
32
|
+
|
33
|
+
def point(state)
|
34
|
+
case state
|
35
|
+
when 'APPROVED'
|
36
|
+
1
|
37
|
+
when 'CHANGES_REQUESTED'
|
38
|
+
-1
|
39
|
+
else
|
40
|
+
0
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def reviews
|
45
|
+
# FIXME: use offical method
|
46
|
+
@reviews ||=
|
47
|
+
github.get "#{Octokit::Repository.path repository}/pulls/#{pull_request_number}/reviews",
|
48
|
+
accept: 'application/vnd.github.black-cat-preview+json'
|
49
|
+
end
|
50
|
+
|
51
|
+
def add_comment
|
52
|
+
github.add_comment(repository, pull_request_number, message)
|
53
|
+
end
|
54
|
+
|
55
|
+
def message
|
56
|
+
env.format(:lgtm_body, event.pull_request.assignee)
|
57
|
+
end
|
58
|
+
|
59
|
+
def add_label(label)
|
60
|
+
return if already_labeled?(label)
|
61
|
+
github.add_labels_to_an_issue(repository, pull_request_number, [label])
|
62
|
+
end
|
63
|
+
|
64
|
+
def remove_label(label)
|
65
|
+
return unless already_labeled?(label)
|
66
|
+
github.remove_label(repository, pull_request_number, label)
|
67
|
+
end
|
68
|
+
|
69
|
+
def already_labeled?(label)
|
70
|
+
labels.map(&:name).any? { |name| name == label }
|
71
|
+
end
|
72
|
+
|
73
|
+
def labels
|
74
|
+
github.labels_for_issue(repository, pull_request_number)
|
75
|
+
end
|
76
|
+
|
77
|
+
def label(name)
|
78
|
+
Config::Env.default[:"lgtm_label_#{name}"] || name.to_s
|
79
|
+
end
|
80
|
+
|
81
|
+
def name
|
82
|
+
env[:mention_comment_members] || 'MEMBERS.md'
|
83
|
+
end
|
84
|
+
|
85
|
+
def repository
|
86
|
+
event.repository.full_name
|
87
|
+
end
|
88
|
+
|
89
|
+
def pull_request_number
|
90
|
+
event.pull_request.number
|
91
|
+
end
|
92
|
+
|
93
|
+
def github
|
94
|
+
Repository::Github.default
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
data/lib/prpr/lgtm.rb
ADDED
data/prpr-lgtm.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'prpr/lgtm/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "prpr-lgtm"
|
8
|
+
spec.version = Prpr::Lgtm::VERSION
|
9
|
+
spec.authors = ["mzp"]
|
10
|
+
spec.email = ["mzpppp@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Prpr plugin to show LGTM as label"
|
13
|
+
spec.description = "When someone says LGTM, add LGTM label"
|
14
|
+
spec.homepage = "https://github.com/mzp/prpr"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_dependency "prpr"
|
25
|
+
end
|
data/screenshot.jpg
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: prpr-lgtm
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- mzp
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: prpr
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: When someone says LGTM, add LGTM label
|
56
|
+
email:
|
57
|
+
- mzpppp@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- bin/console
|
68
|
+
- bin/setup
|
69
|
+
- lib/prpr/action/lgtm/comment.rb
|
70
|
+
- lib/prpr/handler/lgtm.rb
|
71
|
+
- lib/prpr/lgtm.rb
|
72
|
+
- lib/prpr/lgtm/version.rb
|
73
|
+
- prpr-lgtm.gemspec
|
74
|
+
- screenshot.jpg
|
75
|
+
homepage: https://github.com/mzp/prpr
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.2.2
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Prpr plugin to show LGTM as label
|
99
|
+
test_files: []
|