rspec-mergify 0.1.3 → 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 +4 -4
- data/LICENSE +174 -672
- data/README.md +2 -2
- data/lib/mergify/rspec/ci_insights.rb +14 -27
- data/lib/mergify/rspec/configuration.rb +1 -2
- data/lib/mergify/rspec/flaky_detection.rb +30 -84
- data/lib/mergify/rspec/formatter.rb +4 -8
- data/lib/mergify/rspec/native.rb +70 -0
- data/lib/mergify/rspec/quarantine.rb +23 -82
- data/lib/mergify/rspec/utils.rb +11 -95
- data/lib/mergify/rspec/version.rb +7 -12
- metadata +7 -12
- data/lib/mergify/rspec/resources/buildkite.rb +0 -54
- data/lib/mergify/rspec/resources/ci.rb +0 -24
- data/lib/mergify/rspec/resources/git.rb +0 -35
- data/lib/mergify/rspec/resources/github_actions.rb +0 -60
- data/lib/mergify/rspec/resources/jenkins.rb +0 -55
- data/lib/mergify/rspec/resources/mergify.rb +0 -24
data/lib/mergify/rspec/utils.rb
CHANGED
|
@@ -1,24 +1,21 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'open3'
|
|
4
|
-
|
|
5
3
|
module Mergify
|
|
6
4
|
module RSpec
|
|
7
5
|
# Utility methods shared across the rspec-mergify gem.
|
|
6
|
+
#
|
|
7
|
+
# CI detection used to live here -- the provider table, the git shelling
|
|
8
|
+
# out, the per-provider environment mappings. It is the Rust core's now, via
|
|
9
|
+
# the extension in Mergify::RSpec::Native, so that every Mergify test client
|
|
10
|
+
# detects identically. What is left is what is genuinely Ruby's: parsing a
|
|
11
|
+
# repository name the API needs split, and deciding whether the plugin
|
|
12
|
+
# should switch itself on at all.
|
|
8
13
|
module Utils
|
|
9
14
|
module_function
|
|
10
15
|
|
|
11
16
|
# Raised when a repository full name (owner/repo) is malformed.
|
|
12
17
|
class InvalidRepositoryFullNameError < StandardError; end
|
|
13
18
|
|
|
14
|
-
SUPPORTED_CIS = {
|
|
15
|
-
'GITHUB_ACTIONS' => :github_actions,
|
|
16
|
-
'CIRCLECI' => :circleci,
|
|
17
|
-
'JENKINS_URL' => :jenkins,
|
|
18
|
-
'BUILDKITE' => :buildkite,
|
|
19
|
-
'_RSPEC_MERGIFY_TEST' => :rspec_mergify_suite
|
|
20
|
-
}.freeze
|
|
21
|
-
|
|
22
19
|
TRUTHY_STRINGS = %w[y yes t true on 1].freeze
|
|
23
20
|
FALSY_STRINGS = %w[n no f false off 0].freeze
|
|
24
21
|
|
|
@@ -40,45 +37,14 @@ module Mergify
|
|
|
40
37
|
|
|
41
38
|
# Returns true when the suite is running inside CI or when
|
|
42
39
|
# RSPEC_MERGIFY_ENABLE is set to a truthy value.
|
|
40
|
+
#
|
|
41
|
+
# Deliberately not the core's provider detection: this asks whether the
|
|
42
|
+
# plugin should run, which an unrecognised CI or a developer setting
|
|
43
|
+
# RSPEC_MERGIFY_ENABLE both answer yes to.
|
|
43
44
|
def in_ci?
|
|
44
45
|
env_truthy?('CI') || env_truthy?('RSPEC_MERGIFY_ENABLE')
|
|
45
46
|
end
|
|
46
47
|
|
|
47
|
-
# Evaluates whether a CI environment variable should be considered enabled.
|
|
48
|
-
# rubocop:disable Metrics/MethodLength
|
|
49
|
-
def ci_provider
|
|
50
|
-
SUPPORTED_CIS.each do |envvar, name|
|
|
51
|
-
next unless ENV.key?(envvar)
|
|
52
|
-
|
|
53
|
-
enabled =
|
|
54
|
-
begin
|
|
55
|
-
strtobool(ENV.fetch(envvar, ''))
|
|
56
|
-
rescue ArgumentError
|
|
57
|
-
!ENV.fetch(envvar, '').strip.empty?
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
return name if enabled
|
|
61
|
-
end
|
|
62
|
-
nil
|
|
63
|
-
end
|
|
64
|
-
# rubocop:enable Metrics/MethodLength
|
|
65
|
-
|
|
66
|
-
# Parse a git remote URL (SSH or HTTPS) into "owner/repo" form.
|
|
67
|
-
# Returns nil when the URL cannot be recognised.
|
|
68
|
-
def repository_name_from_url(url)
|
|
69
|
-
# SSH: git@github.com:owner/repo.git
|
|
70
|
-
if (m = url.match(%r{\Agit@[\w.-]+:(?<full_name>[\w.-]+/[\w.-]+?)(?:\.git)?/?$}))
|
|
71
|
-
return m[:full_name]
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
# HTTPS/HTTP with optional host (and optional port)
|
|
75
|
-
if (m = url.match(%r{\A(?:https?://[\w.-]+(?::\d+)?/)?(?<full_name>[\w.-]+/[\w.-]+)/?\z}))
|
|
76
|
-
return m[:full_name]
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
nil
|
|
80
|
-
end
|
|
81
|
-
|
|
82
48
|
# Split "owner/repo" into [owner, repo].
|
|
83
49
|
# Raises InvalidRepositoryFullNameError when the format is wrong.
|
|
84
50
|
def split_full_repo_name(full_repo_name)
|
|
@@ -87,56 +53,6 @@ module Mergify
|
|
|
87
53
|
|
|
88
54
|
raise InvalidRepositoryFullNameError, "Invalid repository name: #{full_repo_name}"
|
|
89
55
|
end
|
|
90
|
-
|
|
91
|
-
# Run a git subcommand via Open3.
|
|
92
|
-
# Returns stripped stdout on success, nil on failure.
|
|
93
|
-
def git(*args)
|
|
94
|
-
stdout, status = Open3.capture2('git', *args, err: File::NULL)
|
|
95
|
-
status.success? ? stdout.strip : nil
|
|
96
|
-
rescue StandardError
|
|
97
|
-
nil
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
# Build an attribute hash from a mapping of
|
|
101
|
-
# { attr_name => [cast_method_symbol, env_var_name_or_callable] }.
|
|
102
|
-
# Attributes whose env var is unset or whose callable returns nil are omitted.
|
|
103
|
-
def get_attributes(mapping)
|
|
104
|
-
mapping.each_with_object({}) do |(attr, (cast, env_or_callable)), result|
|
|
105
|
-
value = env_or_callable.respond_to?(:call) ? env_or_callable.call : ENV.fetch(env_or_callable, nil)
|
|
106
|
-
|
|
107
|
-
next if value.nil?
|
|
108
|
-
next if value.respond_to?(:empty?) && value.empty?
|
|
109
|
-
|
|
110
|
-
result[attr] = value.public_send(cast)
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
# Detect the repository name using CI environment variables or a git
|
|
115
|
-
# remote fallback.
|
|
116
|
-
# rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity
|
|
117
|
-
def repository_name
|
|
118
|
-
provider = ci_provider
|
|
119
|
-
|
|
120
|
-
case provider
|
|
121
|
-
when :jenkins
|
|
122
|
-
url = ENV.fetch('GIT_URL', nil)
|
|
123
|
-
return repository_name_from_url(url) if url
|
|
124
|
-
when :github_actions
|
|
125
|
-
return ENV.fetch('GITHUB_REPOSITORY', nil)
|
|
126
|
-
when :circleci
|
|
127
|
-
url = ENV.fetch('CIRCLE_REPOSITORY_URL', nil)
|
|
128
|
-
return repository_name_from_url(url) if url
|
|
129
|
-
when :buildkite
|
|
130
|
-
url = ENV.fetch('BUILDKITE_REPO', nil)
|
|
131
|
-
return repository_name_from_url(url) if url
|
|
132
|
-
when :rspec_mergify_suite
|
|
133
|
-
return 'Mergifyio/rspec-mergify'
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
url = git('config', '--get', 'remote.origin.url')
|
|
137
|
-
repository_name_from_url(url) if url
|
|
138
|
-
end
|
|
139
|
-
# rubocop:enable Metrics/MethodLength,Metrics/CyclomaticComplexity
|
|
140
56
|
end
|
|
141
57
|
end
|
|
142
58
|
end
|
|
@@ -2,17 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
module Mergify
|
|
4
4
|
module RSpec
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"#{parts[0]}.dev#{parts[1]}"
|
|
13
|
-
else
|
|
14
|
-
v
|
|
15
|
-
end
|
|
16
|
-
end
|
|
5
|
+
# Placeholder: the release workflow stamps the real version from the git tag
|
|
6
|
+
# at build time, as it does for pytest-mergify's pyproject.toml and the TS
|
|
7
|
+
# packages' package.json. This used to shell out to `git describe --tags`,
|
|
8
|
+
# which resolved against whatever repository happened to be the working
|
|
9
|
+
# directory at load time -- the monorepo's namespaced tags here, the user's
|
|
10
|
+
# own tags once the gem was installed.
|
|
11
|
+
VERSION = '0.2.0'
|
|
17
12
|
end
|
|
18
13
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rspec-mergify
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mergify
|
|
@@ -66,24 +66,19 @@ files:
|
|
|
66
66
|
- lib/mergify/rspec/configuration.rb
|
|
67
67
|
- lib/mergify/rspec/flaky_detection.rb
|
|
68
68
|
- lib/mergify/rspec/formatter.rb
|
|
69
|
+
- lib/mergify/rspec/native.rb
|
|
69
70
|
- lib/mergify/rspec/quarantine.rb
|
|
70
|
-
- lib/mergify/rspec/resources/buildkite.rb
|
|
71
|
-
- lib/mergify/rspec/resources/ci.rb
|
|
72
|
-
- lib/mergify/rspec/resources/git.rb
|
|
73
|
-
- lib/mergify/rspec/resources/github_actions.rb
|
|
74
|
-
- lib/mergify/rspec/resources/jenkins.rb
|
|
75
|
-
- lib/mergify/rspec/resources/mergify.rb
|
|
76
71
|
- lib/mergify/rspec/resources/rspec.rb
|
|
77
72
|
- lib/mergify/rspec/synchronous_batch_span_processor.rb
|
|
78
73
|
- lib/mergify/rspec/utils.rb
|
|
79
74
|
- lib/mergify/rspec/version.rb
|
|
80
75
|
- lib/rspec_mergify.rb
|
|
81
|
-
homepage: https://github.com/Mergifyio/
|
|
76
|
+
homepage: https://github.com/Mergifyio/mergify-ci-integrations
|
|
82
77
|
licenses:
|
|
83
|
-
-
|
|
78
|
+
- Apache-2.0
|
|
84
79
|
metadata:
|
|
85
|
-
homepage_uri: https://github.com/Mergifyio/
|
|
86
|
-
source_code_uri: https://github.com/Mergifyio/rspec-mergify
|
|
80
|
+
homepage_uri: https://github.com/Mergifyio/mergify-ci-integrations
|
|
81
|
+
source_code_uri: https://github.com/Mergifyio/mergify-ci-integrations/tree/main/clients/rspec-mergify
|
|
87
82
|
rubygems_mfa_required: 'true'
|
|
88
83
|
rdoc_options: []
|
|
89
84
|
require_paths:
|
|
@@ -99,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
99
94
|
- !ruby/object:Gem::Version
|
|
100
95
|
version: '0'
|
|
101
96
|
requirements: []
|
|
102
|
-
rubygems_version:
|
|
97
|
+
rubygems_version: 4.0.16
|
|
103
98
|
specification_version: 4
|
|
104
99
|
summary: RSpec plugin for Mergify CI Insights
|
|
105
100
|
test_files: []
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'opentelemetry-sdk'
|
|
4
|
-
require_relative '../utils'
|
|
5
|
-
require_relative 'git'
|
|
6
|
-
|
|
7
|
-
module Mergify
|
|
8
|
-
module RSpec
|
|
9
|
-
module Resources
|
|
10
|
-
# Detects OpenTelemetry Resource attributes for Buildkite.
|
|
11
|
-
module Buildkite
|
|
12
|
-
module_function
|
|
13
|
-
|
|
14
|
-
BUILDKITE_MAPPING = {
|
|
15
|
-
'cicd.pipeline.name' => [:to_s, 'BUILDKITE_PIPELINE_SLUG'],
|
|
16
|
-
'cicd.pipeline.task.name' => [
|
|
17
|
-
:to_s,
|
|
18
|
-
lambda {
|
|
19
|
-
label = ENV.fetch('BUILDKITE_LABEL', nil)
|
|
20
|
-
label && !label.empty? ? label : ENV.fetch('BUILDKITE_STEP_KEY', nil)
|
|
21
|
-
}
|
|
22
|
-
],
|
|
23
|
-
'cicd.pipeline.run.id' => [:to_s, 'BUILDKITE_BUILD_ID'],
|
|
24
|
-
'cicd.pipeline.run.url' => [:to_s, 'BUILDKITE_BUILD_URL'],
|
|
25
|
-
'cicd.pipeline.run.attempt' => [
|
|
26
|
-
:to_i,
|
|
27
|
-
-> { ENV.fetch('BUILDKITE_RETRY_COUNT', '0').to_i + 1 }
|
|
28
|
-
],
|
|
29
|
-
'cicd.pipeline.runner.name' => [:to_s, 'BUILDKITE_AGENT_NAME'],
|
|
30
|
-
'vcs.ref.head.name' => [:to_s, 'BUILDKITE_BRANCH'],
|
|
31
|
-
'vcs.ref.base.name' => [:to_s, 'BUILDKITE_PULL_REQUEST_BASE_BRANCH'],
|
|
32
|
-
'vcs.ref.head.revision' => [:to_s, 'BUILDKITE_COMMIT'],
|
|
33
|
-
'vcs.repository.url.full' => [:to_s, 'BUILDKITE_REPO'],
|
|
34
|
-
'vcs.repository.name' => [
|
|
35
|
-
:to_s,
|
|
36
|
-
lambda {
|
|
37
|
-
url = ENV.fetch('BUILDKITE_REPO', nil)
|
|
38
|
-
Utils.repository_name_from_url(url) if url
|
|
39
|
-
}
|
|
40
|
-
]
|
|
41
|
-
}.freeze
|
|
42
|
-
|
|
43
|
-
def detect
|
|
44
|
-
return OpenTelemetry::SDK::Resources::Resource.create({}) if Utils.ci_provider != :buildkite
|
|
45
|
-
|
|
46
|
-
git_attrs = Utils.get_attributes(Git::GIT_MAPPING)
|
|
47
|
-
buildkite_attrs = Utils.get_attributes(BUILDKITE_MAPPING)
|
|
48
|
-
merged = git_attrs.merge(buildkite_attrs)
|
|
49
|
-
OpenTelemetry::SDK::Resources::Resource.create(merged)
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'opentelemetry-sdk'
|
|
4
|
-
require_relative '../utils'
|
|
5
|
-
|
|
6
|
-
module Mergify
|
|
7
|
-
module RSpec
|
|
8
|
-
module Resources
|
|
9
|
-
# Detects OpenTelemetry Resource attributes for the CI provider.
|
|
10
|
-
module CI
|
|
11
|
-
module_function
|
|
12
|
-
|
|
13
|
-
def detect
|
|
14
|
-
provider = Utils.ci_provider
|
|
15
|
-
return OpenTelemetry::SDK::Resources::Resource.create({}) if provider.nil?
|
|
16
|
-
|
|
17
|
-
OpenTelemetry::SDK::Resources::Resource.create(
|
|
18
|
-
'cicd.provider.name' => provider.to_s
|
|
19
|
-
)
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'opentelemetry-sdk'
|
|
4
|
-
require_relative '../utils'
|
|
5
|
-
|
|
6
|
-
module Mergify
|
|
7
|
-
module RSpec
|
|
8
|
-
module Resources
|
|
9
|
-
# Detects OpenTelemetry Resource attributes from git.
|
|
10
|
-
module Git
|
|
11
|
-
module_function
|
|
12
|
-
|
|
13
|
-
GIT_MAPPING = {
|
|
14
|
-
'vcs.ref.head.name' => [:to_s, -> { Utils.git('rev-parse', '--abbrev-ref', 'HEAD') }],
|
|
15
|
-
'vcs.ref.head.revision' => [:to_s, -> { Utils.git('rev-parse', 'HEAD') }],
|
|
16
|
-
'vcs.repository.url.full' => [:to_s, -> { Utils.git('config', '--get', 'remote.origin.url') }],
|
|
17
|
-
'vcs.repository.name' => [
|
|
18
|
-
:to_s,
|
|
19
|
-
lambda {
|
|
20
|
-
url = Utils.git('config', '--get', 'remote.origin.url')
|
|
21
|
-
Utils.repository_name_from_url(url) if url
|
|
22
|
-
}
|
|
23
|
-
]
|
|
24
|
-
}.freeze
|
|
25
|
-
|
|
26
|
-
def detect
|
|
27
|
-
return OpenTelemetry::SDK::Resources::Resource.create({}) if Utils.ci_provider.nil?
|
|
28
|
-
|
|
29
|
-
attributes = Utils.get_attributes(GIT_MAPPING)
|
|
30
|
-
OpenTelemetry::SDK::Resources::Resource.create(attributes)
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'json'
|
|
4
|
-
require 'opentelemetry-sdk'
|
|
5
|
-
require_relative '../utils'
|
|
6
|
-
|
|
7
|
-
module Mergify
|
|
8
|
-
module RSpec
|
|
9
|
-
module Resources
|
|
10
|
-
# Detects OpenTelemetry Resource attributes for GitHub Actions.
|
|
11
|
-
module GitHubActions
|
|
12
|
-
module_function
|
|
13
|
-
|
|
14
|
-
def detect
|
|
15
|
-
return OpenTelemetry::SDK::Resources::Resource.create({}) if Utils.ci_provider != :github_actions
|
|
16
|
-
|
|
17
|
-
attributes = Utils.get_attributes(GHA_MAPPING)
|
|
18
|
-
OpenTelemetry::SDK::Resources::Resource.create(attributes)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
GHA_MAPPING = {
|
|
22
|
-
'cicd.pipeline.name' => [:to_s, 'GITHUB_WORKFLOW'],
|
|
23
|
-
'cicd.pipeline.task.name' => [:to_s, 'GITHUB_JOB'],
|
|
24
|
-
'cicd.pipeline.run.id' => [:to_i, 'GITHUB_RUN_ID'],
|
|
25
|
-
'cicd.pipeline.run.attempt' => [:to_i, 'GITHUB_RUN_ATTEMPT'],
|
|
26
|
-
'cicd.pipeline.runner.name' => [:to_s, 'RUNNER_NAME'],
|
|
27
|
-
'vcs.ref.head.name' => [:to_s, -> { head_ref_name }],
|
|
28
|
-
'vcs.ref.head.type' => [:to_s, 'GITHUB_REF_TYPE'],
|
|
29
|
-
'vcs.ref.base.name' => [:to_s, 'GITHUB_BASE_REF'],
|
|
30
|
-
'vcs.repository.name' => [:to_s, 'GITHUB_REPOSITORY'],
|
|
31
|
-
'vcs.repository.id' => [:to_i, 'GITHUB_REPOSITORY_ID'],
|
|
32
|
-
'vcs.repository.url.full' => [:to_s, -> { repository_url }],
|
|
33
|
-
'vcs.ref.head.revision' => [:to_s, -> { head_sha }]
|
|
34
|
-
}.freeze
|
|
35
|
-
|
|
36
|
-
def head_ref_name
|
|
37
|
-
ref = ENV.fetch('GITHUB_HEAD_REF', '')
|
|
38
|
-
ref.empty? ? ENV.fetch('GITHUB_REF_NAME', nil) : ref
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def repository_url
|
|
42
|
-
server = ENV.fetch('GITHUB_SERVER_URL', nil)
|
|
43
|
-
repo = ENV.fetch('GITHUB_REPOSITORY', nil)
|
|
44
|
-
"#{server}/#{repo}" if server && repo
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def head_sha
|
|
48
|
-
if ENV.fetch('GITHUB_EVENT_NAME', nil) == 'pull_request'
|
|
49
|
-
event_path = ENV.fetch('GITHUB_EVENT_PATH', nil)
|
|
50
|
-
if event_path && File.file?(event_path)
|
|
51
|
-
event = JSON.parse(File.read(event_path))
|
|
52
|
-
return event.dig('pull_request', 'head', 'sha').to_s
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
ENV.fetch('GITHUB_SHA', nil)
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'opentelemetry-sdk'
|
|
4
|
-
require_relative '../utils'
|
|
5
|
-
require_relative 'git'
|
|
6
|
-
|
|
7
|
-
module Mergify
|
|
8
|
-
module RSpec
|
|
9
|
-
module Resources
|
|
10
|
-
# Detects OpenTelemetry Resource attributes for Jenkins.
|
|
11
|
-
module Jenkins
|
|
12
|
-
module_function
|
|
13
|
-
|
|
14
|
-
GIT_BRANCH_PREFIXES = %w[origin/ refs/heads/].freeze
|
|
15
|
-
|
|
16
|
-
JENKINS_MAPPING = {
|
|
17
|
-
'cicd.pipeline.name' => [:to_s, 'JOB_NAME'],
|
|
18
|
-
'cicd.pipeline.task.name' => [:to_s, 'JOB_NAME'],
|
|
19
|
-
'cicd.pipeline.run.id' => [:to_s, 'BUILD_ID'],
|
|
20
|
-
'cicd.pipeline.run.url' => [:to_s, 'BUILD_URL'],
|
|
21
|
-
'cicd.pipeline.runner.name' => [:to_s, 'NODE_NAME'],
|
|
22
|
-
'vcs.ref.head.name' => [:to_s, -> { branch }],
|
|
23
|
-
'vcs.ref.head.revision' => [:to_s, 'GIT_COMMIT'],
|
|
24
|
-
'vcs.repository.url.full' => [:to_s, 'GIT_URL'],
|
|
25
|
-
'vcs.repository.name' => [
|
|
26
|
-
:to_s,
|
|
27
|
-
lambda {
|
|
28
|
-
url = ENV.fetch('GIT_URL', nil)
|
|
29
|
-
Utils.repository_name_from_url(url) if url
|
|
30
|
-
}
|
|
31
|
-
]
|
|
32
|
-
}.freeze
|
|
33
|
-
|
|
34
|
-
def detect
|
|
35
|
-
return OpenTelemetry::SDK::Resources::Resource.create({}) if Utils.ci_provider != :jenkins
|
|
36
|
-
|
|
37
|
-
git_attrs = Utils.get_attributes(Git::GIT_MAPPING)
|
|
38
|
-
jenkins_attrs = Utils.get_attributes(JENKINS_MAPPING)
|
|
39
|
-
merged = git_attrs.merge(jenkins_attrs)
|
|
40
|
-
OpenTelemetry::SDK::Resources::Resource.create(merged)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def branch
|
|
44
|
-
raw = ENV.fetch('GIT_BRANCH', nil)
|
|
45
|
-
return nil unless raw
|
|
46
|
-
|
|
47
|
-
GIT_BRANCH_PREFIXES.each do |prefix|
|
|
48
|
-
return raw[prefix.length..] if raw.start_with?(prefix)
|
|
49
|
-
end
|
|
50
|
-
raw
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'opentelemetry-sdk'
|
|
4
|
-
require_relative '../utils'
|
|
5
|
-
|
|
6
|
-
module Mergify
|
|
7
|
-
module RSpec
|
|
8
|
-
module Resources
|
|
9
|
-
# Detects OpenTelemetry Resource attributes for Mergify-specific fields.
|
|
10
|
-
module Mergify
|
|
11
|
-
module_function
|
|
12
|
-
|
|
13
|
-
MERGIFY_MAPPING = {
|
|
14
|
-
'mergify.test.job.name' => [:to_s, 'MERGIFY_TEST_JOB_NAME']
|
|
15
|
-
}.freeze
|
|
16
|
-
|
|
17
|
-
def detect
|
|
18
|
-
attributes = Utils.get_attributes(MERGIFY_MAPPING)
|
|
19
|
-
OpenTelemetry::SDK::Resources::Resource.create(attributes)
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|