danger-gitlab_graph 0.0.7 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/Gemfile.lock +23 -1
- data/README.md +50 -1
- data/danger-gitlab_graph.gemspec +13 -9
- data/lib/gitlab_graph/gem_version.rb +1 -1
- data/lib/gitlab_graph/plugin.rb +87 -36
- data/spec/gitlab_graph_spec.rb +80 -16
- data/spec/spec_helper.rb +24 -2
- data/spec/support/fixtures/graph-simple-expected.svg +369 -0
- data/spec/support/fixtures/jobs-1119.json +97 -0
- data/spec/support/fixtures/jobs-123456.json +97 -0
- data/spec/support/fixtures/pipelines.json +14 -0
- data/spec/support/fixtures/trace-2722.txt +49 -0
- data/spec/support/fixtures/trace-2723.txt +49 -0
- data/spec/support/gitlab_helper.rb +56 -0
- metadata +41 -9
- data/spec/support/fixtures/github_pr.json +0 -277
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a90273371dfdea31771892146d51bb400737899f28e9f194efa2af34d9acf351
|
4
|
+
data.tar.gz: 3154b7f5544cdbd32658f4596b84a217d6d136b124f764045dc38be953c673a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3699777c4212c3a626b972ca3d0046214567f56c1323d8e82b0be255653813771d19ac6abca6d4c7246e590cc0348b861a419167097836cebecb89df9f8997af
|
7
|
+
data.tar.gz: 42c833ab21eafa3bfe452805a61ee98f604624a1b6ad9b14cdc8125d2ee50fabacbb854157df60116e24975d3794fb74e67a3267a2ee20019ce872aa3a8f0c56
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
danger-gitlab_graph (0.0
|
4
|
+
danger-gitlab_graph (0.1.0)
|
5
5
|
danger-plugin-api (~> 1.0)
|
6
6
|
svg-graph (~> 2.2.1)
|
7
7
|
|
@@ -20,6 +20,8 @@ GEM
|
|
20
20
|
colored2 (3.1.2)
|
21
21
|
cork (0.3.0)
|
22
22
|
colored2 (~> 3.1)
|
23
|
+
crack (0.4.5)
|
24
|
+
rexml
|
23
25
|
danger (9.0.0)
|
24
26
|
claide (~> 1.0)
|
25
27
|
claide-plugins (>= 0.9.2)
|
@@ -33,6 +35,9 @@ GEM
|
|
33
35
|
no_proxy_fix
|
34
36
|
octokit (~> 5.0)
|
35
37
|
terminal-table (>= 1, < 4)
|
38
|
+
danger-gitlab (8.0.0)
|
39
|
+
danger
|
40
|
+
gitlab (~> 4.2, >= 4.2.0)
|
36
41
|
danger-plugin-api (1.0.0)
|
37
42
|
danger (> 2.0)
|
38
43
|
diff-lcs (1.5.0)
|
@@ -66,6 +71,9 @@ GEM
|
|
66
71
|
git (1.12.0)
|
67
72
|
addressable (~> 2.8)
|
68
73
|
rchardet (~> 1.8)
|
74
|
+
gitlab (4.19.0)
|
75
|
+
httparty (~> 0.20)
|
76
|
+
terminal-table (>= 1.5.1)
|
69
77
|
guard (2.18.0)
|
70
78
|
formatador (>= 0.2.4)
|
71
79
|
listen (>= 2.7, < 4.0)
|
@@ -80,6 +88,10 @@ GEM
|
|
80
88
|
guard (~> 2.1)
|
81
89
|
guard-compat (~> 1.1)
|
82
90
|
rspec (>= 2.99.0, < 4.0)
|
91
|
+
hashdiff (1.0.1)
|
92
|
+
httparty (0.20.0)
|
93
|
+
mime-types (~> 3.0)
|
94
|
+
multi_xml (>= 0.5.2)
|
83
95
|
json (2.6.2)
|
84
96
|
kramdown (2.4.0)
|
85
97
|
rexml
|
@@ -90,6 +102,10 @@ GEM
|
|
90
102
|
rb-inotify (>= 0.9.7)
|
91
103
|
lumberjack (1.2.8)
|
92
104
|
method_source (1.0.0)
|
105
|
+
mime-types (3.4.1)
|
106
|
+
mime-types-data (~> 3.2015)
|
107
|
+
mime-types-data (3.2022.0105)
|
108
|
+
multi_xml (0.6.0)
|
93
109
|
multipart-post (2.2.3)
|
94
110
|
nap (1.1.0)
|
95
111
|
nenv (0.3.0)
|
@@ -152,6 +168,10 @@ GEM
|
|
152
168
|
unicode-display_width (>= 1.1.1, < 3)
|
153
169
|
thor (1.2.1)
|
154
170
|
unicode-display_width (2.3.0)
|
171
|
+
webmock (2.3.2)
|
172
|
+
addressable (>= 2.3.6)
|
173
|
+
crack (>= 0.3.2)
|
174
|
+
hashdiff
|
155
175
|
webrick (1.7.0)
|
156
176
|
yard (0.9.28)
|
157
177
|
webrick (~> 1.7.0)
|
@@ -161,6 +181,7 @@ PLATFORMS
|
|
161
181
|
|
162
182
|
DEPENDENCIES
|
163
183
|
bundler (~> 2.0)
|
184
|
+
danger-gitlab
|
164
185
|
danger-gitlab_graph!
|
165
186
|
guard (~> 2.14)
|
166
187
|
guard-rspec (~> 4.7)
|
@@ -169,6 +190,7 @@ DEPENDENCIES
|
|
169
190
|
rake (~> 10.0)
|
170
191
|
rspec (~> 3.4)
|
171
192
|
rubocop
|
193
|
+
webmock (~> 2.1)
|
172
194
|
yard
|
173
195
|
|
174
196
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
# danger-gitlab_graph
|
2
2
|
|
3
|
-
|
3
|
+
`danger-gitlab_graph` is a [Danger](https://danger.systems) ruby plugin that allows you to extract and display metrics
|
4
|
+
gathered from the current and previous pipeline runs. This plugin is only works with GitLab CI at the moment.
|
5
|
+
|
6
|
+
It works similar to the existing test coverage extraction provided by GitLab natively: You provide a job name, an
|
7
|
+
extraction regex (including a single capturing group) and some other, optional configuration options. The plugin then
|
8
|
+
creates an svg graph (using the [svg-graph2](https://github.com/lumean/svg-graph2) gem) and adds them to your other
|
9
|
+
Danger comments.
|
4
10
|
|
5
11
|
## Installation
|
6
12
|
|
@@ -11,6 +17,49 @@ A description of danger-gitlab_graph.
|
|
11
17
|
Methods and attributes from this plugin are available in
|
12
18
|
your `Dangerfile` under the `gitlab_graph` namespace.
|
13
19
|
|
20
|
+
### Methods
|
21
|
+
|
22
|
+
`gather_metric` - Gathers metric data from current and pevious pipelines
|
23
|
+
|
24
|
+
Sample code:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
@my_plugin.gather_metric({
|
28
|
+
regex: /took ([0-9]+)/,
|
29
|
+
series_name: "Performance",
|
30
|
+
job_name: "test1"
|
31
|
+
})
|
32
|
+
```
|
33
|
+
|
34
|
+
returns an array similiar to this:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
[{ hash: "b23f54ecdc3add9abea9344f66b49f1699bff547", metric: 16.0, pipeline_id: 1119 },
|
38
|
+
{ hash: "3333333333333333333333333333333333333333", metric: 6.0, pipeline_id: 123_456 }]
|
39
|
+
```
|
40
|
+
|
41
|
+
`report_metric` - Creates and comments a graph based on a certain metric, extracted via regex
|
42
|
+
|
43
|
+
Sample code
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
gitlab_graph.report_metric([{
|
47
|
+
regex: /took ([0-9]+)/,
|
48
|
+
series_name: "Performance",
|
49
|
+
job_name: "test1"
|
50
|
+
}, {
|
51
|
+
regex: /slept ([0-9]+)/,
|
52
|
+
series_name: "IDLE time",
|
53
|
+
job_name: "test1"
|
54
|
+
}]) < /pre>
|
55
|
+
```
|
56
|
+
|
57
|
+
outputs a graph similiar to this
|
58
|
+
|
59
|
+
![sample graph](spec/support/fixtures/graph-simple-expected.svg)
|
60
|
+
|
61
|
+
and writes it directly into the danger comment
|
62
|
+
|
14
63
|
## Development
|
15
64
|
|
16
65
|
1. Clone this repo
|
data/danger-gitlab_graph.gemspec
CHANGED
@@ -5,19 +5,20 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
require "gitlab_graph/gem_version"
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
|
-
spec.name
|
9
|
-
spec.version
|
10
|
-
spec.authors
|
11
|
-
spec.email
|
12
|
-
spec.description
|
13
|
-
spec.summary
|
14
|
-
spec.homepage
|
15
|
-
spec.license
|
8
|
+
spec.name = "danger-gitlab_graph"
|
9
|
+
spec.version = GitlabGraph::VERSION
|
10
|
+
spec.authors = ["Jan Beckmann"]
|
11
|
+
spec.email = ["king-jan1999@hotmail.de"]
|
12
|
+
spec.description = "Danger plugin for creating graph from ci metrics."
|
13
|
+
spec.summary = "Danger plugin which allows you to extract and visualize metrics over previous ci runs."
|
14
|
+
spec.homepage = "https://github.com/kingjan1999/danger-gitlab_graph"
|
15
|
+
spec.license = "MIT"
|
16
|
+
spec.required_ruby_version = ">= 2.7.0"
|
16
17
|
|
17
18
|
spec.files = `git ls-files`.split($/)
|
18
19
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
20
|
spec.require_paths = ["lib"]
|
21
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
21
22
|
|
22
23
|
spec.add_runtime_dependency "danger-plugin-api", "~> 1.0"
|
23
24
|
spec.add_runtime_dependency "svg-graph", "~> 2.2.1"
|
@@ -48,4 +49,7 @@ Gem::Specification.new do |spec|
|
|
48
49
|
#
|
49
50
|
# This will stop test execution and let you inspect the results
|
50
51
|
spec.add_development_dependency "pry"
|
52
|
+
|
53
|
+
spec.add_development_dependency "danger-gitlab"
|
54
|
+
spec.add_development_dependency "webmock", "~> 2.1"
|
51
55
|
end
|
data/lib/gitlab_graph/plugin.rb
CHANGED
@@ -1,66 +1,114 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
|
+
require "svggraph"
|
3
4
|
|
4
5
|
module Danger
|
5
6
|
# This plugin retrieves a certain metric from previous job runs and displays them as a graph
|
6
7
|
#
|
7
8
|
# @example Extract values from job "test" with the given regex
|
8
9
|
#
|
9
|
-
# gitlab_graph.report_metric(
|
10
|
+
# gitlab_graph.report_metric([{
|
11
|
+
# regex: /took ([0-9]+)/,
|
12
|
+
# series_name: "Performance",
|
13
|
+
# job_name: "test1"
|
14
|
+
# }, {
|
15
|
+
# regex: /slept ([0-9]+)/,
|
16
|
+
# series_name: "IDLE time",
|
17
|
+
# job_name: "test1"
|
18
|
+
# }])
|
10
19
|
#
|
20
|
+
# outputs a graph similiar to this ![sample graph](spec/support/fixtures/graph-simple-expected.svg)
|
11
21
|
# @see kingjan1999/danger-gitlab_graph
|
12
22
|
# @tags gitlab, graph, performance
|
13
23
|
#
|
14
24
|
class DangerGitlabGraph < Plugin
|
15
|
-
#
|
16
|
-
# @return
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
project_id = ENV["CI_PROJECT_ID"]
|
25
|
+
# Gathers metric data from current and pevious pipelines
|
26
|
+
# @return [Arrray<{pipeline_id => int, :metric => float}>]
|
27
|
+
def gather_metric(extraction_config, prev_pipeline_count = 10)
|
28
|
+
pipeline_id = ENV["CI_PIPELINE_ID"].to_i
|
29
|
+
project_id = ENV.fetch("CI_PROJECT_ID", nil)
|
21
30
|
|
22
31
|
target_branch = gitlab.branch_for_merge
|
23
32
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
33
|
+
begin
|
34
|
+
new_metric = extract_metric_from_pipeline(project_id, pipeline_id, extraction_config[:regex], extraction_config[:job_name])
|
35
|
+
rescue JobNotFoundException
|
36
|
+
warn("Job #{extraction_config[:job_name]} for metric extraction of #{extraction_config[:series_name]} not found in current pipeline")
|
37
|
+
return []
|
38
|
+
end
|
39
|
+
|
40
|
+
unless new_metric[:metric]
|
41
|
+
warn("No updated metric #{extraction_config[:series_name]} found for job #{extraction_config[:job_name]}")
|
42
|
+
return []
|
28
43
|
end
|
29
44
|
|
30
45
|
previous_target_branch_pipelines = gitlab.api.pipelines(project_id, {
|
31
|
-
status:
|
46
|
+
status: "success",
|
32
47
|
ref: target_branch,
|
33
48
|
per_page: prev_pipeline_count
|
34
49
|
})
|
35
50
|
|
36
|
-
previous_metrics = previous_target_branch_pipelines.collect
|
37
|
-
|
38
|
-
|
51
|
+
previous_metrics = previous_target_branch_pipelines.collect do |pipeline|
|
52
|
+
extract_metric_from_pipeline(project_id, pipeline.id, extraction_config[:regex], extraction_config[:job_name]).merge(hash: pipeline.sha)
|
53
|
+
rescue JobNotFoundException
|
54
|
+
return { pipeline_id: pipeline.id, metric: false, hash: pipeline.sha }
|
55
|
+
end
|
56
|
+
|
57
|
+
previous_metrics + [new_metric.merge(hash: ENV.fetch("CI_COMMIT_SHA", "invalid_hash"))]
|
58
|
+
end
|
59
|
+
|
60
|
+
# Creates and comments a graph based on a certain metric, extracted via regex
|
61
|
+
# @param [Array<hash>] extraction_configs Hash-Array: {:regex, :job_name, :series_name}
|
62
|
+
# @param [int] prev_pipeline_count
|
63
|
+
# @param [hash] graph_options see svg-graph doc
|
64
|
+
# @return [void]
|
65
|
+
def report_metric(extraction_configs, prev_pipeline_count = 10, graph_options = {})
|
66
|
+
project_id = ENV.fetch("CI_PROJECT_ID", nil)
|
39
67
|
|
40
|
-
|
41
|
-
|
68
|
+
fields = nil
|
69
|
+
all_data = []
|
70
|
+
extraction_configs.each do |extraction_config|
|
71
|
+
all_metrics = gather_metric(extraction_config, prev_pipeline_count)
|
42
72
|
|
43
|
-
|
44
|
-
|
73
|
+
if all_metrics.length.zero?
|
74
|
+
next
|
75
|
+
end
|
76
|
+
|
77
|
+
if fields and all_metrics.length != fields.length
|
78
|
+
warn("Not all metrics could be found in an equal amount of jobs. Unable to plot #{extraction_config[:series_name]}")
|
79
|
+
next
|
80
|
+
end
|
81
|
+
|
82
|
+
data = all_metrics.collect { |val| val[:metric] }
|
83
|
+
|
84
|
+
fields ||= all_metrics.collect { |pipeline| pipeline[:hash][0..7] }
|
85
|
+
|
86
|
+
all_data.push({ data: data, title: extraction_config[:series_name] })
|
87
|
+
end
|
88
|
+
|
89
|
+
if all_data.empty?
|
90
|
+
return
|
91
|
+
end
|
45
92
|
|
46
93
|
default_graph_options = {
|
47
|
-
:
|
48
|
-
:
|
49
|
-
:
|
50
|
-
:
|
51
|
-
:
|
52
|
-
:
|
53
|
-
:
|
54
|
-
:
|
55
|
-
:
|
56
|
-
:
|
94
|
+
width: 640,
|
95
|
+
height: 480,
|
96
|
+
graph_title: "Performance Metric",
|
97
|
+
show_graph_title: true,
|
98
|
+
x_title: "Commit",
|
99
|
+
y_title: "Metric Value",
|
100
|
+
show_y_title: true,
|
101
|
+
show_x_title: true,
|
102
|
+
number_format: "%.2fs",
|
103
|
+
fields: fields
|
57
104
|
}
|
58
105
|
|
106
|
+
# create graph
|
59
107
|
g = SVG::Graph::Line.new(default_graph_options.merge(graph_options))
|
60
108
|
|
61
|
-
g.add_data(:data
|
109
|
+
all_data.each { |elem| g.add_data(data: elem[:data], title: elem[:title]) }
|
62
110
|
|
63
|
-
temp_file = Tempfile.new(%w
|
111
|
+
temp_file = Tempfile.new(%w(graph .svg))
|
64
112
|
begin
|
65
113
|
temp_file.write(g.burn_svg_only)
|
66
114
|
uploaded_file = gitlab.api.upload_file(project_id, temp_file.path)
|
@@ -76,16 +124,19 @@ module Danger
|
|
76
124
|
def extract_metric_from_pipeline(project_id, pipeline_id, extraction_regex, job_name)
|
77
125
|
all_jobs = gitlab.api.pipeline_jobs(project_id, pipeline_id)
|
78
126
|
target_job = all_jobs.find { |x| x.name == job_name }
|
79
|
-
|
127
|
+
raise JobNotFoundException, "job #{job_name} not found in pipeline #{pipeline_id}" unless target_job
|
80
128
|
|
81
129
|
job_trace = gitlab.api.job_trace(project_id, target_job.id)
|
82
130
|
|
83
131
|
metric_matches = job_trace.match(extraction_regex)
|
84
|
-
unless metric_matches
|
85
|
-
return pipeline_id, false
|
132
|
+
unless metric_matches&.captures
|
133
|
+
return { pipeline_id: pipeline_id, metric: false }
|
86
134
|
end
|
87
135
|
|
88
|
-
|
136
|
+
{ pipeline_id: pipeline_id, metric: metric_matches.captures[0].to_f }
|
137
|
+
end
|
138
|
+
|
139
|
+
class JobNotFoundException < StandardError
|
89
140
|
end
|
90
141
|
end
|
91
142
|
end
|
data/spec/gitlab_graph_spec.rb
CHANGED
@@ -1,43 +1,107 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "fileutils"
|
3
4
|
require File.expand_path("spec_helper", __dir__)
|
4
5
|
|
5
6
|
module Danger
|
6
|
-
describe Danger::DangerGitlabGraph do
|
7
|
+
describe Danger::DangerGitlabGraph, host: :gitlab do
|
7
8
|
it "should be a plugin" do
|
8
9
|
expect(Danger::DangerGitlabGraph.new(nil)).to be_a Danger::Plugin
|
9
10
|
end
|
10
11
|
|
11
|
-
#
|
12
|
-
# You should test your custom attributes and methods here
|
13
|
-
#
|
14
12
|
describe "with Dangerfile" do
|
13
|
+
graph_tmpfile = nil
|
14
|
+
|
15
15
|
before do
|
16
|
+
stub_version("11.2.3")
|
17
|
+
|
16
18
|
@dangerfile = testing_dangerfile
|
17
19
|
@my_plugin = @dangerfile.gitlab_graph
|
18
20
|
|
19
|
-
allow(@my_plugin.gitlab).to receive(:
|
21
|
+
allow(@my_plugin.gitlab).to receive(:branch_for_merge).and_return("main")
|
22
|
+
|
23
|
+
stub_const("ENV", ENV.to_hash.merge(testing_env))
|
24
|
+
|
25
|
+
pipelines = File.read("#{File.dirname(__FILE__)}/support/fixtures/pipelines.json")
|
26
|
+
|
27
|
+
# stub requests
|
28
|
+
stub_jobs(123_456)
|
29
|
+
stub_jobs(1119)
|
30
|
+
|
31
|
+
stub_trace(2722)
|
32
|
+
stub_trace(2723)
|
33
|
+
|
34
|
+
stub_request(:get, "https://gitlab.com/api/v4/projects/123/pipelines?per_page=10&ref=main&status=success").
|
35
|
+
to_return(status: 200, body: pipelines, headers: {})
|
36
|
+
|
37
|
+
stub_request(:post, "https://gitlab.com/api/v4/projects/123/uploads").
|
38
|
+
to_return do |request|
|
39
|
+
svg_file = request.body[request.body.index("<svg")..request.body.index("</svg>") + 5]
|
40
|
+
graph_tmpfile = Tempfile.new(["tmp-graph", ".svg"])
|
41
|
+
begin
|
42
|
+
graph_tmpfile.write(svg_file)
|
43
|
+
ensure
|
44
|
+
graph_tmpfile.close
|
45
|
+
end
|
46
|
+
|
47
|
+
{ status: 200, body: {
|
48
|
+
markdown: "![description](/link)"
|
49
|
+
}.to_json, headers: {} }
|
50
|
+
end
|
20
51
|
end
|
21
52
|
|
22
|
-
|
23
|
-
|
53
|
+
after do
|
54
|
+
graph_tmpfile&.unlink
|
55
|
+
end
|
24
56
|
|
25
|
-
it "
|
26
|
-
|
27
|
-
|
57
|
+
it "outputs a markdown image link" do
|
58
|
+
@my_plugin.report_metric([{
|
59
|
+
regex: /took ([0-9]+)/,
|
60
|
+
series_name: "Performance",
|
61
|
+
job_name: "test1"
|
62
|
+
}, {
|
63
|
+
regex: /slept ([0-9]+)/,
|
64
|
+
series_name: "IDLE time",
|
65
|
+
job_name: "test1"
|
66
|
+
}])
|
28
67
|
|
29
|
-
@
|
68
|
+
expect(@dangerfile.status_report[:markdowns][0].message).to eq("![description](/link)")
|
69
|
+
expect(graph_tmpfile).not_to be_nil
|
30
70
|
|
31
|
-
|
71
|
+
expected_graph_file = "#{File.dirname(__FILE__)}/support/fixtures/graph-simple-expected.svg"
|
72
|
+
expect(FileUtils.compare_file(graph_tmpfile.path, expected_graph_file)).to be_truthy
|
32
73
|
end
|
33
74
|
|
34
|
-
it "
|
35
|
-
|
36
|
-
|
75
|
+
it "warns an error if there is no match" do
|
76
|
+
@my_plugin.report_metric([{
|
77
|
+
regex: /not found ([0-9]+)/,
|
78
|
+
series_name: "Performance",
|
79
|
+
job_name: "test1"
|
80
|
+
}])
|
81
|
+
|
82
|
+
expect(@dangerfile.status_report[:warnings]).to eq(["No updated metric Performance found for job test1"])
|
83
|
+
end
|
84
|
+
|
85
|
+
it "warns if there is no such job" do
|
86
|
+
@my_plugin.report_metric([{
|
87
|
+
regex: /took ([0-9]+)/,
|
88
|
+
series_name: "Performance",
|
89
|
+
job_name: "not-found-either"
|
90
|
+
}])
|
91
|
+
|
92
|
+
expect(@dangerfile.status_report[:warnings]).to eq(["Job not-found-either for metric extraction of Performance not found in current pipeline"])
|
93
|
+
end
|
37
94
|
|
38
|
-
|
95
|
+
it "gathers all metrics" do
|
96
|
+
metrics = @my_plugin.gather_metric({
|
97
|
+
regex: /took ([0-9]+)/,
|
98
|
+
series_name: "Performance",
|
99
|
+
job_name: "test1"
|
100
|
+
})
|
39
101
|
|
40
102
|
expect(@dangerfile.status_report[:warnings]).to eq([])
|
103
|
+
expect(metrics).to eq([{ hash: "b23f54ecdc3add9abea9344f66b49f1699bff547", metric: 16.0, pipeline_id: 1119 },
|
104
|
+
{ hash: "3333333333333333333333333333333333333333", metric: 6.0, pipeline_id: 123_456 }])
|
41
105
|
end
|
42
106
|
end
|
43
107
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,12 +4,16 @@ require "pathname"
|
|
4
4
|
ROOT = Pathname.new(File.expand_path("..", __dir__))
|
5
5
|
$:.unshift("#{ROOT}lib".to_s)
|
6
6
|
$:.unshift("#{ROOT}spec".to_s)
|
7
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
|
8
|
+
$LOAD_PATH.unshift File.expand_path("..", __dir__)
|
7
9
|
|
8
10
|
require "bundler/setup"
|
9
11
|
require "pry"
|
10
12
|
|
11
13
|
require "rspec"
|
12
14
|
require "danger"
|
15
|
+
require "webmock"
|
16
|
+
require "webmock/rspec"
|
13
17
|
|
14
18
|
if `git remote -v` == ""
|
15
19
|
puts "You cannot run tests without setting a local git remote on this repo"
|
@@ -17,15 +21,22 @@ if `git remote -v` == ""
|
|
17
21
|
exit(0)
|
18
22
|
end
|
19
23
|
|
24
|
+
Dir["spec/support/**/*.rb"].sort.each { |file| require(file) }
|
25
|
+
|
20
26
|
# Use coloured output, it's the best.
|
21
27
|
RSpec.configure do |config|
|
22
28
|
config.filter_gems_from_backtrace "bundler"
|
23
29
|
config.color = true
|
24
30
|
config.tty = true
|
31
|
+
|
32
|
+
config.include Danger::Support::GitLabHelper, host: :gitlab
|
33
|
+
# config.include Danger::Support::CIHelper, use: :ci_helper
|
25
34
|
end
|
26
35
|
|
27
36
|
require "danger_plugin"
|
28
37
|
|
38
|
+
WebMock.disable_net_connect!(allow: "coveralls.io")
|
39
|
+
|
29
40
|
# These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
|
30
41
|
# If you are expanding these files, see if it's already been done ^.
|
31
42
|
|
@@ -36,24 +47,35 @@ require "danger_plugin"
|
|
36
47
|
# rubocop:disable Lint/NestedMethodDefinition
|
37
48
|
def testing_ui
|
38
49
|
@output = StringIO.new
|
50
|
+
|
39
51
|
def @output.winsize
|
40
52
|
[20, 9999]
|
41
53
|
end
|
42
54
|
|
43
55
|
cork = Cork::Board.new(out: @output)
|
56
|
+
|
44
57
|
def cork.string
|
45
58
|
out.string.gsub(/\e\[([;\d]+)?m/, "")
|
46
59
|
end
|
60
|
+
|
47
61
|
cork
|
48
62
|
end
|
63
|
+
|
49
64
|
# rubocop:enable Lint/NestedMethodDefinition
|
50
65
|
|
51
66
|
# Example environment (ENV) that would come from
|
52
67
|
# running a PR on TravisCI
|
53
68
|
def testing_env
|
54
69
|
{
|
55
|
-
"CI_PIPELINE_ID" => "
|
56
|
-
"CI_PROJECT_ID" => "123"
|
70
|
+
"CI_PIPELINE_ID" => "123456",
|
71
|
+
"CI_PROJECT_ID" => "123",
|
72
|
+
"GITLAB_CI" => "1",
|
73
|
+
"CI_COMMIT_SHA" => "3333333333333333333333333333333333333333",
|
74
|
+
"CI_COMMIT_SHORT_SHA" => "33333333",
|
75
|
+
"CI_PROJECT_PATH" => "k0nserv/danger-test",
|
76
|
+
"CI_PROJECT_URL" => "https://gitlab.com/k0nserv/danger-test",
|
77
|
+
"DANGER_GITLAB_API_TOKEN" => "a86e56d46ac78b",
|
78
|
+
"CI_MERGE_REQUEST_IID" => "145"
|
57
79
|
}
|
58
80
|
end
|
59
81
|
|