Skip to content

Commit bde6a30

Browse files
committed
Merge remote-tracking branch 'upstream/main'
* upstream/main: Fix issues count bug (go-gitea#21557) Improve code comment review on mobile (go-gitea#21461) Consolidate remaining colors into variables (go-gitea#21582)
2 parents 0c1b151 + 5e8e3ec commit bde6a30

File tree

14 files changed

+441
-183
lines changed

14 files changed

+441
-183
lines changed

models/issues/comment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ func updateCommentInfos(ctx context.Context, opts *CreateCommentOptions, comment
886886
}
887887
}
888888
case CommentTypeReopen, CommentTypeClose:
889-
if err = updateIssueClosedNum(ctx, opts.Issue); err != nil {
889+
if err = repo_model.UpdateRepoIssueNumbers(ctx, opts.Issue.RepoID, opts.Issue.IsPull, true); err != nil {
890890
return err
891891
}
892892
}

models/issues/issue.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,8 @@ func doChangeIssueStatus(ctx context.Context, issue *Issue, doer *user_model.Use
725725
}
726726
}
727727

728-
if err := updateIssueClosedNum(ctx, issue); err != nil {
728+
// update repository's issue closed number
729+
if err := repo_model.UpdateRepoIssueNumbers(ctx, issue.RepoID, issue.IsPull, true); err != nil {
729730
return nil, err
730731
}
731732

@@ -2137,15 +2138,6 @@ func (issue *Issue) BlockingDependencies(ctx context.Context) (issueDeps []*Depe
21372138
return issueDeps, err
21382139
}
21392140

2140-
func updateIssueClosedNum(ctx context.Context, issue *Issue) (err error) {
2141-
if issue.IsPull {
2142-
err = repo_model.StatsCorrectNumClosed(ctx, issue.RepoID, true, "num_closed_pulls")
2143-
} else {
2144-
err = repo_model.StatsCorrectNumClosed(ctx, issue.RepoID, false, "num_closed_issues")
2145-
}
2146-
return err
2147-
}
2148-
21492141
// FindAndUpdateIssueMentions finds users mentioned in the given content string, and saves them in the database.
21502142
func FindAndUpdateIssueMentions(ctx context.Context, issue *Issue, doer *user_model.User, content string) (mentions []*user_model.User, err error) {
21512143
rawMentions := references.FindAllMentionsMarkdown(content)

models/repo.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -404,24 +404,19 @@ func repoStatsCorrectIssueNumComments(ctx context.Context, id int64) error {
404404
}
405405

406406
func repoStatsCorrectNumIssues(ctx context.Context, id int64) error {
407-
return repoStatsCorrectNum(ctx, id, false, "num_issues")
407+
return repo_model.UpdateRepoIssueNumbers(ctx, id, false, false)
408408
}
409409

410410
func repoStatsCorrectNumPulls(ctx context.Context, id int64) error {
411-
return repoStatsCorrectNum(ctx, id, true, "num_pulls")
412-
}
413-
414-
func repoStatsCorrectNum(ctx context.Context, id int64, isPull bool, field string) error {
415-
_, err := db.GetEngine(ctx).Exec("UPDATE `repository` SET "+field+"=(SELECT COUNT(*) FROM `issue` WHERE repo_id=? AND is_pull=?) WHERE id=?", id, isPull, id)
416-
return err
411+
return repo_model.UpdateRepoIssueNumbers(ctx, id, true, false)
417412
}
418413

419414
func repoStatsCorrectNumClosedIssues(ctx context.Context, id int64) error {
420-
return repo_model.StatsCorrectNumClosed(ctx, id, false, "num_closed_issues")
415+
return repo_model.UpdateRepoIssueNumbers(ctx, id, false, true)
421416
}
422417

423418
func repoStatsCorrectNumClosedPulls(ctx context.Context, id int64) error {
424-
return repo_model.StatsCorrectNumClosed(ctx, id, true, "num_closed_pulls")
419+
return repo_model.UpdateRepoIssueNumbers(ctx, id, true, true)
425420
}
426421

427422
func statsQuery(args ...interface{}) func(context.Context) ([]map[string][]byte, error) {

models/repo/repo.go

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -765,35 +765,30 @@ func CountRepositories(ctx context.Context, opts CountRepositoryOptions) (int64,
765765
return count, nil
766766
}
767767

768-
// StatsCorrectNumClosed update repository's issue related numbers
769-
func StatsCorrectNumClosed(ctx context.Context, id int64, isPull bool, field string) error {
770-
_, err := db.Exec(ctx, "UPDATE `repository` SET "+field+"=(SELECT COUNT(*) FROM `issue` WHERE repo_id=? AND is_closed=? AND is_pull=?) WHERE id=?", id, true, isPull, id)
771-
return err
772-
}
773-
774-
// UpdateRepoIssueNumbers update repository issue numbers
768+
// UpdateRepoIssueNumbers updates one of a repositories amount of (open|closed) (issues|PRs) with the current count
775769
func UpdateRepoIssueNumbers(ctx context.Context, repoID int64, isPull, isClosed bool) error {
776-
e := db.GetEngine(ctx)
770+
field := "num_"
771+
if isClosed {
772+
field += "closed_"
773+
}
777774
if isPull {
778-
if _, err := e.ID(repoID).Decr("num_pulls").Update(new(Repository)); err != nil {
779-
return err
780-
}
781-
if isClosed {
782-
if _, err := e.ID(repoID).Decr("num_closed_pulls").Update(new(Repository)); err != nil {
783-
return err
784-
}
785-
}
775+
field += "pulls"
786776
} else {
787-
if _, err := e.ID(repoID).Decr("num_issues").Update(new(Repository)); err != nil {
788-
return err
789-
}
790-
if isClosed {
791-
if _, err := e.ID(repoID).Decr("num_closed_issues").Update(new(Repository)); err != nil {
792-
return err
793-
}
794-
}
777+
field += "issues"
795778
}
796-
return nil
779+
780+
subQuery := builder.Select("count(*)").
781+
From("issue").Where(builder.Eq{
782+
"repo_id": repoID,
783+
"is_pull": isPull,
784+
}.And(builder.If(isClosed, builder.Eq{"is_closed": isClosed})))
785+
786+
// builder.Update(cond) will generate SQL like UPDATE ... SET cond
787+
query := builder.Update(builder.Eq{field: subQuery}).
788+
From("repository").
789+
Where(builder.Eq{"id": repoID})
790+
_, err := db.Exec(ctx, query)
791+
return err
797792
}
798793

799794
// CountNullArchivedRepository counts the number of repositories with is_archived is null

templates/repo/diff/conversation.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
{{template "repo/diff/comments" dict "root" $ "comments" .comments}}
2727
</ui>
2828
</div>
29-
<div class="df je ac fw mt-3">
29+
<div class="df je js-small ac fw mt-3">
3030
<div class="ui buttons mr-2">
3131
<button class="ui icon tiny basic button previous-conversation">
3232
{{svg "octicon-arrow-up" 12 "icon"}} {{$.locale.Tr "repo.issues.previous"}}

templates/repo/diff/section_split.tmpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
<td class="lines-num"></td>
102102
<td class="lines-escape"></td>
103103
<td class="lines-type-marker"></td>
104-
<td class="add-comment-left">
104+
<td class="add-comment-left" colspan="4">
105105
{{if gt (len $line.Comments) 0}}
106106
{{if eq $line.GetCommentSide "previous"}}
107107
{{template "repo/diff/conversation" mergeinto $.root "comments" $line.Comments}}
@@ -116,7 +116,7 @@
116116
<td class="lines-num"></td>
117117
<td class="lines-escape"></td>
118118
<td class="lines-type-marker"></td>
119-
<td class="add-comment-right">
119+
<td class="add-comment-right" colspan="4">
120120
{{if eq $line.GetCommentSide "proposed"}}
121121
{{template "repo/diff/conversation" mergeinto $.root "comments" $line.Comments}}
122122
{{end}}
@@ -133,7 +133,7 @@
133133
<td class="lines-num"></td>
134134
<td class="lines-escape"></td>
135135
<td class="lines-type-marker"></td>
136-
<td class="add-comment-left">
136+
<td class="add-comment-left" colspan="4">
137137
{{if gt (len $line.Comments) 0}}
138138
{{if eq $line.GetCommentSide "previous"}}
139139
{{template "repo/diff/conversation" mergeinto $.root "comments" $line.Comments}}
@@ -143,7 +143,7 @@
143143
<td class="lines-num"></td>
144144
<td class="lines-escape"></td>
145145
<td class="lines-type-marker"></td>
146-
<td class="add-comment-right">
146+
<td class="add-comment-right" colspan="4">
147147
{{if eq $line.GetCommentSide "proposed"}}
148148
{{template "repo/diff/conversation" mergeinto $.root "comments" $line.Comments}}
149149
{{end}}

templates/repo/diff/section_unified.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
{{if gt (len $line.Comments) 0}}
4747
<tr class="add-comment" data-line-type="{{DiffLineTypeToStr .GetType}}">
4848
<td colspan="3" class="lines-num"></td>
49-
<td class="add-comment-left add-comment-right" colspan="2">
49+
<td class="add-comment-left add-comment-right" colspan="5">
5050
{{template "repo/diff/conversation" mergeinto $.root "comments" $line.Comments}}
5151
</td>
5252
</tr>

web_src/js/features/repo-issue.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,16 +513,16 @@ export function initRepoPullRequestReview() {
513513
<td class="lines-num"></td>
514514
<td class="lines-escape"></td>
515515
<td class="lines-type-marker"></td>
516-
<td class="add-comment-left"></td>
516+
<td class="add-comment-left" colspan="4"></td>
517517
<td class="lines-num"></td>
518518
<td class="lines-escape"></td>
519519
<td class="lines-type-marker"></td>
520-
<td class="add-comment-right"></td>
520+
<td class="add-comment-right" colspan="4"></td>
521521
` : `
522522
<td class="lines-num"></td>
523523
<td class="lines-num"></td>
524524
<td class="lines-escape"></td>
525-
<td class="add-comment-left add-comment-right" colspan="2"></td>
525+
<td class="add-comment-left add-comment-right" colspan="5"></td>
526526
`}
527527
</tr>`);
528528
tr.after(ntr);

0 commit comments

Comments
 (0)