Skip to content

Commit 5c24a90

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Fix duplicate status check contexts (go-gitea#30660) Fix issue label rendering in the issue popup (go-gitea#30763) Fix all rounded borders, change affected tab menus to pills (go-gitea#30707) Rename CodeIndexerEnabled to IsRepoIndexerEnabled (go-gitea#30762) Remove fomantic dimmer module (go-gitea#30723) Resolve lint for unused parameter and unnecessary type arguments (go-gitea#30750) Add support for npm bundleDependencies (go-gitea#30751) Fix cross-compilation errors when CGO_CFLAGS/CGO_LDFLAGS is set (go-gitea#30749)
2 parents 9895397 + 7ad5031 commit 5c24a90

File tree

92 files changed

+398
-1393
lines changed

Some content is hidden

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

92 files changed

+398
-1393
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ generate-backend: $(TAGS_PREREQ) generate-go
778778
.PHONY: generate-go
779779
generate-go: $(TAGS_PREREQ)
780780
@echo "Running go generate..."
781-
@CC= GOOS= GOARCH= $(GO) generate -tags '$(TAGS)' ./...
781+
@CC= GOOS= GOARCH= CGO_ENABLED=0 $(GO) generate -tags '$(TAGS)' ./...
782782

783783
.PHONY: security-check
784784
security-check:

models/git/commit_status.go

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -397,36 +397,16 @@ func GetLatestCommitStatusForRepoCommitIDs(ctx context.Context, repoID int64, co
397397

398398
// FindRepoRecentCommitStatusContexts returns repository's recent commit status contexts
399399
func FindRepoRecentCommitStatusContexts(ctx context.Context, repoID int64, before time.Duration) ([]string, error) {
400-
type result struct {
401-
Index int64
402-
SHA string
403-
}
404-
getBase := func() *xorm.Session {
405-
return db.GetEngine(ctx).Table(&CommitStatus{}).Where("repo_id = ?", repoID)
406-
}
407-
408400
start := timeutil.TimeStampNow().AddDuration(-before)
409-
results := make([]result, 0, 10)
410401

411-
sess := getBase().And("updated_unix >= ?", start).
412-
Select("max( `index` ) as `index`, sha").
413-
GroupBy("context_hash, sha").OrderBy("max( `index` ) desc")
414-
415-
err := sess.Find(&results)
416-
if err != nil {
402+
var contexts []string
403+
if err := db.GetEngine(ctx).Table("commit_status").
404+
Where("repo_id = ?", repoID).And("updated_unix >= ?", start).
405+
Cols("context").Distinct().Find(&contexts); err != nil {
417406
return nil, err
418407
}
419408

420-
contexts := make([]string, 0, len(results))
421-
if len(results) == 0 {
422-
return contexts, nil
423-
}
424-
425-
conds := make([]builder.Cond, 0, len(results))
426-
for _, result := range results {
427-
conds = append(conds, builder.Eq{"`index`": result.Index, "sha": result.SHA})
428-
}
429-
return contexts, getBase().And(builder.Or(conds...)).Select("context").Find(&contexts)
409+
return contexts, nil
430410
}
431411

432412
// NewCommitStatusOptions holds options for creating a CommitStatus

models/git/commit_status_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ package git_test
55

66
import (
77
"testing"
8+
"time"
89

910
"code.gitea.io/gitea/models/db"
1011
git_model "code.gitea.io/gitea/models/git"
1112
repo_model "code.gitea.io/gitea/models/repo"
1213
"code.gitea.io/gitea/models/unittest"
14+
user_model "code.gitea.io/gitea/models/user"
15+
"code.gitea.io/gitea/modules/git"
16+
"code.gitea.io/gitea/modules/gitrepo"
1317
"code.gitea.io/gitea/modules/structs"
1418

1519
"github.com/stretchr/testify/assert"
@@ -175,3 +179,55 @@ func Test_CalcCommitStatus(t *testing.T) {
175179
assert.Equal(t, kase.expected, git_model.CalcCommitStatus(kase.statuses))
176180
}
177181
}
182+
183+
func TestFindRepoRecentCommitStatusContexts(t *testing.T) {
184+
assert.NoError(t, unittest.PrepareTestDatabase())
185+
186+
repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
187+
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
188+
gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo2)
189+
assert.NoError(t, err)
190+
defer gitRepo.Close()
191+
192+
commit, err := gitRepo.GetBranchCommit(repo2.DefaultBranch)
193+
assert.NoError(t, err)
194+
195+
defer func() {
196+
_, err := db.DeleteByBean(db.DefaultContext, &git_model.CommitStatus{
197+
RepoID: repo2.ID,
198+
CreatorID: user2.ID,
199+
SHA: commit.ID.String(),
200+
})
201+
assert.NoError(t, err)
202+
}()
203+
204+
err = git_model.NewCommitStatus(db.DefaultContext, git_model.NewCommitStatusOptions{
205+
Repo: repo2,
206+
Creator: user2,
207+
SHA: commit.ID,
208+
CommitStatus: &git_model.CommitStatus{
209+
State: structs.CommitStatusFailure,
210+
TargetURL: "https://example.com/tests/",
211+
Context: "compliance/lint-backend",
212+
},
213+
})
214+
assert.NoError(t, err)
215+
216+
err = git_model.NewCommitStatus(db.DefaultContext, git_model.NewCommitStatusOptions{
217+
Repo: repo2,
218+
Creator: user2,
219+
SHA: commit.ID,
220+
CommitStatus: &git_model.CommitStatus{
221+
State: structs.CommitStatusSuccess,
222+
TargetURL: "https://example.com/tests/",
223+
Context: "compliance/lint-backend",
224+
},
225+
})
226+
assert.NoError(t, err)
227+
228+
contexts, err := git_model.FindRepoRecentCommitStatusContexts(db.DefaultContext, repo2.ID, time.Hour)
229+
assert.NoError(t, err)
230+
if assert.Len(t, contexts, 1) {
231+
assert.Equal(t, "compliance/lint-backend", contexts[0])
232+
}
233+
}

models/issues/issue_xref_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestXRef_AddCrossReferences(t *testing.T) {
3434

3535
// Comment on PR to reopen issue #1
3636
content = fmt.Sprintf("content2, reopens #%d", itarget.Index)
37-
c := testCreateComment(t, 1, 2, pr.ID, content)
37+
c := testCreateComment(t, 2, pr.ID, content)
3838
ref = unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{IssueID: itarget.ID, RefIssueID: pr.ID, RefCommentID: c.ID})
3939
assert.Equal(t, issues_model.CommentTypeCommentRef, ref.Type)
4040
assert.Equal(t, pr.RepoID, ref.RefRepoID)
@@ -104,18 +104,18 @@ func TestXRef_ResolveCrossReferences(t *testing.T) {
104104
pr := testCreatePR(t, 1, 2, "titlepr", fmt.Sprintf("closes #%d", i1.Index))
105105
rp := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{IssueID: i1.ID, RefIssueID: pr.Issue.ID, RefCommentID: 0})
106106

107-
c1 := testCreateComment(t, 1, 2, pr.Issue.ID, fmt.Sprintf("closes #%d", i2.Index))
107+
c1 := testCreateComment(t, 2, pr.Issue.ID, fmt.Sprintf("closes #%d", i2.Index))
108108
r1 := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{IssueID: i2.ID, RefIssueID: pr.Issue.ID, RefCommentID: c1.ID})
109109

110110
// Must be ignored
111-
c2 := testCreateComment(t, 1, 2, pr.Issue.ID, fmt.Sprintf("mentions #%d", i2.Index))
111+
c2 := testCreateComment(t, 2, pr.Issue.ID, fmt.Sprintf("mentions #%d", i2.Index))
112112
unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{IssueID: i2.ID, RefIssueID: pr.Issue.ID, RefCommentID: c2.ID})
113113

