mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-03 04:31:52 +02:00
Merge branch 'main' into lunny/fix_delete_code_comment
This commit is contained in:
commit
a0cdc7d3f4
134 files changed
+2714
-5632
No files matched your search
@@ -46,7 +46,7 @@ func (Action) ListActionsSecrets(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: owner of the repository
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
@@ -216,7 +216,7 @@ func (Action) GetVariable(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: name of the owner
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
@@ -270,7 +270,7 @@ func (Action) DeleteVariable(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: name of the owner
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
@@ -319,7 +319,7 @@ func (Action) CreateVariable(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: name of the owner
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
@@ -386,7 +386,7 @@ func (Action) UpdateVariable(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: name of the owner
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
@@ -458,7 +458,7 @@ func (Action) ListVariables(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: name of the owner
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
@@ -660,7 +660,7 @@ func (Action) ListWorkflowJobs(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: name of the owner
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
@@ -704,7 +704,7 @@ func (Action) ListWorkflowRuns(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: name of the owner
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
@@ -1110,7 +1110,7 @@ func GetWorkflowRun(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: name of the owner
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
@@ -1156,7 +1156,7 @@ func ListWorkflowRunJobs(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: name of the owner
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
@@ -1215,7 +1215,7 @@ func GetWorkflowJob(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: name of the owner
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
@@ -1261,7 +1261,7 @@ func GetArtifactsOfRun(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: name of the owner
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
@@ -1330,7 +1330,7 @@ func DeleteActionRun(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: name of the owner
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
@@ -1382,7 +1382,7 @@ func GetArtifacts(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: name of the owner
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
@@ -1443,7 +1443,7 @@ func GetArtifact(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: name of the owner
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
@@ -1492,7 +1492,7 @@ func DeleteArtifact(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: name of the owner
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
@@ -1559,7 +1559,7 @@ func DownloadArtifact(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: name of the owner
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
|
||||
@@ -21,7 +21,7 @@ func DownloadActionsRunJobLogs(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: name of the owner
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
|
||||
@@ -52,7 +52,7 @@ func ListPullRequests(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: Owner of the repo
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
|
||||
@@ -329,7 +329,7 @@ func Generate(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: template_owner
|
||||
// in: path
|
||||
// description: name of the template repository owner
|
||||
// description: owner of the template repository
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: template_repo
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/services/context"
|
||||
|
||||
"github.com/gorilla/feeds"
|
||||
@@ -15,10 +16,14 @@ import (
|
||||
|
||||
// ShowBranchFeed shows tags and/or releases on the repo as RSS / Atom feed
|
||||
func ShowBranchFeed(ctx *context.Context, repo *repo.Repository, formatType string) {
|
||||
commits, err := ctx.Repo.Commit.CommitsByRange(0, 10, "", "", "")
|
||||
if err != nil {
|
||||
ctx.ServerError("ShowBranchFeed", err)
|
||||
return
|
||||
var commits []*git.Commit
|
||||
var err error
|
||||
if ctx.Repo.Commit != nil {
|
||||
commits, err = ctx.Repo.Commit.CommitsByRange(0, 10, "", "", "")
|
||||
if err != nil {
|
||||
ctx.ServerError("ShowBranchFeed", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
title := "Latest commits for branch " + ctx.Repo.BranchName
|
||||
|
||||
@@ -581,7 +581,7 @@ func GetPullCommits(ctx *context.Context) {
|
||||
}
|
||||
resp := &pullCommitList{}
|
||||
|
||||
commits, lastReviewCommitSha, err := pull_service.GetPullCommits(ctx, issue)
|
||||
commits, lastReviewCommitSha, err := pull_service.GetPullCommits(ctx, ctx.Repo.GitRepo, ctx.Doer, issue)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusInternalServerError, err)
|
||||
return
|
||||
|
||||
@@ -19,8 +19,8 @@ import (
|
||||
unit_model "code.gitea.io/gitea/models/unit"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
giturl "code.gitea.io/gitea/modules/git/url"
|
||||
"code.gitea.io/gitea/modules/gitrepo"
|
||||
"code.gitea.io/gitea/modules/htmlutil"
|
||||
"code.gitea.io/gitea/modules/httplib"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
repo_module "code.gitea.io/gitea/modules/repository"
|
||||
@@ -258,35 +258,41 @@ func handleRepoEmptyOrBroken(ctx *context.Context) {
|
||||
ctx.Redirect(link)
|
||||
}
|
||||
|
||||
func handleRepoViewSubmodule(ctx *context.Context, submodule *git.SubModule) {
|
||||
// TODO: it needs to use git.NewCommitSubmoduleFile and SubmoduleWebLinkTree to correctly handle relative paths
|
||||
submoduleRepoURL, err := giturl.ParseRepositoryURL(ctx, submodule.URL)
|
||||
if err != nil {
|
||||
HandleGitError(ctx, "handleRepoViewSubmodule: ParseRepositoryURL", err)
|
||||
func isViewHomeOnlyContent(ctx *context.Context) bool {
|
||||
return ctx.FormBool("only_content")
|
||||
}
|
||||
|
||||
func handleRepoViewSubmodule(ctx *context.Context, commitSubmoduleFile *git.CommitSubmoduleFile) {
|
||||
submoduleWebLink := commitSubmoduleFile.SubmoduleWebLinkTree(ctx)
|
||||
if submoduleWebLink == nil {
|
||||
ctx.Data["NotFoundPrompt"] = ctx.Repo.TreePath
|
||||
ctx.NotFound(nil)
|
||||
return
|
||||
}
|
||||
submoduleURL := giturl.MakeRepositoryWebLink(submoduleRepoURL)
|
||||
if httplib.IsCurrentGiteaSiteURL(ctx, submoduleURL) {
|
||||
ctx.RedirectToCurrentSite(submoduleURL)
|
||||
} else {
|
||||
|
||||
redirectLink := submoduleWebLink.CommitWebLink
|
||||
if isViewHomeOnlyContent(ctx) {
|
||||
ctx.Resp.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
_, _ = ctx.Resp.Write([]byte(htmlutil.HTMLFormat(`<a href="%s">%s</a>`, redirectLink, redirectLink)))
|
||||
} else if !httplib.IsCurrentGiteaSiteURL(ctx, redirectLink) {
|
||||
// don't auto-redirect to external URL, to avoid open redirect or phishing
|
||||
ctx.Data["NotFoundPrompt"] = submoduleURL
|
||||
ctx.Data["NotFoundPrompt"] = redirectLink
|
||||
ctx.NotFound(nil)
|
||||
} else {
|
||||
ctx.Redirect(submoduleWebLink.CommitWebLink)
|
||||
}
|
||||
}
|
||||
|
||||
func prepareToRenderDirOrFile(entry *git.TreeEntry) func(ctx *context.Context) {
|
||||
return func(ctx *context.Context) {
|
||||
if entry.IsSubModule() {
|
||||
submodule, err := ctx.Repo.Commit.GetSubModule(entry.Name())
|
||||
commitSubmoduleFile, err := git.GetCommitInfoSubmoduleFile(ctx.Repo.RepoLink, ctx.Repo.TreePath, ctx.Repo.Commit, entry.ID)
|
||||
if err != nil {
|
||||
HandleGitError(ctx, "prepareToRenderDirOrFile: GetSubModule", err)
|
||||
HandleGitError(ctx, "prepareToRenderDirOrFile: GetCommitInfoSubmoduleFile", err)
|
||||
return
|
||||
}
|
||||
handleRepoViewSubmodule(ctx, submodule)
|
||||
return
|
||||
}
|
||||
if entry.IsDir() {
|
||||
handleRepoViewSubmodule(ctx, commitSubmoduleFile)
|
||||
} else if entry.IsDir() {
|
||||
prepareToRenderDirectory(ctx)
|
||||
} else {
|
||||
prepareFileView(ctx, entry)
|
||||
@@ -441,7 +447,7 @@ func Home(ctx *context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
if ctx.FormBool("only_content") {
|
||||
if isViewHomeOnlyContent(ctx) {
|
||||
ctx.HTML(http.StatusOK, tplRepoViewContent)
|
||||
} else if len(treeNames) != 0 {
|
||||
ctx.HTML(http.StatusOK, tplRepoView)
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
git_module "code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/services/contexttest"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -19,14 +18,20 @@ func TestViewHomeSubmoduleRedirect(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
|
||||
ctx, _ := contexttest.MockContext(t, "/user2/repo1/src/branch/master/test-submodule")
|
||||
submodule := &git_module.SubModule{Path: "test-submodule", URL: setting.AppURL + "user2/repo-other.git"}
|
||||
submodule := git_module.NewCommitSubmoduleFile("/user2/repo1", "test-submodule", "../repo-other", "any-ref-id")
|
||||
handleRepoViewSubmodule(ctx, submodule)
|
||||
assert.Equal(t, http.StatusSeeOther, ctx.Resp.WrittenStatus())
|
||||
assert.Equal(t, "/user2/repo-other", ctx.Resp.Header().Get("Location"))
|
||||
assert.Equal(t, "/user2/repo-other/tree/any-ref-id", ctx.Resp.Header().Get("Location"))
|
||||
|
||||
ctx, _ = contexttest.MockContext(t, "/user2/repo1/src/branch/master/test-submodule")
|
||||
submodule = &git_module.SubModule{Path: "test-submodule", URL: "https://other/user2/repo-other.git"}
|
||||
submodule = git_module.NewCommitSubmoduleFile("/user2/repo1", "test-submodule", "https://other/user2/repo-other.git", "any-ref-id")
|
||||
handleRepoViewSubmodule(ctx, submodule)
|
||||
// do not auto-redirect for external URLs, to avoid open redirect or phishing
|
||||
assert.Equal(t, http.StatusNotFound, ctx.Resp.WrittenStatus())
|
||||
|
||||
ctx, respWriter := contexttest.MockContext(t, "/user2/repo1/src/branch/master/test-submodule?only_content=true")
|
||||
submodule = git_module.NewCommitSubmoduleFile("/user2/repo1", "test-submodule", "../repo-other", "any-ref-id")
|
||||
handleRepoViewSubmodule(ctx, submodule)
|
||||
assert.Equal(t, http.StatusOK, ctx.Resp.WrittenStatus())
|
||||
assert.Equal(t, `<a href="/user2/repo-other/tree/any-ref-id">/user2/repo-other/tree/any-ref-id</a>`, respWriter.Body.String())
|
||||
}
|
||||
Reference in new issue
Block a user