Skip to content

Commit

Permalink
pull up branch or tag logic for extractors
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Sep 4, 2023
1 parent c7a2845 commit d2a1035
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 103 deletions.
11 changes: 10 additions & 1 deletion lib/datadog/ci/ext/environment/extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,20 @@ def ci_env_vars
end

def git_branch
return @branch if defined?(@branch)

set_branch_and_tag
@branch
end

def git_repository_url
end

def git_tag
return @tag if defined?(@tag)

set_branch_and_tag
@tag
end

def git_branch_or_tag
Expand Down Expand Up @@ -164,7 +172,8 @@ def git_commit_message
def git_commit_sha
end

def branch_or_tag(branch_or_tag_string)
def set_branch_and_tag
branch_or_tag_string = git_branch_or_tag
@branch = @tag = nil
if branch_or_tag_string && branch_or_tag_string.include?("tags/")
@tag = branch_or_tag_string
Expand Down
20 changes: 2 additions & 18 deletions lib/datadog/ci/ext/environment/providers/azure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,8 @@ def git_commit_sha
env["SYSTEM_PULLREQUEST_SOURCECOMMITID"] || env["BUILD_SOURCEVERSION"]
end

def git_branch
return @branch if defined?(@branch)

set_branch_and_tag
@branch
end

def git_tag
return @tag if defined?(@tag)

set_branch_and_tag
@tag
def git_branch_or_tag
env["SYSTEM_PULLREQUEST_SOURCEBRANCH"] || env["BUILD_SOURCEBRANCH"] || env["BUILD_SOURCEBRANCHNAME"]
end

def git_commit_author_name
Expand Down Expand Up @@ -112,12 +102,6 @@ def team_project_id
def url_defined?
!(build_id && team_foundation_server_uri && team_project_id).nil?
end

def set_branch_and_tag
@branch, @tag = branch_or_tag(
env["SYSTEM_PULLREQUEST_SOURCEBRANCH"] || env["BUILD_SOURCEBRANCH"] || env["BUILD_SOURCEBRANCHNAME"]
)
end
end
end
end
Expand Down
19 changes: 2 additions & 17 deletions lib/datadog/ci/ext/environment/providers/codefresh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,15 @@ def pipeline_url
env["CF_BUILD_URL"]
end

def git_branch
return @branch if defined?(@branch)

set_branch_and_tag
@branch
end

def git_tag
return @tag if defined?(@tag)

set_branch_and_tag
@tag
def git_branch_or_tag
env["CF_BRANCH"]
end

def ci_env_vars
{
"CF_BUILD_ID" => env["CF_BUILD_ID"]
}.to_json
end

# codefresh-specific methods
def set_branch_and_tag
@branch, @tag = branch_or_tag(env["CF_BRANCH"])
end
end
end
end
Expand Down
30 changes: 4 additions & 26 deletions lib/datadog/ci/ext/environment/providers/github_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,10 @@ def git_commit_sha
env["GITHUB_SHA"]
end

def git_branch
return @branch if defined?(@branch)

set_branch_and_tag
@branch
end

def git_tag
return @tag if defined?(@tag)

set_branch_and_tag
@tag
def git_branch_or_tag
ref = env["GITHUB_HEAD_REF"]
ref = env["GITHUB_REF"] if ref.nil? || ref.empty?
ref
end

def ci_env_vars
Expand All @@ -77,20 +69,6 @@ def ci_env_vars
"GITHUB_RUN_ATTEMPT" => env["GITHUB_RUN_ATTEMPT"]
}.reject { |_, v| v.nil? }.to_json
end

# github-specific methods

def ref
return @ref if defined?(@ref)

@ref = env["GITHUB_HEAD_REF"]
@ref = env["GITHUB_REF"] if @ref.nil? || @ref.empty?
@ref
end

def set_branch_and_tag
@branch, @tag = branch_or_tag(ref)
end
end
end
end
Expand Down
20 changes: 2 additions & 18 deletions lib/datadog/ci/ext/environment/providers/jenkins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,31 +57,15 @@ def git_commit_sha
env["GIT_COMMIT"]
end

def git_branch
return @branch if defined?(@branch)

set_branch_and_tag
@branch
end

def git_tag
return @tag if defined?(@tag)

set_branch_and_tag
@tag
def git_branch_or_tag
env["GIT_BRANCH"]
end

def ci_env_vars
{
"DD_CUSTOM_TRACE_ID" => env["DD_CUSTOM_TRACE_ID"]
}.to_json
end

# jenkins-specific methods

def set_branch_and_tag
@branch, @tag = branch_or_tag(env["GIT_BRANCH"])
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion sig/datadog/ci/ext/environment/extractor.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module Datadog

def git_commit_sha: () -> nil

def branch_or_tag: (String? branch_or_tag_string) -> [String?, String?]
def set_branch_and_tag: () -> [String?, String?]

def normalize_ref: (String? name) -> String?

Expand Down
6 changes: 1 addition & 5 deletions sig/datadog/ci/ext/environment/providers/azure.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ module Datadog

def git_commit_sha: () -> String?

def git_branch: () -> String?

def git_tag: () -> String?
def git_branch_or_tag: () -> String?

def git_commit_author_name: () -> String?

Expand All @@ -50,8 +48,6 @@ module Datadog
def team_project_id: () -> String?

def url_defined?: () -> bool

def set_branch_and_tag: () -> [String?, String?]
end
end
end
Expand Down
6 changes: 1 addition & 5 deletions sig/datadog/ci/ext/environment/providers/codefresh.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@ module Datadog

def pipeline_url: () -> String?

def git_branch: () -> String?

def git_tag: () -> String?
def git_branch_or_tag: () -> String?

def ci_env_vars: () -> String

def set_branch_and_tag: () -> [String?, String?]
end
end
end
Expand Down
8 changes: 1 addition & 7 deletions sig/datadog/ci/ext/environment/providers/github_actions.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,9 @@ module Datadog

def git_commit_sha: () -> String?

def git_branch: () -> String?

def git_tag: () -> String?
def git_branch_or_tag: () -> String?

def ci_env_vars: () -> String?

def ref: () -> String

def set_branch_and_tag: () -> [String?, String?]
end
end
end
Expand Down
6 changes: 1 addition & 5 deletions sig/datadog/ci/ext/environment/providers/jenkins.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,9 @@ module Datadog

def git_commit_sha: () -> String?

def git_branch: () -> String?

def git_tag: () -> String?
def git_branch_or_tag: () -> String?

def ci_env_vars: () -> String?

def set_branch_and_tag: () -> [String?, String?]
end
end
end
Expand Down

0 comments on commit d2a1035

Please sign in to comment.