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. // GetActFullName gets the action's user full name.
func (a *Action) GetActFullName() string { func (a *Action) GetActFullName(ctx context.Context) string {
a.LoadActUser(db.DefaultContext) a.LoadActUser(ctx)
return a.ActUser.FullName return a.ActUser.FullName
} }
// GetActUserName gets the action's user name. // GetActUserName gets the action's user name.
func (a *Action) GetActUserName() string { func (a *Action) GetActUserName(ctx context.Context) string {
a.LoadActUser(db.DefaultContext) a.LoadActUser(ctx)
return a.ActUser.Name return a.ActUser.Name
} }
// ShortActUserName gets the action's user name trimmed to max 20 // ShortActUserName gets the action's user name trimmed to max 20
// chars. // chars.
func (a *Action) ShortActUserName() string { func (a *Action) ShortActUserName(ctx context.Context) string {
return base.EllipsisString(a.GetActUserName(), 20) 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. // 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 { if setting.UI.DefaultShowFullName {
trimmedFullName := strings.TrimSpace(a.GetActFullName()) trimmedFullName := strings.TrimSpace(a.GetActFullName(ctx))
if len(trimmedFullName) > 0 { if len(trimmedFullName) > 0 {
return trimmedFullName 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 // 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 { 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. // GetRepoUserName returns the name of the action repository owner.
func (a *Action) GetRepoUserName() string { func (a *Action) GetRepoUserName(ctx context.Context) string {
a.loadRepo(db.DefaultContext) a.loadRepo(ctx)
return a.Repo.OwnerName return a.Repo.OwnerName
} }
// ShortRepoUserName returns the name of the action repository owner // ShortRepoUserName returns the name of the action repository owner
// trimmed to max 20 chars. // trimmed to max 20 chars.
func (a *Action) ShortRepoUserName() string { func (a *Action) ShortRepoUserName(ctx context.Context) string {
return base.EllipsisString(a.GetRepoUserName(), 20) return base.EllipsisString(a.GetRepoUserName(ctx), 20)
} }
// GetRepoName returns the name of the action repository. // GetRepoName returns the name of the action repository.
func (a *Action) GetRepoName() string { func (a *Action) GetRepoName(ctx context.Context) string {
a.loadRepo(db.DefaultContext) a.loadRepo(ctx)
return a.Repo.Name return a.Repo.Name
} }
// ShortRepoName returns the name of the action repository // ShortRepoName returns the name of the action repository
// trimmed to max 33 chars. // trimmed to max 33 chars.
func (a *Action) ShortRepoName() string { func (a *Action) ShortRepoName(ctx context.Context) string {
return base.EllipsisString(a.GetRepoName(), 33) return base.EllipsisString(a.GetRepoName(ctx), 33)
} }
// GetRepoPath returns the virtual path to the action repository. // GetRepoPath returns the virtual path to the action repository.
func (a *Action) GetRepoPath() string { func (a *Action) GetRepoPath(ctx context.Context) string {
return path.Join(a.GetRepoUserName(), a.GetRepoName()) return path.Join(a.GetRepoUserName(ctx), a.GetRepoName(ctx))
} }
// ShortRepoPath returns the virtual path to the action repository // ShortRepoPath returns the virtual path to the action repository
// trimmed to max 20 + 1 + 33 chars. // trimmed to max 20 + 1 + 33 chars.
func (a *Action) ShortRepoPath() string { func (a *Action) ShortRepoPath(ctx context.Context) string {
return path.Join(a.ShortRepoUserName(), a.ShortRepoName()) return path.Join(a.ShortRepoUserName(ctx), a.ShortRepoName(ctx))
} }
// GetRepoLink returns relative link to action repository. // 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 // 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. // GetRepoAbsoluteLink returns the absolute link to action repository.
func (a *Action) GetRepoAbsoluteLink() string { func (a *Action) GetRepoAbsoluteLink(ctx context.Context) string {
return setting.AppURL + url.PathEscape(a.GetRepoUserName()) + "/" + url.PathEscape(a.GetRepoName()) return setting.AppURL + url.PathEscape(a.GetRepoUserName(ctx)) + "/" + url.PathEscape(a.GetRepoName(ctx))
} }
// GetCommentHTMLURL returns link to action comment. // GetCommentHTMLURL returns link to action comment.
func (a *Action) GetCommentHTMLURL() string { func (a *Action) GetCommentHTMLURL(ctx context.Context) string {
return a.getCommentHTMLURL(db.DefaultContext) return a.getCommentHTMLURL(ctx)
} }
func (a *Action) loadComment(ctx context.Context) (err error) { func (a *Action) loadComment(ctx context.Context) (err error) {
@ -309,7 +309,7 @@ func (a *Action) getCommentHTMLURL(ctx context.Context) string {
} }
_ = a.loadComment(ctx) _ = a.loadComment(ctx)
if a.Comment != nil { if a.Comment != nil {
return a.Comment.HTMLURL() return a.Comment.HTMLURL(ctx)
} }
if len(a.GetIssueInfos()) == 0 { if len(a.GetIssueInfos()) == 0 {
return "#" return "#"
@ -334,8 +334,8 @@ func (a *Action) getCommentHTMLURL(ctx context.Context) string {
} }
// GetCommentLink returns link to action comment. // GetCommentLink returns link to action comment.
func (a *Action) GetCommentLink() string { func (a *Action) GetCommentLink(ctx context.Context) string {
return a.getCommentLink(db.DefaultContext) return a.getCommentLink(ctx)
} }
func (a *Action) getCommentLink(ctx context.Context) string { func (a *Action) getCommentLink(ctx context.Context) string {
@ -344,7 +344,7 @@ func (a *Action) getCommentLink(ctx context.Context) string {
} }
_ = a.loadComment(ctx) _ = a.loadComment(ctx)
if a.Comment != nil { if a.Comment != nil {
return a.Comment.Link() return a.Comment.Link(ctx)
} }
if len(a.GetIssueInfos()) == 0 { if len(a.GetIssueInfos()) == 0 {
return "#" return "#"
@ -374,8 +374,8 @@ func (a *Action) GetBranch() string {
} }
// GetRefLink returns the action's ref link. // GetRefLink returns the action's ref link.
func (a *Action) GetRefLink() string { func (a *Action) GetRefLink(ctx context.Context) string {
return git.RefURL(a.GetRepoLink(), a.RefName) return git.RefURL(a.GetRepoLink(ctx), a.RefName)
} }
// GetTag returns the action's repository tag. // GetTag returns the action's repository tag.
@ -399,11 +399,10 @@ func (a *Action) GetIssueInfos() []string {
return strings.SplitN(a.Content, "|", 3) return strings.SplitN(a.Content, "|", 3)
} }
// GetIssueTitle returns the title of first issue associated // GetIssueTitle returns the title of first issue associated with the action.
// with the action. This function will be invoked in template so keep db.DefaultContext here func (a *Action) GetIssueTitle(ctx context.Context) string {
func (a *Action) GetIssueTitle() string {
index, _ := strconv.ParseInt(a.GetIssueInfos()[0], 10, 64) 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 { if err != nil {
log.Error("GetIssueByIndex: %v", err) log.Error("GetIssueByIndex: %v", err)
return "500 when get issue" 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") 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 { if err != nil {
return nil, 0, err return nil, 0, err
} }
@ -473,11 +472,11 @@ func ActivityReadable(user, doer *user_model.User) bool {
doer != nil && (doer.IsAdmin || user.ID == doer.ID) 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() cond := builder.NewCond()
if opts.RequestedTeam != nil && opts.RequestedUser == nil { 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 { if err != nil {
return nil, err return nil, err
} }
@ -564,12 +563,12 @@ func activityQueryCondition(opts GetFeedsOptions) (builder.Cond, error) {
} }
// DeleteOldActions deletes all old actions from database. // 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 { if olderThan <= 0 {
return nil 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 return err
} }
@ -679,8 +678,8 @@ func NotifyWatchers(ctx context.Context, actions ...*Action) error {
} }
// NotifyWatchersActions creates batch of actions for every watcher. // NotifyWatchersActions creates batch of actions for every watcher.
func NotifyWatchersActions(acts []*Action) error { func NotifyWatchersActions(ctx context.Context, acts []*Action) error {
ctx, committer, err := db.TxContext(db.DefaultContext) ctx, committer, err := db.TxContext(ctx)
if err != nil { if err != nil {
return err return err
} }

View File

@ -24,7 +24,7 @@ func TestAction_GetRepoPath(t *testing.T) {
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
action := &activities_model.Action{RepoID: repo.ID} 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) { 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} action := &activities_model.Action{RepoID: repo.ID, CommentID: comment.ID}
setting.AppSubURL = "/suburl" setting.AppSubURL = "/suburl"
expected := path.Join(setting.AppSubURL, owner.Name, repo.Name) expected := path.Join(setting.AppSubURL, owner.Name, repo.Name)
assert.Equal(t, expected, action.GetRepoLink()) assert.Equal(t, expected, action.GetRepoLink(db.DefaultContext))
assert.Equal(t, repo.HTMLURL(), action.GetRepoAbsoluteLink()) assert.Equal(t, repo.HTMLURL(), action.GetRepoAbsoluteLink(db.DefaultContext))
assert.Equal(t, comment.HTMLURL(), action.GetCommentHTMLURL()) assert.Equal(t, comment.HTMLURL(db.DefaultContext), action.GetCommentHTMLURL(db.DefaultContext))
} }
func TestGetFeeds(t *testing.T) { 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 // CreateOrUpdateIssueNotifications creates an issue notification
// for each watcher, or updates it if already exists // for each watcher, or updates it if already exists
// receiverID > 0 just send to receiver, else send to all watcher // receiverID > 0 just send to receiver, else send to all watcher
func CreateOrUpdateIssueNotifications(issueID, commentID, notificationAuthorID, receiverID int64) error { func CreateOrUpdateIssueNotifications(ctx context.Context, issueID, commentID, notificationAuthorID, receiverID int64) error {
ctx, committer, err := db.TxContext(db.DefaultContext) ctx, committer, err := db.TxContext(ctx)
if err != nil { if err != nil {
return err return err
} }
@ -435,21 +435,21 @@ func (n *Notification) loadUser(ctx context.Context) (err error) {
} }
// GetRepo returns the repo of the notification // GetRepo returns the repo of the notification
func (n *Notification) GetRepo() (*repo_model.Repository, error) { func (n *Notification) GetRepo(ctx context.Context) (*repo_model.Repository, error) {
return n.Repository, n.loadRepo(db.DefaultContext) return n.Repository, n.loadRepo(ctx)
} }
// GetIssue returns the issue of the notification // GetIssue returns the issue of the notification
func (n *Notification) GetIssue() (*issues_model.Issue, error) { func (n *Notification) GetIssue(ctx context.Context) (*issues_model.Issue, error) {
return n.Issue, n.loadIssue(db.DefaultContext) return n.Issue, n.loadIssue(ctx)
} }
// HTMLURL formats a URL-string to the notification // HTMLURL formats a URL-string to the notification
func (n *Notification) HTMLURL() string { func (n *Notification) HTMLURL(ctx context.Context) string {
switch n.Source { switch n.Source {
case NotificationSourceIssue, NotificationSourcePullRequest: case NotificationSourceIssue, NotificationSourcePullRequest:
if n.Comment != nil { if n.Comment != nil {
return n.Comment.HTMLURL() return n.Comment.HTMLURL(ctx)
} }
return n.Issue.HTMLURL() return n.Issue.HTMLURL()
case NotificationSourceCommit: case NotificationSourceCommit:
@ -461,11 +461,11 @@ func (n *Notification) HTMLURL() string {
} }
// Link formats a relative URL-string to the notification // 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 { switch n.Source {
case NotificationSourceIssue, NotificationSourcePullRequest: case NotificationSourceIssue, NotificationSourcePullRequest:
if n.Comment != nil { if n.Comment != nil {
return n.Comment.Link() return n.Comment.Link(ctx)
} }
return n.Issue.Link() return n.Issue.Link()
case NotificationSourceCommit: case NotificationSourceCommit:
@ -733,12 +733,12 @@ type UserIDCount struct {
} }
// GetUIDsAndNotificationCounts between the two provided times // 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 ` + sql := `SELECT user_id, count(*) AS count FROM notification ` +
`WHERE user_id IN (SELECT user_id FROM notification WHERE updated_unix >= ? AND ` + `WHERE user_id IN (SELECT user_id FROM notification WHERE updated_unix >= ? AND ` +
`updated_unix < ?) AND status = ? GROUP BY user_id` `updated_unix < ?) AND status = ? GROUP BY user_id`
var res []UserIDCount 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. // 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()) assert.NoError(t, unittest.PrepareTestDatabase())
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1}) 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 // 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}) 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) { func TestNotification_GetRepo(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase()) assert.NoError(t, unittest.PrepareTestDatabase())
notf := unittest.AssertExistsAndLoadBean(t, &activities_model.Notification{RepoID: 1}) notf := unittest.AssertExistsAndLoadBean(t, &activities_model.Notification{RepoID: 1})
repo, err := notf.GetRepo() repo, err := notf.GetRepo(db.DefaultContext)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, repo, notf.Repository) assert.Equal(t, repo, notf.Repository)
assert.EqualValues(t, notf.RepoID, repo.ID) assert.EqualValues(t, notf.RepoID, repo.ID)
@ -59,7 +59,7 @@ func TestNotification_GetRepo(t *testing.T) {
func TestNotification_GetIssue(t *testing.T) { func TestNotification_GetIssue(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase()) assert.NoError(t, unittest.PrepareTestDatabase())
notf := unittest.AssertExistsAndLoadBean(t, &activities_model.Notification{RepoID: 1}) notf := unittest.AssertExistsAndLoadBean(t, &activities_model.Notification{RepoID: 1})
issue, err := notf.GetIssue() issue, err := notf.GetIssue(db.DefaultContext)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, issue, notf.Issue) assert.Equal(t, issue, notf.Issue)
assert.EqualValues(t, notf.IssueID, issue.ID) 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 groupByName = groupBy
} }
cond, err := activityQueryCondition(GetFeedsOptions{ cond, err := activityQueryCondition(ctx, GetFeedsOptions{
RequestedUser: user, RequestedUser: user,
RequestedTeam: team, RequestedTeam: team,
Actor: doer, Actor: doer,

View File

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

View File

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

View File

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

View File

@ -89,7 +89,7 @@ func TestMigrate_InsertIssueComments(t *testing.T) {
Reactions: []*issues_model.Reaction{reaction}, 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) assert.NoError(t, err)
issueModified := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1}) 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, Title: title,
Content: content, Content: content,
} }
err := issues_model.NewIssue(repo, &issue, nil, nil) err := issues_model.NewIssue(db.DefaultContext, repo, &issue, nil, nil)
assert.NoError(t, err) assert.NoError(t, err)
has, err := db.GetEngine(db.DefaultContext).ID(issue.ID).Get(&newIssue) 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. // ChangeIssueRef changes the branch of this issue, as the given user.
func ChangeIssueRef(issue *Issue, doer *user_model.User, oldRef string) (err error) { func ChangeIssueRef(ctx context.Context, issue *Issue, doer *user_model.User, oldRef string) (err error) {
ctx, committer, err := db.TxContext(db.DefaultContext) ctx, committer, err := db.TxContext(ctx)
if err != nil { if err != nil {
return err return err
} }
@ -215,8 +215,8 @@ func AddDeletePRBranchComment(ctx context.Context, doer *user_model.User, repo *
} }
// UpdateIssueAttachments update attachments by UUIDs for the issue // UpdateIssueAttachments update attachments by UUIDs for the issue
func UpdateIssueAttachments(issueID int64, uuids []string) (err error) { func UpdateIssueAttachments(ctx context.Context, issueID int64, uuids []string) (err error) {
ctx, committer, err := db.TxContext(db.DefaultContext) ctx, committer, err := db.TxContext(ctx)
if err != nil { if err != nil {
return err return err
} }
@ -235,8 +235,8 @@ func UpdateIssueAttachments(issueID int64, uuids []string) (err error) {
} }
// ChangeIssueContent changes issue content, as the given user. // ChangeIssueContent changes issue content, as the given user.
func ChangeIssueContent(issue *Issue, doer *user_model.User, content string) (err error) { func ChangeIssueContent(ctx context.Context, issue *Issue, doer *user_model.User, content string) (err error) {
ctx, committer, err := db.TxContext(db.DefaultContext) ctx, committer, err := db.TxContext(ctx)
if err != nil { if err != nil {
return err 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. // NewIssue creates new issue with labels for repository.
func NewIssue(repo *repo_model.Repository, issue *Issue, labelIDs []int64, uuids []string) (err error) { func NewIssue(ctx context.Context, repo *repo_model.Repository, issue *Issue, labelIDs []int64, uuids []string) (err error) {
ctx, committer, err := db.TxContext(db.DefaultContext) ctx, committer, err := db.TxContext(ctx)
if err != nil { if err != nil {
return err return err
} }
@ -432,8 +432,8 @@ func UpdateIssueMentions(ctx context.Context, issueID int64, mentions []*user_mo
// UpdateIssueByAPI updates all allowed fields of given issue. // UpdateIssueByAPI updates all allowed fields of given issue.
// If the issue status is changed a statusChangeComment is returned // If the issue status is changed a statusChangeComment is returned
// similarly if the title is changed the titleChanged bool is set to true // 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) { func UpdateIssueByAPI(ctx context.Context, issue *Issue, doer *user_model.User) (statusChangeComment *Comment, titleChanged bool, err error) {
ctx, committer, err := db.TxContext(db.DefaultContext) ctx, committer, err := db.TxContext(ctx)
if err != nil { if err != nil {
return nil, false, err 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. // 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 the deadline hasn't changed do nothing
if issue.DeadlineUnix == deadlineUnix { if issue.DeadlineUnix == deadlineUnix {
return nil return nil
} }
ctx, committer, err := db.TxContext(db.DefaultContext) ctx, committer, err := db.TxContext(ctx)
if err != nil { if err != nil {
return err 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 // UpdateIssuesMigrationsByType updates all migrated repositories' issues from gitServiceType to replace originalAuthorID to posterID
func UpdateIssuesMigrationsByType(gitServiceType api.GitServiceType, originalAuthorID string, posterID int64) error { func UpdateIssuesMigrationsByType(ctx context.Context, gitServiceType api.GitServiceType, originalAuthorID string, posterID int64) error {
_, err := db.GetEngine(db.DefaultContext).Table("issue"). _, err := db.GetEngine(ctx).Table("issue").
Where("repo_id IN (SELECT id FROM repository WHERE original_service_type = ?)", gitServiceType). Where("repo_id IN (SELECT id FROM repository WHERE original_service_type = ?)", gitServiceType).
And("original_author_id = ?", originalAuthorID). And("original_author_id = ?", originalAuthorID).
Update(map[string]any{ 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 // UpdateReactionsMigrationsByType updates all migrated repositories' reactions from gitServiceType to replace originalAuthorID to posterID
func UpdateReactionsMigrationsByType(gitServiceType api.GitServiceType, originalAuthorID string, userID int64) error { func UpdateReactionsMigrationsByType(ctx context.Context, gitServiceType api.GitServiceType, originalAuthorID string, userID int64) error {
_, err := db.GetEngine(db.DefaultContext).Table("reaction"). _, err := db.GetEngine(ctx).Table("reaction").
Where("original_author_id = ?", originalAuthorID). Where("original_author_id = ?", originalAuthorID).
And(migratedIssueCond(gitServiceType)). And(migratedIssueCond(gitServiceType)).
Update(map[string]any{ Update(map[string]any{
@ -809,7 +809,7 @@ func DeleteOrphanedIssues(ctx context.Context) error {
// Remove issue attachment files. // Remove issue attachment files.
for i := range attachmentPaths { 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 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 // 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 { if c.RefComment != nil {
return nil return nil
} }
c.RefComment, err = GetCommentByID(db.DefaultContext, c.RefCommentID) c.RefComment, err = GetCommentByID(ctx, c.RefCommentID)
return err return err
} }
// LoadRefIssue loads comment that created this reference from database // 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 { if c.RefIssue != nil {
return nil return nil
} }
c.RefIssue, err = GetIssueByID(db.DefaultContext, c.RefIssueID) c.RefIssue, err = GetIssueByID(ctx, c.RefIssueID)
if err == nil { if err == nil {
err = c.RefIssue.LoadRepo(db.DefaultContext) err = c.RefIssue.LoadRepo(ctx)
} }
return err return err
} }
@ -278,21 +278,21 @@ func CommentTypeIsRef(t CommentType) bool {
} }
// RefCommentLink returns the relative URL for the comment that created this reference // 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 // Edge case for when the reference is inside the title or the description of the referring issue
if c.RefCommentID == 0 { 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) log.Error("LoadRefComment(%d): %v", c.RefCommentID, err)
return "" return ""
} }
return c.RefComment.Link() return c.RefComment.Link(ctx)
} }
// RefIssueLink returns the relative URL of the issue where this reference was created // RefIssueLink returns the relative URL of the issue where this reference was created
func (c *Comment) RefIssueLink() string { func (c *Comment) RefIssueLink(ctx context.Context) string {
if err := c.LoadRefIssue(); err != nil { // Silently dropping errors :unamused: if err := c.LoadRefIssue(ctx); err != nil { // Silently dropping errors :unamused:
log.Error("LoadRefIssue(%d): %v", c.RefCommentID, err) log.Error("LoadRefIssue(%d): %v", c.RefCommentID, err)
return "" return ""
} }
@ -300,8 +300,8 @@ func (c *Comment) RefIssueLink() string {
} }
// RefIssueTitle returns the title of the issue where this reference was created // RefIssueTitle returns the title of the issue where this reference was created
func (c *Comment) RefIssueTitle() string { func (c *Comment) RefIssueTitle(ctx context.Context) string {
if err := c.LoadRefIssue(); err != nil { // Silently dropping errors :unamused: if err := c.LoadRefIssue(ctx); err != nil { // Silently dropping errors :unamused:
log.Error("LoadRefIssue(%d): %v", c.RefCommentID, err) log.Error("LoadRefIssue(%d): %v", c.RefCommentID, err)
return "" 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 // RefIssueIdent returns the user friendly identity (e.g. "#1234") of the issue where this reference was created
func (c *Comment) RefIssueIdent() string { func (c *Comment) RefIssueIdent(ctx context.Context) string {
if err := c.LoadRefIssue(); err != nil { // Silently dropping errors :unamused: if err := c.LoadRefIssue(ctx); err != nil { // Silently dropping errors :unamused:
log.Error("LoadRefIssue(%d): %v", c.RefCommentID, err) log.Error("LoadRefIssue(%d): %v", c.RefCommentID, err)
return "" 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 // 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) { func ReviewExists(ctx context.Context, 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}) return db.GetEngine(ctx).Cols("id").Exist(&Comment{IssueID: issue.ID, TreePath: treePath, Line: line, Type: CommentTypeCode})
} }
// ContentEmptyErr represents an content empty error // 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 // 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) { 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(db.DefaultContext) ctx, committer, err := db.TxContext(ctx)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -494,15 +494,15 @@ func GetTeamReviewerByIssueIDAndTeamID(ctx context.Context, issueID, teamID int6
} }
// MarkReviewsAsStale marks existing reviews as stale // MarkReviewsAsStale marks existing reviews as stale
func MarkReviewsAsStale(issueID int64) (err error) { func MarkReviewsAsStale(ctx context.Context, issueID int64) (err error) {
_, err = db.GetEngine(db.DefaultContext).Exec("UPDATE `review` SET stale=? WHERE issue_id=?", true, issueID) _, err = db.GetEngine(ctx).Exec("UPDATE `review` SET stale=? WHERE issue_id=?", true, issueID)
return err return err
} }
// MarkReviewsAsNotStale marks existing reviews as not stale for a giving commit SHA // MarkReviewsAsNotStale marks existing reviews as not stale for a giving commit SHA
func MarkReviewsAsNotStale(issueID int64, commitID string) (err error) { func MarkReviewsAsNotStale(ctx context.Context, 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) _, err = db.GetEngine(ctx).Exec("UPDATE `review` SET stale=? WHERE issue_id=? AND commit_id=?", false, issueID, commitID)
return err return err
} }
@ -525,8 +525,8 @@ func DismissReview(ctx context.Context, review *Review, isDismiss bool) (err err
} }
// InsertReviews inserts review and review comments // InsertReviews inserts review and review comments
func InsertReviews(reviews []*Review) error { func InsertReviews(ctx context.Context, reviews []*Review) error {
ctx, committer, err := db.TxContext(db.DefaultContext) ctx, committer, err := db.TxContext(ctx)
if err != nil { if err != nil {
return err 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 // 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 { if comment.Type != CommentTypeCode {
return nil return nil
} }
@ -813,7 +813,7 @@ func MarkConversation(comment *Comment, doer *user_model.User, isResolve bool) (
return nil 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 return err
} }
} else { } else {
@ -821,7 +821,7 @@ func MarkConversation(comment *Comment, doer *user_model.User, isResolve bool) (
return nil 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 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 // CanMarkConversation Add or remove Conversation mark for a code comment permission check
// the PR writer , offfcial reviewer and poster can do it // 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 { if doer == nil || issue == nil {
return false, fmt.Errorf("issue or doer is nil") return false, fmt.Errorf("issue or doer is nil")
} }
if doer.ID != issue.PosterID { if doer.ID != issue.PosterID {
if err = issue.LoadRepo(db.DefaultContext); err != nil { if err = issue.LoadRepo(ctx); err != nil {
return false, err 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 { if err != nil {
return false, err return false, err
} }
permResult = p.CanAccess(perm.AccessModeWrite, unit.TypePullRequests) permResult = p.CanAccess(perm.AccessModeWrite, unit.TypePullRequests)
if !permResult { if !permResult {
if permResult, err = IsOfficialReviewer(db.DefaultContext, issue, doer); err != nil { if permResult, err = IsOfficialReviewer(ctx, issue, doer); err != nil {
return false, err 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 // DeleteReview delete a review and it's code comments
func DeleteReview(r *Review) error { func DeleteReview(ctx context.Context, r *Review) error {
ctx, committer, err := db.TxContext(db.DefaultContext) ctx, committer, err := db.TxContext(ctx)
if err != nil { if err != nil {
return err return err
} }
@ -912,7 +912,7 @@ func DeleteReview(r *Review) error {
} }
// GetCodeCommentsCount return count of CodeComments a Review has // GetCodeCommentsCount return count of CodeComments a Review has
func (r *Review) GetCodeCommentsCount() int { func (r *Review) GetCodeCommentsCount(ctx context.Context) int {
opts := FindCommentsOptions{ opts := FindCommentsOptions{
Type: CommentTypeCode, Type: CommentTypeCode,
IssueID: r.IssueID, IssueID: r.IssueID,
@ -923,7 +923,7 @@ func (r *Review) GetCodeCommentsCount() int {
conds = conds.And(builder.Eq{"invalidated": false}) 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 { if err != nil {
return 0 return 0
} }
@ -931,18 +931,18 @@ func (r *Review) GetCodeCommentsCount() int {
} }
// HTMLURL formats a URL-string to the related review issue-comment // 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{ opts := FindCommentsOptions{
Type: CommentTypeReview, Type: CommentTypeReview,
IssueID: r.IssueID, IssueID: r.IssueID,
ReviewID: r.ID, ReviewID: r.ID,
} }
comment := new(Comment) 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 { if err != nil || !has {
return "" return ""
} }
return comment.HTMLURL() return comment.HTMLURL(ctx)
} }
// RemapExternalUser ExternalUserRemappable interface // RemapExternalUser ExternalUserRemappable interface
@ -963,8 +963,8 @@ func (r *Review) GetExternalName() string { return r.OriginalAuthor }
func (r *Review) GetExternalID() int64 { return r.OriginalAuthorID } func (r *Review) GetExternalID() int64 { return r.OriginalAuthorID }
// UpdateReviewsMigrationsByType updates reviews' migrations information via given git service type and original id and poster id // 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 { func UpdateReviewsMigrationsByType(ctx context.Context, tp structs.GitServiceType, originalAuthorID string, posterID int64) error {
_, err := db.GetEngine(db.DefaultContext).Table("review"). _, err := db.GetEngine(ctx).Table("review").
Where("original_author_id = ?", originalAuthorID). Where("original_author_id = ?", originalAuthorID).
And(migratedIssueCond(tp)). And(migratedIssueCond(tp)).
Update(map[string]any{ Update(map[string]any{

View File

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

View File

@ -69,8 +69,8 @@ func (Board) TableName() string {
} }
// NumIssues return counter of all issues assigned to the board // NumIssues return counter of all issues assigned to the board
func (b *Board) NumIssues() int { func (b *Board) NumIssues(ctx context.Context) int {
c, err := db.GetEngine(db.DefaultContext).Table("project_issue"). c, err := db.GetEngine(ctx).Table("project_issue").
Where("project_id=?", b.ProjectID). Where("project_id=?", b.ProjectID).
And("project_board_id=?", b.ID). And("project_board_id=?", b.ID).
GroupBy("issue_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 // 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) { if len(board.Color) != 0 && !BoardColorPattern.MatchString(board.Color) {
return fmt.Errorf("bad color code: %s", 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 return err
} }
// DeleteBoardByID removes all issues references to the project board. // DeleteBoardByID removes all issues references to the project board.
func DeleteBoardByID(boardID int64) error { func DeleteBoardByID(ctx context.Context, boardID int64) error {
ctx, committer, err := db.TxContext(db.DefaultContext) ctx, committer, err := db.TxContext(ctx)
if err != nil { if err != nil {
return err 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 // SetDefaultBoard represents a board for issues not assigned to one
// if boardID is 0 unset default // if boardID is 0 unset default
func SetDefaultBoard(projectID, boardID int64) error { func SetDefaultBoard(ctx context.Context, projectID, boardID int64) error {
_, err := db.GetEngine(db.DefaultContext).Where(builder.Eq{ _, err := db.GetEngine(ctx).Where(builder.Eq{
"project_id": projectID, "project_id": projectID,
"`default`": true, "`default`": true,
}).Cols("`default`").Update(&Board{Default: false}) }).Cols("`default`").Update(&Board{Default: false})
@ -275,7 +275,7 @@ func SetDefaultBoard(projectID, boardID int64) error {
} }
if boardID > 0 { 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}) Cols("`default`").Update(&Board{Default: true})
} }
@ -283,9 +283,9 @@ func SetDefaultBoard(projectID, boardID int64) error {
} }
// UpdateBoardSorting update project board sorting // UpdateBoardSorting update project board sorting
func UpdateBoardSorting(bs BoardList) error { func UpdateBoardSorting(ctx context.Context, bs BoardList) error {
for i := range bs { for i := range bs {
_, err := db.GetEngine(db.DefaultContext).ID(bs[i].ID).Cols( _, err := db.GetEngine(ctx).ID(bs[i].ID).Cols(
"sorting", "sorting",
).Update(bs[i]) ).Update(bs[i])
if err != nil { 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 // NumIssues return counter of all issues assigned to a project
func (p *Project) NumIssues() int { func (p *Project) NumIssues(ctx context.Context) int {
c, err := db.GetEngine(db.DefaultContext).Table("project_issue"). c, err := db.GetEngine(ctx).Table("project_issue").
Where("project_id=?", p.ID). Where("project_id=?", p.ID).
GroupBy("issue_id"). GroupBy("issue_id").
Cols("issue_id"). Cols("issue_id").
@ -48,8 +48,8 @@ func (p *Project) NumIssues() int {
} }
// NumClosedIssues return counter of closed issues assigned to a project // NumClosedIssues return counter of closed issues assigned to a project
func (p *Project) NumClosedIssues() int { func (p *Project) NumClosedIssues(ctx context.Context) int {
c, err := db.GetEngine(db.DefaultContext).Table("project_issue"). c, err := db.GetEngine(ctx).Table("project_issue").
Join("INNER", "issue", "project_issue.issue_id=issue.id"). Join("INNER", "issue", "project_issue.issue_id=issue.id").
Where("project_issue.project_id=? AND issue.is_closed=?", p.ID, true). Where("project_issue.project_id=? AND issue.is_closed=?", p.ID, true).
Cols("issue_id"). Cols("issue_id").
@ -62,8 +62,8 @@ func (p *Project) NumClosedIssues() int {
} }
// NumOpenIssues return counter of open issues assigned to a project // NumOpenIssues return counter of open issues assigned to a project
func (p *Project) NumOpenIssues() int { func (p *Project) NumOpenIssues(ctx context.Context) int {
c, err := db.GetEngine(db.DefaultContext).Table("project_issue"). c, err := db.GetEngine(ctx).Table("project_issue").
Join("INNER", "issue", "project_issue.issue_id=issue.id"). Join("INNER", "issue", "project_issue.issue_id=issue.id").
Where("project_issue.project_id=? AND issue.is_closed=?", p.ID, false). Where("project_issue.project_id=? AND issue.is_closed=?", p.ID, false).
Cols("issue_id"). 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 // MoveIssuesOnProjectBoard moves or keeps issues in a column and sorts them inside that column
func MoveIssuesOnProjectBoard(board *Board, sortedIssueIDs map[int64]int64) error { func MoveIssuesOnProjectBoard(ctx context.Context, board *Board, sortedIssueIDs map[int64]int64) error {
return db.WithTx(db.DefaultContext, func(ctx context.Context) error { return db.WithTx(ctx, func(ctx context.Context) error {
sess := db.GetEngine(ctx) sess := db.GetEngine(ctx)
issueIDs := make([]int64, 0, len(sortedIssueIDs)) 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. // Link returns the project's relative URL.
func (p *Project) Link() string { func (p *Project) Link(ctx context.Context) string {
if p.OwnerID > 0 { if p.OwnerID > 0 {
err := p.LoadOwner(db.DefaultContext) err := p.LoadOwner(ctx)
if err != nil { if err != nil {
log.Error("LoadOwner: %v", err) log.Error("LoadOwner: %v", err)
return "" return ""
@ -134,7 +134,7 @@ func (p *Project) Link() string {
return fmt.Sprintf("%s/-/projects/%d", p.Owner.HomeLink(), p.ID) return fmt.Sprintf("%s/-/projects/%d", p.Owner.HomeLink(), p.ID)
} }
if p.RepoID > 0 { if p.RepoID > 0 {
err := p.LoadRepo(db.DefaultContext) err := p.LoadRepo(ctx)
if err != nil { if err != nil {
log.Error("LoadRepo: %v", err) log.Error("LoadRepo: %v", err)
return "" return ""
@ -261,7 +261,7 @@ func FindProjects(ctx context.Context, opts SearchOptions) ([]*Project, int64, e
} }
// NewProject creates a new Project // NewProject creates a new Project
func NewProject(p *Project) error { func NewProject(ctx context.Context, p *Project) error {
if !IsBoardTypeValid(p.BoardType) { if !IsBoardTypeValid(p.BoardType) {
p.BoardType = BoardTypeNone p.BoardType = BoardTypeNone
} }
@ -274,7 +274,7 @@ func NewProject(p *Project) error {
return util.NewInvalidArgumentErrorf("project type is not valid") return util.NewInvalidArgumentErrorf("project type is not valid")
} }
ctx, committer, err := db.TxContext(db.DefaultContext) ctx, committer, err := db.TxContext(ctx)
if err != nil { if err != nil {
return err return err
} }
@ -348,8 +348,8 @@ func updateRepositoryProjectCount(ctx context.Context, repoID int64) error {
} }
// ChangeProjectStatusByRepoIDAndID toggles a project between opened and closed // ChangeProjectStatusByRepoIDAndID toggles a project between opened and closed
func ChangeProjectStatusByRepoIDAndID(repoID, projectID int64, isClosed bool) error { func ChangeProjectStatusByRepoIDAndID(ctx context.Context, repoID, projectID int64, isClosed bool) error {
ctx, committer, err := db.TxContext(db.DefaultContext) ctx, committer, err := db.TxContext(ctx)
if err != nil { if err != nil {
return err return err
} }
@ -372,8 +372,8 @@ func ChangeProjectStatusByRepoIDAndID(repoID, projectID int64, isClosed bool) er
} }
// ChangeProjectStatus toggle a project between opened and closed // ChangeProjectStatus toggle a project between opened and closed
func ChangeProjectStatus(p *Project, isClosed bool) error { func ChangeProjectStatus(ctx context.Context, p *Project, isClosed bool) error {
ctx, committer, err := db.TxContext(db.DefaultContext) ctx, committer, err := db.TxContext(ctx)
if err != nil { if err != nil {
return err return err
} }

View File

@ -60,7 +60,7 @@ func TestProject(t *testing.T) {
CreatorID: 2, CreatorID: 2,
} }
assert.NoError(t, NewProject(project)) assert.NoError(t, NewProject(db.DefaultContext, project))
_, err := GetProjectByID(db.DefaultContext, project.ID) _, err := GetProjectByID(db.DefaultContext, project.ID)
assert.NoError(t, err) assert.NoError(t, err)
@ -74,7 +74,7 @@ func TestProject(t *testing.T) {
assert.Equal(t, project.Title, projectFromDB.Title) 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 // Retrieve from DB afresh to check if it is truly closed
projectFromDB, err = GetProjectByID(db.DefaultContext, project.ID) 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 // CountCollaborators returns total number of collaborators for a repository
func CountCollaborators(repoID int64) (int64, error) { func CountCollaborators(ctx context.Context, repoID int64) (int64, error) {
return db.GetEngine(db.DefaultContext).Where("repo_id = ? ", repoID).Count(&Collaboration{}) return db.GetEngine(ctx).Where("repo_id = ? ", repoID).Count(&Collaboration{})
} }
// GetCollaboration get collaboration for a repository id with a user id // 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 // 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 { if repo.OwnerID == userID {
return true, nil 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"). Join("INNER", "team_unit", "team_unit.team_id = team_user.team_id").
Where("team_repo.repo_id = ?", repo.ID). Where("team_repo.repo_id = ?", repo.ID).
And("team_unit.`type` = ?", unit.TypeCode). And("team_unit.`type` = ?", unit.TypeCode).
@ -154,5 +154,5 @@ func IsOwnerMemberCollaborator(repo *Repository, userID int64) (bool, error) {
return true, nil 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()) assert.NoError(t, unittest.PrepareTestDatabase())
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4}) 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.NoError(t, err)
assert.EqualValues(t, 2, count) assert.EqualValues(t, 2, count)
repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 22}) 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.NoError(t, err)
assert.EqualValues(t, 2, count) assert.EqualValues(t, 2, count)
// Non-existent repository. // Non-existent repository.
count, err = repo_model.CountCollaborators(unittest.NonexistentID) count, err = repo_model.CountCollaborators(db.DefaultContext, unittest.NonexistentID)
assert.NoError(t, err) assert.NoError(t, err)
assert.EqualValues(t, 0, count) assert.EqualValues(t, 0, count)
} }
@ -110,31 +110,31 @@ func TestRepository_IsOwnerMemberCollaborator(t *testing.T) {
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3}) repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
// Organisation owner. // Organisation owner.
actual, err := repo_model.IsOwnerMemberCollaborator(repo1, 2) actual, err := repo_model.IsOwnerMemberCollaborator(db.DefaultContext, repo1, 2)
assert.NoError(t, err) assert.NoError(t, err)
assert.True(t, actual) assert.True(t, actual)
// Team member. // Team member.
actual, err = repo_model.IsOwnerMemberCollaborator(repo1, 4) actual, err = repo_model.IsOwnerMemberCollaborator(db.DefaultContext, repo1, 4)
assert.NoError(t, err) assert.NoError(t, err)
assert.True(t, actual) assert.True(t, actual)
// Normal user. // Normal user.
actual, err = repo_model.IsOwnerMemberCollaborator(repo1, 1) actual, err = repo_model.IsOwnerMemberCollaborator(db.DefaultContext, repo1, 1)
assert.NoError(t, err) assert.NoError(t, err)
assert.False(t, actual) assert.False(t, actual)
repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4}) repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4})
// Collaborator. // Collaborator.
actual, err = repo_model.IsOwnerMemberCollaborator(repo2, 4) actual, err = repo_model.IsOwnerMemberCollaborator(db.DefaultContext, repo2, 4)
assert.NoError(t, err) assert.NoError(t, err)
assert.True(t, actual) assert.True(t, actual)
repo3 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 15}) repo3 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 15})
// Repository owner. // Repository owner.
actual, err = repo_model.IsOwnerMemberCollaborator(repo3, 2) actual, err = repo_model.IsOwnerMemberCollaborator(db.DefaultContext, repo3, 2)
assert.NoError(t, err) assert.NoError(t, err)
assert.True(t, actual) assert.True(t, actual)
} }

View File

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

View File

@ -71,7 +71,7 @@ loop:
now := timeutil.TimeStampNow().Add(-2) now := timeutil.TimeStampNow().Add(-2)
uidCounts, err := activities_model.GetUIDsAndNotificationCounts(then, now) uidCounts, err := activities_model.GetUIDsAndNotificationCounts(ctx, then, now)
if err != nil { if err != nil {
log.Error("Unable to get UIDcounts: %v", err) 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) c.Verification = asymkey_model.ParseCommitWithSignature(ctx, c.Commit)
_ = asymkey_model.CalculateTrustStatus(c.Verification, repository.GetTrustModel(), func(user *user_model.User) (bool, error) { _ = 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) }, &keyMap)
statuses, _, err := git_model.GetLatestCommitStatus(ctx, repository.ID, c.Commit.ID.String(), db.ListOptions{}) 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 // Actioner describes an action
type Actioner interface { type Actioner interface {
GetOpType() activities_model.ActionType GetOpType() activities_model.ActionType
GetActUserName() string GetActUserName(ctx context.Context) string
GetRepoUserName() string GetRepoUserName(ctx context.Context) string
GetRepoName() string GetRepoName(ctx context.Context) string
GetRepoPath() string GetRepoPath(ctx context.Context) string
GetRepoLink() string GetRepoLink(ctx context.Context) string
GetBranch() string GetBranch() string
GetContent() string GetContent() string
GetCreate() time.Time 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})) usersActiveHalfyear := int(user_model.CountUsers(ctx, &user_model.CountUserFilter{LastLoginSince: &timeHaveYearAgo}))
allIssues, _ := issues_model.CountIssues(ctx, &issues_model.IssuesOptions{}) 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{ nodeInfoUsage = structs.NodeInfoUsage{
Users: structs.NodeInfoUsageUsers{ Users: structs.NodeInfoUsageUsers{

View File

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

View File

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

View File

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

View File

@ -53,7 +53,7 @@ func ListCollaborators(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$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 { if err != nil {
ctx.InternalServerError(err) ctx.InternalServerError(err)
return return

View File

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

View File

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

View File

@ -524,7 +524,7 @@ func EditPullRequest(ctx *context.APIContext) {
deadlineUnix = timeutil.TimeStamp(deadline.Unix()) 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) ctx.Error(http.StatusInternalServerError, "UpdateIssueDeadline", err)
return return
} }
@ -591,7 +591,7 @@ func EditPullRequest(ctx *context.APIContext) {
} }
issue.IsClosed = api.StateClosed == api.StateType(*form.State) 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 err != nil {
if issues_model.IsErrDependenciesLeft(err) { if issues_model.IsErrDependenciesLeft(err) {
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this pull request because it still has open dependencies") 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 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)) ctx.Error(http.StatusInternalServerError, "DeleteReview", fmt.Errorf("can not delete ReviewID: %d", review.ID))
return return
} }
@ -713,7 +713,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
} }
if comment != nil && isAdd { if comment != nil && isAdd {
if err = comment.LoadReview(); err != nil { if err = comment.LoadReview(ctx); err != nil {
ctx.ServerError("ReviewRequest", err) ctx.ServerError("ReviewRequest", err)
return return
} }
@ -757,7 +757,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
} }
if comment != nil && isAdd { if comment != nil && isAdd {
if err = comment.LoadReview(); err != nil { if err = comment.LoadReview(ctx); err != nil {
ctx.ServerError("ReviewRequest", err) ctx.ServerError("ReviewRequest", err)
return return
} }

View File

@ -23,28 +23,28 @@ import (
"github.com/gorilla/feeds" "github.com/gorilla/feeds"
) )
func toBranchLink(act *activities_model.Action) string { func toBranchLink(ctx *context.Context, act *activities_model.Action) string {
return act.GetRepoAbsoluteLink() + "/src/branch/" + util.PathEscapeSegments(act.GetBranch()) return act.GetRepoAbsoluteLink(ctx) + "/src/branch/" + util.PathEscapeSegments(act.GetBranch())
} }
func toTagLink(act *activities_model.Action) string { func toTagLink(ctx *context.Context, act *activities_model.Action) string {
return act.GetRepoAbsoluteLink() + "/src/tag/" + util.PathEscapeSegments(act.GetTag()) return act.GetRepoAbsoluteLink(ctx) + "/src/tag/" + util.PathEscapeSegments(act.GetTag())
} }
func toIssueLink(act *activities_model.Action) string { func toIssueLink(ctx *context.Context, act *activities_model.Action) string {
return act.GetRepoAbsoluteLink() + "/issues/" + url.PathEscape(act.GetIssueInfos()[0]) return act.GetRepoAbsoluteLink(ctx) + "/issues/" + url.PathEscape(act.GetIssueInfos()[0])
} }
func toPullLink(act *activities_model.Action) string { func toPullLink(ctx *context.Context, act *activities_model.Action) string {
return act.GetRepoAbsoluteLink() + "/pulls/" + url.PathEscape(act.GetIssueInfos()[0]) return act.GetRepoAbsoluteLink(ctx) + "/pulls/" + url.PathEscape(act.GetIssueInfos()[0])
} }
func toSrcLink(act *activities_model.Action) string { func toSrcLink(ctx *context.Context, act *activities_model.Action) string {
return act.GetRepoAbsoluteLink() + "/src/" + util.PathEscapeSegments(act.GetBranch()) return act.GetRepoAbsoluteLink(ctx) + "/src/" + util.PathEscapeSegments(act.GetBranch())
} }
func toReleaseLink(act *activities_model.Action) string { func toReleaseLink(ctx *context.Context, act *activities_model.Action) string {
return act.GetRepoAbsoluteLink() + "/releases/tag/" + util.PathEscapeSegments(act.GetBranch()) return act.GetRepoAbsoluteLink(ctx) + "/releases/tag/" + util.PathEscapeSegments(act.GetBranch())
} }
// renderMarkdown creates a minimal markdown render context from an action. // 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 { func renderMarkdown(ctx *context.Context, act *activities_model.Action, content string) string {
markdownCtx := &markup.RenderContext{ markdownCtx := &markup.RenderContext{
Ctx: ctx, Ctx: ctx,
URLPrefix: act.GetRepoLink(), URLPrefix: act.GetRepoLink(ctx),
Type: markdown.MarkupName, Type: markdown.MarkupName,
Metas: map[string]string{ Metas: map[string]string{
"user": act.GetRepoUserName(), "user": act.GetRepoUserName(ctx),
"repo": act.GetRepoName(), "repo": act.GetRepoName(ctx),
}, },
} }
markdown, err := markdown.RenderString(markdownCtx, content) markdown, err := markdown.RenderString(markdownCtx, content)
@ -73,123 +73,123 @@ func feedActionsToFeedItems(ctx *context.Context, actions activities_model.Actio
var content, desc, title string var content, desc, title string
link := &feeds.Link{Href: act.GetCommentHTMLURL()} link := &feeds.Link{Href: act.GetCommentHTMLURL(ctx)}
// title // title
title = act.ActUser.DisplayName() + " " title = act.ActUser.DisplayName() + " "
switch act.OpType { switch act.OpType {
case activities_model.ActionCreateRepo: case activities_model.ActionCreateRepo:
title += ctx.TrHTMLEscapeArgs("action.create_repo", act.GetRepoAbsoluteLink(), act.ShortRepoPath()) title += ctx.TrHTMLEscapeArgs("action.create_repo", act.GetRepoAbsoluteLink(ctx), act.ShortRepoPath(ctx))
link.Href = act.GetRepoAbsoluteLink() link.Href = act.GetRepoAbsoluteLink(ctx)
case activities_model.ActionRenameRepo: case activities_model.ActionRenameRepo:
title += ctx.TrHTMLEscapeArgs("action.rename_repo", act.GetContent(), act.GetRepoAbsoluteLink(), act.ShortRepoPath()) title += ctx.TrHTMLEscapeArgs("action.rename_repo", act.GetContent(), act.GetRepoAbsoluteLink(ctx), act.ShortRepoPath(ctx))
link.Href = act.GetRepoAbsoluteLink() link.Href = act.GetRepoAbsoluteLink(ctx)
case activities_model.ActionCommitRepo: case activities_model.ActionCommitRepo:
link.Href = toBranchLink(act) link.Href = toBranchLink(ctx, act)
if len(act.Content) != 0 { 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 { } 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: case activities_model.ActionCreateIssue:
link.Href = toIssueLink(act) link.Href = toIssueLink(ctx, act)
title += ctx.TrHTMLEscapeArgs("action.create_issue", link.Href, act.GetIssueInfos()[0], act.ShortRepoPath()) title += ctx.TrHTMLEscapeArgs("action.create_issue", link.Href, act.GetIssueInfos()[0], act.ShortRepoPath(ctx))
case activities_model.ActionCreatePullRequest: case activities_model.ActionCreatePullRequest:
link.Href = toPullLink(act) link.Href = toPullLink(ctx, act)
title += ctx.TrHTMLEscapeArgs("action.create_pull_request", link.Href, act.GetIssueInfos()[0], act.ShortRepoPath()) title += ctx.TrHTMLEscapeArgs("action.create_pull_request", link.Href, act.GetIssueInfos()[0], act.ShortRepoPath(ctx))
case activities_model.ActionTransferRepo: case activities_model.ActionTransferRepo:
link.Href = act.GetRepoAbsoluteLink() link.Href = act.GetRepoAbsoluteLink(ctx)
title += ctx.TrHTMLEscapeArgs("action.transfer_repo", act.GetContent(), act.GetRepoAbsoluteLink(), act.ShortRepoPath()) title += ctx.TrHTMLEscapeArgs("action.transfer_repo", act.GetContent(), act.GetRepoAbsoluteLink(ctx), act.ShortRepoPath(ctx))
case activities_model.ActionPushTag: case activities_model.ActionPushTag:
link.Href = toTagLink(act) link.Href = toTagLink(ctx, act)
title += ctx.TrHTMLEscapeArgs("action.push_tag", act.GetRepoAbsoluteLink(), link.Href, act.GetTag(), act.ShortRepoPath()) title += ctx.TrHTMLEscapeArgs("action.push_tag", act.GetRepoAbsoluteLink(ctx), link.Href, act.GetTag(), act.ShortRepoPath(ctx))
case activities_model.ActionCommentIssue: case activities_model.ActionCommentIssue:
issueLink := toIssueLink(act) issueLink := toIssueLink(ctx, act)
if link.Href == "#" { if link.Href == "#" {
link.Href = issueLink 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: case activities_model.ActionMergePullRequest:
pullLink := toPullLink(act) pullLink := toPullLink(ctx, act)
if link.Href == "#" { if link.Href == "#" {
link.Href = pullLink 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: case activities_model.ActionAutoMergePullRequest:
pullLink := toPullLink(act) pullLink := toPullLink(ctx, act)
if link.Href == "#" { if link.Href == "#" {
link.Href = pullLink 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: case activities_model.ActionCloseIssue:
issueLink := toIssueLink(act) issueLink := toIssueLink(ctx, act)
if link.Href == "#" { if link.Href == "#" {
link.Href = issueLink 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: case activities_model.ActionReopenIssue:
issueLink := toIssueLink(act) issueLink := toIssueLink(ctx, act)
if link.Href == "#" { if link.Href == "#" {
link.Href = issueLink 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: case activities_model.ActionClosePullRequest:
pullLink := toPullLink(act) pullLink := toPullLink(ctx, act)
if link.Href == "#" { if link.Href == "#" {
link.Href = pullLink 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: case activities_model.ActionReopenPullRequest:
pullLink := toPullLink(act) pullLink := toPullLink(ctx, act)
if link.Href == "#" { if link.Href == "#" {
link.Href = pullLink 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: case activities_model.ActionDeleteTag:
link.Href = act.GetRepoAbsoluteLink() link.Href = act.GetRepoAbsoluteLink(ctx)
title += ctx.TrHTMLEscapeArgs("action.delete_tag", act.GetRepoAbsoluteLink(), act.GetTag(), act.ShortRepoPath()) title += ctx.TrHTMLEscapeArgs("action.delete_tag", act.GetRepoAbsoluteLink(ctx), act.GetTag(), act.ShortRepoPath(ctx))
case activities_model.ActionDeleteBranch: case activities_model.ActionDeleteBranch:
link.Href = act.GetRepoAbsoluteLink() link.Href = act.GetRepoAbsoluteLink(ctx)
title += ctx.TrHTMLEscapeArgs("action.delete_branch", act.GetRepoAbsoluteLink(), html.EscapeString(act.GetBranch()), act.ShortRepoPath()) title += ctx.TrHTMLEscapeArgs("action.delete_branch", act.GetRepoAbsoluteLink(ctx), html.EscapeString(act.GetBranch()), act.ShortRepoPath(ctx))
case activities_model.ActionMirrorSyncPush: case activities_model.ActionMirrorSyncPush:
srcLink := toSrcLink(act) srcLink := toSrcLink(ctx, act)
if link.Href == "#" { if link.Href == "#" {
link.Href = srcLink 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: case activities_model.ActionMirrorSyncCreate:
srcLink := toSrcLink(act) srcLink := toSrcLink(ctx, act)
if link.Href == "#" { if link.Href == "#" {
link.Href = srcLink 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: case activities_model.ActionMirrorSyncDelete:
link.Href = act.GetRepoAbsoluteLink() link.Href = act.GetRepoAbsoluteLink(ctx)
title += ctx.TrHTMLEscapeArgs("action.mirror_sync_delete", act.GetRepoAbsoluteLink(), act.GetBranch(), act.ShortRepoPath()) title += ctx.TrHTMLEscapeArgs("action.mirror_sync_delete", act.GetRepoAbsoluteLink(ctx), act.GetBranch(), act.ShortRepoPath(ctx))
case activities_model.ActionApprovePullRequest: case activities_model.ActionApprovePullRequest:
pullLink := toPullLink(act) pullLink := toPullLink(ctx, act)
title += ctx.TrHTMLEscapeArgs("action.approve_pull_request", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath()) title += ctx.TrHTMLEscapeArgs("action.approve_pull_request", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath(ctx))
case activities_model.ActionRejectPullRequest: case activities_model.ActionRejectPullRequest:
pullLink := toPullLink(act) pullLink := toPullLink(ctx, act)
title += ctx.TrHTMLEscapeArgs("action.reject_pull_request", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath()) title += ctx.TrHTMLEscapeArgs("action.reject_pull_request", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath(ctx))
case activities_model.ActionCommentPull: case activities_model.ActionCommentPull:
pullLink := toPullLink(act) pullLink := toPullLink(ctx, act)
title += ctx.TrHTMLEscapeArgs("action.comment_pull", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath()) title += ctx.TrHTMLEscapeArgs("action.comment_pull", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath(ctx))
case activities_model.ActionPublishRelease: case activities_model.ActionPublishRelease:
releaseLink := toReleaseLink(act) releaseLink := toReleaseLink(ctx, act)
if link.Href == "#" { if link.Href == "#" {
link.Href = releaseLink 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: case activities_model.ActionPullReviewDismissed:
pullLink := toPullLink(act) pullLink := toPullLink(ctx, act)
title += ctx.TrHTMLEscapeArgs("action.review_dismissed", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath(), act.GetIssueInfos()[1]) title += ctx.TrHTMLEscapeArgs("action.review_dismissed", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath(ctx), act.GetIssueInfos()[1])
case activities_model.ActionStarRepo: case activities_model.ActionStarRepo:
link.Href = act.GetRepoAbsoluteLink() link.Href = act.GetRepoAbsoluteLink(ctx)
title += ctx.TrHTMLEscapeArgs("action.starred_repo", act.GetRepoAbsoluteLink(), act.GetRepoPath()) title += ctx.TrHTMLEscapeArgs("action.starred_repo", act.GetRepoAbsoluteLink(ctx), act.GetRepoPath(ctx))
case activities_model.ActionWatchRepo: case activities_model.ActionWatchRepo:
link.Href = act.GetRepoAbsoluteLink() link.Href = act.GetRepoAbsoluteLink(ctx)
title += ctx.TrHTMLEscapeArgs("action.watched_repo", act.GetRepoAbsoluteLink(), act.GetRepoPath()) title += ctx.TrHTMLEscapeArgs("action.watched_repo", act.GetRepoAbsoluteLink(ctx), act.GetRepoPath(ctx))
default: default:
return nil, fmt.Errorf("unknown action type: %v", act.OpType) 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 { switch act.OpType {
case activities_model.ActionCommitRepo, activities_model.ActionMirrorSyncPush: case activities_model.ActionCommitRepo, activities_model.ActionMirrorSyncPush:
push := templates.ActionContent2Commits(act) push := templates.ActionContent2Commits(act)
repoLink := act.GetRepoAbsoluteLink() repoLink := act.GetRepoAbsoluteLink(ctx)
for _, commit := range push.Commits { for _, commit := range push.Commits {
if len(desc) != 0 { if len(desc) != 0 {
desc += "\n\n" desc += "\n\n"
} }
desc += fmt.Sprintf("<a href=\"%s\">%s</a>\n%s", 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, commit.Sha1,
templates.RenderCommitMessage(ctx, commit.Message, repoLink, nil), templates.RenderCommitMessage(ctx, commit.Message, repoLink, nil),
) )
@ -215,14 +215,14 @@ func feedActionsToFeedItems(ctx *context.Context, actions activities_model.Actio
if push.Len > 1 { if push.Len > 1 {
link = &feeds.Link{Href: fmt.Sprintf("%s/%s", setting.AppSubURL, push.CompareURL)} link = &feeds.Link{Href: fmt.Sprintf("%s/%s", setting.AppSubURL, push.CompareURL)}
} else if push.Len == 1 { } 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: case activities_model.ActionCreateIssue, activities_model.ActionCreatePullRequest:
desc = strings.Join(act.GetIssueInfos(), "#") desc = strings.Join(act.GetIssueInfos(), "#")
content = renderMarkdown(ctx, act, act.GetIssueContent(ctx)) content = renderMarkdown(ctx, act, act.GetIssueContent(ctx))
case activities_model.ActionCommentIssue, activities_model.ActionApprovePullRequest, activities_model.ActionRejectPullRequest, activities_model.ActionCommentPull: case activities_model.ActionCommentIssue, activities_model.ActionApprovePullRequest, activities_model.ActionRejectPullRequest, activities_model.ActionCommentPull:
desc = act.GetIssueTitle() desc = act.GetIssueTitle(ctx)
comment := act.GetIssueInfos()[1] comment := act.GetIssueInfos()[1]
if len(comment) != 0 { if len(comment) != 0 {
desc += "\n\n" + renderMarkdown(ctx, act, comment) 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: case activities_model.ActionMergePullRequest, activities_model.ActionAutoMergePullRequest:
desc = act.GetIssueInfos()[1] desc = act.GetIssueInfos()[1]
case activities_model.ActionCloseIssue, activities_model.ActionReopenIssue, activities_model.ActionClosePullRequest, activities_model.ActionReopenPullRequest: case activities_model.ActionCloseIssue, activities_model.ActionReopenIssue, activities_model.ActionClosePullRequest, activities_model.ActionReopenPullRequest:
desc = act.GetIssueTitle() desc = act.GetIssueTitle(ctx)
case activities_model.ActionPullReviewDismissed: case activities_model.ActionPullReviewDismissed:
desc = ctx.Tr("action.review_dismissed_reason") + "\n\n" + act.GetIssueInfos()[2] 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 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) ctx.ServerError("NewProject", err)
return return
} }
@ -201,7 +201,7 @@ func ChangeProjectStatus(ctx *context.Context) {
} }
id := ctx.ParamsInt64(":id") 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) { if project_model.IsErrProjectNotExist(err) {
ctx.NotFound("", err) ctx.NotFound("", err)
} else { } else {
@ -320,7 +320,7 @@ func EditProjectPost(ctx *context.Context) {
ctx.Flash.Success(ctx.Tr("repo.projects.edit_success", p.Title)) ctx.Flash.Success(ctx.Tr("repo.projects.edit_success", p.Title))
if ctx.FormString("redirect") == "project" { if ctx.FormString("redirect") == "project" {
ctx.Redirect(p.Link()) ctx.Redirect(p.Link(ctx))
} else { } else {
ctx.Redirect(ctx.ContextUser.HomeLink() + "/-/projects") ctx.Redirect(ctx.ContextUser.HomeLink() + "/-/projects")
} }
@ -515,7 +515,7 @@ func DeleteProjectBoard(ctx *context.Context) {
return 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) ctx.ServerError("DeleteProjectBoardByID", err)
return return
} }
@ -537,7 +537,7 @@ func AddBoardToProjectPost(ctx *context.Context) {
return return
} }
if err := project_model.NewBoard(&project_model.Board{ if err := project_model.NewBoard(ctx, &project_model.Board{
ProjectID: project.ID, ProjectID: project.ID,
Title: form.Title, Title: form.Title,
Color: form.Color, Color: form.Color,
@ -623,7 +623,7 @@ func SetDefaultProjectBoard(ctx *context.Context) {
return 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) ctx.ServerError("SetDefaultBoard", err)
return return
} }
@ -638,7 +638,7 @@ func UnsetDefaultProjectBoard(ctx *context.Context) {
return 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) ctx.ServerError("SetDefaultBoard", err)
return 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) ctx.ServerError("MoveIssuesOnProjectBoard", err)
return return
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -695,7 +695,7 @@ func SettingsPost(ctx *context.Context) {
if _, err := repo_module.CleanUpMigrateInfo(ctx, repo); err != nil { if _, err := repo_module.CleanUpMigrateInfo(ctx, repo); err != nil {
ctx.ServerError("CleanUpMigrateInfo", err) ctx.ServerError("CleanUpMigrateInfo", err)
return 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) ctx.ServerError("DeleteMirrorByRepoID", err)
return return
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -135,7 +135,7 @@ func registerDeleteOldActions() {
OlderThan: 365 * 24 * time.Hour, OlderThan: 365 * 24 * time.Hour,
}, func(ctx context.Context, _ *user_model.User, config Config) error { }, func(ctx context.Context, _ *user_model.User, config Config) error {
olderThanConfig := config.(*OlderThanConfig) 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 // 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 { 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 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 return err
} }
@ -94,8 +94,8 @@ func UpdateMigrationsByType(ctx context.Context, tp structs.GitServiceType, exte
return err 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 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) 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) 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 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) { func ChangeContent(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, content string) (err error) {
oldContent := issue.Content 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 return err
} }

View File

@ -22,7 +22,7 @@ import (
// NewIssue creates new issue with labels for repository. // 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 { 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 return err
} }
@ -73,7 +73,7 @@ func ChangeIssueRef(ctx context.Context, issue *issues_model.Issue, doer *user_m
oldRef := issue.Ref oldRef := issue.Ref
issue.Ref = 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 return err
} }

View File

@ -510,7 +510,7 @@ func (g *GiteaLocalUploader) CreateComments(comments ...*base.Comment) error {
if len(cms) == 0 { if len(cms) == 0 {
return nil return nil
} }
return issues_model.InsertIssueComments(cms) return issues_model.InsertIssueComments(g.ctx, cms)
} }
// CreatePullRequests creates pull requests // 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. // 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 var referenceID int64
if m, ok := bean.(*repo_model.Mirror); ok { 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) log.Error("Disconnected mirror found: %d", m.ID)
return nil return nil
} }
@ -90,7 +90,7 @@ func Update(ctx context.Context, pullLimit, pushLimit int) error {
pullMirrorsRequested := 0 pullMirrorsRequested := 0
if pullLimit != 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 { if err := handler(idx, bean); err != nil {
return err return err
} }

View File

@ -31,7 +31,7 @@ const gitShortEmptySha = "0000000"
// UpdateAddress writes new address to Git repository and database // UpdateAddress writes new address to Git repository and database
func UpdateAddress(ctx context.Context, m *repo_model.Mirror, addr string) error { func UpdateAddress(ctx context.Context, m *repo_model.Mirror, addr string) error {
remoteName := m.GetRemoteName() remoteName := m.GetRemoteName()
repoPath := m.GetRepository().RepoPath() repoPath := m.GetRepository(ctx).RepoPath()
// Remove old remote // Remove old remote
_, _, err := git.NewCommand(ctx, "remote", "rm").AddDynamicArguments(remoteName).RunStdString(&git.RunOpts{Dir: repoPath}) _, _, 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 ") { 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) log.Error("SyncMirrors [repo_id: %v]: unable to GetMirrorByRepoID: %v", repoID, err)
return false 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)) ctx, _, finished := process.GetManager().AddContext(ctx, fmt.Sprintf("Syncing Mirror %s/%s", m.Repo.OwnerName, m.Repo.Name))
defer finished() defer finished()

View File

@ -336,7 +336,7 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
} }
if changed { if changed {
// Mark old reviews as stale if diff to mergebase has 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) 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) log.Error("MarkReviewsAsNotStale: %v", err)
} }
divergence, err := GetDiverging(ctx, pr) 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 { if !pendingReview && replyReviewID != 0 {
// It's not part of a review; maybe a reply to a review comment or a single comment. // 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 // 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 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 { if err != nil {
return nil, nil, err return nil, nil, err
} }

View File

@ -52,7 +52,7 @@ func NewNotifier() notify_service.Notifier {
func handler(items ...issueNotificationOpts) []issueNotificationOpts { func handler(items ...issueNotificationOpts) []issueNotificationOpts {
for _, opts := range items { 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) log.Error("Was unable to create issue notification: %v", err)
} }
} }

View File

@ -48,28 +48,28 @@
<li class="milestone-card"> <li class="milestone-card">
<h3 class="flex-text-block gt-m-0"> <h3 class="flex-text-block gt-m-0">
{{svg .IconName 16}} {{svg .IconName 16}}
<a class="muted" href="{{.Link}}">{{.Title}}</a> <a class="muted" href="{{.Link ctx}}">{{.Title}}</a>
</h3> </h3>
<div class="milestone-toolbar"> <div class="milestone-toolbar">
<div class="group"> <div class="group">
<div class="flex-text-block"> <div class="flex-text-block">
{{svg "octicon-issue-opened" 14}} {{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>
<div class="flex-text-block"> <div class="flex-text-block">
{{svg "octicon-check" 14}} {{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>
</div> </div>
{{if and $.CanWriteProjects (not $.Repository.IsArchived)}} {{if and $.CanWriteProjects (not $.Repository.IsArchived)}}
<div class="group"> <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}} {{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}} {{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}} {{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> </div>
{{end}} {{end}}
</div> </div>

View File

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

View File

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

View File

@ -137,12 +137,12 @@
{{if eq .RefAction 3}}<del>{{end}} {{if eq .RefAction 3}}<del>{{end}}
<span class="text grey muted-links"> <span class="text grey muted-links">
{{template "shared/user/authorlink" .Poster}} {{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> </span>
{{if eq .RefAction 3}}</del>{{end}} {{if eq .RefAction 3}}</del>{{end}}
<div class="detail"> <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>
</div> </div>
{{else if eq .Type 4}} {{else if eq .Type 4}}
@ -468,7 +468,7 @@
{{$resolveDoer := (index $comms 0).ResolveDoer}} {{$resolveDoer := (index $comms 0).ResolveDoer}}
{{$isNotPending := (not (eq (index $comms 0).Review.Type 0))}} {{$isNotPending := (not (eq (index $comms 0).Review.Type 0))}}
<div class="gt-df gt-ac"> <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}} {{if $invalid}}
<span class="ui label basic small gt-ml-3" data-tooltip-content="{{ctx.Locale.Tr "repo.issues.review.outdated_description"}}"> <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"}} {{ctx.Locale.Tr "repo.issues.review.outdated"}}

View File

@ -173,7 +173,7 @@
{{ctx.Locale.Tr "repo.issues.new.open_projects"}} {{ctx.Locale.Tr "repo.issues.new.open_projects"}}
</div> </div>
{{range .OpenProjects}} {{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}} {{svg .IconName 18 "gt-mr-3"}}{{.Title}}
</a> </a>
{{end}} {{end}}
@ -184,7 +184,7 @@
{{ctx.Locale.Tr "repo.issues.new.closed_projects"}} {{ctx.Locale.Tr "repo.issues.new.closed_projects"}}
</div> </div>
{{range .ClosedProjects}} {{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}} {{svg .IconName 18 "gt-mr-3"}}{{.Title}}
</a> </a>
{{end}} {{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> <span class="no-select item {{if .Issue.Project}}gt-hidden{{end}}">{{ctx.Locale.Tr "repo.issues.new.no_projects"}}</span>
<div class="selected"> <div class="selected">
{{if .Issue.Project}} {{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}} {{svg .Issue.Project.IconName 18 "gt-mr-3"}}{{.Issue.Project.Title}}
</a> </a>
{{end}} {{end}}

View File

@ -93,7 +93,7 @@
</a> </a>
{{end}} {{end}}
{{if .Project}} {{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}} {{svg .Project.IconName 14}}{{.Project.Title}}
</a> </a>
{{end}} {{end}}

View File

@ -7,81 +7,81 @@
<div class="flex-item-main gt-gap-3"> <div class="flex-item-main gt-gap-3">
<div> <div>
{{if gt .ActUser.ID 0}} {{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}} {{else}}
{{.ShortActUserName}} {{.ShortActUserName ctx}}
{{end}} {{end}}
{{if .GetOpType.InActions "create_repo"}} {{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"}} {{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"}} {{else if .GetOpType.InActions "commit_repo"}}
{{if .Content}} {{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}} {{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}} {{end}}
{{else if .GetOpType.InActions "create_issue"}} {{else if .GetOpType.InActions "create_issue"}}
{{$index := index .GetIssueInfos 0}} {{$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"}} {{else if .GetOpType.InActions "create_pull_request"}}
{{$index := index .GetIssueInfos 0}} {{$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"}} {{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"}} {{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"}} {{else if .GetOpType.InActions "comment_issue"}}
{{$index := index .GetIssueInfos 0}} {{$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"}} {{else if .GetOpType.InActions "merge_pull_request"}}
{{$index := index .GetIssueInfos 0}} {{$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"}} {{else if .GetOpType.InActions "close_issue"}}
{{$index := index .GetIssueInfos 0}} {{$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"}} {{else if .GetOpType.InActions "reopen_issue"}}
{{$index := index .GetIssueInfos 0}} {{$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"}} {{else if .GetOpType.InActions "close_pull_request"}}
{{$index := index .GetIssueInfos 0}} {{$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"}} {{else if .GetOpType.InActions "reopen_pull_request"}}
{{$index := index .GetIssueInfos 0}} {{$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"}} {{else if .GetOpType.InActions "delete_tag"}}
{{$index := index .GetIssueInfos 0}} {{$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"}} {{else if .GetOpType.InActions "delete_branch"}}
{{$index := index .GetIssueInfos 0}} {{$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"}} {{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"}} {{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"}} {{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"}} {{else if .GetOpType.InActions "approve_pull_request"}}
{{$index := index .GetIssueInfos 0}} {{$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"}} {{else if .GetOpType.InActions "reject_pull_request"}}
{{$index := index .GetIssueInfos 0}} {{$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"}} {{else if .GetOpType.InActions "comment_pull"}}
{{$index := index .GetIssueInfos 0}} {{$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"}} {{else if .GetOpType.InActions "publish_release"}}
{{$linkText := .Content | RenderEmoji $.Context}} {{$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"}} {{else if .GetOpType.InActions "review_dismissed"}}
{{$index := index .GetIssueInfos 0}} {{$index := index .GetIssueInfos 0}}
{{$reviewer := index .GetIssueInfos 1}} {{$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}} {{end}}
</div> </div>
{{if .GetOpType.InActions "commit_repo" "mirror_sync_push"}} {{if .GetOpType.InActions "commit_repo" "mirror_sync_push"}}
{{$push := ActionContent2Commits .}} {{$push := ActionContent2Commits .}}
{{$repoLink := .GetRepoLink}} {{$repoLink := (.GetRepoLink ctx)}}
{{range $push.Commits}} {{range $push.Commits}}
{{$commitLink := printf "%s/commit/%s" $repoLink .Sha1}} {{$commitLink := printf "%s/commit/%s" $repoLink .Sha1}}
<div class="flex-text-block"> <div class="flex-text-block">
@ -100,7 +100,7 @@
{{else if .GetOpType.InActions "create_pull_request"}} {{else if .GetOpType.InActions "create_pull_request"}}
<span class="text truncate issue title">{{index .GetIssueInfos 1 | RenderEmoji $.Context | RenderCodeBlock}}</span> <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"}} {{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}} {{$comment := index .GetIssueInfos 1}}
{{if gt (len $comment) 0}} {{if gt (len $comment) 0}}
<div class="flex-item-body">{{$comment | RenderEmoji $.Context | RenderCodeBlock}}</div> <div class="flex-item-body">{{$comment | RenderEmoji $.Context | RenderCodeBlock}}</div>
@ -108,7 +108,7 @@
{{else if .GetOpType.InActions "merge_pull_request"}} {{else if .GetOpType.InActions "merge_pull_request"}}
<div class="flex-item-body">{{index .GetIssueInfos 1}}</div> <div class="flex-item-body">{{index .GetIssueInfos 1}}</div>
{{else if .GetOpType.InActions "close_issue" "reopen_issue" "close_pull_request" "reopen_pull_request"}} {{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"}} {{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">{{ctx.Locale.Tr "action.review_dismissed_reason"}}</div>
<div class="flex-item-body">{{index .GetIssueInfos 2 | RenderEmoji $.Context}}</div> <div class="flex-item-body">{{index .GetIssueInfos 2 | RenderEmoji $.Context}}</div>

View File

@ -43,7 +43,7 @@
{{svg "octicon-repo" 16 "text grey"}} {{svg "octicon-repo" 16 "text grey"}}
{{end}} {{end}}
</div> </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"> <div class="notifications-top-row gt-font-13">
{{.Repository.FullName}} {{if .Issue}}<span class="text light-3">#{{.Issue.Index}}</span>{{end}} {{.Repository.FullName}} {{if .Issue}}<span class="text light-3">#{{.Issue.Index}}</span>{{end}}
{{if eq .Status 3}} {{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, "a review from a deleted user", reviewComments[0].Body)
assert.EqualValues(t, comment.ID, reviewComments[0].ID) assert.EqualValues(t, comment.ID, reviewComments[0].ID)
assert.EqualValues(t, comment.UpdatedUnix, reviewComments[0].Updated.Unix()) 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 // 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{ 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{