lita-travis 0.1.2 → 0.2.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: e1072692efa24f4d512b195af6168c21e114716e
4
- data.tar.gz: ec64ee981f77169dc2bdb4d86dde83c6f9201f82
3
+ metadata.gz: 281766fc85013339455d961b7e50a8d474652096
4
+ data.tar.gz: 6344a3fdf756025ef3c61b0320b67cf4bfa3ac28
5
5
  SHA512:
6
- metadata.gz: 1181b5516fa27600b97c46a30e444ff557c099c64286b15e56eaf0722d77d66b706903400b9c0209edb1d48409ff24f74da9959b3b696f2fd96ba2ccad2d1592
7
- data.tar.gz: f226287b1396ac42cec81af17a0a4ee63373f10bb5fa35df272f3a61a4d62f0c74b7b8ca96a6577d8ffad6fe95e983bacec5cb66c5b286c4afb5b780ed80dd4b
6
+ metadata.gz: e58c006f89c8bc6fa830e06c89761a63e512e12c7df7767868c6494f67d96244ff729e26f757dcf1a65ba1924921a91972596b5526e9426aa8729983303ae8f9
7
+ data.tar.gz: bdafa443957cad73565a555b140f9d8e15f86b85990860379b48dbecf75b9254580917be1b7bf1e2fcacc5031d837f26e1e57a6085e33511af9d5f1f7f970108
data/README.md CHANGED
@@ -22,7 +22,8 @@ gem "lita-travis"
22
22
 
23
23
  ### Optional attributes
24
24
 
25
- * `repos` (Hash) - A map of repositories to allow notifications for and the chat rooms to post them in. The keys should be strings in the format "github_username/repository_name" and the values should be either a string room name or an array of string room names. Default: `{}`.
25
+ * `repos` (Hash) - A hash of repositories names and the chat rooms to post their notifications in. The keys should be strings in the format "github_username/repository_name" and the values should be either a string room name or an array of string room names. Default: `{}`.
26
+ * `default_rooms` (String, Array<String>) - A string room name or an array of string room names where notifications for repositories not explicitly specified in the `repos` hash should be sent. If `nil`, notifications for unknown repositories will be ignored. Default: `nil`.
26
27
 
27
28
  ### Example
28
29
 
@@ -30,9 +31,10 @@ gem "lita-travis"
30
31
  Lita.configure do |config|
31
32
  config.handlers.travis.token = "abcdefg123"
32
33
  config.handlers.travis.repos = {
33
- "username/repo1" => "#someroom",
34
- "username/repo2" => ["#someroom", "#someotherroom"]
34
+ "username/repo1" => "#repo1_team",
35
+ "username/repo2" => ["#repo2_team", "#other_team"]
35
36
  }
37
+ config.handlers.travis.default_rooms = "#engineering"
36
38
  end
