pronto-labelman 0.0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +7 -0
- data/README.md +88 -0
- data/lib/pronto/formatter/github_pr_label_formatter.rb +13 -0
- data/lib/pronto/label.rb +9 -0
- data/lib/pronto/labelman/version.rb +5 -0
- data/lib/pronto/labelman.rb +56 -0
- data/lib/pronto/labelman_rules/rule.rb +22 -0
- data/lib/pronto/monkey_patches/formatter.rb +11 -0
- data/lib/pronto/monkey_patches/github.rb +7 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 22681cfb1887260e20a097422950d62fe8707e7e
|
4
|
+
data.tar.gz: 7f9559f96e49afbbff8db650b991c1a81a3f3de8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6b8f196ecb227b5946d64dbb150ddc54d596fc014dee5cc77ba8fbb2024efd87e18bbda05fe685272803af601acc1a2095a30c90936707b1909ce98e698d78ad
|
7
|
+
data.tar.gz: 819e392b94ce3fae701686a7ddb26de9fc78852502347ab4d56317ebf4eb37450b507c8fe77f371d4c29ee277a16b174139f04ed42a602c4c197b661363d8d17
|
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright 2017 Amiel Perez
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
## Pronto-Labelman
|
2
|
+
|
3
|
+
![pronto-labelman-icon](https://cloud.githubusercontent.com/assets/5194847/23691790/a88578d0-0405-11e7-9492-0ac8ec32d545.png)
|
4
|
+
|
5
|
+
### Pronto runner for automatically adding labels to Github Pull Requests.
|
6
|
+
|
7
|
+
### Use Case
|
8
|
+
* You want to automate decision-making and addition of labels to Github PR's, e.g., if a PR contains .HTML files, automatically tag it for Design review.
|
9
|
+
* You are already using [pronto](https://github.com/mmozuras/pronto) with Github
|
10
|
+
|
11
|
+
### How it Works
|
12
|
+
Simple, really. It acts as a pronto runner, giving it visibility over the payload of a pull request. It then tries to find classes that are 1. under the namespace `Pronto::LabelmanRules` and 2.) extend the `Pronto::LabelmanRules::Rule` class.
|
13
|
+
|
14
|
+
These rule classes, which are to be implemented by users of this gem, will be responsible for inspecting the pull request payload and deciding whether to associate it with a particular label (more on this later).
|
15
|
+
|
16
|
+
### Prerequisites
|
17
|
+
* Properly-configured `pronto` environment
|
18
|
+
|
19
|
+
### Installation
|
20
|
+
|
21
|
+
Install the gem
|
22
|
+
```
|
23
|
+
gem install pronto-labelman
|
24
|
+
```
|
25
|
+
|
26
|
+
Invoke from pronto. Set `github_pr_label` as formatter (`-f`) and `labelman` as runner (`-r`)
|
27
|
+
|
28
|
+
```bash
|
29
|
+
pronto run -f github_pr_label -c $BASE_BRANCH_SHA -r labelman
|
30
|
+
```
|
31
|
+
If you want to specify a temporary path where to look for rules, use the `LABELMAN_RULES` environment variable
|
32
|
+
|
33
|
+
```bash
|
34
|
+
export LABELMAN_RULES=path/to/custom/pronto/labelman_rules
|
35
|
+
pronto run -f github_pr_label -c $BASE_BRANCH_SHA -r labelman
|
36
|
+
```
|
37
|
+
|
38
|
+
### Creating Rules
|
39
|
+
1. Subclass `Pronto::LabelmanRules::Rule`. Make sure your subclass is in the namespace `Pronto::LabelmanRules`
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
module Pronto
|
43
|
+
module LabelmanRules
|
44
|
+
class MyCustomRule < Rule
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
2. Define a label using the `label` class method. This should match the name of the label that will be applied
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
module Pronto
|
54
|
+
module LabelmanRules
|
55
|
+
class MyCustomRule < Rule
|
56
|
+
label 'Needs Code Review'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
62
|
+
3. Implement the `applicable?` method. It should return a boolean signifying whether the label must be applied or not. You have access to the `@patches` attribute, signifying the changes
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
module Pronto
|
66
|
+
module LabelmanRules
|
67
|
+
class MyCustomRule < Rule
|
68
|
+
label 'Needs Code Review'
|
69
|
+
|
70
|
+
def applicable?
|
71
|
+
# Apply a label if the patches is not empty.
|
72
|
+
# Simple, dumb rule, yes, but it's just for purposes of illustration
|
73
|
+
true unless @patches.empty?
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
```
|
79
|
+
|
80
|
+
4. Make sure this class is in the load path or use the `LABELMAN_RULES` environment to tell Labelman where to find it
|
81
|
+
|
82
|
+
```
|
83
|
+
export LABELMAN_RULES=custom/pronto/labelman_rules
|
84
|
+
```
|
85
|
+
|
86
|
+
### Todo List
|
87
|
+
* Improve "monkey patching"
|
88
|
+
* More configuration
|
data/lib/pronto/label.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'pronto/monkey_patches/formatter'
|
2
|
+
require 'pronto/monkey_patches/github'
|
3
|
+
require 'pronto/label'
|
4
|
+
require 'pronto/labelman_rules/rule'
|
5
|
+
|
6
|
+
module Pronto
|
7
|
+
class Labelman < Runner
|
8
|
+
def initialize(patches, commit = nil)
|
9
|
+
super
|
10
|
+
|
11
|
+
@rules_load_path = ENV['LABELMAN_RULES']
|
12
|
+
if @rules_load_path
|
13
|
+
p "Using additional rules load path #{File.absolute_path("#{__dir__}/bin")}"
|
14
|
+
require_and_load_rules
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def run
|
19
|
+
return [] unless @patches
|
20
|
+
rule_classes = get_all_rule_implems
|
21
|
+
if rule_classes.empty?
|
22
|
+
p "There are no rule implementations found. Additional load path specified: #{@rules_load_path || '<NONE>'}"
|
23
|
+
return []
|
24
|
+
end
|
25
|
+
|
26
|
+
rule_classes.map do |rule_class|
|
27
|
+
p "Applying rule #{rule_class.name}"
|
28
|
+
[rule_class.new(@patches).apply]
|
29
|
+
end.compact
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def is_frontend_file?(patch)
|
35
|
+
File.extname(patch.new_file_full_path) =~ /\.(s*(c|a)ss|j(s|st\.ejs)|coffee)$/
|
36
|
+
end
|
37
|
+
|
38
|
+
def require_and_load_rules
|
39
|
+
Dir["#{@rules_load_path}/*.rb"].each do |file|
|
40
|
+
require file
|
41
|
+
load file
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_all_rule_implems
|
46
|
+
ns = Pronto::LabelmanRules
|
47
|
+
ns.constants.map do |c|
|
48
|
+
probable_class = ns.const_get(c)
|
49
|
+
if probable_class.is_a?(Class) &&
|
50
|
+
probable_class != Pronto::LabelmanRules::Rule
|
51
|
+
probable_class
|
52
|
+
end
|
53
|
+
end.compact
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Pronto
|
2
|
+
module LabelmanRules
|
3
|
+
class Rule
|
4
|
+
def initialize(patches)
|
5
|
+
@patches = patches
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.label(name)
|
9
|
+
define_method('label_name') { name }
|
10
|
+
end
|
11
|
+
|
12
|
+
def apply
|
13
|
+
Pronto::Label.new(label_name) if applicable?
|
14
|
+
end
|
15
|
+
|
16
|
+
def applicable?
|
17
|
+
# implement me!
|
18
|
+
false
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pronto-labelman
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Amiel Perez
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pronto
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.6'
|
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.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-its
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.0'
|
69
|
+
description: Pronto runner for that labels PRs automatically based on rules
|
70
|
+
email: perezamiel@yahoo.com
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- LICENSE
|
76
|
+
- README.md
|
77
|
+
- lib/pronto/formatter/github_pr_label_formatter.rb
|
78
|
+
- lib/pronto/label.rb
|
79
|
+
- lib/pronto/labelman.rb
|
80
|
+
- lib/pronto/labelman/version.rb
|
81
|
+
- lib/pronto/labelman_rules/rule.rb
|
82
|
+
- lib/pronto/monkey_patches/formatter.rb
|
83
|
+
- lib/pronto/monkey_patches/github.rb
|
84
|
+
homepage: http://github.org/amielperez/pronto-labelman
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 1.3.6
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.2.2
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: Pronto runner for that labels PRs automatically based on rules
|
108
|
+
test_files: []
|