-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3424 from DataDog/anmarchenko/source_code_integra…
…tion [CIVIS-8604] APM source code integration
- Loading branch information
Showing
15 changed files
with
345 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../git/ext' | ||
require_relative '../utils/url' | ||
|
||
module Datadog | ||
module Core | ||
module Environment | ||
# Retrieves git repository information from environment variables | ||
module Git | ||
def self.git_repository_url | ||
return @git_repository_url if defined?(@git_repository_url) | ||
|
||
@git_repository_url = Utils::Url.filter_basic_auth(ENV[Datadog::Core::Git::Ext::ENV_REPOSITORY_URL]) | ||
end | ||
|
||
def self.git_commit_sha | ||
return @git_commit_sha if defined?(@git_commit_sha) | ||
|
||
@git_commit_sha = ENV[Datadog::Core::Git::Ext::ENV_COMMIT_SHA] | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'uri' | ||
|
||
module Datadog | ||
module Core | ||
module Utils | ||
# Helpers class that provides methods to process URLs | ||
# such as filtering sensitive information. | ||
module Url | ||
def self.filter_basic_auth(url) | ||
return nil if url.nil? | ||
|
||
URI(url).tap do |u| | ||
u.user = nil | ||
u.password = nil | ||
end.to_s | ||
# Git scheme: git@github.com:DataDog/dd-trace-rb.git | ||
rescue URI::InvalidURIError | ||
url | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Datadog | ||
module Core | ||
module Environment | ||
module Git | ||
@git_repository_url: String? | ||
|
||
@git_commit_sha: String? | ||
|
||
def self?.git_repository_url: () -> String? | ||
|
||
def self?.git_commit_sha: () -> String? | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Datadog | ||
module Core | ||
module Utils | ||
module Url | ||
def self?.filter_basic_auth: (::String? url) -> ::String? | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
require 'spec_helper' | ||
|
||
require 'datadog/core/environment/git' | ||
|
||
RSpec.describe Datadog::Core::Environment::Git do | ||
def remove_cached_variables | ||
if described_class.instance_variable_defined?(:@git_repository_url) | ||
described_class.remove_instance_variable(:@git_repository_url) | ||
end | ||
|
||
if described_class.instance_variable_defined?(:@git_commit_sha) | ||
described_class.remove_instance_variable(:@git_commit_sha) | ||
end | ||
end | ||
|
||
around do |example| | ||
ClimateControl.modify(env_key => env_value) do | ||
example.run | ||
end | ||
end | ||
|
||
before do | ||
remove_cached_variables | ||
end | ||
|
||
after do | ||
remove_cached_variables | ||
end | ||
|
||
describe '.git_repository_url' do | ||
subject { described_class.git_repository_url } | ||
|
||
let(:env_key) { Datadog::Core::Git::Ext::ENV_REPOSITORY_URL } | ||
let(:env_value) { 'https://gitlab-ci-token:AAA_bbb@gitlab.com/DataDog/systems-test.git' } | ||
|
||
it { is_expected.to eq('https://gitlab.com/DataDog/systems-test.git') } | ||
end | ||
|
||
describe '.git_commit_sha' do | ||
subject { described_class.git_commit_sha } | ||
|
||
let(:env_key) { Datadog::Core::Git::Ext::ENV_COMMIT_SHA } | ||
let(:env_value) { '1234567890abcdef' } | ||
|
||
it { is_expected.to eq('1234567890abcdef') } | ||
end | ||
end |
Oops, something went wrong.