rspec-mergify 0.1.4 → 0.3.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.
@@ -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
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'opentelemetry-sdk'
4
-
5
- module Mergify
6
- module RSpec
7
- class ExportError < StandardError; end
8
-
9
- # A span processor that queues spans in memory and exports them all in one
10
- # batch when force_flush is called. This avoids HTTP requests during test
11
- # execution.
12
- class SynchronousBatchSpanProcessor < OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor
13
- def initialize(exporter)
14
- super
15
- @queue = []
16
- end
17
-
18
- def on_finish(span)
19
- return unless span.context.trace_flags.sampled?
20
-
21
- @queue << span.to_span_data
22
- end
23
-
24
- def force_flush(timeout: nil) # rubocop:disable Lint/UnusedMethodArgument
25
- spans = @queue.dup
26
- @queue.clear
27
- result = @span_exporter.export(spans)
28
- raise ExportError, 'Failed to export traces' unless result == OpenTelemetry::SDK::Trace::Export::SUCCESS
29
-
30
- OpenTelemetry::SDK::Trace::Export::SUCCESS
31
- end
32
- end
33
- end
34
- end