lita-jenkins 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3a7b4cbd688dd19ab921e69b1869f8f28e398c65
4
- data.tar.gz: 2f0b774fed8af11a8b2bdc5cfd867dce41b346f4
3
+ metadata.gz: f1a54f7b723546940928e9bef5ce8c5dfa1d94da
4
+ data.tar.gz: 632b837dece082dd95c84e04d7946813f5db6370
5
5
  SHA512:
6
- metadata.gz: 1ca56b7f2ec44be8f1947edbee6aff6c76491abf99f4a1621cbba8924938a5cabeb323ad2bd0ce927b70b3518998e40d97989a676816f3d6451c588c0a485ee1
7
- data.tar.gz: 2a6c6a3e37622f112f4dc89b92df3ba0ab7b859143c4a5489488defdcd125e2f604afda95ddbee0eab00b68783110c2a7c3f51787c66c07843276e4df2585617
6
+ metadata.gz: 96f618e1cd4d601018fd51542958a23d31a65445a5b44d3b6269c1f781146c0d1d586f4eec2170a40474c0ed9956a6db978f108a8bc2324d2b3f64fe0fa0968c
7
+ data.tar.gz: 6d77af3b63676f3649da534c792b5d785f7280de712a2e935a95a5ddee9082b24a64b083761d73855a09f4bec1402b0c119a462a92202b32084018d472148e86
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # lita-jenkins
2
2
 
3
- TODO: Add a description of the plugin.
3
+ Interact with your Jenkins CI server
4
4
 
5
5
  ## Installation
6
6
 
@@ -12,11 +12,32 @@ gem "lita-jenkins"
12
12
 
13
13
  ## Configuration
14
14
 
15
- TODO: Describe any configuration attributes the plugin exposes.
15
+ ### Required attributes
16
+
17
+ * `url` (String) - Your Jenkins CI url. Default: `nil`.
18
+
19
+ ### Example
20
+
21
+ ``` ruby
22
+ Lita.configure do |config|
23
+ config.handlers.jenkins.url = "http://test.com"
24
+ end
25
+ ```
16
26
 
17
27
  ## Usage
18
28
 
