Skip to content

Commit 189c56e

Browse files
soultDavid Triendl
andauthored
Add GetPipelineConfig (closes GH-176) (#177)
* Add repository.GetPipelineConfig * Add tests for (Get|Update)PipelineConfig Co-authored-by: David Triendl <[email protected]>
1 parent b931d8f commit 189c56e

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed

repository.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,15 @@ func (r *Repository) DeleteDefaultReviewer(rdro *RepositoryDefaultReviewerOption
544544
return r.c.execute("DELETE", urlStr, "")
545545
}
546546

547+
func (r *Repository) GetPipelineConfig(rpo *RepositoryPipelineOptions) (*Pipeline, error) {
548+
urlStr := r.c.requestUrl("/repositories/%s/%s/pipelines_config", rpo.Owner, rpo.RepoSlug)
549+
response, err := r.c.execute("GET", urlStr, "")
550+
if err != nil {
551+
return nil, fmt.Errorf("unable to get pipeline config: %w", err)
552+
}
553+
return decodePipelineRepository(response)
554+
}
555+
547556
func (r *Repository) UpdatePipelineConfig(rpo *RepositoryPipelineOptions) (*Pipeline, error) {
548557
data, err := r.buildPipelineBody(rpo)
549558
if err != nil {

tests/repository_test.go

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,103 @@ func TestRepositoryUpdateForkPolicy(t *testing.T) {
189189
}
190190
}
191191

192+
func TestGetRepositoryPipelineConfig(t *testing.T) {
193+
user := os.Getenv("BITBUCKET_TEST_USERNAME")
194+
pass := os.Getenv("BITBUCKET_TEST_PASSWORD")
195+
owner := os.Getenv("BITBUCKET_TEST_OWNER")
196+
repo := os.Getenv("BITBUCKET_TEST_REPOSLUG")
197+
198+
if user == "" {
199+
t.Error("BITBUCKET_TEST_USERNAME is empty.")
200+
}
201+
if pass == "" {
202+
t.Error("BITBUCKET_TEST_PASSWORD is empty.")
203+
}
204+
if owner == "" {
205+
t.Error("BITBUCKET_TEST_OWNER is empty.")
206+
}
207+
if repo == "" {
208+
t.Error("BITBUCKET_TEST_REPOSLUG is empty.")
209+
}
210+
211+
c := bitbucket.NewBasicAuth(user, pass)
212+
213+
opt := &bitbucket.RepositoryPipelineOptions{
214+
Owner: owner,
215+
RepoSlug: repo,
216+
}
217+
218+
res, err := c.Repositories.Repository.GetPipelineConfig(opt)
219+
if err != nil {
220+
t.Error(err)
221+
}
222+
223+
if res == nil {
224+
t.Error("Cannot get pipeline config")
225+
}
226+
if res.Enabled != false {
227+
t.Error("Got wrong pipelines config data")
228+
}
229+
}
230+
231+
func TestUpdateRepositoryPipelineConfig(t *testing.T) {
232+
user := os.Getenv("BITBUCKET_TEST_USERNAME")
233+
pass := os.Getenv("BITBUCKET_TEST_PASSWORD")
234+
owner := os.Getenv("BITBUCKET_TEST_OWNER")
235+
repo := os.Getenv("BITBUCKET_TEST_REPOSLUG")
236+
237+
if user == "" {
238+
t.Error("BITBUCKET_TEST_USERNAME is empty.")
239+
}
240+
if pass == "" {
241+
t.Error("BITBUCKET_TEST_PASSWORD is empty.")
242+
}
243+
if owner == "" {
244+
t.Error("BITBUCKET_TEST_OWNER is empty.")
245+
}
246+
if repo == "" {
247+
t.Error("BITBUCKET_TEST_REPOSLUG is empty.")
248+
}
249+
250+
c := bitbucket.NewBasicAuth(user, pass)
251+
252+
opt := &bitbucket.RepositoryPipelineOptions{
253+
Owner: owner,
254+
RepoSlug: repo,
255+
Enabled: true,
256+
}
257+
258+
res, err := c.Repositories.Repository.UpdatePipelineConfig(opt)
259+
if err != nil {
260+
t.Error(err)
261+
}
262+
263+
if res == nil {
264+
t.Error("Cannot update pipeline config")
265+
}
266+
if res.Enabled != true {
267+
t.Error("Got wrong pipelines config data")
268+
}
269+
270+
opt = &bitbucket.RepositoryPipelineOptions{
271+
Owner: owner,
272+
RepoSlug: repo,
273+
Enabled: false,
274+
}
275+
276+
res, err = c.Repositories.Repository.UpdatePipelineConfig(opt)
277+
if err != nil {
278+
t.Error(err)
279+
}
280+
281+
if res == nil {
282+
t.Error("Cannot update pipeline config")
283+
}
284+
if res.Enabled != false {
285+
t.Error("Got wrong pipelines config data")
286+
}
287+
}
288+
192289
func TestGetRepositoryPipelineVariables(t *testing.T) {
193290

194291
user := os.Getenv("BITBUCKET_TEST_USERNAME")

0 commit comments

Comments
 (0)