Skip to content

Commit 3597d77

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Fix bugs in rerunning jobs (go-gitea#29955) remove PATH and GOPATH modification in Makefile (go-gitea#29978) Refactor external URL detection (go-gitea#29973) Refactor repo header/list (go-gitea#29969) Fix various loading states, remove `.loading` class (go-gitea#29920) Update register application URL for GitLab (go-gitea#29959) Refactor StringsToInt64s (go-gitea#29967) Switch to happy-dom for testing (go-gitea#29948) Performance improvements for pull request list page (go-gitea#29900)
2 parents 1be56f1 + 2f060c5 commit 3597d77

Some content is hidden

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

57 files changed

+711
-1359
lines changed

Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ DOCKER_TAG ?= latest
4242
DOCKER_REF := $(DOCKER_IMAGE):$(DOCKER_TAG)
4343

4444
ifeq ($(HAS_GO), yes)
45-
GOPATH ?= $(shell $(GO) env GOPATH)
46-
export PATH := $(GOPATH)/bin:$(PATH)
47-
4845
CGO_EXTRA_CFLAGS := -DSQLITE_MAX_VARIABLE_NUMBER=32766
4946
CGO_CFLAGS ?= $(shell $(GO) env CGO_CFLAGS) $(CGO_EXTRA_CFLAGS)
5047
endif

models/activities/notification_list.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
user_model "code.gitea.io/gitea/models/user"
1515
"code.gitea.io/gitea/modules/container"
1616
"code.gitea.io/gitea/modules/log"
17+
"code.gitea.io/gitea/modules/util"
1718

1819
"xorm.io/builder"
1920
)
@@ -470,3 +471,31 @@ func (nl NotificationList) LoadComments(ctx context.Context) ([]int, error) {
470471
}
471472
return failures, nil
472473
}
474+
475+
// LoadIssuePullRequests loads all issues' pull requests if possible
476+
func (nl NotificationList) LoadIssuePullRequests(ctx context.Context) error {
477+
issues := make(map[int64]*issues_model.Issue, len(nl))
478+
for _, notification := range nl {
479+
if notification.Issue != nil && notification.Issue.IsPull && notification.Issue.PullRequest == nil {
480+
issues[notification.Issue.ID] = notification.Issue
481+
}
482+
}
483+
484+
if len(issues) == 0 {
485+
return nil
486+
}
487+
488+
pulls, err := issues_model.GetPullRequestByIssueIDs(ctx, util.KeysOfMap(issues))
489+
if err != nil {
490+
return err
491+
}
492+
493+
for _, pull := range pulls {
494+
if issue := issues[pull.IssueID]; issue != nil {
495+
issue.PullRequest = pull
496+
issue.PullRequest.Issue = issue
497+
}
498+
}
499+
500+
return nil
501+
}

models/issues/issue.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -193,20 +193,6 @@ func (issue *Issue) IsTimetrackerEnabled(ctx context.Context) bool {
193193
return issue.Repo.IsTimetrackerEnabled(ctx)
194194
}
195195

196-
// GetPullRequest returns the issue pull request
197-
func (issue *Issue) GetPullRequest(ctx context.Context) (pr *PullRequest, err error) {
198-
if !issue.IsPull {
199-
return nil, fmt.Errorf("Issue is not a pull request")
200-
}
201-
202-
pr, err = GetPullRequestByIssueID(ctx, issue.ID)
203-
if err != nil {
204-
return nil, err
205-
}
206-
pr.Issue = issue
207-
return pr, err
208-
}
209-
210196
// LoadPoster loads poster
211197
func (issue *Issue) LoadPoster(ctx context.Context) (err error) {
212198
if issue.Poster == nil && issue.PosterID != 0 {

models/issues/issue_list.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,9 @@ func (issues IssueList) LoadPullRequests(ctx context.Context) error {
370370

371371
for _, issue := range issues {
372372
issue.PullRequest = pullRequestMaps[issue.ID]
373+
if issue.PullRequest != nil {
374+
issue.PullRequest.Issue = issue
375+
}
373376
}
374377
return nil
375378
}

models/issues/pull_list.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
access_model "code.gitea.io/gitea/models/perm/access"
1212
"code.gitea.io/gitea/models/unit"
1313
user_model "code.gitea.io/gitea/models/user"
14-
"code.gitea.io/gitea/modules/base"
1514
"code.gitea.io/gitea/modules/log"
1615
"code.gitea.io/gitea/modules/util"
1716

@@ -23,7 +22,7 @@ type PullRequestsOptions struct {
2322
db.ListOptions
2423
State string
2524
SortType string
26-
Labels []string
25+
Labels []int64
2726
MilestoneID int64
2827
}
2928

@@ -36,11 +35,9 @@ func listPullRequestStatement(ctx context.Context, baseRepoID int64, opts *PullR
3635
sess.And("issue.is_closed=?", opts.State == "closed")
3736
}
3837

39-
if labelIDs, err := base.StringsToInt64s(opts.Labels); err != nil {
40-
return nil, err
41-
} else if len(labelIDs) > 0 {
38+
if len(opts.Labels) > 0 {
4239
sess.Join("INNER", "issue_label", "issue.id = issue_label.issue_id").
43-
In("issue_label.label_id", labelIDs)
40+
In("issue_label.label_id", opts.Labels)
4441
}
4542

4643
if opts.MilestoneID > 0 {
@@ -212,3 +209,12 @@ func HasMergedPullRequestInRepo(ctx context.Context, repoID, posterID int64) (bo
212209
Limit(1).
213210
Get(new(Issue))
214211
}
212+
213+
// GetPullRequestByIssueIDs returns all pull requests by issue ids
214+
func GetPullRequestByIssueIDs(ctx context.Context, issueIDs []int64) (PullRequestList, error) {
215+
prs := make([]*PullRequest, 0, len(issueIDs))
216+
return prs, db.GetEngine(ctx).
217+
Where("issue_id > 0").
218+
In("issue_id", issueIDs).
219+
Find(&prs)
220+
}

models/issues/pull_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ func TestPullRequestsNewest(t *testing.T) {
6666
},
6767
State: "open",
6868
SortType: "newest",
69-
Labels: []string{},
7069
})
7170
assert.NoError(t, err)
7271
assert.EqualValues(t, 3, count)
@@ -113,7 +112,6 @@ func TestPullRequestsOldest(t *testing.T) {
113112
},
114113
State: "open",
115114
SortType: "oldest",
116-
Labels: []string{},
117115
})
118116
assert.NoError(t, err)
119117
assert.EqualValues(t, 3, count)

