lita-snap-ci 1.0.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 +7 -0
- data/.gitignore +19 -0
- data/Gemfile +3 -0
- data/README.md +87 -0
- data/Rakefile +6 -0
- data/lib/lita-snap-ci.rb +12 -0
- data/lib/lita/handlers/snap_ci.rb +45 -0
- data/lib/snap_ci.rb +1 -0
- data/lib/snap_ci/http.rb +20 -0
- data/lib/snap_ci/parser.rb +16 -0
- data/lib/snap_ci/project.rb +63 -0
- data/lib/snap_ci/project_list.rb +23 -0
- data/lita-snap-ci.gemspec +25 -0
- data/locales/en.yml +10 -0
- data/spec/fixtures/api_development.json +107 -0
- data/spec/fixtures/api_master.json +127 -0
- data/spec/fixtures/api_staging.json +107 -0
- data/spec/fixtures/front_master.json +78 -0
- data/spec/fixtures/front_staging.json +81 -0
- data/spec/fixtures/pipelines.json +1 -0
- data/spec/fixtures/snap-ci_report.message +12 -0
- data/spec/fixtures/snap-ci_status.message +4 -0
- data/spec/fixtures/websites_develop.json +107 -0
- data/spec/fixtures/websites_master.json +101 -0
- data/spec/lita/handlers/snap_ci_spec.rb +39 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/support/config.rb +21 -0
- data/spec/support/fixture.rb +37 -0
- data/templates/.gitkeep +0 -0
- metadata +185 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: ddb586b39cafbd3a068d285725ef323ca321e38b
|
|
4
|
+
data.tar.gz: 724efdc826a385ba9daed8599aa803f3f8d4411d
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: dcb9956c0ca47defa2bdc96144e7fd2f0f481a27230e46979f76860da8f5dac9fe967182089ea6e2393649f528bcb366ddea5b19bca799f685785ed69ffccc80
|
|
7
|
+
data.tar.gz: ee38d9a0f1cab171177995fce11b7f9302f5b99a353a46105ee19ff8cd0d06c3bb456abf13a9a0db754a04a6a1b64480a0f52cd22ba04cf7bafdad0b4e7d2d2b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# lita-snap-ci
|
|
2
|
+
|
|
3
|
+
Reports from [snap-ci]('https://snap-ci.com/'). [](https://snap-ci.com/groteck/lita-snap-ci/branch/master)
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add lita-snap-ci to your Lita instance's Gemfile:
|
|
8
|
+
|
|
9
|
+
``` ruby
|
|
10
|
+
gem "lita-snap-ci"
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Configuration
|
|
14
|
+
|
|
15
|
+
Information that you need:
|
|
16
|
+
|
|
17
|
+
* [api-key from Snap-ci](https://snap-ci.com/settings/api_key)
|
|
18
|
+
* snap-ci username
|
|
19
|
+
* projects info
|
|
20
|
+
|
|
21
|
+
Configure your `lita-config.rb`.
|
|
22
|
+
|
|
23
|
+
Example:
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
config.handlers.snap_ci.user = "snapUser"
|
|
27
|
+
config.handlers.snap_ci.token = "Snap-ci-api-key"
|
|
28
|
+
config.handlers.snap_ci.projects = [
|
|
29
|
+
{
|
|
30
|
+
owner: 'oneorg',
|
|
31
|
+
repository: 'api',
|
|
32
|
+
branches: ['development', 'staging', 'master']
|
|
33
|
+
},{
|
|
34
|
+
owner: 'oneorg',
|
|
35
|
+
repository: 'front',
|
|
36
|
+
branches: ['staging', 'master']
|
|
37
|
+
},{
|
|
38
|
+
owner: 'otherorg',
|
|
39
|
+
repository: 'websites',
|
|
40
|
+
branches: ['develop' , 'master']
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Usage
|
|
46
|
+
|
|
47
|
+
### Display the status of your repositories.
|
|
48
|
+
|
|
49
|
+
Chat input:
|
|
50
|
+
|
|
51
|
+
`snap-ci report`
|
|
52
|
+
|
|
53
|
+
Chat output:
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
Project: otherorg/websites:
|
|
57
|
+
develop: failed (Test: failed)
|
|
58
|
+
master: failed (Test: failed)
|
|
59
|
+
|
|
60
|
+
Project: oneorg/front:
|
|
61
|
+
staging: passed (TEST: passed, deploy_staging: passed)
|
|
62
|
+
master: passed (TEST: passed, deploy_prod: passed)
|
|
63
|
+
|
|
64
|
+
Project: oneorg/api:
|
|
65
|
+
development: passed (Integration: passed, Brakeman: passed)
|
|
66
|
+
staging: passed (Integration: passed, deploy_staging: passed)
|
|
67
|
+
master: passed (FastFeedback: passed, Integration: passed, deploy_prod: unknown)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Display the status of one repository.
|
|
71
|
+
|
|
72
|
+
Chat input:
|
|
73
|
+
|
|
74
|
+
`snap-ci project api` or `snap-ci project oneorg/api`
|
|
75
|
+
|
|
76
|
+
Chat output:
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
Project: oneorg/api:
|
|
80
|
+
development: passed (Integration: passed, Brakeman: passed)
|
|
81
|
+
staging: passed (Integration: passed, deploy_staging: passed)
|
|
82
|
+
master: passed (FastFeedback: passed, Integration: passed, deploy_prod: unknown)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
lita-snap-ci is released under the [MIT License](http://www.opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/lib/lita-snap-ci.rb
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require "lita"
|
|
2
|
+
|
|
3
|
+
Lita.load_locales Dir[File.expand_path(
|
|
4
|
+
File.join("..", "..", "locales", "*.yml"), __FILE__
|
|
5
|
+
)]
|
|
6
|
+
|
|
7
|
+
require "lita/handlers/snap_ci"
|
|
8
|
+
|
|
9
|
+
Lita::Handlers::SnapCi.template_root File.expand_path(
|
|
10
|
+
File.join("..", "..", "templates"),
|
|
11
|
+
__FILE__
|
|
12
|
+
)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require_relative '../../snap_ci'
|
|
2
|
+
|
|
3
|
+
module Lita
|
|
4
|
+
module Handlers
|
|
5
|
+
class SnapCi < Handler
|
|
6
|
+
config :user, type: String, required: true
|
|
7
|
+
config :token, type: String, required: true
|
|
8
|
+
config :projects, type: Array, required: true
|
|
9
|
+
|
|
10
|
+
route(/^snap-ci\s+report$/,
|
|
11
|
+
:all_projects,
|
|
12
|
+
help: { t('report.command') => t('report.desc') })
|
|
13
|
+
|
|
14
|
+
def all_projects(response)
|
|
15
|
+
response.reply ::SnapCi::ProjectList.new(config).to_message
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
route(/^snap-ci\s+project\s+(.+)$/,
|
|
19
|
+
:project,
|
|
20
|
+
help: { t('project.command') => t('project.desc') })
|
|
21
|
+
|
|
22
|
+
# Return the first match, for an exact match use owner/repository format
|
|
23
|
+
def project(response)
|
|
24
|
+
format = if response.args[1].slice("/").nil?
|
|
25
|
+
:repo
|
|
26
|
+
else
|
|
27
|
+
:owner
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
project_arg = config.projects.detect do |project|
|
|
31
|
+
if format == :owner
|
|
32
|
+
project[:owner] == response.args[1].partition("/").first &&
|
|
33
|
+
project[:repository] == response.args[1].partition("/").last
|
|
34
|
+
else
|
|
35
|
+
project[:repository] == response.args[1]
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
response.reply ::SnapCi::Project.new(project_arg, config).to_message
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
Lita.register_handler(self)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
data/lib/snap_ci.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Dir[File.dirname(__FILE__) + '/snap_ci/**/*.rb'].each { |file| require file }
|
data/lib/snap_ci/http.rb
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require 'faraday'
|
|
2
|
+
|
|
3
|
+
module SnapCi
|
|
4
|
+
class Http
|
|
5
|
+
URL = 'https://api.snap-ci.com'
|
|
6
|
+
|
|
7
|
+
def initialize(config)
|
|
8
|
+
@http = Faraday.new(url: URL) do |conection|
|
|
9
|
+
conection.basic_auth(config.user, config.token)
|
|
10
|
+
conection.headers['Content-Type'] = 'text/plain'
|
|
11
|
+
conection.headers['Accept'] = 'application/vnd.snap-ci.com.v1+json'
|
|
12
|
+
conection.adapter Faraday.default_adapter
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def get(parameters = '')
|
|
17
|
+
@http.get(parameters)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'multi_json'
|
|
2
|
+
|
|
3
|
+
module SnapCi
|
|
4
|
+
class Parser
|
|
5
|
+
def initialize(response)
|
|
6
|
+
@pipeline = MultiJson.load(response.body)['_embedded']['pipelines'].last
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def to_parameters
|
|
10
|
+
{
|
|
11
|
+
status: @pipeline['result'],
|
|
12
|
+
steps: @pipeline['stages']
|
|
13
|
+
}
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
require_relative 'http'
|
|
2
|
+
require_relative 'parser'
|
|
3
|
+
|
|
4
|
+
module SnapCi
|
|
5
|
+
class Project
|
|
6
|
+
attr_reader :owner, :repository, :branches
|
|
7
|
+
|
|
8
|
+
def initialize(args, config)
|
|
9
|
+
@owner = args[:owner]
|
|
10
|
+
@repository = args[:repository]
|
|
11
|
+
@branches = args[:branches]
|
|
12
|
+
@http = Http.new(config)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def to_message
|
|
16
|
+
"Project: #{owner}/#{repository}:\n" + pipelines_to_s
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def fetch_pipelines
|
|
22
|
+
pipelines = {}
|
|
23
|
+
mutex = Mutex.new
|
|
24
|
+
|
|
25
|
+
uris.map do |uri|
|
|
26
|
+
Thread.new do
|
|
27
|
+
pipeline = @http.get(uri[:path])
|
|
28
|
+
mutex.synchronize { pipelines[uri[:branch]] = pipeline }
|
|
29
|
+
end
|
|
30
|
+
end.each(&:join)
|
|
31
|
+
|
|
32
|
+
pipelines
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def pipelines_to_s
|
|
36
|
+
pipelines = []
|
|
37
|
+
|
|
38
|
+
fetch_pipelines.each do |branch, pipeline|
|
|
39
|
+
parameters = Parser.new(pipeline).to_parameters
|
|
40
|
+
pipelines << pipeline_to_s(branch, parameters)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
pipelines.join("\n")
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def pipeline_to_s(branch, parameters)
|
|
47
|
+
" #{branch}: #{parameters[:status]} (#{steps_to_s(parameters[:steps])})"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def steps_to_s(steps)
|
|
51
|
+
steps.map { |step| "#{step["name"]}: #{step["result"]}" }.join(", ")
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def uris
|
|
55
|
+
branches.map do |branch|
|
|
56
|
+
{
|
|
57
|
+
branch: branch,
|
|
58
|
+
path: "/project/#{owner}/#{repository}/branch/#{branch}/pipelines"
|
|
59
|
+
}
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require_relative 'project'
|
|
2
|
+
|
|
3
|
+
module SnapCi
|
|
4
|
+
class ProjectList
|
|
5
|
+
attr_reader :list
|
|
6
|
+
|
|
7
|
+
def initialize(args)
|
|
8
|
+
@list = []
|
|
9
|
+
mutex = Mutex.new
|
|
10
|
+
|
|
11
|
+
args.projects.map do |project_info|
|
|
12
|
+
Thread.new do
|
|
13
|
+
project_message = Project.new(project_info, args).to_message
|
|
14
|
+
mutex.synchronize { @list << project_message }
|
|
15
|
+
end
|
|
16
|
+
end.each(&:join)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def to_message
|
|
20
|
+
list.join("\n\n")
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Gem::Specification.new do |spec|
|
|
2
|
+
spec.name = "lita-snap-ci"
|
|
3
|
+
spec.version = "1.0.0"
|
|
4
|
+
spec.authors = ["Juan Fraire"]
|
|
5
|
+
spec.email = ["groteck@gmail.com"]
|
|
6
|
+
spec.description = "Snap-ci integration with lita"
|
|
7
|
+
spec.summary = "Lita , Snap-ci, ChatOps"
|
|
8
|
+
spec.homepage = "https://github.com/groteck/lita-snap-ci"
|
|
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.7"
|
|
18
|
+
|
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
|
20
|
+
spec.add_development_dependency "pry-byebug"
|
|
21
|
+
spec.add_development_dependency "rake"
|
|
22
|
+
spec.add_development_dependency "rack-test"
|
|
23
|
+
spec.add_development_dependency "webmock"
|
|
24
|
+
spec.add_development_dependency "rspec", ">= 3.0.0"
|
|
25
|
+
end
|
data/locales/en.yml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
en:
|
|
2
|
+
lita:
|
|
3
|
+
handlers:
|
|
4
|
+
snap_ci:
|
|
5
|
+
report:
|
|
6
|
+
command: snap-ci report
|
|
7
|
+
desc: display a general report, with all the branches and status per project
|
|
8
|
+
project:
|
|
9
|
+
command: snap-ci status <owner>/<repo> or <repo>
|
|
10
|
+
desc: display a single project report with all the branches and status
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_links": {
|
|
3
|
+
"self": {
|
|
4
|
+
"href": ""
|
|
5
|
+
},
|
|
6
|
+
"previous": {
|
|
7
|
+
"href": ""
|
|
8
|
+
},
|
|
9
|
+
"latest": {
|
|
10
|
+
"href": ""
|
|
11
|
+
},
|
|
12
|
+
"oldest": {
|
|
13
|
+
"href": ""
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"_embedded": {
|
|
17
|
+
"pipelines": [
|
|
18
|
+
{
|
|
19
|
+
"_links": {
|
|
20
|
+
"self": {
|
|
21
|
+
"href": ""
|
|
22
|
+
},
|
|
23
|
+
"latest": {
|
|
24
|
+
"href": ""
|
|
25
|
+
},
|
|
26
|
+
"oldest": {
|
|
27
|
+
"href": ""
|
|
28
|
+
},
|
|
29
|
+
"previous": {
|
|
30
|
+
"href": ""
|
|
31
|
+
},
|
|
32
|
+
"next": {
|
|
33
|
+
"href": ""
|
|
34
|
+
},
|
|
35
|
+
"docs": {
|
|
36
|
+
"href": ""
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"counter": 177,
|
|
40
|
+
"result": "passed",
|
|
41
|
+
"commits": [
|
|
42
|
+
{
|
|
43
|
+
"_links": {
|
|
44
|
+
"github": [
|
|
45
|
+
{
|
|
46
|
+
"rel": "api",
|
|
47
|
+
"href": ""
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"rel": "http",
|
|
51
|
+
"href": ""
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
"sha": "02a8b141f57640c545043f5ede86f26ab4b32b3d",
|
|
56
|
+
"short_sha": "02a8b14",
|
|
57
|
+
"author": "",
|
|
58
|
+
"message": "",
|
|
59
|
+
"time": "2016-05-19T09:43:56Z"
|
|
60
|
+
}
|
|
61
|
+
],
|
|
62
|
+
"stages": [
|
|
63
|
+
{
|
|
64
|
+
"name": "Integration",
|
|
65
|
+
"full_name": "zenmate/api (development) :: Integration",
|
|
66
|
+
"result": "passed",
|
|
67
|
+
"duration": 119,
|
|
68
|
+
"workers": [
|
|
69
|
+
{
|
|
70
|
+
"counter": 1,
|
|
71
|
+
"result": "passed",
|
|
72
|
+
"duration": 93.09199094772339,
|
|
73
|
+
"artifacts": [
|
|
74
|
+
|
|
75
|
+
],
|
|
76
|
+
"started_at": "2016-05-19T09:44:40Z",
|
|
77
|
+
"completed_at": "2016-05-19T09:46:13Z"
|
|
78
|
+
}
|
|
79
|
+
],
|
|
80
|
+
"started_at": "2016-05-19T09:44:15Z",
|
|
81
|
+
"completed_at": "2016-05-19T09:46:14Z"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"name": "Brakeman",
|
|
85
|
+
"full_name": "oneorg/api (development) :: Brakeman",
|
|
86
|
+
"result": "passed",
|
|
87
|
+
"duration": 47,
|
|
88
|
+
"workers": [
|
|
89
|
+
{
|
|
90
|
+
"counter": 1,
|
|
91
|
+
"result": "passed",
|
|
92
|
+
"duration": 44.53549098968506,
|
|
93
|
+
"artifacts": [
|
|
94
|
+
|
|
95
|
+
],
|
|
96
|
+
"started_at": "2016-05-19T09:46:16Z",
|
|
97
|
+
"completed_at": "2016-05-19T09:47:01Z"
|
|
98
|
+
}
|
|
99
|
+
],
|
|
100
|
+
"started_at": "2016-05-19T09:46:15Z",
|
|
101
|
+
"completed_at": "2016-05-19T09:47:02Z"
|
|
102
|
+
}
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
]
|
|
106
|
+
}
|
|
107
|
+
}
|