Skip to content

Commit 5dddcc1

Browse files
authored
chore: fix some trivial problems and TODOs (#33473)
1. Fix incorrect `MentionCount` (actually it seems to be deadcode, affects nothing) 2. Remove fallback sha1 support for time limit token 3. Use route middleware `reqRepoActionsWriter` for `ArtifactsDeleteView` 4. Use clearer message "Failed to authenticate user" instead of "Verify" when auth fails 5. `tests/integration/benchmarks_test.go` is not quite right, actually it is never used, so delete it. 6. Remove or update TODO comments
1 parent 34692a2 commit 5dddcc1

File tree

10 files changed

+18
-104
lines changed

10 files changed

+18
-104
lines changed

models/issues/issue_stats.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func GetIssueStats(ctx context.Context, opts *IssuesOptions) (*IssueStats, error
107107
accum.YourRepositoriesCount += stats.YourRepositoriesCount
108108
accum.AssignCount += stats.AssignCount
109109
accum.CreateCount += stats.CreateCount
110-
accum.OpenCount += stats.MentionCount
110+
accum.MentionCount += stats.MentionCount
111111
accum.ReviewRequestedCount += stats.ReviewRequestedCount
112112
accum.ReviewedCount += stats.ReviewedCount
113113
i = chunk

models/system/notice_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ func TestCreateRepositoryNotice(t *testing.T) {
4545
unittest.AssertExistsAndLoadBean(t, noticeBean)
4646
}
4747

48-
// TODO TestRemoveAllWithNotice
49-
5048
func TestCountNotices(t *testing.T) {
5149
assert.NoError(t, unittest.PrepareTestDatabase())
5250
assert.Equal(t, int64(3), system.CountNotices(db.DefaultContext))

modules/base/tool.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"time"
1919

2020
"code.gitea.io/gitea/modules/git"
21-
"code.gitea.io/gitea/modules/log"
2221
"code.gitea.io/gitea/modules/setting"
2322
"code.gitea.io/gitea/modules/util"
2423

@@ -64,10 +63,7 @@ func VerifyTimeLimitCode(now time.Time, data string, minutes int, code string) b
6463
// check code
6564
retCode := CreateTimeLimitCode(data, aliveTime, startTimeStr, nil)
6665
if subtle.ConstantTimeCompare([]byte(retCode), []byte(code)) != 1 {
67-
retCode = CreateTimeLimitCode(data, aliveTime, startTimeStr, sha1.New()) // TODO: this is only for the support of legacy codes, remove this in/after 1.23
68-
if subtle.ConstantTimeCompare([]byte(retCode), []byte(code)) != 1 {
69-
return false
70-
}
66+
return false
7167
}
7268

7369
// check time is expired or not: startTime <= now && now < startTime + minutes
@@ -144,13 +140,12 @@ func Int64sToStrings(ints []int64) []string {
144140
return strs
145141
}
146142

147-
// EntryIcon returns the octicon class for displaying files/directories
143+
// EntryIcon returns the octicon name for displaying files/directories
148144
func EntryIcon(entry *git.TreeEntry) string {
149145
switch {
150146
case entry.IsLink():
151147
te, err := entry.FollowLink()
152148
if err != nil {
153-
log.Debug(err.Error())
154149
return "file-symlink-file"
155150
}
156151
if te.IsDir() {

modules/base/tool_test.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,10 @@ JWT_SECRET = %s
8686
verifyDataCode := func(c string) bool {
8787
return VerifyTimeLimitCode(now, "data", 2, c)
8888
}
89-
code1 := CreateTimeLimitCode("data", 2, now, sha1.New())
90-
code2 := CreateTimeLimitCode("data", 2, now, nil)
91-
assert.True(t, verifyDataCode(code1))
92-
assert.True(t, verifyDataCode(code2))
89+
code := CreateTimeLimitCode("data", 2, now, nil)
90+
assert.True(t, verifyDataCode(code))
9391
initGeneralSecret("000_QLUd4fYVyxetjxC4eZkrBgWM2SndOOWDNtgUUko")
94-
assert.False(t, verifyDataCode(code1))
95-
assert.False(t, verifyDataCode(code2))
92+
assert.False(t, verifyDataCode(code))
9693
})
9794
}
9895

@@ -137,5 +134,3 @@ func TestInt64sToStrings(t *testing.T) {
137134
Int64sToStrings([]int64{1, 4, 16, 64, 256}),
138135
)
139136
}
140-
141-
// TODO: Test EntryIcon

modules/markup/html.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var globalVars = sync.OnceValue(func() *globalVarsType {
4747
// NOTE: All below regex matching do not perform any extra validation.
4848
// Thus a link is produced even if the linked entity does not exist.
4949
// While fast, this is also incorrect and lead to false positives.
50-
// TODO: fix invalid linking issue
50+
// TODO: fix invalid linking issue (update: stale TODO, what issues? maybe no TODO anymore)
5151

5252
// valid chars in encoded path and parameter: [-+~_%.a-zA-Z0-9/]
5353

modules/web/middleware/binding.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func GetInclude(field reflect.StructField) string {
7878
return getRuleBody(field, "Include(")
7979
}
8080

81-
// Validate validate TODO:
81+
// Validate validate
8282
func Validate(errs binding.Errors, data map[string]any, f Form, l translation.Locale) binding.Errors {
8383
if errs.Len() == 0 {
8484
return errs

routers/web/repo/actions/view.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -628,11 +628,6 @@ func getRunJobs(ctx *context_module.Context, runIndex, jobIndex int64) (*actions
628628
}
629629

630630
func ArtifactsDeleteView(ctx *context_module.Context) {
631-
if !ctx.Repo.CanWrite(unit.TypeActions) {
632-
ctx.Error(http.StatusForbidden, "no permission")
633-
return
634-
}
635-
636631
runIndex := getRunIndex(ctx)
637632
artifactName := ctx.PathParam("artifact_name")
638633

routers/web/web.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func webAuth(authMethod auth_service.Method) func(*context.Context) {
118118
ar, err := common.AuthShared(ctx.Base, ctx.Session, authMethod)
119119
if err != nil {
120120
log.Error("Failed to verify user: %v", err)
121-
ctx.Error(http.StatusUnauthorized, "Verify")
121+
ctx.Error(http.StatusUnauthorized, "Failed to authenticate user")
122122
return
123123
}
124124
ctx.Doer = ar.Doer
@@ -1430,7 +1430,7 @@ func registerRoutes(m *web.Router) {
14301430
m.Post("/cancel", reqRepoActionsWriter, actions.Cancel)
14311431
m.Post("/approve", reqRepoActionsWriter, actions.Approve)
14321432
m.Get("/artifacts/{artifact_name}", actions.ArtifactsDownloadView)
1433-
m.Delete("/artifacts/{artifact_name}", actions.ArtifactsDeleteView)
1433+
m.Delete("/artifacts/{artifact_name}", reqRepoActionsWriter, actions.ArtifactsDeleteView)
14341434
m.Post("/rerun", reqRepoActionsWriter, actions.Rerun)
14351435
})
14361436
m.Group("/workflows/{workflow_name}", func() {

services/mailer/mail_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func TestComposeIssueCommentMessage(t *testing.T) {
8585

8686
recipients := []*user_model.User{{Name: "Test", Email: "[email protected]"}, {Name: "Test2", Email: "[email protected]"}}
8787
msgs, err := composeIssueCommentMessages(&mailCommentContext{
88-
Context: context.TODO(), // TODO: use a correct context
88+
Context: context.TODO(),
8989
Issue: issue, Doer: doer, ActionType: activities_model.ActionCommentIssue,
9090
Content: fmt.Sprintf("test @%s %s#%d body", doer.Name, issue.Repo.FullName(), issue.Index),
9191
Comment: comment,
@@ -131,7 +131,7 @@ func TestComposeIssueMessage(t *testing.T) {
131131

132132
recipients := []*user_model.User{{Name: "Test", Email: "[email protected]"}, {Name: "Test2", Email: "[email protected]"}}
133133
msgs, err := composeIssueCommentMessages(&mailCommentContext{
134-
Context: context.TODO(), // TODO: use a correct context
134+
Context: context.TODO(),
135135
Issue: issue, Doer: doer, ActionType: activities_model.ActionCreateIssue,
136136
Content: "test body",
137137
}, "en-US", recipients, false, "issue create")
@@ -178,14 +178,14 @@ func TestTemplateSelection(t *testing.T) {
178178
}
179179

180180
msg := testComposeIssueCommentMessage(t, &mailCommentContext{
181-
Context: context.TODO(), // TODO: use a correct context
181+
Context: context.TODO(),
182182
Issue: issue, Doer: doer, ActionType: activities_model.ActionCreateIssue,
183183
Content: "test body",
184184
}, recipients, false, "TestTemplateSelection")
185185
expect(t, msg, "issue/new/subject", "issue/new/body")
186186

187187
msg = testComposeIssueCommentMessage(t, &mailCommentContext{
188-
Context: context.TODO(), // TODO: use a correct context
188+
Context: context.TODO(),
189189
Issue: issue, Doer: doer, ActionType: activities_model.ActionCommentIssue,
190190
Content: "test body", Comment: comment,
191191
}, recipients, false, "TestTemplateSelection")
@@ -194,14 +194,14 @@ func TestTemplateSelection(t *testing.T) {
194194
pull := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2, Repo: repo, Poster: doer})
195195
comment = unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 4, Issue: pull})
196196
msg = testComposeIssueCommentMessage(t, &mailCommentContext{
197-
Context: context.TODO(), // TODO: use a correct context
197+
Context: context.TODO(),
198198
Issue: pull, Doer: doer, ActionType: activities_model.ActionCommentPull,
199199
Content: "test body", Comment: comment,
200200
}, recipients, false, "TestTemplateSelection")
201201
expect(t, msg, "pull/comment/subject", "pull/comment/body")
202202

203203
msg = testComposeIssueCommentMessage(t, &mailCommentContext{
204-
Context: context.TODO(), // TODO: use a correct context
204+
Context: context.TODO(),
205205
Issue: issue, Doer: doer, ActionType: activities_model.ActionCloseIssue,
206206
Content: "test body", Comment: comment,
207207
}, recipients, false, "TestTemplateSelection")
@@ -220,7 +220,7 @@ func TestTemplateServices(t *testing.T) {
220220

221221
recipients := []*user_model.User{{Name: "Test", Email: "[email protected]"}}
222222
msg := testComposeIssueCommentMessage(t, &mailCommentContext{
223-
Context: context.TODO(), // TODO: use a correct context
223+
Context: context.TODO(),
224224
Issue: issue, Doer: doer, ActionType: actionType,
225225
Content: "test body", Comment: comment,
226226
}, recipients, fromMention, "TestTemplateServices")
@@ -263,7 +263,7 @@ func testComposeIssueCommentMessage(t *testing.T, ctx *mailCommentContext, recip
263263
func TestGenerateAdditionalHeaders(t *testing.T) {
264264
doer, _, issue, _ := prepareMailerTest(t)
265265

266-
ctx := &mailCommentContext{Context: context.TODO() /* TODO: use a correct context */, Issue: issue, Doer: doer}
266+
ctx := &mailCommentContext{Context: context.TODO(), Issue: issue, Doer: doer}
267267
recipient := &user_model.User{Name: "test", Email: "[email protected]"}
268268

269269
headers := generateAdditionalHeaders(ctx, "dummy-reason", recipient)

tests/integration/benchmarks_test.go

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)