models/issues/review.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,11 @@ type CreateReviewOptions struct {
239239

240240
// IsOfficialReviewer check if at least one of the provided reviewers can make official reviews in issue (counts towards required approvals)
241241
func IsOfficialReviewer(ctx context.Context, issue *Issue, reviewer *user_model.User) (bool, error) {
242-
pr, err := GetPullRequestByIssueID(ctx, issue.ID)
243-
if err != nil {
242+
if err := issue.LoadPullRequest(ctx); err != nil {
244243
return false, err
245244
}
246245

246+
pr := issue.PullRequest
247247
rule, err := git_model.GetFirstMatchProtectedBranchRule(ctx, pr.BaseRepoID, pr.BaseBranch)
248248
if err != nil {
249249
return false, err
@@ -271,11 +271,10 @@ func IsOfficialReviewer(ctx context.Context, issue *Issue, reviewer *user_model.
271271

272272
// IsOfficialReviewerTeam check if reviewer in this team can make official reviews in issue (counts towards required approvals)
273273
func IsOfficialReviewerTeam(ctx context.Context, issue *Issue, team *organization.Team) (bool, error) {
274-
pr, err := GetPullRequestByIssueID(ctx, issue.ID)
275-
if err != nil {
274+
if err := issue.LoadPullRequest(ctx); err != nil {
276275
return false, err
277276
}
278-
pb, err := git_model.GetFirstMatchProtectedBranchRule(ctx, pr.BaseRepoID, pr.BaseBranch)
277+
pb, err := git_model.GetFirstMatchProtectedBranchRule(ctx, issue.PullRequest.BaseRepoID, issue.PullRequest.BaseBranch)
279278
if err != nil {
280279
return false, err
281280
}

modules/base/tool.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,16 @@ func TruncateString(str string, limit int) string {
150150

151151
// StringsToInt64s converts a slice of string to a slice of int64.
152152
func StringsToInt64s(strs []string) ([]int64, error) {
153-
ints := make([]int64, len(strs))
154-
for i := range strs {
155-
n, err := strconv.ParseInt(strs[i], 10, 64)
153+
if strs == nil {
154+
return nil, nil
155+
}
156+
ints := make([]int64, 0, len(strs))
157+
for _, s := range strs {
158+
n, err := strconv.ParseInt(s, 10, 64)
156159
if err != nil {
157-
return ints, err
160+
return nil, err
158161
}
159-
ints[i] = n
162+
ints = append(ints, n)
160163
}
161164
return ints, nil
162165
}

modules/base/tool_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,13 @@ func TestStringsToInt64s(t *testing.T) {
138138
assert.NoError(t, err)
139139
assert.Equal(t, expected, result)
140140
}
141+
testSuccess(nil, nil)
141142
testSuccess([]string{}, []int64{})
142143
testSuccess([]string{"-1234"}, []int64{-1234})
143-
testSuccess([]string{"1", "4", "16", "64", "256"},
144-
[]int64{1, 4, 16, 64, 256})
144+
testSuccess([]string{"1", "4", "16", "64", "256"}, []int64{1, 4, 16, 64, 256})
145145

146-
_, err := StringsToInt64s([]string{"-1", "a", "$"})
146+
ints, err := StringsToInt64s([]string{"-1", "a"})
147+
assert.Len(t, ints, 0)
147148
assert.Error(t, err)
148149
}
149150

modules/httplib/url.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ func IsCurrentGiteaSiteURL(s string) bool {
3232
return false
3333
}
3434
if u.Path != "" {
35-
u.Path = "/" + util.PathJoinRelX(u.Path)
36-
if !strings.HasSuffix(u.Path, "/") {
37-
u.Path += "/"
35+
cleanedPath := util.PathJoinRelX(u.Path)
36+
if cleanedPath == "" || cleanedPath == "." {
37+
u.Path = "/"
38+
} else {
39+
u.Path += "/" + cleanedPath + "/"
3840
}
3941
}
4042
if urlIsRelative(s, u) {

modules/httplib/url_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ func TestIsCurrentGiteaSiteURL(t *testing.T) {
5353
assert.True(t, IsCurrentGiteaSiteURL(s), "good = %q", s)
5454
}
5555
bad := []string{
56+
".",
57+
"foo",
5658
"/",
5759
"//",
5860
"\\\\",
@@ -67,5 +69,8 @@ func TestIsCurrentGiteaSiteURL(t *testing.T) {
6769

6870
setting.AppURL = "http://localhost:3000/"
6971
setting.AppSubURL = ""
72+
assert.False(t, IsCurrentGiteaSiteURL("//"))
73+
assert.False(t, IsCurrentGiteaSiteURL("\\\\"))
74+
assert.False(t, IsCurrentGiteaSiteURL("http://localhost"))
7075
assert.True(t, IsCurrentGiteaSiteURL("http://localhost:3000?key=val"))
7176
}

modules/util/slice.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,20 @@ func Sorted[S ~[]E, E cmp.Ordered](values S) S {
5454
return values
5555
}
5656

57-
// TODO: Replace with "maps.Values" once available
57+
// TODO: Replace with "maps.Values" once available, current it only in golang.org/x/exp/maps but not in standard library
5858
func ValuesOfMap[K comparable, V any](m map[K]V) []V {
5959
values := make([]V, 0, len(m))
6060
for _, v := range m {
6161
values = append(values, v)
6262
}
6363
return values
6464
}
65+
66+
// TODO: Replace with "maps.Keys" once available, current it only in golang.org/x/exp/maps but not in standard library
67+
func KeysOfMap[K comparable, V any](m map[K]V) []K {
68+
keys := make([]K, 0, len(m))
69+
for k := range m {
70+
keys = append(keys, k)
71+
}
72+
return keys
73+
}

options/locale/locale_en-US.ini

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ loading = Loading…
114114
error = Error
115115
error404 = The page you are trying to reach either <strong>does not exist</strong> or <strong>you are not authorized</strong> to view it.
116116
go_back = Go Back
117+
invalid_data = Invalid data: %v
117118

118119
never = Never
119120
unknown = Unknown
@@ -1062,6 +1063,7 @@ watchers = Watchers
10621063
stargazers = Stargazers
10631064
stars_remove_warning = This will remove all stars from this repository.
10641065
forks = Forks
1066+
stars = Stars
10651067
reactions_more = and %d more
10661068
unit_disabled = The site administrator has disabled this repository section.
10671069
language_other = Other
@@ -2965,9 +2967,6 @@ repos.unadopted.no_more = No more unadopted repositories found
29652967
repos.owner = Owner
29662968
repos.name = Name
29672969
repos.private = Private
2968-
repos.watches = Watches
2969-
repos.stars = Stars
2970-
repos.forks = Forks
29712970
repos.issues = Issues
29722971
repos.size = Size
29732972
repos.lfs_size = LFS Size
@@ -3092,7 +3091,7 @@ auths.tip.nextcloud = Register a new OAuth consumer on your instance using the f
30923091
auths.tip.dropbox = Create a new application at https://www.dropbox.com/developers/apps
30933092
auths.tip.facebook = Register a new application at https://developers.facebook.com/apps and add the product "Facebook Login"
30943093
auths.tip.github = Register a new OAuth application on https://github.com/settings/applications/new
3095-
auths.tip.gitlab = Register a new application on https://gitlab.com/profile/applications
3094+
auths.tip.gitlab_new = Register a new application on https://gitlab.com/-/profile/applications
30963095
auths.tip.google_plus = Obtain OAuth2 client credentials from the Google API console at https://console.developers.google.com/
30973096
auths.tip.openid_connect = Use the OpenID Connect Discovery URL (<server>/.well-known/openid-configuration) to specify the endpoints
30983097
auths.tip.twitter = Go to https://dev.twitter.com/apps, create an application and ensure that the “Allow this application to be used to Sign in with Twitter” option is enabled
@@ -3627,6 +3626,7 @@ runs.scheduled = Scheduled
36273626
runs.pushed_by = pushed by
36283627
runs.invalid_workflow_helper = Workflow config file is invalid. Please check your config file: %s
36293628
runs.no_matching_online_runner_helper = No matching online runner with label: %s
3629+
runs.no_job_without_needs = The workflow must contain at least one job without dependencies.
36303630
runs.actor = Actor
36313631
runs.status = Status
36323632
runs.actors_no_select = All actors

0 commit comments

Comments
 (0)