More db.DefaultContext refactor (#27265)

Part of #27065

This PR touches functions used in templates. As templates are not static
typed, errors are harder to find, but I hope I catch it all. I think
some tests from other persons do not hurt.
This commit is contained in:
JakobDev 2023-09-29 14:12:54 +02:00 committed by GitHub
parent 3945c26722
commit cf0df023be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
66 changed files with 455 additions and 456 deletions

View file

@ -208,91 +208,91 @@ func (a *Action) loadRepo(ctx context.Context) {
}
// GetActFullName gets the action's user full name.
func (a *Action) GetActFullName() string {
a.LoadActUser(db.DefaultContext)
func (a *Action) GetActFullName(ctx context.Context) string {
a.LoadActUser(ctx)
return a.ActUser.FullName
}
// GetActUserName gets the action's user name.
func (a *Action) GetActUserName() string {
a.LoadActUser(db.DefaultContext)
func (a *Action) GetActUserName(ctx context.Context) string {
a.LoadActUser(ctx)
return a.ActUser.Name
}
// ShortActUserName gets the action's user name trimmed to max 20
// chars.
func (a *Action) ShortActUserName() string {
return base.EllipsisString(a.GetActUserName(), 20)
func (a *Action) ShortActUserName(ctx context.Context) string {
return base.EllipsisString(a.GetActUserName(ctx), 20)
}
// GetDisplayName gets the action's display name based on DEFAULT_SHOW_FULL_NAME, or falls back to the username if it is blank.
func (a *Action) GetDisplayName() string {
func (a *Action) GetDisplayName(ctx context.Context) string {
if setting.UI.DefaultShowFullName {
trimmedFullName := strings.TrimSpace(a.GetActFullName())
trimmedFullName := strings.TrimSpace(a.GetActFullName(ctx))
if len(trimmedFullName) > 0 {
return trimmedFullName
}
}
return a.ShortActUserName()
return a.ShortActUserName(ctx)
}
// GetDisplayNameTitle gets the action's display name used for the title (tooltip) based on DEFAULT_SHOW_FULL_NAME
func (a *Action) GetDisplayNameTitle() string {
func (a *Action) GetDisplayNameTitle(ctx context.Context) string {
if setting.UI.DefaultShowFullName {
return a.ShortActUserName()
return a.ShortActUserName(ctx)
}
return a.GetActFullName()
return a.GetActFullName(ctx)
}
// GetRepoUserName returns the name of the action repository owner.
func (a *Action) GetRepoUserName() string {
a.loadRepo(db.DefaultContext)
func (a *Action) GetRepoUserName(ctx context.Context) string {
a.loadRepo(ctx)
return a.Repo.OwnerName
}
// ShortRepoUserName returns the name of the action repository owner
// trimmed to max 20 chars.
func (a *Action) ShortRepoUserName() string {
return base.EllipsisString(a.GetRepoUserName(), 20)
func (a *Action) ShortRepoUserName(ctx context.Context) string {
return base.EllipsisString(a.GetRepoUserName(ctx), 20)
}
// GetRepoName returns the name of the action repository.
func (a *Action) GetRepoName() string {
a.loadRepo(db.DefaultContext)
func (a *Action) GetRepoName(ctx context.Context) string {
a.loadRepo(ctx)
return a.Repo.Name
}
// ShortRepoName returns the name of the action repository
// trimmed to max 33 chars.
func (a *Action) ShortRepoName() string {
return base.EllipsisString(a.GetRepoName(), 33)
func (a *Action) ShortRepoName(ctx context.Context) string {
return base.EllipsisString(a.GetRepoName(ctx), 33)
}
// GetRepoPath returns the virtual path to the action repository.
func (a *Action) GetRepoPath() string {
return path.Join(a.GetRepoUserName(), a.GetRepoName())
func (a *Action) GetRepoPath(ctx context.Context) string {
return path.Join(a.GetRepoUserName(ctx), a.GetRepoName(ctx))
}
// ShortRepoPath returns the virtual path to the action repository
// trimmed to max 20 + 1 + 33 chars.
func (a *Action) ShortRepoPath() string {
return path.Join(a.ShortRepoUserName(), a.ShortRepoName())
func (a *Action) ShortRepoPath(ctx context.Context) string {
return path.Join(a.ShortRepoUserName(ctx), a.ShortRepoName(ctx))
}
// GetRepoLink returns relative link to action repository.
func (a *Action) GetRepoLink() string {
func (a *Action) GetRepoLink(ctx context.Context) string {
// path.Join will skip empty strings
return path.Join(setting.AppSubURL, "/", url.PathEscape(a.GetRepoUserName()), url.PathEscape(a.GetRepoName()))
return path.Join(setting.AppSubURL, "/", url.PathEscape(a.GetRepoUserName(ctx)), url.PathEscape(a.GetRepoName(ctx)))
}
// GetRepoAbsoluteLink returns the absolute link to action repository.
func (a *Action) GetRepoAbsoluteLink() string {
return setting.AppURL + url.PathEscape(a.GetRepoUserName()) + "/" + url.PathEscape(a.GetRepoName())
func (a *Action) GetRepoAbsoluteLink(ctx context.Context) string {
return setting.AppURL + url.PathEscape(a.GetRepoUserName(ctx)) + "/" + url.PathEscape(a.GetRepoName(ctx))
}
// GetCommentHTMLURL returns link to action comment.
func (a *Action) GetCommentHTMLURL() string {
return a.getCommentHTMLURL(db.DefaultContext)
func (a *Action) GetCommentHTMLURL(ctx context.Context) string {
return a.getCommentHTMLURL(ctx)
}
func (a *Action) loadComment(ctx context.Context) (err error) {
@ -309,7 +309,7 @@ func (a *Action) getCommentHTMLURL(ctx context.Context) string {
}
_ = a.loadComment(ctx)
if a.Comment != nil {
return a.Comment.HTMLURL()
return a.Comment.HTMLURL(ctx)
}
if len(a.GetIssueInfos()) == 0 {
return "#"
@ -334,8 +334,8 @@ func (a *Action) getCommentHTMLURL(ctx context.Context) string {
}
// GetCommentLink returns link to action comment.
func (a *Action) GetCommentLink() string {
return a.getCommentLink(db.DefaultContext)
func (a *Action) GetCommentLink(ctx context.Context) string {
return a.getCommentLink(ctx)
}
func (a *Action) getCommentLink(ctx context.Context) string {
@ -344,7 +344,7 @@ func (a *Action) getCommentLink(ctx context.Context) string {
}
_ = a.loadComment(ctx)
if a.Comment != nil {
return a.Comment.Link()
return a.Comment.Link(ctx)
}
if len(a.GetIssueInfos()) == 0 {
return "#"
@ -374,8 +374,8 @@ func (a *Action) GetBranch() string {
}
// GetRefLink returns the action's ref link.
func (a *Action) GetRefLink() string {
return git.RefURL(a.GetRepoLink(), a.RefName)
func (a *Action) GetRefLink(ctx context.Context) string {
return git.RefURL(a.GetRepoLink(ctx), a.RefName)
}
// GetTag returns the action's repository tag.
@ -399,11 +399,10 @@ func (a *Action) GetIssueInfos() []string {
return strings.SplitN(a.Content, "|", 3)
}
// GetIssueTitle returns the title of first issue associated
// with the action. This function will be invoked in template so keep db.DefaultContext here
func (a *Action) GetIssueTitle() string {
// GetIssueTitle returns the title of first issue associated with the action.
func (a *Action) GetIssueTitle(ctx context.Context) string {
index, _ := strconv.ParseInt(a.GetIssueInfos()[0], 10, 64)
issue, err := issues_model.GetIssueByIndex(db.DefaultContext, a.RepoID, index)
issue, err := issues_model.GetIssueByIndex(ctx, a.RepoID, index)
if err != nil {
log.Error("GetIssueByIndex: %v", err)
return "500 when get issue"
@ -442,7 +441,7 @@ func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, int64, err
return nil, 0, fmt.Errorf("need at least one of these filters: RequestedUser, RequestedTeam, RequestedRepo")
}
cond, err := activityQueryCondition(opts)
cond, err := activityQueryCondition(ctx, opts)
if err != nil {
return nil, 0, err
}
@ -473,11 +472,11 @@ func ActivityReadable(user, doer *user_model.User) bool {
doer != nil && (doer.IsAdmin || user.ID == doer.ID)
}
func activityQueryCondition(opts GetFeedsOptions) (builder.Cond, error) {
func activityQueryCondition(ctx context.Context, opts GetFeedsOptions) (builder.Cond, error) {
cond := builder.NewCond()
if opts.RequestedTeam != nil && opts.RequestedUser == nil {
org, err := user_model.GetUserByID(db.DefaultContext, opts.RequestedTeam.OrgID)
org, err := user_model.GetUserByID(ctx, opts.RequestedTeam.OrgID)
if err != nil {
return nil, err
}
@ -564,12 +563,12 @@ func activityQueryCondition(opts GetFeedsOptions) (builder.Cond, error) {
}
// DeleteOldActions deletes all old actions from database.
func DeleteOldActions(olderThan time.Duration) (err error) {
func DeleteOldActions(ctx context.Context, olderThan time.Duration) (err error) {
if olderThan <= 0 {
return nil
}
_, err = db.GetEngine(db.DefaultContext).Where("created_unix < ?", time.Now().Add(-olderThan).Unix()).Delete(&Action{})
_, err = db.GetEngine(ctx).Where("created_unix < ?", time.Now().Add(-olderThan).Unix()).Delete(&Action{})
return err
}
@ -679,8 +678,8 @@ func NotifyWatchers(ctx context.Context, actions ...*Action) error {
}
// NotifyWatchersActions creates batch of actions for every watcher.
func NotifyWatchersActions(acts []*Action) error {
ctx, committer, err := db.TxContext(db.DefaultContext)
func NotifyWatchersActions(ctx context.Context, acts []*Action) error {
ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}

View file

@ -24,7 +24,7 @@ func TestAction_GetRepoPath(t *testing.T) {
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
action := &activities_model.Action{RepoID: repo.ID}
assert.Equal(t, path.Join(owner.Name, repo.Name), action.GetRepoPath())
assert.Equal(t, path.Join(owner.Name, repo.Name), action.GetRepoPath(db.DefaultContext))
}
func TestAction_GetRepoLink(t *testing.T) {
@ -35,9 +35,9 @@ func TestAction_GetRepoLink(t *testing.T) {
action := &activities_model.Action{RepoID: repo.ID, CommentID: comment.ID}
setting.AppSubURL = "/suburl"
expected := path.Join(setting.AppSubURL, owner.Name, repo.Name)
assert.Equal(t, expected, action.GetRepoLink())
assert.Equal(t, repo.HTMLURL(), action.GetRepoAbsoluteLink())
assert.Equal(t, comment.HTMLURL(), action.GetCommentHTMLURL())
assert.Equal(t, expected, action.GetRepoLink(db.DefaultContext))
assert.Equal(t, repo.HTMLURL(), action.GetRepoAbsoluteLink(db.DefaultContext))
assert.Equal(t, comment.HTMLURL(db.DefaultContext), action.GetCommentHTMLURL(db.DefaultContext))
}
func TestGetFeeds(t *testing.T) {

View file

@ -175,8 +175,8 @@ func CreateRepoTransferNotification(ctx context.Context, doer, newOwner *user_mo
// CreateOrUpdateIssueNotifications creates an issue notification
// for each watcher, or updates it if already exists
// receiverID > 0 just send to receiver, else send to all watcher
func CreateOrUpdateIssueNotifications(issueID, commentID, notificationAuthorID, receiverID int64) error {
ctx, committer, err := db.TxContext(db.DefaultContext)
func CreateOrUpdateIssueNotifications(ctx context.Context, issueID, commentID, notificationAuthorID, receiverID int64) error {
ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
@ -435,21 +435,21 @@ func (n *Notification) loadUser(ctx context.Context) (err error) {
}
// GetRepo returns the repo of the notification
func (n *Notification) GetRepo() (*repo_model.Repository, error) {
return n.Repository, n.loadRepo(db.DefaultContext)
func (n *Notification) GetRepo(ctx context.Context) (*repo_model.Repository, error) {
return n.Repository, n.loadRepo(ctx)
}
// GetIssue returns the issue of the notification
func (n *Notification) GetIssue() (*issues_model.Issue, error) {
return n.Issue, n.loadIssue(db.DefaultContext)
func (n *Notification) GetIssue(ctx context.Context) (*issues_model.Issue, error) {
return n.Issue, n.loadIssue(ctx)
}
// HTMLURL formats a URL-string to the notification
func (n *Notification) HTMLURL() string {
func (n *Notification) HTMLURL(ctx context.Context) string {
switch n.Source {
case NotificationSourceIssue, NotificationSourcePullRequest:
if n.Comment != nil {
return n.Comment.HTMLURL()
return n.Comment.HTMLURL(ctx)
}
return n.Issue.HTMLURL()
case NotificationSourceCommit:
@ -461,11 +461,11 @@ func (n *Notification) HTMLURL() string {
}
// Link formats a relative URL-string to the notification
func (n *Notification) Link() string {
func (n *Notification) Link(ctx context.Context) string {
switch n.Source {
case NotificationSourceIssue, NotificationSourcePullRequest:
if n.Comment != nil {
return n.Comment.Link()
return n.Comment.Link(ctx)
}
return n.Issue.Link()
case NotificationSourceCommit:
@ -733,12 +733,12 @@ type UserIDCount struct {
}
// GetUIDsAndNotificationCounts between the two provided times
func GetUIDsAndNotificationCounts(since, until timeutil.TimeStamp) ([]UserIDCount, error) {
func GetUIDsAndNotificationCounts(ctx context.Context, since, until timeutil.TimeStamp) ([]UserIDCount, error) {
sql := `SELECT user_id, count(*) AS count FROM notification ` +
`WHERE user_id IN (SELECT user_id FROM notification WHERE updated_unix >= ? AND ` +
`updated_unix < ?) AND status = ? GROUP BY user_id`
var res []UserIDCount
return res, db.GetEngine(db.DefaultContext).SQL(sql, since, until, NotificationStatusUnread).Find(&res)
return res, db.GetEngine(ctx).SQL(sql, since, until, NotificationStatusUnread).Find(&res)
}
// SetIssueReadBy sets issue to be read by given user.

View file

@ -20,7 +20,7 @@ func TestCreateOrUpdateIssueNotifications(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1})
assert.NoError(t, activities_model.CreateOrUpdateIssueNotifications(issue.ID, 0, 2, 0))
assert.NoError(t, activities_model.CreateOrUpdateIssueNotifications(db.DefaultContext, issue.ID, 0, 2, 0))
// User 9 is inactive, thus notifications for user 1 and 4 are created
notf := unittest.AssertExistsAndLoadBean(t, &activities_model.Notification{UserID: 1, IssueID: issue.ID})
@ -50,7 +50,7 @@ func TestNotificationsForUser(t *testing.T) {
func TestNotification_GetRepo(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
notf := unittest.AssertExistsAndLoadBean(t, &activities_model.Notification{RepoID: 1})
repo, err := notf.GetRepo()
repo, err := notf.GetRepo(db.DefaultContext)
assert.NoError(t, err)
assert.Equal(t, repo, notf.Repository)
assert.EqualValues(t, notf.RepoID, repo.ID)
@ -59,7 +59,7 @@ func TestNotification_GetRepo(t *testing.T) {
func TestNotification_GetIssue(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
notf := unittest.AssertExistsAndLoadBean(t, &activities_model.Notification{RepoID: 1})
issue, err := notf.GetIssue()
issue, err := notf.GetIssue(db.DefaultContext)
assert.NoError(t, err)
assert.Equal(t, issue, notf.Issue)
assert.EqualValues(t, notf.IssueID, issue.ID)

View file

@ -47,7 +47,7 @@ func getUserHeatmapData(ctx context.Context, user *user_model.User, team *organi
groupByName = groupBy
}
cond, err := activityQueryCondition(GetFeedsOptions{
cond, err := activityQueryCondition(ctx, GetFeedsOptions{
RequestedUser: user,
RequestedTeam: team,
Actor: doer,

View file

@ -514,7 +514,7 @@ func ConvertFromGitCommit(ctx context.Context, commits []*git.Commit, repo *repo
user_model.ValidateCommitsWithEmails(ctx, commits),
repo.GetTrustModel(),
func(user *user_model.User) (bool, error) {
return repo_model.IsOwnerMemberCollaborator(repo, user.ID)
return repo_model.IsOwnerMemberCollaborator(ctx, repo, user.ID)
},
),
repo,

View file

@ -371,42 +371,42 @@ func (c *Comment) AfterDelete(ctx context.Context) {
}
// HTMLURL formats a URL-string to the issue-comment
func (c *Comment) HTMLURL() string {
err := c.LoadIssue(db.DefaultContext)
func (c *Comment) HTMLURL(ctx context.Context) string {
err := c.LoadIssue(ctx)
if err != nil { // Silently dropping errors :unamused:
log.Error("LoadIssue(%d): %v", c.IssueID, err)
return ""
}
err = c.Issue.LoadRepo(db.DefaultContext)
err = c.Issue.LoadRepo(ctx)
if err != nil { // Silently dropping errors :unamused:
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
return ""
}
return c.Issue.HTMLURL() + c.hashLink()
return c.Issue.HTMLURL() + c.hashLink(ctx)
}
// Link formats a relative URL-string to the issue-comment
func (c *Comment) Link() string {
err := c.LoadIssue(db.DefaultContext)
func (c *Comment) Link(ctx context.Context) string {
err := c.LoadIssue(ctx)
if err != nil { // Silently dropping errors :unamused:
log.Error("LoadIssue(%d): %v", c.IssueID, err)
return ""
}
err = c.Issue.LoadRepo(db.DefaultContext)
err = c.Issue.LoadRepo(ctx)
if err != nil { // Silently dropping errors :unamused:
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
return ""
}
return c.Issue.Link() + c.hashLink()
return c.Issue.Link() + c.hashLink(ctx)
}
func (c *Comment) hashLink() string {
func (c *Comment) hashLink(ctx context.Context) string {
if c.Type == CommentTypeCode {
if c.ReviewID == 0 {
return "/files#" + c.HashTag()
}
if c.Review == nil {
if err := c.LoadReview(); err != nil {
if err := c.LoadReview(ctx); err != nil {
log.Warn("LoadReview(%d): %v", c.ReviewID, err)
return "/files#" + c.HashTag()
}
@ -419,13 +419,13 @@ func (c *Comment) hashLink() string {
}
// APIURL formats a API-string to the issue-comment
func (c *Comment) APIURL() string {
err := c.LoadIssue(db.DefaultContext)
func (c *Comment) APIURL(ctx context.Context) string {
err := c.LoadIssue(ctx)
if err != nil { // Silently dropping errors :unamused:
log.Error("LoadIssue(%d): %v", c.IssueID, err)
return ""
}
err = c.Issue.LoadRepo(db.DefaultContext)
err = c.Issue.LoadRepo(ctx)
if err != nil { // Silently dropping errors :unamused:
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
return ""
@ -435,8 +435,8 @@ func (c *Comment) APIURL() string {
}
// IssueURL formats a URL-string to the issue
func (c *Comment) IssueURL() string {
err := c.LoadIssue(db.DefaultContext)
func (c *Comment) IssueURL(ctx context.Context) string {
err := c.LoadIssue(ctx)
if err != nil { // Silently dropping errors :unamused:
log.Error("LoadIssue(%d): %v", c.IssueID, err)
return ""
@ -446,7 +446,7 @@ func (c *Comment) IssueURL() string {
return ""
}
err = c.Issue.LoadRepo(db.DefaultContext)
err = c.Issue.LoadRepo(ctx)
if err != nil { // Silently dropping errors :unamused:
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
return ""
@ -455,14 +455,14 @@ func (c *Comment) IssueURL() string {
}
// PRURL formats a URL-string to the pull-request
func (c *Comment) PRURL() string {
err := c.LoadIssue(db.DefaultContext)
func (c *Comment) PRURL(ctx context.Context) string {
err := c.LoadIssue(ctx)
if err != nil { // Silently dropping errors :unamused:
log.Error("LoadIssue(%d): %v", c.IssueID, err)
return ""
}
err = c.Issue.LoadRepo(db.DefaultContext)
err = c.Issue.LoadRepo(ctx)
if err != nil { // Silently dropping errors :unamused:
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
return ""
@ -490,9 +490,9 @@ func (c *Comment) EventTag() string {
}
// LoadLabel if comment.Type is CommentTypeLabel, then load Label
func (c *Comment) LoadLabel() error {
func (c *Comment) LoadLabel(ctx context.Context) error {
var label Label
has, err := db.GetEngine(db.DefaultContext).ID(c.LabelID).Get(&label)
has, err := db.GetEngine(ctx).ID(c.LabelID).Get(&label)
if err != nil {
return err
} else if has {
@ -506,10 +506,10 @@ func (c *Comment) LoadLabel() error {
}
// LoadProject if comment.Type is CommentTypeProject, then load project.
func (c *Comment) LoadProject() error {
func (c *Comment) LoadProject(ctx context.Context) error {
if c.OldProjectID > 0 {
var oldProject project_model.Project
has, err := db.GetEngine(db.DefaultContext).ID(c.OldProjectID).Get(&oldProject)
has, err := db.GetEngine(ctx).ID(c.OldProjectID).Get(&oldProject)
if err != nil {
return err
} else if has {
@ -519,7 +519,7 @@ func (c *Comment) LoadProject() error {
if c.ProjectID > 0 {
var project project_model.Project
has, err := db.GetEngine(db.DefaultContext).ID(c.ProjectID).Get(&project)
has, err := db.GetEngine(ctx).ID(c.ProjectID).Get(&project)
if err != nil {
return err
} else if has {
@ -569,8 +569,8 @@ func (c *Comment) LoadAttachments(ctx context.Context) error {
}
// UpdateAttachments update attachments by UUIDs for the comment
func (c *Comment) UpdateAttachments(uuids []string) error {
ctx, committer, err := db.TxContext(db.DefaultContext)
func (c *Comment) UpdateAttachments(ctx context.Context, uuids []string) error {
ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
@ -591,11 +591,11 @@ func (c *Comment) UpdateAttachments(uuids []string) error {
}
// LoadAssigneeUserAndTeam if comment.Type is CommentTypeAssignees, then load assignees
func (c *Comment) LoadAssigneeUserAndTeam() error {
func (c *Comment) LoadAssigneeUserAndTeam(ctx context.Context) error {
var err error
if c.AssigneeID > 0 && c.Assignee == nil {
c.Assignee, err = user_model.GetUserByID(db.DefaultContext, c.AssigneeID)
c.Assignee, err = user_model.GetUserByID(ctx, c.AssigneeID)
if err != nil {
if !user_model.IsErrUserNotExist(err) {
return err
@ -603,20 +603,20 @@ func (c *Comment) LoadAssigneeUserAndTeam() error {
c.Assignee = user_model.NewGhostUser()
}
} else if c.AssigneeTeamID > 0 && c.AssigneeTeam == nil {
if err = c.LoadIssue(db.DefaultContext); err != nil {
if err = c.LoadIssue(ctx); err != nil {
return err
}
if err = c.Issue.LoadRepo(db.DefaultContext); err != nil {
if err = c.Issue.LoadRepo(ctx); err != nil {
return err
}
if err = c.Issue.Repo.LoadOwner(db.DefaultContext); err != nil {
if err = c.Issue.Repo.LoadOwner(ctx); err != nil {
return err
}
if c.Issue.Repo.Owner.IsOrganization() {
c.AssigneeTeam, err = organization.GetTeamByID(db.DefaultContext, c.AssigneeTeamID)
c.AssigneeTeam, err = organization.GetTeamByID(ctx, c.AssigneeTeamID)
if err != nil && !organization.IsErrTeamNotExist(err) {
return err
}
@ -626,11 +626,11 @@ func (c *Comment) LoadAssigneeUserAndTeam() error {
}
// LoadResolveDoer if comment.Type is CommentTypeCode and ResolveDoerID not zero, then load resolveDoer
func (c *Comment) LoadResolveDoer() (err error) {
func (c *Comment) LoadResolveDoer(ctx context.Context) (err error) {
if c.ResolveDoerID == 0 || c.Type != CommentTypeCode {
return nil
}
c.ResolveDoer, err = user_model.GetUserByID(db.DefaultContext, c.ResolveDoerID)
c.ResolveDoer, err = user_model.GetUserByID(ctx, c.ResolveDoerID)
if err != nil {
if user_model.IsErrUserNotExist(err) {
c.ResolveDoer = user_model.NewGhostUser()
@ -646,11 +646,11 @@ func (c *Comment) IsResolved() bool {
}
// LoadDepIssueDetails loads Dependent Issue Details
func (c *Comment) LoadDepIssueDetails() (err error) {
func (c *Comment) LoadDepIssueDetails(ctx context.Context) (err error) {
if c.DependentIssueID <= 0 || c.DependentIssue != nil {
return nil
}
c.DependentIssue, err = GetIssueByID(db.DefaultContext, c.DependentIssueID)
c.DependentIssue, err = GetIssueByID(ctx, c.DependentIssueID)
return err
}
@ -683,8 +683,8 @@ func (c *Comment) loadReactions(ctx context.Context, repo *repo_model.Repository
}
// LoadReactions loads comment reactions
func (c *Comment) LoadReactions(repo *repo_model.Repository) error {
return c.loadReactions(db.DefaultContext, repo)
func (c *Comment) LoadReactions(ctx context.Context, repo *repo_model.Repository) error {
return c.loadReactions(ctx, repo)
}
func (c *Comment) loadReview(ctx context.Context) (err error) {
@ -698,8 +698,8 @@ func (c *Comment) loadReview(ctx context.Context) (err error) {
}
// LoadReview loads the associated review
func (c *Comment) LoadReview() error {
return c.loadReview(db.DefaultContext)
func (c *Comment) LoadReview(ctx context.Context) error {
return c.loadReview(ctx)
}
// DiffSide returns "previous" if Comment.Line is a LOC of the previous changes and "proposed" if it is a LOC of the proposed changes.
@ -719,13 +719,13 @@ func (c *Comment) UnsignedLine() uint64 {
}
// CodeCommentLink returns the url to a comment in code
func (c *Comment) CodeCommentLink() string {
err := c.LoadIssue(db.DefaultContext)
func (c *Comment) CodeCommentLink(ctx context.Context) string {
err := c.LoadIssue(ctx)
if err != nil { // Silently dropping errors :unamused:
log.Error("LoadIssue(%d): %v", c.IssueID, err)
return ""
}
err = c.Issue.LoadRepo(db.DefaultContext)
err = c.Issue.LoadRepo(ctx)
if err != nil { // Silently dropping errors :unamused:
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
return ""
@ -1074,8 +1074,8 @@ func FindComments(ctx context.Context, opts *FindCommentsOptions) (CommentList,
}
// CountComments count all comments according options by ignoring pagination
func CountComments(opts *FindCommentsOptions) (int64, error) {
sess := db.GetEngine(db.DefaultContext).Where(opts.ToConds())
func CountComments(ctx context.Context, opts *FindCommentsOptions) (int64, error) {
sess := db.GetEngine(ctx).Where(opts.ToConds())
if opts.RepoID > 0 {
sess.Join("INNER", "issue", "issue.id = comment.issue_id")
}
@ -1089,8 +1089,8 @@ func UpdateCommentInvalidate(ctx context.Context, c *Comment) error {
}
// UpdateComment updates information of comment.
func UpdateComment(c *Comment, doer *user_model.User) error {
ctx, committer, err := db.TxContext(db.DefaultContext)
func UpdateComment(ctx context.Context, c *Comment, doer *user_model.User) error {
ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
@ -1147,8 +1147,8 @@ func DeleteComment(ctx context.Context, comment *Comment) error {
}
// UpdateCommentsMigrationsByType updates comments' migrations information via given git service type and original id and poster id
func UpdateCommentsMigrationsByType(tp structs.GitServiceType, originalAuthorID string, posterID int64) error {
_, err := db.GetEngine(db.DefaultContext).Table("comment").
func UpdateCommentsMigrationsByType(ctx context.Context, tp structs.GitServiceType, originalAuthorID string, posterID int64) error {
_, err := db.GetEngine(ctx).Table("comment").
Where(builder.In("issue_id",
builder.Select("issue.id").
From("issue").
@ -1250,7 +1250,7 @@ func (c *Comment) HasOriginalAuthor() bool {
}
// InsertIssueComments inserts many comments of issues.
func InsertIssueComments(comments []*Comment) error {
func InsertIssueComments(ctx context.Context, comments []*Comment) error {
if len(comments) == 0 {
return nil
}
@ -1260,7 +1260,7 @@ func InsertIssueComments(comments []*Comment) error {
issueIDs.Add(comment.IssueID)
}
ctx, committer, err := db.TxContext(db.DefaultContext)
ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}

View file

@ -99,11 +99,11 @@ func findCodeComments(ctx context.Context, opts FindCommentsOptions, issue *Issu
comments[n] = comment
n++
if err := comment.LoadResolveDoer(); err != nil {
if err := comment.LoadResolveDoer(ctx); err != nil {
return nil, err
}
if err := comment.LoadReactions(issue.Repo); err != nil {
if err := comment.LoadReactions(ctx, issue.Repo); err != nil {
return nil, err
}

View file

@ -89,7 +89,7 @@ func TestMigrate_InsertIssueComments(t *testing.T) {
Reactions: []*issues_model.Reaction{reaction},
}
err := issues_model.InsertIssueComments([]*issues_model.Comment{comment})
err := issues_model.InsertIssueComments(db.DefaultContext, []*issues_model.Comment{comment})
assert.NoError(t, err)
issueModified := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1})

View file

@ -253,7 +253,7 @@ func testInsertIssue(t *testing.T, title, content string, expectIndex int64) *is
Title: title,
Content: content,
}
err := issues_model.NewIssue(repo, &issue, nil, nil)
err := issues_model.NewIssue(db.DefaultContext, repo, &issue, nil, nil)
assert.NoError(t, err)
has, err := db.GetEngine(db.DefaultContext).ID(issue.ID).Get(&newIssue)

View file

@ -165,8 +165,8 @@ func ChangeIssueTitle(ctx context.Context, issue *Issue, doer *user_model.User,
}
// ChangeIssueRef changes the branch of this issue, as the given user.
func ChangeIssueRef(issue *Issue, doer *user_model.User, oldRef string) (err error) {
ctx, committer, err := db.TxContext(db.DefaultContext)
func ChangeIssueRef(ctx context.Context, issue *Issue, doer *user_model.User, oldRef string) (err error) {
ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
@ -215,8 +215,8 @@ func AddDeletePRBranchComment(ctx context.Context, doer *user_model.User, repo *
}
// UpdateIssueAttachments update attachments by UUIDs for the issue
func UpdateIssueAttachments(issueID int64, uuids []string) (err error) {
ctx, committer, err := db.TxContext(db.DefaultContext)
func UpdateIssueAttachments(ctx context.Context, issueID int64, uuids []string) (err error) {
ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
@ -235,8 +235,8 @@ func UpdateIssueAttachments(issueID int64, uuids []string) (err error) {
}
// ChangeIssueContent changes issue content, as the given user.
func ChangeIssueContent(issue *Issue, doer *user_model.User, content string) (err error) {
ctx, committer, err := db.TxContext(db.DefaultContext)
func ChangeIssueContent(ctx context.Context, issue *Issue, doer *user_model.User, content string) (err error) {
ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
@ -381,8 +381,8 @@ func NewIssueWithIndex(ctx context.Context, doer *user_model.User, opts NewIssue
}
// NewIssue creates new issue with labels for repository.
func NewIssue(repo *repo_model.Repository, issue *Issue, labelIDs []int64, uuids []string) (err error) {
ctx, committer, err := db.TxContext(db.DefaultContext)
func NewIssue(ctx context.Context, repo *repo_model.Repository, issue *Issue, labelIDs []int64, uuids []string) (err error) {
ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
@ -432,8 +432,8 @@ func UpdateIssueMentions(ctx context.Context, issueID int64, mentions []*user_mo
// UpdateIssueByAPI updates all allowed fields of given issue.
// If the issue status is changed a statusChangeComment is returned
// similarly if the title is changed the titleChanged bool is set to true
func UpdateIssueByAPI(issue *Issue, doer *user_model.User) (statusChangeComment *Comment, titleChanged bool, err error) {
ctx, committer, err := db.TxContext(db.DefaultContext)
func UpdateIssueByAPI(ctx context.Context, issue *Issue, doer *user_model.User) (statusChangeComment *Comment, titleChanged bool, err error) {
ctx, committer, err := db.TxContext(ctx)
if err != nil {
return nil, false, err
}
@ -486,12 +486,12 @@ func UpdateIssueByAPI(issue *Issue, doer *user_model.User) (statusChangeComment
}
// UpdateIssueDeadline updates an issue deadline and adds comments. Setting a deadline to 0 means deleting it.
func UpdateIssueDeadline(issue *Issue, deadlineUnix timeutil.TimeStamp, doer *user_model.User) (err error) {
func UpdateIssueDeadline(ctx context.Context, issue *Issue, deadlineUnix timeutil.TimeStamp, doer *user_model.User) (err error) {
// if the deadline hasn't changed do nothing
if issue.DeadlineUnix == deadlineUnix {
return nil
}
ctx, committer, err := db.TxContext(db.DefaultContext)
ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
@ -669,8 +669,8 @@ func ResolveIssueMentionsByVisibility(ctx context.Context, issue *Issue, doer *u
}
// UpdateIssuesMigrationsByType updates all migrated repositories' issues from gitServiceType to replace originalAuthorID to posterID
func UpdateIssuesMigrationsByType(gitServiceType api.GitServiceType, originalAuthorID string, posterID int64) error {
_, err := db.GetEngine(db.DefaultContext).Table("issue").
func UpdateIssuesMigrationsByType(ctx context.Context, gitServiceType api.GitServiceType, originalAuthorID string, posterID int64) error {
_, err := db.GetEngine(ctx).Table("issue").
Where("repo_id IN (SELECT id FROM repository WHERE original_service_type = ?)", gitServiceType).
And("original_author_id = ?", originalAuthorID).
Update(map[string]any{
@ -682,8 +682,8 @@ func UpdateIssuesMigrationsByType(gitServiceType api.GitServiceType, originalAut
}
// UpdateReactionsMigrationsByType updates all migrated repositories' reactions from gitServiceType to replace originalAuthorID to posterID
func UpdateReactionsMigrationsByType(gitServiceType api.GitServiceType, originalAuthorID string, userID int64) error {
_, err := db.GetEngine(db.DefaultContext).Table("reaction").
func UpdateReactionsMigrationsByType(ctx context.Context, gitServiceType api.GitServiceType, originalAuthorID string, userID int64) error {
_, err := db.GetEngine(ctx).Table("reaction").
Where("original_author_id = ?", originalAuthorID).
And(migratedIssueCond(gitServiceType)).
Update(map[string]any{
@ -809,7 +809,7 @@ func DeleteOrphanedIssues(ctx context.Context) error {
// Remove issue attachment files.
for i := range attachmentPaths {
system_model.RemoveAllWithNotice(db.DefaultContext, "Delete issue attachment", attachmentPaths[i])
system_model.RemoveAllWithNotice(ctx, "Delete issue attachment", attachmentPaths[i])
}
return nil
}

View file

@ -252,22 +252,22 @@ func (c *Comment) neuterCrossReferences(ctx context.Context) error {
}
// LoadRefComment loads comment that created this reference from database
func (c *Comment) LoadRefComment() (err error) {
func (c *Comment) LoadRefComment(ctx context.Context) (err error) {
if c.RefComment != nil {
return nil
}
c.RefComment, err = GetCommentByID(db.DefaultContext, c.RefCommentID)
c.RefComment, err = GetCommentByID(ctx, c.RefCommentID)
return err
}
// LoadRefIssue loads comment that created this reference from database
func (c *Comment) LoadRefIssue() (err error) {
func (c *Comment) LoadRefIssue(ctx context.Context) (err error) {
if c.RefIssue != nil {
return nil
}
c.RefIssue, err = GetIssueByID(db.DefaultContext, c.RefIssueID)
c.RefIssue, err = GetIssueByID(ctx, c.RefIssueID)
if err == nil {
err = c.RefIssue.LoadRepo(db.DefaultContext)
err = c.RefIssue.LoadRepo(ctx)
}
return err
}
@ -278,21 +278,21 @@ func CommentTypeIsRef(t CommentType) bool {
}
// RefCommentLink returns the relative URL for the comment that created this reference
func (c *Comment) RefCommentLink() string {
func (c *Comment) RefCommentLink(ctx context.Context) string {
// Edge case for when the reference is inside the title or the description of the referring issue
if c.RefCommentID == 0 {
return c.RefIssueLink()
return c.RefIssueLink(ctx)
}
if err := c.LoadRefComment(); err != nil { // Silently dropping errors :unamused:
if err := c.LoadRefComment(ctx); err != nil { // Silently dropping errors :unamused:
log.Error("LoadRefComment(%d): %v", c.RefCommentID, err)
return ""
}
return c.RefComment.Link()
return c.RefComment.Link(ctx)
}
// RefIssueLink returns the relative URL of the issue where this reference was created
func (c *Comment) RefIssueLink() string {
if err := c.LoadRefIssue(); err != nil { // Silently dropping errors :unamused:
func (c *Comment) RefIssueLink(ctx context.Context) string {
if err := c.LoadRefIssue(ctx); err != nil { // Silently dropping errors :unamused:
log.Error("LoadRefIssue(%d): %v", c.RefCommentID, err)
return ""
}
@ -300,8 +300,8 @@ func (c *Comment) RefIssueLink() string {
}
// RefIssueTitle returns the title of the issue where this reference was created
func (c *Comment) RefIssueTitle() string {
if err := c.LoadRefIssue(); err != nil { // Silently dropping errors :unamused:
func (c *Comment) RefIssueTitle(ctx context.Context) string {
if err := c.LoadRefIssue(ctx); err != nil { // Silently dropping errors :unamused:
log.Error("LoadRefIssue(%d): %v", c.RefCommentID, err)
return ""
}
@ -309,8 +309,8 @@ func (c *Comment) RefIssueTitle() string {
}
// RefIssueIdent returns the user friendly identity (e.g. "#1234") of the issue where this reference was created
func (c *Comment) RefIssueIdent() string {
if err := c.LoadRefIssue(); err != nil { // Silently dropping errors :unamused:
func (c *Comment) RefIssueIdent(ctx context.Context) string {
if err := c.LoadRefIssue(ctx); err != nil { // Silently dropping errors :unamused:
log.Error("LoadRefIssue(%d): %v", c.RefCommentID, err)
return ""
}

View file

@ -329,8 +329,8 @@ func GetCurrentReview(ctx context.Context, reviewer *user_model.User, issue *Iss
}
// ReviewExists returns whether a review exists for a particular line of code in the PR
func ReviewExists(issue *Issue, treePath string, line int64) (bool, error) {
return db.GetEngine(db.DefaultContext).Cols("id").Exist(&Comment{IssueID: issue.ID, TreePath: treePath, Line: line, Type: CommentTypeCode})
func ReviewExists(ctx context.Context, issue *Issue, treePath string, line int64) (bool, error) {
return db.GetEngine(ctx).Cols("id").Exist(&Comment{IssueID: issue.ID, TreePath: treePath, Line: line, Type: CommentTypeCode})
}
// ContentEmptyErr represents an content empty error
@ -347,8 +347,8 @@ func IsContentEmptyErr(err error) bool {
}
// SubmitReview creates a review out of the existing pending review or creates a new one if no pending review exist
func SubmitReview(doer *user_model.User, issue *Issue, reviewType ReviewType, content, commitID string, stale bool, attachmentUUIDs []string) (*Review, *Comment, error) {
ctx, committer, err := db.TxContext(db.DefaultContext)
func SubmitReview(ctx context.Context, doer *user_model.User, issue *Issue, reviewType ReviewType, content, commitID string, stale bool, attachmentUUIDs []string) (*Review, *Comment, error) {
ctx, committer, err := db.TxContext(ctx)
if err != nil {
return nil, nil, err
}
@ -494,15 +494,15 @@ func GetTeamReviewerByIssueIDAndTeamID(ctx context.Context, issueID, teamID int6
}
// MarkReviewsAsStale marks existing reviews as stale
func MarkReviewsAsStale(issueID int64) (err error) {
_, err = db.GetEngine(db.DefaultContext).Exec("UPDATE `review` SET stale=? WHERE issue_id=?", true, issueID)
func MarkReviewsAsStale(ctx context.Context, issueID int64) (err error) {
_, err = db.GetEngine(ctx).Exec("UPDATE `review` SET stale=? WHERE issue_id=?", true, issueID)
return err
}
// MarkReviewsAsNotStale marks existing reviews as not stale for a giving commit SHA
func MarkReviewsAsNotStale(issueID int64, commitID string) (err error) {
_, err = db.GetEngine(db.DefaultContext).Exec("UPDATE `review` SET stale=? WHERE issue_id=? AND commit_id=?", false, issueID, commitID)
func MarkReviewsAsNotStale(ctx context.Context, issueID int64, commitID string) (err error) {
_, err = db.GetEngine(ctx).Exec("UPDATE `review` SET stale=? WHERE issue_id=? AND commit_id=?", false, issueID, commitID)
return err
}
@ -525,8 +525,8 @@ func DismissReview(ctx context.Context, review *Review, isDismiss bool) (err err
}
// InsertReviews inserts review and review comments
func InsertReviews(reviews []*Review) error {
ctx, committer, err := db.TxContext(db.DefaultContext)
func InsertReviews(ctx context.Context, reviews []*Review) error {
ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
@ -803,7 +803,7 @@ func RemoveTeamReviewRequest(ctx context.Context, issue *Issue, reviewer *organi
}
// MarkConversation Add or remove Conversation mark for a code comment
func MarkConversation(comment *Comment, doer *user_model.User, isResolve bool) (err error) {
func MarkConversation(ctx context.Context, comment *Comment, doer *user_model.User, isResolve bool) (err error) {
if comment.Type != CommentTypeCode {
return nil
}
@ -813,7 +813,7 @@ func MarkConversation(comment *Comment, doer *user_model.User, isResolve bool) (
return nil
}
if _, err = db.GetEngine(db.DefaultContext).Exec("UPDATE `comment` SET resolve_doer_id=? WHERE id=?", doer.ID, comment.ID); err != nil {
if _, err = db.GetEngine(ctx).Exec("UPDATE `comment` SET resolve_doer_id=? WHERE id=?", doer.ID, comment.ID); err != nil {
return err
}
} else {
@ -821,7 +821,7 @@ func MarkConversation(comment *Comment, doer *user_model.User, isResolve bool) (
return nil
}
if _, err = db.GetEngine(db.DefaultContext).Exec("UPDATE `comment` SET resolve_doer_id=? WHERE id=?", 0, comment.ID); err != nil {
if _, err = db.GetEngine(ctx).Exec("UPDATE `comment` SET resolve_doer_id=? WHERE id=?", 0, comment.ID); err != nil {
return err
}
}
@ -831,24 +831,24 @@ func MarkConversation(comment *Comment, doer *user_model.User, isResolve bool) (
// CanMarkConversation Add or remove Conversation mark for a code comment permission check
// the PR writer , offfcial reviewer and poster can do it
func CanMarkConversation(issue *Issue, doer *user_model.User) (permResult bool, err error) {
func CanMarkConversation(ctx context.Context, issue *Issue, doer *user_model.User) (permResult bool, err error) {
if doer == nil || issue == nil {
return false, fmt.Errorf("issue or doer is nil")
}
if doer.ID != issue.PosterID {
if err = issue.LoadRepo(db.DefaultContext); err != nil {
if err = issue.LoadRepo(ctx); err != nil {
return false, err
}
p, err := access_model.GetUserRepoPermission(db.DefaultContext, issue.Repo, doer)
p, err := access_model.GetUserRepoPermission(ctx, issue.Repo, doer)
if err != nil {
return false, err
}
permResult = p.CanAccess(perm.AccessModeWrite, unit.TypePullRequests)
if !permResult {
if permResult, err = IsOfficialReviewer(db.DefaultContext, issue, doer); err != nil {
if permResult, err = IsOfficialReviewer(ctx, issue, doer); err != nil {
return false, err
}
}
@ -862,8 +862,8 @@ func CanMarkConversation(issue *Issue, doer *user_model.User) (permResult bool,
}
// DeleteReview delete a review and it's code comments
func DeleteReview(r *Review) error {
ctx, committer, err := db.TxContext(db.DefaultContext)
func DeleteReview(ctx context.Context, r *Review) error {
ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
@ -912,7 +912,7 @@ func DeleteReview(r *Review) error {
}
// GetCodeCommentsCount return count of CodeComments a Review has
func (r *Review) GetCodeCommentsCount() int {
func (r *Review) GetCodeCommentsCount(ctx context.Context) int {
opts := FindCommentsOptions{
Type: CommentTypeCode,
IssueID: r.IssueID,
@ -923,7 +923,7 @@ func (r *Review) GetCodeCommentsCount() int {
conds = conds.And(builder.Eq{"invalidated": false})
}
count, err := db.GetEngine(db.DefaultContext).Where(conds).Count(new(Comment))
count, err := db.GetEngine(ctx).Where(conds).Count(new(Comment))
if err != nil {
return 0
}
@ -931,18 +931,18 @@ func (r *Review) GetCodeCommentsCount() int {
}
// HTMLURL formats a URL-string to the related review issue-comment
func (r *Review) HTMLURL() string {
func (r *Review) HTMLURL(ctx context.Context) string {
opts := FindCommentsOptions{
Type: CommentTypeReview,
IssueID: r.IssueID,
ReviewID: r.ID,
}
comment := new(Comment)
has, err := db.GetEngine(db.DefaultContext).Where(opts.ToConds()).Get(comment)
has, err := db.GetEngine(ctx).Where(opts.ToConds()).Get(comment)
if err != nil || !has {
return ""
}
return comment.HTMLURL()
return comment.HTMLURL(ctx)
}
// RemapExternalUser ExternalUserRemappable interface
@ -963,8 +963,8 @@ func (r *Review) GetExternalName() string { return r.OriginalAuthor }
func (r *Review) GetExternalID() int64 { return r.OriginalAuthorID }
// UpdateReviewsMigrationsByType updates reviews' migrations information via given git service type and original id and poster id
func UpdateReviewsMigrationsByType(tp structs.GitServiceType, originalAuthorID string, posterID int64) error {
_, err := db.GetEngine(db.DefaultContext).Table("review").
func UpdateReviewsMigrationsByType(ctx context.Context, tp structs.GitServiceType, originalAuthorID string, posterID int64) error {
_, err := db.GetEngine(ctx).Table("review").
Where("original_author_id = ?", originalAuthorID).
And(migratedIssueCond(tp)).
Update(map[string]any{

View file

@ -248,7 +248,7 @@ func TestDeleteReview(t *testing.T) {
})
assert.NoError(t, err)
assert.NoError(t, issues_model.DeleteReview(review2))
assert.NoError(t, issues_model.DeleteReview(db.DefaultContext, review2))
_, err = issues_model.GetReviewByID(db.DefaultContext, review2.ID)
assert.Error(t, err)

View file

@ -69,8 +69,8 @@ func (Board) TableName() string {
}
// NumIssues return counter of all issues assigned to the board
func (b *Board) NumIssues() int {
c, err := db.GetEngine(db.DefaultContext).Table("project_issue").
func (b *Board) NumIssues(ctx context.Context) int {
c, err := db.GetEngine(ctx).Table("project_issue").
Where("project_id=?", b.ProjectID).
And("project_board_id=?", b.ID).
GroupBy("issue_id").
@ -142,18 +142,18 @@ func createBoardsForProjectsType(ctx context.Context, project *Project) error {
}
// NewBoard adds a new project board to a given project
func NewBoard(board *Board) error {
func NewBoard(ctx context.Context, board *Board) error {
if len(board.Color) != 0 && !BoardColorPattern.MatchString(board.Color) {
return fmt.Errorf("bad color code: %s", board.Color)
}
_, err := db.GetEngine(db.DefaultContext).Insert(board)
_, err := db.GetEngine(ctx).Insert(board)
return err
}
// DeleteBoardByID removes all issues references to the project board.
func DeleteBoardByID(boardID int64) error {
ctx, committer, err := db.TxContext(db.DefaultContext)
func DeleteBoardByID(ctx context.Context, boardID int64) error {
ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
@ -265,8 +265,8 @@ func (p *Project) getDefaultBoard(ctx context.Context) (*Board, error) {
// SetDefaultBoard represents a board for issues not assigned to one
// if boardID is 0 unset default
func SetDefaultBoard(projectID, boardID int64) error {
_, err := db.GetEngine(db.DefaultContext).Where(builder.Eq{
func SetDefaultBoard(ctx context.Context, projectID, boardID int64) error {
_, err := db.GetEngine(ctx).Where(builder.Eq{
"project_id": projectID,
"`default`": true,
}).Cols("`default`").Update(&Board{Default: false})
@ -275,7 +275,7 @@ func SetDefaultBoard(projectID, boardID int64) error {
}
if boardID > 0 {
_, err = db.GetEngine(db.DefaultContext).ID(boardID).Where(builder.Eq{"project_id": projectID}).
_, err = db.GetEngine(ctx).ID(boardID).Where(builder.Eq{"project_id": projectID}).
Cols("`default`").Update(&Board{Default: true})
}
@ -283,9 +283,9 @@ func SetDefaultBoard(projectID, boardID int64) error {
}
// UpdateBoardSorting update project board sorting
func UpdateBoardSorting(bs BoardList) error {
func UpdateBoardSorting(ctx context.Context, bs BoardList) error {
for i := range bs {
_, err := db.GetEngine(db.DefaultContext).ID(bs[i].ID).Cols(
_, err := db.GetEngine(ctx).ID(bs[i].ID).Cols(
"sorting",
).Update(bs[i])
if err != nil {

View file

@ -34,8 +34,8 @@ func deleteProjectIssuesByProjectID(ctx context.Context, projectID int64) error
}
// NumIssues return counter of all issues assigned to a project
func (p *Project) NumIssues() int {
c, err := db.GetEngine(db.DefaultContext).Table("project_issue").
func (p *Project) NumIssues(ctx context.Context) int {
c, err := db.GetEngine(ctx).Table("project_issue").
Where("project_id=?", p.ID).
GroupBy("issue_id").
Cols("issue_id").
@ -48,8 +48,8 @@ func (p *Project) NumIssues() int {
}
// NumClosedIssues return counter of closed issues assigned to a project
func (p *Project) NumClosedIssues() int {
c, err := db.GetEngine(db.DefaultContext).Table("project_issue").
func (p *Project) NumClosedIssues(ctx context.Context) int {
c, err := db.GetEngine(ctx).Table("project_issue").
Join("INNER", "issue", "project_issue.issue_id=issue.id").
Where("project_issue.project_id=? AND issue.is_closed=?", p.ID, true).
Cols("issue_id").
@ -62,8 +62,8 @@ func (p *Project) NumClosedIssues() int {
}
// NumOpenIssues return counter of open issues assigned to a project
func (p *Project) NumOpenIssues() int {
c, err := db.GetEngine(db.DefaultContext).Table("project_issue").
func (p *Project) NumOpenIssues(ctx context.Context) int {
c, err := db.GetEngine(ctx).Table("project_issue").
Join("INNER", "issue", "project_issue.issue_id=issue.id").
Where("project_issue.project_id=? AND issue.is_closed=?", p.ID, false).
Cols("issue_id").
@ -76,8 +76,8 @@ func (p *Project) NumOpenIssues() int {
}
// MoveIssuesOnProjectBoard moves or keeps issues in a column and sorts them inside that column
func MoveIssuesOnProjectBoard(board *Board, sortedIssueIDs map[int64]int64) error {
return db.WithTx(db.DefaultContext, func(ctx context.Context) error {
func MoveIssuesOnProjectBoard(ctx context.Context, board *Board, sortedIssueIDs map[int64]int64) error {
return db.WithTx(ctx, func(ctx context.Context) error {
sess := db.GetEngine(ctx)
issueIDs := make([]int64, 0, len(sortedIssueIDs))

View file

@ -124,9 +124,9 @@ func (p *Project) LoadRepo(ctx context.Context) (err error) {
}
// Link returns the project's relative URL.
func (p *Project) Link() string {
func (p *Project) Link(ctx context.Context) string {
if p.OwnerID > 0 {
err := p.LoadOwner(db.DefaultContext)
err := p.LoadOwner(ctx)
if err != nil {
log.Error("LoadOwner: %v", err)
return ""
@ -134,7 +134,7 @@ func (p *Project) Link() string {
return fmt.Sprintf("%s/-/projects/%d", p.Owner.HomeLink(), p.ID)
}
if p.RepoID > 0 {
err := p.LoadRepo(db.DefaultContext)
err := p.LoadRepo(ctx)
if err != nil {
log.Error("LoadRepo: %v", err)
return ""
@ -261,7 +261,7 @@ func FindProjects(ctx context.Context, opts SearchOptions) ([]*Project, int64, e
}
// NewProject creates a new Project
func NewProject(p *Project) error {
func NewProject(ctx context.Context, p *Project) error {
if !IsBoardTypeValid(p.BoardType) {
p.BoardType = BoardTypeNone
}
@ -274,7 +274,7 @@ func NewProject(p *Project) error {
return util.NewInvalidArgumentErrorf("project type is not valid")
}
ctx, committer, err := db.TxContext(db.DefaultContext)
ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
@ -348,8 +348,8 @@ func updateRepositoryProjectCount(ctx context.Context, repoID int64) error {
}
// ChangeProjectStatusByRepoIDAndID toggles a project between opened and closed
func ChangeProjectStatusByRepoIDAndID(repoID, projectID int64, isClosed bool) error {
ctx, committer, err := db.TxContext(db.DefaultContext)
func ChangeProjectStatusByRepoIDAndID(ctx context.Context, repoID, projectID int64, isClosed bool) error {
ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
@ -372,8 +372,8 @@ func ChangeProjectStatusByRepoIDAndID(repoID, projectID int64, isClosed bool) er
}
// ChangeProjectStatus toggle a project between opened and closed
func ChangeProjectStatus(p *Project, isClosed bool) error {
ctx, committer, err := db.TxContext(db.DefaultContext)
func ChangeProjectStatus(ctx context.Context, p *Project, isClosed bool) error {
ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}

View file

@ -60,7 +60,7 @@ func TestProject(t *testing.T) {
CreatorID: 2,
}
assert.NoError(t, NewProject(project))
assert.NoError(t, NewProject(db.DefaultContext, project))
_, err := GetProjectByID(db.DefaultContext, project.ID)
assert.NoError(t, err)
@ -74,7 +74,7 @@ func TestProject(t *testing.T) {
assert.Equal(t, project.Title, projectFromDB.Title)
assert.NoError(t, ChangeProjectStatus(project, true))
assert.NoError(t, ChangeProjectStatus(db.DefaultContext, project, true))
// Retrieve from DB afresh to check if it is truly closed
projectFromDB, err = GetProjectByID(db.DefaultContext, project.ID)

View file

@ -62,8 +62,8 @@ func GetCollaborators(ctx context.Context, repoID int64, listOptions db.ListOpti
}
// CountCollaborators returns total number of collaborators for a repository
func CountCollaborators(repoID int64) (int64, error) {
return db.GetEngine(db.DefaultContext).Where("repo_id = ? ", repoID).Count(&Collaboration{})
func CountCollaborators(ctx context.Context, repoID int64) (int64, error) {
return db.GetEngine(ctx).Where("repo_id = ? ", repoID).Count(&Collaboration{})
}
// GetCollaboration get collaboration for a repository id with a user id
@ -138,11 +138,11 @@ func ChangeCollaborationAccessMode(ctx context.Context, repo *Repository, uid in
}
// IsOwnerMemberCollaborator checks if a provided user is the owner, a collaborator or a member of a team in a repository
func IsOwnerMemberCollaborator(repo *Repository, userID int64) (bool, error) {
func IsOwnerMemberCollaborator(ctx context.Context, repo *Repository, userID int64) (bool, error) {
if repo.OwnerID == userID {
return true, nil
}
teamMember, err := db.GetEngine(db.DefaultContext).Join("INNER", "team_repo", "team_repo.team_id = team_user.team_id").
teamMember, err := db.GetEngine(ctx).Join("INNER", "team_repo", "team_repo.team_id = team_user.team_id").
Join("INNER", "team_unit", "team_unit.team_id = team_user.team_id").
Where("team_repo.repo_id = ?", repo.ID).
And("team_unit.`type` = ?", unit.TypeCode).
@ -154,5 +154,5 @@ func IsOwnerMemberCollaborator(repo *Repository, userID int64) (bool, error) {
return true, nil
}
return db.GetEngine(db.DefaultContext).Get(&Collaboration{RepoID: repo.ID, UserID: userID})
return db.GetEngine(ctx).Get(&Collaboration{RepoID: repo.ID, UserID: userID})
}

View file

@ -89,17 +89,17 @@ func TestRepository_CountCollaborators(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4})
count, err := repo_model.CountCollaborators(repo1.ID)
count, err := repo_model.CountCollaborators(db.DefaultContext, repo1.ID)
assert.NoError(t, err)
assert.EqualValues(t, 2, count)
repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 22})
count, err = repo_model.CountCollaborators(repo2.ID)
count, err = repo_model.CountCollaborators(db.DefaultContext, repo2.ID)
assert.NoError(t, err)
assert.EqualValues(t, 2, count)
// Non-existent repository.
count, err = repo_model.CountCollaborators(unittest.NonexistentID)
count, err = repo_model.CountCollaborators(db.DefaultContext, unittest.NonexistentID)
assert.NoError(t, err)
assert.EqualValues(t, 0, count)
}
@ -110,31 +110,31 @@ func TestRepository_IsOwnerMemberCollaborator(t *testing.T) {
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
// Organisation owner.
actual, err := repo_model.IsOwnerMemberCollaborator(repo1, 2)
actual, err := repo_model.IsOwnerMemberCollaborator(db.DefaultContext, repo1, 2)
assert.NoError(t, err)
assert.True(t, actual)
// Team member.
actual, err = repo_model.IsOwnerMemberCollaborator(repo1, 4)
actual, err = repo_model.IsOwnerMemberCollaborator(db.DefaultContext, repo1, 4)
assert.NoError(t, err)
assert.True(t, actual)
// Normal user.
actual, err = repo_model.IsOwnerMemberCollaborator(repo1, 1)
actual, err = repo_model.IsOwnerMemberCollaborator(db.DefaultContext, repo1, 1)
assert.NoError(t, err)
assert.False(t, actual)
repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4})
// Collaborator.
actual, err = repo_model.IsOwnerMemberCollaborator(repo2, 4)
actual, err = repo_model.IsOwnerMemberCollaborator(db.DefaultContext, repo2, 4)
assert.NoError(t, err)
assert.True(t, actual)
repo3 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 15})
// Repository owner.
actual, err = repo_model.IsOwnerMemberCollaborator(repo3, 2)
actual, err = repo_model.IsOwnerMemberCollaborator(db.DefaultContext, repo3, 2)
assert.NoError(t, err)
assert.True(t, actual)
}

View file

@ -47,12 +47,12 @@ func (m *Mirror) BeforeInsert() {
}
// GetRepository returns the repository.
func (m *Mirror) GetRepository() *Repository {
func (m *Mirror) GetRepository(ctx context.Context) *Repository {
if m.Repo != nil {
return m.Repo
}
var err error
m.Repo, err = GetRepositoryByID(db.DefaultContext, m.RepoID)
m.Repo, err = GetRepositoryByID(ctx, m.RepoID)
if err != nil {
log.Error("getRepositoryByID[%d]: %v", m.ID, err)
}
@ -99,14 +99,14 @@ func TouchMirror(ctx context.Context, m *Mirror) error {
}
// DeleteMirrorByRepoID deletes a mirror by repoID
func DeleteMirrorByRepoID(repoID int64) error {
_, err := db.GetEngine(db.DefaultContext).Delete(&Mirror{RepoID: repoID})
func DeleteMirrorByRepoID(ctx context.Context, repoID int64) error {
_, err := db.GetEngine(ctx).Delete(&Mirror{RepoID: repoID})
return err
}
// MirrorsIterate iterates all mirror repositories.
func MirrorsIterate(limit int, f func(idx int, bean any) error) error {
sess := db.GetEngine(db.DefaultContext).
func MirrorsIterate(ctx context.Context, limit int, f func(idx int, bean any) error) error {
sess := db.GetEngine(ctx).
Where("next_update_unix<=?", time.Now().Unix()).
And("next_update_unix!=0").
OrderBy("updated_unix ASC")

View file

@ -71,7 +71,7 @@ loop:
now := timeutil.TimeStampNow().Add(-2)
uidCounts, err := activities_model.GetUIDsAndNotificationCounts(then, now)
uidCounts, err := activities_model.GetUIDsAndNotificationCounts(ctx, then, now)
if err != nil {
log.Error("Unable to get UIDcounts: %v", err)
}

View file

@ -116,7 +116,7 @@ func (graph *Graph) LoadAndProcessCommits(ctx context.Context, repository *repo_
c.Verification = asymkey_model.ParseCommitWithSignature(ctx, c.Commit)
_ = asymkey_model.CalculateTrustStatus(c.Verification, repository.GetTrustModel(), func(user *user_model.User) (bool, error) {
return repo_model.IsOwnerMemberCollaborator(repository, user.ID)
return repo_model.IsOwnerMemberCollaborator(ctx, repository, user.ID)
}, &keyMap)
statuses, _, err := git_model.GetLatestCommitStatus(ctx, repository.ID, c.Commit.ID.String(), db.ListOptions{})

View file

@ -58,11 +58,11 @@ func IsMultilineCommitMessage(msg string) bool {
// Actioner describes an action
type Actioner interface {
GetOpType() activities_model.ActionType
GetActUserName() string
GetRepoUserName() string
GetRepoName() string
GetRepoPath() string
GetRepoLink() string
GetActUserName(ctx context.Context) string
GetRepoUserName(ctx context.Context) string
GetRepoName(ctx context.Context) string
GetRepoPath(ctx context.Context) string
GetRepoLink(ctx context.Context) string
GetBranch() string
GetContent() string
GetCreate() time.Time

View file

@ -42,7 +42,7 @@ func NodeInfo(ctx *context.APIContext) {
usersActiveHalfyear := int(user_model.CountUsers(ctx, &user_model.CountUserFilter{LastLoginSince: &timeHaveYearAgo}))
allIssues, _ := issues_model.CountIssues(ctx, &issues_model.IssuesOptions{})
allComments, _ := issues_model.CountComments(&issues_model.FindCommentsOptions{})
allComments, _ := issues_model.CountComments(ctx, &issues_model.FindCommentsOptions{})
nodeInfoUsage = structs.NodeInfoUsage{
Users: structs.NodeInfoUsageUsers{

View file

@ -127,7 +127,7 @@ func ListRepoNotifications(ctx *context.APIContext) {
ctx.SetTotalCountHeader(totalCount)
ctx.JSON(http.StatusOK, convert.ToNotifications(nl))
ctx.JSON(http.StatusOK, convert.ToNotifications(ctx, nl))
}
// ReadRepoNotifications mark notification threads as read on a specific repo
@ -222,7 +222,7 @@ func ReadRepoNotifications(ctx *context.APIContext) {
return
}
_ = notif.LoadAttributes(ctx)
changed = append(changed, convert.ToNotificationThread(notif))
changed = append(changed, convert.ToNotificationThread(ctx, notif))
}
ctx.JSON(http.StatusResetContent, changed)
}

View file

@ -46,7 +46,7 @@ func GetThread(ctx *context.APIContext) {
return
}
ctx.JSON(http.StatusOK, convert.ToNotificationThread(n))
ctx.JSON(http.StatusOK, convert.ToNotificationThread(ctx, n))
}
// ReadThread mark notification as read by ID
@ -97,7 +97,7 @@ func ReadThread(ctx *context.APIContext) {
ctx.InternalServerError(err)
return
}
ctx.JSON(http.StatusResetContent, convert.ToNotificationThread(notif))
ctx.JSON(http.StatusResetContent, convert.ToNotificationThread(ctx, notif))
}
func getThread(ctx *context.APIContext) *activities_model.Notification {

View file

@ -86,7 +86,7 @@ func ListNotifications(ctx *context.APIContext) {
}
ctx.SetTotalCountHeader(totalCount)
ctx.JSON(http.StatusOK, convert.ToNotifications(nl))
ctx.JSON(http.StatusOK, convert.ToNotifications(ctx, nl))
}
// ReadNotifications mark notification threads as read, unread, or pinned
@ -167,7 +167,7 @@ func ReadNotifications(ctx *context.APIContext) {
return
}
_ = notif.LoadAttributes(ctx)
changed = append(changed, convert.ToNotificationThread(notif))
changed = append(changed, convert.ToNotificationThread(ctx, notif))
}
ctx.JSON(http.StatusResetContent, changed)

View file

@ -53,7 +53,7 @@ func ListCollaborators(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
count, err := repo_model.CountCollaborators(ctx.Repo.Repository.ID)
count, err := repo_model.CountCollaborators(ctx, ctx.Repo.Repository.ID)
if err != nil {
ctx.InternalServerError(err)
return

View file

@ -805,7 +805,7 @@ func EditIssue(ctx *context.APIContext) {
deadlineUnix = timeutil.TimeStamp(deadline.Unix())
}
if err := issues_model.UpdateIssueDeadline(issue, deadlineUnix, ctx.Doer); err != nil {
if err := issues_model.UpdateIssueDeadline(ctx, issue, deadlineUnix, ctx.Doer); err != nil {
ctx.Error(http.StatusInternalServerError, "UpdateIssueDeadline", err)
return
}
@ -854,7 +854,7 @@ func EditIssue(ctx *context.APIContext) {
}
issue.IsClosed = api.StateClosed == api.StateType(*form.State)
}
statusChangeComment, titleChanged, err := issues_model.UpdateIssueByAPI(issue, ctx.Doer)
statusChangeComment, titleChanged, err := issues_model.UpdateIssueByAPI(ctx, issue, ctx.Doer)
if err != nil {
if issues_model.IsErrDependenciesLeft(err) {
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this issue because it still has open dependencies")
@ -992,7 +992,7 @@ func UpdateIssueDeadline(ctx *context.APIContext) {
deadlineUnix = timeutil.TimeStamp(deadline.Unix())
}
if err := issues_model.UpdateIssueDeadline(issue, deadlineUnix, ctx.Doer); err != nil {
if err := issues_model.UpdateIssueDeadline(ctx, issue, deadlineUnix, ctx.Doer); err != nil {
ctx.Error(http.StatusInternalServerError, "UpdateIssueDeadline", err)
return
}

View file

@ -86,7 +86,7 @@ func ListIssueComments(ctx *context.APIContext) {
return
}
totalCount, err := issues_model.CountComments(opts)
totalCount, err := issues_model.CountComments(ctx, opts)
if err != nil {
ctx.InternalServerError(err)
return
@ -285,7 +285,7 @@ func ListRepoIssueComments(ctx *context.APIContext) {
return
}
totalCount, err := issues_model.CountComments(opts)
totalCount, err := issues_model.CountComments(ctx, opts)
if err != nil {
ctx.InternalServerError(err)
return

View file

@ -524,7 +524,7 @@ func EditPullRequest(ctx *context.APIContext) {
deadlineUnix = timeutil.TimeStamp(deadline.Unix())
}
if err := issues_model.UpdateIssueDeadline(issue, deadlineUnix, ctx.Doer); err != nil {
if err := issues_model.UpdateIssueDeadline(ctx, issue, deadlineUnix, ctx.Doer); err != nil {
ctx.Error(http.StatusInternalServerError, "UpdateIssueDeadline", err)
return
}
@ -591,7 +591,7 @@ func EditPullRequest(ctx *context.APIContext) {
}
issue.IsClosed = api.StateClosed == api.StateType(*form.State)
}
statusChangeComment, titleChanged, err := issues_model.UpdateIssueByAPI(issue, ctx.Doer)
statusChangeComment, titleChanged, err := issues_model.UpdateIssueByAPI(ctx, issue, ctx.Doer)
if err != nil {
if issues_model.IsErrDependenciesLeft(err) {
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this pull request because it still has open dependencies")

View file

@ -260,7 +260,7 @@ func DeletePullReview(ctx *context.APIContext) {
return
}
if err := issues_model.DeleteReview(review); err != nil {
if err := issues_model.DeleteReview(ctx, review); err != nil {
ctx.Error(http.StatusInternalServerError, "DeleteReview", fmt.Errorf("can not delete ReviewID: %d", review.ID))
return
}
@ -713,7 +713,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
}
if comment != nil && isAdd {
if err = comment.LoadReview(); err != nil {
if err = comment.LoadReview(ctx); err != nil {
ctx.ServerError("ReviewRequest", err)
return
}
@ -757,7 +757,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
}
if comment != nil && isAdd {
if err = comment.LoadReview(); err != nil {
if err = comment.LoadReview(ctx); err != nil {
ctx.ServerError("ReviewRequest", err)
return
}

View file

@ -23,28 +23,28 @@ import (
"github.com/gorilla/feeds"
)
func toBranchLink(act *activities_model.Action) string {
return act.GetRepoAbsoluteLink() + "/src/branch/" + util.PathEscapeSegments(act.GetBranch())
func toBranchLink(ctx *context.Context, act *activities_model.Action) string {
return act.GetRepoAbsoluteLink(ctx) + "/src/branch/" + util.PathEscapeSegments(act.GetBranch())
}
func toTagLink(act *activities_model.Action) string {
return act.GetRepoAbsoluteLink() + "/src/tag/" + util.PathEscapeSegments(act.GetTag())
func toTagLink(ctx *context.Context, act *activities_model.Action) string {
return act.GetRepoAbsoluteLink(ctx) + "/src/tag/" + util.PathEscapeSegments(act.GetTag())
}
func toIssueLink(act *activities_model.Action) string {
return act.GetRepoAbsoluteLink() + "/issues/" + url.PathEscape(act.GetIssueInfos()[0])
func toIssueLink(ctx *context.Context, act *activities_model.Action) string {
return act.GetRepoAbsoluteLink(ctx) + "/issues/" + url.PathEscape(act.GetIssueInfos()[0])
}
func toPullLink(act *activities_model.Action) string {
return act.GetRepoAbsoluteLink() + "/pulls/" + url.PathEscape(act.GetIssueInfos()[0])
func toPullLink(ctx *context.Context, act *activities_model.Action) string {
return act.GetRepoAbsoluteLink(ctx) + "/pulls/" + url.PathEscape(act.GetIssueInfos()[0])
}
func toSrcLink(act *activities_model.Action) string {
return act.GetRepoAbsoluteLink() + "/src/" + util.PathEscapeSegments(act.GetBranch())
func toSrcLink(ctx *context.Context, act *activities_model.Action) string {
return act.GetRepoAbsoluteLink(ctx) + "/src/" + util.PathEscapeSegments(act.GetBranch())
}
func toReleaseLink(act *activities_model.Action) string {
return act.GetRepoAbsoluteLink() + "/releases/tag/" + util.PathEscapeSegments(act.GetBranch())
func toReleaseLink(ctx *context.Context, act *activities_model.Action) string {
return act.GetRepoAbsoluteLink(ctx) + "/releases/tag/" + util.PathEscapeSegments(act.GetBranch())
}
// renderMarkdown creates a minimal markdown render context from an action.
@ -52,11 +52,11 @@ func toReleaseLink(act *activities_model.Action) string {
func renderMarkdown(ctx *context.Context, act *activities_model.Action, content string) string {
markdownCtx := &markup.RenderContext{
Ctx: ctx,
URLPrefix: act.GetRepoLink(),
URLPrefix: act.GetRepoLink(ctx),
Type: markdown.MarkupName,
Metas: map[string]string{
"user": act.GetRepoUserName(),
"repo": act.GetRepoName(),
"user": act.GetRepoUserName(ctx),
"repo": act.GetRepoName(ctx),
},
}
markdown, err := markdown.RenderString(markdownCtx, content)
@ -73,123 +73,123 @@ func feedActionsToFeedItems(ctx *context.Context, actions activities_model.Actio
var content, desc, title string
link := &feeds.Link{Href: act.GetCommentHTMLURL()}
link := &feeds.Link{Href: act.GetCommentHTMLURL(ctx)}
// title
title = act.ActUser.DisplayName() + " "
switch act.OpType {
case activities_model.ActionCreateRepo:
title += ctx.TrHTMLEscapeArgs("action.create_repo", act.GetRepoAbsoluteLink(), act.ShortRepoPath())
link.Href = act.GetRepoAbsoluteLink()
title += ctx.TrHTMLEscapeArgs("action.create_repo", act.GetRepoAbsoluteLink(ctx), act.ShortRepoPath(ctx))
link.Href = act.GetRepoAbsoluteLink(ctx)
case activities_model.ActionRenameRepo:
title += ctx.TrHTMLEscapeArgs("action.rename_repo", act.GetContent(), act.GetRepoAbsoluteLink(), act.ShortRepoPath())
link.Href = act.GetRepoAbsoluteLink()
title += ctx.TrHTMLEscapeArgs("action.rename_repo", act.GetContent(), act.GetRepoAbsoluteLink(ctx), act.ShortRepoPath(ctx))
link.Href = act.GetRepoAbsoluteLink(ctx)
case activities_model.ActionCommitRepo:
link.Href = toBranchLink(act)
link.Href = toBranchLink(ctx, act)
if len(act.Content) != 0 {
title += ctx.TrHTMLEscapeArgs("action.commit_repo", act.GetRepoAbsoluteLink(), link.Href, act.GetBranch(), act.ShortRepoPath())
title += ctx.TrHTMLEscapeArgs("action.commit_repo", act.GetRepoAbsoluteLink(ctx), link.Href, act.GetBranch(), act.ShortRepoPath(ctx))
} else {
title += ctx.TrHTMLEscapeArgs("action.create_branch", act.GetRepoAbsoluteLink(), link.Href, act.GetBranch(), act.ShortRepoPath())
title += ctx.TrHTMLEscapeArgs("action.create_branch", act.GetRepoAbsoluteLink(ctx), link.Href, act.GetBranch(), act.ShortRepoPath(ctx))
}
case activities_model.ActionCreateIssue:
link.Href = toIssueLink(act)
title += ctx.TrHTMLEscapeArgs("action.create_issue", link.Href, act.GetIssueInfos()[0], act.ShortRepoPath())
link.Href = toIssueLink(ctx, act)
title += ctx.TrHTMLEscapeArgs("action.create_issue", link.Href, act.GetIssueInfos()[0], act.ShortRepoPath(ctx))
case activities_model.ActionCreatePullRequest:
link.Href = toPullLink(act)
title += ctx.TrHTMLEscapeArgs("action.create_pull_request", link.Href, act.GetIssueInfos()[0], act.ShortRepoPath())
link.Href = toPullLink(ctx, act)
title += ctx.TrHTMLEscapeArgs("action.create_pull_request", link.Href, act.GetIssueInfos()[0], act.ShortRepoPath(ctx))
case activities_model.ActionTransferRepo:
link.Href = act.GetRepoAbsoluteLink()
title += ctx.TrHTMLEscapeArgs("action.transfer_repo", act.GetContent(), act.GetRepoAbsoluteLink(), act.ShortRepoPath())
link.Href = act.GetRepoAbsoluteLink(ctx)
title += ctx.TrHTMLEscapeArgs("action.transfer_repo", act.GetContent(), act.GetRepoAbsoluteLink(ctx), act.ShortRepoPath(ctx))
case activities_model.ActionPushTag:
link.Href = toTagLink(act)
title += ctx.TrHTMLEscapeArgs("action.push_tag", act.GetRepoAbsoluteLink(), link.Href, act.GetTag(), act.ShortRepoPath())
link.Href = toTagLink(ctx, act)
title += ctx.TrHTMLEscapeArgs("action.push_tag", act.GetRepoAbsoluteLink(ctx), link.Href, act.GetTag(), act.ShortRepoPath(ctx))
case activities_model.ActionCommentIssue:
issueLink := toIssueLink(act)
issueLink := toIssueLink(ctx, act)
if link.Href == "#" {
link.Href = issueLink
}
title += ctx.TrHTMLEscapeArgs("action.comment_issue", issueLink, act.GetIssueInfos()[0], act.ShortRepoPath())
title += ctx.TrHTMLEscapeArgs("action.comment_issue", issueLink, act.GetIssueInfos()[0], act.ShortRepoPath(ctx))
case activities_model.ActionMergePullRequest:
pullLink := toPullLink(act)
pullLink := toPullLink(ctx, act)
if link.Href == "#" {
link.Href = pullLink
}
title += ctx.TrHTMLEscapeArgs("action.merge_pull_request", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath())
title += ctx.TrHTMLEscapeArgs("action.merge_pull_request", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath(ctx))
case activities_model.ActionAutoMergePullRequest:
pullLink := toPullLink(act)
pullLink := toPullLink(ctx, act)
if link.Href == "#" {
link.Href = pullLink
}
title += ctx.TrHTMLEscapeArgs("action.auto_merge_pull_request", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath())
title += ctx.TrHTMLEscapeArgs("action.auto_merge_pull_request", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath(ctx))
case activities_model.ActionCloseIssue:
issueLink := toIssueLink(act)
issueLink := toIssueLink(ctx, act)
if link.Href == "#" {
link.Href = issueLink
}
title += ctx.TrHTMLEscapeArgs("action.close_issue", issueLink, act.GetIssueInfos()[0], act.ShortRepoPath())
title += ctx.TrHTMLEscapeArgs("action.close_issue", issueLink, act.GetIssueInfos()[0], act.ShortRepoPath(ctx))
case activities_model.ActionReopenIssue:
issueLink := toIssueLink(act)
issueLink := toIssueLink(ctx, act)
if link.Href == "#" {
link.Href = issueLink
}
title += ctx.TrHTMLEscapeArgs("action.reopen_issue", issueLink, act.GetIssueInfos()[0], act.ShortRepoPath())
title += ctx.TrHTMLEscapeArgs("action.reopen_issue", issueLink, act.GetIssueInfos()[0], act.ShortRepoPath(ctx))
case activities_model.ActionClosePullRequest:
pullLink := toPullLink(act)
pullLink := toPullLink(ctx, act)
if link.Href == "#" {
link.Href = pullLink
}
title += ctx.TrHTMLEscapeArgs("action.close_pull_request", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath())
title += ctx.TrHTMLEscapeArgs("action.close_pull_request", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath(ctx))
case activities_model.ActionReopenPullRequest:
pullLink := toPullLink(act)
pullLink := toPullLink(ctx, act)
if link.Href == "#" {
link.Href = pullLink
}
title += ctx.TrHTMLEscapeArgs("action.reopen_pull_request", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath())
title += ctx.TrHTMLEscapeArgs("action.reopen_pull_request", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath(ctx))
case activities_model.ActionDeleteTag:
link.Href = act.GetRepoAbsoluteLink()
title += ctx.TrHTMLEscapeArgs("action.delete_tag", act.GetRepoAbsoluteLink(), act.GetTag(), act.ShortRepoPath())
link.Href = act.GetRepoAbsoluteLink(ctx)
title += ctx.TrHTMLEscapeArgs("action.delete_tag", act.GetRepoAbsoluteLink(ctx), act.GetTag(), act.ShortRepoPath(ctx))
case activities_model.ActionDeleteBranch:
link.Href = act.GetRepoAbsoluteLink()
title += ctx.TrHTMLEscapeArgs("action.delete_branch", act.GetRepoAbsoluteLink(), html.EscapeString(act.GetBranch()), act.ShortRepoPath())
link.Href = act.GetRepoAbsoluteLink(ctx)
title += ctx.TrHTMLEscapeArgs("action.delete_branch", act.GetRepoAbsoluteLink(ctx), html.EscapeString(act.GetBranch()), act.ShortRepoPath(ctx))
case activities_model.ActionMirrorSyncPush:
srcLink := toSrcLink(act)
srcLink := toSrcLink(ctx, act)
if link.Href == "#" {
link.Href = srcLink
}
title += ctx.TrHTMLEscapeArgs("action.mirror_sync_push", act.GetRepoAbsoluteLink(), srcLink, act.GetBranch(), act.ShortRepoPath())
title += ctx.TrHTMLEscapeArgs("action.mirror_sync_push", act.GetRepoAbsoluteLink(ctx), srcLink, act.GetBranch(), act.ShortRepoPath(ctx))
case activities_model.ActionMirrorSyncCreate:
srcLink := toSrcLink(act)
srcLink := toSrcLink(ctx, act)
if link.Href == "#" {
link.Href = srcLink
}
title += ctx.TrHTMLEscapeArgs("action.mirror_sync_create", act.GetRepoAbsoluteLink(), srcLink, act.GetBranch(), act.ShortRepoPath())
title += ctx.TrHTMLEscapeArgs("action.mirror_sync_create", act.GetRepoAbsoluteLink(ctx), srcLink, act.GetBranch(), act.ShortRepoPath(ctx))
case activities_model.ActionMirrorSyncDelete:
link.Href = act.GetRepoAbsoluteLink()
title += ctx.TrHTMLEscapeArgs("action.mirror_sync_delete", act.GetRepoAbsoluteLink(), act.GetBranch(), act.ShortRepoPath())
link.Href = act.GetRepoAbsoluteLink(ctx)
title += ctx.TrHTMLEscapeArgs("action.mirror_sync_delete", act.GetRepoAbsoluteLink(ctx), act.GetBranch(), act.ShortRepoPath(ctx))
case activities_model.ActionApprovePullRequest:
pullLink := toPullLink(act)
title += ctx.TrHTMLEscapeArgs("action.approve_pull_request", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath())
pullLink := toPullLink(ctx, act)
title += ctx.TrHTMLEscapeArgs("action.approve_pull_request", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath(ctx))
case activities_model.ActionRejectPullRequest:
pullLink := toPullLink(act)
title += ctx.TrHTMLEscapeArgs("action.reject_pull_request", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath())
pullLink := toPullLink(ctx, act)
title += ctx.TrHTMLEscapeArgs("action.reject_pull_request", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath(ctx))
case activities_model.ActionCommentPull:
pullLink := toPullLink(act)
title += ctx.TrHTMLEscapeArgs("action.comment_pull", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath())
pullLink := toPullLink(ctx, act)
title += ctx.TrHTMLEscapeArgs("action.comment_pull", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath(ctx))
case activities_model.ActionPublishRelease:
releaseLink := toReleaseLink(act)
releaseLink := toReleaseLink(ctx, act)
if link.Href == "#" {
link.Href = releaseLink
}
title += ctx.TrHTMLEscapeArgs("action.publish_release", act.GetRepoAbsoluteLink(), releaseLink, act.ShortRepoPath(), act.Content)
title += ctx.TrHTMLEscapeArgs("action.publish_release", act.GetRepoAbsoluteLink(ctx), releaseLink, act.ShortRepoPath(ctx), act.Content)
case activities_model.ActionPullReviewDismissed:
pullLink := toPullLink(act)
title += ctx.TrHTMLEscapeArgs("action.review_dismissed", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath(), act.GetIssueInfos()[1])
pullLink := toPullLink(ctx, act)
title += ctx.TrHTMLEscapeArgs("action.review_dismissed", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath(ctx), act.GetIssueInfos()[1])
case activities_model.ActionStarRepo:
link.Href = act.GetRepoAbsoluteLink()
title += ctx.TrHTMLEscapeArgs("action.starred_repo", act.GetRepoAbsoluteLink(), act.GetRepoPath())
link.Href = act.GetRepoAbsoluteLink(ctx)
title += ctx.TrHTMLEscapeArgs("action.starred_repo", act.GetRepoAbsoluteLink(ctx), act.GetRepoPath(ctx))
case activities_model.ActionWatchRepo:
link.Href = act.GetRepoAbsoluteLink()
title += ctx.TrHTMLEscapeArgs("action.watched_repo", act.GetRepoAbsoluteLink(), act.GetRepoPath())
link.Href = act.GetRepoAbsoluteLink(ctx)
title += ctx.TrHTMLEscapeArgs("action.watched_repo", act.GetRepoAbsoluteLink(ctx), act.GetRepoPath(ctx))
default:
return nil, fmt.Errorf("unknown action type: %v", act.OpType)
}
@ -199,14 +199,14 @@ func feedActionsToFeedItems(ctx *context.Context, actions activities_model.Actio
switch act.OpType {
case activities_model.ActionCommitRepo, activities_model.ActionMirrorSyncPush:
push := templates.ActionContent2Commits(act)
repoLink := act.GetRepoAbsoluteLink()
repoLink := act.GetRepoAbsoluteLink(ctx)
for _, commit := range push.Commits {
if len(desc) != 0 {
desc += "\n\n"
}
desc += fmt.Sprintf("<a href=\"%s\">%s</a>\n%s",
html.EscapeString(fmt.Sprintf("%s/commit/%s", act.GetRepoAbsoluteLink(), commit.Sha1)),
html.EscapeString(fmt.Sprintf("%s/commit/%s", act.GetRepoAbsoluteLink(ctx), commit.Sha1)),
commit.Sha1,
templates.RenderCommitMessage(ctx, commit.Message, repoLink, nil),
)
@ -215,14 +215,14 @@ func feedActionsToFeedItems(ctx *context.Context, actions activities_model.Actio
if push.Len > 1 {
link = &feeds.Link{Href: fmt.Sprintf("%s/%s", setting.AppSubURL, push.CompareURL)}
} else if push.Len == 1 {
link = &feeds.Link{Href: fmt.Sprintf("%s/commit/%s", act.GetRepoAbsoluteLink(), push.Commits[0].Sha1)}
link = &feeds.Link{Href: fmt.Sprintf("%s/commit/%s", act.GetRepoAbsoluteLink(ctx), push.Commits[0].Sha1)}
}
case activities_model.ActionCreateIssue, activities_model.ActionCreatePullRequest:
desc = strings.Join(act.GetIssueInfos(), "#")
content = renderMarkdown(ctx, act, act.GetIssueContent(ctx))
case activities_model.ActionCommentIssue, activities_model.ActionApprovePullRequest, activities_model.ActionRejectPullRequest, activities_model.ActionCommentPull:
desc = act.GetIssueTitle()
desc = act.GetIssueTitle(ctx)
comment := act.GetIssueInfos()[1]
if len(comment) != 0 {
desc += "\n\n" + renderMarkdown(ctx, act, comment)
@ -230,7 +230,7 @@ func feedActionsToFeedItems(ctx *context.Context, actions activities_model.Actio
case activities_model.ActionMergePullRequest, activities_model.ActionAutoMergePullRequest:
desc = act.GetIssueInfos()[1]
case activities_model.ActionCloseIssue, activities_model.ActionReopenIssue, activities_model.ActionClosePullRequest, activities_model.ActionReopenPullRequest:
desc = act.GetIssueTitle()
desc = act.GetIssueTitle(ctx)
case activities_model.ActionPullReviewDismissed:
desc = ctx.Tr("action.review_dismissed_reason") + "\n\n" + act.GetIssueInfos()[2]
}

View file

@ -179,7 +179,7 @@ func NewProjectPost(ctx *context.Context) {
newProject.Type = project_model.TypeIndividual
}
if err := project_model.NewProject(&newProject); err != nil {
if err := project_model.NewProject(ctx, &newProject); err != nil {
ctx.ServerError("NewProject", err)
return
}
@ -201,7 +201,7 @@ func ChangeProjectStatus(ctx *context.Context) {
}
id := ctx.ParamsInt64(":id")
if err := project_model.ChangeProjectStatusByRepoIDAndID(0, id, toClose); err != nil {
if err := project_model.ChangeProjectStatusByRepoIDAndID(ctx, 0, id, toClose); err != nil {
if project_model.IsErrProjectNotExist(err) {
ctx.NotFound("", err)
} else {
@ -320,7 +320,7 @@ func EditProjectPost(ctx *context.Context) {
ctx.Flash.Success(ctx.Tr("repo.projects.edit_success", p.Title))
if ctx.FormString("redirect") == "project" {
ctx.Redirect(p.Link())
ctx.Redirect(p.Link(ctx))
} else {
ctx.Redirect(ctx.ContextUser.HomeLink() + "/-/projects")
}
@ -515,7 +515,7 @@ func DeleteProjectBoard(ctx *context.Context) {
return
}
if err := project_model.DeleteBoardByID(ctx.ParamsInt64(":boardID")); err != nil {
if err := project_model.DeleteBoardByID(ctx, ctx.ParamsInt64(":boardID")); err != nil {
ctx.ServerError("DeleteProjectBoardByID", err)
return
}
@ -537,7 +537,7 @@ func AddBoardToProjectPost(ctx *context.Context) {
return
}
if err := project_model.NewBoard(&project_model.Board{
if err := project_model.NewBoard(ctx, &project_model.Board{
ProjectID: project.ID,
Title: form.Title,
Color: form.Color,
@ -623,7 +623,7 @@ func SetDefaultProjectBoard(ctx *context.Context) {
return
}
if err := project_model.SetDefaultBoard(project.ID, board.ID); err != nil {
if err := project_model.SetDefaultBoard(ctx, project.ID, board.ID); err != nil {
ctx.ServerError("SetDefaultBoard", err)
return
}
@ -638,7 +638,7 @@ func UnsetDefaultProjectBoard(ctx *context.Context) {
return
}
if err := project_model.SetDefaultBoard(project.ID, 0); err != nil {
if err := project_model.SetDefaultBoard(ctx, project.ID, 0); err != nil {
ctx.ServerError("SetDefaultBoard", err)
return
}
@ -738,7 +738,7 @@ func MoveIssues(ctx *context.Context) {
}
}
if err = project_model.MoveIssuesOnProjectBoard(board, sortedIssueIDs); err != nil {
if err = project_model.MoveIssuesOnProjectBoard(ctx, board, sortedIssueIDs); err != nil {
ctx.ServerError("MoveIssuesOnProjectBoard", err)
return
}

View file

@ -361,7 +361,7 @@ func Diff(ctx *context.Context) {
ctx.Data["DiffNotAvailable"] = diff.NumFiles == 0
if err := asymkey_model.CalculateTrustStatus(verification, ctx.Repo.Repository.GetTrustModel(), func(user *user_model.User) (bool, error) {
return repo_model.IsOwnerMemberCollaborator(ctx.Repo.Repository, user.ID)
return repo_model.IsOwnerMemberCollaborator(ctx, ctx.Repo.Repository, user.ID)
}, nil); err != nil {
ctx.ServerError("CalculateTrustStatus", err)
return

View file

@ -1608,7 +1608,7 @@ func ViewIssue(ctx *context.Context) {
marked[comment.PosterID] = comment.ShowRole
participants = addParticipant(comment.Poster, participants)
} else if comment.Type == issues_model.CommentTypeLabel {
if err = comment.LoadLabel(); err != nil {
if err = comment.LoadLabel(ctx); err != nil {
ctx.ServerError("LoadLabel", err)
return
}
@ -1629,7 +1629,7 @@ func ViewIssue(ctx *context.Context) {
}
} else if comment.Type == issues_model.CommentTypeProject {
if err = comment.LoadProject(); err != nil {
if err = comment.LoadProject(ctx); err != nil {
ctx.ServerError("LoadProject", err)
return
}
@ -1648,12 +1648,12 @@ func ViewIssue(ctx *context.Context) {
}
} else if comment.Type == issues_model.CommentTypeAssignees || comment.Type == issues_model.CommentTypeReviewRequest {
if err = comment.LoadAssigneeUserAndTeam(); err != nil {
if err = comment.LoadAssigneeUserAndTeam(ctx); err != nil {
ctx.ServerError("LoadAssigneeUserAndTeam", err)
return
}
} else if comment.Type == issues_model.CommentTypeRemoveDependency || comment.Type == issues_model.CommentTypeAddDependency {
if err = comment.LoadDepIssueDetails(); err != nil {
if err = comment.LoadDepIssueDetails(ctx); err != nil {
if !issues_model.IsErrIssueNotExist(err) {
ctx.ServerError("LoadDepIssueDetails", err)
return
@ -1670,7 +1670,7 @@ func ViewIssue(ctx *context.Context) {
ctx.ServerError("RenderString", err)
return
}
if err = comment.LoadReview(); err != nil && !issues_model.IsErrReviewNotExist(err) {
if err = comment.LoadReview(ctx); err != nil && !issues_model.IsErrReviewNotExist(err) {
ctx.ServerError("LoadReview", err)
return
}
@ -1709,7 +1709,7 @@ func ViewIssue(ctx *context.Context) {
}
}
}
if err = comment.LoadResolveDoer(); err != nil {
if err = comment.LoadResolveDoer(ctx); err != nil {
ctx.ServerError("LoadResolveDoer", err)
return
}
@ -1794,7 +1794,7 @@ func ViewIssue(ctx *context.Context) {
return
}
if ctx.Data["CanMarkConversation"], err = issues_model.CanMarkConversation(issue, ctx.Doer); err != nil {
if ctx.Data["CanMarkConversation"], err = issues_model.CanMarkConversation(ctx, issue, ctx.Doer); err != nil {
ctx.ServerError("CanMarkConversation", err)
return
}
@ -2261,7 +2261,7 @@ func UpdateIssueDeadline(ctx *context.Context) {
deadlineUnix = timeutil.TimeStamp(deadline.Unix())
}
if err := issues_model.UpdateIssueDeadline(issue, deadlineUnix, ctx.Doer); err != nil {
if err := issues_model.UpdateIssueDeadline(ctx, issue, deadlineUnix, ctx.Doer); err != nil {
ctx.Error(http.StatusInternalServerError, "UpdateIssueDeadline", err.Error())
return
}
@ -3319,7 +3319,7 @@ func ChangeCommentReaction(ctx *context.Context) {
}
// Reload new reactions
comment.Reactions = nil
if err = comment.LoadReactions(ctx.Repo.Repository); err != nil {
if err = comment.LoadReactions(ctx, ctx.Repo.Repository); err != nil {
log.Info("comment.LoadReactions: %s", err)
break
}
@ -3333,7 +3333,7 @@ func ChangeCommentReaction(ctx *context.Context) {
// Reload new reactions
comment.Reactions = nil
if err = comment.LoadReactions(ctx.Repo.Repository); err != nil {
if err = comment.LoadReactions(ctx, ctx.Repo.Repository); err != nil {
log.Info("comment.LoadReactions: %s", err)
break
}
@ -3459,9 +3459,9 @@ func updateAttachments(ctx *context.Context, item any, files []string) error {
if len(files) > 0 {
switch content := item.(type) {
case *issues_model.Issue:
err = issues_model.UpdateIssueAttachments(content.ID, files)
err = issues_model.UpdateIssueAttachments(ctx, content.ID, files)
case *issues_model.Comment:
err = content.UpdateAttachments(files)
err = content.UpdateAttachments(ctx, files)
default:
return fmt.Errorf("unknown Type: %T", content)
}

View file

@ -142,7 +142,7 @@ func NewProjectPost(ctx *context.Context) {
return
}
if err := project_model.NewProject(&project_model.Project{
if err := project_model.NewProject(ctx, &project_model.Project{
RepoID: ctx.Repo.Repository.ID,
Title: form.Title,
Description: form.Content,
@ -172,7 +172,7 @@ func ChangeProjectStatus(ctx *context.Context) {
}
id := ctx.ParamsInt64(":id")
if err := project_model.ChangeProjectStatusByRepoIDAndID(ctx.Repo.Repository.ID, id, toClose); err != nil {
if err := project_model.ChangeProjectStatusByRepoIDAndID(ctx, ctx.Repo.Repository.ID, id, toClose); err != nil {
if project_model.IsErrProjectNotExist(err) {
ctx.NotFound("", err)
} else {
@ -279,7 +279,7 @@ func EditProjectPost(ctx *context.Context) {
ctx.Flash.Success(ctx.Tr("repo.projects.edit_success", p.Title))
if ctx.FormString("redirect") == "project" {
ctx.Redirect(p.Link())
ctx.Redirect(p.Link(ctx))
} else {
ctx.Redirect(ctx.Repo.RepoLink + "/projects")
}
@ -445,7 +445,7 @@ func DeleteProjectBoard(ctx *context.Context) {
return
}
if err := project_model.DeleteBoardByID(ctx.ParamsInt64(":boardID")); err != nil {
if err := project_model.DeleteBoardByID(ctx, ctx.ParamsInt64(":boardID")); err != nil {
ctx.ServerError("DeleteProjectBoardByID", err)
return
}
@ -473,7 +473,7 @@ func AddBoardToProjectPost(ctx *context.Context) {
return
}
if err := project_model.NewBoard(&project_model.Board{
if err := project_model.NewBoard(ctx, &project_model.Board{
ProjectID: project.ID,
Title: form.Title,
Color: form.Color,
@ -565,7 +565,7 @@ func SetDefaultProjectBoard(ctx *context.Context) {
return
}
if err := project_model.SetDefaultBoard(project.ID, board.ID); err != nil {
if err := project_model.SetDefaultBoard(ctx, project.ID, board.ID); err != nil {
ctx.ServerError("SetDefaultBoard", err)
return
}
@ -580,7 +580,7 @@ func UnSetDefaultProjectBoard(ctx *context.Context) {
return
}
if err := project_model.SetDefaultBoard(project.ID, 0); err != nil {
if err := project_model.SetDefaultBoard(ctx, project.ID, 0); err != nil {
ctx.ServerError("SetDefaultBoard", err)
return
}
@ -682,7 +682,7 @@ func MoveIssues(ctx *context.Context) {
}
}
if err = project_model.MoveIssuesOnProjectBoard(board, sortedIssueIDs); err != nil {
if err = project_model.MoveIssuesOnProjectBoard(ctx, board, sortedIssueIDs); err != nil {
ctx.ServerError("MoveIssuesOnProjectBoard", err)
return
}

View file

@ -959,7 +959,7 @@ func viewPullFiles(ctx *context.Context, specifiedStartCommit, specifiedEndCommi
}
if ctx.IsSigned && ctx.Doer != nil {
if ctx.Data["CanMarkConversation"], err = issues_model.CanMarkConversation(issue, ctx.Doer); err != nil {
if ctx.Data["CanMarkConversation"], err = issues_model.CanMarkConversation(ctx, issue, ctx.Doer); err != nil {
ctx.ServerError("CanMarkConversation", err)
return
}
@ -986,7 +986,7 @@ func viewPullFiles(ctx *context.Context, specifiedStartCommit, specifiedEndCommi
}
numPendingCodeComments := int64(0)
if currentReview != nil {
numPendingCodeComments, err = issues_model.CountComments(&issues_model.FindCommentsOptions{
numPendingCodeComments, err = issues_model.CountComments(ctx, &issues_model.FindCommentsOptions{
Type: issues_model.CommentTypeCode,
ReviewID: currentReview.ID,
IssueID: issue.ID,

View file

@ -101,7 +101,7 @@ func CreateCodeComment(ctx *context.Context) {
renderConversation(ctx, comment)
return
}
ctx.Redirect(comment.Link())
ctx.Redirect(comment.Link(ctx))
}
// UpdateResolveConversation add or remove an Conversation resolved mark
@ -127,7 +127,7 @@ func UpdateResolveConversation(ctx *context.Context) {
}
var permResult bool
if permResult, err = issues_model.CanMarkConversation(comment.Issue, ctx.Doer); err != nil {
if permResult, err = issues_model.CanMarkConversation(ctx, comment.Issue, ctx.Doer); err != nil {
ctx.ServerError("CanMarkConversation", err)
return
}
@ -142,7 +142,7 @@ func UpdateResolveConversation(ctx *context.Context) {
}
if action == "Resolve" || action == "UnResolve" {
err = issues_model.MarkConversation(comment, ctx.Doer, action == "Resolve")
err = issues_model.MarkConversation(ctx, comment, ctx.Doer, action == "Resolve")
if err != nil {
ctx.ServerError("MarkConversation", err)
return

View file

@ -695,7 +695,7 @@ func SettingsPost(ctx *context.Context) {
if _, err := repo_module.CleanUpMigrateInfo(ctx, repo); err != nil {
ctx.ServerError("CleanUpMigrateInfo", err)
return
} else if err = repo_model.DeleteMirrorByRepoID(ctx.Repo.Repository.ID); err != nil {
} else if err = repo_model.DeleteMirrorByRepoID(ctx, ctx.Repo.Repository.ID); err != nil {
ctx.ServerError("DeleteMirrorByRepoID", err)
return
}

View file

@ -843,7 +843,7 @@ func renderDirectoryFiles(ctx *context.Context, timeout time.Duration) git.Entri
verification := asymkey_model.ParseCommitWithSignature(ctx, latestCommit)
if err := asymkey_model.CalculateTrustStatus(verification, ctx.Repo.Repository.GetTrustModel(), func(user *user_model.User) (bool, error) {
return repo_model.IsOwnerMemberCollaborator(ctx.Repo.Repository, user.ID)
return repo_model.IsOwnerMemberCollaborator(ctx, ctx.Repo.Repository, user.ID)
}, nil); err != nil {
ctx.ServerError("CalculateTrustStatus", err)
return nil

View file

@ -19,9 +19,9 @@ func ToAPIComment(ctx context.Context, repo *repo_model.Repository, c *issues_mo
return &api.Comment{
ID: c.ID,
Poster: ToUser(ctx, c.Poster, nil),
HTMLURL: c.HTMLURL(),
IssueURL: c.IssueURL(),
PRURL: c.PRURL(),
HTMLURL: c.HTMLURL(ctx),
IssueURL: c.IssueURL(ctx),
PRURL: c.PRURL(ctx),
Body: c.Content,
Attachments: ToAPIAttachments(repo, c.Attachments),
Created: c.CreatedUnix.AsTime(),
@ -37,19 +37,19 @@ func ToTimelineComment(ctx context.Context, repo *repo_model.Repository, c *issu
return nil
}
err = c.LoadAssigneeUserAndTeam()
err = c.LoadAssigneeUserAndTeam(ctx)
if err != nil {
log.Error("LoadAssigneeUserAndTeam: %v", err)
return nil
}
err = c.LoadResolveDoer()
err = c.LoadResolveDoer(ctx)
if err != nil {
log.Error("LoadResolveDoer: %v", err)
return nil
}
err = c.LoadDepIssueDetails()
err = c.LoadDepIssueDetails(ctx)
if err != nil {
log.Error("LoadDepIssueDetails: %v", err)
return nil
@ -61,7 +61,7 @@ func ToTimelineComment(ctx context.Context, repo *repo_model.Repository, c *issu
return nil
}
err = c.LoadLabel()
err = c.LoadLabel(ctx)
if err != nil {
log.Error("LoadLabel: %v", err)
return nil
@ -82,9 +82,9 @@ func ToTimelineComment(ctx context.Context, repo *repo_model.Repository, c *issu
ID: c.ID,
Type: c.Type.String(),
Poster: ToUser(ctx, c.Poster, nil),
HTMLURL: c.HTMLURL(),
IssueURL: c.IssueURL(),
PRURL: c.PRURL(),
HTMLURL: c.HTMLURL(ctx),
IssueURL: c.IssueURL(ctx),
PRURL: c.PRURL(ctx),
Body: c.Content,
Created: c.CreatedUnix.AsTime(),
Updated: c.UpdatedUnix.AsTime(),

View file

@ -4,17 +4,17 @@
package convert
import (
"context"
"net/url"
activities_model "code.gitea.io/gitea/models/activities"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/perm"
access_model "code.gitea.io/gitea/models/perm/access"
api "code.gitea.io/gitea/modules/structs"
)
// ToNotificationThread convert a Notification to api.NotificationThread
func ToNotificationThread(n *activities_model.Notification) *api.NotificationThread {
func ToNotificationThread(ctx context.Context, n *activities_model.Notification) *api.NotificationThread {
result := &api.NotificationThread{
ID: n.ID,
Unread: !(n.Status == activities_model.NotificationStatusRead || n.Status == activities_model.NotificationStatusPinned),
@ -25,7 +25,7 @@ func ToNotificationThread(n *activities_model.Notification) *api.NotificationThr
// since user only get notifications when he has access to use minimal access mode
if n.Repository != nil {
result.Repository = ToRepo(db.DefaultContext, n.Repository, access_model.Permission{AccessMode: perm.AccessModeRead})
result.Repository = ToRepo(ctx, n.Repository, access_model.Permission{AccessMode: perm.AccessModeRead})
// This permission is not correct and we should not be reporting it
for repository := result.Repository; repository != nil; repository = repository.Parent {
@ -44,8 +44,8 @@ func ToNotificationThread(n *activities_model.Notification) *api.NotificationThr
result.Subject.State = n.Issue.State()
comment, err := n.Issue.GetLastComment()
if err == nil && comment != nil {
result.Subject.LatestCommentURL = comment.APIURL()
result.Subject.LatestCommentHTMLURL = comment.HTMLURL()
result.Subject.LatestCommentURL = comment.APIURL(ctx)
result.Subject.LatestCommentHTMLURL = comment.HTMLURL(ctx)
}
}
case activities_model.NotificationSourcePullRequest:
@ -57,8 +57,8 @@ func ToNotificationThread(n *activities_model.Notification) *api.NotificationThr
result.Subject.State = n.Issue.State()
comment, err := n.Issue.GetLastComment()
if err == nil && comment != nil {
result.Subject.LatestCommentURL = comment.APIURL()
result.Subject.LatestCommentHTMLURL = comment.HTMLURL()
result.Subject.LatestCommentURL = comment.APIURL(ctx)
result.Subject.LatestCommentHTMLURL = comment.HTMLURL(ctx)
}
pr, _ := n.Issue.GetPullRequest()
@ -88,10 +88,10 @@ func ToNotificationThread(n *activities_model.Notification) *api.NotificationThr
}
// ToNotifications convert list of Notification to api.NotificationThread list
func ToNotifications(nl activities_model.NotificationList) []*api.NotificationThread {
func ToNotifications(ctx context.Context, nl activities_model.NotificationList) []*api.NotificationThread {
result := make([]*api.NotificationThread, 0, len(nl))
for _, n := range nl {
result = append(result, ToNotificationThread(n))
result = append(result, ToNotificationThread(ctx, n))
}
return result
}

View file

@ -36,10 +36,10 @@ func ToPullReview(ctx context.Context, r *issues_model.Review, doer *user_model.
Stale: r.Stale,
Official: r.Official,
Dismissed: r.Dismissed,
CodeCommentsCount: r.GetCodeCommentsCount(),
CodeCommentsCount: r.GetCodeCommentsCount(ctx),
Submitted: r.CreatedUnix.AsTime(),
Updated: r.UpdatedUnix.AsTime(),
HTMLURL: r.HTMLURL(),
HTMLURL: r.HTMLURL(ctx),
HTMLPullURL: r.Issue.HTMLURL(),
}
@ -102,7 +102,7 @@ func ToPullReviewCommentList(ctx context.Context, review *issues_model.Review, d
CommitID: comment.CommitSHA,
OrigCommitID: comment.OldRef,
DiffHunk: patch2diff(comment.Patch),
HTMLURL: comment.HTMLURL(),
HTMLURL: comment.HTMLURL(ctx),
HTMLPullURL: review.Issue.HTMLURL(),
}

View file

@ -135,7 +135,7 @@ func registerDeleteOldActions() {
OlderThan: 365 * 24 * time.Hour,
}, func(ctx context.Context, _ *user_model.User, config Config) error {
olderThanConfig := config.(*OlderThanConfig)
return activities_model.DeleteOldActions(olderThanConfig.OlderThan)
return activities_model.DeleteOldActions(ctx, olderThanConfig.OlderThan)
})
}

View file

@ -82,11 +82,11 @@ func UpdateExternalUser(user *user_model.User, gothUser goth.User) error {
// UpdateMigrationsByType updates all migrated repositories' posterid from gitServiceType to replace originalAuthorID to posterID
func UpdateMigrationsByType(ctx context.Context, tp structs.GitServiceType, externalUserID string, userID int64) error {
if err := issues_model.UpdateIssuesMigrationsByType(tp, externalUserID, userID); err != nil {
if err := issues_model.UpdateIssuesMigrationsByType(ctx, tp, externalUserID, userID); err != nil {
return err
}
if err := issues_model.UpdateCommentsMigrationsByType(tp, externalUserID, userID); err != nil {
if err := issues_model.UpdateCommentsMigrationsByType(ctx, tp, externalUserID, userID); err != nil {
return err
}
@ -94,8 +94,8 @@ func UpdateMigrationsByType(ctx context.Context, tp structs.GitServiceType, exte
return err
}
if err := issues_model.UpdateReactionsMigrationsByType(tp, externalUserID, userID); err != nil {
if err := issues_model.UpdateReactionsMigrationsByType(ctx, tp, externalUserID, userID); err != nil {
return err
}
return issues_model.UpdateReviewsMigrationsByType(tp, externalUserID, userID)
return issues_model.UpdateReviewsMigrationsByType(ctx, tp, externalUserID, userID)
}

View file

@ -265,7 +265,7 @@ func (a *actionNotifier) PullRequestReview(ctx context.Context, pr *issues_model
actions = append(actions, action)
}
if err := activities_model.NotifyWatchersActions(actions); err != nil {
if err := activities_model.NotifyWatchersActions(ctx, actions); err != nil {
log.Error("notify watchers '%d/%d': %v", review.Reviewer.ID, review.Issue.RepoID, err)
}
}

View file

@ -84,7 +84,7 @@ func UpdateComment(ctx context.Context, c *issues_model.Comment, doer *user_mode
}
}
if err := issues_model.UpdateComment(c, doer); err != nil {
if err := issues_model.UpdateComment(ctx, c, doer); err != nil {
return err
}

View file

@ -15,7 +15,7 @@ import (
func ChangeContent(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, content string) (err error) {
oldContent := issue.Content
if err := issues_model.ChangeIssueContent(issue, doer, content); err != nil {
if err := issues_model.ChangeIssueContent(ctx, issue, doer, content); err != nil {
return err
}

View file

@ -22,7 +22,7 @@ import (
// NewIssue creates new issue with labels for repository.
func NewIssue(ctx context.Context, repo *repo_model.Repository, issue *issues_model.Issue, labelIDs []int64, uuids []string, assigneeIDs []int64) error {
if err := issues_model.NewIssue(repo, issue, labelIDs, uuids); err != nil {
if err := issues_model.NewIssue(ctx, repo, issue, labelIDs, uuids); err != nil {
return err
}
@ -73,7 +73,7 @@ func ChangeIssueRef(ctx context.Context, issue *issues_model.Issue, doer *user_m
oldRef := issue.Ref
issue.Ref = ref
if err := issues_model.ChangeIssueRef(issue, doer, oldRef); err != nil {
if err := issues_model.ChangeIssueRef(ctx, issue, doer, oldRef); err != nil {
return err
}

View file

@ -510,7 +510,7 @@ func (g *GiteaLocalUploader) CreateComments(comments ...*base.Comment) error {
if len(cms) == 0 {
return nil
}
return issues_model.InsertIssueComments(cms)
return issues_model.InsertIssueComments(g.ctx, cms)
}
// CreatePullRequests creates pull requests
@ -917,7 +917,7 @@ func (g *GiteaLocalUploader) CreateReviews(reviews ...*base.Review) error {
}
}
return issues_model.InsertReviews(cms)
return issues_model.InsertReviews(g.ctx, cms)
}
// Rollback when migrating failed, this will rollback all the changes.

View file

@ -46,7 +46,7 @@ func Update(ctx context.Context, pullLimit, pushLimit int) error {
var referenceID int64
if m, ok := bean.(*repo_model.Mirror); ok {
if m.GetRepository() == nil {
if m.GetRepository(ctx) == nil {
log.Error("Disconnected mirror found: %d", m.ID)
return nil
}
@ -90,7 +90,7 @@ func Update(ctx context.Context, pullLimit, pushLimit int) error {
pullMirrorsRequested := 0
if pullLimit != 0 {
if err := repo_model.MirrorsIterate(pullLimit, func(idx int, bean any) error {
if err := repo_model.MirrorsIterate(ctx, pullLimit, func(idx int, bean any) error {
if err := handler(idx, bean); err != nil {
return err
}

View file

@ -31,7 +31,7 @@ const gitShortEmptySha = "0000000"
// UpdateAddress writes new address to Git repository and database
func UpdateAddress(ctx context.Context, m *repo_model.Mirror, addr string) error {
remoteName := m.GetRemoteName()
repoPath := m.GetRepository().RepoPath()
repoPath := m.GetRepository(ctx).RepoPath()
// Remove old remote
_, _, err := git.NewCommand(ctx, "remote", "rm").AddDynamicArguments(remoteName).RunStdString(&git.RunOpts{Dir: repoPath})
if err != nil && !strings.HasPrefix(err.Error(), "exit status 128 - fatal: No such remote ") {
@ -428,7 +428,7 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool {
log.Error("SyncMirrors [repo_id: %v]: unable to GetMirrorByRepoID: %v", repoID, err)
return false
}
_ = m.GetRepository() // force load repository of mirror
_ = m.GetRepository(ctx) // force load repository of mirror
ctx, _, finished := process.GetManager().AddContext(ctx, fmt.Sprintf("Syncing Mirror %s/%s", m.Repo.OwnerName, m.Repo.Name))
defer finished()

View file

@ -336,7 +336,7 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
}
if changed {
// Mark old reviews as stale if diff to mergebase has changed
if err := issues_model.MarkReviewsAsStale(pr.IssueID); err != nil {
if err := issues_model.MarkReviewsAsStale(ctx, pr.IssueID); err != nil {
log.Error("MarkReviewsAsStale: %v", err)
}
@ -351,7 +351,7 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
}
}
}
if err := issues_model.MarkReviewsAsNotStale(pr.IssueID, newCommitID); err != nil {
if err := issues_model.MarkReviewsAsNotStale(ctx, pr.IssueID, newCommitID); err != nil {
log.Error("MarkReviewsAsNotStale: %v", err)
}
divergence, err := GetDiverging(ctx, pr)

View file

@ -84,7 +84,7 @@ func CreateCodeComment(ctx context.Context, doer *user_model.User, gitRepo *git.
if !pendingReview && replyReviewID != 0 {
// It's not part of a review; maybe a reply to a review comment or a single comment.
// Check if there are reviews for that line already; if there are, this is a reply
if existsReview, err = issues_model.ReviewExists(issue, treePath, line); err != nil {
if existsReview, err = issues_model.ReviewExists(ctx, issue, treePath, line); err != nil {
return nil, err
}
}
@ -288,7 +288,7 @@ func SubmitReview(ctx context.Context, doer *user_model.User, gitRepo *git.Repos
}
}
review, comm, err := issues_model.SubmitReview(doer, issue, reviewType, content, commitID, stale, attachmentUUIDs)
review, comm, err := issues_model.SubmitReview(ctx, doer, issue, reviewType, content, commitID, stale, attachmentUUIDs)
if err != nil {
return nil, nil, err
}

View file

@ -52,7 +52,7 @@ func NewNotifier() notify_service.Notifier {
func handler(items ...issueNotificationOpts) []issueNotificationOpts {
for _, opts := range items {
if err := activities_model.CreateOrUpdateIssueNotifications(opts.IssueID, opts.CommentID, opts.NotificationAuthorID, opts.ReceiverID); err != nil {
if err := activities_model.CreateOrUpdateIssueNotifications(db.DefaultContext, opts.IssueID, opts.CommentID, opts.NotificationAuthorID, opts.ReceiverID); err != nil {
log.Error("Was unable to create issue notification: %v", err)
}
}

View file

@ -48,28 +48,28 @@
<li class="milestone-card">
<h3 class="flex-text-block gt-m-0">
{{svg .IconName 16}}
<a class="muted" href="{{.Link}}">{{.Title}}</a>
<a class="muted" href="{{.Link ctx}}">{{.Title}}</a>
</h3>
<div class="milestone-toolbar">
<div class="group">
<div class="flex-text-block">
{{svg "octicon-issue-opened" 14}}
{{ctx.Locale.PrettyNumber .NumOpenIssues}}&nbsp;{{ctx.Locale.Tr "repo.issues.open_title"}}
{{ctx.Locale.PrettyNumber (.NumOpenIssues ctx)}}&nbsp;{{ctx.Locale.Tr "repo.issues.open_title"}}
</div>
<div class="flex-text-block">
{{svg "octicon-check" 14}}
{{ctx.Locale.PrettyNumber .NumClosedIssues}}&nbsp;{{ctx.Locale.Tr "repo.issues.closed_title"}}
{{ctx.Locale.PrettyNumber (.NumClosedIssues ctx)}}&nbsp;{{ctx.Locale.Tr "repo.issues.closed_title"}}
</div>
</div>
{{if and $.CanWriteProjects (not $.Repository.IsArchived)}}
<div class="group">
<a class="flex-text-inline" href="{{.Link}}/edit">{{svg "octicon-pencil" 14}}{{ctx.Locale.Tr "repo.issues.label_edit"}}</a>
<a class="flex-text-inline" href="{{.Link ctx}}/edit">{{svg "octicon-pencil" 14}}{{ctx.Locale.Tr "repo.issues.label_edit"}}</a>
{{if .IsClosed}}
<a class="link-action flex-text-inline" href data-url="{{.Link}}/open">{{svg "octicon-check" 14}}{{ctx.Locale.Tr "repo.projects.open"}}</a>
<a class="link-action flex-text-inline" href data-url="{{.Link ctx}}/open">{{svg "octicon-check" 14}}{{ctx.Locale.Tr "repo.projects.open"}}</a>
{{else}}
<a class="link-action flex-text-inline" href data-url="{{.Link}}/close">{{svg "octicon-skip" 14}}{{ctx.Locale.Tr "repo.projects.close"}}</a>
<a class="link-action flex-text-inline" href data-url="{{.Link ctx}}/close">{{svg "octicon-skip" 14}}{{ctx.Locale.Tr "repo.projects.close"}}</a>
{{end}}
<a class="delete-button flex-text-inline" href="#" data-url="{{.Link}}/delete">{{svg "octicon-trash" 14}}{{ctx.Locale.Tr "repo.issues.label_delete"}}</a>
<a class="delete-button flex-text-inline" href="#" data-url="{{.Link ctx}}/delete">{{svg "octicon-trash" 14}}{{ctx.Locale.Tr "repo.issues.label_delete"}}</a>
</div>
{{end}}
</div>

View file

@ -68,7 +68,7 @@
<div class="project-column-header">
<div class="ui large label project-column-title gt-py-2">
<div class="ui small circular grey label project-column-issue-count">
{{.NumIssues}}
{{.NumIssues ctx}}
</div>
{{.Title}}
</div>

View file

@ -39,7 +39,7 @@
</a>
{{range .Actors}}
<a class="item{{if eq .ID $.CurActor}} active{{end}}" href="{{$.Link}}?workflow={{$.CurWorkflow}}&actor={{.ID}}&status={{$.CurStatus}}">
{{ctx.AvatarUtils.Avatar . 20}} {{.GetDisplayName}}
{{ctx.AvatarUtils.Avatar . 20}} {{.GetDisplayName ctx}}
</a>
{{end}}
</div>

View file

@ -137,12 +137,12 @@
{{if eq .RefAction 3}}<del>{{end}}
<span class="text grey muted-links">
{{template "shared/user/authorlink" .Poster}}
{{ctx.Locale.Tr $refTr (.EventTag|Escape) $createdStr (.RefCommentLink|Escape) $refFrom | Safe}}
{{ctx.Locale.Tr $refTr (.EventTag|Escape) $createdStr ((.RefCommentLink ctx)|Escape) $refFrom | Safe}}
</span>
{{if eq .RefAction 3}}</del>{{end}}
<div class="detail">
<span class="text grey muted-links"><a href="{{.RefIssueLink}}"><b>{{.RefIssueTitle}}</b> {{.RefIssueIdent}}</a></span>
<span class="text grey muted-links"><a href="{{.RefIssueLink ctx}}"><b>{{.RefIssueTitle ctx}}</b> {{.RefIssueIdent ctx}}</a></span>
</div>
</div>
{{else if eq .Type 4}}
@ -468,7 +468,7 @@
{{$resolveDoer := (index $comms 0).ResolveDoer}}
{{$isNotPending := (not (eq (index $comms 0).Review.Type 0))}}
<div class="gt-df gt-ac">
<a href="{{(index $comms 0).CodeCommentLink}}" class="file-comment gt-ml-3 gt-word-break">{{$filename}}</a>
<a href="{{(index $comms 0).CodeCommentLink ctx}}" class="file-comment gt-ml-3 gt-word-break">{{$filename}}</a>
{{if $invalid}}
<span class="ui label basic small gt-ml-3" data-tooltip-content="{{ctx.Locale.Tr "repo.issues.review.outdated_description"}}">
{{ctx.Locale.Tr "repo.issues.review.outdated"}}

View file

@ -173,7 +173,7 @@
{{ctx.Locale.Tr "repo.issues.new.open_projects"}}
</div>
{{range .OpenProjects}}
<a class="item muted sidebar-item-link" data-id="{{.ID}}" data-href="{{.Link}}">
<a class="item muted sidebar-item-link" data-id="{{.ID}}" data-href="{{.Link ctx}}">
{{svg .IconName 18 "gt-mr-3"}}{{.Title}}
</a>
{{end}}
@ -184,7 +184,7 @@
{{ctx.Locale.Tr "repo.issues.new.closed_projects"}}
</div>
{{range .ClosedProjects}}
<a class="item muted sidebar-item-link" data-id="{{.ID}}" data-href="{{.Link}}">
<a class="item muted sidebar-item-link" data-id="{{.ID}}" data-href="{{.Link ctx}}">
{{svg .IconName 18 "gt-mr-3"}}{{.Title}}
</a>
{{end}}
@ -195,7 +195,7 @@
<span class="no-select item {{if .Issue.Project}}gt-hidden{{end}}">{{ctx.Locale.Tr "repo.issues.new.no_projects"}}</span>
<div class="selected">
{{if .Issue.Project}}
<a class="item muted sidebar-item-link" href="{{.Issue.Project.Link}}">
<a class="item muted sidebar-item-link" href="{{.Issue.Project.Link ctx}}">
{{svg .Issue.Project.IconName 18 "gt-mr-3"}}{{.Issue.Project.Title}}
</a>
{{end}}

View file

@ -93,7 +93,7 @@
</a>
{{end}}
{{if .Project}}
<a class="project flex-text-inline" href="{{.Project.Link}}">
<a class="project flex-text-inline" href="{{.Project.Link ctx}}">
{{svg .Project.IconName 14}}{{.Project.Title}}
</a>
{{end}}

View file

@ -7,81 +7,81 @@
<div class="flex-item-main gt-gap-3">
<div>
{{if gt .ActUser.ID 0}}
<a href="{{AppSubUrl}}/{{.GetActUserName | PathEscape}}" title="{{.GetDisplayNameTitle}}">{{.GetDisplayName}}</a>
<a href="{{AppSubUrl}}/{{(.GetActUserName ctx) | PathEscape}}" title="{{.GetDisplayNameTitle ctx}}">{{.GetDisplayName ctx}}</a>
{{else}}
{{.ShortActUserName}}
{{.ShortActUserName ctx}}
{{end}}
{{if .GetOpType.InActions "create_repo"}}
{{ctx.Locale.Tr "action.create_repo" (.GetRepoLink|Escape) (.ShortRepoPath|Escape) | Str2html}}
{{ctx.Locale.Tr "action.create_repo" ((.GetRepoLink ctx)|Escape) ((.ShortRepoPath ctx)|Escape) | Str2html}}
{{else if .GetOpType.InActions "rename_repo"}}
{{ctx.Locale.Tr "action.rename_repo" (.GetContent|Escape) (.GetRepoLink|Escape) (.ShortRepoPath|Escape) | Str2html}}
{{ctx.Locale.Tr "action.rename_repo" (.GetContent|Escape) ((.GetRepoLink ctx)|Escape) ((.ShortRepoPath ctx)|Escape) | Str2html}}
{{else if .GetOpType.InActions "commit_repo"}}
{{if .Content}}
{{ctx.Locale.Tr "action.commit_repo" (.GetRepoLink|Escape) (.GetRefLink|Escape) (Escape .GetBranch) (.ShortRepoPath|Escape) | Str2html}}
{{ctx.Locale.Tr "action.commit_repo" ((.GetRepoLink ctx)|Escape) ((.GetRefLink ctx)|Escape) (Escape .GetBranch) ((.ShortRepoPath ctx)|Escape) | Str2html}}
{{else}}
{{ctx.Locale.Tr "action.create_branch" (.GetRepoLink|Escape) (.GetRefLink|Escape) (Escape .GetBranch) (.ShortRepoPath|Escape) | Str2html}}
{{ctx.Locale.Tr "action.create_branch" ((.GetRepoLink ctx)|Escape) ((.GetRefLink ctx)|Escape) (Escape .GetBranch) ((.ShortRepoPath ctx)|Escape) | Str2html}}
{{end}}
{{else if .GetOpType.InActions "create_issue"}}
{{$index := index .GetIssueInfos 0}}
{{ctx.Locale.Tr "action.create_issue" ((printf "%s/issues/%s" .GetRepoLink $index) |Escape) $index (.ShortRepoPath|Escape) | Str2html}}
{{ctx.Locale.Tr "action.create_issue" ((printf "%s/issues/%s" (.GetRepoLink ctx) $index) |Escape) $index ((.ShortRepoPath ctx)|Escape) | Str2html}}
{{else if .GetOpType.InActions "create_pull_request"}}
{{$index := index .GetIssueInfos 0}}
{{ctx.Locale.Tr "action.create_pull_request" ((printf "%s/pulls/%s" .GetRepoLink $index) |Escape) $index (.ShortRepoPath|Escape) | Str2html}}
{{ctx.Locale.Tr "action.create_pull_request" ((printf "%s/pulls/%s" (.GetRepoLink ctx) $index) |Escape) $index ((.ShortRepoPath ctx)|Escape) | Str2html}}
{{else if .GetOpType.InActions "transfer_repo"}}
{{ctx.Locale.Tr "action.transfer_repo" .GetContent (.GetRepoLink|Escape) (.ShortRepoPath|Escape) | Str2html}}
{{ctx.Locale.Tr "action.transfer_repo" .GetContent ((.GetRepoLink ctx)|Escape) ((.ShortRepoPath ctx)|Escape) | Str2html}}
{{else if .GetOpType.InActions "push_tag"}}
{{ctx.Locale.Tr "action.push_tag" (.GetRepoLink|Escape) (.GetRefLink|Escape) (.GetTag|Escape) (.ShortRepoPath|Escape) | Str2html}}
{{ctx.Locale.Tr "action.push_tag" ((.GetRepoLink ctx)|Escape) ((.GetRefLink ctx)|Escape) (.GetTag|Escape) ((.ShortRepoPath ctx)|Escape) | Str2html}}
{{else if .GetOpType.InActions "comment_issue"}}
{{$index := index .GetIssueInfos 0}}
{{ctx.Locale.Tr "action.comment_issue" ((printf "%s/issues/%s" .GetRepoLink $index) |Escape) $index (.ShortRepoPath|Escape) | Str2html}}
{{ctx.Locale.Tr "action.comment_issue" ((printf "%s/issues/%s" (.GetRepoLink ctx) $index) |Escape) $index ((.ShortRepoPath ctx)|Escape) | Str2html}}
{{else if .GetOpType.InActions "merge_pull_request"}}
{{$index := index .GetIssueInfos 0}}
{{ctx.Locale.Tr "action.merge_pull_request" ((printf "%s/pulls/%s" .GetRepoLink $index) |Escape) $index (.ShortRepoPath|Escape) | Str2html}}
{{ctx.Locale.Tr "action.merge_pull_request" ((printf "%s/pulls/%s" (.GetRepoLink ctx) $index) |Escape) $index ((.ShortRepoPath ctx)|Escape) | Str2html}}
{{else if .GetOpType.InActions "close_issue"}}
{{$index := index .GetIssueInfos 0}}
{{ctx.Locale.Tr "action.close_issue" ((printf "%s/issues/%s" .GetRepoLink $index) |Escape) $index (.ShortRepoPath|Escape) | Str2html}}
{{ctx.Locale.Tr "action.close_issue" ((printf "%s/issues/%s" (.GetRepoLink ctx) $index) |Escape) $index ((.ShortRepoPath ctx)|Escape) | Str2html}}
{{else if .GetOpType.InActions "reopen_issue"}}
{{$index := index .GetIssueInfos 0}}
{{ctx.Locale.Tr "action.reopen_issue" ((printf "%s/issues/%s" .GetRepoLink $index) |Escape) $index (.ShortRepoPath|Escape) | Str2html}}
{{ctx.Locale.Tr "action.reopen_issue" ((printf "%s/issues/%s" (.GetRepoLink ctx) $index) |Escape) $index ((.ShortRepoPath ctx)|Escape) | Str2html}}
{{else if .GetOpType.InActions "close_pull_request"}}
{{$index := index .GetIssueInfos 0}}
{{ctx.Locale.Tr "action.close_pull_request" ((printf "%s/pulls/%s" .GetRepoLink $index) |Escape) $index (.ShortRepoPath|Escape) | Str2html}}
{{ctx.Locale.Tr "action.close_pull_request" ((printf "%s/pulls/%s" (.GetRepoLink ctx) $index) |Escape) $index ((.ShortRepoPath ctx)|Escape) | Str2html}}
{{else if .GetOpType.InActions "reopen_pull_request"}}
{{$index := index .GetIssueInfos 0}}
{{ctx.Locale.Tr "action.reopen_pull_request" ((printf "%s/pulls/%s" .GetRepoLink $index) |Escape) $index (.ShortRepoPath|Escape) | Str2html}}
{{ctx.Locale.Tr "action.reopen_pull_request" ((printf "%s/pulls/%s" (.GetRepoLink ctx) $index) |Escape) $index ((.ShortRepoPath ctx)|Escape) | Str2html}}
{{else if .GetOpType.InActions "delete_tag"}}
{{$index := index .GetIssueInfos 0}}
{{ctx.Locale.Tr "action.delete_tag" (.GetRepoLink|Escape) (.GetTag|Escape) (.ShortRepoPath|Escape) | Str2html}}
{{ctx.Locale.Tr "action.delete_tag" ((.GetRepoLink ctx)|Escape) (.GetTag|Escape) ((.ShortRepoPath ctx)|Escape) | Str2html}}
{{else if .GetOpType.InActions "delete_branch"}}
{{$index := index .GetIssueInfos 0}}
{{ctx.Locale.Tr "action.delete_branch" (.GetRepoLink|Escape) (.GetBranch|Escape) (.ShortRepoPath|Escape) | Str2html}}
{{ctx.Locale.Tr "action.delete_branch" ((.GetRepoLink ctx)|Escape) (.GetBranch|Escape) ((.ShortRepoPath ctx)|Escape) | Str2html}}
{{else if .GetOpType.InActions "mirror_sync_push"}}
{{ctx.Locale.Tr "action.mirror_sync_push" (.GetRepoLink|Escape) (.GetRefLink|Escape) (.GetBranch|Escape) (.ShortRepoPath|Escape) | Str2html}}
{{ctx.Locale.Tr "action.mirror_sync_push" ((.GetRepoLink ctx)|Escape) ((.GetRefLink ctx)|Escape) (.GetBranch|Escape) ((.ShortRepoPath ctx)|Escape) | Str2html}}
{{else if .GetOpType.InActions "mirror_sync_create"}}
{{ctx.Locale.Tr "action.mirror_sync_create" (.GetRepoLink|Escape) (.GetRefLink|Escape) (.GetBranch|Escape) (.ShortRepoPath|Escape) | Str2html}}
{{ctx.Locale.Tr "action.mirror_sync_create" ((.GetRepoLink ctx)|Escape) ((.GetRefLink ctx)|Escape) (.GetBranch|Escape) ((.ShortRepoPath ctx)|Escape) | Str2html}}
{{else if .GetOpType.InActions "mirror_sync_delete"}}
{{ctx.Locale.Tr "action.mirror_sync_delete" (.GetRepoLink|Escape) (.GetBranch|Escape) (.ShortRepoPath|Escape) | Str2html}}
{{ctx.Locale.Tr "action.mirror_sync_delete" ((.GetRepoLink ctx)|Escape) (.GetBranch|Escape) ((.ShortRepoPath ctx)|Escape) | Str2html}}
{{else if .GetOpType.InActions "approve_pull_request"}}
{{$index := index .GetIssueInfos 0}}
{{ctx.Locale.Tr "action.approve_pull_request" ((printf "%s/pulls/%s" .GetRepoLink $index) |Escape) $index (.ShortRepoPath|Escape) | Str2html}}
{{ctx.Locale.Tr "action.approve_pull_request" ((printf "%s/pulls/%s" (.GetRepoLink ctx) $index) |Escape) $index ((.ShortRepoPath ctx)|Escape) | Str2html}}
{{else if .GetOpType.InActions "reject_pull_request"}}
{{$index := index .GetIssueInfos 0}}
{{ctx.Locale.Tr "action.reject_pull_request" ((printf "%s/pulls/%s" .GetRepoLink $index) |Escape) $index (.ShortRepoPath|Escape) | Str2html}}
{{ctx.Locale.Tr "action.reject_pull_request" ((printf "%s/pulls/%s" (.GetRepoLink ctx) $index) |Escape) $index ((.ShortRepoPath ctx)|Escape) | Str2html}}
{{else if .GetOpType.InActions "comment_pull"}}
{{$index := index .GetIssueInfos 0}}
{{ctx.Locale.Tr "action.comment_pull" ((printf "%s/pulls/%s" .GetRepoLink $index) |Escape) $index (.ShortRepoPath|Escape) | Str2html}}
{{ctx.Locale.Tr "action.comment_pull" ((printf "%s/pulls/%s" (.GetRepoLink ctx) $index) |Escape) $index ((.ShortRepoPath ctx)|Escape) | Str2html}}
{{else if .GetOpType.InActions "publish_release"}}
{{$linkText := .Content | RenderEmoji $.Context}}
{{ctx.Locale.Tr "action.publish_release" (.GetRepoLink|Escape) ((printf "%s/releases/tag/%s" .GetRepoLink .GetTag)|Escape) (.ShortRepoPath|Escape) $linkText | Str2html}}
{{ctx.Locale.Tr "action.publish_release" ((.GetRepoLink ctx)|Escape) ((printf "%s/releases/tag/%s" .GetRepoLink .GetTag)|Escape) ((.ShortRepoPath ctx)|Escape) $linkText | Str2html}}
{{else if .GetOpType.InActions "review_dismissed"}}
{{$index := index .GetIssueInfos 0}}
{{$reviewer := index .GetIssueInfos 1}}
{{ctx.Locale.Tr "action.review_dismissed" ((printf "%s/pulls/%s" .GetRepoLink $index) |Escape) $index (.ShortRepoPath|Escape) $reviewer | Str2html}}
{{ctx.Locale.Tr "action.review_dismissed" ((printf "%s/pulls/%s" (.GetRepoLink ctx) $index) |Escape) $index ((.ShortRepoPath ctx)|Escape) $reviewer | Str2html}}
{{end}}
</div>
{{if .GetOpType.InActions "commit_repo" "mirror_sync_push"}}
{{$push := ActionContent2Commits .}}
{{$repoLink := .GetRepoLink}}
{{$repoLink := (.GetRepoLink ctx)}}
{{range $push.Commits}}
{{$commitLink := printf "%s/commit/%s" $repoLink .Sha1}}
<div class="flex-text-block">
@ -100,7 +100,7 @@
{{else if .GetOpType.InActions "create_pull_request"}}
<span class="text truncate issue title">{{index .GetIssueInfos 1 | RenderEmoji $.Context | RenderCodeBlock}}</span>
{{else if .GetOpType.InActions "comment_issue" "approve_pull_request" "reject_pull_request" "comment_pull"}}
<a href="{{.GetCommentLink}}" class="text truncate issue title">{{.GetIssueTitle | RenderEmoji $.Context | RenderCodeBlock}}</a>
<a href="{{.GetCommentLink ctx}}" class="text truncate issue title">{{(.GetIssueTitle ctx) | RenderEmoji $.Context | RenderCodeBlock}}</a>
{{$comment := index .GetIssueInfos 1}}
{{if gt (len $comment) 0}}
<div class="flex-item-body">{{$comment | RenderEmoji $.Context | RenderCodeBlock}}</div>
@ -108,7 +108,7 @@
{{else if .GetOpType.InActions "merge_pull_request"}}
<div class="flex-item-body">{{index .GetIssueInfos 1}}</div>
{{else if .GetOpType.InActions "close_issue" "reopen_issue" "close_pull_request" "reopen_pull_request"}}
<span class="text truncate issue title">{{.GetIssueTitle | RenderEmoji $.Context | RenderCodeBlock}}</span>
<span class="text truncate issue title">{{(.GetIssueTitle ctx) | RenderEmoji $.Context | RenderCodeBlock}}</span>
{{else if .GetOpType.InActions "pull_review_dismissed"}}
<div class="flex-item-body">{{ctx.Locale.Tr "action.review_dismissed_reason"}}</div>
<div class="flex-item-body">{{index .GetIssueInfos 2 | RenderEmoji $.Context}}</div>

View file

@ -43,7 +43,7 @@
{{svg "octicon-repo" 16 "text grey"}}
{{end}}
</div>
<a class="notifications-link gt-df gt-f1 gt-fc silenced" href="{{.Link}}">
<a class="notifications-link gt-df gt-f1 gt-fc silenced" href="{{.Link ctx}}">
<div class="notifications-top-row gt-font-13">
{{.Repository.FullName}} {{if .Issue}}<span class="text light-3">#{{.Issue.Index}}</span>{{end}}
{{if eq .Status 3}}

View file

@ -76,7 +76,7 @@ func TestAPIPullReview(t *testing.T) {
assert.EqualValues(t, "a review from a deleted user", reviewComments[0].Body)
assert.EqualValues(t, comment.ID, reviewComments[0].ID)
assert.EqualValues(t, comment.UpdatedUnix, reviewComments[0].Updated.Unix())
assert.EqualValues(t, comment.HTMLURL(), reviewComments[0].HTMLURL)
assert.EqualValues(t, comment.HTMLURL(db.DefaultContext), reviewComments[0].HTMLURL)
// test CreatePullReview
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/reviews?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, token), &api.CreatePullReviewOptions{