Updates to the API for archived repos (#27149)

This commit is contained in:
JakobDev 2023-09-22 01:43:29 +02:00 committed by GitHub
parent 7520cd678c
commit 28f9b313ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 249 additions and 34 deletions

View File

@ -315,6 +315,11 @@ type WhitelistOptions struct {
// This function also performs check if whitelist user and team's IDs have been changed // This function also performs check if whitelist user and team's IDs have been changed
// to avoid unnecessary whitelist delete and regenerate. // to avoid unnecessary whitelist delete and regenerate.
func UpdateProtectBranch(ctx context.Context, repo *repo_model.Repository, protectBranch *ProtectedBranch, opts WhitelistOptions) (err error) { func UpdateProtectBranch(ctx context.Context, repo *repo_model.Repository, protectBranch *ProtectedBranch, opts WhitelistOptions) (err error) {
err = repo.MustNotBeArchived()
if err != nil {
return err
}
if err = repo.LoadOwner(ctx); err != nil { if err = repo.LoadOwner(ctx); err != nil {
return fmt.Errorf("LoadOwner: %v", err) 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. // 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.MustNotBeArchived()
if err != nil {
return err
}
protectedBranch := &ProtectedBranch{ protectedBranch := &ProtectedBranch{
RepoID: repoID, RepoID: repo.ID,
ID: id, ID: id,
} }

View File

@ -47,6 +47,14 @@ func (err ErrUserDoesNotHaveAccessToRepo) Unwrap() error {
return util.ErrPermissionDenied return util.ErrPermissionDenied
} }
type ErrRepoIsArchived struct {
Repo *Repository
}
func (err ErrRepoIsArchived) Error() string {
return fmt.Sprintf("%s is archived", err.Repo.LogString())
}
var ( var (
reservedRepoNames = []string{".", "..", "-"} reservedRepoNames = []string{".", "..", "-"}
reservedRepoPatterns = []string{"*.git", "*.wiki", "*.rss", "*.atom"} reservedRepoPatterns = []string{"*.git", "*.wiki", "*.rss", "*.atom"}
@ -654,6 +662,14 @@ func (repo *Repository) GetTrustModel() TrustModelType {
return trustModel return trustModel
} }
// MustNotBeArchived returns ErrRepoIsArchived if the repo is archived
func (repo *Repository) MustNotBeArchived() error {
if repo.IsArchived {
return ErrRepoIsArchived{Repo: repo}
}
return nil
}
// __________ .__ __ // __________ .__ __
// \______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__. // \______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__.
// | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | | // | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | |

View File

@ -101,6 +101,12 @@ type APIRedirect struct{}
// swagger:response string // swagger:response string
type APIString string type APIString string
// APIRepoArchivedError is an error that is raised when an archived repo should be modified
// swagger:response repoArchivedError
type APIRepoArchivedError struct {
APIError
}
// ServerError responds with error message, status is 500 // ServerError responds with error message, status is 500
func (ctx *APIContext) ServerError(title string, err error) { func (ctx *APIContext) ServerError(title string, err error) {
ctx.Error(http.StatusInternalServerError, title, err) ctx.Error(http.StatusInternalServerError, title, err)

View File

@ -675,7 +675,7 @@ func mustEnableWiki(ctx *context.APIContext) {
func mustNotBeArchived(ctx *context.APIContext) { func mustNotBeArchived(ctx *context.APIContext) {
if ctx.Repo.Repository.IsArchived { if ctx.Repo.Repository.IsArchived {
ctx.NotFound() ctx.Error(http.StatusLocked, "RepoArchived", fmt.Errorf("%s is archived", ctx.Repo.Repository.LogString()))
return return
} }
} }
@ -1108,23 +1108,23 @@ func Routes() *web.Route {
m.Group("/branches", func() { m.Group("/branches", func() {
m.Get("", repo.ListBranches) m.Get("", repo.ListBranches)
m.Get("/*", repo.GetBranch) m.Get("/*", repo.GetBranch)
m.Delete("/*", reqToken(), reqRepoWriter(unit.TypeCode), repo.DeleteBranch) m.Delete("/*", reqToken(), reqRepoWriter(unit.TypeCode), mustNotBeArchived, repo.DeleteBranch)
m.Post("", reqToken(), reqRepoWriter(unit.TypeCode), bind(api.CreateBranchRepoOption{}), repo.CreateBranch) m.Post("", reqToken(), reqRepoWriter(unit.TypeCode), mustNotBeArchived, bind(api.CreateBranchRepoOption{}), repo.CreateBranch)
}, context.ReferencesGitRepo(), reqRepoReader(unit.TypeCode)) }, context.ReferencesGitRepo(), reqRepoReader(unit.TypeCode))
m.Group("/branch_protections", func() { m.Group("/branch_protections", func() {
m.Get("", repo.ListBranchProtections) m.Get("", repo.ListBranchProtections)
m.Post("", bind(api.CreateBranchProtectionOption{}), repo.CreateBranchProtection) m.Post("", bind(api.CreateBranchProtectionOption{}), mustNotBeArchived, repo.CreateBranchProtection)
m.Group("/{name}", func() { m.Group("/{name}", func() {
m.Get("", repo.GetBranchProtection) m.Get("", repo.GetBranchProtection)
m.Patch("", bind(api.EditBranchProtectionOption{}), repo.EditBranchProtection) m.Patch("", bind(api.EditBranchProtectionOption{}), mustNotBeArchived, repo.EditBranchProtection)
m.Delete("", repo.DeleteBranchProtection) m.Delete("", repo.DeleteBranchProtection)
}) })
}, reqToken(), reqAdmin()) }, reqToken(), reqAdmin())
m.Group("/tags", func() { m.Group("/tags", func() {
m.Get("", repo.ListTags) m.Get("", repo.ListTags)
m.Get("/*", repo.GetTag) m.Get("/*", repo.GetTag)
m.Post("", reqToken(), reqRepoWriter(unit.TypeCode), bind(api.CreateTagOption{}), repo.CreateTag) m.Post("", reqToken(), reqRepoWriter(unit.TypeCode), mustNotBeArchived, bind(api.CreateTagOption{}), repo.CreateTag)
m.Delete("/*", reqToken(), repo.DeleteTag) m.Delete("/*", reqToken(), reqRepoWriter(unit.TypeCode), mustNotBeArchived, repo.DeleteTag)
}, reqRepoReader(unit.TypeCode), context.ReferencesGitRepo(true)) }, reqRepoReader(unit.TypeCode), context.ReferencesGitRepo(true))
m.Group("/keys", func() { m.Group("/keys", func() {
m.Combo("").Get(repo.ListDeployKeys). m.Combo("").Get(repo.ListDeployKeys).
@ -1245,15 +1245,15 @@ func Routes() *web.Route {
m.Get("/tags/{sha}", repo.GetAnnotatedTag) m.Get("/tags/{sha}", repo.GetAnnotatedTag)
m.Get("/notes/{sha}", repo.GetNote) m.Get("/notes/{sha}", repo.GetNote)
}, context.ReferencesGitRepo(true), reqRepoReader(unit.TypeCode)) }, 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.Group("/contents", func() {
m.Get("", repo.GetContentsList) 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.Get("/*", repo.GetContents)
m.Group("/*", func() { m.Group("/*", func() {
m.Post("", bind(api.CreateFileOptions{}), reqRepoBranchWriter, repo.CreateFile) m.Post("", bind(api.CreateFileOptions{}), reqRepoBranchWriter, mustNotBeArchived, repo.CreateFile)
m.Put("", bind(api.UpdateFileOptions{}), reqRepoBranchWriter, repo.UpdateFile) m.Put("", bind(api.UpdateFileOptions{}), reqRepoBranchWriter, mustNotBeArchived, repo.UpdateFile)
m.Delete("", bind(api.DeleteFileOptions{}), reqRepoBranchWriter, repo.DeleteFile) m.Delete("", bind(api.DeleteFileOptions{}), reqRepoBranchWriter, mustNotBeArchived, repo.DeleteFile)
}, reqToken()) }, reqToken())
}, reqRepoReader(unit.TypeCode)) }, reqRepoReader(unit.TypeCode))
m.Get("/signing-key.gpg", misc.SigningKey) m.Get("/signing-key.gpg", misc.SigningKey)

View File

@ -117,17 +117,13 @@ func DeleteBranch(ctx *context.APIContext) {
// "$ref": "#/responses/error" // "$ref": "#/responses/error"
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
// "423":
// "$ref": "#/responses/repoArchivedError"
if ctx.Repo.Repository.IsEmpty { if ctx.Repo.Repository.IsEmpty {
ctx.Error(http.StatusNotFound, "", "Git Repository is empty.") ctx.Error(http.StatusNotFound, "", "Git Repository is empty.")
return return
} }
if ctx.Repo.Repository.IsArchived {
ctx.Error(http.StatusForbidden, "", "Git Repository is archived.")
return
}
if ctx.Repo.Repository.IsMirror { if ctx.Repo.Repository.IsMirror {
ctx.Error(http.StatusForbidden, "", "Git Repository is a mirror.") ctx.Error(http.StatusForbidden, "", "Git Repository is a mirror.")
return 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 { if ctx.Repo.Repository.IsMirror {
ctx.Error(http.StatusForbidden, "IsMirrored", fmt.Errorf("can not delete branch of an mirror repository")) ctx.Error(http.StatusForbidden, "IsMirrored", fmt.Errorf("can not delete branch of an mirror repository"))
return return
@ -216,17 +208,14 @@ func CreateBranch(ctx *context.APIContext) {
// description: The old branch does not exist. // description: The old branch does not exist.
// "409": // "409":
// description: The branch with the same name already exists. // description: The branch with the same name already exists.
// "423":
// "$ref": "#/responses/repoArchivedError"
if ctx.Repo.Repository.IsEmpty { if ctx.Repo.Repository.IsEmpty {
ctx.Error(http.StatusNotFound, "", "Git Repository is empty.") ctx.Error(http.StatusNotFound, "", "Git Repository is empty.")
return return
} }
if ctx.Repo.Repository.IsArchived {
ctx.Error(http.StatusForbidden, "", "Git Repository is archived.")
return
}
if ctx.Repo.Repository.IsMirror { if ctx.Repo.Repository.IsMirror {
ctx.Error(http.StatusForbidden, "", "Git Repository is a mirror.") ctx.Error(http.StatusForbidden, "", "Git Repository is a mirror.")
return return
@ -519,6 +508,8 @@ func CreateBranchProtection(ctx *context.APIContext) {
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
// "422": // "422":
// "$ref": "#/responses/validationError" // "$ref": "#/responses/validationError"
// "423":
// "$ref": "#/responses/repoArchivedError"
form := web.GetForm(ctx).(*api.CreateBranchProtectionOption) form := web.GetForm(ctx).(*api.CreateBranchProtectionOption)
repo := ctx.Repo.Repository repo := ctx.Repo.Repository
@ -727,6 +718,8 @@ func EditBranchProtection(ctx *context.APIContext) {
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
// "422": // "422":
// "$ref": "#/responses/validationError" // "$ref": "#/responses/validationError"
// "423":
// "$ref": "#/responses/repoArchivedError"
form := web.GetForm(ctx).(*api.EditBranchProtectionOption) form := web.GetForm(ctx).(*api.EditBranchProtectionOption)
repo := ctx.Repo.Repository repo := ctx.Repo.Repository
bpName := ctx.Params(":name") bpName := ctx.Params(":name")
@ -1004,7 +997,7 @@ func DeleteBranchProtection(ctx *context.APIContext) {
return 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) ctx.Error(http.StatusInternalServerError, "DeleteProtectedBranch", err)
return return
} }

View File

@ -450,6 +450,8 @@ func ChangeFiles(ctx *context.APIContext) {
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
// "422": // "422":
// "$ref": "#/responses/error" // "$ref": "#/responses/error"
// "423":
// "$ref": "#/responses/repoArchivedError"
apiOpts := web.GetForm(ctx).(*api.ChangeFilesOptions) apiOpts := web.GetForm(ctx).(*api.ChangeFilesOptions)
@ -550,6 +552,8 @@ func CreateFile(ctx *context.APIContext) {
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
// "422": // "422":
// "$ref": "#/responses/error" // "$ref": "#/responses/error"
// "423":
// "$ref": "#/responses/repoArchivedError"
apiOpts := web.GetForm(ctx).(*api.CreateFileOptions) apiOpts := web.GetForm(ctx).(*api.CreateFileOptions)
@ -646,6 +650,8 @@ func UpdateFile(ctx *context.APIContext) {
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
// "422": // "422":
// "$ref": "#/responses/error" // "$ref": "#/responses/error"
// "423":
// "$ref": "#/responses/repoArchivedError"
apiOpts := web.GetForm(ctx).(*api.UpdateFileOptions) apiOpts := web.GetForm(ctx).(*api.UpdateFileOptions)
if ctx.Repo.Repository.IsEmpty { if ctx.Repo.Repository.IsEmpty {
ctx.Error(http.StatusUnprocessableEntity, "RepoIsEmpty", fmt.Errorf("repo is empty")) ctx.Error(http.StatusUnprocessableEntity, "RepoIsEmpty", fmt.Errorf("repo is empty"))
@ -806,6 +812,8 @@ func DeleteFile(ctx *context.APIContext) {
// "$ref": "#/responses/error" // "$ref": "#/responses/error"
// "404": // "404":
// "$ref": "#/responses/error" // "$ref": "#/responses/error"
// "423":
// "$ref": "#/responses/repoArchivedError"
apiOpts := web.GetForm(ctx).(*api.DeleteFileOptions) apiOpts := web.GetForm(ctx).(*api.DeleteFileOptions)
if !canWriteFiles(ctx, apiOpts.BranchName) { if !canWriteFiles(ctx, apiOpts.BranchName) {

View File

@ -631,6 +631,8 @@ func CreateIssue(ctx *context.APIContext) {
// "$ref": "#/responses/error" // "$ref": "#/responses/error"
// "422": // "422":
// "$ref": "#/responses/validationError" // "$ref": "#/responses/validationError"
// "423":
// "$ref": "#/responses/repoArchivedError"
form := web.GetForm(ctx).(*api.CreateIssueOption) form := web.GetForm(ctx).(*api.CreateIssueOption)
var deadlineUnix timeutil.TimeStamp var deadlineUnix timeutil.TimeStamp
if form.Deadline != nil && ctx.Repo.CanWrite(unit.TypeIssues) { if form.Deadline != nil && ctx.Repo.CanWrite(unit.TypeIssues) {

View File

@ -153,6 +153,8 @@ func CreateIssueAttachment(ctx *context.APIContext) {
// "$ref": "#/responses/error" // "$ref": "#/responses/error"
// "404": // "404":
// "$ref": "#/responses/error" // "$ref": "#/responses/error"
// "423":
// "$ref": "#/responses/repoArchivedError"
issue := getIssueFromContext(ctx) issue := getIssueFromContext(ctx)
if issue == nil { if issue == nil {
@ -238,6 +240,8 @@ func EditIssueAttachment(ctx *context.APIContext) {
// "$ref": "#/responses/Attachment" // "$ref": "#/responses/Attachment"
// "404": // "404":
// "$ref": "#/responses/error" // "$ref": "#/responses/error"
// "423":
// "$ref": "#/responses/repoArchivedError"
attachment := getIssueAttachmentSafeWrite(ctx) attachment := getIssueAttachmentSafeWrite(ctx)
if attachment == nil { if attachment == nil {
@ -292,6 +296,8 @@ func DeleteIssueAttachment(ctx *context.APIContext) {
// "$ref": "#/responses/empty" // "$ref": "#/responses/empty"
// "404": // "404":
// "$ref": "#/responses/error" // "$ref": "#/responses/error"
// "423":
// "$ref": "#/responses/repoArchivedError"
attachment := getIssueAttachmentSafeWrite(ctx) attachment := getIssueAttachmentSafeWrite(ctx)
if attachment == nil { if attachment == nil {

View File

@ -358,6 +358,8 @@ func CreateIssueComment(ctx *context.APIContext) {
// "$ref": "#/responses/forbidden" // "$ref": "#/responses/forbidden"
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
// "423":
// "$ref": "#/responses/repoArchivedError"
form := web.GetForm(ctx).(*api.CreateIssueCommentOption) form := web.GetForm(ctx).(*api.CreateIssueCommentOption)
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil { if err != nil {
@ -486,7 +488,8 @@ func EditIssueComment(ctx *context.APIContext) {
// "$ref": "#/responses/forbidden" // "$ref": "#/responses/forbidden"
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
// "423":
// "$ref": "#/responses/repoArchivedError"
form := web.GetForm(ctx).(*api.EditIssueCommentOption) form := web.GetForm(ctx).(*api.EditIssueCommentOption)
editIssueComment(ctx, *form) editIssueComment(ctx, *form)
} }

View File

@ -156,6 +156,8 @@ func CreateIssueCommentAttachment(ctx *context.APIContext) {
// "$ref": "#/responses/error" // "$ref": "#/responses/error"
// "404": // "404":
// "$ref": "#/responses/error" // "$ref": "#/responses/error"
// "423":
// "$ref": "#/responses/repoArchivedError"
// Check if comment exists and load comment // Check if comment exists and load comment
comment := getIssueCommentSafe(ctx) comment := getIssueCommentSafe(ctx)
@ -245,7 +247,8 @@ func EditIssueCommentAttachment(ctx *context.APIContext) {
// "$ref": "#/responses/Attachment" // "$ref": "#/responses/Attachment"
// "404": // "404":
// "$ref": "#/responses/error" // "$ref": "#/responses/error"
// "423":
// "$ref": "#/responses/repoArchivedError"
attach := getIssueCommentAttachmentSafeWrite(ctx) attach := getIssueCommentAttachmentSafeWrite(ctx)
if attach == nil { if attach == nil {
return return
@ -297,7 +300,8 @@ func DeleteIssueCommentAttachment(ctx *context.APIContext) {
// "$ref": "#/responses/empty" // "$ref": "#/responses/empty"
// "404": // "404":
// "$ref": "#/responses/error" // "$ref": "#/responses/error"
// "423":
// "$ref": "#/responses/repoArchivedError"
attach := getIssueCommentAttachmentSafeWrite(ctx) attach := getIssueCommentAttachmentSafeWrite(ctx)
if attach == nil { if attach == nil {
return return

View File

@ -187,6 +187,8 @@ func CreateIssueDependency(ctx *context.APIContext) {
// "$ref": "#/responses/Issue" // "$ref": "#/responses/Issue"
// "404": // "404":
// description: the issue does not exist // description: the issue does not exist
// "423":
// "$ref": "#/responses/repoArchivedError"
// We want to make <:index> depend on <Form>, i.e. <:index> is the target // We want to make <:index> depend on <Form>, i.e. <:index> is the target
target := getParamsIssue(ctx) target := getParamsIssue(ctx)
@ -246,6 +248,8 @@ func RemoveIssueDependency(ctx *context.APIContext) {
// "$ref": "#/responses/Issue" // "$ref": "#/responses/Issue"
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
// "423":
// "$ref": "#/responses/repoArchivedError"
// We want to make <:index> depend on <Form>, i.e. <:index> is the target // We want to make <:index> depend on <Form>, i.e. <:index> is the target
target := getParamsIssue(ctx) target := getParamsIssue(ctx)

View File

@ -47,6 +47,8 @@ func ApplyDiffPatch(ctx *context.APIContext) {
// "$ref": "#/responses/FileResponse" // "$ref": "#/responses/FileResponse"
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
// "423":
// "$ref": "#/responses/repoArchivedError"
apiOpts := web.GetForm(ctx).(*api.ApplyDiffPatchFileOptions) apiOpts := web.GetForm(ctx).(*api.ApplyDiffPatchFileOptions)
opts := &files.ApplyDiffPatchOptions{ opts := &files.ApplyDiffPatchOptions{

View File

@ -282,6 +282,8 @@ func CreatePullRequest(ctx *context.APIContext) {
// "$ref": "#/responses/error" // "$ref": "#/responses/error"
// "422": // "422":
// "$ref": "#/responses/validationError" // "$ref": "#/responses/validationError"
// "423":
// "$ref": "#/responses/repoArchivedError"
form := *web.GetForm(ctx).(*api.CreatePullRequestOption) form := *web.GetForm(ctx).(*api.CreatePullRequestOption)
if form.Head == form.Base { if form.Head == form.Base {
@ -741,6 +743,8 @@ func MergePullRequest(ctx *context.APIContext) {
// "$ref": "#/responses/empty" // "$ref": "#/responses/empty"
// "409": // "409":
// "$ref": "#/responses/error" // "$ref": "#/responses/error"
// "423":
// "$ref": "#/responses/repoArchivedError"
form := web.GetForm(ctx).(*forms.MergePullRequestForm) form := web.GetForm(ctx).(*forms.MergePullRequestForm)
@ -1196,6 +1200,8 @@ func CancelScheduledAutoMerge(ctx *context.APIContext) {
// "$ref": "#/responses/forbidden" // "$ref": "#/responses/forbidden"
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
// "423":
// "$ref": "#/responses/repoArchivedError"
pullIndex := ctx.ParamsInt64(":index") pullIndex := ctx.ParamsInt64(":index")
pull, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, pullIndex) pull, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, pullIndex)

View File

@ -184,6 +184,8 @@ func CreateTag(ctx *context.APIContext) {
// "$ref": "#/responses/empty" // "$ref": "#/responses/empty"
// "409": // "409":
// "$ref": "#/responses/conflict" // "$ref": "#/responses/conflict"
// "423":
// "$ref": "#/responses/repoArchivedError"
form := web.GetForm(ctx).(*api.CreateTagOption) form := web.GetForm(ctx).(*api.CreateTagOption)
// If target is not provided use default branch // If target is not provided use default branch
@ -251,6 +253,8 @@ func DeleteTag(ctx *context.APIContext) {
// "$ref": "#/responses/empty" // "$ref": "#/responses/empty"
// "409": // "409":
// "$ref": "#/responses/conflict" // "$ref": "#/responses/conflict"
// "423":
// "$ref": "#/responses/repoArchivedError"
tagName := ctx.Params("*") tagName := ctx.Params("*")
tag, err := repo_model.GetRelease(ctx.Repo.Repository.ID, tagName) tag, err := repo_model.GetRelease(ctx.Repo.Repository.ID, tagName)

View File

@ -52,6 +52,8 @@ func NewWikiPage(ctx *context.APIContext) {
// "$ref": "#/responses/forbidden" // "$ref": "#/responses/forbidden"
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
// "423":
// "$ref": "#/responses/repoArchivedError"
form := web.GetForm(ctx).(*api.CreateWikiPageOptions) form := web.GetForm(ctx).(*api.CreateWikiPageOptions)
@ -128,6 +130,8 @@ func EditWikiPage(ctx *context.APIContext) {
// "$ref": "#/responses/forbidden" // "$ref": "#/responses/forbidden"
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
// "423":
// "$ref": "#/responses/repoArchivedError"
form := web.GetForm(ctx).(*api.CreateWikiPageOptions) form := web.GetForm(ctx).(*api.CreateWikiPageOptions)
@ -234,6 +238,8 @@ func DeleteWikiPage(ctx *context.APIContext) {
// "$ref": "#/responses/forbidden" // "$ref": "#/responses/forbidden"
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
// "423":
// "$ref": "#/responses/repoArchivedError"
wikiName := wiki_service.WebPathFromRequest(ctx.PathParamRaw(":pageName")) wikiName := wiki_service.WebPathFromRequest(ctx.PathParamRaw(":pageName"))

View File

@ -285,7 +285,7 @@ func DeleteProtectedBranchRulePost(ctx *context.Context) {
return 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.Flash.Error(ctx.Tr("repo.settings.remove_protected_branch_failed", rule.RuleName))
ctx.JSONRedirect(fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink)) ctx.JSONRedirect(fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink))
return return

View File

@ -25,6 +25,16 @@ import (
) )
func createTag(ctx context.Context, gitRepo *git.Repository, rel *repo_model.Release, msg string) (bool, error) { 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.MustNotBeArchived()
if err != nil {
return false, err
}
var created bool var created bool
// Only actual create when publish. // Only actual create when publish.
if !rel.IsDraft { if !rel.IsDraft {

View File

@ -29,6 +29,11 @@ import (
// CreateNewBranch creates a new repository branch // CreateNewBranch creates a new repository branch
func CreateNewBranch(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldBranchName, branchName string) (err error) { func CreateNewBranch(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldBranchName, branchName string) (err error) {
err = repo.MustNotBeArchived()
if err != nil {
return err
}
// Check if branch name can be used // Check if branch name can be used
if err := checkBranchName(ctx, repo, branchName); err != nil { if err := checkBranchName(ctx, repo, branchName); err != nil {
return err return err
@ -246,6 +251,11 @@ func checkBranchName(ctx context.Context, repo *repo_model.Repository, name stri
// CreateNewBranchFromCommit creates a new repository branch // CreateNewBranchFromCommit creates a new repository branch
func CreateNewBranchFromCommit(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, commit, branchName string) (err error) { func CreateNewBranchFromCommit(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, commit, branchName string) (err error) {
err = repo.MustNotBeArchived()
if err != nil {
return err
}
// Check if branch name can be used // Check if branch name can be used
if err := checkBranchName(ctx, repo, branchName); err != nil { if err := checkBranchName(ctx, repo, branchName); err != nil {
return err return err
@ -267,6 +277,11 @@ func CreateNewBranchFromCommit(ctx context.Context, doer *user_model.User, repo
// RenameBranch rename a branch // 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) { func RenameBranch(ctx context.Context, repo *repo_model.Repository, doer *user_model.User, gitRepo *git.Repository, from, to string) (string, error) {
err := repo.MustNotBeArchived()
if err != nil {
return "", err
}
if from == to { if from == to {
return "target_exist", nil return "target_exist", nil
} }
@ -315,6 +330,11 @@ var (
// DeleteBranch delete branch // DeleteBranch delete branch
func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, gitRepo *git.Repository, branchName string) error { func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, gitRepo *git.Repository, branchName string) error {
err := repo.MustNotBeArchived()
if err != nil {
return err
}
if branchName == repo.DefaultBranch { if branchName == repo.DefaultBranch {
return ErrBranchIsDefault return ErrBranchIsDefault
} }

View File

@ -95,6 +95,11 @@ func (opts *ApplyDiffPatchOptions) Validate(ctx context.Context, repo *repo_mode
// ApplyDiffPatch applies a patch to the given repository // 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) { func ApplyDiffPatch(ctx context.Context, repo *repo_model.Repository, doer *user_model.User, opts *ApplyDiffPatchOptions) (*structs.FileResponse, error) {
err := repo.MustNotBeArchived()
if err != nil {
return nil, err
}
if err := opts.Validate(ctx, repo, doer); err != nil { if err := opts.Validate(ctx, repo, doer); err != nil {
return nil, err return nil, err
} }

View File

@ -65,6 +65,11 @@ type RepoFileOptions struct {
// ChangeRepoFiles adds, updates or removes multiple files in the given repository // 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) { func ChangeRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *user_model.User, opts *ChangeRepoFilesOptions) (*structs.FilesResponse, error) {
err := repo.MustNotBeArchived()
if err != nil {
return nil, err
}
// If no branch name is set, assume default branch // If no branch name is set, assume default branch
if opts.OldBranch == "" { if opts.OldBranch == "" {
opts.OldBranch = repo.DefaultBranch opts.OldBranch = repo.DefaultBranch

View File

@ -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. // 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) { 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.MustNotBeArchived()
if err != nil {
return err
}
if err = validateWebPath(newWikiName); err != nil { if err = validateWebPath(newWikiName); err != nil {
return err 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. // 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) { func DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, wikiName WebPath) (err error) {
err = repo.MustNotBeArchived()
if err != nil {
return err
}
wikiWorkingPool.CheckIn(fmt.Sprint(repo.ID)) wikiWorkingPool.CheckIn(fmt.Sprint(repo.ID))
defer wikiWorkingPool.CheckOut(fmt.Sprint(repo.ID)) defer wikiWorkingPool.CheckOut(fmt.Sprint(repo.ID))

View File

@ -3719,6 +3719,9 @@
}, },
"422": { "422": {
"$ref": "#/responses/validationError" "$ref": "#/responses/validationError"
},
"423": {
"$ref": "#/responses/repoArchivedError"
} }
} }
} }
@ -3857,6 +3860,9 @@
}, },
"422": { "422": {
"$ref": "#/responses/validationError" "$ref": "#/responses/validationError"
},
"423": {
"$ref": "#/responses/repoArchivedError"
} }
} }
} }
@ -3952,6 +3958,9 @@
}, },
"409": { "409": {
"description": "The branch with the same name already exists." "description": "The branch with the same name already exists."
},
"423": {
"$ref": "#/responses/repoArchivedError"
} }
} }
} }
@ -4039,6 +4048,9 @@
}, },
"404": { "404": {
"$ref": "#/responses/notFound" "$ref": "#/responses/notFound"
},
"423": {
"$ref": "#/responses/repoArchivedError"
} }
} }
} }
@ -4596,6 +4608,9 @@
}, },
"422": { "422": {
"$ref": "#/responses/error" "$ref": "#/responses/error"
},
"423": {
"$ref": "#/responses/repoArchivedError"
} }
} }
} }
@ -4703,6 +4718,9 @@
}, },
"422": { "422": {
"$ref": "#/responses/error" "$ref": "#/responses/error"
},
"423": {
"$ref": "#/responses/repoArchivedError"
} }
} }
}, },
@ -4761,6 +4779,9 @@
}, },
"422": { "422": {
"$ref": "#/responses/error" "$ref": "#/responses/error"
},
"423": {
"$ref": "#/responses/repoArchivedError"
} }
} }
}, },
@ -4819,6 +4840,9 @@
}, },
"404": { "404": {
"$ref": "#/responses/error" "$ref": "#/responses/error"
},
"423": {
"$ref": "#/responses/repoArchivedError"
} }
} }
} }
@ -4866,6 +4890,9 @@
}, },
"404": { "404": {
"$ref": "#/responses/notFound" "$ref": "#/responses/notFound"
},
"423": {
"$ref": "#/responses/repoArchivedError"
} }
} }
} }
@ -6137,6 +6164,9 @@
}, },
"422": { "422": {
"$ref": "#/responses/validationError" "$ref": "#/responses/validationError"
},
"423": {
"$ref": "#/responses/repoArchivedError"
} }
} }
} }
@ -6352,6 +6382,9 @@
}, },
"404": { "404": {
"$ref": "#/responses/notFound" "$ref": "#/responses/notFound"
},
"423": {
"$ref": "#/responses/repoArchivedError"
} }
} }
} }
@ -6457,6 +6490,9 @@
}, },
"404": { "404": {
"$ref": "#/responses/error" "$ref": "#/responses/error"
},
"423": {
"$ref": "#/responses/repoArchivedError"
} }
} }
} }
@ -6559,6 +6595,9 @@
}, },
"404": { "404": {
"$ref": "#/responses/error" "$ref": "#/responses/error"
},
"423": {
"$ref": "#/responses/repoArchivedError"
} }
} }
}, },
@ -6619,6 +6658,9 @@
}, },
"404": { "404": {
"$ref": "#/responses/error" "$ref": "#/responses/error"
},
"423": {
"$ref": "#/responses/repoArchivedError"
} }
} }
} }
@ -7067,6 +7109,9 @@
}, },
"404": { "404": {
"$ref": "#/responses/error" "$ref": "#/responses/error"
},
"423": {
"$ref": "#/responses/repoArchivedError"
} }
} }
} }
@ -7169,6 +7214,9 @@
}, },
"404": { "404": {
"$ref": "#/responses/error" "$ref": "#/responses/error"
},
"423": {
"$ref": "#/responses/repoArchivedError"
} }
} }
}, },
@ -7229,6 +7277,9 @@
}, },
"404": { "404": {
"$ref": "#/responses/error" "$ref": "#/responses/error"
},
"423": {
"$ref": "#/responses/repoArchivedError"
} }
} }
} }
@ -7493,6 +7544,9 @@
}, },
"404": { "404": {
"$ref": "#/responses/notFound" "$ref": "#/responses/notFound"
},
"423": {
"$ref": "#/responses/repoArchivedError"
} }
} }
} }
@ -7771,6 +7825,9 @@
}, },
"404": { "404": {
"description": "the issue does not exist" "description": "the issue does not exist"
},
"423": {
"$ref": "#/responses/repoArchivedError"
} }
} }
}, },
@ -7819,6 +7876,9 @@
}, },
"404": { "404": {
"$ref": "#/responses/notFound" "$ref": "#/responses/notFound"
},
"423": {
"$ref": "#/responses/repoArchivedError"
} }
} }
} }
@ -10205,6 +10265,9 @@
}, },
"422": { "422": {
"$ref": "#/responses/validationError" "$ref": "#/responses/validationError"
},
"423": {
"$ref": "#/responses/repoArchivedError"
} }
} }
} }
@ -10639,6 +10702,9 @@
}, },
"409": { "409": {
"$ref": "#/responses/error" "$ref": "#/responses/error"
},
"423": {
"$ref": "#/responses/repoArchivedError"
} }
} }
}, },
@ -10684,6 +10750,9 @@
}, },
"404": { "404": {
"$ref": "#/responses/notFound" "$ref": "#/responses/notFound"
},
"423": {
"$ref": "#/responses/repoArchivedError"
} }
} }
} }
@ -12725,6 +12794,9 @@
}, },
"409": { "409": {
"$ref": "#/responses/conflict" "$ref": "#/responses/conflict"
},
"423": {
"$ref": "#/responses/repoArchivedError"
} }
} }
} }
@ -12815,6 +12887,9 @@
}, },
"409": { "409": {
"$ref": "#/responses/conflict" "$ref": "#/responses/conflict"
},
"423": {
"$ref": "#/responses/repoArchivedError"
} }
} }
} }
@ -13475,6 +13550,9 @@
}, },
"404": { "404": {
"$ref": "#/responses/notFound" "$ref": "#/responses/notFound"
},
"423": {
"$ref": "#/responses/repoArchivedError"
} }
} }
} }
@ -13559,6 +13637,9 @@
}, },
"404": { "404": {
"$ref": "#/responses/notFound" "$ref": "#/responses/notFound"
},
"423": {
"$ref": "#/responses/repoArchivedError"
} }
} }
}, },
@ -13613,6 +13694,9 @@
}, },
"404": { "404": {
"$ref": "#/responses/notFound" "$ref": "#/responses/notFound"
},
"423": {
"$ref": "#/responses/repoArchivedError"
} }
} }
} }
@ -23903,6 +23987,17 @@
"redirect": { "redirect": {
"description": "APIRedirect is a redirect response" "description": "APIRedirect is a redirect response"
}, },
"repoArchivedError": {
"description": "APIRepoArchivedError is an error that is raised when an archived repo should be modified",
"headers": {
"message": {
"type": "string"
},
"url": {
"type": "string"
}
}
},
"string": { "string": {
"description": "APIString is a string response", "description": "APIString is a string response",
"schema": { "schema": {