lita-reviewme 0.3.1 → 0.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 65fb6f44ca8287b695119bbfc6cb40740c101891
4
- data.tar.gz: a3cd8f88df4ac677ec17b61c5be16f90d4529178
3
+ metadata.gz: 314ab18b6586a16c2e317fbfb50ca9e1f3b7c945
4
+ data.tar.gz: 7fbc8906b146f332eac6e2330999240dccb7948e
5
5
  SHA512:
6
- metadata.gz: d679f71503a9785d8d7df87ae9a8ee32ebcb1beac9cf028fec9f5f07458334753af167a89faec34aa09d5520e1ba82f39d21da69af6ec2fb557283350023e244
7
- data.tar.gz: 3102217b8e66ab74496542dd93643e65431c4067525ab36f58467cb6e21856755b2b5d3871c0719274fa3fed9a935f14afe56dd4abb896132721a5a058db7da7
6
+ metadata.gz: b1f6090dd447abfbdd171e99e25b65cadadf33c277ecc3ff8f27da70fcf98effd75c2a5474b1de87ed1c6323641d0affdcaa69e4b7f2c43a7579cd532a943b3a
7
+ data.tar.gz: 74dc37d914c77454f1637dacf758aa3ccd8cd11ffe1235e4b795ff68ca305b4ff290d5e6a2710e8c01bb1de5ee03f0a475c36c05b260c2d1bb6fdbd5783ce829
data/CHANGELOG.md CHANGED
@@ -4,6 +4,14 @@ This project adheres to [Semantic Versioning](http://semver.org/).
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.4.0] - 2017-02-10
8
+
9
+ ### Added
10
+ - [#50] - Allow custom GitHub messages via plugin config
11
+
12
+ ### Fixed
13
+ - [#51] - Avoid empty GitHub message when there are no reviewers
14
+
7
15
  ## [0.3.1] - 2016-02-10
8
16
 
9
17
  ### Changed
@@ -34,7 +42,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
34
42
  ### Added
35
43
  - Start versioning gem.
36
44
 
37
- [Unreleased]: https://github.com/iamvery/lita-reviewme/compare/v0.3.1...HEAD
45
+ [Unreleased]: https://github.com/iamvery/lita-reviewme/compare/v0.4.0...HEAD
46
+ [0.4.0]: https://github.com/iamvery/lita-reviewme/compare/v0.3.1...v0.4.0
38
47
  [0.3.1]: https://github.com/iamvery/lita-reviewme/compare/v0.3.0...v0.3.1
39
48
  [0.3.0]: https://github.com/iamvery/lita-reviewme/compare/v0.2.0...v0.3.0
40
49
  [0.2.0]: https://github.com/iamvery/lita-reviewme/compare/v0.1.0...v0.2.0
data/README.md CHANGED
@@ -26,6 +26,32 @@ Regardless the user must have access to the repo being reviewed, and the token m
26
26
  config.handlers.reviewme.github_access_token = ENV["GITHUB_ACCESS_TOKEN"]
27
27
  ```
28
28
 
29
+ The default message that is posted on GitHub pull request is `:eyes: @<reviewer>`.
30
+ The message can be customized via `config.handlers.reviewme.github_comment_template`.
31
+ If you would like the reviewer to be notified, be sure add `%{reviewer}` to your string.
32
+
33
+ ```
34
+ # your bot's lita_config.rb
35
+ # Add %{reviewer} for the user to be tagged and notified on GitHub
36
+ config.handlers.reviewme.github_comment_template = "Hey %{reviewer}, check it out! :tada:"
37
+ ```
38
+
39
+ Additionally, you can assign a lambda if you would like more finite control of what GitHub comments are sent.
40
+ Note that `reviewer` and `pull_request` are required arguments.
41
+
42
+ ```
43
+ # your bot's lita_config.rb
44
+ #
45
+ # Note:
46
+ # `reviewer` is a username string without the '@'
47
+ # `pull_request` is a hash object from GitHub API.
48
+
49
+ config.handlers.reviewme.github_comment_template = lamda do |reviewer, pull_request|
50
+ title = pull_request[:title]
51
+ "Hey #{reviewer}, check out my new PR called #{title} :tada:"
52
+ end
53
+ ```
54
+
29
55
  ## Usage
30
56
 
31
57
  ### See who is in the review rotation.
@@ -63,6 +89,8 @@ to the repository.
63
89
  >
64
90
  > **Nerdbot** iamvery should be on it...
65
91
 
92
+ If your Github user is different from your chat user, you might tweak your notification settings to include your Github username.
93
+
66
94
  ## License
67
95
 
68
96
  [MIT](http://opensource.org/licenses/MIT)
@@ -4,8 +4,10 @@ module Lita
4
4
  module Handlers
5
5
  class Reviewme < Handler
6
6
  REDIS_LIST = "reviewers"
7
+ DEFAULT_GITHUB_MSG = ":eyes: %{reviewer}"
7
8
 
8
9
  config :github_access_token
10
+ config :github_comment_template
9
11
 
10
12
  route(
11
13
  /add (.+) to reviews/i,
@@ -96,7 +98,8 @@ module Lita
96
98
  rescue Octokit::Error
97
99
  response.reply("Unable to check who issued the pull request. Sorry if you end up being assigned your own PR!")
98
100
  end
99
- comment = github_comment(reviewer)
101
+ return response.reply('Sorry, no reviewers found') unless reviewer
102
+ comment = github_comment(reviewer, pull_request)
100
103
 
101
104
  begin
102
105
  github_client.add_comment(repo, id, comment)
@@ -119,8 +122,14 @@ module Lita
119
122
  ns_redis(room.id).rpoplpush(REDIS_LIST, REDIS_LIST)
120
123
  end
121
124
 
122
- def github_comment(reviewer)
123
- ":eyes: @#{reviewer}"
125
+ def github_comment(reviewer, pull_request)
126
+ msg = config.github_comment_template || DEFAULT_GITHUB_MSG
127
+
128
+ if msg.respond_to?(:call) # its a proc
129
+ msg.call(reviewer, pull_request)
130
+ else
131
+ msg % { reviewer: "@#{reviewer}" }
132
+ end
124
133
  end
125
134
 
126
135
  def github_client
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-reviewme"
3
- spec.version = "0.3.1"
3
+ spec.version = "0.4.0"
4
4
  spec.authors = ["Jay Hayes"]
5
5
  spec.email = ["ur@iamvery.com"]
6
6
  spec.description = %q{A lita handler that helps with code review}
@@ -56,7 +56,7 @@ describe Lita::Handlers::Reviewme, lita_handler: true do
56
56
  let(:repo) { "gh_user/repo" }
57
57
  let(:id) { "123" }
58
58
  let(:pr) do
59
- OpenStruct.new({ user: OpenStruct.new({ login: "pr-owner" }) })
59
+ OpenStruct.new(user: OpenStruct.new(login: "pr-owner"), title: "PR title")
60
60
  end
61
61
 
62
62
  before do
@@ -65,6 +65,10 @@ describe Lita::Handlers::Reviewme, lita_handler: true do
65
65
  .and_return(pr)
66
66
  end
67
67
 
68
+ after do
69
+ subject.config.github_comment_template = nil
70
+ end
71
+
68
72
  it "posts comment on github" do
69
73
  expect_any_instance_of(Octokit::Client).to receive(:add_comment)
70
74
  .with(repo, id, ":eyes: @iamvery")
@@ -75,6 +79,47 @@ describe Lita::Handlers::Reviewme, lita_handler: true do
75
79
  expect(reply).to eq("iamvery should be on it...")
76
80
  end
77
81
 
82
+ it "does NOT post comment on github when there are no reviewers" do
83
+ expect_any_instance_of(Octokit::Client).to_not receive(:add_comment)
84
+
85
+ send_command("review https://github.com/#{repo}/pull/#{id}")
86
+
87
+ expect(reply).to eq("Sorry, no reviewers found")
88
+ end
89
+
90
+ it "posts custom comments on github if specified" do
91
+ custom_msg = ":tada: %{reviewer} this is awesome"
92
+ expected_msg = ":tada: @iamvery this is awesome"
93
+ subject.config.github_comment_template = custom_msg
94
+
95
+ expect_any_instance_of(Octokit::Client).to receive(:add_comment)
96
+ .with(repo, id, expected_msg)
97
+
98
+ send_command("add iamvery to reviews")
99
+ send_command("review https://github.com/#{repo}/pull/#{id}")
100
+
101
+ expect(reply).to eq("iamvery should be on it...")
102
+ end
103
+
104
+ it "executes a proc if specified in `config.github_comment_template`" do
105
+ my_lambda = lambda do |reviewer, pull_request|
106
+ title = pull_request[:title]
107
+ "hey @#{reviewer}, this is from a lambda! :tada: #{title}"
108
+ end
109
+
110
+ expected_msg = "hey @iamvery, this is from a lambda! :tada: #{pr.title}"
111
+
112
+ subject.config.github_comment_template = my_lambda
113
+
114
+ expect_any_instance_of(Octokit::Client).to receive(:add_comment)
115
+ .with(repo, id, expected_msg)
116
+
117
+ send_command("add iamvery to reviews")
118
+ send_command("review https://github.com/#{repo}/pull/#{id}")
119
+
120
+ expect(reply).to eq("iamvery should be on it...")
121
+ end
122
+
78
123
  it "skips assigning to the GitHub PR owner" do
79
124
  expect_any_instance_of(Octokit::Client).to receive(:pull_request)
80
125
  .with(repo, id).and_return(pr)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-reviewme
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jay Hayes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-10 00:00:00.000000000 Z
11
+ date: 2017-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
141
  version: '0'
142
142
  requirements: []
143
143
  rubyforge_project:
144
- rubygems_version: 2.4.5.1
144
+ rubygems_version: 2.5.2
145
145
  signing_key:
146
146
  specification_version: 4
147
147
  summary: A lita handler that helps with code review