114114
// Must be superseded by c4/r4
115-
c3 := testCreateComment(t, 1, 2, pr.Issue.ID, fmt.Sprintf("reopens #%d", i3.Index))
115+
c3 := testCreateComment(t, 2, pr.Issue.ID, fmt.Sprintf("reopens #%d", i3.Index))
116116
unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{IssueID: i3.ID, RefIssueID: pr.Issue.ID, RefCommentID: c3.ID})
117117

118-
c4 := testCreateComment(t, 1, 2, pr.Issue.ID, fmt.Sprintf("closes #%d", i3.Index))
118+
c4 := testCreateComment(t, 2, pr.Issue.ID, fmt.Sprintf("closes #%d", i3.Index))
119119
r4 := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{IssueID: i3.ID, RefIssueID: pr.Issue.ID, RefCommentID: c4.ID})
120120

121121
refs, err := pr.ResolveCrossReferences(db.DefaultContext)
@@ -168,7 +168,7 @@ func testCreatePR(t *testing.T, repo, doer int64, title, content string) *issues
168168
return pr
169169
}
170170

171-
func testCreateComment(t *testing.T, repo, doer, issue int64, content string) *issues_model.Comment {
171+
func testCreateComment(t *testing.T, doer, issue int64, content string) *issues_model.Comment {
172172
d := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: doer})
173173
i := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: issue})
174174
c := &issues_model.Comment{Type: issues_model.CommentTypeComment, PosterID: doer, Poster: d, IssueID: issue, Issue: i, Content: content}

