Skip to content

Commit 9af2f29

Browse files
authored
add support for deleting pipeline variables (#119)
BitBucket's v2.0 API supports deleting pipeline variables by uuid. On success, an empty response body with HTTP status 204 is returned. Signed-off-by: Kent R. Spillner <[email protected]>
1 parent bc5f024 commit 9af2f29

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

bitbucket.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type repository interface {
3636
UpdatePipelineConfig(opt RepositoryPipelineOptions) (*Pipeline, error)
3737
ListPipelineVariables(opt RepositoryPipelineVariablesOptions) (*PipelineVariables, error)
3838
AddPipelineVariable(opt RepositoryPipelineVariableOptions) (*PipelineVariable, error)
39+
DeletePipelineVariable(opt RepositoryPipelineVariableDeleteOptions) (interface{}, error)
3940
AddPipelineKeyPair(opt RepositoryPipelineKeyPairOptions) (*PipelineKeyPair, error)
4041
UpdatePipelineBuildNumber(opt RepositoryPipelineBuildNumberOptions) (*PipelineBuildNumber, error)
4142
ListFiles(opt RepositoryFilesOptions) (*[]RepositoryFile, error)
@@ -272,6 +273,12 @@ type RepositoryPipelineVariableOptions struct {
272273
Secured bool `json:"secured"`
273274
}
274275

276+
type RepositoryPipelineVariableDeleteOptions struct {
277+
Owner string `json:"owner"`
278+
RepoSlug string `json:"repo_slug"`
279+
Uuid string `json:"uuid"`
280+
}
281+
275282
type RepositoryPipelineKeyPairOptions struct {
276283
Owner string `json:"owner"`
277284
RepoSlug string `json:"repo_slug"`

repository.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,11 @@ func (r *Repository) AddPipelineVariable(rpvo *RepositoryPipelineVariableOptions
388388
return decodePipelineVariableRepository(response)
389389
}
390390

391+
func (r *Repository) DeletePipelineVariable(opt *RepositoryPipelineVariableDeleteOptions) (interface{}, error) {
392+
urlStr := r.c.requestUrl("/repositories/%s/%s/pipelines_config/variables/%s", opt.Owner, opt.RepoSlug, opt.Uuid)
393+
return r.c.execute("DELETE", urlStr, "")
394+
}
395+
391396
func (r *Repository) AddPipelineKeyPair(rpkpo *RepositoryPipelineKeyPairOptions) (*PipelineKeyPair, error) {
392397
data := r.buildPipelineKeyPairBody(rpkpo)
393398
urlStr := r.c.requestUrl("/repositories/%s/%s/pipelines_config/ssh/key_pair", rpkpo.Owner, rpkpo.RepoSlug)

tests/repository_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,51 @@ func TestGetRepositoryPipelineVariables(t *testing.T) {
8181
t.Error("Cannot list pipeline variables")
8282
}
8383
}
84+
85+
func TestDeleteRepositoryPipelineVariables(t *testing.T) {
86+
87+
user := os.Getenv("BITBUCKET_TEST_USERNAME")
88+
pass := os.Getenv("BITBUCKET_TEST_PASSWORD")
89+
owner := os.Getenv("BITBUCKET_TEST_OWNER")
90+
repo := os.Getenv("BITBUCKET_TEST_REPOSLUG")
91+
92+
if user == "" {
93+
t.Error("BITBUCKET_TEST_USERNAME is empty.")
94+
}
95+
if pass == "" {
96+
t.Error("BITBUCKET_TEST_PASSWORD is empty.")
97+
}
98+
if owner == "" {
99+
t.Error("BITBUCKET_TEST_OWNER is empty.")
100+
}
101+
if repo == "" {
102+
t.Error("BITBUCKET_TEST_REPOSLUG is empty.")
103+
}
104+
105+
c := bitbucket.NewBasicAuth(user, pass)
106+
107+
variable := &bitbucket.RepositoryPipelineVariableOptions{
108+
Owner: owner,
109+
RepoSlug: repo,
110+
Key: "test_key_to_delete",
111+
Value: "Some value to delete",
112+
Secured: false,
113+
}
114+
115+
res, err := c.Repositories.Repository.AddPipelineVariable(variable)
116+
if err != nil {
117+
t.Error(err)
118+
}
119+
120+
opt := &bitbucket.RepositoryPipelineVariableDeleteOptions{
121+
Owner: owner,
122+
RepoSlug: repo,
123+
Uuid: res.Uuid,
124+
}
125+
126+
// On success the delete API doesn't return any content (HTTP status 204)
127+
_, err = c.Repositories.Repository.DeletePipelineVariable(opt)
128+
if err != nil {
129+
t.Error(err)
130+
}
131+
}

0 commit comments

Comments
 (0)