lib/datadog/ci/ext/environment.rb in ddtrace-0.53.0 vs lib/datadog/ci/ext/environment.rb in ddtrace-0.54.0
- old
+ new
@@ -38,36 +38,38 @@
].freeze
module_function
def tags(env)
+ # Extract metadata from CI provider environment variables
_, extractor = PROVIDERS.find { |provider_env_var, _| env.key?(provider_env_var) }
- if extractor
- tags = public_send(extractor, env)
+ tags = extractor ? public_send(extractor, env).reject { |_, v| v.nil? || v.strip.empty? } : {}
+ tags.delete(Datadog::Ext::Git::TAG_BRANCH) unless tags[Datadog::Ext::Git::TAG_TAG].nil?
- tags[Datadog::Ext::Git::TAG_TAG] = normalize_ref(tags[Datadog::Ext::Git::TAG_TAG])
- tags.delete(Datadog::Ext::Git::TAG_BRANCH) unless tags[Datadog::Ext::Git::TAG_TAG].nil?
- tags[Datadog::Ext::Git::TAG_BRANCH] = normalize_ref(tags[Datadog::Ext::Git::TAG_BRANCH])
- tags[Datadog::Ext::Git::TAG_REPOSITORY_URL] = filter_sensitive_info(tags[Datadog::Ext::Git::TAG_REPOSITORY_URL])
+ # If user defined metadata is defined, overwrite
+ tags.merge!(extract_user_defined_git(env))
+ if !tags[Datadog::Ext::Git::TAG_BRANCH].nil? && tags[Datadog::Ext::Git::TAG_BRANCH].include?('tags/')
+ tags[Datadog::Ext::Git::TAG_TAG] = tags[Datadog::Ext::Git::TAG_BRANCH]
+ tags.delete(Datadog::Ext::Git::TAG_BRANCH)
+ end
- # Expand ~
- workspace_path = tags[TAG_WORKSPACE_PATH]
- if !workspace_path.nil? && (workspace_path == '~' || workspace_path.start_with?('~/'))
- tags[TAG_WORKSPACE_PATH] = File.expand_path(workspace_path)
- end
- else
- tags = {}
+ # Normalize Git references
+ tags[Datadog::Ext::Git::TAG_TAG] = normalize_ref(tags[Datadog::Ext::Git::TAG_TAG])
+ tags[Datadog::Ext::Git::TAG_BRANCH] = normalize_ref(tags[Datadog::Ext::Git::TAG_BRANCH])
+ tags[Datadog::Ext::Git::TAG_REPOSITORY_URL] = filter_sensitive_info(tags[Datadog::Ext::Git::TAG_REPOSITORY_URL])
+
+ # Expand ~
+ workspace_path = tags[TAG_WORKSPACE_PATH]
+ if !workspace_path.nil? && (workspace_path == '~' || workspace_path.start_with?('~/'))
+ tags[TAG_WORKSPACE_PATH] = File.expand_path(workspace_path)
end
# Fill out tags from local git as fallback
extract_local_git.each do |key, value|
tags[key] ||= value
end
- # If user defined metadata is defined, overwrite
- tags.merge!(extract_user_defined_git(env))
-
tags.reject { |_, v| v.nil? }
end
def normalize_ref(name)
refs = %r{^refs/(heads/)?}
@@ -209,19 +211,22 @@
def extract_github_actions(env)
ref = env['GITHUB_HEAD_REF']
ref = env['GITHUB_REF'] if ref.nil? || ref.empty?
branch, tag = branch_or_tag(ref)
+ pipeline_url = "#{env['GITHUB_SERVER_URL']}/#{env['GITHUB_REPOSITORY']}/actions/runs/#{env['GITHUB_RUN_ID']}"
+ pipeline_url = "#{pipeline_url}/attempts/#{env['GITHUB_RUN_ATTEMPT']}" if env['GITHUB_RUN_ATTEMPT']
+
{
Datadog::Ext::Git::TAG_BRANCH => branch,
Datadog::Ext::Git::TAG_COMMIT_SHA => env['GITHUB_SHA'],
- Datadog::Ext::Git::TAG_REPOSITORY_URL => "https://github.com/#{env['GITHUB_REPOSITORY']}.git",
+ Datadog::Ext::Git::TAG_REPOSITORY_URL => "#{env['GITHUB_SERVER_URL']}/#{env['GITHUB_REPOSITORY']}.git",
Datadog::Ext::Git::TAG_TAG => tag,
- TAG_JOB_URL => "https://github.com/#{env['GITHUB_REPOSITORY']}/commit/#{env['GITHUB_SHA']}/checks",
+ TAG_JOB_URL => "#{env['GITHUB_SERVER_URL']}/#{env['GITHUB_REPOSITORY']}/commit/#{env['GITHUB_SHA']}/checks",
TAG_PIPELINE_ID => env['GITHUB_RUN_ID'],
TAG_PIPELINE_NAME => env['GITHUB_WORKFLOW'],
TAG_PIPELINE_NUMBER => env['GITHUB_RUN_NUMBER'],
- TAG_PIPELINE_URL => "https://github.com/#{env['GITHUB_REPOSITORY']}/commit/#{env['GITHUB_SHA']}/checks",
+ TAG_PIPELINE_URL => pipeline_url,
TAG_PROVIDER_NAME => 'github',
TAG_WORKSPACE_PATH => env['GITHUB_WORKSPACE'],
Datadog::Ext::Git::TAG_COMMIT_AUTHOR_NAME => env['BUILD_REQUESTEDFORID'],
Datadog::Ext::Git::TAG_COMMIT_AUTHOR_EMAIL => env['BUILD_REQUESTEDFOREMAIL'],
Datadog::Ext::Git::TAG_COMMIT_MESSAGE => env['BUILD_SOURCEVERSIONMESSAGE']