models/organization/org_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,15 +291,15 @@ func TestAccessibleReposEnv_CountRepos(t *testing.T) {
291291
func TestAccessibleReposEnv_RepoIDs(t *testing.T) {
292292
assert.NoError(t, unittest.PrepareTestDatabase())
293293
org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 3})
294-
testSuccess := func(userID, _, pageSize int64, expectedRepoIDs []int64) {
294+
testSuccess := func(userID int64, expectedRepoIDs []int64) {
295295
env, err := organization.AccessibleReposEnv(db.DefaultContext, org, userID)
296296
assert.NoError(t, err)
297297
repoIDs, err := env.RepoIDs(1, 100)
298298
assert.NoError(t, err)
299299
assert.Equal(t, expectedRepoIDs, repoIDs)
300300
}
301-
testSuccess(2, 1, 100, []int64{3, 5, 32})
302-
testSuccess(4, 0, 100, []int64{3, 32})
301+
testSuccess(2, []int64{3, 5, 32})
302+
testSuccess(4, []int64{3, 32})
303303
}
304304

305305
func TestAccessibleReposEnv_Repos(t *testing.T) {

modules/actions/workflows.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,14 @@ func detectMatched(gitRepo *git.Repository, commit *git.Commit, triggedEvent web
208208
webhook_module.HookEventIssueAssign,
209209
webhook_module.HookEventIssueLabel,
210210
webhook_module.HookEventIssueMilestone:
211-
return matchIssuesEvent(commit, payload.(*api.IssuePayload), evt)
211+
return matchIssuesEvent(payload.(*api.IssuePayload), evt)
212212

213213
case // issue_comment
214214
webhook_module.HookEventIssueComment,
215215
// `pull_request_comment` is same as `issue_comment`
216216
// See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_comment-use-issue_comment
217217
webhook_module.HookEventPullRequestComment:
218-
return matchIssueCommentEvent(commit, payload.(*api.IssueCommentPayload), evt)
218+
return matchIssueCommentEvent(payload.(*api.IssueCommentPayload), evt)
219219

220220
case // pull_request
221221
webhook_module.HookEventPullRequest,
@@ -229,19 +229,19 @@ func detectMatched(gitRepo *git.Repository, commit *git.Commit, triggedEvent web
229229
case // pull_request_review
230230
webhook_module.HookEventPullRequestReviewApproved,
231231
webhook_module.HookEventPullRequestReviewRejected:
232-
return matchPullRequestReviewEvent(commit, payload.(*api.PullRequestPayload), evt)
232+
return matchPullRequestReviewEvent(payload.(*api.PullRequestPayload), evt)
233233

234234
case // pull_request_review_comment
235235
webhook_module.HookEventPullRequestReviewComment:
236-
return matchPullRequestReviewCommentEvent(commit, payload.(*api.PullRequestPayload), evt)
236+
return matchPullRequestReviewCommentEvent(payload.(*api.PullRequestPayload), evt)
237237

238238
case // release
239239
webhook_module.HookEventRelease:
240-
return matchReleaseEvent(commit, payload.(*api.ReleasePayload), evt)
240+
return matchReleaseEvent(payload.(*api.ReleasePayload), evt)
241241

242242
case // registry_package
243243
webhook_module.HookEventPackage:
244-
return matchPackageEvent(commit, payload.(*api.PackagePayload), evt)
244+
return matchPackageEvent(payload.(*api.PackagePayload), evt)
245245

246246
default:
247247
log.Warn("unsupported event %q", triggedEvent)
@@ -347,7 +347,7 @@ func matchPushEvent(commit *git.Commit, pushPayload *api.PushPayload, evt *jobpa
347347
return matchTimes == len(evt.Acts())
348348
}
349349

350-
func matchIssuesEvent(commit *git.Commit, issuePayload *api.IssuePayload, evt *jobparser.Event) bool {
350+
func matchIssuesEvent(issuePayload *api.IssuePayload, evt *jobparser.Event) bool {
351351
// with no special filter parameters
352352
if len(evt.Acts()) == 0 {
353353
return true
@@ -495,7 +495,7 @@ func matchPullRequestEvent(gitRepo *git.Repository, commit *git.Commit, prPayloa
495495
return activityTypeMatched && matchTimes == len(evt.Acts())
496496
}
497497

498-
func matchIssueCommentEvent(commit *git.Commit, issueCommentPayload *api.IssueCommentPayload, evt *jobparser.Event) bool {
498+
func matchIssueCommentEvent(issueCommentPayload *api.IssueCommentPayload, evt *jobparser.Event) bool {
499499
// with no special filter parameters
500500
if len(evt.Acts()) == 0 {
501501
return true
@@ -527,7 +527,7 @@ func matchIssueCommentEvent(commit *git.Commit, issueCommentPayload *api.IssueCo
527527
return matchTimes == len(evt.Acts())
528528
}
529529

530-
func matchPullRequestReviewEvent(commit *git.Commit, prPayload *api.PullRequestPayload, evt *jobparser.Event) bool {
530+
func matchPullRequestReviewEvent(prPayload *api.PullRequestPayload, evt *jobparser.Event) bool {
531531
// with no special filter parameters
532532
if len(evt.Acts()) == 0 {
533533
return true
@@ -576,7 +576,7 @@ func matchPullRequestReviewEvent(commit *git.Commit, prPayload *api.PullRequestP
576576
return matchTimes == len(evt.Acts())
577577
}
578578

579-
func matchPullRequestReviewCommentEvent(commit *git.Commit, prPayload *api.PullRequestPayload, evt *jobparser.Event) bool {
579+
func matchPullRequestReviewCommentEvent(prPayload *api.PullRequestPayload, evt *jobparser.Event) bool {
580580
// with no special filter parameters
581581
if len(evt.Acts()) == 0 {
582582
return true
@@ -625,7 +625,7 @@ func matchPullRequestReviewCommentEvent(commit *git.Commit, prPayload *api.PullR
625625
return matchTimes == len(evt.Acts())
626626
}
627627

628-
func matchReleaseEvent(commit *git.Commit, payload *api.ReleasePayload, evt *jobparser.Event) bool {
628+
func matchReleaseEvent(payload *api.ReleasePayload, evt *jobparser.Event) bool {
629629
// with no special filter parameters
630630
if len(evt.Acts()) == 0 {
631631
return true
@@ -662,7 +662,7 @@ func matchReleaseEvent(commit *git.Commit, payload *api.ReleasePayload, evt *job
662662
return matchTimes == len(evt.Acts())
663663
}
664664

665-
func matchPackageEvent(commit *git.Commit, payload *api.PackagePayload, evt *jobparser.Event) bool {
665+
func matchPackageEvent(payload *api.PackagePayload, evt *jobparser.Event) bool {
666666
// with no special filter parameters
667667
if len(evt.Acts()) == 0 {
668668
return true

modules/git/commit_info_nogogit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func (tes Entries) GetCommitsInfo(ctx context.Context, commit *Commit, treePath
2929
var revs map[string]*Commit
3030
if commit.repo.LastCommitCache != nil {
3131
var unHitPaths []string
32-
revs, unHitPaths, err = getLastCommitForPathsByCache(ctx, commit.ID.String(), treePath, entryPaths, commit.repo.LastCommitCache)
32+
revs, unHitPaths, err = getLastCommitForPathsByCache(commit.ID.String(), treePath, entryPaths, commit.repo.LastCommitCache)
3333
if err != nil {
3434
return nil, nil, err
3535
}
@@ -97,7 +97,7 @@ func (tes Entries) GetCommitsInfo(ctx context.Context, commit *Commit, treePath
9797
return commitsInfo, treeCommit, nil
9898
}
9999

100-
func getLastCommitForPathsByCache(ctx context.Context, commitID, treePath string, paths []string, cache *LastCommitCache) (map[string]*Commit, []string, error) {
100+
func getLastCommitForPathsByCache(commitID, treePath string, paths []string, cache *LastCommitCache) (map[string]*Commit, []string, error) {
101101
var unHitEntryPaths []string
102102
results := make(map[string]*Commit)
103103
for _, p := range paths {

modules/git/parse_gogit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
)
1919

2020
// ParseTreeEntries parses the output of a `git ls-tree -l` command.
21-
func ParseTreeEntries(h ObjectFormat, data []byte) ([]*TreeEntry, error) {
21+
func ParseTreeEntries(data []byte) ([]*TreeEntry, error) {
2222
return parseTreeEntries(data, nil)
2323
}
2424

modules/git/parse_gogit_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func TestParseTreeEntries(t *testing.T) {
6767
}
6868

6969
for _, testCase := range testCases {
70-
entries, err := ParseTreeEntries(Sha1ObjectFormat, []byte(testCase.Input))
70+
entries, err := ParseTreeEntries([]byte(testCase.Input))
7171
assert.NoError(t, err)
7272
if len(entries) > 1 {
7373
fmt.Println(testCase.Expected[0].ID)

modules/git/parse_nogogit.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ import (
1717
)
1818

1919
// ParseTreeEntries parses the output of a `git ls-tree -l` command.
20-
func ParseTreeEntries(objectFormat ObjectFormat, data []byte) ([]*TreeEntry, error) {
21-
return parseTreeEntries(objectFormat, data, nil)
20+
func ParseTreeEntries(data []byte) ([]*TreeEntry, error) {
21+
return parseTreeEntries(data, nil)
2222
}
2323

2424
var sepSpace = []byte{' '}
2525

26-
func parseTreeEntries(objectFormat ObjectFormat, data []byte, ptree *Tree) ([]*TreeEntry, error) {
26+
func parseTreeEntries(data []byte, ptree *Tree) ([]*TreeEntry, error) {
2727
var err error
2828
entries := make([]*TreeEntry, 0, bytes.Count(data, []byte{'\n'})+1)
2929
for pos := 0; pos < len(data); {

modules/git/parse_nogogit_test.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import (
1212
)
1313

1414
func TestParseTreeEntriesLong(t *testing.T) {
15-
objectFormat := Sha1ObjectFormat
16-
1715
testCases := []struct {
1816
Input string
1917
Expected []*TreeEntry
@@ -56,7 +54,7 @@ func TestParseTreeEntriesLong(t *testing.T) {
5654
},
5755
}
5856
for _, testCase := range testCases {
59-
entries, err := ParseTreeEntries(objectFormat, []byte(testCase.Input))
57+
entries, err := ParseTreeEntries([]byte(testCase.Input))
6058
assert.NoError(t, err)
6159
assert.Len(t, entries, len(testCase.Expected))
6260
for i, entry := range entries {
@@ -66,8 +64,6 @@ func TestParseTreeEntriesLong(t *testing.T) {
6664
}
6765

6866
func TestParseTreeEntriesShort(t *testing.T) {
69-
objectFormat := Sha1ObjectFormat
70-
7167
testCases := []struct {
7268
Input string
7369
Expected []*TreeEntry
@@ -91,7 +87,7 @@ func TestParseTreeEntriesShort(t *testing.T) {
9187
},
9288
}
9389
for _, testCase := range testCases {
94-
entries, err := ParseTreeEntries(objectFormat, []byte(testCase.Input))
90+
entries, err := ParseTreeEntries([]byte(testCase.Input))
9591
assert.NoError(t, err)
9692
assert.Len(t, entries, len(testCase.Expected))
9793
for i, entry := range entries {
@@ -102,7 +98,7 @@ func TestParseTreeEntriesShort(t *testing.T) {
10298

10399
func TestParseTreeEntriesInvalid(t *testing.T) {
104100
// there was a panic: "runtime error: slice bounds out of range" when the input was invalid: #20315
105-
entries, err := ParseTreeEntries(Sha1ObjectFormat, []byte("100644 blob ea0d83c9081af9500ac9f804101b3fd0a5c293af"))
101+
entries, err := ParseTreeEntries([]byte("100644 blob ea0d83c9081af9500ac9f804101b3fd0a5c293af"))
106102
assert.Error(t, err)
107103
assert.Len(t, entries, 0)
108104
}

0 commit comments

Comments
 (0)