Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,15 @@ func (r *Repository) DeleteDefaultReviewer(rdro *RepositoryDefaultReviewerOption
return r.c.execute("DELETE", urlStr, "")
}

func (r *Repository) GetPipelineConfig(rpo *RepositoryPipelineOptions) (*Pipeline, error) {
urlStr := r.c.requestUrl("/repositories/%s/%s/pipelines_config", rpo.Owner, rpo.RepoSlug)
response, err := r.c.execute("GET", urlStr, "")
if err != nil {
return nil, fmt.Errorf("unable to get pipeline config: %w", err)
}
return decodePipelineRepository(response)
}

func (r *Repository) UpdatePipelineConfig(rpo *RepositoryPipelineOptions) (*Pipeline, error) {
data, err := r.buildPipelineBody(rpo)
if err != nil {
Expand Down
97 changes: 97 additions & 0 deletions tests/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,103 @@ func TestRepositoryUpdateForkPolicy(t *testing.T) {
}
}

func TestGetRepositoryPipelineConfig(t *testing.T) {
user := os.Getenv("BITBUCKET_TEST_USERNAME")
pass := os.Getenv("BITBUCKET_TEST_PASSWORD")
owner := os.Getenv("BITBUCKET_TEST_OWNER")
repo := os.Getenv("BITBUCKET_TEST_REPOSLUG")

if user == "" {
t.Error("BITBUCKET_TEST_USERNAME is empty.")
}
if pass == "" {
t.Error("BITBUCKET_TEST_PASSWORD is empty.")
}
if owner == "" {
t.Error("BITBUCKET_TEST_OWNER is empty.")
}
if repo == "" {
t.Error("BITBUCKET_TEST_REPOSLUG is empty.")
}

c := bitbucket.NewBasicAuth(user, pass)

opt := &bitbucket.RepositoryPipelineOptions{
Owner: owner,
RepoSlug: repo,
}

res, err := c.Repositories.Repository.GetPipelineConfig(opt)
if err != nil {
t.Error(err)
}

if res == nil {
t.Error("Cannot get pipeline config")
}
if res.Enabled != false {
t.Error("Got wrong pipelines config data")
}
}

func TestUpdateRepositoryPipelineConfig(t *testing.T) {
user := os.Getenv("BITBUCKET_TEST_USERNAME")
pass := os.Getenv("BITBUCKET_TEST_PASSWORD")
owner := os.Getenv("BITBUCKET_TEST_OWNER")
repo := os.Getenv("BITBUCKET_TEST_REPOSLUG")

if user == "" {
t.Error("BITBUCKET_TEST_USERNAME is empty.")
}
if pass == "" {
t.Error("BITBUCKET_TEST_PASSWORD is empty.")
}
if owner == "" {
t.Error("BITBUCKET_TEST_OWNER is empty.")
}
if repo == "" {
t.Error("BITBUCKET_TEST_REPOSLUG is empty.")
}

c := bitbucket.NewBasicAuth(user, pass)

opt := &bitbucket.RepositoryPipelineOptions{
Owner: owner,
RepoSlug: repo,
Enabled: true,
}

res, err := c.Repositories.Repository.UpdatePipelineConfig(opt)
if err != nil {
t.Error(err)
}

if res == nil {
t.Error("Cannot update pipeline config")
}
if res.Enabled != true {
t.Error("Got wrong pipelines config data")
}

opt = &bitbucket.RepositoryPipelineOptions{
Owner: owner,
RepoSlug: repo,
Enabled: false,
}

res, err = c.Repositories.Repository.UpdatePipelineConfig(opt)
if err != nil {
t.Error(err)
}

if res == nil {
t.Error("Cannot update pipeline config")
}
if res.Enabled != false {
t.Error("Got wrong pipelines config data")
}
}

func TestGetRepositoryPipelineVariables(t *testing.T) {

user := os.Getenv("BITBUCKET_TEST_USERNAME")
Expand Down