lita-jenkins 0.0.2 → 0.0.3
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 +4 -4
- data/README.md +8 -1
- data/lib/lita/handlers/jenkins.rb +57 -10
- data/lita-jenkins.gemspec +1 -1
- data/spec/lita/handlers/jenkins_spec.rb +28 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dcffef9c4fb103a261e3c90e6fdfa19274cf6efc
|
4
|
+
data.tar.gz: 60a9bbe4ef16289c48a21756418a72fec9ea6a6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ab1d5548358ab37e304e3470f506c7a9950acdf4883bae95b5af3ba15d7a8c2ecccf8f1151ac2edd375c8da25b907dcf95624824d8c42e2e8d3570f40595fa7
|
7
|
+
data.tar.gz: e39bd4c67170ba91f49f2668aaff6902e65c380e8713faff672b600876f21d701f26fee977943c8ea545072a456cf0b6badea5080321a06bc196f1d6c2b49422
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# lita-jenkins
|
2
2
|
|
3
|
+
[](https://travis-ci.org/daniely/lita-jenkins)
|
4
|
+
|
3
5
|
Interact with your Jenkins CI server
|
4
6
|
|
5
7
|
## Installation
|
@@ -16,11 +18,16 @@ gem "lita-jenkins"
|
|
16
18
|
|
17
19
|
* `url` (String) - Your Jenkins CI url. Default: `nil`.
|
18
20
|
|
21
|
+
### Optional attributes
|
22
|
+
|
23
|
+
* `auth` (String) - Your Jenkins CI username and password. Default: `nil`.
|
24
|
+
|
19
25
|
### Example
|
20
26
|
|
21
27
|
``` ruby
|
22
28
|
Lita.configure do |config|
|
23
|
-
config.handlers.jenkins.url
|
29
|
+
config.handlers.jenkins.url = "http://test.com"
|
30
|
+
config.handlers.jenkins.auth = "user1:sekret"
|
24
31
|
end
|
25
32
|
```
|
26
33
|
|
@@ -1,38 +1,85 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'base64'
|
2
3
|
|
3
4
|
module Lita
|
4
5
|
module Handlers
|
5
6
|
class Jenkins < Handler
|
7
|
+
class << self
|
8
|
+
attr_accessor :jobs
|
9
|
+
end
|
10
|
+
|
6
11
|
def self.default_config(config)
|
7
12
|
config.url = nil
|
13
|
+
self.jobs = {}
|
8
14
|
end
|
9
15
|
|
10
16
|
route /j(?:enkins)? list( (.+))?/i, :jenkins_list, command: true, help: {
|
11
|
-
'
|
17
|
+
'jenkins list <filter>' => 'lists Jenkins jobs'
|
12
18
|
}
|
13
19
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
20
|
+
route /j(?:enkins)? b(?:uild)? (\d+)/i, :jenkins_build, command: true, help: {
|
21
|
+
'jenkins b(uild) <job_id>' => 'builds the job specified by job_id. List jobs to get ID.'
|
22
|
+
}
|
23
|
+
|
24
|
+
def jenkins_build(response)
|
25
|
+
if job = jobs[response.matches.last.last.to_i - 1]
|
26
|
+
url = Lita.config.handlers.jenkins.url
|
27
|
+
path = "#{url}/job/#{job['name']}/build"
|
18
28
|
|
19
|
-
|
20
|
-
|
21
|
-
|
29
|
+
http_resp = http.post(path) do |req|
|
30
|
+
req.headers = headers
|
31
|
+
end
|
22
32
|
|
23
|
-
|
33
|
+
if http_resp.status == 201
|
34
|
+
response.reply "(#{http_resp.status}) Build started for #{job['name']} #{url}/job/#{job['name']}"
|
35
|
+
else
|
36
|
+
response.reply http_resp.body
|
37
|
+
end
|
38
|
+
else
|
39
|
+
response.reply "I couldn't find that job. Try `jenkins list` to get a list."
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def jenkins_list(response)
|
44
|
+
filter = response.matches.first.last
|
45
|
+
reply = ''
|
46
|
+
|
47
|
+
jobs.each_with_index do |job, i|
|
24
48
|
job_name = job['name']
|
25
49
|
state = color_to_state(job['color'])
|
26
50
|
text_to_check = state + job_name
|
27
51
|
|
28
|
-
reply <<
|
52
|
+
reply << format_job(i, state, job_name) if filter_match(filter, text_to_check)
|
29
53
|
end
|
30
54
|
|
31
55
|
response.reply reply
|
32
56
|
end
|
33
57
|
|
58
|
+
def headers
|
59
|
+
headers = {}
|
60
|
+
if auth = Lita.config.handlers.jenkins.auth
|
61
|
+
headers["Authorization"] = "Basic #{Base64.encode64(auth).chomp}"
|
62
|
+
end
|
63
|
+
headers
|
64
|
+
end
|
65
|
+
|
66
|
+
def jobs
|
67
|
+
if self.class.jobs.empty?
|
68
|
+
path = "#{Lita.config.handlers.jenkins.url}/api/json"
|
69
|
+
api_response = http.get(path) do |req|
|
70
|
+
req.headers = headers
|
71
|
+
end
|
72
|
+
self.class.jobs = JSON.parse(api_response.body)["jobs"]
|
73
|
+
end
|
74
|
+
self.class.jobs
|
75
|
+
end
|
76
|
+
|
34
77
|
private
|
35
78
|
|
79
|
+
def format_job(i, state, job_name)
|
80
|
+
"[#{i+1}] #{state} #{job_name}\n"
|
81
|
+
end
|
82
|
+
|
36
83
|
def color_to_state(text)
|
37
84
|
case text
|
38
85
|
when /disabled/
|
data/lita-jenkins.gemspec
CHANGED
@@ -25,6 +25,7 @@ describe Lita::Handlers::Jenkins, lita_handler: true do
|
|
25
25
|
|
26
26
|
before do
|
27
27
|
allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(response)
|
28
|
+
allow_any_instance_of(Faraday::Connection).to receive(:post).and_return(response)
|
28
29
|
end
|
29
30
|
|
30
31
|
it 'lists all jenkins jobs' do
|
@@ -40,5 +41,32 @@ describe Lita::Handlers::Jenkins, lita_handler: true do
|
|
40
41
|
send_command('jenkins list fail')
|
41
42
|
expect(replies.last).to eq("[2] FAIL deploy\n[4] FAIL website\n")
|
42
43
|
end
|
44
|
+
|
45
|
+
it 'build job id' do
|
46
|
+
allow(response).to receive(:status).and_return(201)
|
47
|
+
allow(response).to receive(:body).and_return(api_response)
|
48
|
+
send_command('jenkins b 2')
|
49
|
+
expect(replies.last).to eq("(201) Build started for deploy /job/deploy")
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'build job bad id' do
|
53
|
+
allow(response).to receive(:status).and_return(201)
|
54
|
+
allow(response).to receive(:body).and_return(api_response)
|
55
|
+
send_command('jenkins b 99')
|
56
|
+
expect(replies.last).to eq("I couldn't find that job. Try `jenkins list` to get a list.")
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'build job error 500 response' do
|
60
|
+
allow(response).to receive(:status).and_return(500)
|
61
|
+
allow(response).to receive(:body).and_return(api_response)
|
62
|
+
send_command('jenkins b 2')
|
63
|
+
expect(replies.last).to eq(api_response)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'build job error 500 response' do
|
67
|
+
Lita.config.handlers.jenkins.auth = "foo:bar"
|
68
|
+
return_value = Lita::Handlers::Jenkins.new.headers
|
69
|
+
expect(return_value.inspect).to eq("{\"Authorization\"=>\"Basic Zm9vOmJhcg==\"}")
|
70
|
+
end
|
43
71
|
end
|
44
72
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-jenkins
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Yoon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|