Skip to content

Commit 76bd60f

Browse files
GiteaBotwxiaoguang
andauthored
Fix various problems (artifact order, api empty slice, assignee check, fuzzy prompt, mirror proxy, adopt git) (#33569) (#33577)
Backport #33569 by @wxiaoguang * Make artifact list output has stable order * Fix #33506 * Fix #33521 * Fix #33288 * Fix #33196 * Fix #33561 Co-authored-by: wxiaoguang <[email protected]>
1 parent 744f7c8 commit 76bd60f

File tree

9 files changed

+45
-19
lines changed

9 files changed

+45
-19
lines changed

models/actions/artifact.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ type FindArtifactsOptions struct {
114114
Status int
115115
}
116116

117+
func (opts FindArtifactsOptions) ToOrders() string {
118+
return "id"
119+
}
120+
121+
var _ db.FindOptionsOrder = (*FindArtifactsOptions)(nil)
122+
117123
func (opts FindArtifactsOptions) ToConds() builder.Cond {
118124
cond := builder.NewCond()
119125
if opts.RepoID > 0 {
@@ -132,7 +138,7 @@ func (opts FindArtifactsOptions) ToConds() builder.Cond {
132138
return cond
133139
}
134140

135-
// ActionArtifactMeta is the meta data of an artifact
141+
// ActionArtifactMeta is the meta-data of an artifact
136142
type ActionArtifactMeta struct {
137143
ArtifactName string
138144
FileSize int64

modules/util/slice.go

+7
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,10 @@ func KeysOfMap[K comparable, V any](m map[K]V) []K {
7171
}
7272
return keys
7373
}
74+
75+
func SliceNilAsEmpty[T any](a []T) []T {
76+
if a == nil {
77+
return []T{}
78+
}
79+
return a
80+
}

routers/common/codesearch.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func PrepareCodeSearch(ctx *context.Context) (ret struct {
2525
}
2626
isFuzzy := ctx.FormOptionalBool("fuzzy").ValueOrDefault(fuzzyDefault)
2727
if isFuzzy && !fuzzyAllow {
28-
ctx.Flash.Info("Fuzzy search is disabled by default due to performance reasons")
28+
ctx.Flash.Info("Fuzzy search is disabled by default due to performance reasons", true)
2929
isFuzzy = false
3030
}
3131

routers/web/repo/issue_new.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,16 @@ func ValidateRepoMetasForNewIssue(ctx *context.Context, form forms.CreateIssueFo
276276
}
277277
pageMetaData.ProjectsData.SelectedProjectID = form.ProjectID
278278

279+
// prepare assignees
279280
candidateAssignees := toSet(pageMetaData.AssigneesData.CandidateAssignees, func(user *user_model.User) int64 { return user.ID })
280281
inputAssigneeIDs, _ := base.StringsToInt64s(strings.Split(form.AssigneeIDs, ","))
281-
if len(inputAssigneeIDs) > 0 && !candidateAssignees.Contains(inputAssigneeIDs...) {
282-
ctx.NotFound("", nil)
283-
return ret
282+
var assigneeIDStrings []string
283+
for _, inputAssigneeID := range inputAssigneeIDs {
284+
if candidateAssignees.Contains(inputAssigneeID) {
285+
assigneeIDStrings = append(assigneeIDStrings, strconv.FormatInt(inputAssigneeID, 10))
286+
}
284287
}
285-
pageMetaData.AssigneesData.SelectedAssigneeIDs = form.AssigneeIDs
288+
pageMetaData.AssigneesData.SelectedAssigneeIDs = strings.Join(assigneeIDStrings, ",")
286289

287290
// Check if the passed reviewers (user/team) actually exist
288291
var reviewers []*user_model.User

services/convert/issue.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func toIssue(ctx context.Context, doer *user_model.User, issue *issues_model.Iss
6767
if err := issue.LoadLabels(ctx); err != nil {
6868
return &api.Issue{}
6969
}
70-
apiIssue.Labels = ToLabelList(issue.Labels, issue.Repo, issue.Repo.Owner)
70+
apiIssue.Labels = util.SliceNilAsEmpty(ToLabelList(issue.Labels, issue.Repo, issue.Repo.Owner))
7171
apiIssue.Repo = &api.RepositoryMeta{
7272
ID: issue.Repo.ID,
7373
Name: issue.Repo.Name,

services/convert/pull.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"code.gitea.io/gitea/modules/gitrepo"
1919
"code.gitea.io/gitea/modules/log"
2020
api "code.gitea.io/gitea/modules/structs"
21+
"code.gitea.io/gitea/modules/util"
2122
)
2223

2324
// ToAPIPullRequest assumes following fields have been assigned with valid values:
@@ -77,7 +78,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
7778
Labels: apiIssue.Labels,
7879
Milestone: apiIssue.Milestone,
7980
Assignee: apiIssue.Assignee,
80-
Assignees: apiIssue.Assignees,
81+
Assignees: util.SliceNilAsEmpty(apiIssue.Assignees),
8182
State: apiIssue.State,
8283
Draft: pr.IsWorkInProgress(ctx),
8384
IsLocked: apiIssue.IsLocked,
@@ -94,6 +95,10 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
9495
Updated: pr.Issue.UpdatedUnix.AsTimePtr(),
9596
PinOrder: apiIssue.PinOrder,
9697

98+
// output "[]" rather than null to align to github outputs
99+
RequestedReviewers: []*api.User{},
100+
RequestedReviewersTeams: []*api.Team{},
101+
97102
AllowMaintainerEdit: pr.AllowMaintainerEdit,
98103

99104
Base: &api.PRBranchInfo{

services/convert/repository.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
unit_model "code.gitea.io/gitea/models/unit"
1616
"code.gitea.io/gitea/modules/log"
1717
api "code.gitea.io/gitea/modules/structs"
18+
"code.gitea.io/gitea/modules/util"
1819
)
1920

2021
// ToRepo converts a Repository to api.Repository
@@ -241,7 +242,7 @@ func innerToRepo(ctx context.Context, repo *repo_model.Repository, permissionInR
241242
MirrorInterval: mirrorInterval,
242243
MirrorUpdated: mirrorUpdated,
243244
RepoTransfer: transfer,
244-
Topics: repo.Topics,
245+
Topics: util.SliceNilAsEmpty(repo.Topics),
245246
ObjectFormatName: repo.ObjectFormatName,
246247
Licenses: repoLicenses.StringList(),
247248
}

services/mirror/mirror_push.go

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"code.gitea.io/gitea/modules/lfs"
2020
"code.gitea.io/gitea/modules/log"
2121
"code.gitea.io/gitea/modules/process"
22+
"code.gitea.io/gitea/modules/proxy"
2223
"code.gitea.io/gitea/modules/repository"
2324
"code.gitea.io/gitea/modules/setting"
2425
"code.gitea.io/gitea/modules/timeutil"
@@ -167,11 +168,13 @@ func runPushSync(ctx context.Context, m *repo_model.PushMirror) error {
167168

168169
log.Trace("Pushing %s mirror[%d] remote %s", path, m.ID, m.RemoteName)
169170

171+
envs := proxy.EnvWithProxy(remoteURL.URL)
170172
if err := git.Push(ctx, path, git.PushOptions{
171173
Remote: m.RemoteName,
172174
Force: true,
173175
Mirror: true,
174176
Timeout: timeout,
177+
Env: envs,
175178
}); err != nil {
176179
log.Error("Error pushing %s mirror[%d] remote %s: %v", path, m.ID, m.RemoteName, err)
177180

services/repository/adopt.go

+11-10
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ func AdoptRepository(ctx context.Context, doer, u *user_model.User, opts CreateR
5252
IsEmpty: !opts.AutoInit,
5353
}
5454

55+
repoPath := repo_model.RepoPath(u.Name, repo.Name)
56+
5557
if err := db.WithTx(ctx, func(ctx context.Context) error {
56-
repoPath := repo_model.RepoPath(u.Name, repo.Name)
5758
isExist, err := util.IsExist(repoPath)
5859
if err != nil {
5960
log.Error("Unable to check if %s exists. Error: %v", repoPath, err)
@@ -75,7 +76,12 @@ func AdoptRepository(ctx context.Context, doer, u *user_model.User, opts CreateR
7576
if repo, err = repo_model.GetRepositoryByID(ctx, repo.ID); err != nil {
7677
return fmt.Errorf("getRepositoryByID: %w", err)
7778
}
79+
return nil
80+
}); err != nil {
81+
return nil, err
82+
}
7883

84+
if err := func() error {
7985
if err := adoptRepository(ctx, repoPath, repo, opts.DefaultBranch); err != nil {
8086
return fmt.Errorf("adoptRepository: %w", err)
8187
}
@@ -84,24 +90,19 @@ func AdoptRepository(ctx context.Context, doer, u *user_model.User, opts CreateR
8490
return fmt.Errorf("checkDaemonExportOK: %w", err)
8591
}
8692

87-
// Initialize Issue Labels if selected
88-
if len(opts.IssueLabels) > 0 {
89-
if err := repo_module.InitializeLabels(ctx, repo.ID, opts.IssueLabels, false); err != nil {
90-
return fmt.Errorf("InitializeLabels: %w", err)
91-
}
92-
}
93-
9493
if stdout, _, err := git.NewCommand(ctx, "update-server-info").
9594
SetDescription(fmt.Sprintf("CreateRepository(git update-server-info): %s", repoPath)).
9695
RunStdString(&git.RunOpts{Dir: repoPath}); err != nil {
9796
log.Error("CreateRepository(git update-server-info) in %v: Stdout: %s\nError: %v", repo, stdout, err)
9897
return fmt.Errorf("CreateRepository(git update-server-info): %w", err)
9998
}
10099
return nil
101-
}); err != nil {
100+
}(); err != nil {
101+
if errDel := DeleteRepository(ctx, doer, repo, false /* no notify */); errDel != nil {
102+
log.Error("Failed to delete repository %s that could not be adopted: %v", repo.FullName(), errDel)
103+
}
102104
return nil, err
103105
}
104-
105106
notify_service.AdoptRepository(ctx, doer, u, repo)
106107

107108
return repo, nil

0 commit comments

Comments
 (0)