Skip to content

Commit

Permalink
feat: add Bitbucket Cloud support for TMC.
Browse files Browse the repository at this point in the history
Signed-off-by: i4k <[email protected]>
  • Loading branch information
i4ki committed Dec 18, 2024
1 parent 2692960 commit 019719b
Show file tree
Hide file tree
Showing 21 changed files with 642 additions and 43 deletions.
34 changes: 34 additions & 0 deletions bitbucket-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2024 Terramate GmbH
# SPDX-License-Identifier: MPL-2.0

image: golang

clone:
enabled: true
depth: full

pipelines:
pull-requests:
'**':
- step:
name: 'build Terramate'
script:
- make build
- go install github.com/hashicorp/hc-install/cmd/hc-install@latest
- hc-install install -version 1.6.0 terraform
- cp ./terraform /usr/local/bin/terraform
- export TMC_API_HOST=api.stg.terramate.io
- export TM_CLOUD_ORGANIZATION=test
- ./bin/terramate run --changed --sync-preview --terraform-plan-file=out.tfplan --target linux-go-packages --parallel 12 -- terraform plan -detailed-exitcode -out=out.tfplan
branches:
main:
- step:
name: 'build Terramate'
script:
- make build
- go install github.com/hashicorp/hc-install/cmd/hc-install@latest
- hc-install install -version 1.6.0 terraform
- cp ./terraform /usr/local/bin/terraform
- export TMC_API_HOST=api.stg.terramate.io
- export TM_CLOUD_ORGANIZATION=test
- ./bin/terramate run --changed --sync-deployment --terraform-plan-file=out.tfplan --target linux-go-packages --parallel 12 -- terraform plan -out=out.tfplan
45 changes: 45 additions & 0 deletions ci/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,51 @@ func DetectPlatformFromEnv() PlatformType {
return typ
}

func (plat PlatformType) String() string {
switch plat {
case PlatformLocal:
return "local"
case PlatformGithub:
return "github"
case PlatformGitlab:
return "gitlab"
case PlatformGenericCI:
return "generic"
case PlatformAppVeyor:
return "appveyor"
case PlatformAzureDevops:
return "azuredevops"
case PlatformBamboo:
return "bamboo"
case PlatformBitBucket:
return "bitbucket"
case PlatformBuddyWorks:
return "buddyworks"
case PlatformBuildKite:
return "buildkite"
case PlatformCircleCI:
return "circleci"
case PlatformCirrus:
return "cirrus"
case PlatformCodeBuild:
return "codebuild"
case PlatformHeroku:
return "heroku"
case PlatformHudson:
return "hudson"
case PlatformJenkins:
return "jenkins"
case PlatformMyGet:
return "myget"
case PlatformTeamCity:
return "teamcity"
case PlatformTravis:
return "travis"
default:
return "unknown"
}
}

func isEnvVarSet(key string) bool {
val := os.Getenv(key)
return val != "" && val != "0" && val != "false"
Expand Down
26 changes: 25 additions & 1 deletion cloud/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ type (
GitMetadata
GithubMetadata
GitlabMetadata
BitbucketMetadata
}

// GitMetadata are the git related metadata.
Expand Down Expand Up @@ -277,6 +278,29 @@ type (
GitlabCICDMergeRequestApproved *bool `json:"gitlab_cicd_merge_request_approved,omitempty"` // CI_MERGE_REQUEST_APPROVED
}

// BitbucketMetadata holds the Bitbucket specific metadata.
BitbucketMetadata struct {
BitbucketPipelinesBuildNumber string `json:"bitbucket_pipelines_build_number,omitempty"`
BitbucketPipelinesPipelineUUID string `json:"bitbucket_pipelines_pipeline_uuid,omitempty"`
BitbucketPipelinesCommit string `json:"bitbucket_pipelines_commit,omitempty"`
BitbucketPipelinesWorkspace string `json:"bitbucket_pipelines_workspace,omitempty"`
BitbucketPipelinesRepoSlug string `json:"bitbucket_pipelines_repo_slug,omitempty"`
BitbucketPipelinesRepoUUID string `json:"bitbucket_pipelines_repo_uuid,omitempty"`
BitbucketPipelinesRepoFullName string `json:"bitbucket_pipelines_repo_full_name,omitempty"`
BitbucketPipelinesBranch string `json:"bitbucket_pipelines_branch,omitempty"`
BitbucketPipelinesDestinationBranch string `json:"bitbucket_pipelines_destination_branch,omitempty"`
BitbucketPipelinesTag string `json:"bitbucket_pipelines_tag,omitempty"` // only available in tag events.
BitbucketPipelinesStepTriggererUUID string `json:"bitbucket_pipelines_step_triggerer_uuid,omitempty"`
BitbucketPipelinesParallelStep string `json:"bitbucket_pipelines_parallel_step,omitempty"`
BitbucketPipelinesParallelStepCount string `json:"bitbucket_pipelines_parallel_step_count,omitempty"`
BitbucketPipelinesPRID string `json:"bitbucket_pipelines_pr_id,omitempty"` // only available in PR events.
BitbucketPipelinesStepUUID string `json:"bitbucket_pipelines_step_uuid,omitempty"`
BitbucketPipelinesDeploymentEnvironment string `json:"bitbucket_pipelines_deployment_environment,omitempty"`
BitbucketPipelinesDeploymentEnvironmentUUID string `json:"bitbucket_pipelines_deployment_environment_uuid,omitempty"`
BitbucketPipelinesProjectKey string `json:"bitbucket_pipelines_project_key,omitempty"`
BitbucketPipelinesProjectUUID string `json:"bitbucket_pipelines_project_uuid,omitempty"`
}

// ReviewRequest is the review_request object.
ReviewRequest struct {
Platform string `json:"platform"`
Expand All @@ -299,7 +323,7 @@ type (
ChecksSuccessCount int `json:"checks_success_count"`
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
PushedAt *time.Time `json:"pushed_at,omitempty"`
PushedAt *int64 `json:"pushed_at,omitempty"`
Branch string `json:"branch"`
BaseBranch string `json:"base_branch"`
}
Expand Down
23 changes: 23 additions & 0 deletions cmd/terramate/cli/bitbucket/_test_mock.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT

resource "local_file" "bitbucket" {
content = <<-EOT
package bitbucket // import "github.com/terramate-io/terramate/cmd/terramate/cli/bitbucket"
Package bitbucket implements the client for Bitbucket Cloud.
type Actor struct{ ... }
type Branch struct{ ... }
type Client struct{ ... }
type Commit struct{ ... }
type PR struct{ ... }
type PRs []PR
type PullRequestResponse struct{ ... }
type Rendered struct{ ... }
type RenderedContent struct{ ... }
type Summary RenderedContent
type TargetBranch struct{ ... }
EOT

filename = "${path.module}/mock-bitbucket.ignore"
}
Loading

0 comments on commit 019719b

Please sign in to comment.