", " ")
- assert.EqualValues(t, expected, string(newTestRenderUtils().RenderIssueTitle(testInput(), nil)))
+ assert.EqualValues(t, expected, string(newTestRenderUtils().RenderIssueTitle(testInput(), testMetas)))
}
func TestRenderMarkdownToHtml(t *testing.T) {
diff --git a/modules/web/route.go b/modules/web/route.go
index 77c411a97b..787521dfb0 100644
--- a/modules/web/route.go
+++ b/modules/web/route.go
@@ -9,6 +9,7 @@ import (
"reflect"
"strings"
+ "code.gitea.io/gitea/modules/htmlutil"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/web/middleware"
@@ -214,7 +215,9 @@ func (r *Router) normalizeRequestPath(resp http.ResponseWriter, req *http.Reques
normalizedPath = "/"
} else if !strings.HasPrefix(normalizedPath+"/", "/v2/") {
// do not respond to other requests, to simulate a real sub-path environment
- http.Error(resp, "404 page not found, sub-path is: "+setting.AppSubURL, http.StatusNotFound)
+ resp.Header().Add("Content-Type", "text/html; charset=utf-8")
+ resp.WriteHeader(http.StatusNotFound)
+ _, _ = resp.Write([]byte(htmlutil.HTMLFormat(`404 page not found, sub-path is: %s`, setting.AppSubURL, setting.AppSubURL)))
return
}
normalized = true
diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini
index 1a2db341e2..b82de7bfb8 100644
--- a/options/locale/locale_en-US.ini
+++ b/options/locale/locale_en-US.ini
@@ -2601,7 +2601,6 @@ diff.generated = generated
diff.vendored = vendored
diff.comment.add_line_comment = Add line comment
diff.comment.placeholder = Leave a comment
-diff.comment.markdown_info = Styling with markdown is supported.
diff.comment.add_single_comment = Add single comment
diff.comment.add_review_comment = Add comment
diff.comment.start_review = Start review
diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go
index 45c5c1cd14..53f3b4648a 100644
--- a/routers/api/v1/repo/branch.go
+++ b/routers/api/v1/repo/branch.go
@@ -150,11 +150,6 @@ func DeleteBranch(ctx *context.APIContext) {
}
}
- if ctx.Repo.Repository.IsMirror {
- ctx.Error(http.StatusForbidden, "IsMirrored", fmt.Errorf("can not delete branch of an mirror repository"))
- return
- }
-
if err := repo_service.DeleteBranch(ctx, ctx.Doer, ctx.Repo.Repository, ctx.Repo.GitRepo, branchName); err != nil {
switch {
case git.IsErrBranchNotExist(err):
diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go
index 28d7379f07..1116a4e9b1 100644
--- a/routers/api/v1/repo/pull.go
+++ b/routers/api/v1/repo/pull.go
@@ -1057,49 +1057,54 @@ func MergePullRequest(ctx *context.APIContext) {
}
log.Trace("Pull request merged: %d", pr.ID)
- if form.DeleteBranchAfterMerge {
- // Don't cleanup when there are other PR's that use this branch as head branch.
- exist, err := issues_model.HasUnmergedPullRequestsByHeadInfo(ctx, pr.HeadRepoID, pr.HeadBranch)
- if err != nil {
- ctx.ServerError("HasUnmergedPullRequestsByHeadInfo", err)
- return
- }
- if exist {
- ctx.Status(http.StatusOK)
- return
- }
-
- var headRepo *git.Repository
- if ctx.Repo != nil && ctx.Repo.Repository != nil && ctx.Repo.Repository.ID == pr.HeadRepoID && ctx.Repo.GitRepo != nil {
- headRepo = ctx.Repo.GitRepo
- } else {
- headRepo, err = gitrepo.OpenRepository(ctx, pr.HeadRepo)
+ // for agit flow, we should not delete the agit reference after merge
+ if form.DeleteBranchAfterMerge && pr.Flow == issues_model.PullRequestFlowGithub {
+ // check permission even it has been checked in repo_service.DeleteBranch so that we don't need to
+ // do RetargetChildrenOnMerge
+ if err := repo_service.CanDeleteBranch(ctx, pr.HeadRepo, pr.HeadBranch, ctx.Doer); err == nil {
+ // Don't cleanup when there are other PR's that use this branch as head branch.
+ exist, err := issues_model.HasUnmergedPullRequestsByHeadInfo(ctx, pr.HeadRepoID, pr.HeadBranch)
if err != nil {
- ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.FullName()), err)
+ ctx.ServerError("HasUnmergedPullRequestsByHeadInfo", err)
return
}
- defer headRepo.Close()
- }
- if err := pull_service.RetargetChildrenOnMerge(ctx, ctx.Doer, pr); err != nil {
- ctx.Error(http.StatusInternalServerError, "RetargetChildrenOnMerge", err)
- return
- }
- if err := repo_service.DeleteBranch(ctx, ctx.Doer, pr.HeadRepo, headRepo, pr.HeadBranch); err != nil {
- switch {
- case git.IsErrBranchNotExist(err):
- ctx.NotFound(err)
- case errors.Is(err, repo_service.ErrBranchIsDefault):
- ctx.Error(http.StatusForbidden, "DefaultBranch", fmt.Errorf("can not delete default branch"))
- case errors.Is(err, git_model.ErrBranchIsProtected):
- ctx.Error(http.StatusForbidden, "IsProtectedBranch", fmt.Errorf("branch protected"))
- default:
- ctx.Error(http.StatusInternalServerError, "DeleteBranch", err)
+ if exist {
+ ctx.Status(http.StatusOK)
+ return
+ }
+
+ var headRepo *git.Repository
+ if ctx.Repo != nil && ctx.Repo.Repository != nil && ctx.Repo.Repository.ID == pr.HeadRepoID && ctx.Repo.GitRepo != nil {
+ headRepo = ctx.Repo.GitRepo
+ } else {
+ headRepo, err = gitrepo.OpenRepository(ctx, pr.HeadRepo)
+ if err != nil {
+ ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.FullName()), err)
+ return
+ }
+ defer headRepo.Close()
+ }
+ if err := pull_service.RetargetChildrenOnMerge(ctx, ctx.Doer, pr); err != nil {
+ ctx.Error(http.StatusInternalServerError, "RetargetChildrenOnMerge", err)
+ return
+ }
+ if err := repo_service.DeleteBranch(ctx, ctx.Doer, pr.HeadRepo, headRepo, pr.HeadBranch); err != nil {
+ switch {
+ case git.IsErrBranchNotExist(err):
+ ctx.NotFound(err)
+ case errors.Is(err, repo_service.ErrBranchIsDefault):
+ ctx.Error(http.StatusForbidden, "DefaultBranch", fmt.Errorf("can not delete default branch"))
+ case errors.Is(err, git_model.ErrBranchIsProtected):
+ ctx.Error(http.StatusForbidden, "IsProtectedBranch", fmt.Errorf("branch protected"))
+ default:
+ ctx.Error(http.StatusInternalServerError, "DeleteBranch", err)
+ }
+ return
+ }
+ if err := issues_model.AddDeletePRBranchComment(ctx, ctx.Doer, pr.BaseRepo, pr.Issue.ID, pr.HeadBranch); err != nil {
+ // Do not fail here as branch has already been deleted
+ log.Error("DeleteBranch: %v", err)
}
- return
- }
- if err := issues_model.AddDeletePRBranchComment(ctx, ctx.Doer, pr.BaseRepo, pr.Issue.ID, pr.HeadBranch); err != nil {
- // Do not fail here as branch has already been deleted
- log.Error("DeleteBranch: %v", err)
}
}
diff --git a/routers/web/repo/commit.go b/routers/web/repo/commit.go
index 0be9689c3f..c5652784fa 100644
--- a/routers/web/repo/commit.go
+++ b/routers/web/repo/commit.go
@@ -394,9 +394,9 @@ func Diff(ctx *context.Context) {
ctx.Data["NoteCommit"] = note.Commit
ctx.Data["NoteAuthor"] = user_model.ValidateCommitWithEmail(ctx, note.Commit)
rctx := renderhelper.NewRenderContextRepoComment(ctx, ctx.Repo.Repository, renderhelper.RepoCommentOptions{CurrentRefPath: path.Join("commit", util.PathEscapeSegments(commitID))})
- ctx.Data["NoteRendered"], err = markup.RenderCommitMessage(rctx, template.HTMLEscapeString(string(charset.ToUTF8WithFallback(note.Message, charset.ConvertOpts{}))))
+ ctx.Data["NoteRendered"], err = markup.PostProcessCommitMessage(rctx, template.HTMLEscapeString(string(charset.ToUTF8WithFallback(note.Message, charset.ConvertOpts{}))))
if err != nil {
- ctx.ServerError("RenderCommitMessage", err)
+ ctx.ServerError("PostProcessCommitMessage", err)
return
}
}
diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go
index cd20c0b18e..e3b329d01d 100644
--- a/routers/web/repo/pull.go
+++ b/routers/web/repo/pull.go
@@ -1185,32 +1185,34 @@ func MergePullRequest(ctx *context.Context) {
log.Trace("Pull request merged: %d", pr.ID)
- if form.DeleteBranchAfterMerge {
- // Don't cleanup when other pr use this branch as head branch
- exist, err := issues_model.HasUnmergedPullRequestsByHeadInfo(ctx, pr.HeadRepoID, pr.HeadBranch)
- if err != nil {
- ctx.ServerError("HasUnmergedPullRequestsByHeadInfo", err)
- return
- }
- if exist {
- ctx.JSONRedirect(issue.Link())
- return
- }
-
- var headRepo *git.Repository
- if ctx.Repo != nil && ctx.Repo.Repository != nil && pr.HeadRepoID == ctx.Repo.Repository.ID && ctx.Repo.GitRepo != nil {
- headRepo = ctx.Repo.GitRepo
- } else {
- headRepo, err = gitrepo.OpenRepository(ctx, pr.HeadRepo)
- if err != nil {
- ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.FullName()), err)
- return
- }
- defer headRepo.Close()
- }
- deleteBranch(ctx, pr, headRepo)
+ if !form.DeleteBranchAfterMerge {
+ ctx.JSONRedirect(issue.Link())
+ return
}
+ // Don't cleanup when other pr use this branch as head branch
+ exist, err := issues_model.HasUnmergedPullRequestsByHeadInfo(ctx, pr.HeadRepoID, pr.HeadBranch)
+ if err != nil {
+ ctx.ServerError("HasUnmergedPullRequestsByHeadInfo", err)
+ return
+ }
+ if exist {
+ ctx.JSONRedirect(issue.Link())
+ return
+ }
+
+ var headRepo *git.Repository
+ if ctx.Repo != nil && ctx.Repo.Repository != nil && pr.HeadRepoID == ctx.Repo.Repository.ID && ctx.Repo.GitRepo != nil {
+ headRepo = ctx.Repo.GitRepo
+ } else {
+ headRepo, err = gitrepo.OpenRepository(ctx, pr.HeadRepo)
+ if err != nil {
+ ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.FullName()), err)
+ return
+ }
+ defer headRepo.Close()
+ }
+ deleteBranch(ctx, pr, headRepo)
ctx.JSONRedirect(issue.Link())
}
@@ -1403,8 +1405,8 @@ func CleanUpPullRequest(ctx *context.Context) {
pr := issue.PullRequest
- // Don't cleanup unmerged and unclosed PRs
- if !pr.HasMerged && !issue.IsClosed {
+ // Don't cleanup unmerged and unclosed PRs and agit PRs
+ if !pr.HasMerged && !issue.IsClosed && pr.Flow != issues_model.PullRequestFlowGithub {
ctx.NotFound("CleanUpPullRequest", nil)
return
}
@@ -1435,13 +1437,12 @@ func CleanUpPullRequest(ctx *context.Context) {
return
}
- perm, err := access_model.GetUserRepoPermission(ctx, pr.HeadRepo, ctx.Doer)
- if err != nil {
- ctx.ServerError("GetUserRepoPermission", err)
- return
- }
- if !perm.CanWrite(unit.TypeCode) {
- ctx.NotFound("CleanUpPullRequest", nil)
+ if err := repo_service.CanDeleteBranch(ctx, pr.HeadRepo, pr.HeadBranch, ctx.Doer); err != nil {
+ if errors.Is(err, util.ErrPermissionDenied) {
+ ctx.NotFound("CanDeleteBranch", nil)
+ } else {
+ ctx.ServerError("CanDeleteBranch", err)
+ }
return
}
diff --git a/routers/web/web.go b/routers/web/web.go
index 895e626578..87d6faca02 100644
--- a/routers/web/web.go
+++ b/routers/web/web.go
@@ -485,6 +485,8 @@ func registerRoutes(m *web.Router) {
m.Methods("GET, HEAD", "/*", public.FileHandlerFunc())
}, optionsCorsHandler())
+ m.Post("/-/markup", reqSignIn, web.Bind(structs.MarkupOption{}), misc.Markup)
+
m.Group("/explore", func() {
m.Get("", func(ctx *context.Context) {
ctx.Redirect(setting.AppSubURL + "/explore/repos")
diff --git a/services/repository/branch.go b/services/repository/branch.go
index a155b1945d..0ce8c2a177 100644
--- a/services/repository/branch.go
+++ b/services/repository/branch.go
@@ -14,7 +14,9 @@ import (
"code.gitea.io/gitea/models/db"
git_model "code.gitea.io/gitea/models/git"
issues_model "code.gitea.io/gitea/models/issues"
+ access_model "code.gitea.io/gitea/models/perm/access"
repo_model "code.gitea.io/gitea/models/repo"
+ "code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/cache"
"code.gitea.io/gitea/modules/git"
@@ -463,15 +465,17 @@ var (
ErrBranchIsDefault = errors.New("branch is default")
)
-// DeleteBranch delete branch
-func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, gitRepo *git.Repository, branchName string) error {
- err := repo.MustNotBeArchived()
+func CanDeleteBranch(ctx context.Context, repo *repo_model.Repository, branchName string, doer *user_model.User) error {
+ if branchName == repo.DefaultBranch {
+ return ErrBranchIsDefault
+ }
+
+ perm, err := access_model.GetUserRepoPermission(ctx, repo, doer)
if err != nil {
return err
}
-
- if branchName == repo.DefaultBranch {
- return ErrBranchIsDefault
+ if !perm.CanWrite(unit.TypeCode) {
+ return util.NewPermissionDeniedErrorf("permission denied to access repo %d unit %s", repo.ID, unit.TypeCode.LogString())
}
isProtected, err := git_model.IsBranchProtected(ctx, repo.ID, branchName)
@@ -481,6 +485,19 @@ func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.R
if isProtected {
return git_model.ErrBranchIsProtected
}
+ return nil
+}
+
+// DeleteBranch delete branch
+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 err := CanDeleteBranch(ctx, repo, branchName, doer); err != nil {
+ return err
+ }
rawBranch, err := git_model.GetBranch(ctx, repo.ID, branchName)
if err != nil && !git_model.IsErrBranchNotExist(err) {
diff --git a/templates/devtest/devtest-footer.tmpl b/templates/devtest/devtest-footer.tmpl
index 1c755508a5..a1b3b86e5c 100644
--- a/templates/devtest/devtest-footer.tmpl
+++ b/templates/devtest/devtest-footer.tmpl
@@ -1,3 +1,3 @@
{{/* TODO: the devtest.js is isolated from index.js, so no module is shared and many index.js functions do not work in devtest.ts */}}
-{{template "base/footer" dict}}
+{{template "base/footer" ctx.RootData}}
diff --git a/templates/devtest/devtest-header.tmpl b/templates/devtest/devtest-header.tmpl
index a5910b96e6..ee08545640 100644
--- a/templates/devtest/devtest-header.tmpl
+++ b/templates/devtest/devtest-header.tmpl
@@ -1,2 +1,2 @@
-{{template "base/head" dict}}
+{{template "base/head" ctx.RootData}}
diff --git a/templates/devtest/gitea-ui.tmpl b/templates/devtest/gitea-ui.tmpl
index 303421fe13..5b40268761 100644
--- a/templates/devtest/gitea-ui.tmpl
+++ b/templates/devtest/gitea-ui.tmpl
@@ -183,8 +183,7 @@
ComboMarkdownEditor
-
ps: no JS code attached, so just a layout
- {{template "shared/combomarkdowneditor" .}}
+ {{template "shared/combomarkdowneditor" dict "MarkdownPreviewContext" "/owner/path"}}
Tailwind CSS Demo
diff --git a/templates/org/settings/options.tmpl b/templates/org/settings/options.tmpl
index 62debfc0ae..3b817d068b 100644
--- a/templates/org/settings/options.tmpl
+++ b/templates/org/settings/options.tmpl
@@ -23,6 +23,7 @@
+ {{/* it is rendered as markdown, but the length is limited, so at the moment we do not use the markdown editor here */}}
diff --git a/templates/projects/new.tmpl b/templates/projects/new.tmpl
index bd173b54bc..a936079c46 100644
--- a/templates/projects/new.tmpl
+++ b/templates/projects/new.tmpl
@@ -18,7 +18,16 @@
-
+ {{/* TODO: repo-level project and org-level project have different behaviros to render */}}
+ {{/* the "Repository" is nil when the project is org-level */}}
+ {{template "shared/combomarkdowneditor" (dict
+ "MarkdownPreviewInRepo" $.Repository
+ "MarkdownPreviewContext" (Iif $.Repository "" .HomeLink)
+ "MarkdownPreviewMode" (Iif $.Repository "comment")
+ "TextareaName" "content"
+ "TextareaContent" .content
+ "TextareaPlaceholder" (ctx.Locale.Tr "repo.projects.description_placeholder")
+ )}}
{{if not .PageIsEditProjects}}
diff --git a/templates/repo/diff/box.tmpl b/templates/repo/diff/box.tmpl
index 20e0c9db66..0f1458bfbf 100644
--- a/templates/repo/diff/box.tmpl
+++ b/templates/repo/diff/box.tmpl
@@ -240,8 +240,9 @@
- {{ctx.RenderUtils.RenderIssueTitle .Issue.Title ($.Repository.ComposeMetas ctx) | RenderCodeBlock}} + {{ctx.RenderUtils.RenderIssueTitle .Issue.Title ($.Repository.ComposeMetas ctx)}} #{{.Issue.Index}}
{{ctx.Locale.Tr "repo.activity.merged_prs_label"}} - #{{.Index}} {{.Issue.Title | ctx.RenderUtils.RenderEmoji | RenderCodeBlock}} + #{{.Index}} {{.Issue.Title | ctx.RenderUtils.RenderIssueSimpleTitle}} {{DateUtils.TimeSince .MergedUnix}}
{{end}} @@ -164,7 +164,7 @@ {{range .Activity.OpenedPRs}}{{ctx.Locale.Tr "repo.activity.opened_prs_label"}} - #{{.Index}} {{.Issue.Title | ctx.RenderUtils.RenderEmoji | RenderCodeBlock}} + #{{.Index}} {{.Issue.Title | ctx.RenderUtils.RenderIssueSimpleTitle}} {{DateUtils.TimeSince .Issue.CreatedUnix}}
{{end}} @@ -183,7 +183,7 @@ {{range .Activity.ClosedIssues}}{{ctx.Locale.Tr "repo.activity.closed_issue_label"}} - #{{.Index}} {{.Title | ctx.RenderUtils.RenderEmoji | RenderCodeBlock}} + #{{.Index}} {{.Title | ctx.RenderUtils.RenderIssueSimpleTitle}} {{DateUtils.TimeSince .ClosedUnix}}
{{end}} @@ -202,7 +202,7 @@ {{range .Activity.OpenedIssues}}{{ctx.Locale.Tr "repo.activity.new_issue_label"}} - #{{.Index}} {{.Title | ctx.RenderUtils.RenderEmoji | RenderCodeBlock}} + #{{.Index}} {{.Title | ctx.RenderUtils.RenderIssueSimpleTitle}} {{DateUtils.TimeSince .CreatedUnix}}
{{end}} @@ -220,9 +220,9 @@ {{ctx.Locale.Tr "repo.activity.unresolved_conv_label"}} #{{.Index}} {{if .IsPull}} - {{.Title | ctx.RenderUtils.RenderEmoji | RenderCodeBlock}} + {{.Title | ctx.RenderUtils.RenderIssueSimpleTitle}} {{else}} - {{.Title | ctx.RenderUtils.RenderEmoji | RenderCodeBlock}} + {{.Title | ctx.RenderUtils.RenderIssueSimpleTitle}} {{end}} {{DateUtils.TimeSince .UpdatedUnix}} diff --git a/templates/repo/release/new.tmpl b/templates/repo/release/new.tmpl index c01f9a421b..574b0d0311 100644 --- a/templates/repo/release/new.tmpl +++ b/templates/repo/release/new.tmpl @@ -50,12 +50,11 @@