Skip to content

Commit

Permalink
Add GetPipelineConfig (closes GH-176) (#177)
Browse files Browse the repository at this point in the history
* Add repository.GetPipelineConfig

* Add tests for (Get|Update)PipelineConfig

Co-authored-by: David Triendl <[email protected]>
  • Loading branch information
soult and David Triendl authored Dec 13, 2021
1 parent b931d8f commit 189c56e
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
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

0 comments on commit 189c56e

Please sign in to comment.