1
1
mirror of https://github.com/go-gitea/gitea synced 2025-08-29 12:58:29 +00:00

Fix context usages (#35348)

This commit is contained in:
wxiaoguang
2025-08-27 19:00:01 +08:00
committed by GitHub
parent da5ce5c8e7
commit e837c998b7
48 changed files with 98 additions and 100 deletions

View File

@@ -108,17 +108,12 @@ func getExistingAzureADAuthSources(ctx context.Context) ([]string, error) {
return existingAzureProviders, nil
}
// GetSupportedOAuth2Providers returns the map of unconfigured OAuth2 providers
// GetSupportedOAuth2Providers returns the list of supported OAuth2 providers with context for filtering
// key is used as technical name (like in the callbackURL)
// values to display
// Note: Azure AD providers (azuread, microsoftonline, azureadv2) are filtered out
// unless they already exist in the system to encourage use of OpenID Connect
func GetSupportedOAuth2Providers() []Provider {
return GetSupportedOAuth2ProvidersWithContext(context.Background())
}
// GetSupportedOAuth2ProvidersWithContext returns the list of supported OAuth2 providers with context for filtering
func GetSupportedOAuth2ProvidersWithContext(ctx context.Context) []Provider {
func GetSupportedOAuth2Providers(ctx context.Context) []Provider {
providers := make([]Provider, 0, len(gothProviders))
existingAzureSources, err := getExistingAzureADAuthSources(ctx)
if err != nil {

View File

@@ -66,7 +66,7 @@ func toIssue(ctx context.Context, doer *user_model.User, issue *issues_model.Iss
return &api.Issue{}
}
apiIssue.URL = issue.APIURL(ctx)
apiIssue.HTMLURL = issue.HTMLURL()
apiIssue.HTMLURL = issue.HTMLURL(ctx)
if err := issue.LoadLabels(ctx); err != nil {
return &api.Issue{}
}
@@ -112,7 +112,7 @@ func toIssue(ctx context.Context, doer *user_model.User, issue *issues_model.Iss
apiIssue.PullRequest.Merged = issue.PullRequest.MergedUnix.AsTimePtr()
}
// Add pr's html url
apiIssue.PullRequest.HTMLURL = issue.HTMLURL()
apiIssue.PullRequest.HTMLURL = issue.HTMLURL(ctx)
}
}
if issue.DeadlineUnix != 0 {

View File

@@ -40,7 +40,7 @@ func ToNotificationThread(ctx context.Context, n *activities_model.Notification)
if n.Issue != nil {
result.Subject.Title = n.Issue.Title
result.Subject.URL = n.Issue.APIURL(ctx)
result.Subject.HTMLURL = n.Issue.HTMLURL()
result.Subject.HTMLURL = n.Issue.HTMLURL(ctx)
result.Subject.State = n.Issue.State()
comment, err := n.Issue.GetLastComment(ctx)
if err == nil && comment != nil {
@@ -53,7 +53,7 @@ func ToNotificationThread(ctx context.Context, n *activities_model.Notification)
if n.Issue != nil {
result.Subject.Title = n.Issue.Title
result.Subject.URL = n.Issue.APIURL(ctx)
result.Subject.HTMLURL = n.Issue.HTMLURL()
result.Subject.HTMLURL = n.Issue.HTMLURL(ctx)
result.Subject.State = n.Issue.State()
comment, err := n.Issue.GetLastComment(ctx)
if err == nil && comment != nil {

View File

@@ -35,7 +35,7 @@ func ToPackage(ctx context.Context, pd *packages.PackageDescriptor, doer *user_m
Name: pd.Package.Name,
Version: pd.Version.Version,
CreatedAt: pd.Version.CreatedUnix.AsTime(),
HTMLURL: pd.VersionHTMLURL(),
HTMLURL: pd.VersionHTMLURL(ctx),
}, nil
}

View File

@@ -73,7 +73,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
apiPullRequest := &api.PullRequest{
ID: pr.ID,
URL: pr.Issue.HTMLURL(),
URL: pr.Issue.HTMLURL(ctx),
Index: pr.Index,
Poster: apiIssue.Poster,
Title: apiIssue.Title,
@@ -87,7 +87,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
IsLocked: apiIssue.IsLocked,
Comments: apiIssue.Comments,
ReviewComments: pr.GetReviewCommentsCount(ctx),
HTMLURL: pr.Issue.HTMLURL(),
HTMLURL: pr.Issue.HTMLURL(ctx),
DiffURL: pr.Issue.DiffURL(),
PatchURL: pr.Issue.PatchURL(),
HasMerged: pr.HasMerged,
@@ -348,7 +348,7 @@ func ToAPIPullRequests(ctx context.Context, baseRepo *repo_model.Repository, prs
apiPullRequest := &api.PullRequest{
ID: pr.ID,
URL: pr.Issue.HTMLURL(),
URL: pr.Issue.HTMLURL(ctx),
Index: pr.Index,
Poster: apiIssue.Poster,
Title: apiIssue.Title,
@@ -362,7 +362,7 @@ func ToAPIPullRequests(ctx context.Context, baseRepo *repo_model.Repository, prs
IsLocked: apiIssue.IsLocked,
Comments: apiIssue.Comments,
ReviewComments: reviewCounts[pr.IssueID],
HTMLURL: pr.Issue.HTMLURL(),
HTMLURL: pr.Issue.HTMLURL(ctx),
DiffURL: pr.Issue.DiffURL(),
PatchURL: pr.Issue.PatchURL(),
HasMerged: pr.HasMerged,

View File

@@ -34,7 +34,7 @@ func ToPullReview(ctx context.Context, r *issues_model.Review, doer *user_model.
Submitted: r.CreatedUnix.AsTime(),
Updated: r.UpdatedUnix.AsTime(),
HTMLURL: r.HTMLURL(ctx),
HTMLPullURL: r.Issue.HTMLURL(),
HTMLPullURL: r.Issue.HTMLURL(ctx),
}
if r.ReviewerTeam != nil {
@@ -105,7 +105,7 @@ func ToPullReviewCommentList(ctx context.Context, review *issues_model.Review, d
OrigCommitID: comment.OldRef,
DiffHunk: patch2diff(comment.Patch),
HTMLURL: comment.HTMLURL(ctx),
HTMLPullURL: review.Issue.HTMLURL(),
HTMLPullURL: review.Issue.HTMLURL(ctx),
}
if comment.Line < 0 {

View File

@@ -53,7 +53,7 @@ func toUser(ctx context.Context, user *user_model.User, signed, authed bool) *ap
FullName: user.FullName,
Email: user.GetPlaceholderEmail(),
AvatarURL: user.AvatarLink(ctx),
HTMLURL: user.HTMLURL(),
HTMLURL: user.HTMLURL(ctx),
Created: user.CreatedUnix.AsTime(),
Restricted: user.IsRestricted,
Location: user.Location,

View File

@@ -36,7 +36,7 @@ func initDBSkipLogger(ctx context.Context) error {
return fmt.Errorf("db.InitEngine: %w", err)
}
// some doctor sub-commands need to use git command
if err := git.InitFull(ctx); err != nil {
if err := git.InitFull(); err != nil {
return fmt.Errorf("git.InitFull: %w", err)
}
return nil

View File

@@ -56,9 +56,9 @@ func composeIssueCommentMessages(ctx context.Context, comment *mailComment, lang
commentType := issues_model.CommentTypeComment
if comment.Comment != nil {
commentType = comment.Comment.Type
link = comment.Issue.HTMLURL() + "#" + comment.Comment.HashTag()
link = comment.Issue.HTMLURL(ctx) + "#" + comment.Comment.HashTag()
} else {
link = comment.Issue.HTMLURL()
link = comment.Issue.HTMLURL(ctx)
}
reviewType := issues_model.ReviewTypeComment
@@ -175,7 +175,7 @@ func composeIssueCommentMessages(ctx context.Context, comment *mailComment, lang
msg.SetHeader("In-Reply-To", reference)
references := []string{reference}
listUnsubscribe := []string{"<" + comment.Issue.HTMLURL() + ">"}
listUnsubscribe := []string{"<" + comment.Issue.HTMLURL(ctx) + ">"}
if setting.IncomingEmail.Enabled {
if replyPayload != nil {
@@ -313,7 +313,7 @@ func generateAdditionalHeadersForIssue(ctx *mailComment, reason string, recipien
maps.Copy(headers, generateReasonHeaders(reason))
headers["X-Gitea-Issue-ID"] = issueID
headers["X-Gitea-Issue-Link"] = ctx.Issue.HTMLURL()
headers["X-Gitea-Issue-Link"] = ctx.Issue.HTMLURL(context.TODO()) // FIXME: use proper context
headers["X-GitLab-Issue-IID"] = issueID
return headers

View File

@@ -150,12 +150,12 @@ func TestComposeIssueComment(t *testing.T) {
assert.NoError(t, err)
// text/plain
assert.Contains(t, string(b), fmt.Sprintf(`( %s )`, doer.HTMLURL()))
assert.Contains(t, string(b), fmt.Sprintf(`( %s )`, issue.HTMLURL()))
assert.Contains(t, string(b), fmt.Sprintf(`( %s )`, doer.HTMLURL(t.Context())))
assert.Contains(t, string(b), fmt.Sprintf(`( %s )`, issue.HTMLURL(t.Context())))
// text/html
assert.Contains(t, string(b), fmt.Sprintf(`href="%s"`, doer.HTMLURL()))
assert.Contains(t, string(b), fmt.Sprintf(`href="%s"`, issue.HTMLURL()))
assert.Contains(t, string(b), fmt.Sprintf(`href="%s"`, doer.HTMLURL(t.Context())))
assert.Contains(t, string(b), fmt.Sprintf(`href="%s"`, issue.HTMLURL(t.Context())))
}
func TestMailMentionsComment(t *testing.T) {

View File

@@ -128,7 +128,7 @@ func (m *mailNotifier) IssueChangeAssignee(ctx context.Context, doer *user_model
func (m *mailNotifier) PullRequestReviewRequest(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment) {
if isRequest && doer.ID != reviewer.ID && reviewer.EmailNotificationsPreference != user_model.EmailNotificationsDisabled {
ct := fmt.Sprintf("Requested to review %s.", issue.HTMLURL())
ct := fmt.Sprintf("Requested to review %s.", issue.HTMLURL(ctx))
if err := SendIssueAssignedMail(ctx, issue, doer, ct, comment, []*user_model.User{reviewer}); err != nil {
log.Error("Error in SendIssueAssignedMail for issue[%d] to reviewer[%d]: %v", issue.ID, reviewer.ID, err)
}

View File

@@ -196,7 +196,7 @@ func NewAccessTokenResponse(ctx context.Context, grant *auth.OAuth2Grant, server
if grant.ScopeContains("profile") {
idToken.Name = user.DisplayName()
idToken.PreferredUsername = user.Name
idToken.Profile = user.HTMLURL()
idToken.Profile = user.HTMLURL(ctx)
idToken.Picture = user.AvatarLink(ctx)
idToken.Website = user.Website
idToken.Locale = user.Language