Skip to content

Commit

Permalink
extract bitrise
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Sep 4, 2023
1 parent 3b898c1 commit ca3b200
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 32 deletions.
31 changes: 0 additions & 31 deletions lib/datadog/ci/ext/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ module Environment
TAG_CI_ENV_VARS = "_dd.ci.env_vars"

PROVIDERS = [
["BITRISE_BUILD_SLUG", :extract_bitrise],
["CF_BUILD_ID", :extract_codefresh]
].freeze

Expand Down Expand Up @@ -76,36 +75,6 @@ def filter_sensitive_info(url)
end

# CI providers
def extract_bitrise(env)
commit = (
env["BITRISE_GIT_COMMIT"] || env["GIT_CLONE_COMMIT_HASH"]
)
branch = (
env["BITRISEIO_GIT_BRANCH_DEST"] || env["BITRISE_GIT_BRANCH"]
)
commiter_email = (
env["GIT_CLONE_COMMIT_COMMITER_EMAIL"] || env["GIT_CLONE_COMMIT_COMMITER_NAME"]
)

{
TAG_PROVIDER_NAME => "bitrise",
TAG_PIPELINE_ID => env["BITRISE_BUILD_SLUG"],
TAG_PIPELINE_NAME => env["BITRISE_TRIGGERED_WORKFLOW_ID"],
TAG_PIPELINE_NUMBER => env["BITRISE_BUILD_NUMBER"],
TAG_PIPELINE_URL => env["BITRISE_BUILD_URL"],
TAG_WORKSPACE_PATH => env["BITRISE_SOURCE_DIR"],
Git::TAG_REPOSITORY_URL => env["GIT_REPOSITORY_URL"],
Git::TAG_COMMIT_SHA => commit,
Git::TAG_BRANCH => branch,
Git::TAG_TAG => env["BITRISE_GIT_TAG"],
Git::TAG_COMMIT_MESSAGE => env["BITRISE_GIT_MESSAGE"],
Git::TAG_COMMIT_AUTHOR_NAME => env["GIT_CLONE_COMMIT_AUTHOR_NAME"],
Git::TAG_COMMIT_AUTHOR_EMAIL => env["GIT_CLONE_COMMIT_AUTHOR_EMAIL"],
Git::TAG_COMMIT_COMMITTER_NAME => env["GIT_CLONE_COMMIT_COMMITER_NAME"],
Git::TAG_COMMIT_COMMITTER_EMAIL => commiter_email
}
end

def extract_codefresh(env)
branch, tag = branch_or_tag(env["CF_BRANCH"])

Expand Down
4 changes: 3 additions & 1 deletion lib/datadog/ci/ext/environment/extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Extractor
require_relative "providers/jenkins"
require_relative "providers/teamcity"
require_relative "providers/travis"
require_relative "providers/bitrise"

PROVIDERS = [
["APPVEYOR", Providers::Appveyor],
Expand All @@ -35,7 +36,8 @@ class Extractor
["GITLAB_CI", Providers::Gitlab],
["JENKINS_URL", Providers::Jenkins],
["TEAMCITY_VERSION", Providers::Teamcity],
["TRAVIS", Providers::Travis]
["TRAVIS", Providers::Travis],
["BITRISE_BUILD_SLUG", Providers::Bitrise]
]

def self.for_environment(env)
Expand Down
80 changes: 80 additions & 0 deletions lib/datadog/ci/ext/environment/providers/bitrise.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# frozen_string_literal: true

require_relative "../extractor"

module Datadog
module CI
module Ext
module Environment
module Providers
# Bitrise: https://bitrise.io/
# Environment variables docs: https://devcenter.bitrise.io/en/references/available-environment-variables.html
class Bitrise < Extractor
private

# overridden methods
def provider_name
"bitrise"
end

def pipeline_id
env["BITRISE_BUILD_SLUG"]
end

def pipeline_name
env["BITRISE_TRIGGERED_WORKFLOW_ID"]
end

def pipeline_number
env["BITRISE_BUILD_NUMBER"]
end

def pipeline_url
env["BITRISE_BUILD_URL"]
end

def workspace_path
env["BITRISE_SOURCE_DIR"]
end

def git_repository_url
env["GIT_REPOSITORY_URL"]
end

def git_commit_sha
env["BITRISE_GIT_COMMIT"] || env["GIT_CLONE_COMMIT_HASH"]
end

def git_branch
env["BITRISEIO_GIT_BRANCH_DEST"] || env["BITRISE_GIT_BRANCH"]
end

def git_tag
env["BITRISE_GIT_TAG"]
end

def git_commit_message
env["BITRISE_GIT_MESSAGE"]
end

def git_commit_author_name
env["GIT_CLONE_COMMIT_AUTHOR_NAME"]
end

def git_commit_author_email
env["GIT_CLONE_COMMIT_AUTHOR_EMAIL"]
end

def git_commit_committer_name
env["GIT_CLONE_COMMIT_COMMITER_NAME"]
end

def git_commit_committer_email
env["GIT_CLONE_COMMIT_COMMITER_EMAIL"] || env["GIT_CLONE_COMMIT_COMMITER_NAME"]
end
end
end
end
end
end
end
42 changes: 42 additions & 0 deletions sig/datadog/ci/ext/environment/providers/bitrise.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module Datadog
module CI
module Ext
module Environment
module Providers
class Bitrise < Extractor
private
def provider_name: () -> "bitrise"

def pipeline_id: () -> String?

def pipeline_name: () -> String?

def pipeline_number: () -> String?

def pipeline_url: () -> String?

def workspace_path: () -> String?

def git_repository_url: () -> String?

def git_commit_sha: () -> String?

def git_branch: () -> String?

def git_tag: () -> String?

def git_commit_message: () -> String?

def git_commit_author_name: () -> String?

def git_commit_author_email: () -> String?

def git_commit_committer_name: () -> String?

def git_commit_committer_email: () -> String?
end
end
end
end
end
end

0 comments on commit ca3b200

Please sign in to comment.