Skip to content

Commit 57a69ef

Browse files
adelowotechknowlogick
authored andcommitted
don't allow pull requests to be created on an archived repository (#5883)
* don't allow pull requests to be created on an archived repository Also disable the "PR" button if the repo is archived * Refuse creating an issue/PR via API calls too
1 parent 6dc2f40 commit 57a69ef

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

routers/api/v1/api.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ import (
7474
api "code.gitea.io/sdk/gitea"
7575

7676
"github.com/go-macaron/binding"
77-
"gopkg.in/macaron.v1"
77+
macaron "gopkg.in/macaron.v1"
7878
)
7979

8080
func sudo() macaron.Handler {
@@ -371,6 +371,13 @@ func mustEnableUserHeatmap(ctx *context.Context) {
371371
}
372372
}
373373

374+
func mustNotBeArchived(ctx *context.Context) {
375+
if ctx.Repo.Repository.IsArchived {
376+
ctx.Status(404)
377+
return
378+
}
379+
}
380+
374381
// RegisterRoutes registers all v1 APIs routes to web application.
375382
// FIXME: custom form error response
376383
func RegisterRoutes(m *macaron.Macaron) {
@@ -518,11 +525,11 @@ func RegisterRoutes(m *macaron.Macaron) {
518525
}, mustEnableIssues)
519526
m.Group("/issues", func() {
520527
m.Combo("").Get(repo.ListIssues).
521-
Post(reqToken(), bind(api.CreateIssueOption{}), repo.CreateIssue)
528+
Post(reqToken(), mustNotBeArchived, bind(api.CreateIssueOption{}), repo.CreateIssue)
522529
m.Group("/comments", func() {
523530
m.Get("", repo.ListRepoIssueComments)
524531
m.Combo("/:id", reqToken()).
525-
Patch(bind(api.EditIssueCommentOption{}), repo.EditIssueComment).
532+
Patch(mustNotBeArchived, bind(api.EditIssueCommentOption{}), repo.EditIssueComment).
526533
Delete(repo.DeleteIssueComment)
527534
})
528535
m.Group("/:index", func() {
@@ -531,7 +538,7 @@ func RegisterRoutes(m *macaron.Macaron) {
531538

532539
m.Group("/comments", func() {
533540
m.Combo("").Get(repo.ListIssueComments).
534-
Post(reqToken(), bind(api.CreateIssueCommentOption{}), repo.CreateIssueComment)
541+
Post(reqToken(), mustNotBeArchived, bind(api.CreateIssueCommentOption{}), repo.CreateIssueComment)
535542
m.Combo("/:id", reqToken()).Patch(bind(api.EditIssueCommentOption{}), repo.EditIssueCommentDeprecated).
536543
Delete(repo.DeleteIssueCommentDeprecated)
537544
})
@@ -593,12 +600,12 @@ func RegisterRoutes(m *macaron.Macaron) {
593600
m.Get("/editorconfig/:filename", context.RepoRef(), reqRepoReader(models.UnitTypeCode), repo.GetEditorconfig)
594601
m.Group("/pulls", func() {
595602
m.Combo("").Get(bind(api.ListPullRequestsOptions{}), repo.ListPullRequests).
596-
Post(reqToken(), bind(api.CreatePullRequestOption{}), repo.CreatePullRequest)
603+
Post(reqToken(), mustNotBeArchived, bind(api.CreatePullRequestOption{}), repo.CreatePullRequest)
597604
m.Group("/:index", func() {
598605
m.Combo("").Get(repo.GetPullRequest).
599606
Patch(reqToken(), reqRepoWriter(models.UnitTypePullRequests), bind(api.EditPullRequestOption{}), repo.EditPullRequest)
600607
m.Combo("/merge").Get(repo.IsPullRequestMerged).
601-
Post(reqToken(), reqRepoWriter(models.UnitTypePullRequests), bind(auth.MergePullRequestForm{}), repo.MergePullRequest)
608+
Post(reqToken(), mustNotBeArchived, reqRepoWriter(models.UnitTypePullRequests), bind(auth.MergePullRequestForm{}), repo.MergePullRequest)
602609
})
603610
}, mustAllowPulls, reqRepoReader(models.UnitTypeCode), context.ReferencesGitRepo())
604611
m.Group("/statuses", func() {

routers/routes/routes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ func RegisterRoutes(m *macaron.Macaron) {
586586
m.Group("/milestone", func() {
587587
m.Get("/:id", repo.MilestoneIssuesAndPulls)
588588
}, reqRepoIssuesOrPullsWriter, context.RepoRef())
589-
m.Combo("/compare/*", reqRepoCodeReader, reqRepoPullsReader, repo.MustAllowPulls, repo.SetEditorconfigIfExists).
589+
m.Combo("/compare/*", context.RepoMustNotBeArchived(), reqRepoCodeReader, reqRepoPullsReader, repo.MustAllowPulls, repo.SetEditorconfigIfExists).
590590
Get(repo.SetDiffViewStyle, repo.CompareAndPullRequest).
591591
Post(bindIgnErr(auth.CreateIssueForm{}), repo.CompareAndPullRequestPost)
592592

templates/repo/home.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
{{end}}
5858
{{template "repo/sub_menu" .}}
5959
<div class="ui stackable secondary menu mobile--margin-between-items mobile--no-negative-margins">
60-
{{if and .PullRequestCtx.Allowed .IsViewBranch}}
60+
{{if and .PullRequestCtx.Allowed .IsViewBranch (not .Repository.IsArchived)}}
6161
<div class="fitted item">
6262
<a href="{{.BaseRepo.Link}}/compare/{{.BaseRepo.DefaultBranch | EscapePound}}...{{ if .Repository.IsFork }}{{.Repository.Owner.Name}}{{ else }}{{ .SignedUserName }}{{ end }}:{{.BranchName | EscapePound}}">
6363
<button class="ui green tiny compact button"><i class="octicon octicon-git-compare"></i></button>

0 commit comments

Comments
 (0)