Skip to content

Commit a22e5f8

Browse files
kyttaGusted
authored andcommitted
fix: Allow SHA-256 in PR commit URLs (#10309)
Closes #9129. I decided to try myself in contributing to Forgejo after having found this bug mentioned on Fedi. I have also added a basic test for this behaviour, but this means that this PR adds a SHA-256 repo to the fixture set, so it can be reused in other tests. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10309 Reviewed-by: Lucas <sclu1034@noreply.codeberg.org> Reviewed-by: 0ko <0ko@noreply.codeberg.org> Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: Nikita Karamov <me@kytta.dev> Co-committed-by: Nikita Karamov <me@kytta.dev>
1 parent 0398fa8 commit a22e5f8

46 files changed

Lines changed: 260 additions & 32 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

models/fixtures/branch.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,25 @@
6969
is_deleted: false
7070
deleted_by_id: 0
7171
deleted_unix: 0
72+
73+
- id: 17
74+
repo_id: 66
75+
name: 'master'
76+
commit_id: '7b299a0be8450b8304e30f1f7feea2383903e02bb4b7600d37eb2bb6e934daba'
77+
commit_message: 'Initial commit'
78+
commit_time: 1764879244
79+
pusher_id: 2
80+
is_deleted: false
81+
deleted_by_id: 0
82+
deleted_unix: 0
83+
84+
- id: 18
85+
repo_id: 66
86+
name: 'branch2'
87+
commit_id: '004581b3bb63754502364664021404490ee747ce58e98d27c046f2e46f5f2f55'
88+
commit_message: 'PR'
89+
commit_time: 1764879438
90+
pusher_id: 2
91+
is_deleted: false
92+
deleted_by_id: 0
93+
deleted_unix: 0

models/fixtures/issue.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,3 +372,19 @@
372372
created_unix: 1707270422
373373
updated_unix: 1707270422
374374
is_locked: false
375+
376+
- id: 24
377+
repo_id: 66
378+
index: 1
379+
poster_id: 2
380+
original_author_id: 0
381+
name: PR
382+
content: ''
383+
milestone_id: 0
384+
priority: 0
385+
is_closed: false
386+
is_pull: true
387+
num_comments: 0
388+
created_unix: 1764879458
389+
updated_unix: 1764879458
390+
is_locked: false

models/fixtures/issue_index.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@
2525
-
2626
group_id: 51
2727
max_index: 1
28+
29+
- group_id: 66
30+
max_index: 1

models/fixtures/pull_request.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,16 @@
119119
index: 1
120120
head_repo_id: 61
121121
base_repo_id: 61
122+
123+
- id: 12
124+
type: 0 # gitea pull request
125+
status: 2 # mergeable
126+
issue_id: 24
127+
index: 1
128+
head_repo_id: 66
129+
base_repo_id: 66
130+
head_branch: branch2
131+
base_branch: master
132+
merge_base: 004581b3bb63754502364664021404490ee747ce58e98d27c046f2e46f5f2f55
133+
has_merged: false
134+

models/fixtures/repo_unit.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,3 +802,34 @@
802802
type: 10
803803
config: "{}"
804804
created_unix: 946684810
805+
806+
-
807+
id: 116
808+
repo_id: 66
809+
type: 1
810+
config: "{}"
811+
created_unix: 1764879302
812+
813+
- id: 117
814+
repo_id: 66
815+
type: 2
816+
config: "{\"EnableTimetracker\":true,\"AllowOnlyContributorsToTrackTime\":true,\"EnableDependencies\":true}"
817+
created_unix: 1764879302
818+
819+
- id: 118
820+
repo_id: 66
821+
type: 3
822+
config: "{\"IgnoreWhitespaceConflicts\":false,\"AllowMerge\":true,\"AllowRebase\":true,\"AllowRebaseMerge\":true,\"AllowSquash\":true}"
823+
created_unix: 1764879302
824+
825+
- id: 119
826+
repo_id: 66
827+
type: 4
828+
config: "{}"
829+
created_unix: 1764879302
830+
831+
- id: 120
832+
repo_id: 66
833+
type: 5
834+
config: "{}"
835+
created_unix: 1764879302

models/fixtures/repository.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,3 +1684,34 @@
16841684
is_fsck_enabled: true
16851685
close_issues_via_commit_in_any_branch: false
16861686
topics: '[]'
1687+
1688+
-
1689+
id: 66
1690+
owner_id: 2
1691+
owner_name: user2
1692+
lower_name: repo256
1693+
name: repo256
1694+
default_branch: master
1695+
num_watches: 0
1696+
num_stars: 0
1697+
num_forks: 0
1698+
num_milestones: 0
1699+
num_closed_milestones: 0
1700+
num_projects: 0
1701+
num_closed_projects: 0
1702+
is_private: false
1703+
is_empty: false
1704+
is_archived: false
1705+
is_mirror: false
1706+
status: 0
1707+
is_fork: false
1708+
fork_id: 0
1709+
is_template: false
1710+
template_id: 0
1711+
size: 24586
1712+
is_fsck_enabled: true
1713+
close_issues_via_commit_in_any_branch: false
1714+
created_unix: 1764879302
1715+
updated_unix: 1764879302
1716+
topics: '[]'
1717+
object_format_name: 'sha256'

models/fixtures/user.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
num_followers: 2
7171
num_following: 1
7272
num_stars: 2
73-
num_repos: 18
73+
num_repos: 19
7474
num_teams: 0
7575
num_members: 0
7676
visibility: 0

models/issues/issue_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ func TestCountIssues(t *testing.T) {
431431
require.NoError(t, unittest.PrepareTestDatabase())
432432
count, err := issues_model.CountIssues(db.DefaultContext, &issues_model.IssuesOptions{})
433433
require.NoError(t, err)
434-
assert.EqualValues(t, 22, count)
434+
assert.EqualValues(t, 23, count)
435435
}
436436

437437
func TestIssueLoadAttributes(t *testing.T) {

models/repo/repo_list_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,12 @@ func getTestCases() []struct {
142142
{
143143
name: "AllPublic/PublicRepositoriesOfUserIncludingCollaborative",
144144
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, AllPublic: true, Template: optional.Some(false)},
145-
count: 35,
145+
count: 36,
146146
},
147147
{
148148
name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborative",
149149
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, Private: true, AllPublic: true, AllLimited: true, Template: optional.Some(false)},
150-
count: 40,
150+
count: 41,
151151
},
152152
{
153153
name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborativeByName",
@@ -162,7 +162,7 @@ func getTestCases() []struct {
162162
{
163163
name: "AllPublic/PublicRepositoriesOfOrganization",
164164
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 17, AllPublic: true, Collaborate: optional.Some(false), Template: optional.Some(false)},
165-
count: 35,
165+
count: 36,
166166
},
167167
{
168168
name: "AllTemplates",
@@ -172,7 +172,7 @@ func getTestCases() []struct {
172172
{
173173
name: "OwnerSlashRepoSearch",
174174
opts: &repo_model.SearchRepoOptions{Keyword: "user/repo2", ListOptions: db.ListOptions{Page: 1, PageSize: 10}, Private: true, OwnerID: 0},
175-
count: 2,
175+
count: 3,
176176
},
177177
{
178178
name: "OwnerSlashSearch",
@@ -420,15 +420,15 @@ func TestSearchRepositoryIDsByCondition(t *testing.T) {
420420
}{
421421
{
422422
user: nil,
423-
repoIDs: []int64{1, 4, 8, 9, 10, 11, 12, 14, 17, 18, 21, 23, 25, 27, 29, 32, 33, 34, 35, 36, 37, 42, 44, 45, 46, 47, 48, 49, 50, 51, 53, 57, 58, 60, 61, 62, 1059},
423+
repoIDs: []int64{1, 4, 8, 9, 10, 11, 12, 14, 17, 18, 21, 23, 25, 27, 29, 32, 33, 34, 35, 36, 37, 42, 44, 45, 46, 47, 48, 49, 50, 51, 53, 57, 58, 60, 61, 62, 66, 1059},
424424
},
425425
{
426426
user: unittest.AssertExistsAndLoadBean(t, &user.User{ID: 4}),
427-
repoIDs: []int64{1, 3, 4, 8, 9, 10, 11, 12, 14, 17, 18, 21, 23, 25, 27, 29, 32, 33, 34, 35, 36, 37, 38, 40, 42, 44, 45, 46, 47, 48, 49, 50, 51, 53, 57, 58, 60, 61, 62, 1001, 1059},
427+
repoIDs: []int64{1, 3, 4, 8, 9, 10, 11, 12, 14, 17, 18, 21, 23, 25, 27, 29, 32, 33, 34, 35, 36, 37, 38, 40, 42, 44, 45, 46, 47, 48, 49, 50, 51, 53, 57, 58, 60, 61, 62, 66, 1001, 1059},
428428
},
429429
{
430430
user: unittest.AssertExistsAndLoadBean(t, &user.User{ID: 5}),
431-
repoIDs: []int64{1, 4, 8, 9, 10, 11, 12, 14, 17, 18, 21, 23, 25, 27, 29, 32, 33, 34, 35, 36, 37, 38, 40, 42, 44, 45, 46, 47, 48, 49, 50, 51, 53, 57, 58, 60, 61, 62, 1001, 1059},
431+
repoIDs: []int64{1, 4, 8, 9, 10, 11, 12, 14, 17, 18, 21, 23, 25, 27, 29, 32, 33, 34, 35, 36, 37, 38, 40, 42, 44, 45, 46, 47, 48, 49, 50, 51, 53, 57, 58, 60, 61, 62, 66, 1001, 1059},
432432
},
433433
}
434434

modules/indexer/issues/indexer_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func searchIssueByID(t *testing.T) {
157157
{
158158
// NOTE: This tests no assignees filtering and also ToSearchOptions() to ensure it will set AssigneeID to 0 when it is passed as -1.
159159
opts: *ToSearchOptions(t.Context(), "", &issues.IssuesOptions{AssigneeID: -1}),
160-
expectedIDs: []int64{22, 21, 16, 15, 14, 13, 12, 11, 20, 5, 19, 18, 10, 7, 4, 9, 8, 3, 2},
160+
expectedIDs: []int64{24, 22, 21, 16, 15, 14, 13, 12, 11, 20, 5, 19, 18, 10, 7, 4, 9, 8, 3, 2},
161161
},
162162
{
163163
opts: SearchOptions{
@@ -222,7 +222,7 @@ func searchIssueIsPull(t *testing.T) {
222222
SearchOptions{
223223
IsPull: optional.Some(true),
224224
},
225-
[]int64{22, 21, 12, 11, 20, 19, 9, 8, 3, 2},
225+
[]int64{24, 22, 21, 12, 11, 20, 19, 9, 8, 3, 2},
226226
},
227227
}
228228
for _, test := range tests {
@@ -242,7 +242,7 @@ func searchIssueIsClosed(t *testing.T) {
242242
SearchOptions{
243243
IsClosed: optional.Some(false),
244244
},
245-
[]int64{22, 21, 17, 16, 15, 14, 13, 12, 11, 20, 6, 19, 18, 10, 7, 9, 8, 3, 2, 1},
245+
[]int64{24, 22, 21, 17, 16, 15, 14, 13, 12, 11, 20, 6, 19, 18, 10, 7, 9, 8, 3, 2, 1},
246246
},
247247
{
248248
SearchOptions{
@@ -305,7 +305,7 @@ func searchIssueByLabelID(t *testing.T) {
305305
SearchOptions{
306306
ExcludedLabelIDs: []int64{1},
307307
},
308-
[]int64{22, 21, 17, 16, 15, 14, 13, 12, 11, 20, 6, 5, 19, 18, 10, 7, 4, 9, 8, 3},
308+
[]int64{24, 22, 21, 17, 16, 15, 14, 13, 12, 11, 20, 6, 5, 19, 18, 10, 7, 4, 9, 8, 3},
309309
},
310310
}
311311
for _, test := range tests {
@@ -325,7 +325,7 @@ func searchIssueByTime(t *testing.T) {
325325
SearchOptions{
326326
UpdatedAfterUnix: optional.Some(int64(0)),
327327
},
328-
[]int64{22, 21, 17, 16, 15, 14, 13, 12, 11, 20, 6, 5, 19, 18, 10, 7, 4, 9, 8, 3, 2, 1},
328+
[]int64{24, 22, 21, 17, 16, 15, 14, 13, 12, 11, 20, 6, 5, 19, 18, 10, 7, 4, 9, 8, 3, 2, 1},
329329
},
330330
}
331331
for _, test := range tests {
@@ -345,7 +345,7 @@ func searchIssueWithOrder(t *testing.T) {
345345
SearchOptions{
346346
SortBy: internal.SortByCreatedAsc,
347347
},
348-
[]int64{1, 2, 3, 8, 9, 4, 7, 10, 18, 19, 5, 6, 20, 11, 12, 13, 14, 15, 16, 17, 21, 22},
348+
[]int64{1, 2, 3, 8, 9, 4, 7, 10, 18, 19, 5, 6, 20, 11, 12, 13, 14, 15, 16, 17, 21, 22, 24},
349349
},
350350
}
351351
for _, test := range tests {
@@ -400,8 +400,8 @@ func searchIssueWithPaginator(t *testing.T) {
400400
PageSize: 5,
401401
},
402402
},
403-
[]int64{22, 21, 17, 16, 15},
404-
22,
403+
[]int64{24, 22, 21, 17, 16},
404+
23,
405405
},
406406
}
407407
for _, test := range tests {

0 commit comments

Comments
 (0)