From b952b9d9ccc8b05b65b42be2f485c1649e05e9b6 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Wed, 20 Sep 2023 11:58:40 +0200 Subject: [PATCH 1/3] Some updates to the API for archived repos --- models/git/protected_branch.go | 14 ++- models/repo/repo.go | 18 ++++ modules/context/api.go | 6 ++ routers/api/v1/api.go | 24 ++--- routers/api/v1/repo/branch.go | 25 ++--- routers/api/v1/repo/file.go | 8 ++ routers/api/v1/repo/issue.go | 2 + routers/api/v1/repo/issue_attachment.go | 6 ++ routers/api/v1/repo/issue_comment.go | 5 +- .../api/v1/repo/issue_comment_attachment.go | 8 +- routers/api/v1/repo/issue_dependency.go | 4 + routers/api/v1/repo/patch.go | 2 + routers/api/v1/repo/pull.go | 6 ++ routers/api/v1/repo/tag.go | 4 + routers/api/v1/repo/wiki.go | 6 ++ routers/web/repo/setting/protected_branch.go | 2 +- services/release/release.go | 10 ++ services/repository/branch.go | 20 ++++ services/repository/files/patch.go | 5 + services/repository/files/update.go | 5 + services/wiki/wiki.go | 10 ++ templates/swagger/v1_json.tmpl | 95 +++++++++++++++++++ 22 files changed, 251 insertions(+), 34 deletions(-) diff --git a/models/git/protected_branch.go b/models/git/protected_branch.go index 5ed1003749749..87439e8c84e27 100644 --- a/models/git/protected_branch.go +++ b/models/git/protected_branch.go @@ -315,6 +315,11 @@ type WhitelistOptions struct { // This function also performs check if whitelist user and team's IDs have been changed // to avoid unnecessary whitelist delete and regenerate. func UpdateProtectBranch(ctx context.Context, repo *repo_model.Repository, protectBranch *ProtectedBranch, opts WhitelistOptions) (err error) { + err = repo.GetIsArchivedError() + if err != nil { + return err + } + if err = repo.LoadOwner(ctx); err != nil { return fmt.Errorf("LoadOwner: %v", err) } @@ -445,9 +450,14 @@ func updateTeamWhitelist(ctx context.Context, repo *repo_model.Repository, curre } // DeleteProtectedBranch removes ProtectedBranch relation between the user and repository. -func DeleteProtectedBranch(ctx context.Context, repoID, id int64) (err error) { +func DeleteProtectedBranch(ctx context.Context, repo *repo_model.Repository, id int64) (err error) { + err = repo.GetIsArchivedError() + if err != nil { + return err + } + protectedBranch := &ProtectedBranch{ - RepoID: repoID, + RepoID: repo.ID, ID: id, } diff --git a/models/repo/repo.go b/models/repo/repo.go index 5ebc7bfc24208..2fc50f3f046bb 100644 --- a/models/repo/repo.go +++ b/models/repo/repo.go @@ -47,6 +47,16 @@ func (err ErrUserDoesNotHaveAccessToRepo) Unwrap() error { return util.ErrPermissionDenied } +type ErrRepoIsArchived struct { + ID int64 + Name string + Owner string +} + +func (err ErrRepoIsArchived) Error() string { + return fmt.Sprint("repo %s/%s is archived", err.Owner, err.Name) +} + var ( reservedRepoNames = []string{".", "..", "-"} reservedRepoPatterns = []string{"*.git", "*.wiki", "*.rss", "*.atom"} @@ -654,6 +664,14 @@ func (repo *Repository) GetTrustModel() TrustModelType { return trustModel } +// GetIsArchivedError returns ErrRepoIsArchived is the repo is archived +func (repo *Repository) GetIsArchivedError() error { + if repo.IsArchived { + return ErrRepoIsArchived{ID: repo.ID, Name: repo.Name, Owner: repo.OwnerName} + } + return nil +} + // __________ .__ __ // \______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__. // | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | | diff --git a/modules/context/api.go b/modules/context/api.go index 044ec51b56599..52a8f4eb1c24e 100644 --- a/modules/context/api.go +++ b/modules/context/api.go @@ -101,6 +101,12 @@ type APIRedirect struct{} // swagger:response string type APIString string +// APIRepoArchivedError is error that is raised when a repo is archived +// swagger:response repoArchived +type APIRepoArchivedError struct { + APIError +} + // ServerError responds with error message, status is 500 func (ctx *APIContext) ServerError(title string, err error) { ctx.Error(http.StatusInternalServerError, title, err) diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 763d56ecd2622..b480ea2f8d6ae 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -675,7 +675,7 @@ func mustEnableWiki(ctx *context.APIContext) { func mustNotBeArchived(ctx *context.APIContext) { if ctx.Repo.Repository.IsArchived { - ctx.NotFound() + ctx.Error(http.StatusLocked, "RepoArchived", fmt.Errorf("repo %s/%s is archived", ctx.Repo.Repository.OwnerName, ctx.Repo.Repository.Name)) return } } @@ -1108,23 +1108,23 @@ func Routes() *web.Route { m.Group("/branches", func() { m.Get("", repo.ListBranches) m.Get("/*", repo.GetBranch) - m.Delete("/*", reqToken(), reqRepoWriter(unit.TypeCode), repo.DeleteBranch) - m.Post("", reqToken(), reqRepoWriter(unit.TypeCode), bind(api.CreateBranchRepoOption{}), repo.CreateBranch) + m.Delete("/*", reqToken(), reqRepoWriter(unit.TypeCode), mustNotBeArchived, repo.DeleteBranch) + m.Post("", reqToken(), reqRepoWriter(unit.TypeCode), mustNotBeArchived, bind(api.CreateBranchRepoOption{}), repo.CreateBranch) }, context.ReferencesGitRepo(), reqRepoReader(unit.TypeCode)) m.Group("/branch_protections", func() { m.Get("", repo.ListBranchProtections) - m.Post("", bind(api.CreateBranchProtectionOption{}), repo.CreateBranchProtection) + m.Post("", bind(api.CreateBranchProtectionOption{}), mustNotBeArchived, repo.CreateBranchProtection) m.Group("/{name}", func() { m.Get("", repo.GetBranchProtection) - m.Patch("", bind(api.EditBranchProtectionOption{}), repo.EditBranchProtection) + m.Patch("", bind(api.EditBranchProtectionOption{}), mustNotBeArchived, repo.EditBranchProtection) m.Delete("", repo.DeleteBranchProtection) }) }, reqToken(), reqAdmin()) m.Group("/tags", func() { m.Get("", repo.ListTags) m.Get("/*", repo.GetTag) - m.Post("", reqToken(), reqRepoWriter(unit.TypeCode), bind(api.CreateTagOption{}), repo.CreateTag) - m.Delete("/*", reqToken(), repo.DeleteTag) + m.Post("", reqToken(), reqRepoWriter(unit.TypeCode), mustNotBeArchived, bind(api.CreateTagOption{}), repo.CreateTag) + m.Delete("/*", reqToken(), reqRepoWriter(unit.TypeCode), mustNotBeArchived, repo.DeleteTag) }, reqRepoReader(unit.TypeCode), context.ReferencesGitRepo(true)) m.Group("/keys", func() { m.Combo("").Get(repo.ListDeployKeys). @@ -1245,15 +1245,15 @@ func Routes() *web.Route { m.Get("/tags/{sha}", repo.GetAnnotatedTag) m.Get("/notes/{sha}", repo.GetNote) }, context.ReferencesGitRepo(true), reqRepoReader(unit.TypeCode)) - m.Post("/diffpatch", reqRepoWriter(unit.TypeCode), reqToken(), bind(api.ApplyDiffPatchFileOptions{}), repo.ApplyDiffPatch) + m.Post("/diffpatch", reqRepoWriter(unit.TypeCode), reqToken(), bind(api.ApplyDiffPatchFileOptions{}), mustNotBeArchived, repo.ApplyDiffPatch) m.Group("/contents", func() { m.Get("", repo.GetContentsList) - m.Post("", reqToken(), bind(api.ChangeFilesOptions{}), reqRepoBranchWriter, repo.ChangeFiles) + m.Post("", reqToken(), bind(api.ChangeFilesOptions{}), reqRepoBranchWriter, mustNotBeArchived, repo.ChangeFiles) m.Get("/*", repo.GetContents) m.Group("/*", func() { - m.Post("", bind(api.CreateFileOptions{}), reqRepoBranchWriter, repo.CreateFile) - m.Put("", bind(api.UpdateFileOptions{}), reqRepoBranchWriter, repo.UpdateFile) - m.Delete("", bind(api.DeleteFileOptions{}), reqRepoBranchWriter, repo.DeleteFile) + m.Post("", bind(api.CreateFileOptions{}), reqRepoBranchWriter, mustNotBeArchived, repo.CreateFile) + m.Put("", bind(api.UpdateFileOptions{}), reqRepoBranchWriter, mustNotBeArchived, repo.UpdateFile) + m.Delete("", bind(api.DeleteFileOptions{}), reqRepoBranchWriter, mustNotBeArchived, repo.DeleteFile) }, reqToken()) }, reqRepoReader(unit.TypeCode)) m.Get("/signing-key.gpg", misc.SigningKey) diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go index c851525c0f023..90d65f4f310df 100644 --- a/routers/api/v1/repo/branch.go +++ b/routers/api/v1/repo/branch.go @@ -117,17 +117,13 @@ func DeleteBranch(ctx *context.APIContext) { // "$ref": "#/responses/error" // "404": // "$ref": "#/responses/notFound" - + // "423": + // "$ref": "#/responses/repoArchived" if ctx.Repo.Repository.IsEmpty { ctx.Error(http.StatusNotFound, "", "Git Repository is empty.") return } - if ctx.Repo.Repository.IsArchived { - ctx.Error(http.StatusForbidden, "", "Git Repository is archived.") - return - } - if ctx.Repo.Repository.IsMirror { ctx.Error(http.StatusForbidden, "", "Git Repository is a mirror.") return @@ -157,10 +153,6 @@ func DeleteBranch(ctx *context.APIContext) { } } - if ctx.Repo.Repository.IsArchived { - ctx.Error(http.StatusForbidden, "IsArchived", fmt.Errorf("can not delete branch of an archived repository")) - return - } if ctx.Repo.Repository.IsMirror { ctx.Error(http.StatusForbidden, "IsMirrored", fmt.Errorf("can not delete branch of an mirror repository")) return @@ -216,17 +208,14 @@ func CreateBranch(ctx *context.APIContext) { // description: The old branch does not exist. // "409": // description: The branch with the same name already exists. + // "423": + // "$ref": "#/responses/repoArchived" if ctx.Repo.Repository.IsEmpty { ctx.Error(http.StatusNotFound, "", "Git Repository is empty.") return } - if ctx.Repo.Repository.IsArchived { - ctx.Error(http.StatusForbidden, "", "Git Repository is archived.") - return - } - if ctx.Repo.Repository.IsMirror { ctx.Error(http.StatusForbidden, "", "Git Repository is a mirror.") return @@ -519,6 +508,8 @@ func CreateBranchProtection(ctx *context.APIContext) { // "$ref": "#/responses/notFound" // "422": // "$ref": "#/responses/validationError" + // "423": + // "$ref": "#/responses/repoArchived" form := web.GetForm(ctx).(*api.CreateBranchProtectionOption) repo := ctx.Repo.Repository @@ -727,6 +718,8 @@ func EditBranchProtection(ctx *context.APIContext) { // "$ref": "#/responses/notFound" // "422": // "$ref": "#/responses/validationError" + // "423": + // "$ref": "#/responses/repoArchived" form := web.GetForm(ctx).(*api.EditBranchProtectionOption) repo := ctx.Repo.Repository bpName := ctx.Params(":name") @@ -1004,7 +997,7 @@ func DeleteBranchProtection(ctx *context.APIContext) { return } - if err := git_model.DeleteProtectedBranch(ctx, ctx.Repo.Repository.ID, bp.ID); err != nil { + if err := git_model.DeleteProtectedBranch(ctx, ctx.Repo.Repository, bp.ID); err != nil { ctx.Error(http.StatusInternalServerError, "DeleteProtectedBranch", err) return } diff --git a/routers/api/v1/repo/file.go b/routers/api/v1/repo/file.go index ea311c3202924..d8a08b70c9709 100644 --- a/routers/api/v1/repo/file.go +++ b/routers/api/v1/repo/file.go @@ -450,6 +450,8 @@ func ChangeFiles(ctx *context.APIContext) { // "$ref": "#/responses/notFound" // "422": // "$ref": "#/responses/error" + // "423": + // "$ref": "#/responses/repoArchived" apiOpts := web.GetForm(ctx).(*api.ChangeFilesOptions) @@ -550,6 +552,8 @@ func CreateFile(ctx *context.APIContext) { // "$ref": "#/responses/notFound" // "422": // "$ref": "#/responses/error" + // "423": + // "$ref": "#/responses/repoArchived" apiOpts := web.GetForm(ctx).(*api.CreateFileOptions) @@ -646,6 +650,8 @@ func UpdateFile(ctx *context.APIContext) { // "$ref": "#/responses/notFound" // "422": // "$ref": "#/responses/error" + // "423": + // "$ref": "#/responses/repoArchived" apiOpts := web.GetForm(ctx).(*api.UpdateFileOptions) if ctx.Repo.Repository.IsEmpty { ctx.Error(http.StatusUnprocessableEntity, "RepoIsEmpty", fmt.Errorf("repo is empty")) @@ -806,6 +812,8 @@ func DeleteFile(ctx *context.APIContext) { // "$ref": "#/responses/error" // "404": // "$ref": "#/responses/error" + // "423": + // "$ref": "#/responses/repoArchived" apiOpts := web.GetForm(ctx).(*api.DeleteFileOptions) if !canWriteFiles(ctx, apiOpts.BranchName) { diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index 05dfa45e3d94c..1c615912ff97f 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -631,6 +631,8 @@ func CreateIssue(ctx *context.APIContext) { // "$ref": "#/responses/error" // "422": // "$ref": "#/responses/validationError" + // "423": + // "$ref": "#/responses/repoArchived" form := web.GetForm(ctx).(*api.CreateIssueOption) var deadlineUnix timeutil.TimeStamp if form.Deadline != nil && ctx.Repo.CanWrite(unit.TypeIssues) { diff --git a/routers/api/v1/repo/issue_attachment.go b/routers/api/v1/repo/issue_attachment.go index 60e554990f864..9d39c4a4c812a 100644 --- a/routers/api/v1/repo/issue_attachment.go +++ b/routers/api/v1/repo/issue_attachment.go @@ -153,6 +153,8 @@ func CreateIssueAttachment(ctx *context.APIContext) { // "$ref": "#/responses/error" // "404": // "$ref": "#/responses/error" + // "423": + // "$ref": "#/responses/repoArchived" issue := getIssueFromContext(ctx) if issue == nil { @@ -238,6 +240,8 @@ func EditIssueAttachment(ctx *context.APIContext) { // "$ref": "#/responses/Attachment" // "404": // "$ref": "#/responses/error" + // "423": + // "$ref": "#/responses/repoArchived" attachment := getIssueAttachmentSafeWrite(ctx) if attachment == nil { @@ -292,6 +296,8 @@ func DeleteIssueAttachment(ctx *context.APIContext) { // "$ref": "#/responses/empty" // "404": // "$ref": "#/responses/error" + // "423": + // "$ref": "#/responses/repoArchived" attachment := getIssueAttachmentSafeWrite(ctx) if attachment == nil { diff --git a/routers/api/v1/repo/issue_comment.go b/routers/api/v1/repo/issue_comment.go index c9179e69db626..607774d05c469 100644 --- a/routers/api/v1/repo/issue_comment.go +++ b/routers/api/v1/repo/issue_comment.go @@ -358,6 +358,8 @@ func CreateIssueComment(ctx *context.APIContext) { // "$ref": "#/responses/forbidden" // "404": // "$ref": "#/responses/notFound" + // "423": + // "$ref": "#/responses/repoArchived" form := web.GetForm(ctx).(*api.CreateIssueCommentOption) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) if err != nil { @@ -486,7 +488,8 @@ func EditIssueComment(ctx *context.APIContext) { // "$ref": "#/responses/forbidden" // "404": // "$ref": "#/responses/notFound" - + // "423": + // "$ref": "#/responses/repoArchived" form := web.GetForm(ctx).(*api.EditIssueCommentOption) editIssueComment(ctx, *form) } diff --git a/routers/api/v1/repo/issue_comment_attachment.go b/routers/api/v1/repo/issue_comment_attachment.go index c30e8278dbc98..8c92454b33acb 100644 --- a/routers/api/v1/repo/issue_comment_attachment.go +++ b/routers/api/v1/repo/issue_comment_attachment.go @@ -156,6 +156,8 @@ func CreateIssueCommentAttachment(ctx *context.APIContext) { // "$ref": "#/responses/error" // "404": // "$ref": "#/responses/error" + // "423": + // "$ref": "#/responses/repoArchived" // Check if comment exists and load comment comment := getIssueCommentSafe(ctx) @@ -245,7 +247,8 @@ func EditIssueCommentAttachment(ctx *context.APIContext) { // "$ref": "#/responses/Attachment" // "404": // "$ref": "#/responses/error" - + // "423": + // "$ref": "#/responses/repoArchived" attach := getIssueCommentAttachmentSafeWrite(ctx) if attach == nil { return @@ -297,7 +300,8 @@ func DeleteIssueCommentAttachment(ctx *context.APIContext) { // "$ref": "#/responses/empty" // "404": // "$ref": "#/responses/error" - + // "423": + // "$ref": "#/responses/repoArchived" attach := getIssueCommentAttachmentSafeWrite(ctx) if attach == nil { return diff --git a/routers/api/v1/repo/issue_dependency.go b/routers/api/v1/repo/issue_dependency.go index 5ea3836da1afc..29823855a154e 100644 --- a/routers/api/v1/repo/issue_dependency.go +++ b/routers/api/v1/repo/issue_dependency.go @@ -187,6 +187,8 @@ func CreateIssueDependency(ctx *context.APIContext) { // "$ref": "#/responses/Issue" // "404": // description: the issue does not exist + // "423": + // "$ref": "#/responses/repoArchived" // We want to make <:index> depend on
, i.e. <:index> is the target target := getParamsIssue(ctx) @@ -246,6 +248,8 @@ func RemoveIssueDependency(ctx *context.APIContext) { // "$ref": "#/responses/Issue" // "404": // "$ref": "#/responses/notFound" + // "423": + // "$ref": "#/responses/repoArchived" // We want to make <:index> depend on , i.e. <:index> is the target target := getParamsIssue(ctx) diff --git a/routers/api/v1/repo/patch.go b/routers/api/v1/repo/patch.go index 080908ab7edc1..6f74879f219b9 100644 --- a/routers/api/v1/repo/patch.go +++ b/routers/api/v1/repo/patch.go @@ -47,6 +47,8 @@ func ApplyDiffPatch(ctx *context.APIContext) { // "$ref": "#/responses/FileResponse" // "404": // "$ref": "#/responses/notFound" + // "423": + // "$ref": "#/responses/repoArchived" apiOpts := web.GetForm(ctx).(*api.ApplyDiffPatchFileOptions) opts := &files.ApplyDiffPatchOptions{ diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 4f22a059a13c6..1983cb0fdb445 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -282,6 +282,8 @@ func CreatePullRequest(ctx *context.APIContext) { // "$ref": "#/responses/error" // "422": // "$ref": "#/responses/validationError" + // "423": + // "$ref": "#/responses/repoArchived" form := *web.GetForm(ctx).(*api.CreatePullRequestOption) if form.Head == form.Base { @@ -741,6 +743,8 @@ func MergePullRequest(ctx *context.APIContext) { // "$ref": "#/responses/empty" // "409": // "$ref": "#/responses/error" + // "423": + // "$ref": "#/responses/repoArchived" form := web.GetForm(ctx).(*forms.MergePullRequestForm) @@ -1196,6 +1200,8 @@ func CancelScheduledAutoMerge(ctx *context.APIContext) { // "$ref": "#/responses/forbidden" // "404": // "$ref": "#/responses/notFound" + // "423": + // "$ref": "#/responses/repoArchived" pullIndex := ctx.ParamsInt64(":index") pull, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, pullIndex) diff --git a/routers/api/v1/repo/tag.go b/routers/api/v1/repo/tag.go index 0c0a73698f749..c1c8777ddeda3 100644 --- a/routers/api/v1/repo/tag.go +++ b/routers/api/v1/repo/tag.go @@ -184,6 +184,8 @@ func CreateTag(ctx *context.APIContext) { // "$ref": "#/responses/empty" // "409": // "$ref": "#/responses/conflict" + // "423": + // "$ref": "#/responses/repoArchived" form := web.GetForm(ctx).(*api.CreateTagOption) // If target is not provided use default branch @@ -251,6 +253,8 @@ func DeleteTag(ctx *context.APIContext) { // "$ref": "#/responses/empty" // "409": // "$ref": "#/responses/conflict" + // "423": + // "$ref": "#/responses/repoArchived" tagName := ctx.Params("*") tag, err := repo_model.GetRelease(ctx.Repo.Repository.ID, tagName) diff --git a/routers/api/v1/repo/wiki.go b/routers/api/v1/repo/wiki.go index 4ea3fbd11d680..e7aea12b0617b 100644 --- a/routers/api/v1/repo/wiki.go +++ b/routers/api/v1/repo/wiki.go @@ -52,6 +52,8 @@ func NewWikiPage(ctx *context.APIContext) { // "$ref": "#/responses/forbidden" // "404": // "$ref": "#/responses/notFound" + // "423": + // "$ref": "#/responses/repoArchived" form := web.GetForm(ctx).(*api.CreateWikiPageOptions) @@ -128,6 +130,8 @@ func EditWikiPage(ctx *context.APIContext) { // "$ref": "#/responses/forbidden" // "404": // "$ref": "#/responses/notFound" + // "423": + // "$ref": "#/responses/repoArchived" form := web.GetForm(ctx).(*api.CreateWikiPageOptions) @@ -234,6 +238,8 @@ func DeleteWikiPage(ctx *context.APIContext) { // "$ref": "#/responses/forbidden" // "404": // "$ref": "#/responses/notFound" + // "423": + // "$ref": "#/responses/repoArchived" wikiName := wiki_service.WebPathFromRequest(ctx.PathParamRaw(":pageName")) diff --git a/routers/web/repo/setting/protected_branch.go b/routers/web/repo/setting/protected_branch.go index e0f2294a14f7c..3138f2327b28d 100644 --- a/routers/web/repo/setting/protected_branch.go +++ b/routers/web/repo/setting/protected_branch.go @@ -285,7 +285,7 @@ func DeleteProtectedBranchRulePost(ctx *context.Context) { return } - if err := git_model.DeleteProtectedBranch(ctx, ctx.Repo.Repository.ID, ruleID); err != nil { + if err := git_model.DeleteProtectedBranch(ctx, ctx.Repo.Repository, ruleID); err != nil { ctx.Flash.Error(ctx.Tr("repo.settings.remove_protected_branch_failed", rule.RuleName)) ctx.JSONRedirect(fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink)) return diff --git a/services/release/release.go b/services/release/release.go index ac3acc9085934..7cacd1045a070 100644 --- a/services/release/release.go +++ b/services/release/release.go @@ -25,6 +25,16 @@ import ( ) func createTag(ctx context.Context, gitRepo *git.Repository, rel *repo_model.Release, msg string) (bool, error) { + err := rel.LoadAttributes(ctx) + if err != nil { + return false, err + } + + err = rel.Repo.GetIsArchivedError() + if err != nil { + return false, err + } + var created bool // Only actual create when publish. if !rel.IsDraft { diff --git a/services/repository/branch.go b/services/repository/branch.go index 011dc5568ec0a..e6fb6249f58e0 100644 --- a/services/repository/branch.go +++ b/services/repository/branch.go @@ -29,6 +29,11 @@ import ( // CreateNewBranch creates a new repository branch func CreateNewBranch(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldBranchName, branchName string) (err error) { + err = repo.GetIsArchivedError() + if err != nil { + return err + } + // Check if branch name can be used if err := checkBranchName(ctx, repo, branchName); err != nil { return err @@ -246,6 +251,11 @@ func checkBranchName(ctx context.Context, repo *repo_model.Repository, name stri // CreateNewBranchFromCommit creates a new repository branch func CreateNewBranchFromCommit(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, commit, branchName string) (err error) { + err = repo.GetIsArchivedError() + if err != nil { + return err + } + // Check if branch name can be used if err := checkBranchName(ctx, repo, branchName); err != nil { return err @@ -267,6 +277,11 @@ func CreateNewBranchFromCommit(ctx context.Context, doer *user_model.User, repo // RenameBranch rename a branch func RenameBranch(ctx context.Context, repo *repo_model.Repository, doer *user_model.User, gitRepo *git.Repository, from, to string) (string, error) { + err := repo.GetIsArchivedError() + if err != nil { + return "", err + } + if from == to { return "target_exist", nil } @@ -315,6 +330,11 @@ var ( // DeleteBranch delete branch func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, gitRepo *git.Repository, branchName string) error { + err := repo.GetIsArchivedError() + if err != nil { + return err + } + if branchName == repo.DefaultBranch { return ErrBranchIsDefault } diff --git a/services/repository/files/patch.go b/services/repository/files/patch.go index fdf0b32f1a1d3..fad478e9b3733 100644 --- a/services/repository/files/patch.go +++ b/services/repository/files/patch.go @@ -95,6 +95,11 @@ func (opts *ApplyDiffPatchOptions) Validate(ctx context.Context, repo *repo_mode // ApplyDiffPatch applies a patch to the given repository func ApplyDiffPatch(ctx context.Context, repo *repo_model.Repository, doer *user_model.User, opts *ApplyDiffPatchOptions) (*structs.FileResponse, error) { + err := repo.GetIsArchivedError() + if err != nil { + return nil, err + } + if err := opts.Validate(ctx, repo, doer); err != nil { return nil, err } diff --git a/services/repository/files/update.go b/services/repository/files/update.go index f01092d360d6c..f8329d6702afd 100644 --- a/services/repository/files/update.go +++ b/services/repository/files/update.go @@ -65,6 +65,11 @@ type RepoFileOptions struct { // ChangeRepoFiles adds, updates or removes multiple files in the given repository func ChangeRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *user_model.User, opts *ChangeRepoFilesOptions) (*structs.FilesResponse, error) { + err := repo.GetIsArchivedError() + if err != nil { + return nil, err + } + // If no branch name is set, assume default branch if opts.OldBranch == "" { opts.OldBranch = repo.DefaultBranch diff --git a/services/wiki/wiki.go b/services/wiki/wiki.go index c0183dd2b590a..f6de469a977ff 100644 --- a/services/wiki/wiki.go +++ b/services/wiki/wiki.go @@ -79,6 +79,11 @@ func prepareGitPath(gitRepo *git.Repository, wikiPath WebPath) (bool, string, er // updateWikiPage adds a new page or edits an existing page in repository wiki. func updateWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldWikiName, newWikiName WebPath, content, message string, isNew bool) (err error) { + err = repo.GetIsArchivedError() + if err != nil { + return err + } + if err = validateWebPath(newWikiName); err != nil { return err } @@ -238,6 +243,11 @@ func EditWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.R // DeleteWikiPage deletes a wiki page identified by its path. func DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, wikiName WebPath) (err error) { + err = repo.GetIsArchivedError() + if err != nil { + return err + } + wikiWorkingPool.CheckIn(fmt.Sprint(repo.ID)) defer wikiWorkingPool.CheckOut(fmt.Sprint(repo.ID)) diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 39c5a7fe117df..998f8a1b6109a 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -3719,6 +3719,9 @@ }, "422": { "$ref": "#/responses/validationError" + }, + "423": { + "$ref": "#/responses/repoArchived" } } } @@ -3857,6 +3860,9 @@ }, "422": { "$ref": "#/responses/validationError" + }, + "423": { + "$ref": "#/responses/repoArchived" } } } @@ -3952,6 +3958,9 @@ }, "409": { "description": "The branch with the same name already exists." + }, + "423": { + "$ref": "#/responses/repoArchived" } } } @@ -4039,6 +4048,9 @@ }, "404": { "$ref": "#/responses/notFound" + }, + "423": { + "$ref": "#/responses/repoArchived" } } } @@ -4596,6 +4608,9 @@ }, "422": { "$ref": "#/responses/error" + }, + "423": { + "$ref": "#/responses/repoArchived" } } } @@ -4703,6 +4718,9 @@ }, "422": { "$ref": "#/responses/error" + }, + "423": { + "$ref": "#/responses/repoArchived" } } }, @@ -4761,6 +4779,9 @@ }, "422": { "$ref": "#/responses/error" + }, + "423": { + "$ref": "#/responses/repoArchived" } } }, @@ -4819,6 +4840,9 @@ }, "404": { "$ref": "#/responses/error" + }, + "423": { + "$ref": "#/responses/repoArchived" } } } @@ -4866,6 +4890,9 @@ }, "404": { "$ref": "#/responses/notFound" + }, + "423": { + "$ref": "#/responses/repoArchived" } } } @@ -6137,6 +6164,9 @@ }, "422": { "$ref": "#/responses/validationError" + }, + "423": { + "$ref": "#/responses/repoArchived" } } } @@ -6352,6 +6382,9 @@ }, "404": { "$ref": "#/responses/notFound" + }, + "423": { + "$ref": "#/responses/repoArchived" } } } @@ -6457,6 +6490,9 @@ }, "404": { "$ref": "#/responses/error" + }, + "423": { + "$ref": "#/responses/repoArchived" } } } @@ -6559,6 +6595,9 @@ }, "404": { "$ref": "#/responses/error" + }, + "423": { + "$ref": "#/responses/repoArchived" } } }, @@ -6619,6 +6658,9 @@ }, "404": { "$ref": "#/responses/error" + }, + "423": { + "$ref": "#/responses/repoArchived" } } } @@ -7067,6 +7109,9 @@ }, "404": { "$ref": "#/responses/error" + }, + "423": { + "$ref": "#/responses/repoArchived" } } } @@ -7169,6 +7214,9 @@ }, "404": { "$ref": "#/responses/error" + }, + "423": { + "$ref": "#/responses/repoArchived" } } }, @@ -7229,6 +7277,9 @@ }, "404": { "$ref": "#/responses/error" + }, + "423": { + "$ref": "#/responses/repoArchived" } } } @@ -7493,6 +7544,9 @@ }, "404": { "$ref": "#/responses/notFound" + }, + "423": { + "$ref": "#/responses/repoArchived" } } } @@ -7771,6 +7825,9 @@ }, "404": { "description": "the issue does not exist" + }, + "423": { + "$ref": "#/responses/repoArchived" } } }, @@ -7819,6 +7876,9 @@ }, "404": { "$ref": "#/responses/notFound" + }, + "423": { + "$ref": "#/responses/repoArchived" } } } @@ -10205,6 +10265,9 @@ }, "422": { "$ref": "#/responses/validationError" + }, + "423": { + "$ref": "#/responses/repoArchived" } } } @@ -10639,6 +10702,9 @@ }, "409": { "$ref": "#/responses/error" + }, + "423": { + "$ref": "#/responses/repoArchived" } } }, @@ -10684,6 +10750,9 @@ }, "404": { "$ref": "#/responses/notFound" + }, + "423": { + "$ref": "#/responses/repoArchived" } } } @@ -12725,6 +12794,9 @@ }, "409": { "$ref": "#/responses/conflict" + }, + "423": { + "$ref": "#/responses/repoArchived" } } } @@ -12815,6 +12887,9 @@ }, "409": { "$ref": "#/responses/conflict" + }, + "423": { + "$ref": "#/responses/repoArchived" } } } @@ -13475,6 +13550,9 @@ }, "404": { "$ref": "#/responses/notFound" + }, + "423": { + "$ref": "#/responses/repoArchived" } } } @@ -13559,6 +13637,9 @@ }, "404": { "$ref": "#/responses/notFound" + }, + "423": { + "$ref": "#/responses/repoArchived" } } }, @@ -13613,6 +13694,9 @@ }, "404": { "$ref": "#/responses/notFound" + }, + "423": { + "$ref": "#/responses/repoArchived" } } } @@ -23903,6 +23987,17 @@ "redirect": { "description": "APIRedirect is a redirect response" }, + "repoArchived": { + "description": "APIRepoArchivedError is error that is raised when a repo is archived", + "headers": { + "message": { + "type": "string" + }, + "url": { + "type": "string" + } + } + }, "string": { "description": "APIString is a string response", "schema": { From 3f1d43f2b5cb3ce9ac519ade6bfbe67dff01ef41 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Wed, 20 Sep 2023 12:08:11 +0200 Subject: [PATCH 2/3] Use Sprintf --- models/repo/repo.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/repo/repo.go b/models/repo/repo.go index 2fc50f3f046bb..5087042ac3b19 100644 --- a/models/repo/repo.go +++ b/models/repo/repo.go @@ -54,7 +54,7 @@ type ErrRepoIsArchived struct { } func (err ErrRepoIsArchived) Error() string { - return fmt.Sprint("repo %s/%s is archived", err.Owner, err.Name) + return fmt.Sprintf("repo %s/%s is archived", err.Owner, err.Name) } var ( From 174d4dfdffa046424a851002807a54e1728dcf3b Mon Sep 17 00:00:00 2001 From: JakobDev Date: Wed, 20 Sep 2023 17:50:03 +0200 Subject: [PATCH 3/3] Changes requested by delvh --- models/git/protected_branch.go | 4 +- models/repo/repo.go | 12 ++-- modules/context/api.go | 4 +- routers/api/v1/api.go | 2 +- routers/api/v1/repo/branch.go | 8 +-- routers/api/v1/repo/file.go | 8 +-- routers/api/v1/repo/issue.go | 2 +- routers/api/v1/repo/issue_attachment.go | 6 +- routers/api/v1/repo/issue_comment.go | 4 +- .../api/v1/repo/issue_comment_attachment.go | 6 +- routers/api/v1/repo/issue_dependency.go | 4 +- routers/api/v1/repo/patch.go | 2 +- routers/api/v1/repo/pull.go | 6 +- routers/api/v1/repo/tag.go | 4 +- routers/api/v1/repo/wiki.go | 6 +- services/release/release.go | 2 +- services/repository/branch.go | 8 +-- services/repository/files/patch.go | 2 +- services/repository/files/update.go | 2 +- services/wiki/wiki.go | 4 +- templates/swagger/v1_json.tmpl | 60 +++++++++---------- 21 files changed, 77 insertions(+), 79 deletions(-) diff --git a/models/git/protected_branch.go b/models/git/protected_branch.go index 87439e8c84e27..5be35f4b113c7 100644 --- a/models/git/protected_branch.go +++ b/models/git/protected_branch.go @@ -315,7 +315,7 @@ type WhitelistOptions struct { // This function also performs check if whitelist user and team's IDs have been changed // to avoid unnecessary whitelist delete and regenerate. func UpdateProtectBranch(ctx context.Context, repo *repo_model.Repository, protectBranch *ProtectedBranch, opts WhitelistOptions) (err error) { - err = repo.GetIsArchivedError() + err = repo.MustNotBeArchived() if err != nil { return err } @@ -451,7 +451,7 @@ func updateTeamWhitelist(ctx context.Context, repo *repo_model.Repository, curre // DeleteProtectedBranch removes ProtectedBranch relation between the user and repository. func DeleteProtectedBranch(ctx context.Context, repo *repo_model.Repository, id int64) (err error) { - err = repo.GetIsArchivedError() + err = repo.MustNotBeArchived() if err != nil { return err } diff --git a/models/repo/repo.go b/models/repo/repo.go index 5087042ac3b19..0b0c029993a9b 100644 --- a/models/repo/repo.go +++ b/models/repo/repo.go @@ -48,13 +48,11 @@ func (err ErrUserDoesNotHaveAccessToRepo) Unwrap() error { } type ErrRepoIsArchived struct { - ID int64 - Name string - Owner string + Repo *Repository } func (err ErrRepoIsArchived) Error() string { - return fmt.Sprintf("repo %s/%s is archived", err.Owner, err.Name) + return fmt.Sprintf("%s is archived", err.Repo.LogString()) } var ( @@ -664,10 +662,10 @@ func (repo *Repository) GetTrustModel() TrustModelType { return trustModel } -// GetIsArchivedError returns ErrRepoIsArchived is the repo is archived -func (repo *Repository) GetIsArchivedError() error { +// MustNotBeArchived returns ErrRepoIsArchived if the repo is archived +func (repo *Repository) MustNotBeArchived() error { if repo.IsArchived { - return ErrRepoIsArchived{ID: repo.ID, Name: repo.Name, Owner: repo.OwnerName} + return ErrRepoIsArchived{Repo: repo} } return nil } diff --git a/modules/context/api.go b/modules/context/api.go index 52a8f4eb1c24e..a46af6ed78232 100644 --- a/modules/context/api.go +++ b/modules/context/api.go @@ -101,8 +101,8 @@ type APIRedirect struct{} // swagger:response string type APIString string -// APIRepoArchivedError is error that is raised when a repo is archived -// swagger:response repoArchived +// APIRepoArchivedError is an error that is raised when an archived repo should be modified +// swagger:response repoArchivedError type APIRepoArchivedError struct { APIError } diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index b480ea2f8d6ae..dc1f914922a10 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -675,7 +675,7 @@ func mustEnableWiki(ctx *context.APIContext) { func mustNotBeArchived(ctx *context.APIContext) { if ctx.Repo.Repository.IsArchived { - ctx.Error(http.StatusLocked, "RepoArchived", fmt.Errorf("repo %s/%s is archived", ctx.Repo.Repository.OwnerName, ctx.Repo.Repository.Name)) + ctx.Error(http.StatusLocked, "RepoArchived", fmt.Errorf("%s is archived", ctx.Repo.Repository.LogString())) return } } diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go index 90d65f4f310df..583b591d10b07 100644 --- a/routers/api/v1/repo/branch.go +++ b/routers/api/v1/repo/branch.go @@ -118,7 +118,7 @@ func DeleteBranch(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" // "423": - // "$ref": "#/responses/repoArchived" + // "$ref": "#/responses/repoArchivedError" if ctx.Repo.Repository.IsEmpty { ctx.Error(http.StatusNotFound, "", "Git Repository is empty.") return @@ -209,7 +209,7 @@ func CreateBranch(ctx *context.APIContext) { // "409": // description: The branch with the same name already exists. // "423": - // "$ref": "#/responses/repoArchived" + // "$ref": "#/responses/repoArchivedError" if ctx.Repo.Repository.IsEmpty { ctx.Error(http.StatusNotFound, "", "Git Repository is empty.") @@ -509,7 +509,7 @@ func CreateBranchProtection(ctx *context.APIContext) { // "422": // "$ref": "#/responses/validationError" // "423": - // "$ref": "#/responses/repoArchived" + // "$ref": "#/responses/repoArchivedError" form := web.GetForm(ctx).(*api.CreateBranchProtectionOption) repo := ctx.Repo.Repository @@ -719,7 +719,7 @@ func EditBranchProtection(ctx *context.APIContext) { // "422": // "$ref": "#/responses/validationError" // "423": - // "$ref": "#/responses/repoArchived" + // "$ref": "#/responses/repoArchivedError" form := web.GetForm(ctx).(*api.EditBranchProtectionOption) repo := ctx.Repo.Repository bpName := ctx.Params(":name") diff --git a/routers/api/v1/repo/file.go b/routers/api/v1/repo/file.go index d8a08b70c9709..94e634461c278 100644 --- a/routers/api/v1/repo/file.go +++ b/routers/api/v1/repo/file.go @@ -451,7 +451,7 @@ func ChangeFiles(ctx *context.APIContext) { // "422": // "$ref": "#/responses/error" // "423": - // "$ref": "#/responses/repoArchived" + // "$ref": "#/responses/repoArchivedError" apiOpts := web.GetForm(ctx).(*api.ChangeFilesOptions) @@ -553,7 +553,7 @@ func CreateFile(ctx *context.APIContext) { // "422": // "$ref": "#/responses/error" // "423": - // "$ref": "#/responses/repoArchived" + // "$ref": "#/responses/repoArchivedError" apiOpts := web.GetForm(ctx).(*api.CreateFileOptions) @@ -651,7 +651,7 @@ func UpdateFile(ctx *context.APIContext) { // "422": // "$ref": "#/responses/error" // "423": - // "$ref": "#/responses/repoArchived" + // "$ref": "#/responses/repoArchivedError" apiOpts := web.GetForm(ctx).(*api.UpdateFileOptions) if ctx.Repo.Repository.IsEmpty { ctx.Error(http.StatusUnprocessableEntity, "RepoIsEmpty", fmt.Errorf("repo is empty")) @@ -813,7 +813,7 @@ func DeleteFile(ctx *context.APIContext) { // "404": // "$ref": "#/responses/error" // "423": - // "$ref": "#/responses/repoArchived" + // "$ref": "#/responses/repoArchivedError" apiOpts := web.GetForm(ctx).(*api.DeleteFileOptions) if !canWriteFiles(ctx, apiOpts.BranchName) { diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index 1c615912ff97f..2bced1f233e78 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -632,7 +632,7 @@ func CreateIssue(ctx *context.APIContext) { // "422": // "$ref": "#/responses/validationError" // "423": - // "$ref": "#/responses/repoArchived" + // "$ref": "#/responses/repoArchivedError" form := web.GetForm(ctx).(*api.CreateIssueOption) var deadlineUnix timeutil.TimeStamp if form.Deadline != nil && ctx.Repo.CanWrite(unit.TypeIssues) { diff --git a/routers/api/v1/repo/issue_attachment.go b/routers/api/v1/repo/issue_attachment.go index 9d39c4a4c812a..b4768004adad3 100644 --- a/routers/api/v1/repo/issue_attachment.go +++ b/routers/api/v1/repo/issue_attachment.go @@ -154,7 +154,7 @@ func CreateIssueAttachment(ctx *context.APIContext) { // "404": // "$ref": "#/responses/error" // "423": - // "$ref": "#/responses/repoArchived" + // "$ref": "#/responses/repoArchivedError" issue := getIssueFromContext(ctx) if issue == nil { @@ -241,7 +241,7 @@ func EditIssueAttachment(ctx *context.APIContext) { // "404": // "$ref": "#/responses/error" // "423": - // "$ref": "#/responses/repoArchived" + // "$ref": "#/responses/repoArchivedError" attachment := getIssueAttachmentSafeWrite(ctx) if attachment == nil { @@ -297,7 +297,7 @@ func DeleteIssueAttachment(ctx *context.APIContext) { // "404": // "$ref": "#/responses/error" // "423": - // "$ref": "#/responses/repoArchived" + // "$ref": "#/responses/repoArchivedError" attachment := getIssueAttachmentSafeWrite(ctx) if attachment == nil { diff --git a/routers/api/v1/repo/issue_comment.go b/routers/api/v1/repo/issue_comment.go index 607774d05c469..8ef968c128d5f 100644 --- a/routers/api/v1/repo/issue_comment.go +++ b/routers/api/v1/repo/issue_comment.go @@ -359,7 +359,7 @@ func CreateIssueComment(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" // "423": - // "$ref": "#/responses/repoArchived" + // "$ref": "#/responses/repoArchivedError" form := web.GetForm(ctx).(*api.CreateIssueCommentOption) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) if err != nil { @@ -489,7 +489,7 @@ func EditIssueComment(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" // "423": - // "$ref": "#/responses/repoArchived" + // "$ref": "#/responses/repoArchivedError" form := web.GetForm(ctx).(*api.EditIssueCommentOption) editIssueComment(ctx, *form) } diff --git a/routers/api/v1/repo/issue_comment_attachment.go b/routers/api/v1/repo/issue_comment_attachment.go index 8c92454b33acb..63ed51c72d903 100644 --- a/routers/api/v1/repo/issue_comment_attachment.go +++ b/routers/api/v1/repo/issue_comment_attachment.go @@ -157,7 +157,7 @@ func CreateIssueCommentAttachment(ctx *context.APIContext) { // "404": // "$ref": "#/responses/error" // "423": - // "$ref": "#/responses/repoArchived" + // "$ref": "#/responses/repoArchivedError" // Check if comment exists and load comment comment := getIssueCommentSafe(ctx) @@ -248,7 +248,7 @@ func EditIssueCommentAttachment(ctx *context.APIContext) { // "404": // "$ref": "#/responses/error" // "423": - // "$ref": "#/responses/repoArchived" + // "$ref": "#/responses/repoArchivedError" attach := getIssueCommentAttachmentSafeWrite(ctx) if attach == nil { return @@ -301,7 +301,7 @@ func DeleteIssueCommentAttachment(ctx *context.APIContext) { // "404": // "$ref": "#/responses/error" // "423": - // "$ref": "#/responses/repoArchived" + // "$ref": "#/responses/repoArchivedError" attach := getIssueCommentAttachmentSafeWrite(ctx) if attach == nil { return diff --git a/routers/api/v1/repo/issue_dependency.go b/routers/api/v1/repo/issue_dependency.go index 29823855a154e..9571532800d85 100644 --- a/routers/api/v1/repo/issue_dependency.go +++ b/routers/api/v1/repo/issue_dependency.go @@ -188,7 +188,7 @@ func CreateIssueDependency(ctx *context.APIContext) { // "404": // description: the issue does not exist // "423": - // "$ref": "#/responses/repoArchived" + // "$ref": "#/responses/repoArchivedError" // We want to make <:index> depend on , i.e. <:index> is the target target := getParamsIssue(ctx) @@ -249,7 +249,7 @@ func RemoveIssueDependency(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" // "423": - // "$ref": "#/responses/repoArchived" + // "$ref": "#/responses/repoArchivedError" // We want to make <:index> depend on , i.e. <:index> is the target target := getParamsIssue(ctx) diff --git a/routers/api/v1/repo/patch.go b/routers/api/v1/repo/patch.go index 6f74879f219b9..9b5635d245a0c 100644 --- a/routers/api/v1/repo/patch.go +++ b/routers/api/v1/repo/patch.go @@ -48,7 +48,7 @@ func ApplyDiffPatch(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" // "423": - // "$ref": "#/responses/repoArchived" + // "$ref": "#/responses/repoArchivedError" apiOpts := web.GetForm(ctx).(*api.ApplyDiffPatchFileOptions) opts := &files.ApplyDiffPatchOptions{ diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 1983cb0fdb445..1439d48a8eb1c 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -283,7 +283,7 @@ func CreatePullRequest(ctx *context.APIContext) { // "422": // "$ref": "#/responses/validationError" // "423": - // "$ref": "#/responses/repoArchived" + // "$ref": "#/responses/repoArchivedError" form := *web.GetForm(ctx).(*api.CreatePullRequestOption) if form.Head == form.Base { @@ -744,7 +744,7 @@ func MergePullRequest(ctx *context.APIContext) { // "409": // "$ref": "#/responses/error" // "423": - // "$ref": "#/responses/repoArchived" + // "$ref": "#/responses/repoArchivedError" form := web.GetForm(ctx).(*forms.MergePullRequestForm) @@ -1201,7 +1201,7 @@ func CancelScheduledAutoMerge(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" // "423": - // "$ref": "#/responses/repoArchived" + // "$ref": "#/responses/repoArchivedError" pullIndex := ctx.ParamsInt64(":index") pull, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, pullIndex) diff --git a/routers/api/v1/repo/tag.go b/routers/api/v1/repo/tag.go index c1c8777ddeda3..cd29937cb834a 100644 --- a/routers/api/v1/repo/tag.go +++ b/routers/api/v1/repo/tag.go @@ -185,7 +185,7 @@ func CreateTag(ctx *context.APIContext) { // "409": // "$ref": "#/responses/conflict" // "423": - // "$ref": "#/responses/repoArchived" + // "$ref": "#/responses/repoArchivedError" form := web.GetForm(ctx).(*api.CreateTagOption) // If target is not provided use default branch @@ -254,7 +254,7 @@ func DeleteTag(ctx *context.APIContext) { // "409": // "$ref": "#/responses/conflict" // "423": - // "$ref": "#/responses/repoArchived" + // "$ref": "#/responses/repoArchivedError" tagName := ctx.Params("*") tag, err := repo_model.GetRelease(ctx.Repo.Repository.ID, tagName) diff --git a/routers/api/v1/repo/wiki.go b/routers/api/v1/repo/wiki.go index e7aea12b0617b..8e5ecce310e3e 100644 --- a/routers/api/v1/repo/wiki.go +++ b/routers/api/v1/repo/wiki.go @@ -53,7 +53,7 @@ func NewWikiPage(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" // "423": - // "$ref": "#/responses/repoArchived" + // "$ref": "#/responses/repoArchivedError" form := web.GetForm(ctx).(*api.CreateWikiPageOptions) @@ -131,7 +131,7 @@ func EditWikiPage(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" // "423": - // "$ref": "#/responses/repoArchived" + // "$ref": "#/responses/repoArchivedError" form := web.GetForm(ctx).(*api.CreateWikiPageOptions) @@ -239,7 +239,7 @@ func DeleteWikiPage(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" // "423": - // "$ref": "#/responses/repoArchived" + // "$ref": "#/responses/repoArchivedError" wikiName := wiki_service.WebPathFromRequest(ctx.PathParamRaw(":pageName")) diff --git a/services/release/release.go b/services/release/release.go index 7cacd1045a070..55cc7bfe2fcb4 100644 --- a/services/release/release.go +++ b/services/release/release.go @@ -30,7 +30,7 @@ func createTag(ctx context.Context, gitRepo *git.Repository, rel *repo_model.Rel return false, err } - err = rel.Repo.GetIsArchivedError() + err = rel.Repo.MustNotBeArchived() if err != nil { return false, err } diff --git a/services/repository/branch.go b/services/repository/branch.go index e6fb6249f58e0..3351252200166 100644 --- a/services/repository/branch.go +++ b/services/repository/branch.go @@ -29,7 +29,7 @@ import ( // CreateNewBranch creates a new repository branch func CreateNewBranch(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldBranchName, branchName string) (err error) { - err = repo.GetIsArchivedError() + err = repo.MustNotBeArchived() if err != nil { return err } @@ -251,7 +251,7 @@ func checkBranchName(ctx context.Context, repo *repo_model.Repository, name stri // CreateNewBranchFromCommit creates a new repository branch func CreateNewBranchFromCommit(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, commit, branchName string) (err error) { - err = repo.GetIsArchivedError() + err = repo.MustNotBeArchived() if err != nil { return err } @@ -277,7 +277,7 @@ func CreateNewBranchFromCommit(ctx context.Context, doer *user_model.User, repo // RenameBranch rename a branch func RenameBranch(ctx context.Context, repo *repo_model.Repository, doer *user_model.User, gitRepo *git.Repository, from, to string) (string, error) { - err := repo.GetIsArchivedError() + err := repo.MustNotBeArchived() if err != nil { return "", err } @@ -330,7 +330,7 @@ var ( // DeleteBranch delete branch func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, gitRepo *git.Repository, branchName string) error { - err := repo.GetIsArchivedError() + err := repo.MustNotBeArchived() if err != nil { return err } diff --git a/services/repository/files/patch.go b/services/repository/files/patch.go index fad478e9b3733..5ef0619636e77 100644 --- a/services/repository/files/patch.go +++ b/services/repository/files/patch.go @@ -95,7 +95,7 @@ func (opts *ApplyDiffPatchOptions) Validate(ctx context.Context, repo *repo_mode // ApplyDiffPatch applies a patch to the given repository func ApplyDiffPatch(ctx context.Context, repo *repo_model.Repository, doer *user_model.User, opts *ApplyDiffPatchOptions) (*structs.FileResponse, error) { - err := repo.GetIsArchivedError() + err := repo.MustNotBeArchived() if err != nil { return nil, err } diff --git a/services/repository/files/update.go b/services/repository/files/update.go index f8329d6702afd..2a08bcbaceac2 100644 --- a/services/repository/files/update.go +++ b/services/repository/files/update.go @@ -65,7 +65,7 @@ type RepoFileOptions struct { // ChangeRepoFiles adds, updates or removes multiple files in the given repository func ChangeRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *user_model.User, opts *ChangeRepoFilesOptions) (*structs.FilesResponse, error) { - err := repo.GetIsArchivedError() + err := repo.MustNotBeArchived() if err != nil { return nil, err } diff --git a/services/wiki/wiki.go b/services/wiki/wiki.go index f6de469a977ff..250b539080221 100644 --- a/services/wiki/wiki.go +++ b/services/wiki/wiki.go @@ -79,7 +79,7 @@ func prepareGitPath(gitRepo *git.Repository, wikiPath WebPath) (bool, string, er // updateWikiPage adds a new page or edits an existing page in repository wiki. func updateWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldWikiName, newWikiName WebPath, content, message string, isNew bool) (err error) { - err = repo.GetIsArchivedError() + err = repo.MustNotBeArchived() if err != nil { return err } @@ -243,7 +243,7 @@ func EditWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.R // DeleteWikiPage deletes a wiki page identified by its path. func DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, wikiName WebPath) (err error) { - err = repo.GetIsArchivedError() + err = repo.MustNotBeArchived() if err != nil { return err } diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 998f8a1b6109a..4b43200bc6072 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -3721,7 +3721,7 @@ "$ref": "#/responses/validationError" }, "423": { - "$ref": "#/responses/repoArchived" + "$ref": "#/responses/repoArchivedError" } } } @@ -3862,7 +3862,7 @@ "$ref": "#/responses/validationError" }, "423": { - "$ref": "#/responses/repoArchived" + "$ref": "#/responses/repoArchivedError" } } } @@ -3960,7 +3960,7 @@ "description": "The branch with the same name already exists." }, "423": { - "$ref": "#/responses/repoArchived" + "$ref": "#/responses/repoArchivedError" } } } @@ -4050,7 +4050,7 @@ "$ref": "#/responses/notFound" }, "423": { - "$ref": "#/responses/repoArchived" + "$ref": "#/responses/repoArchivedError" } } } @@ -4610,7 +4610,7 @@ "$ref": "#/responses/error" }, "423": { - "$ref": "#/responses/repoArchived" + "$ref": "#/responses/repoArchivedError" } } } @@ -4720,7 +4720,7 @@ "$ref": "#/responses/error" }, "423": { - "$ref": "#/responses/repoArchived" + "$ref": "#/responses/repoArchivedError" } } }, @@ -4781,7 +4781,7 @@ "$ref": "#/responses/error" }, "423": { - "$ref": "#/responses/repoArchived" + "$ref": "#/responses/repoArchivedError" } } }, @@ -4842,7 +4842,7 @@ "$ref": "#/responses/error" }, "423": { - "$ref": "#/responses/repoArchived" + "$ref": "#/responses/repoArchivedError" } } } @@ -4892,7 +4892,7 @@ "$ref": "#/responses/notFound" }, "423": { - "$ref": "#/responses/repoArchived" + "$ref": "#/responses/repoArchivedError" } } } @@ -6166,7 +6166,7 @@ "$ref": "#/responses/validationError" }, "423": { - "$ref": "#/responses/repoArchived" + "$ref": "#/responses/repoArchivedError" } } } @@ -6384,7 +6384,7 @@ "$ref": "#/responses/notFound" }, "423": { - "$ref": "#/responses/repoArchived" + "$ref": "#/responses/repoArchivedError" } } } @@ -6492,7 +6492,7 @@ "$ref": "#/responses/error" }, "423": { - "$ref": "#/responses/repoArchived" + "$ref": "#/responses/repoArchivedError" } } } @@ -6597,7 +6597,7 @@ "$ref": "#/responses/error" }, "423": { - "$ref": "#/responses/repoArchived" + "$ref": "#/responses/repoArchivedError" } } }, @@ -6660,7 +6660,7 @@ "$ref": "#/responses/error" }, "423": { - "$ref": "#/responses/repoArchived" + "$ref": "#/responses/repoArchivedError" } } } @@ -7111,7 +7111,7 @@ "$ref": "#/responses/error" }, "423": { - "$ref": "#/responses/repoArchived" + "$ref": "#/responses/repoArchivedError" } } } @@ -7216,7 +7216,7 @@ "$ref": "#/responses/error" }, "423": { - "$ref": "#/responses/repoArchived" + "$ref": "#/responses/repoArchivedError" } } }, @@ -7279,7 +7279,7 @@ "$ref": "#/responses/error" }, "423": { - "$ref": "#/responses/repoArchived" + "$ref": "#/responses/repoArchivedError" } } } @@ -7546,7 +7546,7 @@ "$ref": "#/responses/notFound" }, "423": { - "$ref": "#/responses/repoArchived" + "$ref": "#/responses/repoArchivedError" } } } @@ -7827,7 +7827,7 @@ "description": "the issue does not exist" }, "423": { - "$ref": "#/responses/repoArchived" + "$ref": "#/responses/repoArchivedError" } } }, @@ -7878,7 +7878,7 @@ "$ref": "#/responses/notFound" }, "423": { - "$ref": "#/responses/repoArchived" + "$ref": "#/responses/repoArchivedError" } } } @@ -10267,7 +10267,7 @@ "$ref": "#/responses/validationError" }, "423": { - "$ref": "#/responses/repoArchived" + "$ref": "#/responses/repoArchivedError" } } } @@ -10704,7 +10704,7 @@ "$ref": "#/responses/error" }, "423": { - "$ref": "#/responses/repoArchived" + "$ref": "#/responses/repoArchivedError" } } }, @@ -10752,7 +10752,7 @@ "$ref": "#/responses/notFound" }, "423": { - "$ref": "#/responses/repoArchived" + "$ref": "#/responses/repoArchivedError" } } } @@ -12796,7 +12796,7 @@ "$ref": "#/responses/conflict" }, "423": { - "$ref": "#/responses/repoArchived" + "$ref": "#/responses/repoArchivedError" } } } @@ -12889,7 +12889,7 @@ "$ref": "#/responses/conflict" }, "423": { - "$ref": "#/responses/repoArchived" + "$ref": "#/responses/repoArchivedError" } } } @@ -13552,7 +13552,7 @@ "$ref": "#/responses/notFound" }, "423": { - "$ref": "#/responses/repoArchived" + "$ref": "#/responses/repoArchivedError" } } } @@ -13639,7 +13639,7 @@ "$ref": "#/responses/notFound" }, "423": { - "$ref": "#/responses/repoArchived" + "$ref": "#/responses/repoArchivedError" } } }, @@ -13696,7 +13696,7 @@ "$ref": "#/responses/notFound" }, "423": { - "$ref": "#/responses/repoArchived" + "$ref": "#/responses/repoArchivedError" } } } @@ -23987,8 +23987,8 @@ "redirect": { "description": "APIRedirect is a redirect response" }, - "repoArchived": { - "description": "APIRepoArchivedError is error that is raised when a repo is archived", + "repoArchivedError": { + "description": "APIRepoArchivedError is an error that is raised when an archived repo should be modified", "headers": { "message": { "type": "string"