diff --git a/cmd/cli/app.go b/cmd/cli/app.go index 4b3fe6698..086914804 100644 --- a/cmd/cli/app.go +++ b/cmd/cli/app.go @@ -29,7 +29,6 @@ import ( "go.woodpecker-ci.org/woodpecker/v2/cli/org" "go.woodpecker-ci.org/woodpecker/v2/cli/pipeline" "go.woodpecker-ci.org/woodpecker/v2/cli/repo" - "go.woodpecker-ci.org/woodpecker/v2/cli/repo/registry" "go.woodpecker-ci.org/woodpecker/v2/cli/secret" "go.woodpecker-ci.org/woodpecker/v2/cli/setup" "go.woodpecker-ci.org/woodpecker/v2/cli/update" @@ -57,8 +56,6 @@ func newApp() *cli.Command { deploy.Command, exec.Command, info.Command, - // TODO: Remove in 3.x - registry.Command, secret.Command, user.Command, lint.Command, diff --git a/docs/docs/30-administration/40-advanced/100-external-configuration-api.md b/docs/docs/30-administration/40-advanced/100-external-configuration-api.md index db112126d..a24abd3bd 100644 --- a/docs/docs/30-administration/40-advanced/100-external-configuration-api.md +++ b/docs/docs/30-administration/40-advanced/100-external-configuration-api.md @@ -81,12 +81,11 @@ WOODPECKER_CONFIG_SERVICE_ENDPOINT=https://example.com/ciconfig "updated_at": 0, "verified": false }, - "configs": [ - { - "name": ".woodpecker.yaml", - "data": "steps:\n - name: backend\n image: alpine\n commands:\n - echo \"Hello there from Repo (.woodpecker.yaml)\"\n" - } - ] + "netrc": { + "machine": "https://example.com", + "login": "user", + "password": "password" + } } ``` diff --git a/docs/docs/91-migrations.md b/docs/docs/91-migrations.md index 84aa4304a..aeb24e2c2 100644 --- a/docs/docs/91-migrations.md +++ b/docs/docs/91-migrations.md @@ -20,6 +20,9 @@ Some versions need some changes to the server configuration or the pipeline conf - Renamed `start_time`, `end_time`, `created_at`, `started_at`, `finished_at` and `reviewed_at` JSON fields to `started`, `finished`, `created`, `started`, `finished`, `reviewed` - Update all webhooks by pressing the "Repair all" button in the admin settings as the webhook token claims have changed - Crons now use standard Linux syntax without seconds +- Replaced `configs` object by `netrc` in external configuration APIs +- Removed old API routes: `registry/` -> `registries`, `/authorize/token` +- Replaced `registry` command with `repo registry` in cli - Deprecated `detached` in favor of services ## 2.0.0 diff --git a/pipeline/frontend/metadata/drone_compatibility_test.go b/pipeline/frontend/metadata/drone_compatibility_test.go index 2e06fdabf..228c87b0a 100644 --- a/pipeline/frontend/metadata/drone_compatibility_test.go +++ b/pipeline/frontend/metadata/drone_compatibility_test.go @@ -151,6 +151,8 @@ CI_PREV_COMMIT_REF=refs/heads/main CI_PREV_COMMIT_REFSPEC= CI_PREV_COMMIT_SHA=8826c98181353075bbeee8f99b400496488e3523 CI_PREV_COMMIT_URL=http://1.2.3.4:3000/test/woodpecker-test/commit/8826c98181353075bbeee8f99b400496488e3523 +CI_PREV_COMMIT_SOURCE_BRANCH= +CI_PREV_COMMIT_TARGET_BRANCH= CI_PREV_PIPELINE_CREATED=1721086039 CI_PREV_PIPELINE_DEPLOY_TARGET= CI_PREV_PIPELINE_DEPLOY_TASK= diff --git a/pipeline/frontend/metadata/environment.go b/pipeline/frontend/metadata/environment.go index ccb4396b8..9b0cf1656 100644 --- a/pipeline/frontend/metadata/environment.go +++ b/pipeline/frontend/metadata/environment.go @@ -30,19 +30,26 @@ var ( maxChangedFiles = 500 ) -// Environ returns the metadata as a map of environment variables. -func (m *Metadata) Environ() map[string]string { +func getSourceTargetBranches(refspec string) (string, string) { var ( sourceBranch string targetBranch string ) - branchParts := strings.Split(m.Curr.Commit.Refspec, ":") + branchParts := strings.Split(refspec, ":") if len(branchParts) == 2 { //nolint:mnd sourceBranch = branchParts[0] targetBranch = branchParts[1] } + return sourceBranch, targetBranch +} + +// Environ returns the metadata as a map of environment variables. +func (m *Metadata) Environ() map[string]string { + sourceBranch, targetBranch := getSourceTargetBranches(m.Curr.Commit.Refspec) + prevSourceBranch, prevTargetBranch := getSourceTargetBranches(m.Prev.Commit.Refspec) + params := map[string]string{ "CI": m.Sys.Name, "CI_REPO": path.Join(m.Repo.Owner, m.Repo.Name), @@ -102,6 +109,8 @@ func (m *Metadata) Environ() map[string]string { "CI_PREV_COMMIT_AUTHOR": m.Prev.Commit.Author.Name, "CI_PREV_COMMIT_AUTHOR_EMAIL": m.Prev.Commit.Author.Email, "CI_PREV_COMMIT_AUTHOR_AVATAR": m.Prev.Commit.Author.Avatar, + "CI_PREV_COMMIT_SOURCE_BRANCH": prevSourceBranch, + "CI_PREV_COMMIT_TARGET_BRANCH": prevTargetBranch, "CI_PREV_PIPELINE_NUMBER": strconv.FormatInt(m.Prev.Number, 10), "CI_PREV_PIPELINE_PARENT": strconv.FormatInt(m.Prev.Parent, 10), diff --git a/server/api/login.go b/server/api/login.go index ebe6cf7b3..57bd91eae 100644 --- a/server/api/login.go +++ b/server/api/login.go @@ -297,54 +297,3 @@ func GetLogout(c *gin.Context) { httputil.DelCookie(c.Writer, c.Request, "user_last") c.Redirect(http.StatusSeeOther, server.Config.Server.RootPath+"/") } - -// TODO: remove in 3.0 -func DeprecatedGetLoginToken(c *gin.Context) { - _store := store.FromContext(c) - - _forge, err := server.Config.Services.Manager.ForgeByID(1) - if err != nil { - log.Error().Err(err).Msg("Cannot get main forge") - c.AbortWithStatus(http.StatusInternalServerError) - return - } - - in := &tokenPayload{} - err = c.Bind(in) - if err != nil { - _ = c.AbortWithError(http.StatusBadRequest, err) - return - } - - login, err := _forge.Auth(c, in.Access, in.Refresh) - if err != nil { - _ = c.AbortWithError(http.StatusUnauthorized, err) - return - } - - user, err := _store.GetUserLogin(login) - if err != nil { - handleDBError(c, err) - return - } - - exp := time.Now().Add(server.Config.Server.SessionExpires).Unix() - newToken := token.New(token.SessToken) - newToken.Set("user-id", strconv.FormatInt(user.ID, 10)) - tokenStr, err := newToken.SignExpires(user.Hash, exp) - if err != nil { - _ = c.AbortWithError(http.StatusInternalServerError, err) - return - } - - c.JSON(http.StatusOK, &tokenPayload{ - Access: tokenStr, - Expires: exp - time.Now().Unix(), - }) -} - -type tokenPayload struct { - Access string `json:"access_token,omitempty"` - Refresh string `json:"refresh_token,omitempty"` - Expires int64 `json:"expires_in,omitempty"` -} diff --git a/server/pipeline/stepbuilder/metadata_test.go b/server/pipeline/stepbuilder/metadata_test.go index a0d451425..af8978e27 100644 --- a/server/pipeline/stepbuilder/metadata_test.go +++ b/server/pipeline/stepbuilder/metadata_test.go @@ -49,7 +49,7 @@ func TestMetadataFromStruct(t *testing.T) { "CI_COMMIT_TAG": "", "CI_COMMIT_TARGET_BRANCH": "", "CI_COMMIT_URL": "", "CI_FORGE_TYPE": "", "CI_FORGE_URL": "", "CI_PIPELINE_CREATED": "0", "CI_PIPELINE_DEPLOY_TARGET": "", "CI_PIPELINE_DEPLOY_TASK": "", "CI_PIPELINE_EVENT": "", "CI_PIPELINE_FINISHED": "0", "CI_PIPELINE_FILES": "[]", "CI_PIPELINE_NUMBER": "0", "CI_PIPELINE_PARENT": "0", "CI_PIPELINE_STARTED": "0", "CI_PIPELINE_STATUS": "", "CI_PIPELINE_URL": "/repos/0/pipeline/0", "CI_PIPELINE_FORGE_URL": "", - "CI_PREV_COMMIT_AUTHOR": "", "CI_PREV_COMMIT_AUTHOR_AVATAR": "", "CI_PREV_COMMIT_AUTHOR_EMAIL": "", "CI_PREV_COMMIT_BRANCH": "", + "CI_PREV_COMMIT_AUTHOR": "", "CI_PREV_COMMIT_AUTHOR_AVATAR": "", "CI_PREV_COMMIT_AUTHOR_EMAIL": "", "CI_PREV_COMMIT_BRANCH": "", "CI_PREV_COMMIT_SOURCE_BRANCH": "", "CI_PREV_COMMIT_TARGET_BRANCH": "", "CI_PREV_COMMIT_MESSAGE": "", "CI_PREV_COMMIT_REF": "", "CI_PREV_COMMIT_REFSPEC": "", "CI_PREV_COMMIT_SHA": "", "CI_PREV_COMMIT_URL": "", "CI_PREV_PIPELINE_CREATED": "0", "CI_PREV_PIPELINE_DEPLOY_TARGET": "", "CI_PREV_PIPELINE_DEPLOY_TASK": "", "CI_PREV_PIPELINE_EVENT": "", "CI_PREV_PIPELINE_FINISHED": "0", "CI_PREV_PIPELINE_NUMBER": "0", "CI_PREV_PIPELINE_PARENT": "0", "CI_PREV_PIPELINE_STARTED": "0", "CI_PREV_PIPELINE_STATUS": "", "CI_PREV_PIPELINE_URL": "/repos/0/pipeline/0", "CI_PREV_PIPELINE_FORGE_URL": "", "CI_REPO": "", "CI_REPO_CLONE_URL": "", "CI_REPO_CLONE_SSH_URL": "", "CI_REPO_DEFAULT_BRANCH": "", "CI_REPO_REMOTE_ID": "", @@ -84,7 +84,7 @@ func TestMetadataFromStruct(t *testing.T) { "CI_COMMIT_TAG": "", "CI_COMMIT_TARGET_BRANCH": "", "CI_COMMIT_URL": "", "CI_FORGE_TYPE": "gitea", "CI_FORGE_URL": "https://gitea.com", "CI_PIPELINE_CREATED": "0", "CI_PIPELINE_DEPLOY_TARGET": "", "CI_PIPELINE_DEPLOY_TASK": "", "CI_PIPELINE_EVENT": "", "CI_PIPELINE_FINISHED": "0", "CI_PIPELINE_FILES": `["test.go","markdown file.md"]`, "CI_PIPELINE_NUMBER": "3", "CI_PIPELINE_PARENT": "0", "CI_PIPELINE_STARTED": "0", "CI_PIPELINE_STATUS": "", "CI_PIPELINE_URL": "https://example.com/repos/0/pipeline/3", "CI_PIPELINE_FORGE_URL": "", - "CI_PREV_COMMIT_AUTHOR": "", "CI_PREV_COMMIT_AUTHOR_AVATAR": "", "CI_PREV_COMMIT_AUTHOR_EMAIL": "", "CI_PREV_COMMIT_BRANCH": "", + "CI_PREV_COMMIT_AUTHOR": "", "CI_PREV_COMMIT_AUTHOR_AVATAR": "", "CI_PREV_COMMIT_AUTHOR_EMAIL": "", "CI_PREV_COMMIT_BRANCH": "", "CI_PREV_COMMIT_SOURCE_BRANCH": "", "CI_PREV_COMMIT_TARGET_BRANCH": "", "CI_PREV_COMMIT_MESSAGE": "", "CI_PREV_COMMIT_REF": "", "CI_PREV_COMMIT_REFSPEC": "", "CI_PREV_COMMIT_SHA": "", "CI_PREV_COMMIT_URL": "", "CI_PREV_PIPELINE_CREATED": "0", "CI_PREV_PIPELINE_DEPLOY_TARGET": "", "CI_PREV_PIPELINE_DEPLOY_TASK": "", "CI_PREV_PIPELINE_EVENT": "", "CI_PREV_PIPELINE_FINISHED": "0", "CI_PREV_PIPELINE_NUMBER": "2", "CI_PREV_PIPELINE_PARENT": "0", "CI_PREV_PIPELINE_STARTED": "0", "CI_PREV_PIPELINE_STATUS": "", "CI_PREV_PIPELINE_URL": "https://example.com/repos/0/pipeline/2", "CI_PREV_PIPELINE_FORGE_URL": "", "CI_REPO": "testUser/testRepo", "CI_REPO_CLONE_URL": "https://gitea.com/testUser/testRepo.git", "CI_REPO_CLONE_SSH_URL": "git@gitea.com:testUser/testRepo.git", diff --git a/server/router/api.go b/server/router/api.go index 3fb760760..a7c9f8f5e 100644 --- a/server/router/api.go +++ b/server/router/api.go @@ -129,13 +129,6 @@ func apiRoutes(e *gin.RouterGroup) { repo.PATCH("/registries/:registry", session.MustPush, api.PatchRegistry) repo.DELETE("/registries/:registry", session.MustPush, api.DeleteRegistry) - // TODO: remove with 3.x - repo.GET("/registry", session.MustPush, api.GetRegistryList) - repo.POST("/registry", session.MustPush, api.PostRegistry) - repo.GET("/registry/:registry", session.MustPush, api.GetRegistry) - repo.PATCH("/registry/:registry", session.MustPush, api.PatchRegistry) - repo.DELETE("/registry/:registry", session.MustPush, api.DeleteRegistry) - // requires push permissions repo.GET("/cron", session.MustPush, api.GetCronList) repo.POST("/cron", session.MustPush, api.PostCron) diff --git a/server/router/router.go b/server/router/router.go index 89e1046f9..c873062d3 100644 --- a/server/router/router.go +++ b/server/router/router.go @@ -62,7 +62,6 @@ func Load(noRouteHandler http.HandlerFunc, middleware ...gin.HandlerFunc) http.H { auth.GET("", api.HandleAuth) auth.POST("", api.HandleAuth) - auth.POST("/token", api.DeprecatedGetLoginToken) } base.GET("/metrics", metrics.PromHandler()) diff --git a/server/services/config/http.go b/server/services/config/http.go index 3eb512cd4..33dcfc756 100644 --- a/server/services/config/http.go +++ b/server/services/config/http.go @@ -38,10 +38,9 @@ type configData struct { } type requestStructure struct { - Repo *model.Repo `json:"repo"` - Pipeline *model.Pipeline `json:"pipeline"` - Netrc *model.Netrc `json:"netrc"` - Configuration []*configData `json:"configs"` // TODO: deprecate in favor of netrc and remove in next major release + Repo *model.Repo `json:"repo"` + Pipeline *model.Pipeline `json:"pipeline"` + Netrc *model.Netrc `json:"netrc"` } type responseStructure struct { @@ -53,11 +52,6 @@ func NewHTTP(endpoint string, privateKey ed25519.PrivateKey) Service { } func (h *http) Fetch(ctx context.Context, forge forge.Forge, user *model.User, repo *model.Repo, pipeline *model.Pipeline, oldConfigData []*types.FileMeta, _ bool) ([]*types.FileMeta, error) { - currentConfigs := make([]*configData, len(oldConfigData)) - for i, pipe := range oldConfigData { - currentConfigs[i] = &configData{Name: pipe.Name, Data: string(pipe.Data)} - } - netrc, err := forge.Netrc(user, repo) if err != nil { return nil, fmt.Errorf("could not get Netrc data from forge: %w", err) @@ -65,10 +59,9 @@ func (h *http) Fetch(ctx context.Context, forge forge.Forge, user *model.User, r response := new(responseStructure) body := requestStructure{ - Repo: repo, - Pipeline: pipeline, - Configuration: currentConfigs, - Netrc: netrc, + Repo: repo, + Pipeline: pipeline, + Netrc: netrc, } status, err := utils.Send(ctx, net_http.MethodPost, h.endpoint, h.privateKey, body, response) diff --git a/web/src/assets/locales/de.json b/web/src/assets/locales/de.json index e8bdab397..8507dd95f 100644 --- a/web/src/assets/locales/de.json +++ b/web/src/assets/locales/de.json @@ -226,7 +226,8 @@ "title": "Zusätzliche Pipeline-Variablen", "value": "Variablenwert", "delete": "Variable löschen" - } + }, + "show_pipelines": "Pipelines anzeigen" }, "not_allowed": "Zugriff auf dieses Repository nicht erlaubt", "open_in_forge": "Repository in der Forge öffnen", @@ -296,7 +297,8 @@ "log_delete_confirm": "Möchtest du die Logs diesen Schrittes wirklich löschen?", "log_delete_error": "Es gab einen Fehler beim Löschen der Logs des Schrittes", "duration": "Pipeline-Dauer", - "created": "Erstellt: {created}" + "created": "Erstellt: {created}", + "no_logs": "Keine Logs" }, "pull_requests": "Pull-Requests", "settings": { diff --git a/web/src/assets/locales/ru.json b/web/src/assets/locales/ru.json index ef5ea630e..68716b4dc 100644 --- a/web/src/assets/locales/ru.json +++ b/web/src/assets/locales/ru.json @@ -225,7 +225,8 @@ "title": "Дополнительные переменные для конвейера", "value": "Значение переменной", "delete": "Удалить переменную" - } + }, + "show_pipelines": "Показать конвейеры" }, "not_allowed": "У вас нет прав для доступа к этому репозиторию", "open_in_forge": "Открыть репозиторий в платформе разработки",