lita-pullrequests 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 70bef7ab4b7be5fc0e5f962cfb08398e2ff46cb1
4
+ data.tar.gz: 825b2b2d31027dbe2cd8570fce5906ac33ec97e0
5
+ SHA512:
6
+ metadata.gz: 5996838b6aba9b79e3a725af316ea583a72f5506e152bfc3a71a004542b1557c6f432759388b0593a3f74208a51a55e1fe5e23cfbfb2bba26f67b48651c5d874
7
+ data.tar.gz: 6971f04b3f2a9cb2b99af838b2a7a7cf7db2fb7cec27e37f0b242b5ed6f49212f0cf8c949a62bd0284f9c0588f9ef7922397ac5c7265122849d6dc22782b8a92
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2015 Taylor Lapeyre
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # lita-pullrequests
2
+
3
+ A Lita handler to help you keep track of your pull requests.
4
+
5
+ ## Installation
6
+
7
+ Add lita-pullrequests to your Lita instance's Gemfile:
8
+
9
+ ``` ruby
10
+ gem "lita-pullrequests"
11
+ ```
12
+
13
+ ## Configuration
14
+
15
+ Add the following configuration lines to your `lita_config`:
16
+
17
+ ``` ruby
18
+ config.handlers.pullrequests.access_token = "a-github-api-access-token"
19
+ config.handlers.pullrequests.repo = "username/reponame"
20
+ config.handlers.pullrequests.review_label = "title of a label that represents a pr ready for review"
21
+ config.handlers.pullrequests.review_label = "title of a label that represents a pr ready for merge"
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ ```
27
+ > @robot: give me something to review
28
+ ...
29
+
30
+ > @robot: summarize pull requests
31
+ ....
32
+ ```
33
+
34
+ ## License
35
+
36
+ [MIT](http://opensource.org/licenses/MIT)
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,99 @@
1
+ module Lita
2
+ module Handlers
3
+ class Pullrequests < Handler
4
+ config :access_token, type: String, required: true # bdaf08383ca76c58ab779ab8ff1ad7f6dc5bb3a4
5
+ config :repo, type: String, required: true
6
+ config :review_label, type: String, required: false
7
+ config :merge_label, type: String, required: false
8
+
9
+ route(/(pull request( me)?)|(give me something to review)/, :get_random_pr, command: true, help: {
10
+ "give me something to review" => "Shows you a random pull request that needs reviewing.",
11
+ "pull request (me)" => "Shows you a random pull request that needs reviewing."
12
+ })
13
+
14
+ route(/(summarize|all) pull requests/, :list_all_pull_requests, command: true, help: {
15
+ "(summarize|all) pull requests" => "Lists all pull requests that need action."
16
+ })
17
+
18
+
19
+ # Helper method
20
+ def truncate(str, truncate_at, options = {})
21
+ return dup unless str.length > truncate_at
22
+
23
+ omission = options[:omission] || '...'
24
+ length_with_room_for_omission = truncate_at - omission.length
25
+ stop = if options[:separator]
26
+ str.rindex(options[:separator], length_with_room_for_omission) || length_with_room_for_omission
27
+ else
28
+ length_with_room_for_omission
29
+ end
30
+
31
+ "#{str[0, stop]}#{omission}"
32
+ end
33
+
34
+ def fetch_pull_requests
35
+ url = "https://api.github.com/repos/#{config.repo}/issues"
36
+ req = http.get(url, access_token: config.access_token)
37
+ issues = MultiJson.load(req.body)
38
+ issues.select { |issue| issue["pull_request"] }
39
+ end
40
+
41
+ def get_random_pr(chat)
42
+ pr = pulls_that_need_reviews.sample
43
+ if pr
44
+ title, user, body = pr["title"], pr["user"]["login"], truncate(pr["body"], 200)
45
+ url = pr["pull_request"]["html_url"]
46
+
47
+ chat.reply %Q(
48
+ #{title} - #{user}
49
+ #{url}
50
+ -------------------
51
+ #{body}
52
+ )
53
+ else
54
+ chat.reply "No pull requests need reviews right now!"
55
+ end
56
+ end
57
+
58
+ def pulls_that_need_reviews
59
+ pulls = fetch_pull_requests
60
+ review_label = config.review_label || "Needs Review"
61
+
62
+ pulls.select do |pr|
63
+ pr["labels"].any? { |label| label["name"] == config.review_label }
64
+ end
65
+ end
66
+
67
+ def pulls_that_need_merging
68
+ pulls = fetch_pull_requests
69
+ merge_label = config.merge_label || "Ready To Merge"
70
+
71
+ pulls.select do |pr|
72
+ pr["labels"].any? { |label| label["name"] == config.merge_label }
73
+ end
74
+ end
75
+
76
+ def list_all_pull_requests(chat)
77
+ response = ":heavy_exclamation_mark: Pull Requests that need review:\n"
78
+
79
+ response += pulls_that_need_reviews.map do |pr|
80
+ title, user = pr["title"], pr["user"]["login"]
81
+ url = pr["pull_request"]["html_url"]
82
+ "- #{title} - #{user} \n #{url}"
83
+ end.join("\n")
84
+
85
+ response += "\n\n:white_check_mark: Pull Requests that are ready for merging:\n"
86
+
87
+ response += pulls_that_need_merging.map do |pr|
88
+ title, user = pr["title"], pr["user"]["login"]
89
+ url = pr["pull_request"]["html_url"]
90
+ "- #{title} - #{user} \n #{url}"
91
+ end.join("\n")
92
+
93
+ chat.reply(response)
94
+ end
95
+ end
96
+
97
+ Lita.register_handler(Pullrequests)
98
+ end
99
+ end
@@ -0,0 +1,7 @@
1
+ require "lita"
2
+
3
+ Lita.load_locales Dir[File.expand_path(
4
+ File.join("..", "..", "locales", "*.yml"), __FILE__
5
+ )]
6
+
7
+ require "lita/handlers/pullrequests"
@@ -0,0 +1,23 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "lita-pullrequests"
3
+ spec.version = "0.0.1"
4
+ spec.authors = ["Taylor Lapeyre"]
5
+ spec.email = ["taylorlapeyre@gmail.com"]
6
+ spec.description = %q{A Lita handler to help you keep track of your pull requests.}
7
+ spec.summary = %q{A Lita handler to help you keep track of your pull requests.}
8
+ spec.homepage = "https://github.com/taylorlapeyre/lita-pullrequests"
9
+ spec.license = "MIT"
10
+ spec.metadata = { "lita_plugin_type" => "handler" }
11
+
12
+ spec.files = `git ls-files`.split($/)
13
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.require_paths = ["lib"]
16
+
17
+ spec.add_runtime_dependency "lita", ">= 4.1"
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.3"
20
+ spec.add_development_dependency "rake"
21
+ spec.add_development_dependency "rack-test"
22
+ spec.add_development_dependency "rspec", ">= 3.0.0"
23
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,4 @@
1
+ en:
2
+ lita:
3
+ handlers:
4
+ pullrequests:
@@ -0,0 +1,29 @@
1
+ require "spec_helper"
2
+
3
+ describe Lita::Handlers::Pullrequests, lita_handler: true do
4
+ before do
5
+ Lita.config.handlers.pullrequests.access_token = "87084d4f3a658f2979a892b6cbf7be80b9949bcf"
6
+ Lita.config.handlers.pullrequests.repo = "taylorlapeyre/lita-pullrequests"
7
+ Lita.config.handlers.pullrequests.review_label = "Needs Review"
8
+ Lita.config.handlers.pullrequests.merge_label = "Ready To Merge"
9
+ end
10
+
11
+ it { is_expected.to route_command("pull request") }
12
+ it { is_expected.to route_command("pull request me") }
13
+ it { is_expected.to route_command("give me something to review") }
14
+ it { is_expected.to route_command("all pull requests") }
15
+ it { is_expected.to route_command("summarize pull requests") }
16
+
17
+ it "can respond with a random pull request" do
18
+ send_command("give me something to review")
19
+ expect(replies).to_not be_empty
20
+ expect(replies.last).to match /Example of a pull request ready for review/
21
+ end
22
+
23
+ it "can respond with all pull requests" do
24
+ send_command("summarize pull requests")
25
+ expect(replies).to_not be_empty
26
+ expect(replies.last).to match /Example of a pull request ready for merge/
27
+ expect(replies.last).to match /Example of a pull request ready for review/
28
+ end
29
+ end
@@ -0,0 +1,6 @@
1
+ require "lita-pullrequests"
2
+ require "lita/rspec"
3
+
4
+ # A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
5
+ # was generated with Lita 4, the compatibility mode should be left disabled.
6
+ Lita.version_3_compatibility_mode = false
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-pullrequests
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Taylor Lapeyre
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lita
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
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: rack-test
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 3.0.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 3.0.0
83
+ description: A Lita handler to help you keep track of your pull requests.
84
+ email:
85
+ - taylorlapeyre@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - LICENSE
93
+ - README.md
94
+ - Rakefile
95
+ - lib/lita-pullrequests.rb
96
+ - lib/lita/handlers/pullrequests.rb
97
+ - lita-pullrequests.gemspec
98
+ - locales/en.yml
99
+ - spec/lita/handlers/pullrequests_spec.rb
100
+ - spec/spec_helper.rb
101
+ homepage: https://github.com/taylorlapeyre/lita-pullrequests
102
+ licenses:
103
+ - MIT
104
+ metadata:
105
+ lita_plugin_type: handler
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.4.5
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: A Lita handler to help you keep track of your pull requests.
126
+ test_files:
127
+ - spec/lita/handlers/pullrequests_spec.rb
128
+ - spec/spec_helper.rb