From 10951f0efe68a32ef10f89f52215152a5baced64 Mon Sep 17 00:00:00 2001 From: Greeshma Date: Wed, 18 Dec 2024 01:41:07 +0530 Subject: [PATCH] APPS-9365: Add bitbucket source to app spec (#764) --- apps.gen.go | 78 +++++++++++++++++++++++----------------- apps.go | 15 +++++--- apps_accessors.go | 80 ++++++++++++++++++++++++++++++++++++++++++ apps_accessors_test.go | 70 ++++++++++++++++++++++++++++++++++++ apps_test.go | 12 ++++--- 5 files changed, 214 insertions(+), 41 deletions(-) diff --git a/apps.gen.go b/apps.gen.go index 6fc029cb..63457cda 100644 --- a/apps.gen.go +++ b/apps.gen.go @@ -285,10 +285,11 @@ const ( // AppFunctionsSpec struct for AppFunctionsSpec type AppFunctionsSpec struct { // The name. Must be unique across all components within the same app. - Name string `json:"name"` - Git *GitSourceSpec `json:"git,omitempty"` - GitHub *GitHubSourceSpec `json:"github,omitempty"` - GitLab *GitLabSourceSpec `json:"gitlab,omitempty"` + Name string `json:"name"` + Git *GitSourceSpec `json:"git,omitempty"` + GitHub *GitHubSourceSpec `json:"github,omitempty"` + GitLab *GitLabSourceSpec `json:"gitlab,omitempty"` + Bitbucket *BitbucketSourceSpec `json:"bitbucket,omitempty"` // An optional path to the working directory to use for the build. Must be relative to the root of the repo. SourceDir string `json:"source_dir,omitempty"` // A list of environment variables made available to the component. @@ -365,11 +366,12 @@ type AppIngressSpecRuleStringMatch struct { // AppJobSpec struct for AppJobSpec type AppJobSpec struct { // The name. Must be unique across all components within the same app. - Name string `json:"name"` - Git *GitSourceSpec `json:"git,omitempty"` - GitHub *GitHubSourceSpec `json:"github,omitempty"` - Image *ImageSourceSpec `json:"image,omitempty"` - GitLab *GitLabSourceSpec `json:"gitlab,omitempty"` + Name string `json:"name"` + Git *GitSourceSpec `json:"git,omitempty"` + GitHub *GitHubSourceSpec `json:"github,omitempty"` + Image *ImageSourceSpec `json:"image,omitempty"` + GitLab *GitLabSourceSpec `json:"gitlab,omitempty"` + Bitbucket *BitbucketSourceSpec `json:"bitbucket,omitempty"` // The path to the Dockerfile relative to the root of the repo. If set, it will be used to build this component. Otherwise, App Platform will attempt to build it using buildpacks. DockerfilePath string `json:"dockerfile_path,omitempty"` // An optional build command to run while building this component from source. @@ -481,11 +483,12 @@ type AppRouteSpec struct { // AppServiceSpec struct for AppServiceSpec type AppServiceSpec struct { // The name. Must be unique across all components within the same app. - Name string `json:"name"` - Git *GitSourceSpec `json:"git,omitempty"` - GitHub *GitHubSourceSpec `json:"github,omitempty"` - Image *ImageSourceSpec `json:"image,omitempty"` - GitLab *GitLabSourceSpec `json:"gitlab,omitempty"` + Name string `json:"name"` + Git *GitSourceSpec `json:"git,omitempty"` + GitHub *GitHubSourceSpec `json:"github,omitempty"` + Image *ImageSourceSpec `json:"image,omitempty"` + GitLab *GitLabSourceSpec `json:"gitlab,omitempty"` + Bitbucket *BitbucketSourceSpec `json:"bitbucket,omitempty"` // The path to the Dockerfile relative to the root of the repo. If set, it will be used to build this component. Otherwise, App Platform will attempt to build it using buildpacks. DockerfilePath string `json:"dockerfile_path,omitempty"` // An optional build command to run while building this component from source. @@ -578,10 +581,11 @@ type AppSpec struct { // AppStaticSiteSpec struct for AppStaticSiteSpec type AppStaticSiteSpec struct { // The name. Must be unique across all components within the same app. - Name string `json:"name"` - Git *GitSourceSpec `json:"git,omitempty"` - GitHub *GitHubSourceSpec `json:"github,omitempty"` - GitLab *GitLabSourceSpec `json:"gitlab,omitempty"` + Name string `json:"name"` + Git *GitSourceSpec `json:"git,omitempty"` + GitHub *GitHubSourceSpec `json:"github,omitempty"` + GitLab *GitLabSourceSpec `json:"gitlab,omitempty"` + Bitbucket *BitbucketSourceSpec `json:"bitbucket,omitempty"` // The path to the Dockerfile relative to the root of the repo. If set, it will be used to build this component. Otherwise, App Platform will attempt to build it using buildpacks. DockerfilePath string `json:"dockerfile_path,omitempty"` // An optional build command to run while building this component from source. @@ -617,11 +621,12 @@ type AppVariableDefinition struct { // AppWorkerSpec struct for AppWorkerSpec type AppWorkerSpec struct { // The name. Must be unique across all components within the same app. - Name string `json:"name"` - Git *GitSourceSpec `json:"git,omitempty"` - GitHub *GitHubSourceSpec `json:"github,omitempty"` - Image *ImageSourceSpec `json:"image,omitempty"` - GitLab *GitLabSourceSpec `json:"gitlab,omitempty"` + Name string `json:"name"` + Git *GitSourceSpec `json:"git,omitempty"` + GitHub *GitHubSourceSpec `json:"github,omitempty"` + Image *ImageSourceSpec `json:"image,omitempty"` + GitLab *GitLabSourceSpec `json:"gitlab,omitempty"` + Bitbucket *BitbucketSourceSpec `json:"bitbucket,omitempty"` // The path to the Dockerfile relative to the root of the repo. If set, it will be used to build this component. Otherwise, App Platform will attempt to build it using buildpacks. DockerfilePath string `json:"dockerfile_path,omitempty"` // An optional build command to run while building this component from source. @@ -651,6 +656,13 @@ type AppWorkerSpecTermination struct { GracePeriodSeconds int32 `json:"grace_period_seconds,omitempty"` } +// BitbucketSourceSpec struct for BitbucketSourceSpec +type BitbucketSourceSpec struct { + Repo string `json:"repo,omitempty"` + Branch string `json:"branch,omitempty"` + DeployOnPush bool `json:"deploy_on_push,omitempty"` +} + // Buildpack struct for Buildpack type Buildpack struct { // The ID of the buildpack. @@ -702,12 +714,13 @@ type DeploymentCauseDetailsDOCRPush struct { // DeploymentCauseDetailsGitPush struct for DeploymentCauseDetailsGitPush type DeploymentCauseDetailsGitPush struct { - GitHub *GitHubSourceSpec `json:"github,omitempty"` - GitLab *GitLabSourceSpec `json:"gitlab,omitempty"` - Username string `json:"username,omitempty"` - CommitAuthor string `json:"commit_author,omitempty"` - CommitSHA string `json:"commit_sha,omitempty"` - CommitMessage string `json:"commit_message,omitempty"` + GitHub *GitHubSourceSpec `json:"github,omitempty"` + GitLab *GitLabSourceSpec `json:"gitlab,omitempty"` + Bitbucket *BitbucketSourceSpec `json:"bitbucket,omitempty"` + Username string `json:"username,omitempty"` + CommitAuthor string `json:"commit_author,omitempty"` + CommitSHA string `json:"commit_sha,omitempty"` + CommitMessage string `json:"commit_message,omitempty"` } // AppCORSPolicy struct for AppCORSPolicy @@ -911,9 +924,10 @@ type DeploymentWorker struct { // DetectRequest struct for DetectRequest type DetectRequest struct { - Git *GitSourceSpec `json:"git,omitempty"` - GitHub *GitHubSourceSpec `json:"github,omitempty"` - GitLab *GitLabSourceSpec `json:"gitlab,omitempty"` + Git *GitSourceSpec `json:"git,omitempty"` + GitHub *GitHubSourceSpec `json:"github,omitempty"` + GitLab *GitLabSourceSpec `json:"gitlab,omitempty"` + Bitbucket *BitbucketSourceSpec `json:"bitbucket,omitempty"` // An optional commit hash to use instead of the branch specified in the source spec. CommitSHA string `json:"commit_sha,omitempty"` // An optional path to the working directory for the detection process. diff --git a/apps.go b/apps.go index 97b0cbd7..f6b78d90 100644 --- a/apps.go +++ b/apps.go @@ -689,6 +689,7 @@ type AppBuildableComponentSpec interface { GetGit() *GitSourceSpec GetGitHub() *GitHubSourceSpec GetGitLab() *GitLabSourceSpec + GetBitbucket() *BitbucketSourceSpec GetSourceDir() string @@ -731,10 +732,11 @@ type AppRoutableComponentSpec interface { type AppSourceType string const ( - AppSourceTypeGitHub AppSourceType = "github" - AppSourceTypeGitLab AppSourceType = "gitlab" - AppSourceTypeGit AppSourceType = "git" - AppSourceTypeImage AppSourceType = "image" + AppSourceTypeBitbucket AppSourceType = "bitbucket" + AppSourceTypeGitHub AppSourceType = "github" + AppSourceTypeGitLab AppSourceType = "gitlab" + AppSourceTypeGit AppSourceType = "git" + AppSourceTypeImage AppSourceType = "image" ) // SourceSpec represents a source. @@ -742,6 +744,11 @@ type SourceSpec interface { GetType() AppSourceType } +// GetType returns the Bitbucket source type. +func (s *BitbucketSourceSpec) GetType() AppSourceType { + return AppSourceTypeBitbucket +} + // GetType returns the GitHub source type. func (s *GitHubSourceSpec) GetType() AppSourceType { return AppSourceTypeGitHub diff --git a/apps_accessors.go b/apps_accessors.go index 02e7c4b1..4d9a214a 100644 --- a/apps_accessors.go +++ b/apps_accessors.go @@ -805,6 +805,14 @@ func (a *AppFunctionsSpec) GetAlerts() []*AppAlertSpec { return a.Alerts } +// GetBitbucket returns the Bitbucket field. +func (a *AppFunctionsSpec) GetBitbucket() *BitbucketSourceSpec { + if a == nil { + return nil + } + return a.Bitbucket +} + // GetCORS returns the CORS field. func (a *AppFunctionsSpec) GetCORS() *AppCORSPolicy { if a == nil { @@ -1141,6 +1149,14 @@ func (a *AppJobSpec) GetAlerts() []*AppAlertSpec { return a.Alerts } +// GetBitbucket returns the Bitbucket field. +func (a *AppJobSpec) GetBitbucket() *BitbucketSourceSpec { + if a == nil { + return nil + } + return a.Bitbucket +} + // GetBuildCommand returns the BuildCommand field. func (a *AppJobSpec) GetBuildCommand() string { if a == nil { @@ -1645,6 +1661,14 @@ func (a *AppServiceSpec) GetAutoscaling() *AppAutoscalingSpec { return a.Autoscaling } +// GetBitbucket returns the Bitbucket field. +func (a *AppServiceSpec) GetBitbucket() *BitbucketSourceSpec { + if a == nil { + return nil + } + return a.Bitbucket +} + // GetBuildCommand returns the BuildCommand field. func (a *AppServiceSpec) GetBuildCommand() string { if a == nil { @@ -2013,6 +2037,14 @@ func (a *AppSpec) GetWorkers() []*AppWorkerSpec { return a.Workers } +// GetBitbucket returns the Bitbucket field. +func (a *AppStaticSiteSpec) GetBitbucket() *BitbucketSourceSpec { + if a == nil { + return nil + } + return a.Bitbucket +} + // GetBuildCommand returns the BuildCommand field. func (a *AppStaticSiteSpec) GetBuildCommand() string { if a == nil { @@ -2237,6 +2269,14 @@ func (a *AppWorkerSpec) GetAutoscaling() *AppAutoscalingSpec { return a.Autoscaling } +// GetBitbucket returns the Bitbucket field. +func (a *AppWorkerSpec) GetBitbucket() *BitbucketSourceSpec { + if a == nil { + return nil + } + return a.Bitbucket +} + // GetBuildCommand returns the BuildCommand field. func (a *AppWorkerSpec) GetBuildCommand() string { if a == nil { @@ -2365,6 +2405,30 @@ func (a *AppWorkerSpecTermination) GetGracePeriodSeconds() int32 { return a.GracePeriodSeconds } +// GetBranch returns the Branch field. +func (b *BitbucketSourceSpec) GetBranch() string { + if b == nil { + return "" + } + return b.Branch +} + +// GetDeployOnPush returns the DeployOnPush field. +func (b *BitbucketSourceSpec) GetDeployOnPush() bool { + if b == nil { + return false + } + return b.DeployOnPush +} + +// GetRepo returns the Repo field. +func (b *BitbucketSourceSpec) GetRepo() string { + if b == nil { + return "" + } + return b.Repo +} + // GetDescription returns the Description field. func (b *Buildpack) GetDescription() []string { if b == nil { @@ -2701,6 +2765,14 @@ func (d *DeploymentCauseDetailsDOCRPush) GetTag() string { return d.Tag } +// GetBitbucket returns the Bitbucket field. +func (d *DeploymentCauseDetailsGitPush) GetBitbucket() *BitbucketSourceSpec { + if d == nil { + return nil + } + return d.Bitbucket +} + // GetCommitAuthor returns the CommitAuthor field. func (d *DeploymentCauseDetailsGitPush) GetCommitAuthor() string { if d == nil { @@ -3077,6 +3149,14 @@ func (d *DeployTemplate) GetSpec() *AppSpec { return d.Spec } +// GetBitbucket returns the Bitbucket field. +func (d *DetectRequest) GetBitbucket() *BitbucketSourceSpec { + if d == nil { + return nil + } + return d.Bitbucket +} + // GetCommitSHA returns the CommitSHA field. func (d *DetectRequest) GetCommitSHA() string { if d == nil { diff --git a/apps_accessors_test.go b/apps_accessors_test.go index 418f4330..3fad93fa 100644 --- a/apps_accessors_test.go +++ b/apps_accessors_test.go @@ -706,6 +706,13 @@ func TestAppFunctionsSpec_GetAlerts(tt *testing.T) { a.GetAlerts() } +func TestAppFunctionsSpec_GetBitbucket(tt *testing.T) { + a := &AppFunctionsSpec{} + a.GetBitbucket() + a = nil + a.GetBitbucket() +} + func TestAppFunctionsSpec_GetCORS(tt *testing.T) { a := &AppFunctionsSpec{} a.GetCORS() @@ -1000,6 +1007,13 @@ func TestAppJobSpec_GetAlerts(tt *testing.T) { a.GetAlerts() } +func TestAppJobSpec_GetBitbucket(tt *testing.T) { + a := &AppJobSpec{} + a.GetBitbucket() + a = nil + a.GetBitbucket() +} + func TestAppJobSpec_GetBuildCommand(tt *testing.T) { a := &AppJobSpec{} a.GetBuildCommand() @@ -1441,6 +1455,13 @@ func TestAppServiceSpec_GetAutoscaling(tt *testing.T) { a.GetAutoscaling() } +func TestAppServiceSpec_GetBitbucket(tt *testing.T) { + a := &AppServiceSpec{} + a.GetBitbucket() + a = nil + a.GetBitbucket() +} + func TestAppServiceSpec_GetBuildCommand(tt *testing.T) { a := &AppServiceSpec{} a.GetBuildCommand() @@ -1763,6 +1784,13 @@ func TestAppSpec_GetWorkers(tt *testing.T) { a.GetWorkers() } +func TestAppStaticSiteSpec_GetBitbucket(tt *testing.T) { + a := &AppStaticSiteSpec{} + a.GetBitbucket() + a = nil + a.GetBitbucket() +} + func TestAppStaticSiteSpec_GetBuildCommand(tt *testing.T) { a := &AppStaticSiteSpec{} a.GetBuildCommand() @@ -1959,6 +1987,13 @@ func TestAppWorkerSpec_GetAutoscaling(tt *testing.T) { a.GetAutoscaling() } +func TestAppWorkerSpec_GetBitbucket(tt *testing.T) { + a := &AppWorkerSpec{} + a.GetBitbucket() + a = nil + a.GetBitbucket() +} + func TestAppWorkerSpec_GetBuildCommand(tt *testing.T) { a := &AppWorkerSpec{} a.GetBuildCommand() @@ -2071,6 +2106,27 @@ func TestAppWorkerSpecTermination_GetGracePeriodSeconds(tt *testing.T) { a.GetGracePeriodSeconds() } +func TestBitbucketSourceSpec_GetBranch(tt *testing.T) { + b := &BitbucketSourceSpec{} + b.GetBranch() + b = nil + b.GetBranch() +} + +func TestBitbucketSourceSpec_GetDeployOnPush(tt *testing.T) { + b := &BitbucketSourceSpec{} + b.GetDeployOnPush() + b = nil + b.GetDeployOnPush() +} + +func TestBitbucketSourceSpec_GetRepo(tt *testing.T) { + b := &BitbucketSourceSpec{} + b.GetRepo() + b = nil + b.GetRepo() +} + func TestBuildpack_GetDescription(tt *testing.T) { b := &Buildpack{} b.GetDescription() @@ -2365,6 +2421,13 @@ func TestDeploymentCauseDetailsDOCRPush_GetTag(tt *testing.T) { d.GetTag() } +func TestDeploymentCauseDetailsGitPush_GetBitbucket(tt *testing.T) { + d := &DeploymentCauseDetailsGitPush{} + d.GetBitbucket() + d = nil + d.GetBitbucket() +} + func TestDeploymentCauseDetailsGitPush_GetCommitAuthor(tt *testing.T) { d := &DeploymentCauseDetailsGitPush{} d.GetCommitAuthor() @@ -2694,6 +2757,13 @@ func TestDeployTemplate_GetSpec(tt *testing.T) { d.GetSpec() } +func TestDetectRequest_GetBitbucket(tt *testing.T) { + d := &DetectRequest{} + d.GetBitbucket() + d = nil + d.GetBitbucket() +} + func TestDetectRequest_GetCommitSHA(tt *testing.T) { d := &DetectRequest{} d.GetCommitSHA() diff --git a/apps_test.go b/apps_test.go index a67ed3af..8e91837c 100644 --- a/apps_test.go +++ b/apps_test.go @@ -1016,6 +1016,7 @@ func TestApps_Interfaces(t *testing.T) { &GitHubSourceSpec{}, &GitLabSourceSpec{}, &ImageSourceSpec{}, + &BitbucketSourceSpec{}, } { if _, ok := impl.(SourceSpec); !ok { t.Fatalf("%T should match interface", impl) @@ -1028,17 +1029,18 @@ func TestApps_Interfaces(t *testing.T) { &GitSourceSpec{}, &GitHubSourceSpec{}, &GitLabSourceSpec{}, + &BitbucketSourceSpec{}, } { if _, ok := impl.(VCSSourceSpec); !ok { t.Fatalf("%T should match interface", impl) } } for impl, wantMatch := range map[any]bool{ - &GitSourceSpec{}: true, - &GitHubSourceSpec{}: true, - &GitLabSourceSpec{}: true, - - &ImageSourceSpec{}: false, + &GitSourceSpec{}: true, + &GitHubSourceSpec{}: true, + &GitLabSourceSpec{}: true, + &BitbucketSourceSpec{}: true, + &ImageSourceSpec{}: false, } { _, ok := impl.(VCSSourceSpec) if wantMatch && !ok {