37
39
  ```
38
40
 
@@ -9,6 +9,7 @@ module Lita
9
9
  def self.default_config(config)
10
10
  config.token = nil
11
11
  config.repos = {}
12
+ config.default_rooms = nil
12
13
  end
13
14
 
14
15
  http.post "/travis", :receive
@@ -26,9 +27,7 @@ module Lita
26
27
  begin
27
28
  MultiJson.load(json)
28
29
  rescue MultiJson::LoadError => e
29
- Lita.logger.error(
30
- "Could not parse JSON payload from Travis CI: #{e.message}"
31
- )
30
+ Lita.logger.error(t("parse_error", message: e.message))
32
31
  return
33
32
  end
34
33
  end
@@ -39,11 +38,16 @@ module Lita
39
38
 
40
39
  def notify_rooms(repo, data)
41
40
  rooms = rooms_for_repo(repo) or return
42
- message = <<-MSG.chomp
43
- [Travis CI] #{repo}: #{data["status_message"]} at \
44
- #{data["commit"][0...7]} (#{data["branch"]}) by #{data["committer_name"]} \
45
- - #{data["compare_url"]}
46
- MSG
41
+
42
+ message = t(
43
+ "message",
44
+ repo: repo,
45
+ status_message: data["status_message"],
46
+ commit: data["commit"][0...7],
47
+ branch: data["branch"],
48
+ committer_name: data["committer_name"],
49
+ compare_url: data["compare_url"]
50
+ )
47
51
 
48
52
  rooms.each do |room|
49
53
  target = Source.new(room: room)
@@ -53,13 +57,14 @@ module Lita
53
57
 
54
58
  def rooms_for_repo(repo)
55
59
  rooms = Lita.config.handlers.travis.repos[repo]
60
+ default_rooms = Lita.config.handlers.travis.default_rooms
56
61
 
57
62
  if rooms
58
63
  Array(rooms)
64
+ elsif default_rooms
65
+ Array(default_rooms)
59
66
  else
60
- Lita.logger.warn <<-WARNING.chomp
61
- Notification from Travis CI for unconfigured project: #{repo}
62
- WARNING
67
+ Lita.logger.warn(t("no_room_configured"), repo: repo)
63
68
  return
64
69
  end
65
70
  end
@@ -68,17 +73,12 @@ WARNING
68
73
  token = Lita.config.handlers.travis.token
69
74
 
70
75
  unless token
71
- Lita.logger.warn <<-WARNING.chomp
72
- Notification from Travis CI could not be validated because \
73
- Lita.config.handlers.token is not set.
74
- WARNING
76
+ Lita.logger.warn(t("no_token"))
75
77
  return
76
78
  end
77
79
 
78
80
  unless Digest::SHA2.hexdigest("#{repo}#{token}") == auth_hash
79
- Lita.logger.warn <<-WARNING.chomp
80
- Notification from Travis CI did not pass authentication.
81
- WARNING
81
+ Lita.logger.warn(t("auth_failed"), repo: repo)
82
82
  return
83
83
  end
84
84
 
@@ -89,3 +89,7 @@ Notification from Travis CI did not pass authentication.
89
89
  Lita.register_handler(Travis)
90
90
  end
91
91
  end
92
+
93
+ Lita.load_locales Dir[File.expand_path(
94
+ File.join("..", "..", "..", "..", "locales", "*.yml"), __FILE__
95
+ )]
data/lita-travis.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-travis"
3
- spec.version = "0.1.2"
3
+ spec.version = "0.2.0"
4
4
  spec.authors = ["Jimmy Cuadra"]
5
5
  spec.email = ["jimmy@jimmycuadra.com"]
6
6
  spec.description = %q{A Lita handler for receiving notifications from Travis CI.}
data/locales/en.yml ADDED
@@ -0,0 +1,15 @@
1
+ en:
2
+ lita:
3
+ handlers:
4
+ travis:
5
+ auth_failed: "Notification from Travis CI for %{repo} did not pass authentication."
6
+ parse_error: "Could not parse JSON payload from Travis CI: %{message}"
7
+ message: >-
8
+ [Travis CI] %{repo}: %{status_message} at %{commit} (%{branch}) by
9
+ %{committer_name} - %{compare_url}"
10
+ no_room_configured: >-
11
+ Notification from Travis CI for %{repo} ignored because no rooms were specified in the
12
+ config.repos hash, and no default rooms were specified in config.default_rooms.
13
+ no_token: >-
14
+ Notification from Travis CI could not be validated because Lita.config.handlers.token
15
+ is not set.
@@ -102,16 +102,33 @@ describe Lita::Handlers::Travis, lita_handler: true do
102
102
  end
103
103
  end
104
104
 
105
- context "without setting a value for the repo in config.repos" do
105
+ context "with only config.default_rooms set" do
106
106
  before do
107
107
  Lita.config.handlers.travis.token = "abc123"
108
+ Lita.config.handlers.travis.default_rooms = "#default"
108
109
  allow(request).to receive(:env).and_return(valid_env)
109
110
  allow(params).to receive(:[]).with("payload").and_return(valid_payload)
110
111
  end
111
112
 
112
- it "logs a warning that the request was invalid" do
113
+ it "sends a notification message to the applicable rooms" do
114
+ expect(robot).to receive(:send_message) do |target, message|
115
+ expect(target.room).to eq("#default")
116
+ expect(message).to include("[Travis CI]")
117
+ end
118
+ subject.receive(request, response)
119
+ end
120
+ end
121
+
122
+ context "without setting a value for the repo in config.repos and no default" do
123
+ before do
124
+ Lita.config.handlers.travis.token = "abc123"
125
+ allow(request).to receive(:env).and_return(valid_env)
126
+ allow(params).to receive(:[]).with("payload").and_return(valid_payload)
127
+ end
128
+
129
+ it "logs a warning that the request was ignored" do
113
130
  expect(Lita.logger).to receive(:warn) do |warning|
114
- expect(warning).to include("unconfigured project")
131
+ expect(warning).to include("ignored because no rooms were specified")
115
132
  end
116
133
  subject.receive(request, response)
117
134
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-travis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jimmy Cuadra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-26 00:00:00.000000000 Z
11
+ date: 2014-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita
@@ -110,6 +110,7 @@ files:
110
110
  - lib/lita-travis.rb
111
111
  - lib/lita/handlers/travis.rb
112
112
  - lita-travis.gemspec
113
+ - locales/en.yml
113
114
  - spec/lita/handlers/travis_spec.rb
114
115
  - spec/spec_helper.rb
115
116
  homepage: https://github.com/jimmycuadra/lita-travis