mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-06-10 09:29:34 +00:00
Rename remote
to forge
(#1357)
As of #745 Co-authored-by: Anbraten <anton@ju60.de>
This commit is contained in:
parent
2ee75dbceb
commit
3372d1a87c
|
@ -242,7 +242,7 @@ func metadataFromContext(c *cli.Context, axis matrix.Axis) frontend.Metadata {
|
||||||
Repo: frontend.Repo{
|
Repo: frontend.Repo{
|
||||||
Name: c.String("repo-name"),
|
Name: c.String("repo-name"),
|
||||||
Link: c.String("repo-link"),
|
Link: c.String("repo-link"),
|
||||||
Remote: c.String("repo-remote-url"),
|
CloneURL: c.String("repo-clone-url"),
|
||||||
Private: c.Bool("repo-private"),
|
Private: c.Bool("repo-private"),
|
||||||
},
|
},
|
||||||
Curr: frontend.Pipeline{
|
Curr: frontend.Pipeline{
|
||||||
|
|
|
@ -123,8 +123,8 @@ var flags = []cli.Flag{
|
||||||
Name: "repo-link",
|
Name: "repo-link",
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
EnvVars: []string{"CI_REPO_REMOTE"},
|
EnvVars: []string{"CI_REPO_CLONE_URL", "CI_REPO_REMOTE"},
|
||||||
Name: "repo-remote-url",
|
Name: "repo-clone-url",
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
EnvVars: []string{"CI_REPO_PRIVATE"},
|
EnvVars: []string{"CI_REPO_PRIVATE"},
|
||||||
|
|
|
@ -53,5 +53,5 @@ Visibility: {{ .Visibility }}
|
||||||
Private: {{ .IsSCMPrivate }}
|
Private: {{ .IsSCMPrivate }}
|
||||||
Trusted: {{ .IsTrusted }}
|
Trusted: {{ .IsTrusted }}
|
||||||
Gated: {{ .IsGated }}
|
Gated: {{ .IsGated }}
|
||||||
Remote: {{ .Clone }}
|
Forge: {{ .Clone }}
|
||||||
`
|
`
|
||||||
|
|
|
@ -521,7 +521,7 @@ var flags = []cli.Flag{
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
EnvVars: []string{"WOODPECKER_FLAT_PERMISSIONS"},
|
EnvVars: []string{"WOODPECKER_FLAT_PERMISSIONS"},
|
||||||
Name: "flat-permissions",
|
Name: "flat-permissions",
|
||||||
Usage: "no remote call for permissions should be made",
|
Usage: "no forge call for permissions should be made",
|
||||||
Hidden: true,
|
Hidden: true,
|
||||||
// TODO(485) temporary workaround to not hit api rate limits
|
// TODO(485) temporary workaround to not hit api rate limits
|
||||||
},
|
},
|
||||||
|
|
|
@ -39,12 +39,12 @@ import (
|
||||||
"github.com/woodpecker-ci/woodpecker/pipeline/rpc/proto"
|
"github.com/woodpecker-ci/woodpecker/pipeline/rpc/proto"
|
||||||
"github.com/woodpecker-ci/woodpecker/server"
|
"github.com/woodpecker-ci/woodpecker/server"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/cron"
|
"github.com/woodpecker-ci/woodpecker/server/cron"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge"
|
||||||
woodpeckerGrpcServer "github.com/woodpecker-ci/woodpecker/server/grpc"
|
woodpeckerGrpcServer "github.com/woodpecker-ci/woodpecker/server/grpc"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/logging"
|
"github.com/woodpecker-ci/woodpecker/server/logging"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/plugins/config"
|
"github.com/woodpecker-ci/woodpecker/server/plugins/config"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/pubsub"
|
"github.com/woodpecker-ci/woodpecker/server/pubsub"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote"
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server/router"
|
"github.com/woodpecker-ci/woodpecker/server/router"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/router/middleware"
|
"github.com/woodpecker-ci/woodpecker/server/router/middleware"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/store"
|
"github.com/woodpecker-ci/woodpecker/server/store"
|
||||||
|
@ -101,7 +101,7 @@ func run(c *cli.Context) error {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
_remote, err := setupRemote(c)
|
_forge, err := setupForge(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal().Err(err).Msg("")
|
log.Fatal().Err(err).Msg("")
|
||||||
}
|
}
|
||||||
|
@ -116,14 +116,14 @@ func run(c *cli.Context) error {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
setupEvilGlobals(c, _store, _remote)
|
setupEvilGlobals(c, _store, _forge)
|
||||||
|
|
||||||
var g errgroup.Group
|
var g errgroup.Group
|
||||||
|
|
||||||
setupMetrics(&g, _store)
|
setupMetrics(&g, _store)
|
||||||
|
|
||||||
g.Go(func() error {
|
g.Go(func() error {
|
||||||
return cron.Start(c.Context, _store, _remote)
|
return cron.Start(c.Context, _store, _forge)
|
||||||
})
|
})
|
||||||
|
|
||||||
// start the grpc server
|
// start the grpc server
|
||||||
|
@ -144,7 +144,7 @@ func run(c *cli.Context) error {
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
woodpeckerServer := woodpeckerGrpcServer.NewWoodpeckerServer(
|
woodpeckerServer := woodpeckerGrpcServer.NewWoodpeckerServer(
|
||||||
_remote,
|
_forge,
|
||||||
server.Config.Services.Queue,
|
server.Config.Services.Queue,
|
||||||
server.Config.Services.Logs,
|
server.Config.Services.Logs,
|
||||||
server.Config.Services.Pubsub,
|
server.Config.Services.Pubsub,
|
||||||
|
@ -253,12 +253,12 @@ func run(c *cli.Context) error {
|
||||||
return g.Wait()
|
return g.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupEvilGlobals(c *cli.Context, v store.Store, r remote.Remote) {
|
func setupEvilGlobals(c *cli.Context, v store.Store, f forge.Forge) {
|
||||||
// storage
|
// storage
|
||||||
server.Config.Storage.Files = v
|
server.Config.Storage.Files = v
|
||||||
|
|
||||||
// remote
|
// forge
|
||||||
server.Config.Services.Remote = r
|
server.Config.Services.Forge = f
|
||||||
|
|
||||||
// services
|
// services
|
||||||
server.Config.Services.Queue = setupQueue(c, v)
|
server.Config.Services.Queue = setupQueue(c, v)
|
||||||
|
@ -270,7 +270,7 @@ func setupEvilGlobals(c *cli.Context, v store.Store, r remote.Remote) {
|
||||||
server.Config.Services.Registries = setupRegistryService(c, v)
|
server.Config.Services.Registries = setupRegistryService(c, v)
|
||||||
server.Config.Services.Secrets = setupSecretService(c, v)
|
server.Config.Services.Secrets = setupSecretService(c, v)
|
||||||
server.Config.Services.Environ = setupEnvironService(c, v)
|
server.Config.Services.Environ = setupEnvironService(c, v)
|
||||||
server.Config.Services.Membership = setupMembershipService(c, r)
|
server.Config.Services.Membership = setupMembershipService(c, f)
|
||||||
|
|
||||||
server.Config.Services.SignaturePrivateKey, server.Config.Services.SignaturePublicKey = setupSignatureKeys(v)
|
server.Config.Services.SignaturePrivateKey, server.Config.Services.SignaturePublicKey = setupSignatureKeys(v)
|
||||||
|
|
||||||
|
|
|
@ -36,19 +36,19 @@ import (
|
||||||
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server"
|
"github.com/woodpecker-ci/woodpecker/server"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/cache"
|
"github.com/woodpecker-ci/woodpecker/server/cache"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/bitbucket"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/bitbucketserver"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/coding"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/gitea"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/github"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/gitlab"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/gogs"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/plugins/environments"
|
"github.com/woodpecker-ci/woodpecker/server/plugins/environments"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/plugins/registry"
|
"github.com/woodpecker-ci/woodpecker/server/plugins/registry"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/plugins/secrets"
|
"github.com/woodpecker-ci/woodpecker/server/plugins/secrets"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/queue"
|
"github.com/woodpecker-ci/woodpecker/server/queue"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote"
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/bitbucket"
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/bitbucketserver"
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/coding"
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/gitea"
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/github"
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/gitlab"
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/gogs"
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server/store"
|
"github.com/woodpecker-ci/woodpecker/server/store"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/store/datastore"
|
"github.com/woodpecker-ci/woodpecker/server/store/datastore"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/store/types"
|
"github.com/woodpecker-ci/woodpecker/server/store/types"
|
||||||
|
@ -182,12 +182,12 @@ func setupEnvironService(c *cli.Context, s store.Store) model.EnvironService {
|
||||||
return environments.Parse(c.StringSlice("environment"))
|
return environments.Parse(c.StringSlice("environment"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupMembershipService(_ *cli.Context, r remote.Remote) cache.MembershipService {
|
func setupMembershipService(_ *cli.Context, r forge.Forge) cache.MembershipService {
|
||||||
return cache.NewMembershipService(r)
|
return cache.NewMembershipService(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// setupRemote helper function to setup the remote from the CLI arguments.
|
// setupForge helper function to setup the forge from the CLI arguments.
|
||||||
func setupRemote(c *cli.Context) (remote.Remote, error) {
|
func setupForge(c *cli.Context) (forge.Forge, error) {
|
||||||
switch {
|
switch {
|
||||||
case c.Bool("github"):
|
case c.Bool("github"):
|
||||||
return setupGithub(c)
|
return setupGithub(c)
|
||||||
|
@ -208,18 +208,18 @@ func setupRemote(c *cli.Context) (remote.Remote, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function to setup the Bitbucket remote from the CLI arguments.
|
// helper function to setup the Bitbucket forge from the CLI arguments.
|
||||||
func setupBitbucket(c *cli.Context) (remote.Remote, error) {
|
func setupBitbucket(c *cli.Context) (forge.Forge, error) {
|
||||||
opts := &bitbucket.Opts{
|
opts := &bitbucket.Opts{
|
||||||
Client: c.String("bitbucket-client"),
|
Client: c.String("bitbucket-client"),
|
||||||
Secret: c.String("bitbucket-secret"),
|
Secret: c.String("bitbucket-secret"),
|
||||||
}
|
}
|
||||||
log.Trace().Msgf("Remote (bitbucket) opts: %#v", opts)
|
log.Trace().Msgf("Forge (bitbucket) opts: %#v", opts)
|
||||||
return bitbucket.New(opts)
|
return bitbucket.New(opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function to setup the Gogs remote from the CLI arguments.
|
// helper function to setup the Gogs forge from the CLI arguments.
|
||||||
func setupGogs(c *cli.Context) (remote.Remote, error) {
|
func setupGogs(c *cli.Context) (forge.Forge, error) {
|
||||||
opts := gogs.Opts{
|
opts := gogs.Opts{
|
||||||
URL: c.String("gogs-server"),
|
URL: c.String("gogs-server"),
|
||||||
Username: c.String("gogs-git-username"),
|
Username: c.String("gogs-git-username"),
|
||||||
|
@ -227,12 +227,12 @@ func setupGogs(c *cli.Context) (remote.Remote, error) {
|
||||||
PrivateMode: c.Bool("gogs-private-mode"),
|
PrivateMode: c.Bool("gogs-private-mode"),
|
||||||
SkipVerify: c.Bool("gogs-skip-verify"),
|
SkipVerify: c.Bool("gogs-skip-verify"),
|
||||||
}
|
}
|
||||||
log.Trace().Msgf("Remote (gogs) opts: %#v", opts)
|
log.Trace().Msgf("Forge (gogs) opts: %#v", opts)
|
||||||
return gogs.New(opts)
|
return gogs.New(opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function to setup the Gitea remote from the CLI arguments.
|
// helper function to setup the Gitea forge from the CLI arguments.
|
||||||
func setupGitea(c *cli.Context) (remote.Remote, error) {
|
func setupGitea(c *cli.Context) (forge.Forge, error) {
|
||||||
server, err := url.Parse(c.String("gitea-server"))
|
server, err := url.Parse(c.String("gitea-server"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -246,12 +246,12 @@ func setupGitea(c *cli.Context) (remote.Remote, error) {
|
||||||
if len(opts.URL) == 0 {
|
if len(opts.URL) == 0 {
|
||||||
log.Fatal().Msg("WOODPECKER_GITEA_URL must be set")
|
log.Fatal().Msg("WOODPECKER_GITEA_URL must be set")
|
||||||
}
|
}
|
||||||
log.Trace().Msgf("Remote (gitea) opts: %#v", opts)
|
log.Trace().Msgf("Forge (gitea) opts: %#v", opts)
|
||||||
return gitea.New(opts)
|
return gitea.New(opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function to setup the Stash remote from the CLI arguments.
|
// helper function to setup the Stash forge from the CLI arguments.
|
||||||
func setupStash(c *cli.Context) (remote.Remote, error) {
|
func setupStash(c *cli.Context) (forge.Forge, error) {
|
||||||
opts := bitbucketserver.Opts{
|
opts := bitbucketserver.Opts{
|
||||||
URL: c.String("stash-server"),
|
URL: c.String("stash-server"),
|
||||||
Username: c.String("stash-git-username"),
|
Username: c.String("stash-git-username"),
|
||||||
|
@ -261,12 +261,12 @@ func setupStash(c *cli.Context) (remote.Remote, error) {
|
||||||
ConsumerRSAString: c.String("stash-consumer-rsa-string"),
|
ConsumerRSAString: c.String("stash-consumer-rsa-string"),
|
||||||
SkipVerify: c.Bool("stash-skip-verify"),
|
SkipVerify: c.Bool("stash-skip-verify"),
|
||||||
}
|
}
|
||||||
log.Trace().Msgf("Remote (bitbucketserver) opts: %#v", opts)
|
log.Trace().Msgf("Forge (bitbucketserver) opts: %#v", opts)
|
||||||
return bitbucketserver.New(opts)
|
return bitbucketserver.New(opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function to setup the Gitlab remote from the CLI arguments.
|
// helper function to setup the Gitlab forge from the CLI arguments.
|
||||||
func setupGitlab(c *cli.Context) (remote.Remote, error) {
|
func setupGitlab(c *cli.Context) (forge.Forge, error) {
|
||||||
return gitlab.New(gitlab.Opts{
|
return gitlab.New(gitlab.Opts{
|
||||||
URL: c.String("gitlab-server"),
|
URL: c.String("gitlab-server"),
|
||||||
ClientID: c.String("gitlab-client"),
|
ClientID: c.String("gitlab-client"),
|
||||||
|
@ -275,8 +275,8 @@ func setupGitlab(c *cli.Context) (remote.Remote, error) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function to setup the GitHub remote from the CLI arguments.
|
// helper function to setup the GitHub forge from the CLI arguments.
|
||||||
func setupGithub(c *cli.Context) (remote.Remote, error) {
|
func setupGithub(c *cli.Context) (forge.Forge, error) {
|
||||||
opts := github.Opts{
|
opts := github.Opts{
|
||||||
URL: c.String("github-server"),
|
URL: c.String("github-server"),
|
||||||
Client: c.String("github-client"),
|
Client: c.String("github-client"),
|
||||||
|
@ -284,12 +284,12 @@ func setupGithub(c *cli.Context) (remote.Remote, error) {
|
||||||
SkipVerify: c.Bool("github-skip-verify"),
|
SkipVerify: c.Bool("github-skip-verify"),
|
||||||
MergeRef: c.Bool("github-merge-ref"),
|
MergeRef: c.Bool("github-merge-ref"),
|
||||||
}
|
}
|
||||||
log.Trace().Msgf("Remote (github) opts: %#v", opts)
|
log.Trace().Msgf("Forge (github) opts: %#v", opts)
|
||||||
return github.New(opts)
|
return github.New(opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function to setup the Coding remote from the CLI arguments.
|
// helper function to setup the Coding forge from the CLI arguments.
|
||||||
func setupCoding(c *cli.Context) (remote.Remote, error) {
|
func setupCoding(c *cli.Context) (forge.Forge, error) {
|
||||||
opts := coding.Opts{
|
opts := coding.Opts{
|
||||||
URL: c.String("coding-server"),
|
URL: c.String("coding-server"),
|
||||||
Client: c.String("coding-client"),
|
Client: c.String("coding-client"),
|
||||||
|
@ -299,7 +299,7 @@ func setupCoding(c *cli.Context) (remote.Remote, error) {
|
||||||
Password: c.String("coding-git-password"),
|
Password: c.String("coding-git-password"),
|
||||||
SkipVerify: c.Bool("coding-skip-verify"),
|
SkipVerify: c.Bool("coding-skip-verify"),
|
||||||
}
|
}
|
||||||
log.Trace().Msgf("Remote (coding) opts: %#v", opts)
|
log.Trace().Msgf("Forge (coding) opts: %#v", opts)
|
||||||
return coding.New(opts)
|
return coding.New(opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ The Multi-Pipeline feature allows the pipeline to be split into several files an
|
||||||
|
|
||||||
## Rational
|
## Rational
|
||||||
|
|
||||||
- faster lint/test feedback, the pipeline doesn't have to run fully to have a lint status pushed to the remote
|
- faster lint/test feedback, the pipeline doesn't have to run fully to have a lint status pushed to the forge
|
||||||
- better organization of the pipeline along various concerns: testing, linting, feature apps
|
- better organization of the pipeline along various concerns: testing, linting, feature apps
|
||||||
- utilizing more agents to speed up build
|
- utilizing more agents to speed up build
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ This is the reference list of all environment variables available to your pipeli
|
||||||
| `CI_REPO_NAME` | repository name |
|
| `CI_REPO_NAME` | repository name |
|
||||||
| `CI_REPO_SCM` | repository SCM (git) |
|
| `CI_REPO_SCM` | repository SCM (git) |
|
||||||
| `CI_REPO_LINK` | repository link |
|
| `CI_REPO_LINK` | repository link |
|
||||||
| `CI_REPO_REMOTE` | repository clone URL |
|
| `CI_REPO_CLONE_URL` | repository clone URL |
|
||||||
| `CI_REPO_DEFAULT_BRANCH` | repository default branch (master) |
|
| `CI_REPO_DEFAULT_BRANCH` | repository default branch (master) |
|
||||||
| `CI_REPO_PRIVATE` | repository is private |
|
| `CI_REPO_PRIVATE` | repository is private |
|
||||||
| `CI_REPO_TRUSTED` | repository is trusted |
|
| `CI_REPO_TRUSTED` | repository is trusted |
|
||||||
|
@ -68,7 +68,7 @@ This is the reference list of all environment variables available to your pipeli
|
||||||
| `CI_COMMIT_TARGET_BRANCH` | commit target branch |
|
| `CI_COMMIT_TARGET_BRANCH` | commit target branch |
|
||||||
| `CI_COMMIT_TAG` | commit tag name (empty if event is not `tag`) |
|
| `CI_COMMIT_TAG` | commit tag name (empty if event is not `tag`) |
|
||||||
| `CI_COMMIT_PULL_REQUEST` | commit pull request number (empty if event is not `pull_request`) |
|
| `CI_COMMIT_PULL_REQUEST` | commit pull request number (empty if event is not `pull_request`) |
|
||||||
| `CI_COMMIT_LINK` | commit link in remote |
|
| `CI_COMMIT_LINK` | commit link in forge |
|
||||||
| `CI_COMMIT_MESSAGE` | commit message |
|
| `CI_COMMIT_MESSAGE` | commit message |
|
||||||
| `CI_COMMIT_AUTHOR` | commit author username |
|
| `CI_COMMIT_AUTHOR` | commit author username |
|
||||||
| `CI_COMMIT_AUTHOR_EMAIL` | commit author email address |
|
| `CI_COMMIT_AUTHOR_EMAIL` | commit author email address |
|
||||||
|
@ -95,7 +95,7 @@ This is the reference list of all environment variables available to your pipeli
|
||||||
| `CI_PREV_COMMIT_BRANCH` | previous commit branch |
|
| `CI_PREV_COMMIT_BRANCH` | previous commit branch |
|
||||||
| `CI_PREV_COMMIT_SOURCE_BRANCH` | previous commit source branch |
|
| `CI_PREV_COMMIT_SOURCE_BRANCH` | previous commit source branch |
|
||||||
| `CI_PREV_COMMIT_TARGET_BRANCH` | previous commit target branch |
|
| `CI_PREV_COMMIT_TARGET_BRANCH` | previous commit target branch |
|
||||||
| `CI_PREV_COMMIT_LINK` | previous commit link in remote |
|
| `CI_PREV_COMMIT_LINK` | previous commit link in forge |
|
||||||
| `CI_PREV_COMMIT_MESSAGE` | previous commit message |
|
| `CI_PREV_COMMIT_MESSAGE` | previous commit message |
|
||||||
| `CI_PREV_COMMIT_AUTHOR` | previous commit author username |
|
| `CI_PREV_COMMIT_AUTHOR` | previous commit author username |
|
||||||
| `CI_PREV_COMMIT_AUTHOR_EMAIL` | previous commit author email address |
|
| `CI_PREV_COMMIT_AUTHOR_EMAIL` | previous commit author email address |
|
||||||
|
|
|
@ -69,7 +69,7 @@ WOODPECKER_CONFIG_SERVICE_ENDPOINT=https://example.com/ciconfig
|
||||||
"parent": 0,
|
"parent": 0,
|
||||||
"ref": "refs/heads/master",
|
"ref": "refs/heads/master",
|
||||||
"refspec": "",
|
"refspec": "",
|
||||||
"remote": "",
|
"clone_url": "",
|
||||||
"reviewed_at": 0,
|
"reviewed_at": 0,
|
||||||
"reviewed_by": "",
|
"reviewed_by": "",
|
||||||
"sender": "myUser",
|
"sender": "myUser",
|
||||||
|
|
|
@ -9,6 +9,7 @@ Some versions need some changes to the server configuration or the pipeline conf
|
||||||
- Renamed step environment variable `CI_SYSTEM_ARCH` to `CI_SYSTEM_PLATFORM`. Same applies for the cli exec variable.
|
- Renamed step environment variable `CI_SYSTEM_ARCH` to `CI_SYSTEM_PLATFORM`. Same applies for the cli exec variable.
|
||||||
- Renamed environment variables `CI_BUILD_*` and `CI_PREV_BUILD_*` to `CI_PIPELINE_*` and `CI_PREV_PIPELINE_*`, old ones are still available but deprecated
|
- Renamed environment variables `CI_BUILD_*` and `CI_PREV_BUILD_*` to `CI_PIPELINE_*` and `CI_PREV_PIPELINE_*`, old ones are still available but deprecated
|
||||||
- Renamed environment variables `CI_JOB_*` to `CI_STEP_*`, old ones are still available but deprecated
|
- Renamed environment variables `CI_JOB_*` to `CI_STEP_*`, old ones are still available but deprecated
|
||||||
|
- Renamed environment variable `CI_REPO_REMOTE` to `CI_REPO_CLONE_URL`
|
||||||
- Renamed API endpoints for pipelines (`<owner>/<repo>/builds/<buildId>` -> `<owner>/<repo>/pipelines/<pipelineId>`), old ones are still available but deprecated
|
- Renamed API endpoints for pipelines (`<owner>/<repo>/builds/<buildId>` -> `<owner>/<repo>/pipelines/<pipelineId>`), old ones are still available but deprecated
|
||||||
- Updated Prometheus gauge `build_*` to `pipeline_*`
|
- Updated Prometheus gauge `build_*` to `pipeline_*`
|
||||||
- Updated Prometheus gauge `*_job_*` to `*_step_*`
|
- Updated Prometheus gauge `*_job_*` to `*_step_*`
|
||||||
|
|
|
@ -20,19 +20,19 @@
|
||||||
### Server
|
### Server
|
||||||
|
|
||||||
| package | meaning | imports
|
| package | meaning | imports
|
||||||
|---------------------|-------------------------------------------------|----------
|
|----------------------|-------------------------------------------------------------------------------------|----------
|
||||||
| `server/api/**` | handle web requests from `server/router` | `pipeline`, `../badges`, `../ccmenue`, `../logging`, `../model`, `../pubsub`, `../queue`, `../remote`, `../shared`, `../store`, `shared`, (TODO: mv `server/router/middleware/session`)
|
| `server/api/**` | handle web requests from `server/router` | `pipeline`, `../badges`, `../ccmenue`, `../logging`, `../model`, `../pubsub`, `../queue`, `../forge`, `../shared`, `../store`, `shared`, (TODO: mv `server/router/middleware/session`)
|
||||||
| `server/badges/**` | generate svg badges for pipelines | `../model`
|
| `server/badges/**` | generate svg badges for pipelines | `../model`
|
||||||
| `server/ccmenu/**` | generate xml ccmenu for pipelines | `../model`
|
| `server/ccmenu/**` | generate xml ccmenu for pipelines | `../model`
|
||||||
| `server/grpc/**` | gRPC server agents can connect to | `pipeline/rpc/**`, `../logging`, `../model`, `../pubsub`, `../queue`, `../remote`, `../pipeline`, `../store`
|
| `server/grpc/**` | gRPC server agents can connect to | `pipeline/rpc/**`, `../logging`, `../model`, `../pubsub`, `../queue`, `../forge`, `../pipeline`, `../store`
|
||||||
| `server/logging/**` | logging lib for gPRC server to stream logs while running | std
|
| `server/logging/**` | logging lib for gPRC server to stream logs while running | std
|
||||||
| `server/model/**` | structs for store (db) and api (json) | std
|
| `server/model/**` | structs for store (db) and api (json) | std
|
||||||
| `server/plugins/**` | plugins for server | `../model`, `../remote`
|
| `server/plugins/**` | plugins for server | `../model`, `../forge`
|
||||||
| `server/pipeline/**`| orchestrate pipelines | `pipeline`, `../model`, `../pubsub`, `../queue`, `../remote`, `../store`, `../plugins`
|
| `server/pipeline/**` | orchestrate pipelines | `pipeline`, `../model`, `../pubsub`, `../queue`, `../forge`, `../store`, `../plugins`
|
||||||
| `server/pubsub/**` | pubsub lib for server to push changes to the WebUI | std
|
| `server/pubsub/**` | pubsub lib for server to push changes to the WebUI | std
|
||||||
| `server/queue/**` | queue lib for server where agents pull new pipelines from via gRPC | `server/model`
|
| `server/queue/**` | queue lib for server where agents pull new pipelines from via gRPC | `server/model`
|
||||||
| `server/remote/**` | remote lib for server to connect and handle forge specific stuff | `shared`, `server/model`
|
| `server/forge/**` | forge lib for server to connect and handle forge specific stuff | `shared`, `server/model`
|
||||||
| `server/router/**` | handle requests to REST API (and all middleware) and serve UI and WebUI config | `shared`, `../api`, `../model`, `../remote`, `../store`, `../web`
|
| `server/router/**` | handle requests to REST API (and all middleware) and serve UI and WebUI config | `shared`, `../api`, `../model`, `../forge`, `../store`, `../web`
|
||||||
| `server/store/**` | handle database | `server/model`
|
| `server/store/**` | handle database | `server/model`
|
||||||
| `server/shared/**` | TODO: move and split [#974](https://github.com/woodpecker-ci/woodpecker/issues/974) |
|
| `server/shared/**` | TODO: move and split [#974](https://github.com/woodpecker-ci/woodpecker/issues/974) |
|
||||||
| `server/web/**` | server SPA |
|
| `server/web/**` | server SPA |
|
||||||
|
|
|
@ -51,8 +51,8 @@ func (m *Metadata) setDroneEnviron(env map[string]string) {
|
||||||
env["DRONE_REPO_BRANCH"] = env["CI_REPO_DEFAULT_BRANCH"]
|
env["DRONE_REPO_BRANCH"] = env["CI_REPO_DEFAULT_BRANCH"]
|
||||||
env["DRONE_REPO_PRIVATE"] = env["CI_REPO_PRIVATE"]
|
env["DRONE_REPO_PRIVATE"] = env["CI_REPO_PRIVATE"]
|
||||||
// clone
|
// clone
|
||||||
env["DRONE_REMOTE_URL"] = env["CI_REPO_REMOTE"]
|
env["DRONE_REMOTE_URL"] = env["CI_REPO_CLONE_URL"]
|
||||||
env["DRONE_GIT_HTTP_URL"] = env["CI_REPO_REMOTE"]
|
env["DRONE_GIT_HTTP_URL"] = env["CI_REPO_CLONE_URL"]
|
||||||
// misc
|
// misc
|
||||||
env["DRONE_SYSTEM_HOST"] = env["CI_SYSTEM_HOST"]
|
env["DRONE_SYSTEM_HOST"] = env["CI_SYSTEM_HOST"]
|
||||||
env["DRONE_STEP_NUMBER"] = env["CI_STEP_NUMBER"]
|
env["DRONE_STEP_NUMBER"] = env["CI_STEP_NUMBER"]
|
||||||
|
|
|
@ -47,7 +47,7 @@ type (
|
||||||
Repo struct {
|
Repo struct {
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
Link string `json:"link,omitempty"`
|
Link string `json:"link,omitempty"`
|
||||||
Remote string `json:"remote,omitempty"`
|
CloneURL string `json:"clone_url,omitempty"`
|
||||||
Private bool `json:"private,omitempty"`
|
Private bool `json:"private,omitempty"`
|
||||||
Secrets []Secret `json:"secrets,omitempty"`
|
Secrets []Secret `json:"secrets,omitempty"`
|
||||||
Branch string `json:"default_branch,omitempty"`
|
Branch string `json:"default_branch,omitempty"`
|
||||||
|
@ -142,7 +142,7 @@ func (m *Metadata) Environ() map[string]string {
|
||||||
"CI_REPO_NAME": repoName,
|
"CI_REPO_NAME": repoName,
|
||||||
"CI_REPO_SCM": "git",
|
"CI_REPO_SCM": "git",
|
||||||
"CI_REPO_LINK": m.Repo.Link,
|
"CI_REPO_LINK": m.Repo.Link,
|
||||||
"CI_REPO_REMOTE": m.Repo.Remote,
|
"CI_REPO_CLONE_URL": m.Repo.CloneURL,
|
||||||
"CI_REPO_DEFAULT_BRANCH": m.Repo.Branch,
|
"CI_REPO_DEFAULT_BRANCH": m.Repo.Branch,
|
||||||
"CI_REPO_PRIVATE": strconv.FormatBool(m.Repo.Private),
|
"CI_REPO_PRIVATE": strconv.FormatBool(m.Repo.Private),
|
||||||
"CI_REPO_TRUSTED": "false", // TODO should this be added?
|
"CI_REPO_TRUSTED": "false", // TODO should this be added?
|
||||||
|
@ -229,6 +229,8 @@ func (m *Metadata) Environ() map[string]string {
|
||||||
"CI_JOB_STATUS": "", // will be set by agent
|
"CI_JOB_STATUS": "", // will be set by agent
|
||||||
"CI_JOB_STARTED": "", // will be set by agent
|
"CI_JOB_STARTED": "", // will be set by agent
|
||||||
"CI_JOB_FINISHED": "", // will be set by agent
|
"CI_JOB_FINISHED": "", // will be set by agent
|
||||||
|
// CI_REPO_CLONE_URL
|
||||||
|
"CI_REPO_REMOTE": m.Repo.CloneURL,
|
||||||
}
|
}
|
||||||
if m.Curr.Event == EventTag {
|
if m.Curr.Event == EventTag {
|
||||||
params["CI_COMMIT_TAG"] = strings.TrimPrefix(m.Curr.Commit.Ref, "refs/tags/")
|
params["CI_COMMIT_TAG"] = strings.TrimPrefix(m.Curr.Commit.Ref, "refs/tags/")
|
||||||
|
|
|
@ -103,7 +103,7 @@ func TestWithMetadata(t *testing.T) {
|
||||||
Name: "octocat/hello-world",
|
Name: "octocat/hello-world",
|
||||||
Private: true,
|
Private: true,
|
||||||
Link: "https://github.com/octocat/hello-world",
|
Link: "https://github.com/octocat/hello-world",
|
||||||
Remote: "https://github.com/octocat/hello-world.git",
|
CloneURL: "https://github.com/octocat/hello-world.git",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
compiler := New(
|
compiler := New(
|
||||||
|
@ -119,8 +119,8 @@ func TestWithMetadata(t *testing.T) {
|
||||||
if compiler.env["CI_REPO_LINK"] != metadata.Repo.Link {
|
if compiler.env["CI_REPO_LINK"] != metadata.Repo.Link {
|
||||||
t.Errorf("WithMetadata must set CI_REPO_LINK")
|
t.Errorf("WithMetadata must set CI_REPO_LINK")
|
||||||
}
|
}
|
||||||
if compiler.env["CI_REPO_REMOTE"] != metadata.Repo.Remote {
|
if compiler.env["CI_REPO_CLONE_URL"] != metadata.Repo.CloneURL {
|
||||||
t.Errorf("WithMetadata must set CI_REPO_REMOTE")
|
t.Errorf("WithMetadata must set CI_REPO_CLONE_URL")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ func RunCron(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
repo, newPipeline, err := cronScheduler.CreatePipeline(c, _store, server.Config.Services.Remote, cron)
|
repo, newPipeline, err := cronScheduler.CreatePipeline(c, _store, server.Config.Services.Forge, cron)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(http.StatusInternalServerError, "Error creating pipeline for cron %q. %s", id, err)
|
c.String(http.StatusInternalServerError, "Error creating pipeline for cron %q. %s", id, err)
|
||||||
return
|
return
|
||||||
|
@ -82,7 +82,7 @@ func PostCron(c *gin.Context) {
|
||||||
repo := session.Repo(c)
|
repo := session.Repo(c)
|
||||||
user := session.User(c)
|
user := session.User(c)
|
||||||
store := store.FromContext(c)
|
store := store.FromContext(c)
|
||||||
remote := server.Config.Services.Remote
|
forge := server.Config.Services.Forge
|
||||||
|
|
||||||
in := new(model.Cron)
|
in := new(model.Cron)
|
||||||
if err := c.Bind(in); err != nil {
|
if err := c.Bind(in); err != nil {
|
||||||
|
@ -109,8 +109,8 @@ func PostCron(c *gin.Context) {
|
||||||
cron.NextExec = nextExec.Unix()
|
cron.NextExec = nextExec.Unix()
|
||||||
|
|
||||||
if in.Branch != "" {
|
if in.Branch != "" {
|
||||||
// check if branch exists on remote
|
// check if branch exists on forge
|
||||||
_, err := remote.BranchHead(c, user, repo, in.Branch)
|
_, err := forge.BranchHead(c, user, repo, in.Branch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(400, "Error inserting cron. branch not resolved: %s", err)
|
c.String(400, "Error inserting cron. branch not resolved: %s", err)
|
||||||
return
|
return
|
||||||
|
@ -129,7 +129,7 @@ func PatchCron(c *gin.Context) {
|
||||||
repo := session.Repo(c)
|
repo := session.Repo(c)
|
||||||
user := session.User(c)
|
user := session.User(c)
|
||||||
store := store.FromContext(c)
|
store := store.FromContext(c)
|
||||||
remote := server.Config.Services.Remote
|
forge := server.Config.Services.Forge
|
||||||
|
|
||||||
id, err := strconv.ParseInt(c.Param("cron"), 10, 64)
|
id, err := strconv.ParseInt(c.Param("cron"), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -150,8 +150,8 @@ func PatchCron(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if in.Branch != "" {
|
if in.Branch != "" {
|
||||||
// check if branch exists on remote
|
// check if branch exists on forge
|
||||||
_, err := remote.BranchHead(c, user, repo, in.Branch)
|
_, err := forge.BranchHead(c, user, repo, in.Branch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(400, "Error inserting cron. branch not resolved: %s", err)
|
c.String(400, "Error inserting cron. branch not resolved: %s", err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -21,9 +21,9 @@ import (
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server"
|
"github.com/woodpecker-ci/woodpecker/server"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/pipeline"
|
"github.com/woodpecker-ci/woodpecker/server/pipeline"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote"
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server/store"
|
"github.com/woodpecker-ci/woodpecker/server/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -39,12 +39,12 @@ func handlePipelineErr(c *gin.Context, err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the remote has a refresh token, the current access token may be stale.
|
// if the forge has a refresh token, the current access token may be stale.
|
||||||
// Therefore, we should refresh prior to dispatching the job.
|
// Therefore, we should refresh prior to dispatching the job.
|
||||||
func refreshUserToken(c *gin.Context, user *model.User) {
|
func refreshUserToken(c *gin.Context, user *model.User) {
|
||||||
_remote := server.Config.Services.Remote
|
_forge := server.Config.Services.Forge
|
||||||
_store := store.FromContext(c)
|
_store := store.FromContext(c)
|
||||||
if refresher, ok := _remote.(remote.Refresher); ok {
|
if refresher, ok := _forge.(forge.Refresher); ok {
|
||||||
ok, err := refresher.Refresh(c, user)
|
ok, err := refresher.Refresh(c, user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msgf("refresh oauth token of user '%s' failed", user.Login)
|
log.Error().Err(err).Msgf("refresh oauth token of user '%s' failed", user.Login)
|
||||||
|
|
|
@ -70,9 +70,9 @@ func BlockTilQueueHasRunningItem(c *gin.Context) {
|
||||||
// PostHook start a pipeline triggered by a forges post webhook
|
// PostHook start a pipeline triggered by a forges post webhook
|
||||||
func PostHook(c *gin.Context) {
|
func PostHook(c *gin.Context) {
|
||||||
_store := store.FromContext(c)
|
_store := store.FromContext(c)
|
||||||
remote := server.Config.Services.Remote
|
forge := server.Config.Services.Forge
|
||||||
|
|
||||||
tmpRepo, tmpBuild, err := remote.Hook(c, c.Request)
|
tmpRepo, tmpBuild, err := forge.Hook(c, c.Request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg := "failure to parse hook"
|
msg := "failure to parse hook"
|
||||||
log.Debug().Err(err).Msg(msg)
|
log.Debug().Err(err).Msg(msg)
|
||||||
|
@ -102,7 +102,7 @@ func PostHook(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
repo, err := _store.GetRepoNameFallback(tmpRepo.RemoteID, tmpRepo.FullName)
|
repo, err := _store.GetRepoNameFallback(tmpRepo.ForgeID, tmpRepo.FullName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg := fmt.Sprintf("failure to get repo %s from store", tmpRepo.FullName)
|
msg := fmt.Sprintf("failure to get repo %s from store", tmpRepo.FullName)
|
||||||
log.Error().Err(err).Msg(msg)
|
log.Error().Err(err).Msg(msg)
|
||||||
|
|
|
@ -49,13 +49,13 @@ func HandleAuth(c *gin.Context) {
|
||||||
// cannot, however, remember why, so need to revisit this line.
|
// cannot, however, remember why, so need to revisit this line.
|
||||||
c.Writer.Header().Del("Content-Type")
|
c.Writer.Header().Del("Content-Type")
|
||||||
|
|
||||||
tmpuser, err := server.Config.Services.Remote.Login(c, c.Writer, c.Request)
|
tmpuser, err := server.Config.Services.Forge.Login(c, c.Writer, c.Request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Msgf("cannot authenticate user. %s", err)
|
log.Error().Msgf("cannot authenticate user. %s", err)
|
||||||
c.Redirect(303, "/login?error=oauth_error")
|
c.Redirect(303, "/login?error=oauth_error")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// this will happen when the user is redirected by the remote provider as
|
// this will happen when the user is redirected by the forge as
|
||||||
// part of the authorization workflow.
|
// part of the authorization workflow.
|
||||||
if tmpuser == nil {
|
if tmpuser == nil {
|
||||||
return
|
return
|
||||||
|
@ -75,7 +75,7 @@ func HandleAuth(c *gin.Context) {
|
||||||
// if self-registration is enabled for whitelisted organizations we need to
|
// if self-registration is enabled for whitelisted organizations we need to
|
||||||
// check the user's organization membership.
|
// check the user's organization membership.
|
||||||
if len(config.Orgs) != 0 {
|
if len(config.Orgs) != 0 {
|
||||||
teams, terr := server.Config.Services.Remote.Teams(c, tmpuser)
|
teams, terr := server.Config.Services.Forge.Teams(c, tmpuser)
|
||||||
if terr != nil || !config.IsMember(teams) {
|
if terr != nil || !config.IsMember(teams) {
|
||||||
log.Error().Msgf("cannot verify team membership for %s.", u.Login)
|
log.Error().Msgf("cannot verify team membership for %s.", u.Login)
|
||||||
c.Redirect(303, "/login?error=access_denied")
|
c.Redirect(303, "/login?error=access_denied")
|
||||||
|
@ -112,7 +112,7 @@ func HandleAuth(c *gin.Context) {
|
||||||
// if self-registration is enabled for whitelisted organizations we need to
|
// if self-registration is enabled for whitelisted organizations we need to
|
||||||
// check the user's organization membership.
|
// check the user's organization membership.
|
||||||
if len(config.Orgs) != 0 {
|
if len(config.Orgs) != 0 {
|
||||||
teams, terr := server.Config.Services.Remote.Teams(c, u)
|
teams, terr := server.Config.Services.Forge.Teams(c, u)
|
||||||
if terr != nil || !config.IsMember(teams) {
|
if terr != nil || !config.IsMember(teams) {
|
||||||
log.Error().Msgf("cannot verify team membership for %s.", u.Login)
|
log.Error().Msgf("cannot verify team membership for %s.", u.Login)
|
||||||
c.Redirect(303, "/login?error=access_denied")
|
c.Redirect(303, "/login?error=access_denied")
|
||||||
|
@ -155,7 +155,7 @@ func GetLoginToken(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
login, err := server.Config.Services.Remote.Auth(c, in.Access, in.Refresh)
|
login, err := server.Config.Services.Forge.Auth(c, in.Access, in.Refresh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = c.AbortWithError(http.StatusUnauthorized, err)
|
_ = c.AbortWithError(http.StatusUnauthorized, err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -54,7 +54,7 @@ func CreatePipeline(c *gin.Context) {
|
||||||
|
|
||||||
user := session.User(c)
|
user := session.User(c)
|
||||||
|
|
||||||
lastCommit, _ := server.Config.Services.Remote.BranchHead(c, user, repo, p.Branch)
|
lastCommit, _ := server.Config.Services.Forge.BranchHead(c, user, repo, p.Branch)
|
||||||
|
|
||||||
tmpBuild := createTmpPipeline(model.EventManual, lastCommit, repo, user, &p)
|
tmpBuild := createTmpPipeline(model.EventManual, lastCommit, repo, user, &p)
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func PostRepo(c *gin.Context) {
|
func PostRepo(c *gin.Context) {
|
||||||
remote := server.Config.Services.Remote
|
forge := server.Config.Services.Forge
|
||||||
_store := store.FromContext(c)
|
_store := store.FromContext(c)
|
||||||
user := session.User(c)
|
user := session.User(c)
|
||||||
repo := session.Repo(c)
|
repo := session.Repo(c)
|
||||||
|
@ -87,7 +87,7 @@ func PostRepo(c *gin.Context) {
|
||||||
sig,
|
sig,
|
||||||
)
|
)
|
||||||
|
|
||||||
from, err := remote.Repo(c, user, repo.RemoteID, repo.Owner, repo.Name)
|
from, err := forge.Repo(c, user, repo.ForgeID, repo.Owner, repo.Name)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if repo.FullName != from.FullName {
|
if repo.FullName != from.FullName {
|
||||||
// create a redirection
|
// create a redirection
|
||||||
|
@ -100,7 +100,7 @@ func PostRepo(c *gin.Context) {
|
||||||
repo.Update(from)
|
repo.Update(from)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = remote.Activate(c, user, repo, link)
|
err = forge.Activate(c, user, repo, link)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(http.StatusInternalServerError, err.Error())
|
c.String(http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
|
@ -198,9 +198,9 @@ func GetRepoPermissions(c *gin.Context) {
|
||||||
func GetRepoBranches(c *gin.Context) {
|
func GetRepoBranches(c *gin.Context) {
|
||||||
repo := session.Repo(c)
|
repo := session.Repo(c)
|
||||||
user := session.User(c)
|
user := session.User(c)
|
||||||
r := server.Config.Services.Remote
|
f := server.Config.Services.Forge
|
||||||
|
|
||||||
branches, err := r.Branches(c, user, repo)
|
branches, err := f.Branches(c, user, repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = c.AbortWithError(http.StatusInternalServerError, err)
|
_ = c.AbortWithError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
|
@ -231,7 +231,7 @@ func DeleteRepo(c *gin.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := server.Config.Services.Remote.Deactivate(c, user, repo, server.Config.Server.Host); err != nil {
|
if err := server.Config.Services.Forge.Deactivate(c, user, repo, server.Config.Server.Host); err != nil {
|
||||||
_ = c.AbortWithError(http.StatusInternalServerError, err)
|
_ = c.AbortWithError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -239,7 +239,7 @@ func DeleteRepo(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func RepairRepo(c *gin.Context) {
|
func RepairRepo(c *gin.Context) {
|
||||||
remote := server.Config.Services.Remote
|
forge := server.Config.Services.Forge
|
||||||
_store := store.FromContext(c)
|
_store := store.FromContext(c)
|
||||||
repo := session.Repo(c)
|
repo := session.Repo(c)
|
||||||
user := session.User(c)
|
user := session.User(c)
|
||||||
|
@ -260,9 +260,9 @@ func RepairRepo(c *gin.Context) {
|
||||||
sig,
|
sig,
|
||||||
)
|
)
|
||||||
|
|
||||||
from, err := remote.Repo(c, user, repo.RemoteID, repo.Owner, repo.Name)
|
from, err := forge.Repo(c, user, repo.ForgeID, repo.Owner, repo.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msgf("get repo '%s/%s' from remote", repo.Owner, repo.Name)
|
log.Error().Err(err).Msgf("get repo '%s/%s' from forge", repo.Owner, repo.Name)
|
||||||
c.AbortWithStatus(http.StatusInternalServerError)
|
c.AbortWithStatus(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -282,10 +282,10 @@ func RepairRepo(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := remote.Deactivate(c, user, repo, host); err != nil {
|
if err := forge.Deactivate(c, user, repo, host); err != nil {
|
||||||
log.Trace().Err(err).Msgf("deactivate repo '%s' to repair failed", repo.FullName)
|
log.Trace().Err(err).Msgf("deactivate repo '%s' to repair failed", repo.FullName)
|
||||||
}
|
}
|
||||||
if err := remote.Activate(c, user, repo, link); err != nil {
|
if err := forge.Activate(c, user, repo, link); err != nil {
|
||||||
c.String(500, err.Error())
|
c.String(500, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -294,7 +294,7 @@ func RepairRepo(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func MoveRepo(c *gin.Context) {
|
func MoveRepo(c *gin.Context) {
|
||||||
remote := server.Config.Services.Remote
|
forge := server.Config.Services.Forge
|
||||||
_store := store.FromContext(c)
|
_store := store.FromContext(c)
|
||||||
repo := session.Repo(c)
|
repo := session.Repo(c)
|
||||||
user := session.User(c)
|
user := session.User(c)
|
||||||
|
@ -312,7 +312,7 @@ func MoveRepo(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
from, err := remote.Repo(c, user, "", owner, name)
|
from, err := forge.Repo(c, user, "", owner, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = c.AbortWithError(http.StatusInternalServerError, err)
|
_ = c.AbortWithError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
|
@ -352,10 +352,10 @@ func MoveRepo(c *gin.Context) {
|
||||||
sig,
|
sig,
|
||||||
)
|
)
|
||||||
|
|
||||||
if err := remote.Deactivate(c, user, repo, host); err != nil {
|
if err := forge.Deactivate(c, user, repo, host); err != nil {
|
||||||
log.Trace().Err(err).Msgf("deactivate repo '%s' for move to activate later, got an error", repo.FullName)
|
log.Trace().Err(err).Msgf("deactivate repo '%s' for move to activate later, got an error", repo.FullName)
|
||||||
}
|
}
|
||||||
if err := remote.Activate(c, user, repo, link); err != nil {
|
if err := forge.Activate(c, user, repo, link); err != nil {
|
||||||
c.String(500, err.Error())
|
c.String(500, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ func GetSelf(c *gin.Context) {
|
||||||
|
|
||||||
func GetFeed(c *gin.Context) {
|
func GetFeed(c *gin.Context) {
|
||||||
_store := store.FromContext(c)
|
_store := store.FromContext(c)
|
||||||
remote := server.Config.Services.Remote
|
forge := server.Config.Services.Forge
|
||||||
|
|
||||||
user := session.User(c)
|
user := session.User(c)
|
||||||
latest, _ := strconv.ParseBool(c.Query("latest"))
|
latest, _ := strconv.ParseBool(c.Query("latest"))
|
||||||
|
@ -55,7 +55,7 @@ func GetFeed(c *gin.Context) {
|
||||||
config := ToConfig(c)
|
config := ToConfig(c)
|
||||||
|
|
||||||
sync := shared.Syncer{
|
sync := shared.Syncer{
|
||||||
Remote: remote,
|
Forge: forge,
|
||||||
Store: _store,
|
Store: _store,
|
||||||
Perms: _store,
|
Perms: _store,
|
||||||
Match: shared.NamespaceFilter(config.OwnersWhitelist),
|
Match: shared.NamespaceFilter(config.OwnersWhitelist),
|
||||||
|
@ -87,7 +87,7 @@ func GetFeed(c *gin.Context) {
|
||||||
|
|
||||||
func GetRepos(c *gin.Context) {
|
func GetRepos(c *gin.Context) {
|
||||||
_store := store.FromContext(c)
|
_store := store.FromContext(c)
|
||||||
remote := server.Config.Services.Remote
|
forge := server.Config.Services.Forge
|
||||||
|
|
||||||
user := session.User(c)
|
user := session.User(c)
|
||||||
all, _ := strconv.ParseBool(c.Query("all"))
|
all, _ := strconv.ParseBool(c.Query("all"))
|
||||||
|
@ -104,7 +104,7 @@ func GetRepos(c *gin.Context) {
|
||||||
config := ToConfig(c)
|
config := ToConfig(c)
|
||||||
|
|
||||||
sync := shared.Syncer{
|
sync := shared.Syncer{
|
||||||
Remote: remote,
|
Forge: forge,
|
||||||
Store: _store,
|
Store: _store,
|
||||||
Perms: _store,
|
Perms: _store,
|
||||||
Match: shared.NamespaceFilter(config.OwnersWhitelist),
|
Match: shared.NamespaceFilter(config.OwnersWhitelist),
|
||||||
|
|
10
server/cache/membership.go
vendored
10
server/cache/membership.go
vendored
|
@ -18,8 +18,8 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote"
|
|
||||||
|
|
||||||
"github.com/lafriks/ttlcache/v3"
|
"github.com/lafriks/ttlcache/v3"
|
||||||
)
|
)
|
||||||
|
@ -31,16 +31,16 @@ type MembershipService interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type membershipCache struct {
|
type membershipCache struct {
|
||||||
Remote remote.Remote
|
Forge forge.Forge
|
||||||
Cache *ttlcache.Cache[string, *model.OrgPerm]
|
Cache *ttlcache.Cache[string, *model.OrgPerm]
|
||||||
TTL time.Duration
|
TTL time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMembershipService creates a new membership service.
|
// NewMembershipService creates a new membership service.
|
||||||
func NewMembershipService(r remote.Remote) MembershipService {
|
func NewMembershipService(f forge.Forge) MembershipService {
|
||||||
return &membershipCache{
|
return &membershipCache{
|
||||||
TTL: 10 * time.Minute,
|
TTL: 10 * time.Minute,
|
||||||
Remote: r,
|
Forge: f,
|
||||||
Cache: ttlcache.New(ttlcache.WithDisableTouchOnHit[string, *model.OrgPerm]()),
|
Cache: ttlcache.New(ttlcache.WithDisableTouchOnHit[string, *model.OrgPerm]()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ func (c *membershipCache) Get(ctx context.Context, u *model.User, name string) (
|
||||||
return item.Value(), nil
|
return item.Value(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
perm, err := c.Remote.OrgMembership(ctx, u, name)
|
perm, err := c.Forge.OrgMembership(ctx, u, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,12 +22,12 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server/cache"
|
"github.com/woodpecker-ci/woodpecker/server/cache"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/logging"
|
"github.com/woodpecker-ci/woodpecker/server/logging"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/plugins/config"
|
"github.com/woodpecker-ci/woodpecker/server/plugins/config"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/pubsub"
|
"github.com/woodpecker-ci/woodpecker/server/pubsub"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/queue"
|
"github.com/woodpecker-ci/woodpecker/server/queue"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var Config = struct {
|
var Config = struct {
|
||||||
|
@ -38,7 +38,7 @@ var Config = struct {
|
||||||
Secrets model.SecretService
|
Secrets model.SecretService
|
||||||
Registries model.RegistryService
|
Registries model.RegistryService
|
||||||
Environ model.EnvironService
|
Environ model.EnvironService
|
||||||
Remote remote.Remote
|
Forge forge.Forge
|
||||||
Membership cache.MembershipService
|
Membership cache.MembershipService
|
||||||
ConfigService config.Extension
|
ConfigService config.Extension
|
||||||
SignaturePrivateKey crypto.PrivateKey
|
SignaturePrivateKey crypto.PrivateKey
|
||||||
|
|
|
@ -22,9 +22,9 @@ import (
|
||||||
"github.com/robfig/cron"
|
"github.com/robfig/cron"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/pipeline"
|
"github.com/woodpecker-ci/woodpecker/server/pipeline"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote"
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server/store"
|
"github.com/woodpecker-ci/woodpecker/server/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start starts the cron scheduler loop
|
// Start starts the cron scheduler loop
|
||||||
func Start(ctx context.Context, store store.Store, remote remote.Remote) error {
|
func Start(ctx context.Context, store store.Store, forge forge.Forge) error {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
@ -54,7 +54,7 @@ func Start(ctx context.Context, store store.Store, remote remote.Remote) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, cron := range crons {
|
for _, cron := range crons {
|
||||||
if err := runCron(store, remote, cron, now); err != nil {
|
if err := runCron(store, forge, cron, now); err != nil {
|
||||||
log.Error().Err(err).Int64("cronID", cron.ID).Msg("run cron failed")
|
log.Error().Err(err).Int64("cronID", cron.ID).Msg("run cron failed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ func CalcNewNext(schedule string, now time.Time) (time.Time, error) {
|
||||||
return c.Next(now), nil
|
return c.Next(now), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func runCron(store store.Store, remote remote.Remote, cron *model.Cron, now time.Time) error {
|
func runCron(store store.Store, forge forge.Forge, cron *model.Cron, now time.Time) error {
|
||||||
log.Trace().Msgf("Cron: run id[%d]", cron.ID)
|
log.Trace().Msgf("Cron: run id[%d]", cron.ID)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ func runCron(store store.Store, remote remote.Remote, cron *model.Cron, now time
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
repo, newPipeline, err := CreatePipeline(ctx, store, remote, cron)
|
repo, newPipeline, err := CreatePipeline(ctx, store, forge, cron)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@ func runCron(store store.Store, remote remote.Remote, cron *model.Cron, now time
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreatePipeline(ctx context.Context, store store.Store, remote remote.Remote, cron *model.Cron) (*model.Repo, *model.Pipeline, error) {
|
func CreatePipeline(ctx context.Context, store store.Store, forge forge.Forge, cron *model.Cron) (*model.Repo, *model.Pipeline, error) {
|
||||||
repo, err := store.GetRepo(cron.RepoID)
|
repo, err := store.GetRepo(cron.RepoID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
|
@ -121,7 +121,7 @@ func CreatePipeline(ctx context.Context, store store.Store, remote remote.Remote
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
commit, err := remote.BranchHead(ctx, creator, repo, cron.Branch)
|
commit, err := forge.BranchHead(ctx, creator, repo, cron.Branch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,13 +22,13 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
|
|
||||||
|
mocks_forge "github.com/woodpecker-ci/woodpecker/server/forge/mocks"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
mocks_remote "github.com/woodpecker-ci/woodpecker/server/remote/mocks"
|
|
||||||
mocks_store "github.com/woodpecker-ci/woodpecker/server/store/mocks"
|
mocks_store "github.com/woodpecker-ci/woodpecker/server/store/mocks"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCreateBuild(t *testing.T) {
|
func TestCreateBuild(t *testing.T) {
|
||||||
remote := mocks_remote.NewRemote(t)
|
forge := mocks_forge.NewForge(t)
|
||||||
store := mocks_store.NewStore(t)
|
store := mocks_store.NewStore(t)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
|
@ -47,9 +47,9 @@ func TestCreateBuild(t *testing.T) {
|
||||||
// mock things
|
// mock things
|
||||||
store.On("GetRepo", mock.Anything).Return(repo1, nil)
|
store.On("GetRepo", mock.Anything).Return(repo1, nil)
|
||||||
store.On("GetUser", mock.Anything).Return(creator, nil)
|
store.On("GetUser", mock.Anything).Return(creator, nil)
|
||||||
remote.On("BranchHead", mock.Anything, creator, repo1, "default").Return("sha1", nil)
|
forge.On("BranchHead", mock.Anything, creator, repo1, "default").Return("sha1", nil)
|
||||||
|
|
||||||
_, pipeline, err := CreatePipeline(ctx, store, remote, &model.Cron{
|
_, pipeline, err := CreatePipeline(ctx, store, forge, &model.Cron{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
|
@ -24,10 +24,10 @@ import (
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server"
|
"github.com/woodpecker-ci/woodpecker/server"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/bitbucket/internal"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/common"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote"
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/bitbucket/internal"
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/common"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Bitbucket cloud endpoints.
|
// Bitbucket cloud endpoints.
|
||||||
|
@ -36,7 +36,7 @@ const (
|
||||||
DefaultURL = "https://bitbucket.org"
|
DefaultURL = "https://bitbucket.org"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Opts are remote options for bitbucket
|
// Opts are forge options for bitbucket
|
||||||
type Opts struct {
|
type Opts struct {
|
||||||
Client string
|
Client string
|
||||||
Secret string
|
Secret string
|
||||||
|
@ -49,9 +49,9 @@ type config struct {
|
||||||
Secret string
|
Secret string
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new remote Configuration for integrating with the Bitbucket
|
// New returns a new forge Configuration for integrating with the Bitbucket
|
||||||
// repository hosting service at https://bitbucket.org
|
// repository hosting service at https://bitbucket.org
|
||||||
func New(opts *Opts) (remote.Remote, error) {
|
func New(opts *Opts) (forge.Forge, error) {
|
||||||
return &config{
|
return &config{
|
||||||
API: DefaultAPI,
|
API: DefaultAPI,
|
||||||
URL: DefaultURL,
|
URL: DefaultURL,
|
||||||
|
@ -73,7 +73,7 @@ func (c *config) Login(ctx context.Context, w http.ResponseWriter, req *http.Req
|
||||||
|
|
||||||
// get the OAuth errors
|
// get the OAuth errors
|
||||||
if err := req.FormValue("error"); err != "" {
|
if err := req.FormValue("error"); err != "" {
|
||||||
return nil, &remote.AuthError{
|
return nil, &forge.AuthError{
|
||||||
Err: err,
|
Err: err,
|
||||||
Description: req.FormValue("error_description"),
|
Description: req.FormValue("error_description"),
|
||||||
URI: req.FormValue("error_uri"),
|
URI: req.FormValue("error_uri"),
|
||||||
|
@ -143,7 +143,7 @@ func (c *config) Teams(ctx context.Context, u *model.User) ([]*model.Team, error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Repo returns the named Bitbucket repository.
|
// Repo returns the named Bitbucket repository.
|
||||||
func (c *config) Repo(ctx context.Context, u *model.User, id model.RemoteID, owner, name string) (*model.Repo, error) {
|
func (c *config) Repo(ctx context.Context, u *model.User, id model.ForgeID, owner, name string) (*model.Repo, error) {
|
||||||
if id.IsValid() {
|
if id.IsValid() {
|
||||||
name = string(id)
|
name = string(id)
|
||||||
}
|
}
|
||||||
|
@ -222,7 +222,7 @@ func (c *config) File(ctx context.Context, u *model.User, r *model.Repo, p *mode
|
||||||
return []byte(*config), err
|
return []byte(*config), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *config) Dir(ctx context.Context, u *model.User, r *model.Repo, p *model.Pipeline, f string) ([]*remote.FileMeta, error) {
|
func (c *config) Dir(ctx context.Context, u *model.User, r *model.Repo, p *model.Pipeline, f string) ([]*forge.FileMeta, error) {
|
||||||
return nil, fmt.Errorf("Not implemented")
|
return nil, fmt.Errorf("Not implemented")
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,9 +25,9 @@ import (
|
||||||
"github.com/franela/goblin"
|
"github.com/franela/goblin"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/bitbucket/fixtures"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/bitbucket/internal"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/bitbucket/fixtures"
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/bitbucket/internal"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_bitbucket(t *testing.T) {
|
func Test_bitbucket(t *testing.T) {
|
||||||
|
@ -44,16 +44,16 @@ func Test_bitbucket(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
g.It("Should return client with default endpoint", func() {
|
g.It("Should return client with default endpoint", func() {
|
||||||
remote, _ := New(&Opts{Client: "4vyW6b49Z", Secret: "a5012f6c6"})
|
forge, _ := New(&Opts{Client: "4vyW6b49Z", Secret: "a5012f6c6"})
|
||||||
g.Assert(remote.(*config).URL).Equal(DefaultURL)
|
g.Assert(forge.(*config).URL).Equal(DefaultURL)
|
||||||
g.Assert(remote.(*config).API).Equal(DefaultAPI)
|
g.Assert(forge.(*config).API).Equal(DefaultAPI)
|
||||||
g.Assert(remote.(*config).Client).Equal("4vyW6b49Z")
|
g.Assert(forge.(*config).Client).Equal("4vyW6b49Z")
|
||||||
g.Assert(remote.(*config).Secret).Equal("a5012f6c6")
|
g.Assert(forge.(*config).Secret).Equal("a5012f6c6")
|
||||||
})
|
})
|
||||||
|
|
||||||
g.It("Should return the netrc file", func() {
|
g.It("Should return the netrc file", func() {
|
||||||
remote, _ := New(&Opts{})
|
forge, _ := New(&Opts{})
|
||||||
netrc, _ := remote.Netrc(fakeUser, fakeRepo)
|
netrc, _ := forge.Netrc(fakeUser, fakeRepo)
|
||||||
g.Assert(netrc.Machine).Equal("bitbucket.org")
|
g.Assert(netrc.Machine).Equal("bitbucket.org")
|
||||||
g.Assert(netrc.Login).Equal("x-token-auth")
|
g.Assert(netrc.Login).Equal("x-token-auth")
|
||||||
g.Assert(netrc.Password).Equal(fakeUser.Token)
|
g.Assert(netrc.Password).Equal(fakeUser.Token)
|
|
@ -23,8 +23,8 @@ import (
|
||||||
|
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
|
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/bitbucket/internal"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/bitbucket/internal"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -50,7 +50,7 @@ func convertStatus(status model.StatusValue) string {
|
||||||
// structure to the common Woodpecker repository structure.
|
// structure to the common Woodpecker repository structure.
|
||||||
func convertRepo(from *internal.Repo) *model.Repo {
|
func convertRepo(from *internal.Repo) *model.Repo {
|
||||||
repo := model.Repo{
|
repo := model.Repo{
|
||||||
RemoteID: model.RemoteID(from.UUID),
|
ForgeID: model.ForgeID(from.UUID),
|
||||||
Clone: cloneLink(from),
|
Clone: cloneLink(from),
|
||||||
Owner: strings.Split(from.FullName, "/")[0],
|
Owner: strings.Split(from.FullName, "/")[0],
|
||||||
Name: strings.Split(from.FullName, "/")[1],
|
Name: strings.Split(from.FullName, "/")[1],
|
||||||
|
@ -140,7 +140,7 @@ func convertPullHook(from *internal.PullRequestHook) *model.Pipeline {
|
||||||
from.PullRequest.Source.Branch.Name,
|
from.PullRequest.Source.Branch.Name,
|
||||||
from.PullRequest.Dest.Branch.Name,
|
from.PullRequest.Dest.Branch.Name,
|
||||||
),
|
),
|
||||||
Remote: fmt.Sprintf("https://bitbucket.org/%s", from.PullRequest.Source.Repo.FullName),
|
CloneURL: fmt.Sprintf("https://bitbucket.org/%s", from.PullRequest.Source.Repo.FullName),
|
||||||
Link: from.PullRequest.Links.HTML.Href,
|
Link: from.PullRequest.Links.HTML.Href,
|
||||||
Branch: from.PullRequest.Dest.Branch.Name,
|
Branch: from.PullRequest.Dest.Branch.Name,
|
||||||
Message: from.PullRequest.Desc,
|
Message: from.PullRequest.Desc,
|
|
@ -22,8 +22,8 @@ import (
|
||||||
"github.com/franela/goblin"
|
"github.com/franela/goblin"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
|
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/bitbucket/internal"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/bitbucket/internal"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_helper(t *testing.T) {
|
func Test_helper(t *testing.T) {
|
||||||
|
@ -137,7 +137,7 @@ func Test_helper(t *testing.T) {
|
||||||
g.Assert(pipeline.Link).Equal(hook.PullRequest.Links.HTML.Href)
|
g.Assert(pipeline.Link).Equal(hook.PullRequest.Links.HTML.Href)
|
||||||
g.Assert(pipeline.Ref).Equal("refs/heads/master")
|
g.Assert(pipeline.Ref).Equal("refs/heads/master")
|
||||||
g.Assert(pipeline.Refspec).Equal("change:master")
|
g.Assert(pipeline.Refspec).Equal("change:master")
|
||||||
g.Assert(pipeline.Remote).Equal("https://bitbucket.org/baz/bar")
|
g.Assert(pipeline.CloneURL).Equal("https://bitbucket.org/baz/bar")
|
||||||
g.Assert(pipeline.Message).Equal(hook.PullRequest.Desc)
|
g.Assert(pipeline.Message).Equal(hook.PullRequest.Desc)
|
||||||
g.Assert(pipeline.Timestamp).Equal(hook.PullRequest.Updated.Unix())
|
g.Assert(pipeline.Timestamp).Equal(hook.PullRequest.Updated.Unix())
|
||||||
})
|
})
|
|
@ -19,8 +19,8 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/bitbucket/internal"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/bitbucket/internal"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
|
@ -21,8 +21,8 @@ import (
|
||||||
|
|
||||||
"github.com/franela/goblin"
|
"github.com/franela/goblin"
|
||||||
|
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/bitbucket/fixtures"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/bitbucket/fixtures"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_parser(t *testing.T) {
|
func Test_parser(t *testing.T) {
|
|
@ -30,10 +30,10 @@ import (
|
||||||
|
|
||||||
"github.com/mrjones/oauth"
|
"github.com/mrjones/oauth"
|
||||||
|
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/bitbucketserver/internal"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/common"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote"
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/bitbucketserver/internal"
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/common"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -61,9 +61,9 @@ type Config struct {
|
||||||
Consumer *oauth.Consumer
|
Consumer *oauth.Consumer
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a Remote implementation that integrates with Bitbucket Server,
|
// New returns a Forge implementation that integrates with Bitbucket Server,
|
||||||
// the on-premise edition of Bitbucket Cloud, formerly known as Stash.
|
// the on-premise edition of Bitbucket Cloud, formerly known as Stash.
|
||||||
func New(opts Opts) (remote.Remote, error) {
|
func New(opts Opts) (forge.Forge, error) {
|
||||||
config := &Config{
|
config := &Config{
|
||||||
URL: opts.URL,
|
URL: opts.URL,
|
||||||
Username: opts.Username,
|
Username: opts.Username,
|
||||||
|
@ -152,7 +152,7 @@ func (*Config) TeamPerm(u *model.User, org string) (*model.Perm, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) Repo(ctx context.Context, u *model.User, _ model.RemoteID, owner, name string) (*model.Repo, error) {
|
func (c *Config) Repo(ctx context.Context, u *model.User, _ model.ForgeID, owner, name string) (*model.Repo, error) {
|
||||||
repo, err := internal.NewClientWithToken(ctx, c.URL, c.Consumer, u.Token).FindRepo(owner, name)
|
repo, err := internal.NewClientWithToken(ctx, c.URL, c.Consumer, u.Token).FindRepo(owner, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -185,7 +185,7 @@ func (c *Config) File(ctx context.Context, u *model.User, r *model.Repo, p *mode
|
||||||
return client.FindFileForRepo(r.Owner, r.Name, f, p.Ref)
|
return client.FindFileForRepo(r.Owner, r.Name, f, p.Ref)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) Dir(ctx context.Context, u *model.User, r *model.Repo, p *model.Pipeline, f string) ([]*remote.FileMeta, error) {
|
func (c *Config) Dir(ctx context.Context, u *model.User, r *model.Repo, p *model.Pipeline, f string) ([]*forge.FileMeta, error) {
|
||||||
return nil, fmt.Errorf("Not implemented")
|
return nil, fmt.Errorf("Not implemented")
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,8 @@ import (
|
||||||
|
|
||||||
"github.com/mrjones/oauth"
|
"github.com/mrjones/oauth"
|
||||||
|
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/bitbucketserver/internal"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/bitbucketserver/internal"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -52,7 +52,7 @@ func convertStatus(status model.StatusValue) string {
|
||||||
// structure to the common Woodpecker repository structure.
|
// structure to the common Woodpecker repository structure.
|
||||||
func convertRepo(from *internal.Repo) *model.Repo {
|
func convertRepo(from *internal.Repo) *model.Repo {
|
||||||
repo := model.Repo{
|
repo := model.Repo{
|
||||||
RemoteID: model.RemoteID(fmt.Sprint(from.ID)),
|
ForgeID: model.ForgeID(fmt.Sprint(from.ID)),
|
||||||
Name: from.Slug,
|
Name: from.Slug,
|
||||||
Owner: from.Project.Key,
|
Owner: from.Project.Key,
|
||||||
Branch: "master",
|
Branch: "master",
|
|
@ -21,8 +21,8 @@ import (
|
||||||
"github.com/franela/goblin"
|
"github.com/franela/goblin"
|
||||||
"github.com/mrjones/oauth"
|
"github.com/mrjones/oauth"
|
||||||
|
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/bitbucketserver/internal"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/bitbucketserver/internal"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_helper(t *testing.T) {
|
func Test_helper(t *testing.T) {
|
|
@ -19,8 +19,8 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/bitbucketserver/internal"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/bitbucketserver/internal"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// parseHook parses a Bitbucket hook from an http.Request request and returns
|
// parseHook parses a Bitbucket hook from an http.Request request and returns
|
|
@ -25,10 +25,10 @@ import (
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server"
|
"github.com/woodpecker-ci/woodpecker/server"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/coding/internal"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/common"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote"
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/coding/internal"
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/common"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -46,9 +46,9 @@ type Opts struct {
|
||||||
SkipVerify bool // Skip ssl verification.
|
SkipVerify bool // Skip ssl verification.
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a Remote implementation that integrates with a Coding Platform or
|
// New returns a Forge implementation that integrates with a Coding Platform or
|
||||||
// Coding Enterprise version control hosting provider.
|
// Coding Enterprise version control hosting provider.
|
||||||
func New(opts Opts) (remote.Remote, error) {
|
func New(opts Opts) (forge.Forge, error) {
|
||||||
r := &Coding{
|
r := &Coding{
|
||||||
URL: defaultURL,
|
URL: defaultURL,
|
||||||
Client: opts.Client,
|
Client: opts.Client,
|
||||||
|
@ -81,13 +81,13 @@ func (c *Coding) Name() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Login authenticates the session and returns the
|
// Login authenticates the session and returns the
|
||||||
// remote user details.
|
// forge user details.
|
||||||
func (c *Coding) Login(ctx context.Context, res http.ResponseWriter, req *http.Request) (*model.User, error) {
|
func (c *Coding) Login(ctx context.Context, res http.ResponseWriter, req *http.Request) (*model.User, error) {
|
||||||
config := c.newConfig(server.Config.Server.Host)
|
config := c.newConfig(server.Config.Server.Host)
|
||||||
|
|
||||||
// get the OAuth errors
|
// get the OAuth errors
|
||||||
if err := req.FormValue("error"); err != "" {
|
if err := req.FormValue("error"); err != "" {
|
||||||
return nil, &remote.AuthError{
|
return nil, &forge.AuthError{
|
||||||
Err: err,
|
Err: err,
|
||||||
Description: req.FormValue("error_description"),
|
Description: req.FormValue("error_description"),
|
||||||
URI: req.FormValue("error_uri"),
|
URI: req.FormValue("error_uri"),
|
||||||
|
@ -121,7 +121,7 @@ func (c *Coding) Login(ctx context.Context, res http.ResponseWriter, req *http.R
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Auth authenticates the session and returns the remote user
|
// Auth authenticates the session and returns the forge user
|
||||||
// login for the given token and secret
|
// login for the given token and secret
|
||||||
func (c *Coding) Auth(ctx context.Context, token, secret string) (string, error) {
|
func (c *Coding) Auth(ctx context.Context, token, secret string) (string, error) {
|
||||||
user, err := c.newClientToken(ctx, token).GetCurrentUser()
|
user, err := c.newClientToken(ctx, token).GetCurrentUser()
|
||||||
|
@ -148,21 +148,21 @@ func (c *Coding) Refresh(ctx context.Context, u *model.User) (bool, error) {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Teams fetches a list of team memberships from the remote system.
|
// Teams fetches a list of team memberships from the forge.
|
||||||
func (c *Coding) Teams(ctx context.Context, u *model.User) ([]*model.Team, error) {
|
func (c *Coding) Teams(ctx context.Context, u *model.User) ([]*model.Team, error) {
|
||||||
// EMPTY: not implemented in Coding OAuth API
|
// EMPTY: not implemented in Coding OAuth API
|
||||||
return nil, fmt.Errorf("Not implemented")
|
return nil, fmt.Errorf("Not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TeamPerm fetches the named organization permissions from
|
// TeamPerm fetches the named organization permissions from
|
||||||
// the remote system for the specified user.
|
// the forge for the specified user.
|
||||||
func (c *Coding) TeamPerm(u *model.User, org string) (*model.Perm, error) {
|
func (c *Coding) TeamPerm(u *model.User, org string) (*model.Perm, error) {
|
||||||
// EMPTY: not implemented in Coding OAuth API
|
// EMPTY: not implemented in Coding OAuth API
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Repo fetches the repository from the remote system.
|
// Repo fetches the repository from the forge.
|
||||||
func (c *Coding) Repo(ctx context.Context, u *model.User, _ model.RemoteID, owner, name string) (*model.Repo, error) {
|
func (c *Coding) Repo(ctx context.Context, u *model.User, _ model.ForgeID, owner, name string) (*model.Repo, error) {
|
||||||
client := c.newClient(ctx, u)
|
client := c.newClient(ctx, u)
|
||||||
project, err := client.GetProject(owner, name)
|
project, err := client.GetProject(owner, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -173,7 +173,7 @@ func (c *Coding) Repo(ctx context.Context, u *model.User, _ model.RemoteID, owne
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &model.Repo{
|
return &model.Repo{
|
||||||
// TODO(1138) RemoteID: project.ID,
|
// TODO(1138) ForgeID: project.ID,
|
||||||
Owner: project.Owner,
|
Owner: project.Owner,
|
||||||
Name: project.Name,
|
Name: project.Name,
|
||||||
FullName: projectFullName(project.Owner, project.Name),
|
FullName: projectFullName(project.Owner, project.Name),
|
||||||
|
@ -186,7 +186,7 @@ func (c *Coding) Repo(ctx context.Context, u *model.User, _ model.RemoteID, owne
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Repos fetches a list of repos from the remote system.
|
// Repos fetches a list of repos from the forge.
|
||||||
func (c *Coding) Repos(ctx context.Context, u *model.User) ([]*model.Repo, error) {
|
func (c *Coding) Repos(ctx context.Context, u *model.User) ([]*model.Repo, error) {
|
||||||
client := c.newClient(ctx, u)
|
client := c.newClient(ctx, u)
|
||||||
projectList, err := client.GetProjectList()
|
projectList, err := client.GetProjectList()
|
||||||
|
@ -201,7 +201,7 @@ func (c *Coding) Repos(ctx context.Context, u *model.User) ([]*model.Repo, error
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
repo := &model.Repo{
|
repo := &model.Repo{
|
||||||
// TODO(1138) RemoteID: project.ID,
|
// TODO(1138) ForgeID: project.ID,
|
||||||
Owner: project.Owner,
|
Owner: project.Owner,
|
||||||
Name: project.Name,
|
Name: project.Name,
|
||||||
FullName: projectFullName(project.Owner, project.Name),
|
FullName: projectFullName(project.Owner, project.Name),
|
||||||
|
@ -218,7 +218,7 @@ func (c *Coding) Repos(ctx context.Context, u *model.User) ([]*model.Repo, error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perm fetches the named repository permissions from
|
// Perm fetches the named repository permissions from
|
||||||
// the remote system for the specified user.
|
// the forge for the specified user.
|
||||||
func (c *Coding) Perm(ctx context.Context, u *model.User, repo *model.Repo) (*model.Perm, error) {
|
func (c *Coding) Perm(ctx context.Context, u *model.User, repo *model.Repo) (*model.Perm, error) {
|
||||||
project, err := c.newClient(ctx, u).GetProject(repo.Owner, repo.Name)
|
project, err := c.newClient(ctx, u).GetProject(repo.Owner, repo.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -234,7 +234,7 @@ func (c *Coding) Perm(ctx context.Context, u *model.User, repo *model.Repo) (*mo
|
||||||
return &model.Perm{Pull: false, Push: false, Admin: false}, nil
|
return &model.Perm{Pull: false, Push: false, Admin: false}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// File fetches a file from the remote repository and returns in string
|
// File fetches a file from the forge repository and returns in string
|
||||||
// format.
|
// format.
|
||||||
func (c *Coding) File(ctx context.Context, u *model.User, r *model.Repo, b *model.Pipeline, f string) ([]byte, error) {
|
func (c *Coding) File(ctx context.Context, u *model.User, r *model.Repo, b *model.Pipeline, f string) ([]byte, error) {
|
||||||
data, err := c.newClient(ctx, u).GetFile(r.Owner, r.Name, b.Commit, f)
|
data, err := c.newClient(ctx, u).GetFile(r.Owner, r.Name, b.Commit, f)
|
||||||
|
@ -244,18 +244,18 @@ func (c *Coding) File(ctx context.Context, u *model.User, r *model.Repo, b *mode
|
||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Coding) Dir(ctx context.Context, u *model.User, r *model.Repo, b *model.Pipeline, f string) ([]*remote.FileMeta, error) {
|
func (c *Coding) Dir(ctx context.Context, u *model.User, r *model.Repo, b *model.Pipeline, f string) ([]*forge.FileMeta, error) {
|
||||||
return nil, fmt.Errorf("Not implemented")
|
return nil, fmt.Errorf("Not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Status sends the commit status to the remote system.
|
// Status sends the commit status to the forge.
|
||||||
func (c *Coding) Status(ctx context.Context, u *model.User, r *model.Repo, b *model.Pipeline, step *model.Step) error {
|
func (c *Coding) Status(ctx context.Context, u *model.User, r *model.Repo, b *model.Pipeline, step *model.Step) error {
|
||||||
// EMPTY: not implemented in Coding OAuth API
|
// EMPTY: not implemented in Coding OAuth API
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Netrc returns a .netrc file that can be used to clone
|
// Netrc returns a .netrc file that can be used to clone
|
||||||
// private repositories from a remote system.
|
// private repositories from a forge.
|
||||||
func (c *Coding) Netrc(u *model.User, r *model.Repo) (*model.Netrc, error) {
|
func (c *Coding) Netrc(u *model.User, r *model.Repo) (*model.Netrc, error) {
|
||||||
host, err := common.ExtractHostFromCloneURL(r.Clone)
|
host, err := common.ExtractHostFromCloneURL(r.Clone)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -318,7 +318,7 @@ func (c *Coding) OrgMembership(ctx context.Context, u *model.User, owner string)
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function to return the Coding oauth2 context using an HTTPClient that
|
// helper function to return the Coding oauth2 context using an HTTPClient that
|
||||||
// disables TLS verification if disabled in the remote settings.
|
// disables TLS verification if disabled in the forge settings.
|
||||||
func (c *Coding) newContext(ctx context.Context) context.Context {
|
func (c *Coding) newContext(ctx context.Context) context.Context {
|
||||||
if !c.SkipVerify {
|
if !c.SkipVerify {
|
||||||
return ctx
|
return ctx
|
|
@ -25,8 +25,8 @@ import (
|
||||||
"github.com/franela/goblin"
|
"github.com/franela/goblin"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/coding/fixtures"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/coding/fixtures"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_coding(t *testing.T) {
|
func Test_coding(t *testing.T) {
|
||||||
|
@ -42,9 +42,9 @@ func Test_coding(t *testing.T) {
|
||||||
s.Close()
|
s.Close()
|
||||||
})
|
})
|
||||||
|
|
||||||
g.Describe("Creating a remote", func() {
|
g.Describe("Creating a forge", func() {
|
||||||
g.It("Should return client with specified options", func() {
|
g.It("Should return client with specified options", func() {
|
||||||
remote, _ := New(Opts{
|
forge, _ := New(Opts{
|
||||||
URL: "https://coding.net",
|
URL: "https://coding.net",
|
||||||
Client: "KTNF2ALdm3ofbtxLh6IbV95Ro5AKWJUP",
|
Client: "KTNF2ALdm3ofbtxLh6IbV95Ro5AKWJUP",
|
||||||
Secret: "zVtxJrKhNhBcNyqCz1NggNAAmehAxnRO3Z0fXmCp",
|
Secret: "zVtxJrKhNhBcNyqCz1NggNAAmehAxnRO3Z0fXmCp",
|
||||||
|
@ -53,13 +53,13 @@ func Test_coding(t *testing.T) {
|
||||||
Password: "password",
|
Password: "password",
|
||||||
SkipVerify: true,
|
SkipVerify: true,
|
||||||
})
|
})
|
||||||
g.Assert(remote.(*Coding).URL).Equal("https://coding.net")
|
g.Assert(forge.(*Coding).URL).Equal("https://coding.net")
|
||||||
g.Assert(remote.(*Coding).Client).Equal("KTNF2ALdm3ofbtxLh6IbV95Ro5AKWJUP")
|
g.Assert(forge.(*Coding).Client).Equal("KTNF2ALdm3ofbtxLh6IbV95Ro5AKWJUP")
|
||||||
g.Assert(remote.(*Coding).Secret).Equal("zVtxJrKhNhBcNyqCz1NggNAAmehAxnRO3Z0fXmCp")
|
g.Assert(forge.(*Coding).Secret).Equal("zVtxJrKhNhBcNyqCz1NggNAAmehAxnRO3Z0fXmCp")
|
||||||
g.Assert(remote.(*Coding).Scopes).Equal([]string{"user", "project", "project:depot"})
|
g.Assert(forge.(*Coding).Scopes).Equal([]string{"user", "project", "project:depot"})
|
||||||
g.Assert(remote.(*Coding).Username).Equal("someuser")
|
g.Assert(forge.(*Coding).Username).Equal("someuser")
|
||||||
g.Assert(remote.(*Coding).Password).Equal("password")
|
g.Assert(forge.(*Coding).Password).Equal("password")
|
||||||
g.Assert(remote.(*Coding).SkipVerify).Equal(true)
|
g.Assert(forge.(*Coding).SkipVerify).Equal(true)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -170,19 +170,19 @@ func Test_coding(t *testing.T) {
|
||||||
|
|
||||||
g.Describe("When requesting a netrc config", func() {
|
g.Describe("When requesting a netrc config", func() {
|
||||||
g.It("Should return the netrc file for global credential", func() {
|
g.It("Should return the netrc file for global credential", func() {
|
||||||
remote, _ := New(Opts{
|
forge, _ := New(Opts{
|
||||||
Username: "someuser",
|
Username: "someuser",
|
||||||
Password: "password",
|
Password: "password",
|
||||||
})
|
})
|
||||||
netrc, err := remote.Netrc(fakeUser, fakeRepo)
|
netrc, err := forge.Netrc(fakeUser, fakeRepo)
|
||||||
g.Assert(err).IsNil()
|
g.Assert(err).IsNil()
|
||||||
g.Assert(netrc.Login).Equal("someuser")
|
g.Assert(netrc.Login).Equal("someuser")
|
||||||
g.Assert(netrc.Password).Equal("password")
|
g.Assert(netrc.Password).Equal("password")
|
||||||
g.Assert(netrc.Machine).Equal("git.coding.net")
|
g.Assert(netrc.Machine).Equal("git.coding.net")
|
||||||
})
|
})
|
||||||
g.It("Should return the netrc file for specified user", func() {
|
g.It("Should return the netrc file for specified user", func() {
|
||||||
remote, _ := New(Opts{})
|
forge, _ := New(Opts{})
|
||||||
netrc, err := remote.Netrc(fakeUser, fakeRepo)
|
netrc, err := forge.Netrc(fakeUser, fakeRepo)
|
||||||
g.Assert(err).IsNil()
|
g.Assert(err).IsNil()
|
||||||
g.Assert(netrc.Login).Equal(fakeUser.Token)
|
g.Assert(netrc.Login).Equal(fakeUser.Token)
|
||||||
g.Assert(netrc.Password).Equal("x-oauth-basic")
|
g.Assert(netrc.Password).Equal("x-oauth-basic")
|
|
@ -138,7 +138,7 @@ func convertRepository(repo *Repository) (*model.Repo, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return &model.Repo{
|
return &model.Repo{
|
||||||
// TODO RemoteID: repo.ID,
|
// TODO ForgeID: repo.ID,
|
||||||
Owner: matches[1],
|
Owner: matches[1],
|
||||||
Name: repo.Name,
|
Name: repo.Name,
|
||||||
FullName: projectFullName(repo.Owner.GlobalKey, repo.Name),
|
FullName: projectFullName(repo.Owner.GlobalKey, repo.Name),
|
||||||
|
@ -176,7 +176,7 @@ func parsePushHook(raw []byte) (*model.Repo, *model.Pipeline, error) {
|
||||||
Email: lastCommit.Committer.Email,
|
Email: lastCommit.Committer.Email,
|
||||||
Avatar: hook.User.Avatar,
|
Avatar: hook.User.Avatar,
|
||||||
Author: hook.User.GlobalKey,
|
Author: hook.User.GlobalKey,
|
||||||
Remote: hook.Repository.HTTPSURL,
|
CloneURL: hook.Repository.HTTPSURL,
|
||||||
}
|
}
|
||||||
return repo, pipeline, nil
|
return repo, pipeline, nil
|
||||||
}
|
}
|
||||||
|
@ -206,7 +206,7 @@ func parsePullRequestHook(raw []byte) (*model.Repo, *model.Pipeline, error) {
|
||||||
Author: hook.PullRequest.User.GlobalKey,
|
Author: hook.PullRequest.User.GlobalKey,
|
||||||
Avatar: hook.PullRequest.User.Avatar,
|
Avatar: hook.PullRequest.User.Avatar,
|
||||||
Title: hook.PullRequest.Title,
|
Title: hook.PullRequest.Title,
|
||||||
Remote: hook.Repository.HTTPSURL,
|
CloneURL: hook.Repository.HTTPSURL,
|
||||||
Refspec: fmt.Sprintf("%s:%s", hook.PullRequest.SourceBranch, hook.PullRequest.TargetBranch),
|
Refspec: fmt.Sprintf("%s:%s", hook.PullRequest.SourceBranch, hook.PullRequest.TargetBranch),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,7 +239,7 @@ func parseMergeReuqestHook(raw []byte) (*model.Repo, *model.Pipeline, error) {
|
||||||
Author: hook.MergeRequest.User.GlobalKey,
|
Author: hook.MergeRequest.User.GlobalKey,
|
||||||
Avatar: hook.MergeRequest.User.Avatar,
|
Avatar: hook.MergeRequest.User.Avatar,
|
||||||
Title: hook.MergeRequest.Title,
|
Title: hook.MergeRequest.Title,
|
||||||
Remote: hook.Repository.HTTPSURL,
|
CloneURL: hook.Repository.HTTPSURL,
|
||||||
Refspec: fmt.Sprintf("%s:%s", hook.MergeRequest.SourceBranch, hook.MergeRequest.TargetBranch),
|
Refspec: fmt.Sprintf("%s:%s", hook.MergeRequest.SourceBranch, hook.MergeRequest.TargetBranch),
|
||||||
}
|
}
|
||||||
return repo, pipeline, nil
|
return repo, pipeline, nil
|
|
@ -23,8 +23,8 @@ import (
|
||||||
|
|
||||||
"github.com/franela/goblin"
|
"github.com/franela/goblin"
|
||||||
|
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/coding/fixtures"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/coding/fixtures"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_hook(t *testing.T) {
|
func Test_hook(t *testing.T) {
|
||||||
|
@ -58,7 +58,7 @@ func Test_hook(t *testing.T) {
|
||||||
Email: "demo1@gmail.com",
|
Email: "demo1@gmail.com",
|
||||||
Avatar: "/static/fruit_avatar/Fruit-20.png",
|
Avatar: "/static/fruit_avatar/Fruit-20.png",
|
||||||
Author: "demo1",
|
Author: "demo1",
|
||||||
Remote: "https://git.coding.net/demo1/test1.git",
|
CloneURL: "https://git.coding.net/demo1/test1.git",
|
||||||
}
|
}
|
||||||
|
|
||||||
actualRepo, actualPipeline, err := parseHook(r)
|
actualRepo, actualPipeline, err := parseHook(r)
|
||||||
|
@ -126,7 +126,7 @@ func Test_hook(t *testing.T) {
|
||||||
Email: "demo1@gmail.com",
|
Email: "demo1@gmail.com",
|
||||||
Avatar: "/static/fruit_avatar/Fruit-20.png",
|
Avatar: "/static/fruit_avatar/Fruit-20.png",
|
||||||
Author: "demo1",
|
Author: "demo1",
|
||||||
Remote: "https://git.coding.net/demo1/test1.git",
|
CloneURL: "https://git.coding.net/demo1/test1.git",
|
||||||
}
|
}
|
||||||
|
|
||||||
actualRepo, actualPipeline, err := parsePushHook([]byte(fixtures.PushHook))
|
actualRepo, actualPipeline, err := parsePushHook([]byte(fixtures.PushHook))
|
||||||
|
@ -162,7 +162,7 @@ func Test_hook(t *testing.T) {
|
||||||
Author: "demo2",
|
Author: "demo2",
|
||||||
Avatar: "/static/fruit_avatar/Fruit-2.png",
|
Avatar: "/static/fruit_avatar/Fruit-2.png",
|
||||||
Title: "pr1",
|
Title: "pr1",
|
||||||
Remote: "https://git.coding.net/demo1/test2.git",
|
CloneURL: "https://git.coding.net/demo1/test2.git",
|
||||||
Refspec: "master:master",
|
Refspec: "master:master",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,7 +192,7 @@ func Test_hook(t *testing.T) {
|
||||||
Author: "demo1",
|
Author: "demo1",
|
||||||
Avatar: "/static/fruit_avatar/Fruit-20.png",
|
Avatar: "/static/fruit_avatar/Fruit-20.png",
|
||||||
Title: "mr1",
|
Title: "mr1",
|
||||||
Remote: "https://git.coding.net/demo1/test1.git",
|
CloneURL: "https://git.coding.net/demo1/test1.git",
|
||||||
Refspec: "branch1:master",
|
Refspec: "branch1:master",
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/common"
|
"github.com/woodpecker-ci/woodpecker/server/forge/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_Netrc(t *testing.T) {
|
func Test_Netrc(t *testing.T) {
|
|
@ -12,9 +12,9 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package remote
|
package forge
|
||||||
|
|
||||||
// AuthError represents remote authentication error.
|
// AuthError represents forge authentication error.
|
||||||
type AuthError struct {
|
type AuthError struct {
|
||||||
Err string
|
Err string
|
||||||
Description string
|
Description string
|
|
@ -36,9 +36,9 @@ import (
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server"
|
"github.com/woodpecker-ci/woodpecker/server"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/common"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote"
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/common"
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server/store"
|
"github.com/woodpecker-ci/woodpecker/server/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -64,9 +64,9 @@ type Opts struct {
|
||||||
SkipVerify bool // Skip ssl verification.
|
SkipVerify bool // Skip ssl verification.
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a Remote implementation that integrates with Gitea,
|
// New returns a Forge implementation that integrates with Gitea,
|
||||||
// an open source Git service written in Go. See https://gitea.io/
|
// an open source Git service written in Go. See https://gitea.io/
|
||||||
func New(opts Opts) (remote.Remote, error) {
|
func New(opts Opts) (forge.Forge, error) {
|
||||||
u, err := url.Parse(opts.URL)
|
u, err := url.Parse(opts.URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -112,7 +112,7 @@ func (c *Gitea) Login(ctx context.Context, w http.ResponseWriter, req *http.Requ
|
||||||
|
|
||||||
// get the OAuth errors
|
// get the OAuth errors
|
||||||
if err := req.FormValue("error"); err != "" {
|
if err := req.FormValue("error"); err != "" {
|
||||||
return nil, &remote.AuthError{
|
return nil, &forge.AuthError{
|
||||||
Err: err,
|
Err: err,
|
||||||
Description: req.FormValue("error_description"),
|
Description: req.FormValue("error_description"),
|
||||||
URI: req.FormValue("error_uri"),
|
URI: req.FormValue("error_uri"),
|
||||||
|
@ -217,7 +217,7 @@ func (c *Gitea) TeamPerm(u *model.User, org string) (*model.Perm, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Repo returns the Gitea repository.
|
// Repo returns the Gitea repository.
|
||||||
func (c *Gitea) Repo(ctx context.Context, u *model.User, id model.RemoteID, owner, name string) (*model.Repo, error) {
|
func (c *Gitea) Repo(ctx context.Context, u *model.User, id model.ForgeID, owner, name string) (*model.Repo, error) {
|
||||||
client, err := c.newClientToken(ctx, u.Token)
|
client, err := c.newClientToken(ctx, u.Token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -292,8 +292,8 @@ func (c *Gitea) File(ctx context.Context, u *model.User, r *model.Repo, b *model
|
||||||
return cfg, err
|
return cfg, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Gitea) Dir(ctx context.Context, u *model.User, r *model.Repo, b *model.Pipeline, f string) ([]*remote.FileMeta, error) {
|
func (c *Gitea) Dir(ctx context.Context, u *model.User, r *model.Repo, b *model.Pipeline, f string) ([]*forge.FileMeta, error) {
|
||||||
var configs []*remote.FileMeta
|
var configs []*forge.FileMeta
|
||||||
|
|
||||||
client, err := c.newClientToken(ctx, u.Token)
|
client, err := c.newClientToken(ctx, u.Token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -316,7 +316,7 @@ func (c *Gitea) Dir(ctx context.Context, u *model.User, r *model.Repo, b *model.
|
||||||
return nil, fmt.Errorf("multi-pipeline cannot get %s: %s", e.Path, err)
|
return nil, fmt.Errorf("multi-pipeline cannot get %s: %s", e.Path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
configs = append(configs, &remote.FileMeta{
|
configs = append(configs, &forge.FileMeta{
|
||||||
Name: e.Path,
|
Name: e.Path,
|
||||||
Data: data,
|
Data: data,
|
||||||
})
|
})
|
||||||
|
@ -565,7 +565,7 @@ func (c *Gitea) getChangedFilesForPR(ctx context.Context, repo *model.Repo, inde
|
||||||
return []string{}, nil
|
return []string{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
repo, err := _store.GetRepoNameFallback(repo.RemoteID, repo.FullName)
|
repo, err := _store.GetRepoNameFallback(repo.ForgeID, repo.FullName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
|
@ -27,8 +27,8 @@ import (
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
"github.com/woodpecker-ci/woodpecker/shared/utils"
|
"github.com/woodpecker-ci/woodpecker/shared/utils"
|
||||||
|
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/gitea/fixtures"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/gitea/fixtures"
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server/store"
|
"github.com/woodpecker-ci/woodpecker/server/store"
|
||||||
mocks_store "github.com/woodpecker-ci/woodpecker/server/store/mocks"
|
mocks_store "github.com/woodpecker-ci/woodpecker/server/store/mocks"
|
||||||
)
|
)
|
||||||
|
@ -51,14 +51,14 @@ func Test_gitea(t *testing.T) {
|
||||||
s.Close()
|
s.Close()
|
||||||
})
|
})
|
||||||
|
|
||||||
g.Describe("Creating a remote", func() {
|
g.Describe("Creating a forge", func() {
|
||||||
g.It("Should return client with specified options", func() {
|
g.It("Should return client with specified options", func() {
|
||||||
remote, _ := New(Opts{
|
forge, _ := New(Opts{
|
||||||
URL: "http://localhost:8080",
|
URL: "http://localhost:8080",
|
||||||
SkipVerify: true,
|
SkipVerify: true,
|
||||||
})
|
})
|
||||||
g.Assert(remote.(*Gitea).URL).Equal("http://localhost:8080")
|
g.Assert(forge.(*Gitea).URL).Equal("http://localhost:8080")
|
||||||
g.Assert(remote.(*Gitea).SkipVerify).Equal(true)
|
g.Assert(forge.(*Gitea).SkipVerify).Equal(true)
|
||||||
})
|
})
|
||||||
g.It("Should handle malformed url", func() {
|
g.It("Should handle malformed url", func() {
|
||||||
_, err := New(Opts{URL: "%gh&%ij"})
|
_, err := New(Opts{URL: "%gh&%ij"})
|
||||||
|
@ -68,15 +68,15 @@ func Test_gitea(t *testing.T) {
|
||||||
|
|
||||||
g.Describe("Generating a netrc file", func() {
|
g.Describe("Generating a netrc file", func() {
|
||||||
g.It("Should return a netrc with the user token", func() {
|
g.It("Should return a netrc with the user token", func() {
|
||||||
remote, _ := New(Opts{})
|
forge, _ := New(Opts{})
|
||||||
netrc, _ := remote.Netrc(fakeUser, fakeRepo)
|
netrc, _ := forge.Netrc(fakeUser, fakeRepo)
|
||||||
g.Assert(netrc.Machine).Equal("gitea.com")
|
g.Assert(netrc.Machine).Equal("gitea.com")
|
||||||
g.Assert(netrc.Login).Equal(fakeUser.Login)
|
g.Assert(netrc.Login).Equal(fakeUser.Login)
|
||||||
g.Assert(netrc.Password).Equal(fakeUser.Token)
|
g.Assert(netrc.Password).Equal(fakeUser.Token)
|
||||||
})
|
})
|
||||||
g.It("Should return a netrc with the machine account", func() {
|
g.It("Should return a netrc with the machine account", func() {
|
||||||
remote, _ := New(Opts{})
|
forge, _ := New(Opts{})
|
||||||
netrc, _ := remote.Netrc(nil, fakeRepo)
|
netrc, _ := forge.Netrc(nil, fakeRepo)
|
||||||
g.Assert(netrc.Machine).Equal("gitea.com")
|
g.Assert(netrc.Machine).Equal("gitea.com")
|
||||||
g.Assert(netrc.Login).Equal("")
|
g.Assert(netrc.Login).Equal("")
|
||||||
g.Assert(netrc.Password).Equal("")
|
g.Assert(netrc.Password).Equal("")
|
||||||
|
@ -85,7 +85,7 @@ func Test_gitea(t *testing.T) {
|
||||||
|
|
||||||
g.Describe("Requesting a repository", func() {
|
g.Describe("Requesting a repository", func() {
|
||||||
g.It("Should return the repository details", func() {
|
g.It("Should return the repository details", func() {
|
||||||
repo, err := c.Repo(ctx, fakeUser, fakeRepo.RemoteID, fakeRepo.Owner, fakeRepo.Name)
|
repo, err := c.Repo(ctx, fakeUser, fakeRepo.ForgeID, fakeRepo.Owner, fakeRepo.Name)
|
||||||
g.Assert(err).IsNil()
|
g.Assert(err).IsNil()
|
||||||
g.Assert(repo.Owner).Equal(fakeRepo.Owner)
|
g.Assert(repo.Owner).Equal(fakeRepo.Owner)
|
||||||
g.Assert(repo.Name).Equal(fakeRepo.Name)
|
g.Assert(repo.Name).Equal(fakeRepo.Name)
|
||||||
|
@ -118,7 +118,7 @@ func Test_gitea(t *testing.T) {
|
||||||
g.It("Should return the repository list", func() {
|
g.It("Should return the repository list", func() {
|
||||||
repos, err := c.Repos(ctx, fakeUser)
|
repos, err := c.Repos(ctx, fakeUser)
|
||||||
g.Assert(err).IsNil()
|
g.Assert(err).IsNil()
|
||||||
g.Assert(repos[0].RemoteID).Equal(fakeRepo.RemoteID)
|
g.Assert(repos[0].ForgeID).Equal(fakeRepo.ForgeID)
|
||||||
g.Assert(repos[0].Owner).Equal(fakeRepo.Owner)
|
g.Assert(repos[0].Owner).Equal(fakeRepo.Owner)
|
||||||
g.Assert(repos[0].Name).Equal(fakeRepo.Name)
|
g.Assert(repos[0].Name).Equal(fakeRepo.Name)
|
||||||
g.Assert(repos[0].FullName).Equal(fakeRepo.Owner + "/" + fakeRepo.Name)
|
g.Assert(repos[0].FullName).Equal(fakeRepo.Owner + "/" + fakeRepo.Name)
|
||||||
|
@ -193,7 +193,7 @@ var (
|
||||||
|
|
||||||
fakeRepo = &model.Repo{
|
fakeRepo = &model.Repo{
|
||||||
Clone: "http://gitea.com/test_name/repo_name.git",
|
Clone: "http://gitea.com/test_name/repo_name.git",
|
||||||
RemoteID: "5",
|
ForgeID: "5",
|
||||||
Owner: "test_name",
|
Owner: "test_name",
|
||||||
Name: "repo_name",
|
Name: "repo_name",
|
||||||
FullName: "test_name/repo_name",
|
FullName: "test_name/repo_name",
|
|
@ -37,7 +37,7 @@ func toRepo(from *gitea.Repository) *model.Repo {
|
||||||
from.Owner.AvatarURL,
|
from.Owner.AvatarURL,
|
||||||
)
|
)
|
||||||
return &model.Repo{
|
return &model.Repo{
|
||||||
RemoteID: model.RemoteID(fmt.Sprint(from.ID)),
|
ForgeID: model.ForgeID(fmt.Sprint(from.ID)),
|
||||||
SCMKind: model.RepoGit,
|
SCMKind: model.RepoGit,
|
||||||
Name: name,
|
Name: name,
|
||||||
Owner: from.Owner.UserName,
|
Owner: from.Owner.UserName,
|
|
@ -22,8 +22,8 @@ import (
|
||||||
"code.gitea.io/sdk/gitea"
|
"code.gitea.io/sdk/gitea"
|
||||||
"github.com/franela/goblin"
|
"github.com/franela/goblin"
|
||||||
|
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/gitea/fixtures"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/gitea/fixtures"
|
|
||||||
"github.com/woodpecker-ci/woodpecker/shared/utils"
|
"github.com/woodpecker-ci/woodpecker/shared/utils"
|
||||||
)
|
)
|
||||||
|
|
|
@ -22,8 +22,8 @@ import (
|
||||||
|
|
||||||
"github.com/franela/goblin"
|
"github.com/franela/goblin"
|
||||||
|
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/gitea/fixtures"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/gitea/fixtures"
|
|
||||||
"github.com/woodpecker-ci/woodpecker/shared/utils"
|
"github.com/woodpecker-ci/woodpecker/shared/utils"
|
||||||
)
|
)
|
||||||
|
|
|
@ -85,7 +85,7 @@ func convertDesc(status model.StatusValue) string {
|
||||||
// structure to the common Woodpecker repository structure.
|
// structure to the common Woodpecker repository structure.
|
||||||
func convertRepo(from *github.Repository) *model.Repo {
|
func convertRepo(from *github.Repository) *model.Repo {
|
||||||
repo := &model.Repo{
|
repo := &model.Repo{
|
||||||
RemoteID: model.RemoteID(fmt.Sprint(from.GetID())),
|
ForgeID: model.ForgeID(fmt.Sprint(from.GetID())),
|
||||||
Name: from.GetName(),
|
Name: from.GetName(),
|
||||||
FullName: from.GetFullName(),
|
FullName: from.GetFullName(),
|
||||||
Link: from.GetHTMLURL(),
|
Link: from.GetHTMLURL(),
|
||||||
|
@ -146,7 +146,7 @@ func convertTeam(from *github.Organization) *model.Team {
|
||||||
// from a webhook and convert to the common Woodpecker repository structure.
|
// from a webhook and convert to the common Woodpecker repository structure.
|
||||||
func convertRepoHook(eventRepo *github.PushEventRepository) *model.Repo {
|
func convertRepoHook(eventRepo *github.PushEventRepository) *model.Repo {
|
||||||
repo := &model.Repo{
|
repo := &model.Repo{
|
||||||
RemoteID: model.RemoteID(fmt.Sprint(eventRepo.GetID())),
|
ForgeID: model.ForgeID(fmt.Sprint(eventRepo.GetID())),
|
||||||
Owner: eventRepo.GetOwner().GetLogin(),
|
Owner: eventRepo.GetOwner().GetLogin(),
|
||||||
Name: eventRepo.GetName(),
|
Name: eventRepo.GetName(),
|
||||||
FullName: eventRepo.GetFullName(),
|
FullName: eventRepo.GetFullName(),
|
|
@ -212,7 +212,7 @@ func Test_helper(t *testing.T) {
|
||||||
g.Assert(pipeline.Branch).Equal(*from.PullRequest.Base.Ref)
|
g.Assert(pipeline.Branch).Equal(*from.PullRequest.Base.Ref)
|
||||||
g.Assert(pipeline.Ref).Equal("refs/pull/42/merge")
|
g.Assert(pipeline.Ref).Equal("refs/pull/42/merge")
|
||||||
g.Assert(pipeline.Refspec).Equal("changes:master")
|
g.Assert(pipeline.Refspec).Equal("changes:master")
|
||||||
g.Assert(pipeline.Remote).Equal("https://github.com/octocat/hello-world-fork")
|
g.Assert(pipeline.CloneURL).Equal("https://github.com/octocat/hello-world-fork")
|
||||||
g.Assert(pipeline.Commit).Equal(*from.PullRequest.Head.SHA)
|
g.Assert(pipeline.Commit).Equal(*from.PullRequest.Head.SHA)
|
||||||
g.Assert(pipeline.Message).Equal(*from.PullRequest.Title)
|
g.Assert(pipeline.Message).Equal(*from.PullRequest.Title)
|
||||||
g.Assert(pipeline.Title).Equal(*from.PullRequest.Title)
|
g.Assert(pipeline.Title).Equal(*from.PullRequest.Title)
|
||||||
|
@ -266,7 +266,7 @@ func Test_helper(t *testing.T) {
|
||||||
g.Assert(pipeline.Author).Equal(*from.Sender.Login)
|
g.Assert(pipeline.Author).Equal(*from.Sender.Login)
|
||||||
g.Assert(pipeline.Avatar).Equal(*from.Sender.AvatarURL)
|
g.Assert(pipeline.Avatar).Equal(*from.Sender.AvatarURL)
|
||||||
g.Assert(pipeline.Email).Equal(*from.HeadCommit.Author.Email)
|
g.Assert(pipeline.Email).Equal(*from.HeadCommit.Author.Email)
|
||||||
g.Assert(pipeline.Remote).Equal(*from.Repo.CloneURL)
|
g.Assert(pipeline.CloneURL).Equal(*from.Repo.CloneURL)
|
||||||
})
|
})
|
||||||
|
|
||||||
g.It("should convert a tag from webhook", func() {
|
g.It("should convert a tag from webhook", func() {
|
|
@ -30,9 +30,9 @@ import (
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server"
|
"github.com/woodpecker-ci/woodpecker/server"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/common"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote"
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/common"
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server/store"
|
"github.com/woodpecker-ci/woodpecker/server/store"
|
||||||
"github.com/woodpecker-ci/woodpecker/shared/utils"
|
"github.com/woodpecker-ci/woodpecker/shared/utils"
|
||||||
)
|
)
|
||||||
|
@ -51,9 +51,9 @@ type Opts struct {
|
||||||
MergeRef bool // Clone pull requests using the merge ref.
|
MergeRef bool // Clone pull requests using the merge ref.
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a Remote implementation that integrates with a GitHub Cloud or
|
// New returns a Forge implementation that integrates with a GitHub Cloud or
|
||||||
// GitHub Enterprise version control hosting provider.
|
// GitHub Enterprise version control hosting provider.
|
||||||
func New(opts Opts) (remote.Remote, error) {
|
func New(opts Opts) (forge.Forge, error) {
|
||||||
r := &client{
|
r := &client{
|
||||||
API: defaultAPI,
|
API: defaultAPI,
|
||||||
URL: defaultURL,
|
URL: defaultURL,
|
||||||
|
@ -84,13 +84,13 @@ func (c *client) Name() string {
|
||||||
return "github"
|
return "github"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Login authenticates the session and returns the remote user details.
|
// Login authenticates the session and returns the forge user details.
|
||||||
func (c *client) Login(ctx context.Context, res http.ResponseWriter, req *http.Request) (*model.User, error) {
|
func (c *client) Login(ctx context.Context, res http.ResponseWriter, req *http.Request) (*model.User, error) {
|
||||||
config := c.newConfig(req)
|
config := c.newConfig(req)
|
||||||
|
|
||||||
// get the OAuth errors
|
// get the OAuth errors
|
||||||
if err := req.FormValue("error"); err != "" {
|
if err := req.FormValue("error"); err != "" {
|
||||||
return nil, &remote.AuthError{
|
return nil, &forge.AuthError{
|
||||||
Err: err,
|
Err: err,
|
||||||
Description: req.FormValue("error_description"),
|
Description: req.FormValue("error_description"),
|
||||||
URI: req.FormValue("error_uri"),
|
URI: req.FormValue("error_uri"),
|
||||||
|
@ -165,7 +165,7 @@ func (c *client) Teams(ctx context.Context, u *model.User) ([]*model.Team, error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Repo returns the GitHub repository.
|
// Repo returns the GitHub repository.
|
||||||
func (c *client) Repo(ctx context.Context, u *model.User, id model.RemoteID, owner, name string) (*model.Repo, error) {
|
func (c *client) Repo(ctx context.Context, u *model.User, id model.ForgeID, owner, name string) (*model.Repo, error) {
|
||||||
client := c.newClientToken(ctx, u.Token)
|
client := c.newClientToken(ctx, u.Token)
|
||||||
|
|
||||||
if id.IsValid() {
|
if id.IsValid() {
|
||||||
|
@ -235,7 +235,7 @@ func (c *client) File(ctx context.Context, u *model.User, r *model.Repo, b *mode
|
||||||
return []byte(data), err
|
return []byte(data), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) Dir(ctx context.Context, u *model.User, r *model.Repo, b *model.Pipeline, f string) ([]*remote.FileMeta, error) {
|
func (c *client) Dir(ctx context.Context, u *model.User, r *model.Repo, b *model.Pipeline, f string) ([]*forge.FileMeta, error) {
|
||||||
client := c.newClientToken(ctx, u.Token)
|
client := c.newClientToken(ctx, u.Token)
|
||||||
|
|
||||||
opts := new(github.RepositoryContentGetOptions)
|
opts := new(github.RepositoryContentGetOptions)
|
||||||
|
@ -245,7 +245,7 @@ func (c *client) Dir(ctx context.Context, u *model.User, r *model.Repo, b *model
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
fc := make(chan *remote.FileMeta)
|
fc := make(chan *forge.FileMeta)
|
||||||
errc := make(chan error)
|
errc := make(chan error)
|
||||||
|
|
||||||
for _, file := range data {
|
for _, file := range data {
|
||||||
|
@ -254,7 +254,7 @@ func (c *client) Dir(ctx context.Context, u *model.User, r *model.Repo, b *model
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errc <- err
|
errc <- err
|
||||||
} else {
|
} else {
|
||||||
fc <- &remote.FileMeta{
|
fc <- &forge.FileMeta{
|
||||||
Name: path,
|
Name: path,
|
||||||
Data: content,
|
Data: content,
|
||||||
}
|
}
|
||||||
|
@ -262,7 +262,7 @@ func (c *client) Dir(ctx context.Context, u *model.User, r *model.Repo, b *model
|
||||||
}(f + "/" + *file.Name)
|
}(f + "/" + *file.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
var files []*remote.FileMeta
|
var files []*forge.FileMeta
|
||||||
|
|
||||||
for i := 0; i < len(data); i++ {
|
for i := 0; i < len(data); i++ {
|
||||||
select {
|
select {
|
||||||
|
@ -332,7 +332,7 @@ func (c *client) OrgMembership(ctx context.Context, u *model.User, owner string)
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function to return the GitHub oauth2 context using an HTTPClient that
|
// helper function to return the GitHub oauth2 context using an HTTPClient that
|
||||||
// disables TLS verification if disabled in the remote settings.
|
// disables TLS verification if disabled in the forge settings.
|
||||||
func (c *client) newContext(ctx context.Context) context.Context {
|
func (c *client) newContext(ctx context.Context) context.Context {
|
||||||
if !c.SkipVerify {
|
if !c.SkipVerify {
|
||||||
return ctx
|
return ctx
|
||||||
|
@ -435,7 +435,7 @@ func matchingHooks(hooks []*github.Hook, rawurl string) *github.Hook {
|
||||||
|
|
||||||
var reDeploy = regexp.MustCompile(`.+/deployments/(\d+)`)
|
var reDeploy = regexp.MustCompile(`.+/deployments/(\d+)`)
|
||||||
|
|
||||||
// Status sends the commit status to the remote system.
|
// Status sends the commit status to the forge.
|
||||||
// An example would be the GitHub pull request status.
|
// An example would be the GitHub pull request status.
|
||||||
func (c *client) Status(ctx context.Context, user *model.User, repo *model.Repo, pipeline *model.Pipeline, step *model.Step) error {
|
func (c *client) Status(ctx context.Context, user *model.User, repo *model.Repo, pipeline *model.Pipeline, step *model.Step) error {
|
||||||
client := c.newClientToken(ctx, user.Token)
|
client := c.newClientToken(ctx, user.Token)
|
||||||
|
@ -545,7 +545,7 @@ func (c *client) loadChangedFilesFromPullRequest(ctx context.Context, pull *gith
|
||||||
return pipeline, nil
|
return pipeline, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
repo, err := _store.GetRepoNameFallback(tmpRepo.RemoteID, tmpRepo.FullName)
|
repo, err := _store.GetRepoNameFallback(tmpRepo.ForgeID, tmpRepo.FullName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
|
@ -23,8 +23,8 @@ import (
|
||||||
"github.com/franela/goblin"
|
"github.com/franela/goblin"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/github/fixtures"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/github/fixtures"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_github(t *testing.T) {
|
func Test_github(t *testing.T) {
|
||||||
|
@ -43,33 +43,33 @@ func Test_github(t *testing.T) {
|
||||||
s.Close()
|
s.Close()
|
||||||
})
|
})
|
||||||
|
|
||||||
g.Describe("Creating a remote", func() {
|
g.Describe("Creating a forge", func() {
|
||||||
g.It("Should return client with specified options", func() {
|
g.It("Should return client with specified options", func() {
|
||||||
remote, _ := New(Opts{
|
forge, _ := New(Opts{
|
||||||
URL: "http://localhost:8080/",
|
URL: "http://localhost:8080/",
|
||||||
Client: "0ZXh0IjoiI",
|
Client: "0ZXh0IjoiI",
|
||||||
Secret: "I1NiIsInR5",
|
Secret: "I1NiIsInR5",
|
||||||
SkipVerify: true,
|
SkipVerify: true,
|
||||||
})
|
})
|
||||||
g.Assert(remote.(*client).URL).Equal("http://localhost:8080")
|
g.Assert(forge.(*client).URL).Equal("http://localhost:8080")
|
||||||
g.Assert(remote.(*client).API).Equal("http://localhost:8080/api/v3/")
|
g.Assert(forge.(*client).API).Equal("http://localhost:8080/api/v3/")
|
||||||
g.Assert(remote.(*client).Client).Equal("0ZXh0IjoiI")
|
g.Assert(forge.(*client).Client).Equal("0ZXh0IjoiI")
|
||||||
g.Assert(remote.(*client).Secret).Equal("I1NiIsInR5")
|
g.Assert(forge.(*client).Secret).Equal("I1NiIsInR5")
|
||||||
g.Assert(remote.(*client).SkipVerify).Equal(true)
|
g.Assert(forge.(*client).SkipVerify).Equal(true)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
g.Describe("Generating a netrc file", func() {
|
g.Describe("Generating a netrc file", func() {
|
||||||
g.It("Should return a netrc with the user token", func() {
|
g.It("Should return a netrc with the user token", func() {
|
||||||
remote, _ := New(Opts{})
|
forge, _ := New(Opts{})
|
||||||
netrc, _ := remote.Netrc(fakeUser, fakeRepo)
|
netrc, _ := forge.Netrc(fakeUser, fakeRepo)
|
||||||
g.Assert(netrc.Machine).Equal("github.com")
|
g.Assert(netrc.Machine).Equal("github.com")
|
||||||
g.Assert(netrc.Login).Equal(fakeUser.Token)
|
g.Assert(netrc.Login).Equal(fakeUser.Token)
|
||||||
g.Assert(netrc.Password).Equal("x-oauth-basic")
|
g.Assert(netrc.Password).Equal("x-oauth-basic")
|
||||||
})
|
})
|
||||||
g.It("Should return a netrc with the machine account", func() {
|
g.It("Should return a netrc with the machine account", func() {
|
||||||
remote, _ := New(Opts{})
|
forge, _ := New(Opts{})
|
||||||
netrc, _ := remote.Netrc(nil, fakeRepo)
|
netrc, _ := forge.Netrc(nil, fakeRepo)
|
||||||
g.Assert(netrc.Machine).Equal("github.com")
|
g.Assert(netrc.Machine).Equal("github.com")
|
||||||
g.Assert(netrc.Login).Equal("")
|
g.Assert(netrc.Login).Equal("")
|
||||||
g.Assert(netrc.Password).Equal("")
|
g.Assert(netrc.Password).Equal("")
|
||||||
|
@ -78,9 +78,9 @@ func Test_github(t *testing.T) {
|
||||||
|
|
||||||
g.Describe("Requesting a repository", func() {
|
g.Describe("Requesting a repository", func() {
|
||||||
g.It("Should return the repository details", func() {
|
g.It("Should return the repository details", func() {
|
||||||
repo, err := c.Repo(ctx, fakeUser, fakeRepo.RemoteID, fakeRepo.Owner, fakeRepo.Name)
|
repo, err := c.Repo(ctx, fakeUser, fakeRepo.ForgeID, fakeRepo.Owner, fakeRepo.Name)
|
||||||
g.Assert(err).IsNil()
|
g.Assert(err).IsNil()
|
||||||
g.Assert(repo.RemoteID).Equal(fakeRepo.RemoteID)
|
g.Assert(repo.ForgeID).Equal(fakeRepo.ForgeID)
|
||||||
g.Assert(repo.Owner).Equal(fakeRepo.Owner)
|
g.Assert(repo.Owner).Equal(fakeRepo.Owner)
|
||||||
g.Assert(repo.Name).Equal(fakeRepo.Name)
|
g.Assert(repo.Name).Equal(fakeRepo.Name)
|
||||||
g.Assert(repo.FullName).Equal(fakeRepo.FullName)
|
g.Assert(repo.FullName).Equal(fakeRepo.FullName)
|
||||||
|
@ -133,7 +133,7 @@ var (
|
||||||
}
|
}
|
||||||
|
|
||||||
fakeRepo = &model.Repo{
|
fakeRepo = &model.Repo{
|
||||||
RemoteID: "5",
|
ForgeID: "5",
|
||||||
Owner: "octocat",
|
Owner: "octocat",
|
||||||
Name: "Hello-World",
|
Name: "Hello-World",
|
||||||
FullName: "octocat/Hello-World",
|
FullName: "octocat/Hello-World",
|
|
@ -86,7 +86,7 @@ func parsePushHook(hook *github.PushEvent) (*model.Repo, *model.Pipeline, error)
|
||||||
Email: hook.GetHeadCommit().GetAuthor().GetEmail(),
|
Email: hook.GetHeadCommit().GetAuthor().GetEmail(),
|
||||||
Avatar: hook.GetSender().GetAvatarURL(),
|
Avatar: hook.GetSender().GetAvatarURL(),
|
||||||
Author: hook.GetSender().GetLogin(),
|
Author: hook.GetSender().GetLogin(),
|
||||||
Remote: hook.GetRepo().GetCloneURL(),
|
CloneURL: hook.GetRepo().GetCloneURL(),
|
||||||
Sender: hook.GetSender().GetLogin(),
|
Sender: hook.GetSender().GetLogin(),
|
||||||
ChangedFiles: getChangedFilesFromCommits(hook.Commits),
|
ChangedFiles: getChangedFilesFromCommits(hook.Commits),
|
||||||
}
|
}
|
||||||
|
@ -165,7 +165,7 @@ func parsePullHook(hook *github.PullRequestEvent, merge bool) (*github.PullReque
|
||||||
Avatar: hook.GetPullRequest().GetUser().GetAvatarURL(),
|
Avatar: hook.GetPullRequest().GetUser().GetAvatarURL(),
|
||||||
Title: hook.GetPullRequest().GetTitle(),
|
Title: hook.GetPullRequest().GetTitle(),
|
||||||
Sender: hook.GetSender().GetLogin(),
|
Sender: hook.GetSender().GetLogin(),
|
||||||
Remote: hook.GetPullRequest().GetHead().GetRepo().GetCloneURL(),
|
CloneURL: hook.GetPullRequest().GetHead().GetRepo().GetCloneURL(),
|
||||||
Refspec: fmt.Sprintf(refSpec,
|
Refspec: fmt.Sprintf(refSpec,
|
||||||
hook.GetPullRequest().GetHead().GetRef(),
|
hook.GetPullRequest().GetHead().GetRef(),
|
||||||
hook.GetPullRequest().GetBase().GetRef(),
|
hook.GetPullRequest().GetBase().GetRef(),
|
|
@ -23,8 +23,8 @@ import (
|
||||||
|
|
||||||
"github.com/franela/goblin"
|
"github.com/franela/goblin"
|
||||||
|
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/github/fixtures"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/github/fixtures"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
|
@ -37,7 +37,7 @@ func (g *Gitlab) convertGitlabRepo(_repo *gitlab.Project) (*model.Repo, error) {
|
||||||
owner := strings.Join(parts[:len(parts)-1], "/")
|
owner := strings.Join(parts[:len(parts)-1], "/")
|
||||||
name := parts[len(parts)-1]
|
name := parts[len(parts)-1]
|
||||||
repo := &model.Repo{
|
repo := &model.Repo{
|
||||||
RemoteID: model.RemoteID(fmt.Sprint(_repo.ID)),
|
ForgeID: model.ForgeID(fmt.Sprint(_repo.ID)),
|
||||||
Owner: owner,
|
Owner: owner,
|
||||||
Name: name,
|
Name: name,
|
||||||
FullName: _repo.PathWithNamespace,
|
FullName: _repo.PathWithNamespace,
|
||||||
|
@ -88,7 +88,7 @@ func convertMergeRequestHook(hook *gitlab.MergeEvent, req *http.Request) (int, *
|
||||||
repo.FullName = fmt.Sprintf("%s/%s", repo.Owner, repo.Name)
|
repo.FullName = fmt.Sprintf("%s/%s", repo.Owner, repo.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
repo.RemoteID = model.RemoteID(fmt.Sprint(obj.TargetProjectID))
|
repo.ForgeID = model.ForgeID(fmt.Sprint(obj.TargetProjectID))
|
||||||
repo.Link = target.WebURL
|
repo.Link = target.WebURL
|
||||||
|
|
||||||
if target.GitHTTPURL != "" {
|
if target.GitHTTPURL != "" {
|
||||||
|
@ -113,7 +113,7 @@ func convertMergeRequestHook(hook *gitlab.MergeEvent, req *http.Request) (int, *
|
||||||
|
|
||||||
pipeline.Message = lastCommit.Message
|
pipeline.Message = lastCommit.Message
|
||||||
pipeline.Commit = lastCommit.ID
|
pipeline.Commit = lastCommit.ID
|
||||||
pipeline.Remote = obj.Source.HTTPURL
|
pipeline.CloneURL = obj.Source.HTTPURL
|
||||||
|
|
||||||
pipeline.Ref = fmt.Sprintf(mergeRefs, obj.IID)
|
pipeline.Ref = fmt.Sprintf(mergeRefs, obj.IID)
|
||||||
pipeline.Branch = obj.SourceBranch
|
pipeline.Branch = obj.SourceBranch
|
||||||
|
@ -142,7 +142,7 @@ func convertPushHook(hook *gitlab.PushEvent) (*model.Repo, *model.Pipeline, erro
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
repo.RemoteID = model.RemoteID(fmt.Sprint(hook.ProjectID))
|
repo.ForgeID = model.ForgeID(fmt.Sprint(hook.ProjectID))
|
||||||
repo.Avatar = hook.Project.AvatarURL
|
repo.Avatar = hook.Project.AvatarURL
|
||||||
repo.Link = hook.Project.WebURL
|
repo.Link = hook.Project.WebURL
|
||||||
repo.Clone = hook.Project.GitHTTPURL
|
repo.Clone = hook.Project.GitHTTPURL
|
||||||
|
@ -194,7 +194,7 @@ func convertTagHook(hook *gitlab.TagEvent) (*model.Repo, *model.Pipeline, error)
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
repo.RemoteID = model.RemoteID(fmt.Sprint(hook.ProjectID))
|
repo.ForgeID = model.ForgeID(fmt.Sprint(hook.ProjectID))
|
||||||
repo.Avatar = hook.Project.AvatarURL
|
repo.Avatar = hook.Project.AvatarURL
|
||||||
repo.Link = hook.Project.WebURL
|
repo.Link = hook.Project.WebURL
|
||||||
repo.Clone = hook.Project.GitHTTPURL
|
repo.Clone = hook.Project.GitHTTPURL
|
|
@ -31,9 +31,9 @@ import (
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server"
|
"github.com/woodpecker-ci/woodpecker/server"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/common"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote"
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/common"
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server/store"
|
"github.com/woodpecker-ci/woodpecker/server/store"
|
||||||
"github.com/woodpecker-ci/woodpecker/shared/utils"
|
"github.com/woodpecker-ci/woodpecker/shared/utils"
|
||||||
)
|
)
|
||||||
|
@ -51,7 +51,7 @@ type Opts struct {
|
||||||
SkipVerify bool // Skip ssl verification.
|
SkipVerify bool // Skip ssl verification.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gitlab implements "Remote" interface
|
// Gitlab implements "Forge" interface
|
||||||
type Gitlab struct {
|
type Gitlab struct {
|
||||||
URL string
|
URL string
|
||||||
ClientID string
|
ClientID string
|
||||||
|
@ -61,9 +61,9 @@ type Gitlab struct {
|
||||||
Search bool
|
Search bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a Remote implementation that integrates with Gitlab, an open
|
// New returns a Forge implementation that integrates with Gitlab, an open
|
||||||
// source Git service. See https://gitlab.com
|
// source Git service. See https://gitlab.com
|
||||||
func New(opts Opts) (remote.Remote, error) {
|
func New(opts Opts) (forge.Forge, error) {
|
||||||
return &Gitlab{
|
return &Gitlab{
|
||||||
URL: opts.URL,
|
URL: opts.URL,
|
||||||
ClientID: opts.ClientID,
|
ClientID: opts.ClientID,
|
||||||
|
@ -96,13 +96,13 @@ func (g *Gitlab) oauth2Config(ctx context.Context) (*oauth2.Config, context.Cont
|
||||||
}
|
}
|
||||||
|
|
||||||
// Login authenticates the session and returns the
|
// Login authenticates the session and returns the
|
||||||
// remote user details.
|
// forge user details.
|
||||||
func (g *Gitlab) Login(ctx context.Context, res http.ResponseWriter, req *http.Request) (*model.User, error) {
|
func (g *Gitlab) Login(ctx context.Context, res http.ResponseWriter, req *http.Request) (*model.User, error) {
|
||||||
config, oauth2Ctx := g.oauth2Config(ctx)
|
config, oauth2Ctx := g.oauth2Config(ctx)
|
||||||
|
|
||||||
// get the OAuth errors
|
// get the OAuth errors
|
||||||
if err := req.FormValue("error"); err != "" {
|
if err := req.FormValue("error"); err != "" {
|
||||||
return nil, &remote.AuthError{
|
return nil, &forge.AuthError{
|
||||||
Err: err,
|
Err: err,
|
||||||
Description: req.FormValue("error_description"),
|
Description: req.FormValue("error_description"),
|
||||||
URI: req.FormValue("error_uri"),
|
URI: req.FormValue("error_uri"),
|
||||||
|
@ -168,7 +168,7 @@ func (g *Gitlab) Refresh(ctx context.Context, user *model.User) (bool, error) {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Auth authenticates the session and returns the remote user login for the given token
|
// Auth authenticates the session and returns the forge user login for the given token
|
||||||
func (g *Gitlab) Auth(ctx context.Context, token, _ string) (string, error) {
|
func (g *Gitlab) Auth(ctx context.Context, token, _ string) (string, error) {
|
||||||
client, err := newClient(g.URL, token, g.SkipVerify)
|
client, err := newClient(g.URL, token, g.SkipVerify)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -182,7 +182,7 @@ func (g *Gitlab) Auth(ctx context.Context, token, _ string) (string, error) {
|
||||||
return login.Username, nil
|
return login.Username, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Teams fetches a list of team memberships from the remote system.
|
// Teams fetches a list of team memberships from the forge.
|
||||||
func (g *Gitlab) Teams(ctx context.Context, user *model.User) ([]*model.Team, error) {
|
func (g *Gitlab) Teams(ctx context.Context, user *model.User) ([]*model.Team, error) {
|
||||||
client, err := newClient(g.URL, user.Token, g.SkipVerify)
|
client, err := newClient(g.URL, user.Token, g.SkipVerify)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -217,7 +217,7 @@ func (g *Gitlab) Teams(ctx context.Context, user *model.User) ([]*model.Team, er
|
||||||
return teams, nil
|
return teams, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// getProject fetches the named repository from the remote system.
|
// getProject fetches the named repository from the forge.
|
||||||
func (g *Gitlab) getProject(ctx context.Context, client *gitlab.Client, owner, name string) (*gitlab.Project, error) {
|
func (g *Gitlab) getProject(ctx context.Context, client *gitlab.Client, owner, name string) (*gitlab.Project, error) {
|
||||||
repo, _, err := client.Projects.GetProject(fmt.Sprintf("%s/%s", owner, name), nil, gitlab.WithContext(ctx))
|
repo, _, err := client.Projects.GetProject(fmt.Sprintf("%s/%s", owner, name), nil, gitlab.WithContext(ctx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -227,8 +227,8 @@ func (g *Gitlab) getProject(ctx context.Context, client *gitlab.Client, owner, n
|
||||||
return repo, nil
|
return repo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Repo fetches the repository from the remote system.
|
// Repo fetches the repository from the forge.
|
||||||
func (g *Gitlab) Repo(ctx context.Context, user *model.User, id model.RemoteID, owner, name string) (*model.Repo, error) {
|
func (g *Gitlab) Repo(ctx context.Context, user *model.User, id model.ForgeID, owner, name string) (*model.Repo, error) {
|
||||||
client, err := newClient(g.URL, user.Token, g.SkipVerify)
|
client, err := newClient(g.URL, user.Token, g.SkipVerify)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -254,7 +254,7 @@ func (g *Gitlab) Repo(ctx context.Context, user *model.User, id model.RemoteID,
|
||||||
return g.convertGitlabRepo(_repo)
|
return g.convertGitlabRepo(_repo)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Repos fetches a list of repos from the remote system.
|
// Repos fetches a list of repos from the forge.
|
||||||
func (g *Gitlab) Repos(ctx context.Context, user *model.User) ([]*model.Repo, error) {
|
func (g *Gitlab) Repos(ctx context.Context, user *model.User) ([]*model.Repo, error) {
|
||||||
client, err := newClient(g.URL, user.Token, g.SkipVerify)
|
client, err := newClient(g.URL, user.Token, g.SkipVerify)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -300,7 +300,7 @@ func (g *Gitlab) Repos(ctx context.Context, user *model.User) ([]*model.Repo, er
|
||||||
return repos, err
|
return repos, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perm fetches the named repository from the remote system.
|
// Perm fetches the named repository from the forge.
|
||||||
func (g *Gitlab) Perm(ctx context.Context, user *model.User, r *model.Repo) (*model.Perm, error) {
|
func (g *Gitlab) Perm(ctx context.Context, user *model.User, r *model.Repo) (*model.Perm, error) {
|
||||||
client, err := newClient(g.URL, user.Token, g.SkipVerify)
|
client, err := newClient(g.URL, user.Token, g.SkipVerify)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -324,7 +324,7 @@ func (g *Gitlab) Perm(ctx context.Context, user *model.User, r *model.Repo) (*mo
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// File fetches a file from the remote repository and returns in string format.
|
// File fetches a file from the forge repository and returns in string format.
|
||||||
func (g *Gitlab) File(ctx context.Context, user *model.User, repo *model.Repo, pipeline *model.Pipeline, fileName string) ([]byte, error) {
|
func (g *Gitlab) File(ctx context.Context, user *model.User, repo *model.Repo, pipeline *model.Pipeline, fileName string) ([]byte, error) {
|
||||||
client, err := newClient(g.URL, user.Token, g.SkipVerify)
|
client, err := newClient(g.URL, user.Token, g.SkipVerify)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -338,14 +338,14 @@ func (g *Gitlab) File(ctx context.Context, user *model.User, repo *model.Repo, p
|
||||||
return file, err
|
return file, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dir fetches a folder from the remote repository
|
// Dir fetches a folder from the forge repository
|
||||||
func (g *Gitlab) Dir(ctx context.Context, user *model.User, repo *model.Repo, pipeline *model.Pipeline, path string) ([]*remote.FileMeta, error) {
|
func (g *Gitlab) Dir(ctx context.Context, user *model.User, repo *model.Repo, pipeline *model.Pipeline, path string) ([]*forge.FileMeta, error) {
|
||||||
client, err := newClient(g.URL, user.Token, g.SkipVerify)
|
client, err := newClient(g.URL, user.Token, g.SkipVerify)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
files := make([]*remote.FileMeta, 0, perPage)
|
files := make([]*forge.FileMeta, 0, perPage)
|
||||||
_repo, err := g.getProject(ctx, client, repo.Owner, repo.Name)
|
_repo, err := g.getProject(ctx, client, repo.Owner, repo.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -372,7 +372,7 @@ func (g *Gitlab) Dir(ctx context.Context, user *model.User, repo *model.Repo, pi
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
files = append(files, &remote.FileMeta{
|
files = append(files, &forge.FileMeta{
|
||||||
Name: batch[i].Path,
|
Name: batch[i].Path,
|
||||||
Data: data,
|
Data: data,
|
||||||
})
|
})
|
||||||
|
@ -681,7 +681,7 @@ func (g *Gitlab) loadChangedFilesFromMergeRequest(ctx context.Context, tmpRepo *
|
||||||
return pipeline, nil
|
return pipeline, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
repo, err := _store.GetRepoNameFallback(tmpRepo.RemoteID, tmpRepo.FullName)
|
repo, err := _store.GetRepoNameFallback(tmpRepo.ForgeID, tmpRepo.FullName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
|
@ -26,8 +26,8 @@ import (
|
||||||
"github.com/franela/goblin"
|
"github.com/franela/goblin"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/gitlab/testdata"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/gitlab/testdata"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func load(t *testing.T, config string) *Gitlab {
|
func load(t *testing.T, config string) *Gitlab {
|
|
@ -27,7 +27,7 @@ func NewServer(t *testing.T) *httptest.Server {
|
||||||
|
|
||||||
// handle requests and serve mock data
|
// handle requests and serve mock data
|
||||||
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
t.Logf("gitlab remote mock server: [%s] %s", r.Method, r.URL.Path)
|
t.Logf("gitlab forge mock server: [%s] %s", r.Method, r.URL.Path)
|
||||||
// evaluate the path to serve a dummy data file
|
// evaluate the path to serve a dummy data file
|
||||||
|
|
||||||
// TODO: find source of "/api/v4/" requests
|
// TODO: find source of "/api/v4/" requests
|
|
@ -26,9 +26,9 @@ import (
|
||||||
|
|
||||||
"github.com/gogits/go-gogs-client"
|
"github.com/gogits/go-gogs-client"
|
||||||
|
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/common"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote"
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/common"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Opts defines configuration options.
|
// Opts defines configuration options.
|
||||||
|
@ -48,9 +48,9 @@ type client struct {
|
||||||
SkipVerify bool
|
SkipVerify bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a Remote implementation that integrates with Gogs, an open
|
// New returns a Forge implementation that integrates with Gogs, an open
|
||||||
// source Git service written in Go. See https://gogs.io/
|
// source Git service written in Go. See https://gogs.io/
|
||||||
func New(opts Opts) (remote.Remote, error) {
|
func New(opts Opts) (forge.Forge, error) {
|
||||||
u, err := url.Parse(opts.URL)
|
u, err := url.Parse(opts.URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -149,7 +149,7 @@ func (c *client) Teams(ctx context.Context, u *model.User) ([]*model.Team, error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Repo returns the named Gogs repository.
|
// Repo returns the named Gogs repository.
|
||||||
func (c *client) Repo(ctx context.Context, u *model.User, _ model.RemoteID, owner, name string) (*model.Repo, error) {
|
func (c *client) Repo(ctx context.Context, u *model.User, _ model.ForgeID, owner, name string) (*model.Repo, error) {
|
||||||
client := c.newClientToken(u.Token)
|
client := c.newClientToken(u.Token)
|
||||||
repo, err := client.GetRepo(owner, name)
|
repo, err := client.GetRepo(owner, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -209,7 +209,7 @@ func (c *client) File(ctx context.Context, u *model.User, r *model.Repo, b *mode
|
||||||
return cfg, err
|
return cfg, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) Dir(ctx context.Context, u *model.User, r *model.Repo, b *model.Pipeline, f string) ([]*remote.FileMeta, error) {
|
func (c *client) Dir(ctx context.Context, u *model.User, r *model.Repo, b *model.Pipeline, f string) ([]*forge.FileMeta, error) {
|
||||||
return nil, fmt.Errorf("Not implemented")
|
return nil, fmt.Errorf("Not implemented")
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,8 @@ import (
|
||||||
"github.com/franela/goblin"
|
"github.com/franela/goblin"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/gogs/fixtures"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/gogs/fixtures"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_gogs(t *testing.T) {
|
func Test_gogs(t *testing.T) {
|
||||||
|
@ -43,20 +43,20 @@ func Test_gogs(t *testing.T) {
|
||||||
s.Close()
|
s.Close()
|
||||||
})
|
})
|
||||||
|
|
||||||
g.Describe("Creating a remote", func() {
|
g.Describe("Creating a forge", func() {
|
||||||
g.It("Should return client with specified options", func() {
|
g.It("Should return client with specified options", func() {
|
||||||
remote, _ := New(Opts{
|
forge, _ := New(Opts{
|
||||||
URL: "http://localhost:8080",
|
URL: "http://localhost:8080",
|
||||||
Username: "someuser",
|
Username: "someuser",
|
||||||
Password: "password",
|
Password: "password",
|
||||||
SkipVerify: true,
|
SkipVerify: true,
|
||||||
PrivateMode: true,
|
PrivateMode: true,
|
||||||
})
|
})
|
||||||
g.Assert(remote.(*client).URL).Equal("http://localhost:8080")
|
g.Assert(forge.(*client).URL).Equal("http://localhost:8080")
|
||||||
g.Assert(remote.(*client).Username).Equal("someuser")
|
g.Assert(forge.(*client).Username).Equal("someuser")
|
||||||
g.Assert(remote.(*client).Password).Equal("password")
|
g.Assert(forge.(*client).Password).Equal("password")
|
||||||
g.Assert(remote.(*client).SkipVerify).Equal(true)
|
g.Assert(forge.(*client).SkipVerify).Equal(true)
|
||||||
g.Assert(remote.(*client).PrivateMode).Equal(true)
|
g.Assert(forge.(*client).PrivateMode).Equal(true)
|
||||||
})
|
})
|
||||||
g.It("Should handle malformed url", func() {
|
g.It("Should handle malformed url", func() {
|
||||||
_, err := New(Opts{URL: "%gh&%ij"})
|
_, err := New(Opts{URL: "%gh&%ij"})
|
||||||
|
@ -66,18 +66,18 @@ func Test_gogs(t *testing.T) {
|
||||||
|
|
||||||
g.Describe("Generating a netrc file", func() {
|
g.Describe("Generating a netrc file", func() {
|
||||||
g.It("Should return a netrc with the user token", func() {
|
g.It("Should return a netrc with the user token", func() {
|
||||||
remote, _ := New(Opts{})
|
forge, _ := New(Opts{})
|
||||||
netrc, _ := remote.Netrc(fakeUser, fakeRepo)
|
netrc, _ := forge.Netrc(fakeUser, fakeRepo)
|
||||||
g.Assert(netrc.Machine).Equal("gogs.com")
|
g.Assert(netrc.Machine).Equal("gogs.com")
|
||||||
g.Assert(netrc.Login).Equal(fakeUser.Token)
|
g.Assert(netrc.Login).Equal(fakeUser.Token)
|
||||||
g.Assert(netrc.Password).Equal("x-oauth-basic")
|
g.Assert(netrc.Password).Equal("x-oauth-basic")
|
||||||
})
|
})
|
||||||
g.It("Should return a netrc with the machine account", func() {
|
g.It("Should return a netrc with the machine account", func() {
|
||||||
remote, _ := New(Opts{
|
forge, _ := New(Opts{
|
||||||
Username: "someuser",
|
Username: "someuser",
|
||||||
Password: "password",
|
Password: "password",
|
||||||
})
|
})
|
||||||
netrc, _ := remote.Netrc(nil, fakeRepo)
|
netrc, _ := forge.Netrc(nil, fakeRepo)
|
||||||
g.Assert(netrc.Machine).Equal("gogs.com")
|
g.Assert(netrc.Machine).Equal("gogs.com")
|
||||||
g.Assert(netrc.Login).Equal("someuser")
|
g.Assert(netrc.Login).Equal("someuser")
|
||||||
g.Assert(netrc.Password).Equal("password")
|
g.Assert(netrc.Password).Equal("password")
|
||||||
|
@ -86,7 +86,7 @@ func Test_gogs(t *testing.T) {
|
||||||
|
|
||||||
g.Describe("Requesting a repository", func() {
|
g.Describe("Requesting a repository", func() {
|
||||||
g.It("Should return the repository details", func() {
|
g.It("Should return the repository details", func() {
|
||||||
repo, err := c.Repo(ctx, fakeUser, fakeRepo.RemoteID, fakeRepo.Owner, fakeRepo.Name)
|
repo, err := c.Repo(ctx, fakeUser, fakeRepo.ForgeID, fakeRepo.Owner, fakeRepo.Name)
|
||||||
g.Assert(err).IsNil()
|
g.Assert(err).IsNil()
|
||||||
g.Assert(repo.Owner).Equal(fakeRepo.Owner)
|
g.Assert(repo.Owner).Equal(fakeRepo.Owner)
|
||||||
g.Assert(repo.Name).Equal(fakeRepo.Name)
|
g.Assert(repo.Name).Equal(fakeRepo.Name)
|
||||||
|
@ -119,7 +119,7 @@ func Test_gogs(t *testing.T) {
|
||||||
g.It("Should return the repository list", func() {
|
g.It("Should return the repository list", func() {
|
||||||
repos, err := c.Repos(ctx, fakeUser)
|
repos, err := c.Repos(ctx, fakeUser)
|
||||||
g.Assert(err).IsNil()
|
g.Assert(err).IsNil()
|
||||||
g.Assert(repos[0].RemoteID).Equal(fakeRepo.RemoteID)
|
g.Assert(repos[0].ForgeID).Equal(fakeRepo.ForgeID)
|
||||||
g.Assert(repos[0].Owner).Equal(fakeRepo.Owner)
|
g.Assert(repos[0].Owner).Equal(fakeRepo.Owner)
|
||||||
g.Assert(repos[0].Name).Equal(fakeRepo.Name)
|
g.Assert(repos[0].Name).Equal(fakeRepo.Name)
|
||||||
g.Assert(repos[0].FullName).Equal(fakeRepo.Owner + "/" + fakeRepo.Name)
|
g.Assert(repos[0].FullName).Equal(fakeRepo.Owner + "/" + fakeRepo.Name)
|
||||||
|
@ -183,7 +183,7 @@ var (
|
||||||
}
|
}
|
||||||
|
|
||||||
fakeRepo = &model.Repo{
|
fakeRepo = &model.Repo{
|
||||||
RemoteID: "5",
|
ForgeID: "5",
|
||||||
Clone: "http://gogs.com/test_name/repo_name.git",
|
Clone: "http://gogs.com/test_name/repo_name.git",
|
||||||
Owner: "test_name",
|
Owner: "test_name",
|
||||||
Name: "repo_name",
|
Name: "repo_name",
|
|
@ -36,7 +36,7 @@ func toRepo(from *gogs.Repository, privateMode bool) *model.Repo {
|
||||||
from.Owner.AvatarUrl,
|
from.Owner.AvatarUrl,
|
||||||
)
|
)
|
||||||
return &model.Repo{
|
return &model.Repo{
|
||||||
RemoteID: model.RemoteID(fmt.Sprint(from.ID)),
|
ForgeID: model.ForgeID(fmt.Sprint(from.ID)),
|
||||||
SCMKind: model.RepoGit,
|
SCMKind: model.RepoGit,
|
||||||
Name: name,
|
Name: name,
|
||||||
Owner: from.Owner.UserName,
|
Owner: from.Owner.UserName,
|
|
@ -22,8 +22,8 @@ import (
|
||||||
"github.com/franela/goblin"
|
"github.com/franela/goblin"
|
||||||
"github.com/gogits/go-gogs-client"
|
"github.com/gogits/go-gogs-client"
|
||||||
|
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge/gogs/fixtures"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote/gogs/fixtures"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_parse(t *testing.T) {
|
func Test_parse(t *testing.T) {
|
|
@ -6,20 +6,20 @@ import (
|
||||||
context "context"
|
context "context"
|
||||||
http "net/http"
|
http "net/http"
|
||||||
|
|
||||||
|
forge "github.com/woodpecker-ci/woodpecker/server/forge"
|
||||||
|
|
||||||
mock "github.com/stretchr/testify/mock"
|
mock "github.com/stretchr/testify/mock"
|
||||||
|
|
||||||
model "github.com/woodpecker-ci/woodpecker/server/model"
|
model "github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
|
|
||||||
remote "github.com/woodpecker-ci/woodpecker/server/remote"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Remote is an autogenerated mock type for the Remote type
|
// Forge is an autogenerated mock type for the Forge type
|
||||||
type Remote struct {
|
type Forge struct {
|
||||||
mock.Mock
|
mock.Mock
|
||||||
}
|
}
|
||||||
|
|
||||||
// Activate provides a mock function with given fields: ctx, u, r, link
|
// Activate provides a mock function with given fields: ctx, u, r, link
|
||||||
func (_m *Remote) Activate(ctx context.Context, u *model.User, r *model.Repo, link string) error {
|
func (_m *Forge) Activate(ctx context.Context, u *model.User, r *model.Repo, link string) error {
|
||||||
ret := _m.Called(ctx, u, r, link)
|
ret := _m.Called(ctx, u, r, link)
|
||||||
|
|
||||||
var r0 error
|
var r0 error
|
||||||
|
@ -33,7 +33,7 @@ func (_m *Remote) Activate(ctx context.Context, u *model.User, r *model.Repo, li
|
||||||
}
|
}
|
||||||
|
|
||||||
// Auth provides a mock function with given fields: ctx, token, secret
|
// Auth provides a mock function with given fields: ctx, token, secret
|
||||||
func (_m *Remote) Auth(ctx context.Context, token string, secret string) (string, error) {
|
func (_m *Forge) Auth(ctx context.Context, token string, secret string) (string, error) {
|
||||||
ret := _m.Called(ctx, token, secret)
|
ret := _m.Called(ctx, token, secret)
|
||||||
|
|
||||||
var r0 string
|
var r0 string
|
||||||
|
@ -54,7 +54,7 @@ func (_m *Remote) Auth(ctx context.Context, token string, secret string) (string
|
||||||
}
|
}
|
||||||
|
|
||||||
// BranchHead provides a mock function with given fields: ctx, u, r, branch
|
// BranchHead provides a mock function with given fields: ctx, u, r, branch
|
||||||
func (_m *Remote) BranchHead(ctx context.Context, u *model.User, r *model.Repo, branch string) (string, error) {
|
func (_m *Forge) BranchHead(ctx context.Context, u *model.User, r *model.Repo, branch string) (string, error) {
|
||||||
ret := _m.Called(ctx, u, r, branch)
|
ret := _m.Called(ctx, u, r, branch)
|
||||||
|
|
||||||
var r0 string
|
var r0 string
|
||||||
|
@ -75,7 +75,7 @@ func (_m *Remote) BranchHead(ctx context.Context, u *model.User, r *model.Repo,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Branches provides a mock function with given fields: ctx, u, r
|
// Branches provides a mock function with given fields: ctx, u, r
|
||||||
func (_m *Remote) Branches(ctx context.Context, u *model.User, r *model.Repo) ([]string, error) {
|
func (_m *Forge) Branches(ctx context.Context, u *model.User, r *model.Repo) ([]string, error) {
|
||||||
ret := _m.Called(ctx, u, r)
|
ret := _m.Called(ctx, u, r)
|
||||||
|
|
||||||
var r0 []string
|
var r0 []string
|
||||||
|
@ -98,7 +98,7 @@ func (_m *Remote) Branches(ctx context.Context, u *model.User, r *model.Repo) ([
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deactivate provides a mock function with given fields: ctx, u, r, link
|
// Deactivate provides a mock function with given fields: ctx, u, r, link
|
||||||
func (_m *Remote) Deactivate(ctx context.Context, u *model.User, r *model.Repo, link string) error {
|
func (_m *Forge) Deactivate(ctx context.Context, u *model.User, r *model.Repo, link string) error {
|
||||||
ret := _m.Called(ctx, u, r, link)
|
ret := _m.Called(ctx, u, r, link)
|
||||||
|
|
||||||
var r0 error
|
var r0 error
|
||||||
|
@ -112,15 +112,15 @@ func (_m *Remote) Deactivate(ctx context.Context, u *model.User, r *model.Repo,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dir provides a mock function with given fields: ctx, u, r, b, f
|
// Dir provides a mock function with given fields: ctx, u, r, b, f
|
||||||
func (_m *Remote) Dir(ctx context.Context, u *model.User, r *model.Repo, b *model.Pipeline, f string) ([]*remote.FileMeta, error) {
|
func (_m *Forge) Dir(ctx context.Context, u *model.User, r *model.Repo, b *model.Pipeline, f string) ([]*forge.FileMeta, error) {
|
||||||
ret := _m.Called(ctx, u, r, b, f)
|
ret := _m.Called(ctx, u, r, b, f)
|
||||||
|
|
||||||
var r0 []*remote.FileMeta
|
var r0 []*forge.FileMeta
|
||||||
if rf, ok := ret.Get(0).(func(context.Context, *model.User, *model.Repo, *model.Pipeline, string) []*remote.FileMeta); ok {
|
if rf, ok := ret.Get(0).(func(context.Context, *model.User, *model.Repo, *model.Pipeline, string) []*forge.FileMeta); ok {
|
||||||
r0 = rf(ctx, u, r, b, f)
|
r0 = rf(ctx, u, r, b, f)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
r0 = ret.Get(0).([]*remote.FileMeta)
|
r0 = ret.Get(0).([]*forge.FileMeta)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ func (_m *Remote) Dir(ctx context.Context, u *model.User, r *model.Repo, b *mode
|
||||||
}
|
}
|
||||||
|
|
||||||
// File provides a mock function with given fields: ctx, u, r, b, f
|
// File provides a mock function with given fields: ctx, u, r, b, f
|
||||||
func (_m *Remote) File(ctx context.Context, u *model.User, r *model.Repo, b *model.Pipeline, f string) ([]byte, error) {
|
func (_m *Forge) File(ctx context.Context, u *model.User, r *model.Repo, b *model.Pipeline, f string) ([]byte, error) {
|
||||||
ret := _m.Called(ctx, u, r, b, f)
|
ret := _m.Called(ctx, u, r, b, f)
|
||||||
|
|
||||||
var r0 []byte
|
var r0 []byte
|
||||||
|
@ -158,7 +158,7 @@ func (_m *Remote) File(ctx context.Context, u *model.User, r *model.Repo, b *mod
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hook provides a mock function with given fields: ctx, r
|
// Hook provides a mock function with given fields: ctx, r
|
||||||
func (_m *Remote) Hook(ctx context.Context, r *http.Request) (*model.Repo, *model.Pipeline, error) {
|
func (_m *Forge) Hook(ctx context.Context, r *http.Request) (*model.Repo, *model.Pipeline, error) {
|
||||||
ret := _m.Called(ctx, r)
|
ret := _m.Called(ctx, r)
|
||||||
|
|
||||||
var r0 *model.Repo
|
var r0 *model.Repo
|
||||||
|
@ -190,7 +190,7 @@ func (_m *Remote) Hook(ctx context.Context, r *http.Request) (*model.Repo, *mode
|
||||||
}
|
}
|
||||||
|
|
||||||
// Login provides a mock function with given fields: ctx, w, r
|
// Login provides a mock function with given fields: ctx, w, r
|
||||||
func (_m *Remote) Login(ctx context.Context, w http.ResponseWriter, r *http.Request) (*model.User, error) {
|
func (_m *Forge) Login(ctx context.Context, w http.ResponseWriter, r *http.Request) (*model.User, error) {
|
||||||
ret := _m.Called(ctx, w, r)
|
ret := _m.Called(ctx, w, r)
|
||||||
|
|
||||||
var r0 *model.User
|
var r0 *model.User
|
||||||
|
@ -213,7 +213,7 @@ func (_m *Remote) Login(ctx context.Context, w http.ResponseWriter, r *http.Requ
|
||||||
}
|
}
|
||||||
|
|
||||||
// Name provides a mock function with given fields:
|
// Name provides a mock function with given fields:
|
||||||
func (_m *Remote) Name() string {
|
func (_m *Forge) Name() string {
|
||||||
ret := _m.Called()
|
ret := _m.Called()
|
||||||
|
|
||||||
var r0 string
|
var r0 string
|
||||||
|
@ -227,7 +227,7 @@ func (_m *Remote) Name() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Netrc provides a mock function with given fields: u, r
|
// Netrc provides a mock function with given fields: u, r
|
||||||
func (_m *Remote) Netrc(u *model.User, r *model.Repo) (*model.Netrc, error) {
|
func (_m *Forge) Netrc(u *model.User, r *model.Repo) (*model.Netrc, error) {
|
||||||
ret := _m.Called(u, r)
|
ret := _m.Called(u, r)
|
||||||
|
|
||||||
var r0 *model.Netrc
|
var r0 *model.Netrc
|
||||||
|
@ -250,7 +250,7 @@ func (_m *Remote) Netrc(u *model.User, r *model.Repo) (*model.Netrc, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// OrgMembership provides a mock function with given fields: ctx, u, owner
|
// OrgMembership provides a mock function with given fields: ctx, u, owner
|
||||||
func (_m *Remote) OrgMembership(ctx context.Context, u *model.User, owner string) (*model.OrgPerm, error) {
|
func (_m *Forge) OrgMembership(ctx context.Context, u *model.User, owner string) (*model.OrgPerm, error) {
|
||||||
ret := _m.Called(ctx, u, owner)
|
ret := _m.Called(ctx, u, owner)
|
||||||
|
|
||||||
var r0 *model.OrgPerm
|
var r0 *model.OrgPerm
|
||||||
|
@ -273,7 +273,7 @@ func (_m *Remote) OrgMembership(ctx context.Context, u *model.User, owner string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perm provides a mock function with given fields: ctx, u, r
|
// Perm provides a mock function with given fields: ctx, u, r
|
||||||
func (_m *Remote) Perm(ctx context.Context, u *model.User, r *model.Repo) (*model.Perm, error) {
|
func (_m *Forge) Perm(ctx context.Context, u *model.User, r *model.Repo) (*model.Perm, error) {
|
||||||
ret := _m.Called(ctx, u, r)
|
ret := _m.Called(ctx, u, r)
|
||||||
|
|
||||||
var r0 *model.Perm
|
var r0 *model.Perm
|
||||||
|
@ -296,11 +296,11 @@ func (_m *Remote) Perm(ctx context.Context, u *model.User, r *model.Repo) (*mode
|
||||||
}
|
}
|
||||||
|
|
||||||
// Repo provides a mock function with given fields: ctx, u, id, owner, name
|
// Repo provides a mock function with given fields: ctx, u, id, owner, name
|
||||||
func (_m *Remote) Repo(ctx context.Context, u *model.User, id model.RemoteID, owner string, name string) (*model.Repo, error) {
|
func (_m *Forge) Repo(ctx context.Context, u *model.User, id model.ForgeID, owner string, name string) (*model.Repo, error) {
|
||||||
ret := _m.Called(ctx, u, id, owner, name)
|
ret := _m.Called(ctx, u, id, owner, name)
|
||||||
|
|
||||||
var r0 *model.Repo
|
var r0 *model.Repo
|
||||||
if rf, ok := ret.Get(0).(func(context.Context, *model.User, model.RemoteID, string, string) *model.Repo); ok {
|
if rf, ok := ret.Get(0).(func(context.Context, *model.User, model.ForgeID, string, string) *model.Repo); ok {
|
||||||
r0 = rf(ctx, u, id, owner, name)
|
r0 = rf(ctx, u, id, owner, name)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
|
@ -309,7 +309,7 @@ func (_m *Remote) Repo(ctx context.Context, u *model.User, id model.RemoteID, ow
|
||||||
}
|
}
|
||||||
|
|
||||||
var r1 error
|
var r1 error
|
||||||
if rf, ok := ret.Get(1).(func(context.Context, *model.User, model.RemoteID, string, string) error); ok {
|
if rf, ok := ret.Get(1).(func(context.Context, *model.User, model.ForgeID, string, string) error); ok {
|
||||||
r1 = rf(ctx, u, id, owner, name)
|
r1 = rf(ctx, u, id, owner, name)
|
||||||
} else {
|
} else {
|
||||||
r1 = ret.Error(1)
|
r1 = ret.Error(1)
|
||||||
|
@ -319,7 +319,7 @@ func (_m *Remote) Repo(ctx context.Context, u *model.User, id model.RemoteID, ow
|
||||||
}
|
}
|
||||||
|
|
||||||
// Repos provides a mock function with given fields: ctx, u
|
// Repos provides a mock function with given fields: ctx, u
|
||||||
func (_m *Remote) Repos(ctx context.Context, u *model.User) ([]*model.Repo, error) {
|
func (_m *Forge) Repos(ctx context.Context, u *model.User) ([]*model.Repo, error) {
|
||||||
ret := _m.Called(ctx, u)
|
ret := _m.Called(ctx, u)
|
||||||
|
|
||||||
var r0 []*model.Repo
|
var r0 []*model.Repo
|
||||||
|
@ -342,7 +342,7 @@ func (_m *Remote) Repos(ctx context.Context, u *model.User) ([]*model.Repo, erro
|
||||||
}
|
}
|
||||||
|
|
||||||
// Status provides a mock function with given fields: ctx, u, r, b, p
|
// Status provides a mock function with given fields: ctx, u, r, b, p
|
||||||
func (_m *Remote) Status(ctx context.Context, u *model.User, r *model.Repo, b *model.Pipeline, p *model.Step) error {
|
func (_m *Forge) Status(ctx context.Context, u *model.User, r *model.Repo, b *model.Pipeline, p *model.Step) error {
|
||||||
ret := _m.Called(ctx, u, r, b, p)
|
ret := _m.Called(ctx, u, r, b, p)
|
||||||
|
|
||||||
var r0 error
|
var r0 error
|
||||||
|
@ -356,7 +356,7 @@ func (_m *Remote) Status(ctx context.Context, u *model.User, r *model.Repo, b *m
|
||||||
}
|
}
|
||||||
|
|
||||||
// Teams provides a mock function with given fields: ctx, u
|
// Teams provides a mock function with given fields: ctx, u
|
||||||
func (_m *Remote) Teams(ctx context.Context, u *model.User) ([]*model.Team, error) {
|
func (_m *Forge) Teams(ctx context.Context, u *model.User) ([]*model.Team, error) {
|
||||||
ret := _m.Called(ctx, u)
|
ret := _m.Called(ctx, u)
|
||||||
|
|
||||||
var r0 []*model.Team
|
var r0 []*model.Team
|
||||||
|
@ -378,14 +378,14 @@ func (_m *Remote) Teams(ctx context.Context, u *model.User) ([]*model.Team, erro
|
||||||
return r0, r1
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
type mockConstructorTestingTNewRemote interface {
|
type mockConstructorTestingTNewForge interface {
|
||||||
mock.TestingT
|
mock.TestingT
|
||||||
Cleanup(func())
|
Cleanup(func())
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRemote creates a new instance of Remote. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
// NewForge creates a new instance of Forge. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||||
func NewRemote(t mockConstructorTestingTNewRemote) *Remote {
|
func NewForge(t mockConstructorTestingTNewForge) *Forge {
|
||||||
mock := &Remote{}
|
mock := &Forge{}
|
||||||
mock.Mock.Test(t)
|
mock.Mock.Test(t)
|
||||||
|
|
||||||
t.Cleanup(func() { mock.AssertExpectations(t) })
|
t.Cleanup(func() { mock.AssertExpectations(t) })
|
|
@ -13,10 +13,10 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package remote
|
package forge
|
||||||
|
|
||||||
//go:generate go install github.com/vektra/mockery/v2@latest
|
//go:generate go install github.com/vektra/mockery/v2@latest
|
||||||
//go:generate mockery --name Remote --output mocks --case underscore
|
//go:generate mockery --name Forge --output mocks --case underscore
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -28,44 +28,44 @@ import (
|
||||||
// TODO: use pagination
|
// TODO: use pagination
|
||||||
// TODO: add Driver() who return source forge back
|
// TODO: add Driver() who return source forge back
|
||||||
|
|
||||||
type Remote interface {
|
type Forge interface {
|
||||||
// Name returns the string name of this driver
|
// Name returns the string name of this driver
|
||||||
Name() string
|
Name() string
|
||||||
|
|
||||||
// Login authenticates the session and returns the
|
// Login authenticates the session and returns the
|
||||||
// remote user details.
|
// forge user details.
|
||||||
Login(ctx context.Context, w http.ResponseWriter, r *http.Request) (*model.User, error)
|
Login(ctx context.Context, w http.ResponseWriter, r *http.Request) (*model.User, error)
|
||||||
|
|
||||||
// Auth authenticates the session and returns the remote user
|
// Auth authenticates the session and returns the forge user
|
||||||
// login for the given token and secret
|
// login for the given token and secret
|
||||||
Auth(ctx context.Context, token, secret string) (string, error)
|
Auth(ctx context.Context, token, secret string) (string, error)
|
||||||
|
|
||||||
// Teams fetches a list of team memberships from the remote system.
|
// Teams fetches a list of team memberships from the forge.
|
||||||
Teams(ctx context.Context, u *model.User) ([]*model.Team, error)
|
Teams(ctx context.Context, u *model.User) ([]*model.Team, error)
|
||||||
|
|
||||||
// Repo fetches the repository from the remote system, preferred is using the ID, fallback is owner/name.
|
// Repo fetches the repository from the forge, preferred is using the ID, fallback is owner/name.
|
||||||
Repo(ctx context.Context, u *model.User, id model.RemoteID, owner, name string) (*model.Repo, error)
|
Repo(ctx context.Context, u *model.User, id model.ForgeID, owner, name string) (*model.Repo, error)
|
||||||
|
|
||||||
// Repos fetches a list of repos from the remote system.
|
// Repos fetches a list of repos from the forge.
|
||||||
Repos(ctx context.Context, u *model.User) ([]*model.Repo, error)
|
Repos(ctx context.Context, u *model.User) ([]*model.Repo, error)
|
||||||
|
|
||||||
// Perm fetches the named repository permissions from
|
// Perm fetches the named repository permissions from
|
||||||
// the remote system for the specified user.
|
// the forge for the specified user.
|
||||||
Perm(ctx context.Context, u *model.User, r *model.Repo) (*model.Perm, error)
|
Perm(ctx context.Context, u *model.User, r *model.Repo) (*model.Perm, error)
|
||||||
|
|
||||||
// File fetches a file from the remote repository and returns in string
|
// File fetches a file from the forge repository and returns in string
|
||||||
// format.
|
// format.
|
||||||
File(ctx context.Context, u *model.User, r *model.Repo, b *model.Pipeline, f string) ([]byte, error)
|
File(ctx context.Context, u *model.User, r *model.Repo, b *model.Pipeline, f string) ([]byte, error)
|
||||||
|
|
||||||
// Dir fetches a folder from the remote repository
|
// Dir fetches a folder from the forge repository
|
||||||
Dir(ctx context.Context, u *model.User, r *model.Repo, b *model.Pipeline, f string) ([]*FileMeta, error)
|
Dir(ctx context.Context, u *model.User, r *model.Repo, b *model.Pipeline, f string) ([]*FileMeta, error)
|
||||||
|
|
||||||
// Status sends the commit status to the remote system.
|
// Status sends the commit status to the forge.
|
||||||
// An example would be the GitHub pull request status.
|
// An example would be the GitHub pull request status.
|
||||||
Status(ctx context.Context, u *model.User, r *model.Repo, b *model.Pipeline, p *model.Step) error
|
Status(ctx context.Context, u *model.User, r *model.Repo, b *model.Pipeline, p *model.Step) error
|
||||||
|
|
||||||
// Netrc returns a .netrc file that can be used to clone
|
// Netrc returns a .netrc file that can be used to clone
|
||||||
// private repositories from a remote system.
|
// private repositories from a forge.
|
||||||
Netrc(u *model.User, r *model.Repo) (*model.Netrc, error)
|
Netrc(u *model.User, r *model.Repo) (*model.Netrc, error)
|
||||||
|
|
||||||
// Activate activates a repository by creating the post-commit hook.
|
// Activate activates a repository by creating the post-commit hook.
|
||||||
|
@ -76,7 +76,7 @@ type Remote interface {
|
||||||
Deactivate(ctx context.Context, u *model.User, r *model.Repo, link string) error
|
Deactivate(ctx context.Context, u *model.User, r *model.Repo, link string) error
|
||||||
|
|
||||||
// Branches returns the names of all branches for the named repository.
|
// Branches returns the names of all branches for the named repository.
|
||||||
// TODO: Add proper pagination handling and remove workaround in gitea remote
|
// TODO: Add proper pagination handling and remove workaround in gitea forge
|
||||||
Branches(ctx context.Context, u *model.User, r *model.Repo) ([]string, error)
|
Branches(ctx context.Context, u *model.User, r *model.Repo) ([]string, error)
|
||||||
|
|
||||||
// BranchHead returns the sha of the head (lastest commit) of the specified branch
|
// BranchHead returns the sha of the head (lastest commit) of the specified branch
|
|
@ -32,17 +32,17 @@ import (
|
||||||
|
|
||||||
"github.com/woodpecker-ci/woodpecker/pipeline/rpc"
|
"github.com/woodpecker-ci/woodpecker/pipeline/rpc"
|
||||||
"github.com/woodpecker-ci/woodpecker/server"
|
"github.com/woodpecker-ci/woodpecker/server"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/logging"
|
"github.com/woodpecker-ci/woodpecker/server/logging"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/pubsub"
|
"github.com/woodpecker-ci/woodpecker/server/pubsub"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/queue"
|
"github.com/woodpecker-ci/woodpecker/server/queue"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote"
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server/shared"
|
"github.com/woodpecker-ci/woodpecker/server/shared"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/store"
|
"github.com/woodpecker-ci/woodpecker/server/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RPC struct {
|
type RPC struct {
|
||||||
remote remote.Remote
|
forge forge.Forge
|
||||||
queue queue.Queue
|
queue queue.Queue
|
||||||
pubsub pubsub.Publisher
|
pubsub pubsub.Publisher
|
||||||
logger logging.Log
|
logger logging.Log
|
||||||
|
@ -351,7 +351,7 @@ func (s *RPC) Done(c context.Context, id string, state rpc.State) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s.updateRemoteStatus(c, repo, pipeline, step)
|
s.updateForgeStatus(c, repo, pipeline, step)
|
||||||
|
|
||||||
if err := s.logger.Close(c, id); err != nil {
|
if err := s.logger.Close(c, id); err != nil {
|
||||||
log.Error().Err(err).Msgf("done: cannot close build_id %d logger", step.ID)
|
log.Error().Err(err).Msgf("done: cannot close build_id %d logger", step.ID)
|
||||||
|
@ -392,14 +392,14 @@ func (s *RPC) completeChildrenIfParentCompleted(steps []*model.Step, completedSt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *RPC) updateRemoteStatus(ctx context.Context, repo *model.Repo, pipeline *model.Pipeline, step *model.Step) {
|
func (s *RPC) updateForgeStatus(ctx context.Context, repo *model.Repo, pipeline *model.Pipeline, step *model.Step) {
|
||||||
user, err := s.store.GetUser(repo.UserID)
|
user, err := s.store.GetUser(repo.UserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msgf("can not get user with id '%d'", repo.UserID)
|
log.Error().Err(err).Msgf("can not get user with id '%d'", repo.UserID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if refresher, ok := s.remote.(remote.Refresher); ok {
|
if refresher, ok := s.forge.(forge.Refresher); ok {
|
||||||
ok, err := refresher.Refresh(ctx, user)
|
ok, err := refresher.Refresh(ctx, user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msgf("grpc: refresh oauth token of user '%s' failed", user.Login)
|
log.Error().Err(err).Msgf("grpc: refresh oauth token of user '%s' failed", user.Login)
|
||||||
|
@ -412,7 +412,7 @@ func (s *RPC) updateRemoteStatus(ctx context.Context, repo *model.Repo, pipeline
|
||||||
|
|
||||||
// only do status updates for parent steps
|
// only do status updates for parent steps
|
||||||
if step != nil && step.IsParent() {
|
if step != nil && step.IsParent() {
|
||||||
err = s.remote.Status(ctx, user, repo, pipeline, step)
|
err = s.forge.Status(ctx, user, repo, pipeline, step)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msgf("error setting commit status for %s/%d", repo.FullName, pipeline.Number)
|
log.Error().Err(err).Msgf("error setting commit status for %s/%d", repo.FullName, pipeline.Number)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,10 +23,10 @@ import (
|
||||||
|
|
||||||
"github.com/woodpecker-ci/woodpecker/pipeline/rpc"
|
"github.com/woodpecker-ci/woodpecker/pipeline/rpc"
|
||||||
"github.com/woodpecker-ci/woodpecker/pipeline/rpc/proto"
|
"github.com/woodpecker-ci/woodpecker/pipeline/rpc/proto"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/forge"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/logging"
|
"github.com/woodpecker-ci/woodpecker/server/logging"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/pubsub"
|
"github.com/woodpecker-ci/woodpecker/server/pubsub"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/queue"
|
"github.com/woodpecker-ci/woodpecker/server/queue"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/remote"
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server/store"
|
"github.com/woodpecker-ci/woodpecker/server/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ type WoodpeckerServer struct {
|
||||||
peer RPC
|
peer RPC
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWoodpeckerServer(remote remote.Remote, queue queue.Queue, logger logging.Log, pubsub pubsub.Publisher, store store.Store, host string) *WoodpeckerServer {
|
func NewWoodpeckerServer(forge forge.Forge, queue queue.Queue, logger logging.Log, pubsub pubsub.Publisher, store store.Store, host string) *WoodpeckerServer {
|
||||||
pipelineTime := promauto.NewGaugeVec(prometheus.GaugeOpts{
|
pipelineTime := promauto.NewGaugeVec(prometheus.GaugeOpts{
|
||||||
Namespace: "woodpecker",
|
Namespace: "woodpecker",
|
||||||
Name: "pipeline_time",
|
Name: "pipeline_time",
|
||||||
|
@ -48,7 +48,7 @@ func NewWoodpeckerServer(remote remote.Remote, queue queue.Queue, logger logging
|
||||||
Help: "Pipeline count.",
|
Help: "Pipeline count.",
|
||||||
}, []string{"repo", "branch", "status", "pipeline"})
|
}, []string{"repo", "branch", "status", "pipeline"})
|
||||||
peer := RPC{
|
peer := RPC{
|
||||||
remote: remote,
|
forge: forge,
|
||||||
store: store,
|
store: store,
|
||||||
queue: queue,
|
queue: queue,
|
||||||
pubsub: pubsub,
|
pubsub: pubsub,
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue