everypolitician-pull_request 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 +10 -0
- data/.rubocop.yml +6 -0
- data/.rubocop_todo.yml +22 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/Rakefile +13 -0
- data/bin/console +10 -0
- data/bin/setup +8 -0
- data/comment_template.md.erb +126 -0
- data/everypolitician-pull_request.gemspec +32 -0
- data/lib/everypolitician/pull_request.rb +7 -0
- data/lib/everypolitician/pull_request/compare_popolo.rb +69 -0
- data/lib/everypolitician/pull_request/find_popolo_files.rb +11 -0
- data/lib/everypolitician/pull_request/report/base.rb +14 -0
- data/lib/everypolitician/pull_request/report/elections.rb +21 -0
- data/lib/everypolitician/pull_request/report/organizations.rb +15 -0
- data/lib/everypolitician/pull_request/report/people.rb +15 -0
- data/lib/everypolitician/pull_request/report/people_addtional_names.rb +25 -0
- data/lib/everypolitician/pull_request/report/people_names.rb +26 -0
- data/lib/everypolitician/pull_request/report/terms.rb +21 -0
- data/lib/everypolitician/pull_request/report/wikidata.rb +20 -0
- data/lib/everypolitician/pull_request/review_changes.rb +23 -0
- data/lib/everypolitician/pull_request/summary.rb +46 -0
- data/lib/everypolitician/pull_request/version.rb +5 -0
- metadata +210 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 992468ae0a956df5932c7fef0f1c3113e3b33862
|
4
|
+
data.tar.gz: b9f3da521445ec749b3a350b213680b9ea9300b1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 121f2fd5500bc183b41f02aae5fa897af6e21e5f842146557b378b0fb2546c517472b7abeac663b9bf52ae00b4688619e35c213ae2e1804c45bd16181c3c118d
|
7
|
+
data.tar.gz: 65731efebba647c13a95a7f0c27c66ed48ec2488ca4692bff7b2f9c0e65959539b2e383fe9aabb2335a5f879134af2e2da2cf828e3b56a845502e32ee1553528
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2016-09-12 14:27:30 +0100 using RuboCop version 0.42.0.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 4
|
10
|
+
Metrics/AbcSize:
|
11
|
+
Max: 38
|
12
|
+
|
13
|
+
# Offense count: 35
|
14
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
|
15
|
+
# URISchemes: http, https
|
16
|
+
Metrics/LineLength:
|
17
|
+
Max: 139
|
18
|
+
|
19
|
+
# Offense count: 2
|
20
|
+
# Configuration parameters: CountComments.
|
21
|
+
Metrics/MethodLength:
|
22
|
+
Max: 15
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Chris Mytton
|
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,44 @@
|
|
1
|
+
# EveryPolitician Pull Request summary
|
2
|
+
|
3
|
+
Produces a summary of an EveryPolitician data pull request like [this one](https://github.com/everypolitician/everypolitician-data/pull/16984#issuecomment-246282991).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'everypolitician-pull_request'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install everypolitician-pull_request
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
To print a summary of an [everypolitician-data](https://github.com/everypolitician/everypolitician-data) pull request as markdown, use the following:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'everypolitician/pull_request'
|
27
|
+
puts Everypolitician::PullRequest::Summary.new(16984).as_markdown
|
28
|
+
```
|
29
|
+
|
30
|
+
Where `16984` is the pull request number in [everypolitician-data](https://github.com/everypolitician/everypolitician-data) that you want the review for.
|
31
|
+
|
32
|
+
## Development
|
33
|
+
|
34
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
35
|
+
|
36
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/everypolitician/everypolitician-pull_request.
|
41
|
+
|
42
|
+
## License
|
43
|
+
|
44
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
Rake::TestTask.new(:test) do |t|
|
5
|
+
t.libs << 'test'
|
6
|
+
t.libs << 'lib'
|
7
|
+
t.test_files = FileList['test/**/*_test.rb']
|
8
|
+
end
|
9
|
+
|
10
|
+
task default: :test
|
11
|
+
|
12
|
+
require 'rubocop/rake_task'
|
13
|
+
RuboCop::RakeTask.new
|
data/bin/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'everypolitician/pull_request'
|
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
|
+
require 'pry'
|
10
|
+
Pry.start
|
data/bin/setup
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
<% if popolo_files.empty? %>
|
2
|
+
No Popolo files were changed in this pull request.
|
3
|
+
<% else %>
|
4
|
+
<% popolo_files.each do |file| %>
|
5
|
+
Summary of changes in `<%= file.path %>`:
|
6
|
+
|
7
|
+
## People
|
8
|
+
|
9
|
+
### Added
|
10
|
+
|
11
|
+
<% if file.people_added.any? %>
|
12
|
+
<% file.people_added.each do |person| %>
|
13
|
+
- `<%= person.id %>` - <%= person.name %>
|
14
|
+
<% end %>
|
15
|
+
<% else %>
|
16
|
+
No people added
|
17
|
+
<% end %>
|
18
|
+
|
19
|
+
### Removed
|
20
|
+
|
21
|
+
<% if file.people_removed.any? %>
|
22
|
+
<% file.people_removed.each do |person| %>
|
23
|
+
- `<%= person.id %>` - <%= person.name %>
|
24
|
+
<% end %>
|
25
|
+
<% else %>
|
26
|
+
No people removed
|
27
|
+
<% end %>
|
28
|
+
|
29
|
+
### Name Changes
|
30
|
+
|
31
|
+
<% if file.people_name_changes.any? %>
|
32
|
+
<% file.people_name_changes.each do |r| %>
|
33
|
+
- `<%= r[:id] %>`: <%= r[:was] %> → <%= r[:now] %>
|
34
|
+
<% end %>
|
35
|
+
<% else %>
|
36
|
+
No name changes
|
37
|
+
<% end %>
|
38
|
+
|
39
|
+
### Additional Name Changes
|
40
|
+
|
41
|
+
<% if file.people_additional_name_changes.any? %>
|
42
|
+
<% file.people_additional_name_changes.each do |r| %>
|
43
|
+
- `<%= r[:id] %>` (<%= r[:name] %>): <% if r[:removed].any? %>Removed: <%= r[:removed].join(" ﹠ ") %>. <% end %><% if r[:added].any? %>Added: <%= r[:added].join(" ﹠ ") %>.<% end %>
|
44
|
+
<% end %>
|
45
|
+
<% else %>
|
46
|
+
No name changes
|
47
|
+
<% end %>
|
48
|
+
|
49
|
+
### Wikidata Changes
|
50
|
+
|
51
|
+
<% if file.wikidata_links_changed.any? %>
|
52
|
+
<% file.wikidata_links_changed.each do |r| %>
|
53
|
+
- `<%= r[:id] %>`: <%= r[:was] %> → <%= r[:now] %>
|
54
|
+
<% end %>
|
55
|
+
<% else %>
|
56
|
+
No changes
|
57
|
+
<% end %>
|
58
|
+
|
59
|
+
## Organizations
|
60
|
+
|
61
|
+
### Added
|
62
|
+
|
63
|
+
<% if file.organizations_added.any? %>
|
64
|
+
<% file.organizations_added.each do |org| %>
|
65
|
+
- `<%= org.id %>` - <%= org.name %>
|
66
|
+
<% end %>
|
67
|
+
<% else %>
|
68
|
+
No organizations added
|
69
|
+
<% end %>
|
70
|
+
|
71
|
+
### Removed
|
72
|
+
|
73
|
+
<% if file.organizations_removed.any? %>
|
74
|
+
<% file.organizations_removed.each do |org| %>
|
75
|
+
- `<%= org.id %>` - <%= org.name %>
|
76
|
+
<% end %>
|
77
|
+
<% else %>
|
78
|
+
No organizations removed
|
79
|
+
<% end %>
|
80
|
+
|
81
|
+
## Terms
|
82
|
+
|
83
|
+
### Added
|
84
|
+
|
85
|
+
<% if file.terms_added.any? %>
|
86
|
+
<% file.terms_added.each do |term| %>
|
87
|
+
- `<%= term.id %>` - <%= term.name %>
|
88
|
+
<% end %>
|
89
|
+
<% else %>
|
90
|
+
No terms added
|
91
|
+
<% end %>
|
92
|
+
|
93
|
+
### Removed
|
94
|
+
|
95
|
+
<% if file.terms_removed.any? %>
|
96
|
+
<% file.terms_removed.each do |term| %>
|
97
|
+
- `<%= term.id %>` - <%= term.name %>
|
98
|
+
<% end %>
|
99
|
+
<% else %>
|
100
|
+
No terms removed
|
101
|
+
<% end %>
|
102
|
+
|
103
|
+
## Elections
|
104
|
+
|
105
|
+
### Added
|
106
|
+
|
107
|
+
<% if file.elections_added.any? %>
|
108
|
+
<% file.elections_added.each do |election| %>
|
109
|
+
- `<%= election.id %>` - <%= election.name %>
|
110
|
+
<% end %>
|
111
|
+
<% else %>
|
112
|
+
No elections added
|
113
|
+
<% end %>
|
114
|
+
|
115
|
+
### Removed
|
116
|
+
|
117
|
+
<% if file.elections_removed.any? %>
|
118
|
+
<% file.elections_removed.each do |election| %>
|
119
|
+
- `<%= election.id %>` - <%= election.name %>
|
120
|
+
<% end %>
|
121
|
+
<% else %>
|
122
|
+
No elections removed
|
123
|
+
<% end %>
|
124
|
+
|
125
|
+
<% end %>
|
126
|
+
<% end %>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'everypolitician/pull_request/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'everypolitician-pull_request'
|
8
|
+
spec.version = Everypolitician::PullRequest::VERSION
|
9
|
+
spec.authors = ['Chris Mytton']
|
10
|
+
spec.email = ['chrismytton@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Produces a summary of EveryPolitician data pull requests'
|
13
|
+
spec.homepage = 'https://github.com/everypolitician/everypolitician-pull_request'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = 'exe'
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'everypolitician-popolo'
|
22
|
+
spec.add_runtime_dependency 'require_all'
|
23
|
+
spec.add_runtime_dependency 'octokit'
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
28
|
+
spec.add_development_dependency 'pry', '~> 0.10'
|
29
|
+
spec.add_development_dependency 'rubocop', '~> 0.42'
|
30
|
+
spec.add_development_dependency 'vcr', '~> 3.0'
|
31
|
+
spec.add_development_dependency 'webmock', '~> 2.1'
|
32
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'everypolitician/popolo'
|
2
|
+
|
3
|
+
require_rel 'report'
|
4
|
+
|
5
|
+
module Everypolitician
|
6
|
+
module PullRequest
|
7
|
+
class ComparePopolo
|
8
|
+
attr_reader :before
|
9
|
+
attr_reader :after
|
10
|
+
attr_reader :path
|
11
|
+
|
12
|
+
def self.parse(options)
|
13
|
+
before = Everypolitician::Popolo.parse(options[:before])
|
14
|
+
after = Everypolitician::Popolo.parse(options[:after])
|
15
|
+
new(before: before, after: after, path: options[:path])
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(options)
|
19
|
+
@before = options[:before]
|
20
|
+
@after = options[:after]
|
21
|
+
@path = options[:path]
|
22
|
+
end
|
23
|
+
|
24
|
+
def people_name_changes
|
25
|
+
Report::PeopleNames.new(before, after).changed
|
26
|
+
end
|
27
|
+
|
28
|
+
def people_additional_name_changes
|
29
|
+
Report::PeopleAdditionalNames.new(before, after).changed
|
30
|
+
end
|
31
|
+
|
32
|
+
def people_added
|
33
|
+
Report::People.new(before, after).added
|
34
|
+
end
|
35
|
+
|
36
|
+
def people_removed
|
37
|
+
Report::People.new(before, after).removed
|
38
|
+
end
|
39
|
+
|
40
|
+
def wikidata_links_changed
|
41
|
+
Report::Wikidata.new(before, after).changed
|
42
|
+
end
|
43
|
+
|
44
|
+
def organizations_added
|
45
|
+
Report::Organizations.new(before, after).added
|
46
|
+
end
|
47
|
+
|
48
|
+
def organizations_removed
|
49
|
+
Report::Organizations.new(before, after).removed
|
50
|
+
end
|
51
|
+
|
52
|
+
def terms_added
|
53
|
+
Report::Terms.new(before, after).added
|
54
|
+
end
|
55
|
+
|
56
|
+
def terms_removed
|
57
|
+
Report::Terms.new(before, after).removed
|
58
|
+
end
|
59
|
+
|
60
|
+
def elections_added
|
61
|
+
Report::Elections.new(before, after).added
|
62
|
+
end
|
63
|
+
|
64
|
+
def elections_removed
|
65
|
+
Report::Elections.new(before, after).removed
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Everypolitician
|
2
|
+
module PullRequest
|
3
|
+
class Report
|
4
|
+
class Elections < Base
|
5
|
+
def elections(events)
|
6
|
+
events.select do |event|
|
7
|
+
event if event.document[:classification] == 'general election'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def added
|
12
|
+
elections(after.events - before.events)
|
13
|
+
end
|
14
|
+
|
15
|
+
def removed
|
16
|
+
elections(before.events - after.events)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Everypolitician
|
2
|
+
module PullRequest
|
3
|
+
class Report
|
4
|
+
class PeopleAdditionalNames < PeopleNames
|
5
|
+
def changed
|
6
|
+
all_names = lambda do |p|
|
7
|
+
other_names = p.other_names.map { |n| n[:name] } rescue []
|
8
|
+
(other_names | [p.name]).to_set
|
9
|
+
end
|
10
|
+
names_all_pre = Hash[before.persons.map { |p| [p.id, all_names.call(p)] }]
|
11
|
+
names_all_post = Hash[after.persons.map { |p| [p.id, all_names.call(p)] }]
|
12
|
+
in_both = names_all_pre.keys & names_all_post.keys
|
13
|
+
in_both.select { |id| names_all_pre[id] != names_all_post[id] }.map do |id|
|
14
|
+
{
|
15
|
+
id: id,
|
16
|
+
name: before_names[id],
|
17
|
+
removed: (names_all_pre[id] - names_all_post[id]).to_a,
|
18
|
+
added: (names_all_post[id] - names_all_pre[id]).to_a,
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Everypolitician
|
2
|
+
module PullRequest
|
3
|
+
class Report
|
4
|
+
class PeopleNames < Base
|
5
|
+
def before_names
|
6
|
+
@name_hash_pre ||= Hash[before.persons.map { |p| [p.id, p.name] }]
|
7
|
+
end
|
8
|
+
|
9
|
+
def after_names
|
10
|
+
@name_hash_post ||= Hash[after.persons.map { |p| [p.id, p.name] }]
|
11
|
+
end
|
12
|
+
|
13
|
+
def changed
|
14
|
+
in_both = before_names.keys & after_names.keys
|
15
|
+
in_both.select { |id| !before_names[id].casecmp(after_names[id].downcase).zero? }.map do |id|
|
16
|
+
{
|
17
|
+
id: id,
|
18
|
+
was: before_names[id],
|
19
|
+
now: after_names[id],
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Everypolitician
|
2
|
+
module PullRequest
|
3
|
+
class Report
|
4
|
+
class Terms < Base
|
5
|
+
def terms(events)
|
6
|
+
events.select do |event|
|
7
|
+
event if event.document[:classification] == 'legislative period'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def added
|
12
|
+
terms(after.events - before.events)
|
13
|
+
end
|
14
|
+
|
15
|
+
def removed
|
16
|
+
terms(before.events - after.events)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Everypolitician
|
2
|
+
module PullRequest
|
3
|
+
class Report
|
4
|
+
class Wikidata < Base
|
5
|
+
def changed
|
6
|
+
prev = Hash[before.persons.map { |p| [p.id, p.wikidata] }]
|
7
|
+
post = Hash[after.persons.map { |p| [p.id, p.wikidata] }]
|
8
|
+
in_both = prev.keys & post.keys
|
9
|
+
in_both.select { |id| prev[id] != post[id] }.map do |id|
|
10
|
+
{
|
11
|
+
id: id,
|
12
|
+
was: prev[id] || 'none',
|
13
|
+
now: post[id] || 'none',
|
14
|
+
}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
module Everypolitician
|
4
|
+
module PullRequest
|
5
|
+
class ReviewChanges
|
6
|
+
attr_reader :popolo_files
|
7
|
+
|
8
|
+
def initialize(popolo_before_after)
|
9
|
+
@popolo_files = popolo_before_after.map do |opts|
|
10
|
+
ComparePopolo.parse(opts)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_html
|
15
|
+
template.result(binding)
|
16
|
+
end
|
17
|
+
|
18
|
+
def template
|
19
|
+
@template ||= ERB.new(File.read(File.expand_path('../../../../comment_template.md.erb', __FILE__)))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'octokit'
|
2
|
+
require 'open-uri'
|
3
|
+
|
4
|
+
module Everypolitician
|
5
|
+
module PullRequest
|
6
|
+
class Summary
|
7
|
+
class Error < StandardError; end
|
8
|
+
|
9
|
+
attr_reader :pull_request_number
|
10
|
+
|
11
|
+
def initialize(pull_request_number)
|
12
|
+
@pull_request_number = pull_request_number
|
13
|
+
end
|
14
|
+
|
15
|
+
def as_markdown
|
16
|
+
pull_request = github.pull_request(everypolitician_data_repo, pull_request_number)
|
17
|
+
files = github.pull_request_files(everypolitician_data_repo, pull_request_number)
|
18
|
+
popolo_before_after = FindPopoloFiles.from(files).map do |file|
|
19
|
+
{
|
20
|
+
path: file[:filename],
|
21
|
+
before: open(file[:raw_url].sub(pull_request[:head][:sha], pull_request[:base][:sha])).read,
|
22
|
+
after: open(file[:raw_url]).read,
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
begin
|
27
|
+
ReviewChanges.new(popolo_before_after).to_html
|
28
|
+
rescue Octokit::UnprocessableEntity => e
|
29
|
+
raise Error, "Unable to review pull request #{pull_request_number}: #{e.message}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def github
|
36
|
+
@github ||= Octokit::Client.new.tap do |g|
|
37
|
+
g.access_token = ENV['GITHUB_ACCESS_TOKEN']
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def everypolitician_data_repo
|
42
|
+
ENV.fetch('EVERYPOLITICIAN_DATA_REPO', 'everypolitician/everypolitician-data')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,210 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: everypolitician-pull_request
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Mytton
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: everypolitician-popolo
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: require_all
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: octokit
|
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
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.12'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.12'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '5.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '5.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.10'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.10'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.42'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.42'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: vcr
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '3.0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '3.0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: webmock
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '2.1'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '2.1'
|
153
|
+
description:
|
154
|
+
email:
|
155
|
+
- chrismytton@gmail.com
|
156
|
+
executables: []
|
157
|
+
extensions: []
|
158
|
+
extra_rdoc_files: []
|
159
|
+
files:
|
160
|
+
- ".gitignore"
|
161
|
+
- ".rubocop.yml"
|
162
|
+
- ".rubocop_todo.yml"
|
163
|
+
- ".travis.yml"
|
164
|
+
- Gemfile
|
165
|
+
- LICENSE.txt
|
166
|
+
- README.md
|
167
|
+
- Rakefile
|
168
|
+
- bin/console
|
169
|
+
- bin/setup
|
170
|
+
- comment_template.md.erb
|
171
|
+
- everypolitician-pull_request.gemspec
|
172
|
+
- lib/everypolitician/pull_request.rb
|
173
|
+
- lib/everypolitician/pull_request/compare_popolo.rb
|
174
|
+
- lib/everypolitician/pull_request/find_popolo_files.rb
|
175
|
+
- lib/everypolitician/pull_request/report/base.rb
|
176
|
+
- lib/everypolitician/pull_request/report/elections.rb
|
177
|
+
- lib/everypolitician/pull_request/report/organizations.rb
|
178
|
+
- lib/everypolitician/pull_request/report/people.rb
|
179
|
+
- lib/everypolitician/pull_request/report/people_addtional_names.rb
|
180
|
+
- lib/everypolitician/pull_request/report/people_names.rb
|
181
|
+
- lib/everypolitician/pull_request/report/terms.rb
|
182
|
+
- lib/everypolitician/pull_request/report/wikidata.rb
|
183
|
+
- lib/everypolitician/pull_request/review_changes.rb
|
184
|
+
- lib/everypolitician/pull_request/summary.rb
|
185
|
+
- lib/everypolitician/pull_request/version.rb
|
186
|
+
homepage: https://github.com/everypolitician/everypolitician-pull_request
|
187
|
+
licenses:
|
188
|
+
- MIT
|
189
|
+
metadata: {}
|
190
|
+
post_install_message:
|
191
|
+
rdoc_options: []
|
192
|
+
require_paths:
|
193
|
+
- lib
|
194
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
195
|
+
requirements:
|
196
|
+
- - ">="
|
197
|
+
- !ruby/object:Gem::Version
|
198
|
+
version: '0'
|
199
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
200
|
+
requirements:
|
201
|
+
- - ">="
|
202
|
+
- !ruby/object:Gem::Version
|
203
|
+
version: '0'
|
204
|
+
requirements: []
|
205
|
+
rubyforge_project:
|
206
|
+
rubygems_version: 2.5.1
|
207
|
+
signing_key:
|
208
|
+
specification_version: 4
|
209
|
+
summary: Produces a summary of EveryPolitician data pull requests
|
210
|
+
test_files: []
|