19
- TODO: Describe the plugin's features and how to use them.
29
+ ```
30
+ [You] Lita: jenkins list
31
+ [Lita]
32
+ [1] DISA chef_converge
33
+ [2] SUCC deploy
34
+ [3] FAIL build-all
35
+
36
+ [You] Lita: jenkins list fail
37
+ [Lita]
38
+ [3] FAIL build-all
39
+ ```
40
+ ```
20
41
 
21
42
  ## License
22
43
 
@@ -1,12 +1,51 @@
1
+ require 'json'
2
+
1
3
  module Lita
2
4
  module Handlers
3
5
  class Jenkins < Handler
6
+ def self.default_config(config)
7
+ config.url = nil
8
+ end
9
+
4
10
  route /j(?:enkins)? list( (.+))?/i, :jenkins_list, command: true, help: {
5
11
  'jekins list <filter>' => 'lists Jenkins jobs'
6
12
  }
7
13
 
8
14
  def jenkins_list(response)
9
- filter = response.matches.first.first.downcase
15
+ url = Lita.config.handlers.jenkins.url
16
+ path = "#{url}/api/json"
17
+ filter = response.matches.first.last
18
+
19
+ api_response = http.get(path)
20
+ parsed_response = JSON.parse(api_response.body)
21
+ reply = ''
22
+
23
+ parsed_response['jobs'].each_with_index do |job, i|
24
+ job_name = job['name']
25
+ state = color_to_state(job['color'])
26
+ text_to_check = state + job_name
27
+
28
+ reply << "[#{i+1}] #{state} #{job_name}\n" if filter_match(filter, text_to_check)
29
+ end
30
+
31
+ response.reply reply
32
+ end
33
+
34
+ private
35
+
36
+ def color_to_state(text)
37
+ case text
38
+ when /disabled/
39
+ 'DISA'
40
+ when /red/
41
+ 'FAIL'
42
+ else
43
+ 'SUCC'
44
+ end
45
+ end
46
+
47
+ def filter_match(filter, text)
48
+ text.match(/#{filter}/i)
10
49
  end
11
50
  end
12
51
 
data/lita-jenkins.gemspec CHANGED
@@ -1,8 +1,8 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-jenkins"
3
- spec.version = "0.0.1"
3
+ spec.version = "0.0.2"
4
4
  spec.authors = ["Daniel Yoon"]
5
- spec.email = ["robotright@gmail.com"]
5
+ spec.email = ["daniel.kiros@gmail.com"]
6
6
  spec.description = %q{Interact with Jenkins CI server.}
7
7
  spec.summary = %q{Interact with Jenkins CI server.}
8
8
  spec.homepage = "https://github.com/daniely/lita-jenkins.git"
@@ -3,4 +3,42 @@ require "spec_helper"
3
3
  describe Lita::Handlers::Jenkins, lita_handler: true do
4
4
  it { routes_command('jenkins list').to(:jenkins_list) }
5
5
  it { routes_command('jenkins list filter').to(:jenkins_list) }
6
+
7
+ describe '#jenkins list' do
8
+ let(:response) { double("Faraday::Response") }
9
+ let(:api_response) { %{
10
+ {"assignedLabels":[{}],"mode":"NORMAL","nodeDescription":"the master Jenkins node",
11
+ "nodeName":"","numExecutors":4,"description":null,"jobs":[
12
+ {"name":"chef_converge", "url":"http://test.com/job/chef_converge/","color":"disabled"},
13
+ {"name":"deploy", "url":"http://test.com/job/deploy/","color":"red"},
14
+ {"name":"build-all", "url":"http://test.com/job/build-all/","color":"blue"},
15
+ {"name":"website", "url":"http://test.com/job/website/","color":"red"}],
16
+ "overallLoad":{},
17
+ "primaryView":{"name":"All","url":"http://test.com/"},"quietingDown":false,"slaveAgentPort":8090,"unlabeledLoad":{},
18
+ "useCrumbs":false,"useSecurity":true,"views":[
19
+ {"name":"All","url":"http://test.com/"},
20
+ {"name":"Chef","url":"http://test.com/view/Chef/"},
21
+ {"name":"Deploy","url":"http://test.com/view/Deploy/"},
22
+ {"name":"Status","url":"http://test.com/view/Status/"},
23
+ {"name":"deploy-pipeline","url":"http://test.com/view/deploy-pipeline/"}]}
24
+ } }
25
+
26
+ before do
27
+ allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(response)
28
+ end
29
+
30
+ it 'lists all jenkins jobs' do
31
+ allow(response).to receive(:status).and_return(200)
32
+ allow(response).to receive(:body).and_return(api_response)
33
+ send_command('jenkins list')
34
+ expect(replies.last).to eq("[1] DISA chef_converge\n[2] FAIL deploy\n[3] SUCC build-all\n[4] FAIL website\n")
35
+ end
36
+
37
+ it 'filters jobs' do
38
+ allow(response).to receive(:status).and_return(200)
39
+ allow(response).to receive(:body).and_return(api_response)
40
+ send_command('jenkins list fail')
41
+ expect(replies.last).to eq("[2] FAIL deploy\n[4] FAIL website\n")
42
+ end
43
+ end
6
44
  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.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Yoon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-09 00:00:00.000000000 Z
11
+ date: 2014-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita
@@ -96,7 +96,7 @@ dependencies:
96
96
  version: '0'
97
97
  description: Interact with Jenkins CI server.
98
98
  email:
99
- - robotright@gmail.com
99
+ - daniel.kiros@gmail.com
100
100
  executables: []
101
101
  extensions: []
102
102
  extra_rdoc_files: []