loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request 'Enable switch check in linter' (#4555) from thefox/reenable-switch-check into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4555
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Reviewed-by: Otto <otto@codeberg.org>

Otto 2cbc9cec 22d57cfc

+126 -123
-1
.golangci.yml
··· 43 43 gocritic: 44 44 disabled-checks: 45 45 - ifElseChain 46 - - singleCaseSwitch # Every time this occurred in the code, there was no other way. 47 46 revive: 48 47 severity: error 49 48 rules:
+2 -1
models/db/convert.go
··· 58 58 59 59 v, _ := strconv.ParseInt(string((*val).([]uint8)), 10, 64) 60 60 return v 61 + default: 62 + return (*val).(int64) 61 63 } 62 - return (*val).(int64) 63 64 }
+1 -2
models/repo/repo_unit.go
··· 235 235 236 236 // BeforeSet is invoked from XORM before setting the value of a field of this object. 237 237 func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) { 238 - switch colName { 239 - case "type": 238 + if colName == "type" { 240 239 switch unit.Type(db.Cell2Int64(val)) { 241 240 case unit.TypeExternalWiki: 242 241 r.Config = new(ExternalWikiConfig)
+2 -4
modules/actions/workflows.go
··· 649 649 // unpublished, created, deleted, prereleased, released 650 650 651 651 action := payload.Action 652 - switch action { 653 - case api.HookReleaseUpdated: 652 + if action == api.HookReleaseUpdated { 654 653 action = "edited" 655 654 } 656 655 for _, val := range vals { ··· 686 685 // updated 687 686 688 687 action := payload.Action 689 - switch action { 690 - case api.HookPackageCreated: 688 + if action == api.HookPackageCreated { 691 689 action = "published" 692 690 } 693 691 for _, val := range vals {
+96 -79
modules/actions/workflows_test.go
··· 16 16 17 17 func TestDetectMatched(t *testing.T) { 18 18 testCases := []struct { 19 - desc string 20 - commit *git.Commit 21 - triggedEvent webhook_module.HookEventType 22 - payload api.Payloader 23 - yamlOn string 24 - expected bool 19 + desc string 20 + commit *git.Commit 21 + triggeredEvent webhook_module.HookEventType 22 + payload api.Payloader 23 + yamlOn string 24 + expected bool 25 25 }{ 26 26 { 27 - desc: "HookEventCreate(create) matches GithubEventCreate(create)", 28 - triggedEvent: webhook_module.HookEventCreate, 29 - payload: nil, 30 - yamlOn: "on: create", 31 - expected: true, 27 + desc: "HookEventCreate(create) matches GithubEventCreate(create)", 28 + triggeredEvent: webhook_module.HookEventCreate, 29 + payload: nil, 30 + yamlOn: "on: create", 31 + expected: true, 32 32 }, 33 33 { 34 - desc: "HookEventIssues(issues) `opened` action matches GithubEventIssues(issues)", 35 - triggedEvent: webhook_module.HookEventIssues, 36 - payload: &api.IssuePayload{Action: api.HookIssueOpened}, 37 - yamlOn: "on: issues", 38 - expected: true, 34 + desc: "HookEventIssues(issues) `opened` action matches GithubEventIssues(issues)", 35 + triggeredEvent: webhook_module.HookEventIssues, 36 + payload: &api.IssuePayload{Action: api.HookIssueOpened}, 37 + yamlOn: "on: issues", 38 + expected: true, 39 39 }, 40 40 { 41 - desc: "HookEventIssues(issues) `milestoned` action matches GithubEventIssues(issues)", 42 - triggedEvent: webhook_module.HookEventIssues, 43 - payload: &api.IssuePayload{Action: api.HookIssueMilestoned}, 44 - yamlOn: "on: issues", 45 - expected: true, 41 + desc: "HookEventIssueComment(issue_comment) `created` action matches GithubEventIssueComment(issue_comment)", 42 + triggeredEvent: webhook_module.HookEventIssueComment, 43 + payload: &api.IssueCommentPayload{Action: api.HookIssueCommentCreated}, 44 + yamlOn: "on:\n issue_comment:\n types: [created]", 45 + expected: true, 46 46 }, 47 + 47 48 { 48 - desc: "HookEventPullRequestSync(pull_request_sync) matches GithubEventPullRequest(pull_request)", 49 - triggedEvent: webhook_module.HookEventPullRequestSync, 50 - payload: &api.PullRequestPayload{Action: api.HookIssueSynchronized}, 51 - yamlOn: "on: pull_request", 52 - expected: true, 49 + desc: "HookEventIssues(issues) `milestoned` action matches GithubEventIssues(issues)", 50 + triggeredEvent: webhook_module.HookEventIssues, 51 + payload: &api.IssuePayload{Action: api.HookIssueMilestoned}, 52 + yamlOn: "on: issues", 53 + expected: true, 53 54 }, 55 + 54 56 { 55 - desc: "HookEventPullRequest(pull_request) `label_updated` action doesn't match GithubEventPullRequest(pull_request) with no activity type", 56 - triggedEvent: webhook_module.HookEventPullRequest, 57 - payload: &api.PullRequestPayload{Action: api.HookIssueLabelUpdated}, 58 - yamlOn: "on: pull_request", 59 - expected: false, 57 + desc: "HookEventPullRequestSync(pull_request_sync) matches GithubEventPullRequest(pull_request)", 58 + triggeredEvent: webhook_module.HookEventPullRequestSync, 59 + payload: &api.PullRequestPayload{Action: api.HookIssueSynchronized}, 60 + yamlOn: "on: pull_request", 61 + expected: true, 60 62 }, 61 63 { 62 - desc: "HookEventPullRequest(pull_request) `closed` action doesn't match GithubEventPullRequest(pull_request) with no activity type", 63 - triggedEvent: webhook_module.HookEventPullRequest, 64 - payload: &api.PullRequestPayload{Action: api.HookIssueClosed}, 65 - yamlOn: "on: pull_request", 66 - expected: false, 64 + desc: "HookEventPullRequest(pull_request) `label_updated` action doesn't match GithubEventPullRequest(pull_request) with no activity type", 65 + triggeredEvent: webhook_module.HookEventPullRequest, 66 + payload: &api.PullRequestPayload{Action: api.HookIssueLabelUpdated}, 67 + yamlOn: "on: pull_request", 68 + expected: false, 67 69 }, 68 70 { 69 - desc: "HookEventPullRequest(pull_request) `closed` action doesn't match GithubEventPullRequest(pull_request) with branches", 70 - triggedEvent: webhook_module.HookEventPullRequest, 71 + desc: "HookEventPullRequest(pull_request) `closed` action doesn't match GithubEventPullRequest(pull_request) with no activity type", 72 + triggeredEvent: webhook_module.HookEventPullRequest, 73 + payload: &api.PullRequestPayload{Action: api.HookIssueClosed}, 74 + yamlOn: "on: pull_request", 75 + expected: false, 76 + }, 77 + { 78 + desc: "HookEventPullRequest(pull_request) `closed` action doesn't match GithubEventPullRequest(pull_request) with branches", 79 + triggeredEvent: webhook_module.HookEventPullRequest, 71 80 payload: &api.PullRequestPayload{ 72 81 Action: api.HookIssueClosed, 73 82 PullRequest: &api.PullRequest{ ··· 78 87 expected: false, 79 88 }, 80 89 { 81 - desc: "HookEventPullRequest(pull_request) `label_updated` action matches GithubEventPullRequest(pull_request) with `label` activity type", 82 - triggedEvent: webhook_module.HookEventPullRequest, 83 - payload: &api.PullRequestPayload{Action: api.HookIssueLabelUpdated}, 84 - yamlOn: "on:\n pull_request:\n types: [labeled]", 85 - expected: true, 90 + desc: "HookEventPullRequest(pull_request) `label_updated` action matches GithubEventPullRequest(pull_request) with `label` activity type", 91 + triggeredEvent: webhook_module.HookEventPullRequest, 92 + payload: &api.PullRequestPayload{Action: api.HookIssueLabelUpdated}, 93 + yamlOn: "on:\n pull_request:\n types: [labeled]", 94 + expected: true, 86 95 }, 87 96 { 88 - desc: "HookEventPullRequestReviewComment(pull_request_review_comment) matches GithubEventPullRequestReviewComment(pull_request_review_comment)", 89 - triggedEvent: webhook_module.HookEventPullRequestReviewComment, 90 - payload: &api.PullRequestPayload{Action: api.HookIssueReviewed}, 91 - yamlOn: "on:\n pull_request_review_comment:\n types: [created]", 92 - expected: true, 97 + desc: "HookEventPullRequestReviewComment(pull_request_review_comment) matches GithubEventPullRequestReviewComment(pull_request_review_comment)", 98 + triggeredEvent: webhook_module.HookEventPullRequestReviewComment, 99 + payload: &api.PullRequestPayload{Action: api.HookIssueReviewed}, 100 + yamlOn: "on:\n pull_request_review_comment:\n types: [created]", 101 + expected: true, 93 102 }, 94 103 { 95 - desc: "HookEventPullRequestReviewRejected(pull_request_review_rejected) doesn't match GithubEventPullRequestReview(pull_request_review) with `dismissed` activity type (we don't support `dismissed` at present)", 96 - triggedEvent: webhook_module.HookEventPullRequestReviewRejected, 97 - payload: &api.PullRequestPayload{Action: api.HookIssueReviewed}, 98 - yamlOn: "on:\n pull_request_review:\n types: [dismissed]", 99 - expected: false, 104 + desc: "HookEventPullRequestReviewRejected(pull_request_review_rejected) doesn't match GithubEventPullRequestReview(pull_request_review) with `dismissed` activity type (we don't support `dismissed` at present)", 105 + triggeredEvent: webhook_module.HookEventPullRequestReviewRejected, 106 + payload: &api.PullRequestPayload{Action: api.HookIssueReviewed}, 107 + yamlOn: "on:\n pull_request_review:\n types: [dismissed]", 108 + expected: false, 100 109 }, 101 110 { 102 - desc: "HookEventRelease(release) `published` action matches GithubEventRelease(release) with `published` activity type", 103 - triggedEvent: webhook_module.HookEventRelease, 104 - payload: &api.ReleasePayload{Action: api.HookReleasePublished}, 105 - yamlOn: "on:\n release:\n types: [published]", 106 - expected: true, 111 + desc: "HookEventRelease(release) `published` action matches GithubEventRelease(release) with `published` activity type", 112 + triggeredEvent: webhook_module.HookEventRelease, 113 + payload: &api.ReleasePayload{Action: api.HookReleasePublished}, 114 + yamlOn: "on:\n release:\n types: [published]", 115 + expected: true, 107 116 }, 108 117 { 109 - desc: "HookEventPackage(package) `created` action doesn't match GithubEventRegistryPackage(registry_package) with `updated` activity type", 110 - triggedEvent: webhook_module.HookEventPackage, 111 - payload: &api.PackagePayload{Action: api.HookPackageCreated}, 112 - yamlOn: "on:\n registry_package:\n types: [updated]", 113 - expected: false, 118 + desc: "HookEventRelease(updated) `updated` action matches GithubEventRelease(edited) with `edited` activity type", 119 + triggeredEvent: webhook_module.HookEventRelease, 120 + payload: &api.ReleasePayload{Action: api.HookReleaseUpdated}, 121 + yamlOn: "on:\n release:\n types: [edited]", 122 + expected: true, 123 + }, 124 + 125 + { 126 + desc: "HookEventPackage(package) `created` action doesn't match GithubEventRegistryPackage(registry_package) with `updated` activity type", 127 + triggeredEvent: webhook_module.HookEventPackage, 128 + payload: &api.PackagePayload{Action: api.HookPackageCreated}, 129 + yamlOn: "on:\n registry_package:\n types: [updated]", 130 + expected: false, 114 131 }, 115 132 { 116 - desc: "HookEventWiki(wiki) matches GithubEventGollum(gollum)", 117 - triggedEvent: webhook_module.HookEventWiki, 118 - payload: nil, 119 - yamlOn: "on: gollum", 120 - expected: true, 133 + desc: "HookEventWiki(wiki) matches GithubEventGollum(gollum)", 134 + triggeredEvent: webhook_module.HookEventWiki, 135 + payload: nil, 136 + yamlOn: "on: gollum", 137 + expected: true, 121 138 }, 122 139 { 123 - desc: "HookEventSchedue(schedule) matches GithubEventSchedule(schedule)", 124 - triggedEvent: webhook_module.HookEventSchedule, 125 - payload: nil, 126 - yamlOn: "on: schedule", 127 - expected: true, 140 + desc: "HookEventSchedule(schedule) matches GithubEventSchedule(schedule)", 141 + triggeredEvent: webhook_module.HookEventSchedule, 142 + payload: nil, 143 + yamlOn: "on: schedule", 144 + expected: true, 128 145 }, 129 146 { 130 - desc: "HookEventWorkflowDispatch(workflow_dispatch) matches GithubEventWorkflowDispatch(workflow_dispatch)", 131 - triggedEvent: webhook_module.HookEventWorkflowDispatch, 132 - payload: nil, 133 - yamlOn: "on: workflow_dispatch", 134 - expected: true, 147 + desc: "HookEventWorkflowDispatch(workflow_dispatch) matches GithubEventWorkflowDispatch(workflow_dispatch)", 148 + triggeredEvent: webhook_module.HookEventWorkflowDispatch, 149 + payload: nil, 150 + yamlOn: "on: workflow_dispatch", 151 + expected: true, 135 152 }, 136 153 } 137 154 ··· 140 157 evts, err := GetEventsFromContent([]byte(tc.yamlOn)) 141 158 require.NoError(t, err) 142 159 assert.Len(t, evts, 1) 143 - assert.Equal(t, tc.expected, detectMatched(nil, tc.commit, tc.triggedEvent, tc.payload, evts[0])) 160 + assert.Equal(t, tc.expected, detectMatched(nil, tc.commit, tc.triggeredEvent, tc.payload, evts[0])) 144 161 }) 145 162 } 146 163 }
+6 -3
modules/forgefed/forgefed.go
··· 16 16 switch typ { 17 17 case RepositoryType: 18 18 return RepositoryNew(""), nil 19 + default: 20 + return ap.GetItemByType(typ) 19 21 } 20 - return ap.GetItemByType(typ) 21 22 } 22 23 23 24 // JSONUnmarshalerFn is the function that will load the data from a fastjson.Value into an Item ··· 28 29 return OnRepository(i, func(r *Repository) error { 29 30 return JSONLoadRepository(val, r) 30 31 }) 32 + default: 33 + return nil 31 34 } 32 - return nil 33 35 } 34 36 35 37 // NotEmpty is the function that checks if an object is empty ··· 44 46 return false 45 47 } 46 48 return ap.NotEmpty(r.Actor) 49 + default: 50 + return ap.NotEmpty(i) 47 51 } 48 - return ap.NotEmpty(i) 49 52 }
+1 -2
modules/markup/markdown/callout/github.go
··· 34 34 return ast.WalkContinue, nil 35 35 } 36 36 37 - switch v := n.(type) { 38 - case *ast.Blockquote: 37 + if v, ok := n.(*ast.Blockquote); ok { 39 38 if v.ChildCount() == 0 { 40 39 return ast.WalkContinue, nil 41 40 }
+1 -2
modules/markup/markdown/callout/github_legacy.go
··· 23 23 return ast.WalkContinue, nil 24 24 } 25 25 26 - switch v := n.(type) { 27 - case *ast.Blockquote: 26 + if v, ok := n.(*ast.Blockquote); ok { 28 27 if v.ChildCount() == 0 { 29 28 return ast.WalkContinue, nil 30 29 }
+1 -2
modules/repository/license.go
··· 98 98 99 99 // Some special placeholders for specific licenses. 100 100 // It's unsafe to apply them to all licenses. 101 - switch name { 102 - case "0BSD": 101 + if name == "0BSD" { 103 102 return &licensePlaceholder{ 104 103 Owner: []string{"AUTHOR"}, 105 104 Email: []string{"EMAIL"},
+1 -2
modules/session/redis.go
··· 122 122 uri := nosql.ToRedisURI(configs) 123 123 124 124 for k, v := range uri.Query() { 125 - switch k { 126 - case "prefix": 125 + if k == "prefix" { 127 126 p.prefix = v[0] 128 127 } 129 128 }
+2 -1
modules/structs/task.go
··· 13 13 switch taskType { 14 14 case TaskTypeMigrateRepo: 15 15 return "Migrate Repository" 16 + default: 17 + return "" 16 18 } 17 - return "" 18 19 } 19 20 20 21 // TaskStatus defines task status
+1 -2
routers/web/user/package.go
··· 208 208 groups := make(container.Set[string]) 209 209 for _, f := range pd.Files { 210 210 for _, pp := range f.Properties { 211 - switch pp.Name { 212 - case arch_model.PropertyDistribution: 211 + if pp.Name == arch_model.PropertyDistribution { 213 212 groups.Add(pp.Value) 214 213 } 215 214 }
+3 -6
services/actions/workflows.go
··· 83 83 } 84 84 continue 85 85 } 86 - } else { 87 - switch input.Type { 88 - case "boolean": 89 - // Since "boolean" inputs are rendered as a checkbox in html, the value inside the form is "on" 90 - val = strconv.FormatBool(val == "on") 91 - } 86 + } else if input.Type == "boolean" { 87 + // Since "boolean" inputs are rendered as a checkbox in html, the value inside the form is "on" 88 + val = strconv.FormatBool(val == "on") 92 89 } 93 90 inputs[key] = val 94 91 }
+2 -2
services/mailer/incoming/incoming_handler.go
··· 181 181 } 182 182 183 183 return issues_model.CreateOrUpdateIssueWatch(ctx, doer.ID, issue.ID, false) 184 + default: 185 + return fmt.Errorf("unsupported unsubscribe reference: %v", ref) 184 186 } 185 - 186 - return fmt.Errorf("unsupported unsubscribe reference: %v", ref) 187 187 }
+1 -2
services/webhook/dingtalk.go
··· 160 160 // Review implements PayloadConvertor Review method 161 161 func (dc dingtalkConvertor) Review(p *api.PullRequestPayload, event webhook_module.HookEventType) (DingtalkPayload, error) { 162 162 var text, title string 163 - switch p.Action { 164 - case api.HookIssueReviewed: 163 + if p.Action == api.HookIssueReviewed { 165 164 action, err := parseHookPullRequestEventType(event) 166 165 if err != nil { 167 166 return DingtalkPayload{}, err
+1 -2
services/webhook/discord.go
··· 215 215 func (d discordConvertor) Review(p *api.PullRequestPayload, event webhook_module.HookEventType) (DiscordPayload, error) { 216 216 var text, title string 217 217 var color int 218 - switch p.Action { 219 - case api.HookIssueReviewed: 218 + if p.Action == api.HookIssueReviewed { 220 219 action, err := parseHookPullRequestEventType(event) 221 220 if err != nil { 222 221 return DiscordPayload{}, err
+1 -2
services/webhook/matrix.go
··· 237 237 repoLink := htmlLinkFormatter(p.Repository.HTMLURL, p.Repository.FullName) 238 238 var text string 239 239 240 - switch p.Action { 241 - case api.HookIssueReviewed: 240 + if p.Action == api.HookIssueReviewed { 242 241 action, err := parseHookPullRequestEventType(event) 243 242 if err != nil { 244 243 return MatrixPayload{}, err
+1 -2
services/webhook/msteams.go
··· 225 225 func (m msteamsConvertor) Review(p *api.PullRequestPayload, event webhook_module.HookEventType) (MSTeamsPayload, error) { 226 226 var text, title string 227 227 var color int 228 - switch p.Action { 229 - case api.HookIssueReviewed: 228 + if p.Action == api.HookIssueReviewed { 230 229 action, err := parseHookPullRequestEventType(event) 231 230 if err != nil { 232 231 return MSTeamsPayload{}, err
+1 -2
services/webhook/slack.go
··· 289 289 repoLink := SlackLinkFormatter(p.Repository.HTMLURL, p.Repository.FullName) 290 290 var text string 291 291 292 - switch p.Action { 293 - case api.HookIssueReviewed: 292 + if p.Action == api.HookIssueReviewed { 294 293 action, err := parseHookPullRequestEventType(event) 295 294 if err != nil { 296 295 return SlackPayload{}, err
+1 -2
services/webhook/telegram.go
··· 164 164 // Review implements PayloadConvertor Review method 165 165 func (t telegramConvertor) Review(p *api.PullRequestPayload, event webhook_module.HookEventType) (TelegramPayload, error) { 166 166 var text, attachmentText string 167 - switch p.Action { 168 - case api.HookIssueReviewed: 167 + if p.Action == api.HookIssueReviewed { 169 168 action, err := parseHookPullRequestEventType(event) 170 169 if err != nil { 171 170 return TelegramPayload{}, err
+1 -2
services/webhook/wechatwork.go
··· 154 154 // Review implements PayloadConvertor Review method 155 155 func (wc wechatworkConvertor) Review(p *api.PullRequestPayload, event webhook_module.HookEventType) (WechatworkPayload, error) { 156 156 var text, title string 157 - switch p.Action { 158 - case api.HookIssueReviewed: 157 + if p.Action == api.HookIssueReviewed { 159 158 action, err := parseHookPullRequestEventType(event) 160 159 if err != nil { 161 160 return WechatworkPayload{}, err