1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-12-24 10:07:21 +02:00

Rename remote to forge (#1357)

As of #745

Co-authored-by: Anbraten <anton@ju60.de>
This commit is contained in:
qwerty287 2022-11-05 00:35:06 +01:00 committed by GitHub
parent 2ee75dbceb
commit 3372d1a87c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
135 changed files with 750 additions and 698 deletions

View File

@ -240,10 +240,10 @@ func metadataFromContext(c *cli.Context, axis matrix.Axis) frontend.Metadata {
return frontend.Metadata{
Repo: frontend.Repo{
Name: c.String("repo-name"),
Link: c.String("repo-link"),
Remote: c.String("repo-remote-url"),
Private: c.Bool("repo-private"),
Name: c.String("repo-name"),
Link: c.String("repo-link"),
CloneURL: c.String("repo-clone-url"),
Private: c.Bool("repo-private"),
},
Curr: frontend.Pipeline{
Number: c.Int64("pipeline-number"),

View File

@ -123,8 +123,8 @@ var flags = []cli.Flag{
Name: "repo-link",
},
&cli.StringFlag{
EnvVars: []string{"CI_REPO_REMOTE"},
Name: "repo-remote-url",
EnvVars: []string{"CI_REPO_CLONE_URL", "CI_REPO_REMOTE"},
Name: "repo-clone-url",
},
&cli.StringFlag{
EnvVars: []string{"CI_REPO_PRIVATE"},

View File

@ -53,5 +53,5 @@ Visibility: {{ .Visibility }}
Private: {{ .IsSCMPrivate }}
Trusted: {{ .IsTrusted }}
Gated: {{ .IsGated }}
Remote: {{ .Clone }}
Forge: {{ .Clone }}
`

View File

@ -521,7 +521,7 @@ var flags = []cli.Flag{
&cli.BoolFlag{
EnvVars: []string{"WOODPECKER_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,
// TODO(485) temporary workaround to not hit api rate limits
},

View File

@ -39,12 +39,12 @@ import (
"github.com/woodpecker-ci/woodpecker/pipeline/rpc/proto"
"github.com/woodpecker-ci/woodpecker/server"
"github.com/woodpecker-ci/woodpecker/server/cron"
"github.com/woodpecker-ci/woodpecker/server/forge"
woodpeckerGrpcServer "github.com/woodpecker-ci/woodpecker/server/grpc"
"github.com/woodpecker-ci/woodpecker/server/logging"
"github.com/woodpecker-ci/woodpecker/server/model"
"github.com/woodpecker-ci/woodpecker/server/plugins/config"
"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/middleware"
"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 {
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
setupMetrics(&g, _store)
g.Go(func() error {
return cron.Start(c.Context, _store, _remote)
return cron.Start(c.Context, _store, _forge)
})
// start the grpc server
@ -144,7 +144,7 @@ func run(c *cli.Context) error {
}),
)
woodpeckerServer := woodpeckerGrpcServer.NewWoodpeckerServer(
_remote,
_forge,
server.Config.Services.Queue,
server.Config.Services.Logs,
server.Config.Services.Pubsub,
@ -253,12 +253,12 @@ func run(c *cli.Context) error {
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
server.Config.Storage.Files = v
// remote
server.Config.Services.Remote = r
// forge
server.Config.Services.Forge = f
// services
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.Secrets = setupSecretService(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)

View File

@ -36,19 +36,19 @@ import (
"github.com/woodpecker-ci/woodpecker/server"
"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/plugins/environments"
"github.com/woodpecker-ci/woodpecker/server/plugins/registry"
"github.com/woodpecker-ci/woodpecker/server/plugins/secrets"
"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/datastore"
"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"))
}
func setupMembershipService(_ *cli.Context, r remote.Remote) cache.MembershipService {
func setupMembershipService(_ *cli.Context, r forge.Forge) cache.MembershipService {
return cache.NewMembershipService(r)
}
// setupRemote helper function to setup the remote from the CLI arguments.
func setupRemote(c *cli.Context) (remote.Remote, error) {
// setupForge helper function to setup the forge from the CLI arguments.
func setupForge(c *cli.Context) (forge.Forge, error) {
switch {
case c.Bool("github"):
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.
func setupBitbucket(c *cli.Context) (remote.Remote, error) {
// helper function to setup the Bitbucket forge from the CLI arguments.
func setupBitbucket(c *cli.Context) (forge.Forge, error) {
opts := &bitbucket.Opts{
Client: c.String("bitbucket-client"),
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)
}
// helper function to setup the Gogs remote from the CLI arguments.
func setupGogs(c *cli.Context) (remote.Remote, error) {
// helper function to setup the Gogs forge from the CLI arguments.
func setupGogs(c *cli.Context) (forge.Forge, error) {
opts := gogs.Opts{
URL: c.String("gogs-server"),
Username: c.String("gogs-git-username"),
@ -227,12 +227,12 @@ func setupGogs(c *cli.Context) (remote.Remote, error) {
PrivateMode: c.Bool("gogs-private-mode"),
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)
}
// helper function to setup the Gitea remote from the CLI arguments.
func setupGitea(c *cli.Context) (remote.Remote, error) {
// helper function to setup the Gitea forge from the CLI arguments.
func setupGitea(c *cli.Context) (forge.Forge, error) {
server, err := url.Parse(c.String("gitea-server"))
if err != nil {
return nil, err
@ -246,12 +246,12 @@ func setupGitea(c *cli.Context) (remote.Remote, error) {
if len(opts.URL) == 0 {
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)
}
// helper function to setup the Stash remote from the CLI arguments.
func setupStash(c *cli.Context) (remote.Remote, error) {
// helper function to setup the Stash forge from the CLI arguments.
func setupStash(c *cli.Context) (forge.Forge, error) {
opts := bitbucketserver.Opts{
URL: c.String("stash-server"),
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"),
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)
}
// helper function to setup the Gitlab remote from the CLI arguments.
func setupGitlab(c *cli.Context) (remote.Remote, error) {
// helper function to setup the Gitlab forge from the CLI arguments.
func setupGitlab(c *cli.Context) (forge.Forge, error) {
return gitlab.New(gitlab.Opts{
URL: c.String("gitlab-server"),
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.
func setupGithub(c *cli.Context) (remote.Remote, error) {
// helper function to setup the GitHub forge from the CLI arguments.
func setupGithub(c *cli.Context) (forge.Forge, error) {
opts := github.Opts{
URL: c.String("github-server"),
Client: c.String("github-client"),
@ -284,12 +284,12 @@ func setupGithub(c *cli.Context) (remote.Remote, error) {
SkipVerify: c.Bool("github-skip-verify"),
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)
}
// helper function to setup the Coding remote from the CLI arguments.
func setupCoding(c *cli.Context) (remote.Remote, error) {
// helper function to setup the Coding forge from the CLI arguments.
func setupCoding(c *cli.Context) (forge.Forge, error) {
opts := coding.Opts{
URL: c.String("coding-server"),
Client: c.String("coding-client"),
@ -299,7 +299,7 @@ func setupCoding(c *cli.Context) (remote.Remote, error) {
Password: c.String("coding-git-password"),
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)
}

View File

@ -10,7 +10,7 @@ The Multi-Pipeline feature allows the pipeline to be split into several files an
## 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
- utilizing more agents to speed up build

View File

@ -55,7 +55,7 @@ This is the reference list of all environment variables available to your pipeli
| `CI_REPO_NAME` | repository name |
| `CI_REPO_SCM` | repository SCM (git) |
| `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_PRIVATE` | repository is private |
| `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_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_LINK` | commit link in remote |
| `CI_COMMIT_LINK` | commit link in forge |
| `CI_COMMIT_MESSAGE` | commit message |
| `CI_COMMIT_AUTHOR` | commit author username |
| `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_SOURCE_BRANCH` | previous commit source 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_AUTHOR` | previous commit author username |
| `CI_PREV_COMMIT_AUTHOR_EMAIL` | previous commit author email address |

View File

@ -69,7 +69,7 @@ WOODPECKER_CONFIG_SERVICE_ENDPOINT=https://example.com/ciconfig
"parent": 0,
"ref": "refs/heads/master",
"refspec": "",
"remote": "",
"clone_url": "",
"reviewed_at": 0,
"reviewed_by": "",
"sender": "myUser",

View File

@ -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 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 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
- Updated Prometheus gauge `build_*` to `pipeline_*`
- Updated Prometheus gauge `*_job_*` to `*_step_*`

View File

@ -19,23 +19,23 @@
### Server
| 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/badges/**` | generate svg badges 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/logging/**` | logging lib for gPRC server to stream logs while running | std
| `server/model/**` | structs for store (db) and api (json) | std
| `server/plugins/**` | plugins for server | `../model`, `../remote`
| `server/pipeline/**`| orchestrate pipelines | `pipeline`, `../model`, `../pubsub`, `../queue`, `../remote`, `../store`, `../plugins`
| `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/remote/**` | remote 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/store/**` | handle database | `server/model`
| `server/shared/**` | TODO: move and split [#974](https://github.com/woodpecker-ci/woodpecker/issues/974) |
| `server/web/**` | server SPA |
| package | meaning | imports
|----------------------|-------------------------------------------------------------------------------------|----------
| `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/ccmenu/**` | generate xml ccmenu for pipelines | `../model`
| `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/model/**` | structs for store (db) and api (json) | std
| `server/plugins/**` | plugins for server | `../model`, `../forge`
| `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/queue/**` | queue lib for server where agents pull new pipelines from via gRPC | `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`, `../forge`, `../store`, `../web`
| `server/store/**` | handle database | `server/model`
| `server/shared/**` | TODO: move and split [#974](https://github.com/woodpecker-ci/woodpecker/issues/974) |
| `server/web/**` | server SPA |
* `../` = `server/`

View File

@ -51,8 +51,8 @@ func (m *Metadata) setDroneEnviron(env map[string]string) {
env["DRONE_REPO_BRANCH"] = env["CI_REPO_DEFAULT_BRANCH"]
env["DRONE_REPO_PRIVATE"] = env["CI_REPO_PRIVATE"]
// clone
env["DRONE_REMOTE_URL"] = env["CI_REPO_REMOTE"]
env["DRONE_GIT_HTTP_URL"] = env["CI_REPO_REMOTE"]
env["DRONE_REMOTE_URL"] = env["CI_REPO_CLONE_URL"]
env["DRONE_GIT_HTTP_URL"] = env["CI_REPO_CLONE_URL"]
// misc
env["DRONE_SYSTEM_HOST"] = env["CI_SYSTEM_HOST"]
env["DRONE_STEP_NUMBER"] = env["CI_STEP_NUMBER"]

View File

@ -45,12 +45,12 @@ type (
// Repo defines runtime metadata for a repository.
Repo struct {
Name string `json:"name,omitempty"`
Link string `json:"link,omitempty"`
Remote string `json:"remote,omitempty"`
Private bool `json:"private,omitempty"`
Secrets []Secret `json:"secrets,omitempty"`
Branch string `json:"default_branch,omitempty"`
Name string `json:"name,omitempty"`
Link string `json:"link,omitempty"`
CloneURL string `json:"clone_url,omitempty"`
Private bool `json:"private,omitempty"`
Secrets []Secret `json:"secrets,omitempty"`
Branch string `json:"default_branch,omitempty"`
}
// Pipeline defines runtime metadata for a pipeline.
@ -142,7 +142,7 @@ func (m *Metadata) Environ() map[string]string {
"CI_REPO_NAME": repoName,
"CI_REPO_SCM": "git",
"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_PRIVATE": strconv.FormatBool(m.Repo.Private),
"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_STARTED": "", // 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 {
params["CI_COMMIT_TAG"] = strings.TrimPrefix(m.Curr.Commit.Ref, "refs/tags/")

View File

@ -100,10 +100,10 @@ func TestWithPrefix(t *testing.T) {
func TestWithMetadata(t *testing.T) {
metadata := frontend.Metadata{
Repo: frontend.Repo{
Name: "octocat/hello-world",
Private: true,
Link: "https://github.com/octocat/hello-world",
Remote: "https://github.com/octocat/hello-world.git",
Name: "octocat/hello-world",
Private: true,
Link: "https://github.com/octocat/hello-world",
CloneURL: "https://github.com/octocat/hello-world.git",
},
}
compiler := New(
@ -119,8 +119,8 @@ func TestWithMetadata(t *testing.T) {
if compiler.env["CI_REPO_LINK"] != metadata.Repo.Link {
t.Errorf("WithMetadata must set CI_REPO_LINK")
}
if compiler.env["CI_REPO_REMOTE"] != metadata.Repo.Remote {
t.Errorf("WithMetadata must set CI_REPO_REMOTE")
if compiler.env["CI_REPO_CLONE_URL"] != metadata.Repo.CloneURL {
t.Errorf("WithMetadata must set CI_REPO_CLONE_URL")
}
}

View File

@ -62,7 +62,7 @@ func RunCron(c *gin.Context) {
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 {
c.String(http.StatusInternalServerError, "Error creating pipeline for cron %q. %s", id, err)
return
@ -82,7 +82,7 @@ func PostCron(c *gin.Context) {
repo := session.Repo(c)
user := session.User(c)
store := store.FromContext(c)
remote := server.Config.Services.Remote
forge := server.Config.Services.Forge
in := new(model.Cron)
if err := c.Bind(in); err != nil {
@ -109,8 +109,8 @@ func PostCron(c *gin.Context) {
cron.NextExec = nextExec.Unix()
if in.Branch != "" {
// check if branch exists on remote
_, err := remote.BranchHead(c, user, repo, in.Branch)
// check if branch exists on forge
_, err := forge.BranchHead(c, user, repo, in.Branch)
if err != nil {
c.String(400, "Error inserting cron. branch not resolved: %s", err)
return
@ -129,7 +129,7 @@ func PatchCron(c *gin.Context) {
repo := session.Repo(c)
user := session.User(c)
store := store.FromContext(c)
remote := server.Config.Services.Remote
forge := server.Config.Services.Forge
id, err := strconv.ParseInt(c.Param("cron"), 10, 64)
if err != nil {
@ -150,8 +150,8 @@ func PatchCron(c *gin.Context) {
return
}
if in.Branch != "" {
// check if branch exists on remote
_, err := remote.BranchHead(c, user, repo, in.Branch)
// check if branch exists on forge
_, err := forge.BranchHead(c, user, repo, in.Branch)
if err != nil {
c.String(400, "Error inserting cron. branch not resolved: %s", err)
return

View File

@ -21,9 +21,9 @@ import (
"github.com/rs/zerolog/log"
"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/pipeline"
"github.com/woodpecker-ci/woodpecker/server/remote"
"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.
func refreshUserToken(c *gin.Context, user *model.User) {
_remote := server.Config.Services.Remote
_forge := server.Config.Services.Forge
_store := store.FromContext(c)
if refresher, ok := _remote.(remote.Refresher); ok {
if refresher, ok := _forge.(forge.Refresher); ok {
ok, err := refresher.Refresh(c, user)
if err != nil {
log.Error().Err(err).Msgf("refresh oauth token of user '%s' failed", user.Login)

View File

@ -70,9 +70,9 @@ func BlockTilQueueHasRunningItem(c *gin.Context) {
// PostHook start a pipeline triggered by a forges post webhook
func PostHook(c *gin.Context) {
_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 {
msg := "failure to parse hook"
log.Debug().Err(err).Msg(msg)
@ -102,7 +102,7 @@ func PostHook(c *gin.Context) {
return
}
repo, err := _store.GetRepoNameFallback(tmpRepo.RemoteID, tmpRepo.FullName)
repo, err := _store.GetRepoNameFallback(tmpRepo.ForgeID, tmpRepo.FullName)
if err != nil {
msg := fmt.Sprintf("failure to get repo %s from store", tmpRepo.FullName)
log.Error().Err(err).Msg(msg)

View File

@ -49,13 +49,13 @@ func HandleAuth(c *gin.Context) {
// cannot, however, remember why, so need to revisit this line.
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 {
log.Error().Msgf("cannot authenticate user. %s", err)
c.Redirect(303, "/login?error=oauth_error")
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.
if tmpuser == nil {
return
@ -75,7 +75,7 @@ func HandleAuth(c *gin.Context) {
// if self-registration is enabled for whitelisted organizations we need to
// check the user's organization membership.
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) {
log.Error().Msgf("cannot verify team membership for %s.", u.Login)
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
// check the user's organization membership.
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) {
log.Error().Msgf("cannot verify team membership for %s.", u.Login)
c.Redirect(303, "/login?error=access_denied")
@ -155,7 +155,7 @@ func GetLoginToken(c *gin.Context) {
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 {
_ = c.AbortWithError(http.StatusUnauthorized, err)
return

View File

@ -54,7 +54,7 @@ func CreatePipeline(c *gin.Context) {
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)

View File

@ -39,7 +39,7 @@ const (
)
func PostRepo(c *gin.Context) {
remote := server.Config.Services.Remote
forge := server.Config.Services.Forge
_store := store.FromContext(c)
user := session.User(c)
repo := session.Repo(c)
@ -87,7 +87,7 @@ func PostRepo(c *gin.Context) {
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 repo.FullName != from.FullName {
// create a redirection
@ -100,7 +100,7 @@ func PostRepo(c *gin.Context) {
repo.Update(from)
}
err = remote.Activate(c, user, repo, link)
err = forge.Activate(c, user, repo, link)
if err != nil {
c.String(http.StatusInternalServerError, err.Error())
return
@ -198,9 +198,9 @@ func GetRepoPermissions(c *gin.Context) {
func GetRepoBranches(c *gin.Context) {
repo := session.Repo(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 {
_ = c.AbortWithError(http.StatusInternalServerError, err)
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)
return
}
@ -239,7 +239,7 @@ func DeleteRepo(c *gin.Context) {
}
func RepairRepo(c *gin.Context) {
remote := server.Config.Services.Remote
forge := server.Config.Services.Forge
_store := store.FromContext(c)
repo := session.Repo(c)
user := session.User(c)
@ -260,9 +260,9 @@ func RepairRepo(c *gin.Context) {
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 {
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)
return
}
@ -282,10 +282,10 @@ func RepairRepo(c *gin.Context) {
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)
}
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())
return
}
@ -294,7 +294,7 @@ func RepairRepo(c *gin.Context) {
}
func MoveRepo(c *gin.Context) {
remote := server.Config.Services.Remote
forge := server.Config.Services.Forge
_store := store.FromContext(c)
repo := session.Repo(c)
user := session.User(c)
@ -312,7 +312,7 @@ func MoveRepo(c *gin.Context) {
return
}
from, err := remote.Repo(c, user, "", owner, name)
from, err := forge.Repo(c, user, "", owner, name)
if err != nil {
_ = c.AbortWithError(http.StatusInternalServerError, err)
return
@ -352,10 +352,10 @@ func MoveRepo(c *gin.Context) {
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)
}
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())
return
}

View File

@ -38,7 +38,7 @@ func GetSelf(c *gin.Context) {
func GetFeed(c *gin.Context) {
_store := store.FromContext(c)
remote := server.Config.Services.Remote
forge := server.Config.Services.Forge
user := session.User(c)
latest, _ := strconv.ParseBool(c.Query("latest"))
@ -55,10 +55,10 @@ func GetFeed(c *gin.Context) {
config := ToConfig(c)
sync := shared.Syncer{
Remote: remote,
Store: _store,
Perms: _store,
Match: shared.NamespaceFilter(config.OwnersWhitelist),
Forge: forge,
Store: _store,
Perms: _store,
Match: shared.NamespaceFilter(config.OwnersWhitelist),
}
if err := sync.Sync(c, user, server.Config.FlatPermissions); err != nil {
log.Debug().Msgf("sync error: %s: %s", user.Login, err)
@ -87,7 +87,7 @@ func GetFeed(c *gin.Context) {
func GetRepos(c *gin.Context) {
_store := store.FromContext(c)
remote := server.Config.Services.Remote
forge := server.Config.Services.Forge
user := session.User(c)
all, _ := strconv.ParseBool(c.Query("all"))
@ -104,10 +104,10 @@ func GetRepos(c *gin.Context) {
config := ToConfig(c)
sync := shared.Syncer{
Remote: remote,
Store: _store,
Perms: _store,
Match: shared.NamespaceFilter(config.OwnersWhitelist),
Forge: forge,
Store: _store,
Perms: _store,
Match: shared.NamespaceFilter(config.OwnersWhitelist),
}
if err := sync.Sync(c, user, server.Config.FlatPermissions); err != nil {

View File

@ -18,8 +18,8 @@ import (
"context"
"time"
"github.com/woodpecker-ci/woodpecker/server/forge"
"github.com/woodpecker-ci/woodpecker/server/model"
"github.com/woodpecker-ci/woodpecker/server/remote"
"github.com/lafriks/ttlcache/v3"
)
@ -31,17 +31,17 @@ type MembershipService interface {
}
type membershipCache struct {
Remote remote.Remote
Cache *ttlcache.Cache[string, *model.OrgPerm]
TTL time.Duration
Forge forge.Forge
Cache *ttlcache.Cache[string, *model.OrgPerm]
TTL time.Duration
}
// NewMembershipService creates a new membership service.
func NewMembershipService(r remote.Remote) MembershipService {
func NewMembershipService(f forge.Forge) MembershipService {
return &membershipCache{
TTL: 10 * time.Minute,
Remote: r,
Cache: ttlcache.New(ttlcache.WithDisableTouchOnHit[string, *model.OrgPerm]()),
TTL: 10 * time.Minute,
Forge: f,
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
}
perm, err := c.Remote.OrgMembership(ctx, u, name)
perm, err := c.Forge.OrgMembership(ctx, u, name)
if err != nil {
return nil, err
}

View File

@ -22,12 +22,12 @@ import (
"time"
"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/model"
"github.com/woodpecker-ci/woodpecker/server/plugins/config"
"github.com/woodpecker-ci/woodpecker/server/pubsub"
"github.com/woodpecker-ci/woodpecker/server/queue"
"github.com/woodpecker-ci/woodpecker/server/remote"
)
var Config = struct {
@ -38,7 +38,7 @@ var Config = struct {
Secrets model.SecretService
Registries model.RegistryService
Environ model.EnvironService
Remote remote.Remote
Forge forge.Forge
Membership cache.MembershipService
ConfigService config.Extension
SignaturePrivateKey crypto.PrivateKey

View File

@ -22,9 +22,9 @@ import (
"github.com/robfig/cron"
"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/pipeline"
"github.com/woodpecker-ci/woodpecker/server/remote"
"github.com/woodpecker-ci/woodpecker/server/store"
)
@ -37,7 +37,7 @@ const (
)
// 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 {
select {
case <-ctx.Done():
@ -54,7 +54,7 @@ func Start(ctx context.Context, store store.Store, remote remote.Remote) error {
}
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")
}
}
@ -77,7 +77,7 @@ func CalcNewNext(schedule string, now time.Time) (time.Time, error) {
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)
ctx := context.Background()
@ -96,7 +96,7 @@ func runCron(store store.Store, remote remote.Remote, cron *model.Cron, now time
return nil
}
repo, newPipeline, err := CreatePipeline(ctx, store, remote, cron)
repo, newPipeline, err := CreatePipeline(ctx, store, forge, cron)
if err != nil {
return err
}
@ -105,7 +105,7 @@ func runCron(store store.Store, remote remote.Remote, cron *model.Cron, now time
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)
if err != nil {
return nil, nil, err
@ -121,7 +121,7 @@ func CreatePipeline(ctx context.Context, store store.Store, remote remote.Remote
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 {
return nil, nil, err
}

View File

@ -22,13 +22,13 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
mocks_forge "github.com/woodpecker-ci/woodpecker/server/forge/mocks"
"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"
)
func TestCreateBuild(t *testing.T) {
remote := mocks_remote.NewRemote(t)
forge := mocks_forge.NewForge(t)
store := mocks_store.NewStore(t)
ctx := context.Background()
@ -47,9 +47,9 @@ func TestCreateBuild(t *testing.T) {
// mock things
store.On("GetRepo", mock.Anything).Return(repo1, 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",
})
assert.NoError(t, err)

View File

@ -24,10 +24,10 @@ import (
"golang.org/x/oauth2"
"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/remote"
"github.com/woodpecker-ci/woodpecker/server/remote/bitbucket/internal"
"github.com/woodpecker-ci/woodpecker/server/remote/common"
)
// Bitbucket cloud endpoints.
@ -36,7 +36,7 @@ const (
DefaultURL = "https://bitbucket.org"
)
// Opts are remote options for bitbucket
// Opts are forge options for bitbucket
type Opts struct {
Client string
Secret string
@ -49,9 +49,9 @@ type config struct {
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
func New(opts *Opts) (remote.Remote, error) {
func New(opts *Opts) (forge.Forge, error) {
return &config{
API: DefaultAPI,
URL: DefaultURL,
@ -73,7 +73,7 @@ func (c *config) Login(ctx context.Context, w http.ResponseWriter, req *http.Req
// get the OAuth errors
if err := req.FormValue("error"); err != "" {
return nil, &remote.AuthError{
return nil, &forge.AuthError{
Err: err,
Description: req.FormValue("error_description"),
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.
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() {
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
}
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")
}

View File

@ -25,9 +25,9 @@ import (
"github.com/franela/goblin"
"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/remote/bitbucket/fixtures"
"github.com/woodpecker-ci/woodpecker/server/remote/bitbucket/internal"
)
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() {
remote, _ := New(&Opts{Client: "4vyW6b49Z", Secret: "a5012f6c6"})
g.Assert(remote.(*config).URL).Equal(DefaultURL)
g.Assert(remote.(*config).API).Equal(DefaultAPI)
g.Assert(remote.(*config).Client).Equal("4vyW6b49Z")
g.Assert(remote.(*config).Secret).Equal("a5012f6c6")
forge, _ := New(&Opts{Client: "4vyW6b49Z", Secret: "a5012f6c6"})
g.Assert(forge.(*config).URL).Equal(DefaultURL)
g.Assert(forge.(*config).API).Equal(DefaultAPI)
g.Assert(forge.(*config).Client).Equal("4vyW6b49Z")
g.Assert(forge.(*config).Secret).Equal("a5012f6c6")
})
g.It("Should return the netrc file", func() {
remote, _ := New(&Opts{})
netrc, _ := remote.Netrc(fakeUser, fakeRepo)
forge, _ := New(&Opts{})
netrc, _ := forge.Netrc(fakeUser, fakeRepo)
g.Assert(netrc.Machine).Equal("bitbucket.org")
g.Assert(netrc.Login).Equal("x-token-auth")
g.Assert(netrc.Password).Equal(fakeUser.Token)

View File

@ -23,8 +23,8 @@ import (
"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/remote/bitbucket/internal"
)
const (
@ -50,7 +50,7 @@ func convertStatus(status model.StatusValue) string {
// structure to the common Woodpecker repository structure.
func convertRepo(from *internal.Repo) *model.Repo {
repo := model.Repo{
RemoteID: model.RemoteID(from.UUID),
ForgeID: model.ForgeID(from.UUID),
Clone: cloneLink(from),
Owner: strings.Split(from.FullName, "/")[0],
Name: strings.Split(from.FullName, "/")[1],
@ -140,7 +140,7 @@ func convertPullHook(from *internal.PullRequestHook) *model.Pipeline {
from.PullRequest.Source.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,
Branch: from.PullRequest.Dest.Branch.Name,
Message: from.PullRequest.Desc,

View File

@ -22,8 +22,8 @@ import (
"github.com/franela/goblin"
"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/remote/bitbucket/internal"
)
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.Ref).Equal("refs/heads/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.Timestamp).Equal(hook.PullRequest.Updated.Unix())
})

View File

@ -19,8 +19,8 @@ import (
"io"
"net/http"
"github.com/woodpecker-ci/woodpecker/server/forge/bitbucket/internal"
"github.com/woodpecker-ci/woodpecker/server/model"
"github.com/woodpecker-ci/woodpecker/server/remote/bitbucket/internal"
)
const (

View File

@ -21,8 +21,8 @@ import (
"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/remote/bitbucket/fixtures"
)
func Test_parser(t *testing.T) {

View File

@ -30,10 +30,10 @@ import (
"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/remote"
"github.com/woodpecker-ci/woodpecker/server/remote/bitbucketserver/internal"
"github.com/woodpecker-ci/woodpecker/server/remote/common"
)
const (
@ -61,9 +61,9 @@ type Config struct {
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.
func New(opts Opts) (remote.Remote, error) {
func New(opts Opts) (forge.Forge, error) {
config := &Config{
URL: opts.URL,
Username: opts.Username,
@ -152,7 +152,7 @@ func (*Config) TeamPerm(u *model.User, org string) (*model.Perm, error) {
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)
if err != nil {
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)
}
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")
}

View File

@ -25,8 +25,8 @@ import (
"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/remote/bitbucketserver/internal"
)
const (
@ -52,7 +52,7 @@ func convertStatus(status model.StatusValue) string {
// structure to the common Woodpecker repository structure.
func convertRepo(from *internal.Repo) *model.Repo {
repo := model.Repo{
RemoteID: model.RemoteID(fmt.Sprint(from.ID)),
ForgeID: model.ForgeID(fmt.Sprint(from.ID)),
Name: from.Slug,
Owner: from.Project.Key,
Branch: "master",

View File

@ -21,8 +21,8 @@ import (
"github.com/franela/goblin"
"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/remote/bitbucketserver/internal"
)
func Test_helper(t *testing.T) {

View File

@ -19,8 +19,8 @@ import (
"encoding/json"
"net/http"
"github.com/woodpecker-ci/woodpecker/server/forge/bitbucketserver/internal"
"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

View File

@ -25,10 +25,10 @@ import (
"golang.org/x/oauth2"
"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/remote"
"github.com/woodpecker-ci/woodpecker/server/remote/coding/internal"
"github.com/woodpecker-ci/woodpecker/server/remote/common"
)
const (
@ -46,9 +46,9 @@ type Opts struct {
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.
func New(opts Opts) (remote.Remote, error) {
func New(opts Opts) (forge.Forge, error) {
r := &Coding{
URL: defaultURL,
Client: opts.Client,
@ -81,13 +81,13 @@ func (c *Coding) Name() string {
}
// 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) {
config := c.newConfig(server.Config.Server.Host)
// get the OAuth errors
if err := req.FormValue("error"); err != "" {
return nil, &remote.AuthError{
return nil, &forge.AuthError{
Err: err,
Description: req.FormValue("error_description"),
URI: req.FormValue("error_uri"),
@ -121,7 +121,7 @@ func (c *Coding) Login(ctx context.Context, res http.ResponseWriter, req *http.R
}, 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
func (c *Coding) Auth(ctx context.Context, token, secret string) (string, error) {
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
}
// 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) {
// EMPTY: not implemented in Coding OAuth API
return nil, fmt.Errorf("Not implemented")
}
// 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) {
// EMPTY: not implemented in Coding OAuth API
return nil, nil
}
// Repo fetches the repository from the remote system.
func (c *Coding) Repo(ctx context.Context, u *model.User, _ model.RemoteID, owner, name string) (*model.Repo, error) {
// Repo fetches the repository from the forge.
func (c *Coding) Repo(ctx context.Context, u *model.User, _ model.ForgeID, owner, name string) (*model.Repo, error) {
client := c.newClient(ctx, u)
project, err := client.GetProject(owner, name)
if err != nil {
@ -173,7 +173,7 @@ func (c *Coding) Repo(ctx context.Context, u *model.User, _ model.RemoteID, owne
return nil, err
}
return &model.Repo{
// TODO(1138) RemoteID: project.ID,
// TODO(1138) ForgeID: project.ID,
Owner: project.Owner,
Name: 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
}
// 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) {
client := c.newClient(ctx, u)
projectList, err := client.GetProjectList()
@ -201,7 +201,7 @@ func (c *Coding) Repos(ctx context.Context, u *model.User) ([]*model.Repo, error
return nil, err
}
repo := &model.Repo{
// TODO(1138) RemoteID: project.ID,
// TODO(1138) ForgeID: project.ID,
Owner: project.Owner,
Name: 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
// 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) {
project, err := c.newClient(ctx, u).GetProject(repo.Owner, repo.Name)
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
}
// 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.
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)
@ -244,18 +244,18 @@ func (c *Coding) File(ctx context.Context, u *model.User, r *model.Repo, b *mode
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")
}
// 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 {
// EMPTY: not implemented in Coding OAuth API
return nil
}
// 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) {
host, err := common.ExtractHostFromCloneURL(r.Clone)
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
// 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 {
if !c.SkipVerify {
return ctx

View File

@ -25,8 +25,8 @@ import (
"github.com/franela/goblin"
"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/remote/coding/fixtures"
)
func Test_coding(t *testing.T) {
@ -42,9 +42,9 @@ func Test_coding(t *testing.T) {
s.Close()
})
g.Describe("Creating a remote", func() {
g.Describe("Creating a forge", func() {
g.It("Should return client with specified options", func() {
remote, _ := New(Opts{
forge, _ := New(Opts{
URL: "https://coding.net",
Client: "KTNF2ALdm3ofbtxLh6IbV95Ro5AKWJUP",
Secret: "zVtxJrKhNhBcNyqCz1NggNAAmehAxnRO3Z0fXmCp",
@ -53,13 +53,13 @@ func Test_coding(t *testing.T) {
Password: "password",
SkipVerify: true,
})
g.Assert(remote.(*Coding).URL).Equal("https://coding.net")
g.Assert(remote.(*Coding).Client).Equal("KTNF2ALdm3ofbtxLh6IbV95Ro5AKWJUP")
g.Assert(remote.(*Coding).Secret).Equal("zVtxJrKhNhBcNyqCz1NggNAAmehAxnRO3Z0fXmCp")
g.Assert(remote.(*Coding).Scopes).Equal([]string{"user", "project", "project:depot"})
g.Assert(remote.(*Coding).Username).Equal("someuser")
g.Assert(remote.(*Coding).Password).Equal("password")
g.Assert(remote.(*Coding).SkipVerify).Equal(true)
g.Assert(forge.(*Coding).URL).Equal("https://coding.net")
g.Assert(forge.(*Coding).Client).Equal("KTNF2ALdm3ofbtxLh6IbV95Ro5AKWJUP")
g.Assert(forge.(*Coding).Secret).Equal("zVtxJrKhNhBcNyqCz1NggNAAmehAxnRO3Z0fXmCp")
g.Assert(forge.(*Coding).Scopes).Equal([]string{"user", "project", "project:depot"})
g.Assert(forge.(*Coding).Username).Equal("someuser")
g.Assert(forge.(*Coding).Password).Equal("password")
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.It("Should return the netrc file for global credential", func() {
remote, _ := New(Opts{
forge, _ := New(Opts{
Username: "someuser",
Password: "password",
})
netrc, err := remote.Netrc(fakeUser, fakeRepo)
netrc, err := forge.Netrc(fakeUser, fakeRepo)
g.Assert(err).IsNil()
g.Assert(netrc.Login).Equal("someuser")
g.Assert(netrc.Password).Equal("password")
g.Assert(netrc.Machine).Equal("git.coding.net")
})
g.It("Should return the netrc file for specified user", func() {
remote, _ := New(Opts{})
netrc, err := remote.Netrc(fakeUser, fakeRepo)
forge, _ := New(Opts{})
netrc, err := forge.Netrc(fakeUser, fakeRepo)
g.Assert(err).IsNil()
g.Assert(netrc.Login).Equal(fakeUser.Token)
g.Assert(netrc.Password).Equal("x-oauth-basic")

View File

@ -138,7 +138,7 @@ func convertRepository(repo *Repository) (*model.Repo, error) {
}
return &model.Repo{
// TODO RemoteID: repo.ID,
// TODO ForgeID: repo.ID,
Owner: matches[1],
Name: repo.Name,
FullName: projectFullName(repo.Owner.GlobalKey, repo.Name),
@ -167,16 +167,16 @@ func parsePushHook(raw []byte) (*model.Repo, *model.Pipeline, error) {
lastCommit := findLastCommit(hook.Commits, hook.After)
pipeline := &model.Pipeline{
Event: model.EventPush,
Commit: hook.After,
Ref: hook.Ref,
Link: fmt.Sprintf("%s/git/commit/%s", hook.Repository.WebURL, hook.After),
Branch: strings.Replace(hook.Ref, "refs/heads/", "", -1),
Message: lastCommit.ShortMessage,
Email: lastCommit.Committer.Email,
Avatar: hook.User.Avatar,
Author: hook.User.GlobalKey,
Remote: hook.Repository.HTTPSURL,
Event: model.EventPush,
Commit: hook.After,
Ref: hook.Ref,
Link: fmt.Sprintf("%s/git/commit/%s", hook.Repository.WebURL, hook.After),
Branch: strings.Replace(hook.Ref, "refs/heads/", "", -1),
Message: lastCommit.ShortMessage,
Email: lastCommit.Committer.Email,
Avatar: hook.User.Avatar,
Author: hook.User.GlobalKey,
CloneURL: hook.Repository.HTTPSURL,
}
return repo, pipeline, nil
}
@ -197,17 +197,17 @@ func parsePullRequestHook(raw []byte) (*model.Repo, *model.Pipeline, error) {
return nil, nil, err
}
pipeline := &model.Pipeline{
Event: model.EventPull,
Commit: hook.PullRequest.CommitSHA,
Link: hook.PullRequest.WebURL,
Ref: fmt.Sprintf("refs/pull/%d/MERGE", int(hook.PullRequest.Number)),
Branch: hook.PullRequest.TargetBranch,
Message: hook.PullRequest.Body,
Author: hook.PullRequest.User.GlobalKey,
Avatar: hook.PullRequest.User.Avatar,
Title: hook.PullRequest.Title,
Remote: hook.Repository.HTTPSURL,
Refspec: fmt.Sprintf("%s:%s", hook.PullRequest.SourceBranch, hook.PullRequest.TargetBranch),
Event: model.EventPull,
Commit: hook.PullRequest.CommitSHA,
Link: hook.PullRequest.WebURL,
Ref: fmt.Sprintf("refs/pull/%d/MERGE", int(hook.PullRequest.Number)),
Branch: hook.PullRequest.TargetBranch,
Message: hook.PullRequest.Body,
Author: hook.PullRequest.User.GlobalKey,
Avatar: hook.PullRequest.User.Avatar,
Title: hook.PullRequest.Title,
CloneURL: hook.Repository.HTTPSURL,
Refspec: fmt.Sprintf("%s:%s", hook.PullRequest.SourceBranch, hook.PullRequest.TargetBranch),
}
return repo, pipeline, nil
@ -230,17 +230,17 @@ func parseMergeReuqestHook(raw []byte) (*model.Repo, *model.Pipeline, error) {
}
pipeline := &model.Pipeline{
Event: model.EventPull,
Commit: hook.MergeRequest.CommitSHA,
Link: hook.MergeRequest.WebURL,
Ref: fmt.Sprintf("refs/merge/%d/MERGE", int(hook.MergeRequest.Number)),
Branch: hook.MergeRequest.TargetBranch,
Message: hook.MergeRequest.Body,
Author: hook.MergeRequest.User.GlobalKey,
Avatar: hook.MergeRequest.User.Avatar,
Title: hook.MergeRequest.Title,
Remote: hook.Repository.HTTPSURL,
Refspec: fmt.Sprintf("%s:%s", hook.MergeRequest.SourceBranch, hook.MergeRequest.TargetBranch),
Event: model.EventPull,
Commit: hook.MergeRequest.CommitSHA,
Link: hook.MergeRequest.WebURL,
Ref: fmt.Sprintf("refs/merge/%d/MERGE", int(hook.MergeRequest.Number)),
Branch: hook.MergeRequest.TargetBranch,
Message: hook.MergeRequest.Body,
Author: hook.MergeRequest.User.GlobalKey,
Avatar: hook.MergeRequest.User.Avatar,
Title: hook.MergeRequest.Title,
CloneURL: hook.Repository.HTTPSURL,
Refspec: fmt.Sprintf("%s:%s", hook.MergeRequest.SourceBranch, hook.MergeRequest.TargetBranch),
}
return repo, pipeline, nil
}

View File

@ -23,8 +23,8 @@ import (
"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/remote/coding/fixtures"
)
func Test_hook(t *testing.T) {
@ -49,16 +49,16 @@ func Test_hook(t *testing.T) {
}
pipeline := &model.Pipeline{
Event: model.EventPush,
Commit: "5b9912a6ff272e9c93a4c44c278fe9b359ed1ab4",
Ref: "refs/heads/master",
Link: "https://coding.net/u/demo1/p/test1/git/commit/5b9912a6ff272e9c93a4c44c278fe9b359ed1ab4",
Branch: "master",
Message: "new file .woodpecker.yml\n",
Email: "demo1@gmail.com",
Avatar: "/static/fruit_avatar/Fruit-20.png",
Author: "demo1",
Remote: "https://git.coding.net/demo1/test1.git",
Event: model.EventPush,
Commit: "5b9912a6ff272e9c93a4c44c278fe9b359ed1ab4",
Ref: "refs/heads/master",
Link: "https://coding.net/u/demo1/p/test1/git/commit/5b9912a6ff272e9c93a4c44c278fe9b359ed1ab4",
Branch: "master",
Message: "new file .woodpecker.yml\n",
Email: "demo1@gmail.com",
Avatar: "/static/fruit_avatar/Fruit-20.png",
Author: "demo1",
CloneURL: "https://git.coding.net/demo1/test1.git",
}
actualRepo, actualPipeline, err := parseHook(r)
@ -117,16 +117,16 @@ func Test_hook(t *testing.T) {
}
pipeline := &model.Pipeline{
Event: model.EventPush,
Commit: "5b9912a6ff272e9c93a4c44c278fe9b359ed1ab4",
Ref: "refs/heads/master",
Link: "https://coding.net/u/demo1/p/test1/git/commit/5b9912a6ff272e9c93a4c44c278fe9b359ed1ab4",
Branch: "master",
Message: "new file .woodpecker.yml\n",
Email: "demo1@gmail.com",
Avatar: "/static/fruit_avatar/Fruit-20.png",
Author: "demo1",
Remote: "https://git.coding.net/demo1/test1.git",
Event: model.EventPush,
Commit: "5b9912a6ff272e9c93a4c44c278fe9b359ed1ab4",
Ref: "refs/heads/master",
Link: "https://coding.net/u/demo1/p/test1/git/commit/5b9912a6ff272e9c93a4c44c278fe9b359ed1ab4",
Branch: "master",
Message: "new file .woodpecker.yml\n",
Email: "demo1@gmail.com",
Avatar: "/static/fruit_avatar/Fruit-20.png",
Author: "demo1",
CloneURL: "https://git.coding.net/demo1/test1.git",
}
actualRepo, actualPipeline, err := parsePushHook([]byte(fixtures.PushHook))
@ -153,17 +153,17 @@ func Test_hook(t *testing.T) {
}
pipeline := &model.Pipeline{
Event: model.EventPull,
Commit: "55e77b328b71d3ee4f9e70a5f67231b0acceeadc",
Link: "https://coding.net/u/demo1/p/test2/git/pull/1",
Ref: "refs/pull/1/MERGE",
Branch: "master",
Message: "pr message",
Author: "demo2",
Avatar: "/static/fruit_avatar/Fruit-2.png",
Title: "pr1",
Remote: "https://git.coding.net/demo1/test2.git",
Refspec: "master:master",
Event: model.EventPull,
Commit: "55e77b328b71d3ee4f9e70a5f67231b0acceeadc",
Link: "https://coding.net/u/demo1/p/test2/git/pull/1",
Ref: "refs/pull/1/MERGE",
Branch: "master",
Message: "pr message",
Author: "demo2",
Avatar: "/static/fruit_avatar/Fruit-2.png",
Title: "pr1",
CloneURL: "https://git.coding.net/demo1/test2.git",
Refspec: "master:master",
}
actualRepo, actualPipeline, err := parsePullRequestHook([]byte(fixtures.PullRequestHook))
@ -183,17 +183,17 @@ func Test_hook(t *testing.T) {
}
pipeline := &model.Pipeline{
Event: model.EventPull,
Commit: "74e6755580c34e9fd81dbcfcbd43ee5f30259436",
Link: "https://coding.net/u/demo1/p/test1/git/merge/1",
Ref: "refs/merge/1/MERGE",
Branch: "master",
Message: "<p>mr message</p>",
Author: "demo1",
Avatar: "/static/fruit_avatar/Fruit-20.png",
Title: "mr1",
Remote: "https://git.coding.net/demo1/test1.git",
Refspec: "branch1:master",
Event: model.EventPull,
Commit: "74e6755580c34e9fd81dbcfcbd43ee5f30259436",
Link: "https://coding.net/u/demo1/p/test1/git/merge/1",
Ref: "refs/merge/1/MERGE",
Branch: "master",
Message: "<p>mr message</p>",
Author: "demo1",
Avatar: "/static/fruit_avatar/Fruit-20.png",
Title: "mr1",
CloneURL: "https://git.coding.net/demo1/test1.git",
Refspec: "branch1:master",
}
actualRepo, actualPipeline, err := parseMergeReuqestHook([]byte(fixtures.MergeRequestHook))

View File

@ -18,7 +18,7 @@ import (
"testing"
"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) {

View File

@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package remote
package forge
// AuthError represents remote authentication error.
// AuthError represents forge authentication error.
type AuthError struct {
Err string
Description string

View File

@ -36,9 +36,9 @@ import (
"golang.org/x/oauth2"
"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/remote"
"github.com/woodpecker-ci/woodpecker/server/remote/common"
"github.com/woodpecker-ci/woodpecker/server/store"
)
@ -64,9 +64,9 @@ type Opts struct {
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/
func New(opts Opts) (remote.Remote, error) {
func New(opts Opts) (forge.Forge, error) {
u, err := url.Parse(opts.URL)
if err != nil {
return nil, err
@ -112,7 +112,7 @@ func (c *Gitea) Login(ctx context.Context, w http.ResponseWriter, req *http.Requ
// get the OAuth errors
if err := req.FormValue("error"); err != "" {
return nil, &remote.AuthError{
return nil, &forge.AuthError{
Err: err,
Description: req.FormValue("error_description"),
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.
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)
if err != nil {
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
}
func (c *Gitea) Dir(ctx context.Context, u *model.User, r *model.Repo, b *model.Pipeline, f string) ([]*remote.FileMeta, error) {
var configs []*remote.FileMeta
func (c *Gitea) Dir(ctx context.Context, u *model.User, r *model.Repo, b *model.Pipeline, f string) ([]*forge.FileMeta, error) {
var configs []*forge.FileMeta
client, err := c.newClientToken(ctx, u.Token)
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)
}
configs = append(configs, &remote.FileMeta{
configs = append(configs, &forge.FileMeta{
Name: e.Path,
Data: data,
})
@ -565,7 +565,7 @@ func (c *Gitea) getChangedFilesForPR(ctx context.Context, repo *model.Repo, inde
return []string{}, nil
}
repo, err := _store.GetRepoNameFallback(repo.RemoteID, repo.FullName)
repo, err := _store.GetRepoNameFallback(repo.ForgeID, repo.FullName)
if err != nil {
return nil, err
}

View File

@ -27,8 +27,8 @@ import (
"github.com/stretchr/testify/mock"
"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/remote/gitea/fixtures"
"github.com/woodpecker-ci/woodpecker/server/store"
mocks_store "github.com/woodpecker-ci/woodpecker/server/store/mocks"
)
@ -51,14 +51,14 @@ func Test_gitea(t *testing.T) {
s.Close()
})
g.Describe("Creating a remote", func() {
g.Describe("Creating a forge", func() {
g.It("Should return client with specified options", func() {
remote, _ := New(Opts{
forge, _ := New(Opts{
URL: "http://localhost:8080",
SkipVerify: true,
})
g.Assert(remote.(*Gitea).URL).Equal("http://localhost:8080")
g.Assert(remote.(*Gitea).SkipVerify).Equal(true)
g.Assert(forge.(*Gitea).URL).Equal("http://localhost:8080")
g.Assert(forge.(*Gitea).SkipVerify).Equal(true)
})
g.It("Should handle malformed url", func() {
_, err := New(Opts{URL: "%gh&%ij"})
@ -68,15 +68,15 @@ func Test_gitea(t *testing.T) {
g.Describe("Generating a netrc file", func() {
g.It("Should return a netrc with the user token", func() {
remote, _ := New(Opts{})
netrc, _ := remote.Netrc(fakeUser, fakeRepo)
forge, _ := New(Opts{})
netrc, _ := forge.Netrc(fakeUser, fakeRepo)
g.Assert(netrc.Machine).Equal("gitea.com")
g.Assert(netrc.Login).Equal(fakeUser.Login)
g.Assert(netrc.Password).Equal(fakeUser.Token)
})
g.It("Should return a netrc with the machine account", func() {
remote, _ := New(Opts{})
netrc, _ := remote.Netrc(nil, fakeRepo)
forge, _ := New(Opts{})
netrc, _ := forge.Netrc(nil, fakeRepo)
g.Assert(netrc.Machine).Equal("gitea.com")
g.Assert(netrc.Login).Equal("")
g.Assert(netrc.Password).Equal("")
@ -85,7 +85,7 @@ func Test_gitea(t *testing.T) {
g.Describe("Requesting a repository", 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(repo.Owner).Equal(fakeRepo.Owner)
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() {
repos, err := c.Repos(ctx, fakeUser)
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].Name).Equal(fakeRepo.Name)
g.Assert(repos[0].FullName).Equal(fakeRepo.Owner + "/" + fakeRepo.Name)
@ -193,7 +193,7 @@ var (
fakeRepo = &model.Repo{
Clone: "http://gitea.com/test_name/repo_name.git",
RemoteID: "5",
ForgeID: "5",
Owner: "test_name",
Name: "repo_name",
FullName: "test_name/repo_name",

View File

@ -37,7 +37,7 @@ func toRepo(from *gitea.Repository) *model.Repo {
from.Owner.AvatarURL,
)
return &model.Repo{
RemoteID: model.RemoteID(fmt.Sprint(from.ID)),
ForgeID: model.ForgeID(fmt.Sprint(from.ID)),
SCMKind: model.RepoGit,
Name: name,
Owner: from.Owner.UserName,

View File

@ -22,8 +22,8 @@ import (
"code.gitea.io/sdk/gitea"
"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/remote/gitea/fixtures"
"github.com/woodpecker-ci/woodpecker/shared/utils"
)

View File

@ -22,8 +22,8 @@ import (
"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/remote/gitea/fixtures"
"github.com/woodpecker-ci/woodpecker/shared/utils"
)

View File

@ -85,7 +85,7 @@ func convertDesc(status model.StatusValue) string {
// structure to the common Woodpecker repository structure.
func convertRepo(from *github.Repository) *model.Repo {
repo := &model.Repo{
RemoteID: model.RemoteID(fmt.Sprint(from.GetID())),
ForgeID: model.ForgeID(fmt.Sprint(from.GetID())),
Name: from.GetName(),
FullName: from.GetFullName(),
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.
func convertRepoHook(eventRepo *github.PushEventRepository) *model.Repo {
repo := &model.Repo{
RemoteID: model.RemoteID(fmt.Sprint(eventRepo.GetID())),
ForgeID: model.ForgeID(fmt.Sprint(eventRepo.GetID())),
Owner: eventRepo.GetOwner().GetLogin(),
Name: eventRepo.GetName(),
FullName: eventRepo.GetFullName(),

View File

@ -212,7 +212,7 @@ func Test_helper(t *testing.T) {
g.Assert(pipeline.Branch).Equal(*from.PullRequest.Base.Ref)
g.Assert(pipeline.Ref).Equal("refs/pull/42/merge")
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.Message).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.Avatar).Equal(*from.Sender.AvatarURL)
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() {

View File

@ -30,9 +30,9 @@ import (
"golang.org/x/oauth2"
"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/remote"
"github.com/woodpecker-ci/woodpecker/server/remote/common"
"github.com/woodpecker-ci/woodpecker/server/store"
"github.com/woodpecker-ci/woodpecker/shared/utils"
)
@ -51,9 +51,9 @@ type Opts struct {
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.
func New(opts Opts) (remote.Remote, error) {
func New(opts Opts) (forge.Forge, error) {
r := &client{
API: defaultAPI,
URL: defaultURL,
@ -84,13 +84,13 @@ func (c *client) Name() string {
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) {
config := c.newConfig(req)
// get the OAuth errors
if err := req.FormValue("error"); err != "" {
return nil, &remote.AuthError{
return nil, &forge.AuthError{
Err: err,
Description: req.FormValue("error_description"),
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.
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)
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
}
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)
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
}
fc := make(chan *remote.FileMeta)
fc := make(chan *forge.FileMeta)
errc := make(chan error)
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 {
errc <- err
} else {
fc <- &remote.FileMeta{
fc <- &forge.FileMeta{
Name: path,
Data: content,
}
@ -262,7 +262,7 @@ func (c *client) Dir(ctx context.Context, u *model.User, r *model.Repo, b *model
}(f + "/" + *file.Name)
}
var files []*remote.FileMeta
var files []*forge.FileMeta
for i := 0; i < len(data); i++ {
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
// 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 {
if !c.SkipVerify {
return ctx
@ -435,7 +435,7 @@ func matchingHooks(hooks []*github.Hook, rawurl string) *github.Hook {
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.
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)
@ -545,7 +545,7 @@ func (c *client) loadChangedFilesFromPullRequest(ctx context.Context, pull *gith
return pipeline, nil
}
repo, err := _store.GetRepoNameFallback(tmpRepo.RemoteID, tmpRepo.FullName)
repo, err := _store.GetRepoNameFallback(tmpRepo.ForgeID, tmpRepo.FullName)
if err != nil {
return nil, err
}

View File

@ -23,8 +23,8 @@ import (
"github.com/franela/goblin"
"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/remote/github/fixtures"
)
func Test_github(t *testing.T) {
@ -43,33 +43,33 @@ func Test_github(t *testing.T) {
s.Close()
})
g.Describe("Creating a remote", func() {
g.Describe("Creating a forge", func() {
g.It("Should return client with specified options", func() {
remote, _ := New(Opts{
forge, _ := New(Opts{
URL: "http://localhost:8080/",
Client: "0ZXh0IjoiI",
Secret: "I1NiIsInR5",
SkipVerify: true,
})
g.Assert(remote.(*client).URL).Equal("http://localhost:8080")
g.Assert(remote.(*client).API).Equal("http://localhost:8080/api/v3/")
g.Assert(remote.(*client).Client).Equal("0ZXh0IjoiI")
g.Assert(remote.(*client).Secret).Equal("I1NiIsInR5")
g.Assert(remote.(*client).SkipVerify).Equal(true)
g.Assert(forge.(*client).URL).Equal("http://localhost:8080")
g.Assert(forge.(*client).API).Equal("http://localhost:8080/api/v3/")
g.Assert(forge.(*client).Client).Equal("0ZXh0IjoiI")
g.Assert(forge.(*client).Secret).Equal("I1NiIsInR5")
g.Assert(forge.(*client).SkipVerify).Equal(true)
})
})
g.Describe("Generating a netrc file", func() {
g.It("Should return a netrc with the user token", func() {
remote, _ := New(Opts{})
netrc, _ := remote.Netrc(fakeUser, fakeRepo)
forge, _ := New(Opts{})
netrc, _ := forge.Netrc(fakeUser, fakeRepo)
g.Assert(netrc.Machine).Equal("github.com")
g.Assert(netrc.Login).Equal(fakeUser.Token)
g.Assert(netrc.Password).Equal("x-oauth-basic")
})
g.It("Should return a netrc with the machine account", func() {
remote, _ := New(Opts{})
netrc, _ := remote.Netrc(nil, fakeRepo)
forge, _ := New(Opts{})
netrc, _ := forge.Netrc(nil, fakeRepo)
g.Assert(netrc.Machine).Equal("github.com")
g.Assert(netrc.Login).Equal("")
g.Assert(netrc.Password).Equal("")
@ -78,9 +78,9 @@ func Test_github(t *testing.T) {
g.Describe("Requesting a repository", 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(repo.RemoteID).Equal(fakeRepo.RemoteID)
g.Assert(repo.ForgeID).Equal(fakeRepo.ForgeID)
g.Assert(repo.Owner).Equal(fakeRepo.Owner)
g.Assert(repo.Name).Equal(fakeRepo.Name)
g.Assert(repo.FullName).Equal(fakeRepo.FullName)
@ -133,7 +133,7 @@ var (
}
fakeRepo = &model.Repo{
RemoteID: "5",
ForgeID: "5",
Owner: "octocat",
Name: "Hello-World",
FullName: "octocat/Hello-World",

View File

@ -86,7 +86,7 @@ func parsePushHook(hook *github.PushEvent) (*model.Repo, *model.Pipeline, error)
Email: hook.GetHeadCommit().GetAuthor().GetEmail(),
Avatar: hook.GetSender().GetAvatarURL(),
Author: hook.GetSender().GetLogin(),
Remote: hook.GetRepo().GetCloneURL(),
CloneURL: hook.GetRepo().GetCloneURL(),
Sender: hook.GetSender().GetLogin(),
ChangedFiles: getChangedFilesFromCommits(hook.Commits),
}
@ -155,17 +155,17 @@ func parsePullHook(hook *github.PullRequestEvent, merge bool) (*github.PullReque
}
pipeline := &model.Pipeline{
Event: model.EventPull,
Commit: hook.GetPullRequest().GetHead().GetSHA(),
Link: hook.GetPullRequest().GetHTMLURL(),
Ref: fmt.Sprintf(headRefs, hook.GetPullRequest().GetNumber()),
Branch: hook.GetPullRequest().GetBase().GetRef(),
Message: hook.GetPullRequest().GetTitle(),
Author: hook.GetPullRequest().GetUser().GetLogin(),
Avatar: hook.GetPullRequest().GetUser().GetAvatarURL(),
Title: hook.GetPullRequest().GetTitle(),
Sender: hook.GetSender().GetLogin(),
Remote: hook.GetPullRequest().GetHead().GetRepo().GetCloneURL(),
Event: model.EventPull,
Commit: hook.GetPullRequest().GetHead().GetSHA(),
Link: hook.GetPullRequest().GetHTMLURL(),
Ref: fmt.Sprintf(headRefs, hook.GetPullRequest().GetNumber()),
Branch: hook.GetPullRequest().GetBase().GetRef(),
Message: hook.GetPullRequest().GetTitle(),
Author: hook.GetPullRequest().GetUser().GetLogin(),
Avatar: hook.GetPullRequest().GetUser().GetAvatarURL(),
Title: hook.GetPullRequest().GetTitle(),
Sender: hook.GetSender().GetLogin(),
CloneURL: hook.GetPullRequest().GetHead().GetRepo().GetCloneURL(),
Refspec: fmt.Sprintf(refSpec,
hook.GetPullRequest().GetHead().GetRef(),
hook.GetPullRequest().GetBase().GetRef(),

View File

@ -23,8 +23,8 @@ import (
"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/remote/github/fixtures"
)
const (

View File

@ -37,7 +37,7 @@ func (g *Gitlab) convertGitlabRepo(_repo *gitlab.Project) (*model.Repo, error) {
owner := strings.Join(parts[:len(parts)-1], "/")
name := parts[len(parts)-1]
repo := &model.Repo{
RemoteID: model.RemoteID(fmt.Sprint(_repo.ID)),
ForgeID: model.ForgeID(fmt.Sprint(_repo.ID)),
Owner: owner,
Name: name,
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.RemoteID = model.RemoteID(fmt.Sprint(obj.TargetProjectID))
repo.ForgeID = model.ForgeID(fmt.Sprint(obj.TargetProjectID))
repo.Link = target.WebURL
if target.GitHTTPURL != "" {
@ -113,7 +113,7 @@ func convertMergeRequestHook(hook *gitlab.MergeEvent, req *http.Request) (int, *
pipeline.Message = lastCommit.Message
pipeline.Commit = lastCommit.ID
pipeline.Remote = obj.Source.HTTPURL
pipeline.CloneURL = obj.Source.HTTPURL
pipeline.Ref = fmt.Sprintf(mergeRefs, obj.IID)
pipeline.Branch = obj.SourceBranch
@ -142,7 +142,7 @@ func convertPushHook(hook *gitlab.PushEvent) (*model.Repo, *model.Pipeline, erro
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.Link = hook.Project.WebURL
repo.Clone = hook.Project.GitHTTPURL
@ -194,7 +194,7 @@ func convertTagHook(hook *gitlab.TagEvent) (*model.Repo, *model.Pipeline, error)
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.Link = hook.Project.WebURL
repo.Clone = hook.Project.GitHTTPURL

View File

@ -31,9 +31,9 @@ import (
"golang.org/x/oauth2"
"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/remote"
"github.com/woodpecker-ci/woodpecker/server/remote/common"
"github.com/woodpecker-ci/woodpecker/server/store"
"github.com/woodpecker-ci/woodpecker/shared/utils"
)
@ -51,7 +51,7 @@ type Opts struct {
SkipVerify bool // Skip ssl verification.
}
// Gitlab implements "Remote" interface
// Gitlab implements "Forge" interface
type Gitlab struct {
URL string
ClientID string
@ -61,9 +61,9 @@ type Gitlab struct {
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
func New(opts Opts) (remote.Remote, error) {
func New(opts Opts) (forge.Forge, error) {
return &Gitlab{
URL: opts.URL,
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
// remote user details.
// forge user details.
func (g *Gitlab) Login(ctx context.Context, res http.ResponseWriter, req *http.Request) (*model.User, error) {
config, oauth2Ctx := g.oauth2Config(ctx)
// get the OAuth errors
if err := req.FormValue("error"); err != "" {
return nil, &remote.AuthError{
return nil, &forge.AuthError{
Err: err,
Description: req.FormValue("error_description"),
URI: req.FormValue("error_uri"),
@ -168,7 +168,7 @@ func (g *Gitlab) Refresh(ctx context.Context, user *model.User) (bool, error) {
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) {
client, err := newClient(g.URL, token, g.SkipVerify)
if err != nil {
@ -182,7 +182,7 @@ func (g *Gitlab) Auth(ctx context.Context, token, _ string) (string, error) {
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) {
client, err := newClient(g.URL, user.Token, g.SkipVerify)
if err != nil {
@ -217,7 +217,7 @@ func (g *Gitlab) Teams(ctx context.Context, user *model.User) ([]*model.Team, er
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) {
repo, _, err := client.Projects.GetProject(fmt.Sprintf("%s/%s", owner, name), nil, gitlab.WithContext(ctx))
if err != nil {
@ -227,8 +227,8 @@ func (g *Gitlab) getProject(ctx context.Context, client *gitlab.Client, owner, n
return repo, nil
}
// Repo fetches the repository from the remote system.
func (g *Gitlab) Repo(ctx context.Context, user *model.User, id model.RemoteID, owner, name string) (*model.Repo, error) {
// Repo fetches the repository from the forge.
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)
if err != nil {
return nil, err
@ -254,7 +254,7 @@ func (g *Gitlab) Repo(ctx context.Context, user *model.User, id model.RemoteID,
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) {
client, err := newClient(g.URL, user.Token, g.SkipVerify)
if err != nil {
@ -300,7 +300,7 @@ func (g *Gitlab) Repos(ctx context.Context, user *model.User) ([]*model.Repo, er
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) {
client, err := newClient(g.URL, user.Token, g.SkipVerify)
if err != nil {
@ -324,7 +324,7 @@ func (g *Gitlab) Perm(ctx context.Context, user *model.User, r *model.Repo) (*mo
}, 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) {
client, err := newClient(g.URL, user.Token, g.SkipVerify)
if err != nil {
@ -338,14 +338,14 @@ func (g *Gitlab) File(ctx context.Context, user *model.User, repo *model.Repo, p
return file, err
}
// Dir fetches a folder from the remote repository
func (g *Gitlab) Dir(ctx context.Context, user *model.User, repo *model.Repo, pipeline *model.Pipeline, path string) ([]*remote.FileMeta, error) {
// 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) ([]*forge.FileMeta, error) {
client, err := newClient(g.URL, user.Token, g.SkipVerify)
if err != nil {
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)
if err != nil {
return nil, err
@ -372,7 +372,7 @@ func (g *Gitlab) Dir(ctx context.Context, user *model.User, repo *model.Repo, pi
if err != nil {
return nil, err
}
files = append(files, &remote.FileMeta{
files = append(files, &forge.FileMeta{
Name: batch[i].Path,
Data: data,
})
@ -681,7 +681,7 @@ func (g *Gitlab) loadChangedFilesFromMergeRequest(ctx context.Context, tmpRepo *
return pipeline, nil
}
repo, err := _store.GetRepoNameFallback(tmpRepo.RemoteID, tmpRepo.FullName)
repo, err := _store.GetRepoNameFallback(tmpRepo.ForgeID, tmpRepo.FullName)
if err != nil {
return nil, err
}

View File

@ -26,8 +26,8 @@ import (
"github.com/franela/goblin"
"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/remote/gitlab/testdata"
)
func load(t *testing.T, config string) *Gitlab {

View File

@ -27,7 +27,7 @@ func NewServer(t *testing.T) *httptest.Server {
// handle requests and serve mock data
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
// TODO: find source of "/api/v4/" requests

View File

@ -26,9 +26,9 @@ import (
"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/remote"
"github.com/woodpecker-ci/woodpecker/server/remote/common"
)
// Opts defines configuration options.
@ -48,9 +48,9 @@ type client struct {
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/
func New(opts Opts) (remote.Remote, error) {
func New(opts Opts) (forge.Forge, error) {
u, err := url.Parse(opts.URL)
if err != nil {
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.
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)
repo, err := client.GetRepo(owner, name)
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
}
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")
}

View File

@ -23,8 +23,8 @@ import (
"github.com/franela/goblin"
"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/remote/gogs/fixtures"
)
func Test_gogs(t *testing.T) {
@ -43,20 +43,20 @@ func Test_gogs(t *testing.T) {
s.Close()
})
g.Describe("Creating a remote", func() {
g.Describe("Creating a forge", func() {
g.It("Should return client with specified options", func() {
remote, _ := New(Opts{
forge, _ := New(Opts{
URL: "http://localhost:8080",
Username: "someuser",
Password: "password",
SkipVerify: true,
PrivateMode: true,
})
g.Assert(remote.(*client).URL).Equal("http://localhost:8080")
g.Assert(remote.(*client).Username).Equal("someuser")
g.Assert(remote.(*client).Password).Equal("password")
g.Assert(remote.(*client).SkipVerify).Equal(true)
g.Assert(remote.(*client).PrivateMode).Equal(true)
g.Assert(forge.(*client).URL).Equal("http://localhost:8080")
g.Assert(forge.(*client).Username).Equal("someuser")
g.Assert(forge.(*client).Password).Equal("password")
g.Assert(forge.(*client).SkipVerify).Equal(true)
g.Assert(forge.(*client).PrivateMode).Equal(true)
})
g.It("Should handle malformed url", func() {
_, err := New(Opts{URL: "%gh&%ij"})
@ -66,18 +66,18 @@ func Test_gogs(t *testing.T) {
g.Describe("Generating a netrc file", func() {
g.It("Should return a netrc with the user token", func() {
remote, _ := New(Opts{})
netrc, _ := remote.Netrc(fakeUser, fakeRepo)
forge, _ := New(Opts{})
netrc, _ := forge.Netrc(fakeUser, fakeRepo)
g.Assert(netrc.Machine).Equal("gogs.com")
g.Assert(netrc.Login).Equal(fakeUser.Token)
g.Assert(netrc.Password).Equal("x-oauth-basic")
})
g.It("Should return a netrc with the machine account", func() {
remote, _ := New(Opts{
forge, _ := New(Opts{
Username: "someuser",
Password: "password",
})
netrc, _ := remote.Netrc(nil, fakeRepo)
netrc, _ := forge.Netrc(nil, fakeRepo)
g.Assert(netrc.Machine).Equal("gogs.com")
g.Assert(netrc.Login).Equal("someuser")
g.Assert(netrc.Password).Equal("password")
@ -86,7 +86,7 @@ func Test_gogs(t *testing.T) {
g.Describe("Requesting a repository", 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(repo.Owner).Equal(fakeRepo.Owner)
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() {
repos, err := c.Repos(ctx, fakeUser)
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].Name).Equal(fakeRepo.Name)
g.Assert(repos[0].FullName).Equal(fakeRepo.Owner + "/" + fakeRepo.Name)
@ -183,7 +183,7 @@ var (
}
fakeRepo = &model.Repo{
RemoteID: "5",
ForgeID: "5",
Clone: "http://gogs.com/test_name/repo_name.git",
Owner: "test_name",
Name: "repo_name",

View File

@ -36,7 +36,7 @@ func toRepo(from *gogs.Repository, privateMode bool) *model.Repo {
from.Owner.AvatarUrl,
)
return &model.Repo{
RemoteID: model.RemoteID(fmt.Sprint(from.ID)),
ForgeID: model.ForgeID(fmt.Sprint(from.ID)),
SCMKind: model.RepoGit,
Name: name,
Owner: from.Owner.UserName,

View File

@ -22,8 +22,8 @@ import (
"github.com/franela/goblin"
"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/remote/gogs/fixtures"
)
func Test_parse(t *testing.T) {

View File

@ -6,20 +6,20 @@ import (
context "context"
http "net/http"
forge "github.com/woodpecker-ci/woodpecker/server/forge"
mock "github.com/stretchr/testify/mock"
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
type Remote struct {
// Forge is an autogenerated mock type for the Forge type
type Forge struct {
mock.Mock
}
// 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)
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
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)
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
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)
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
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)
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
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)
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
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)
var r0 []*remote.FileMeta
if rf, ok := ret.Get(0).(func(context.Context, *model.User, *model.Repo, *model.Pipeline, string) []*remote.FileMeta); ok {
var r0 []*forge.FileMeta
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)
} else {
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
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)
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
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)
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
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)
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:
func (_m *Remote) Name() string {
func (_m *Forge) Name() string {
ret := _m.Called()
var r0 string
@ -227,7 +227,7 @@ func (_m *Remote) Name() string {
}
// 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)
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
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)
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
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)
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
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)
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)
} else {
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
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)
} else {
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
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)
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
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)
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
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)
var r0 []*model.Team
@ -378,14 +378,14 @@ func (_m *Remote) Teams(ctx context.Context, u *model.User) ([]*model.Team, erro
return r0, r1
}
type mockConstructorTestingTNewRemote interface {
type mockConstructorTestingTNewForge interface {
mock.TestingT
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.
func NewRemote(t mockConstructorTestingTNewRemote) *Remote {
mock := &Remote{}
// 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 NewForge(t mockConstructorTestingTNewForge) *Forge {
mock := &Forge{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })

View File

@ -13,10 +13,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package remote
package forge
//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 (
"context"
@ -28,44 +28,44 @@ import (
// TODO: use pagination
// TODO: add Driver() who return source forge back
type Remote interface {
type Forge interface {
// Name returns the string name of this driver
Name() string
// 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)
// 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
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)
// Repo fetches the repository from the remote system, 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 fetches the repository from the forge, preferred is using the ID, fallback is owner/name.
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)
// 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)
// 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.
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)
// 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.
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
// private repositories from a remote system.
// private repositories from a forge.
Netrc(u *model.User, r *model.Repo) (*model.Netrc, error)
// 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
// 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)
// BranchHead returns the sha of the head (lastest commit) of the specified branch

View File

@ -32,17 +32,17 @@ import (
"github.com/woodpecker-ci/woodpecker/pipeline/rpc"
"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/model"
"github.com/woodpecker-ci/woodpecker/server/pubsub"
"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/store"
)
type RPC struct {
remote remote.Remote
forge forge.Forge
queue queue.Queue
pubsub pubsub.Publisher
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 {
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)
if err != nil {
log.Error().Err(err).Msgf("can not get user with id '%d'", repo.UserID)
return
}
if refresher, ok := s.remote.(remote.Refresher); ok {
if refresher, ok := s.forge.(forge.Refresher); ok {
ok, err := refresher.Refresh(ctx, user)
if err != nil {
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
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 {
log.Error().Err(err).Msgf("error setting commit status for %s/%d", repo.FullName, pipeline.Number)
}

View File

@ -23,10 +23,10 @@ import (
"github.com/woodpecker-ci/woodpecker/pipeline/rpc"
"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/pubsub"
"github.com/woodpecker-ci/woodpecker/server/queue"
"github.com/woodpecker-ci/woodpecker/server/remote"
"github.com/woodpecker-ci/woodpecker/server/store"
)
@ -36,7 +36,7 @@ type WoodpeckerServer struct {
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{
Namespace: "woodpecker",
Name: "pipeline_time",
@ -48,7 +48,7 @@ func NewWoodpeckerServer(remote remote.Remote, queue queue.Queue, logger logging
Help: "Pipeline count.",
}, []string{"repo", "branch", "status", "pipeline"})
peer := RPC{
remote: remote,
forge: forge,
store: store,
queue: queue,
pubsub: pubsub,

Some files were not shown because too many files have changed in this diff Show More