aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web/repo
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2024-03-27 10:34:10 +0800
committerGitHub <noreply@github.com>2024-03-27 02:34:10 +0000
commit538790ad1db8bf66942ff2ead4ef78df5ab8b702 (patch)
tree20f455eda554c8e14e557ee31d13f58edd7b3213 /routers/web/repo
parentf47e00d9d3c3bd58b5944a29c4ff5cec0357520a (diff)
downloadgitea-538790ad1db8bf66942ff2ead4ef78df5ab8b702.tar.gz
gitea-538790ad1db8bf66942ff2ead4ef78df5ab8b702.zip
Put an edit file button on pull request files to allow a quick operation (#29697)
Resolve #23848 This PR put an edit file button on pull request files to allow a quick edit for a file. After the edit finished, it will return back to the viewed file position on pull request files tab. It also use a branch view file link instead of commit link when it's a non-commit pull request files view. <img width="1532" alt="image" src="https://github.com/go-gitea/gitea/assets/81045/3637ca4c-89d5-4621-847b-79702a44f617"> --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: silverwind <me@silverwind.io>
Diffstat (limited to 'routers/web/repo')
-rw-r--r--routers/web/repo/editor.go12
-rw-r--r--routers/web/repo/pull.go26
2 files changed, 36 insertions, 2 deletions
diff --git a/routers/web/repo/editor.go b/routers/web/repo/editor.go
index 082666276a..474f7ff1da 100644
--- a/routers/web/repo/editor.go
+++ b/routers/web/repo/editor.go
@@ -80,8 +80,12 @@ func redirectForCommitChoice(ctx *context.Context, commitChoice, newBranchName,
}
}
- // Redirect to viewing file or folder
- ctx.Redirect(ctx.Repo.RepoLink + "/src/branch/" + util.PathEscapeSegments(newBranchName) + "/" + util.PathEscapeSegments(treePath))
+ returnURI := ctx.FormString("return_uri")
+
+ ctx.RedirectToCurrentSite(
+ returnURI,
+ ctx.Repo.RepoLink+"/src/branch/"+util.PathEscapeSegments(newBranchName)+"/"+util.PathEscapeSegments(treePath),
+ )
}
// getParentTreeFields returns list of parent tree names and corresponding tree paths
@@ -100,6 +104,7 @@ func getParentTreeFields(treePath string) (treeNames, treePaths []string) {
}
func editFile(ctx *context.Context, isNewFile bool) {
+ ctx.Data["PageIsViewCode"] = true
ctx.Data["PageIsEdit"] = true
ctx.Data["IsNewFile"] = isNewFile
canCommit := renderCommitRights(ctx)
@@ -190,6 +195,9 @@ func editFile(ctx *context.Context, isNewFile bool) {
ctx.Data["LineWrapExtensions"] = strings.Join(setting.Repository.Editor.LineWrapExtensions, ",")
ctx.Data["EditorconfigJson"] = GetEditorConfig(ctx, treePath)
+ ctx.Data["IsEditingFileOnly"] = ctx.FormString("return_uri") != ""
+ ctx.Data["ReturnURI"] = ctx.FormString("return_uri")
+
ctx.HTML(http.StatusOK, tplEditFile)
}
diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go
index 2422be39b8..a0a8e5410c 100644
--- a/routers/web/repo/pull.go
+++ b/routers/web/repo/pull.go
@@ -857,6 +857,32 @@ func viewPullFiles(ctx *context.Context, specifiedStartCommit, specifiedEndCommi
ctx.Data["CanBlockUser"] = func(blocker, blockee *user_model.User) bool {
return user_service.CanBlockUser(ctx, ctx.Doer, blocker, blockee)
}
+ if !willShowSpecifiedCommit && !willShowSpecifiedCommitRange && pull.Flow == issues_model.PullRequestFlowGithub {
+ if err := pull.LoadHeadRepo(ctx); err != nil {
+ ctx.ServerError("LoadHeadRepo", err)
+ return
+ }
+
+ if pull.HeadRepo != nil {
+ ctx.Data["SourcePath"] = pull.HeadRepo.Link() + "/src/branch/" + util.PathEscapeSegments(pull.HeadBranch)
+ }
+
+ if !pull.HasMerged && ctx.Doer != nil {
+ perm, err := access_model.GetUserRepoPermission(ctx, pull.HeadRepo, ctx.Doer)
+ if err != nil {
+ ctx.ServerError("GetUserRepoPermission", err)
+ return
+ }
+
+ if perm.CanWrite(unit.TypeCode) || issues_model.CanMaintainerWriteToBranch(ctx, perm, pull.HeadBranch, ctx.Doer) {
+ ctx.Data["CanEditFile"] = true
+ ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.edit_this_file")
+ ctx.Data["HeadRepoLink"] = pull.HeadRepo.Link()
+ ctx.Data["HeadBranchName"] = pull.HeadBranch
+ ctx.Data["BackToLink"] = setting.AppSubURL + ctx.Req.URL.RequestURI()
+ }
+ }
+ }
ctx.HTML(http.StatusOK, tplPullFiles)
}