Skip to content
This repository has been archived by the owner on Feb 5, 2025. It is now read-only.

Bitbucket provider support #77

Merged
merged 8 commits into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from 7 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
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,40 @@ DRONE_CONVERT_PLUGIN_ENDPOINT=http://1.2.3.4:3000
DRONE_CONVERT_PLUGIN_SECRET=bea26a2221fd8090ea38720fc445eca6
```

## Bitbucket

_Bitbucket support is currently considered experimental_

1. Create an "App password" via https://bitbucket.org/account/settings/app-passwords and select only "Read" under "Repositories"

2. Create a shared secret:

```console
$ openssl rand -hex 16
bea26a2221fd8090ea38720fc445eca6
```

3. Download and run the plugin:

```console
$ docker run -d \
--publish=3000:3000 \
--env=DRONE_DEBUG=true \
--env=DRONE_SECRET=bea26a2221fd8090ea38720fc445eca6 \
--env=BITBUCKET_USER=youruser \
--env=BITBUCKET_PASSWORD='yourpassword' \
--env=PROVIDER=bitbucket \
--restart=always \
--name=converter meltwater/drone-convert-pathschanged
```

4. Update your Drone server configuration to include the plugin address and the shared secret.

```text
DRONE_CONVERT_PLUGIN_ENDPOINT=http://1.2.3.4:3000
DRONE_CONVERT_PLUGIN_SECRET=bea26a2221fd8090ea38720fc445eca6
```

## Bitbucket Server

_Bitbucket Server support is currently considered experimental_
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ require (
github.com/buildkite/yaml v2.1.0+incompatible
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/drone/drone-go v1.7.1
github.com/drone/go-scm v1.15.2
github.com/drone/go-scm v1.16.0
github.com/gfleury/go-bitbucket-v1 v0.0.0-20210826163055-dff2223adeac
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.5
github.com/h2non/gock v1.0.9
github.com/joho/godotenv v1.4.0
github.com/kelseyhightower/envconfig v1.4.0
github.com/mitchellh/mapstructure v1.4.2 // indirect
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 // indirect
github.com/prometheus/client_golang v1.11.0
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/drone/drone-go v1.7.1 h1:ZX+3Rs8YHUSUQ5mkuMLmm1zr1ttiiE2YGNxF3AnyDKw=
github.com/drone/drone-go v1.7.1/go.mod h1:fxCf9jAnXDZV1yDr0ckTuWd1intvcQwfJmTRpTZ1mXg=
github.com/drone/go-scm v1.15.2 h1:H5iDEGTYZwb/n3sx+ekbXHOwqi/3sYTJJunJUiXLAVA=
github.com/drone/go-scm v1.15.2/go.mod h1:lXwfbyrIJwFFME5TpzavkwO2T5X8yBK6t6cve7g91x0=
github.com/drone/go-scm v1.16.0 h1:HvWd01b2MzBSlOq/O+jY9kjDlG+8ODu6W9GGGU5NUnY=
github.com/drone/go-scm v1.16.0/go.mod h1:DFIJJjhMj0TSXPz+0ni4nyZ9gtTtC40Vh/TGRugtyWw=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
Expand Down
26 changes: 18 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ type spec struct {
Text bool `envconfig:"DRONE_LOGS_TEXT"`
Secret string `envconfig:"DRONE_SECRET"`

Provider string `envconfig:"PROVIDER"`
Token string `envconfig:"TOKEN"`
BitBucketAddress string `envconfig:"BB_ADDRESS"`
GithubServer string `envconfig:"GITHUB_SERVER"`
Provider string `envconfig:"PROVIDER"`
Token string `envconfig:"TOKEN"`
BitBucketAddress string `envconfig:"BB_ADDRESS"`
BitBucketUser string `envconfig:"BITBUCKET_USER"`
BitBucketPassword string `envconfig:"BITBUCKET_PASSWORD"`
GithubServer string `envconfig:"GITHUB_SERVER"`
}

func contains(s []string, str string) bool {
Expand Down Expand Up @@ -56,17 +58,23 @@ func main() {
if spec.Secret == "" {
logrus.Fatalln("missing secret key")
}
if spec.Token == "" {
logrus.Fatalln("missing token")
}
if spec.Provider == "" {
logrus.Fatalln("missing provider")
} else {
providers := []string{"bitbucket-server", "github"}
providers := []string{"bitbucket", "bitbucket-server", "github"}
if !contains(providers, spec.Provider) {
logrus.Fatalln("invalid provider:", spec.Provider)
}
}
if spec.Token == "" && (spec.Provider == "github" || spec.Provider == "bitbucket-server") {
logrus.Fatalln("missing token")
}
if spec.BitBucketUser == "" && spec.Provider == "bitbucket" {
logrus.Fatalln("missing bitbucket user")
}
if spec.BitBucketPassword == "" && spec.Provider == "bitbucket" {
logrus.Fatalln("missing bitbucket password")
}
if spec.BitBucketAddress == "" && spec.Provider == "bitbucket-server" {
logrus.Fatalln("missing bitbucket server address")
}
Expand All @@ -79,6 +87,8 @@ func main() {
spec.Token,
spec.Provider,
spec.GithubServer,
spec.BitBucketUser,
spec.BitBucketPassword,
),
spec.Secret,
logrus.StandardLogger(),
Expand Down
26 changes: 18 additions & 8 deletions plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ import (

"github.com/drone/drone-go/drone"
"github.com/drone/drone-go/plugin/converter"
"github.com/drone/go-scm/scm"

"github.com/buildkite/yaml"
"github.com/sirupsen/logrus"
)

type (
plugin struct {
token string
provider string
bitbucketAddress string
githubAddress string
token string
provider string
bitbucketAddress string
bitbucketUser string
bitbucketPassword string
githubAddress string
}

resource struct {
Expand Down Expand Up @@ -105,11 +108,13 @@ func marshal(in []*resource) ([]byte, error) {
}

// New returns a new conversion plugin.
func New(token string, provider string, githubAddress string) converter.Plugin {
func New(token string, provider string, githubAddress string, bitbucketUser string, bitbucketPassword string) converter.Plugin {
return &plugin{
token: token,
provider: provider,
githubAddress: githubAddress,
token: token,
provider: provider,
githubAddress: githubAddress,
bitbucketUser: bitbucketUser,
bitbucketPassword: bitbucketPassword,
}
}

Expand Down Expand Up @@ -154,6 +159,11 @@ func (p *plugin) Convert(ctx context.Context, req *converter.Request) (*drone.Co
if err != nil {
return nil, err
}
case "bitbucket":
changedFiles, err = providers.GetBitbucketFilesChanged(req.Repo, req.Build, p.bitbucketUser, p.bitbucketPassword, scm.ListOptions{})
if err != nil {
return nil, err
}
case "bitbucket-server":
changedFiles, err = providers.GetBBFilesChanged(req.Repo, req.Build, p.token)
if err != nil {
Expand Down
Loading