Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ci-app] Add User Provided Git Metadata #1662

Merged
merged 11 commits into from
Sep 8, 2021

Conversation

juan-fernandez
Copy link
Contributor

@juan-fernandez juan-fernandez commented Aug 27, 2021

Motivation

Provide a way for users to provide git metadata when other methods fail.

How

  • Read certain environment variables and set them as span tags if they're present. These take precedence over other methods to get git metadata.

Note: I don't understand what's happening with sorbet's job. If I run the typecheck in master the same errors show, so I'm not sure if they're related to my changes. Also, the files with errors seem not to be the ones I changed?

Copy link
Contributor

@AdrianLC AdrianLC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM left some minor suggestions

lib/datadog/ci/ext/environment.rb Outdated Show resolved Hide resolved
lib/datadog/ci/ext/environment.rb Outdated Show resolved Hide resolved
Co-authored-by: Adrián López Calvo <adrian.lopezcalvo@datadoghq.com>
@juan-fernandez juan-fernandez marked this pull request as ready for review August 27, 2021 10:14
@juan-fernandez juan-fernandez requested a review from a team August 27, 2021 10:14
Copy link
Contributor

@delner delner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall seems fine, but I think we should migrate some constants to follow convention.

Datadog::Ext::Git::TAG_COMMIT_COMMITTER_NAME => env['DD_GIT_COMMIT_COMMITTER_NAME'],
Datadog::Ext::Git::TAG_COMMIT_COMMITTER_EMAIL => env['DD_GIT_COMMIT_COMMITTER_EMAIL'],
Datadog::Ext::Git::TAG_COMMIT_COMMITTER_DATE => env['DD_GIT_COMMIT_COMMITTER_DATE']
}.reject { |_, v| v.nil? || v.empty? }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend using strip on the values first, as sometimes users will introduce whitespace characters that will make the string "not empty", e.g.:

2.5.1 :002 > ' '.empty?
 => false

@@ -324,6 +327,22 @@ def extract_bitrise(env)
}
end

def extract_user_defined_git(env)
{
Datadog::Ext::Git::TAG_REPOSITORY_URL => env['DD_GIT_REPOSITORY_URL'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these strings should be frozen, migrated to Datadog::Ext::Git and prefixed with ENV_

e.g. 'DD_GIT_REPOSITORY_URL' => Datadog::Ext::Git::ENV_REPOSITORY_URL = 'DD_GIT_REPOSITORY_URL'.freeze

is_expected.to eq(
{
'ci.workspace_path' => "#{Dir.pwd}/spec/datadog/ci/ext/fixtures/git",
'git.branch' => 'my-branch',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor suggestion, but you could derive these values from the env above e.g. 'git.branch' => env['DD_GIT_BRANCH']

@marcotc marcotc merged commit fc02a07 into master Sep 8, 2021
@marcotc marcotc deleted the juan-fernandez/ci-app-add-user-provided-metadata branch September 8, 2021 19:07
@github-actions github-actions bot added this to the 0.53.0 milestone Sep 8, 2021
@marcotc marcotc added the ci-app CI product for test suite instrumentation label Sep 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci-app CI product for test suite instrumentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants