mirror of
https://github.com/go-gitea/gitea
synced 2025-09-15 05:08:13 +00:00
Fix context usages (#35348)
This commit is contained in:
@@ -320,7 +320,7 @@ func (a *Action) GetCommentHTMLURL(ctx context.Context) string {
|
||||
return "#"
|
||||
}
|
||||
|
||||
return a.Issue.HTMLURL()
|
||||
return a.Issue.HTMLURL(ctx)
|
||||
}
|
||||
|
||||
// GetCommentLink returns link to action comment.
|
||||
|
@@ -280,11 +280,11 @@ func (n *Notification) HTMLURL(ctx context.Context) string {
|
||||
if n.Comment != nil {
|
||||
return n.Comment.HTMLURL(ctx)
|
||||
}
|
||||
return n.Issue.HTMLURL()
|
||||
return n.Issue.HTMLURL(ctx)
|
||||
case NotificationSourceCommit:
|
||||
return n.Repository.HTMLURL() + "/commit/" + url.PathEscape(n.CommitID)
|
||||
return n.Repository.HTMLURL(ctx) + "/commit/" + url.PathEscape(n.CommitID)
|
||||
case NotificationSourceRepository:
|
||||
return n.Repository.HTMLURL()
|
||||
return n.Repository.HTMLURL(ctx)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
@@ -414,7 +414,7 @@ func (c *Comment) HTMLURL(ctx context.Context) string {
|
||||
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
|
||||
return ""
|
||||
}
|
||||
return c.Issue.HTMLURL() + c.hashLink(ctx)
|
||||
return c.Issue.HTMLURL(ctx) + c.hashLink(ctx)
|
||||
}
|
||||
|
||||
// Link formats a relative URL-string to the issue-comment
|
||||
@@ -483,7 +483,7 @@ func (c *Comment) IssueURL(ctx context.Context) string {
|
||||
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
|
||||
return ""
|
||||
}
|
||||
return c.Issue.HTMLURL()
|
||||
return c.Issue.HTMLURL(ctx)
|
||||
}
|
||||
|
||||
// PRURL formats a URL-string to the pull-request
|
||||
@@ -503,7 +503,7 @@ func (c *Comment) PRURL(ctx context.Context) string {
|
||||
if !c.Issue.IsPull {
|
||||
return ""
|
||||
}
|
||||
return c.Issue.HTMLURL()
|
||||
return c.Issue.HTMLURL(ctx)
|
||||
}
|
||||
|
||||
// CommentHashTag returns unique hash tag for comment id.
|
||||
|
@@ -405,14 +405,14 @@ func (issue *Issue) APIURL(ctx context.Context) string {
|
||||
}
|
||||
|
||||
// HTMLURL returns the absolute URL to this issue.
|
||||
func (issue *Issue) HTMLURL() string {
|
||||
func (issue *Issue) HTMLURL(ctx context.Context) string {
|
||||
var path string
|
||||
if issue.IsPull {
|
||||
path = "pulls"
|
||||
} else {
|
||||
path = "issues"
|
||||
}
|
||||
return fmt.Sprintf("%s/%s/%d", issue.Repo.HTMLURL(), path, issue.Index)
|
||||
return fmt.Sprintf("%s/%s/%d", issue.Repo.HTMLURL(ctx), path, issue.Index)
|
||||
}
|
||||
|
||||
// Link returns the issue's relative URL.
|
||||
|
@@ -4,7 +4,6 @@
|
||||
package base
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -124,7 +123,7 @@ func MainTest(m *testing.M) {
|
||||
setting.AppDataPath = tmpDataPath
|
||||
|
||||
unittest.InitSettingsForTesting()
|
||||
if err = git.InitFull(context.Background()); err != nil {
|
||||
if err = git.InitFull(); err != nil {
|
||||
testlogger.Fatalf("Unable to InitFull: %v\n", err)
|
||||
}
|
||||
setting.LoadDBSetting()
|
||||
|
@@ -501,7 +501,7 @@ Please try upgrading to a lower version first (suggested v1.6.4), then upgrade t
|
||||
|
||||
// Some migration tasks depend on the git command
|
||||
if git.DefaultContext == nil {
|
||||
if err = git.InitSimple(context.Background()); err != nil {
|
||||
if err = git.InitSimple(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@@ -159,8 +159,8 @@ func (org *Organization) AvatarLink(ctx context.Context) string {
|
||||
}
|
||||
|
||||
// HTMLURL returns the organization's full link.
|
||||
func (org *Organization) HTMLURL() string {
|
||||
return org.AsUser().HTMLURL()
|
||||
func (org *Organization) HTMLURL(ctx context.Context) string {
|
||||
return org.AsUser().HTMLURL(ctx)
|
||||
}
|
||||
|
||||
// OrganisationLink returns the organization sub page link.
|
||||
|
@@ -83,13 +83,13 @@ func (pd *PackageDescriptor) VersionWebLink() string {
|
||||
}
|
||||
|
||||
// PackageHTMLURL returns the absolute package HTML URL
|
||||
func (pd *PackageDescriptor) PackageHTMLURL() string {
|
||||
return fmt.Sprintf("%s/-/packages/%s/%s", pd.Owner.HTMLURL(), string(pd.Package.Type), url.PathEscape(pd.Package.LowerName))
|
||||
func (pd *PackageDescriptor) PackageHTMLURL(ctx context.Context) string {
|
||||
return fmt.Sprintf("%s/-/packages/%s/%s", pd.Owner.HTMLURL(ctx), string(pd.Package.Type), url.PathEscape(pd.Package.LowerName))
|
||||
}
|
||||
|
||||
// VersionHTMLURL returns the absolute package version HTML URL
|
||||
func (pd *PackageDescriptor) VersionHTMLURL() string {
|
||||
return fmt.Sprintf("%s/%s", pd.PackageHTMLURL(), url.PathEscape(pd.Version.LowerVersion))
|
||||
func (pd *PackageDescriptor) VersionHTMLURL(ctx context.Context) string {
|
||||
return fmt.Sprintf("%s/%s", pd.PackageHTMLURL(ctx), url.PathEscape(pd.Version.LowerVersion))
|
||||
}
|
||||
|
||||
// CalculateBlobSize returns the total blobs size in bytes
|
||||
|
@@ -363,10 +363,8 @@ func (repo *Repository) FullName() string {
|
||||
|
||||
// HTMLURL returns the repository HTML URL
|
||||
func (repo *Repository) HTMLURL(ctxs ...context.Context) string {
|
||||
ctx := context.TODO()
|
||||
if len(ctxs) > 0 {
|
||||
ctx = ctxs[0]
|
||||
}
|
||||
// FIXME: this HTMLURL is still used in mail templates, so the "ctx" is not provided.
|
||||
ctx := util.OptionalArg(ctxs, context.TODO())
|
||||
return httplib.MakeAbsoluteURL(ctx, repo.Link())
|
||||
}
|
||||
|
||||
|
@@ -141,7 +141,7 @@ func MainTest(m *testing.M, testOptsArg ...*TestOptions) {
|
||||
fatalTestError("util.SyncDirs: %v\n", err)
|
||||
}
|
||||
|
||||
if err = git.InitFull(context.Background()); err != nil {
|
||||
if err = git.InitFull(); err != nil {
|
||||
fatalTestError("git.Init: %v\n", err)
|
||||
}
|
||||
|
||||
|
@@ -27,6 +27,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/container"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/httplib"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/optional"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
@@ -303,8 +304,8 @@ func (u *User) HomeLink() string {
|
||||
}
|
||||
|
||||
// HTMLURL returns the user or organization's full link.
|
||||
func (u *User) HTMLURL() string {
|
||||
return setting.AppURL + url.PathEscape(u.Name)
|
||||
func (u *User) HTMLURL(ctx context.Context) string {
|
||||
return httplib.MakeAbsoluteURL(ctx, u.HomeLink())
|
||||
}
|
||||
|
||||
// OrganisationLink returns the organization sub page link.
|
||||
|
Reference in New Issue
Block a user