Skip to content

Commit c919783

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Fix duplicate ID when deleting repo (go-gitea#28520) chore(api): support ignore password if login source type is LDAP for creating user API (go-gitea#28491) Update go dependencies (go-gitea#28518) Bump google/go-github to v57 (go-gitea#28514) Only check online runner when detecting matching runners in workflows (go-gitea#28286) Add orphaned topic consistency check (go-gitea#28507) Improve the prompt for "ssh-keygen sign" (go-gitea#28509)
2 parents a17d5f9 + 128eac9 commit c919783

File tree

19 files changed

+350
-439
lines changed

19 files changed

+350
-439
lines changed

assets/go-licenses.json

+9-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contrib/backport/backport.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"strings"
1818
"syscall"
1919

20-
"github.com/google/go-github/v53/github"
20+
"github.com/google/go-github/v57/github"
2121
"github.com/urfave/cli/v2"
2222
"gopkg.in/yaml.v3"
2323
)

go.mod

+83-83
Large diffs are not rendered by default.

go.sum

+175-309
Large diffs are not rendered by default.

models/actions/runner.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ type ActionRunner struct {
5151
Deleted timeutil.TimeStamp `xorm:"deleted"`
5252
}
5353

54+
const (
55+
RunnerOfflineTime = time.Minute
56+
RunnerIdleTime = 10 * time.Second
57+
)
58+
5459
// BelongsToOwnerName before calling, should guarantee that all attributes are loaded
5560
func (r *ActionRunner) BelongsToOwnerName() string {
5661
if r.RepoID != 0 {
@@ -76,11 +81,12 @@ func (r *ActionRunner) BelongsToOwnerType() types.OwnerType {
7681
return types.OwnerTypeSystemGlobal
7782
}
7883

84+
// if the logic here changed, you should also modify FindRunnerOptions.ToCond
7985
func (r *ActionRunner) Status() runnerv1.RunnerStatus {
80-
if time.Since(r.LastOnline.AsTime()) > time.Minute {
86+
if time.Since(r.LastOnline.AsTime()) > RunnerOfflineTime {
8187
return runnerv1.RunnerStatus_RUNNER_STATUS_OFFLINE
8288
}
83-
if time.Since(r.LastActive.AsTime()) > 10*time.Second {
89+
if time.Since(r.LastActive.AsTime()) > RunnerIdleTime {
8490
return runnerv1.RunnerStatus_RUNNER_STATUS_IDLE
8591
}
8692
return runnerv1.RunnerStatus_RUNNER_STATUS_ACTIVE
@@ -153,6 +159,7 @@ type FindRunnerOptions struct {
153159
OwnerID int64
154160
Sort string
155161
Filter string
162+
IsOnline util.OptionalBool
156163
WithAvailable bool // not only runners belong to, but also runners can be used
157164
}
158165

@@ -178,6 +185,12 @@ func (opts FindRunnerOptions) ToConds() builder.Cond {
178185
if opts.Filter != "" {
179186
cond = cond.And(builder.Like{"name", opts.Filter})
180187
}
188+
189+
if opts.IsOnline.IsTrue() {
190+
cond = cond.And(builder.Gt{"last_online": time.Now().Add(-RunnerOfflineTime).Unix()})
191+
} else if opts.IsOnline.IsFalse() {
192+
cond = cond.And(builder.Lte{"last_online": time.Now().Add(-RunnerOfflineTime).Unix()})
193+
}
181194
return cond
182195
}
183196

models/repo/topic.go

+10
Original file line numberDiff line numberDiff line change
@@ -377,3 +377,13 @@ func syncTopicsInRepository(sess db.Engine, repoID int64) error {
377377
}
378378
return nil
379379
}
380+
381+
// CountOrphanedAttachments returns the number of topics that don't belong to any repository.
382+
func CountOrphanedTopics(ctx context.Context) (int64, error) {
383+
return db.GetEngine(ctx).Where("repo_count = 0").Count(new(Topic))
384+
}
385+
386+
// DeleteOrphanedAttachments delete all topics that don't belong to any repository.
387+
func DeleteOrphanedTopics(ctx context.Context) (int64, error) {
388+
return db.GetEngine(ctx).Where("repo_count = 0").Delete(new(Topic))
389+
}

modules/doctor/dbconsistency.go

+6
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ func checkDBConsistency(ctx context.Context, logger log.Logger, autofix bool) er
158158
Fixer: actions_model.FixRunnersWithoutBelongingOwner,
159159
FixedMessage: "Removed",
160160
},
161+
{
162+
Name: "Topics with empty repository count",
163+
Counter: repo_model.CountOrphanedTopics,
164+
Fixer: repo_model.DeleteOrphanedTopics,
165+
FixedMessage: "Removed",
166+
},
161167
}
162168

163169
// TODO: function to recalc all counters

modules/git/repo_commitgraph_gogit.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func (r *Repository) CommitNodeIndex() (cgobject.CommitNodeIndex, *os.File) {
2222

2323
file, err := os.Open(indexPath)
2424
if err == nil {
25-
var index commitgraph.Index
25+
var index commitgraph.Index // TODO: in newer go-git, it might need to use "github.com/go-git/go-git/v5/plumbing/format/commitgraph/v2" package to compile
2626
index, err = commitgraph.OpenFileIndex(file)
2727
if err == nil {
2828
return cgobject.NewGraphCommitNodeIndex(index, r.gogitRepo.Storer), file

modules/structs/admin_user.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ type CreateUserOption struct {
1515
FullName string `json:"full_name" binding:"MaxSize(100)"`
1616
// required: true
1717
// swagger:strfmt email
18-
Email string `json:"email" binding:"Required;Email;MaxSize(254)"`
19-
// required: true
20-
Password string `json:"password" binding:"Required;MaxSize(255)"`
18+
Email string `json:"email" binding:"Required;Email;MaxSize(254)"`
19+
Password string `json:"password" binding:"MaxSize(255)"`
2120
MustChangePassword *bool `json:"must_change_password"`
2221
SendNotify bool `json:"send_notify"`
2322
Restricted *bool `json:"restricted"`

options/locale/locale_en-US.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -3525,7 +3525,7 @@ runs.commit = Commit
35253525
runs.scheduled = Scheduled
35263526
runs.pushed_by = pushed by
35273527
runs.invalid_workflow_helper = Workflow config file is invalid. Please check your config file: %s
3528-
runs.no_matching_runner_helper = No matching runner: %s
3528+
runs.no_matching_online_runner_helper = No matching online runner with label: %s
35293529
runs.actor = Actor
35303530
runs.status = Status
35313531
runs.actors_no_select = All actors

routers/api/v1/admin/user.go

+21-11
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,28 @@ func CreateUser(ctx *context.APIContext) {
9393
if ctx.Written() {
9494
return
9595
}
96-
if !password.IsComplexEnough(form.Password) {
97-
err := errors.New("PasswordComplexity")
98-
ctx.Error(http.StatusBadRequest, "PasswordComplexity", err)
99-
return
100-
}
101-
pwned, err := password.IsPwned(ctx, form.Password)
102-
if pwned {
103-
if err != nil {
104-
log.Error(err.Error())
96+
97+
if u.LoginType == auth.Plain {
98+
if len(form.Password) < setting.MinPasswordLength {
99+
err := errors.New("PasswordIsRequired")
100+
ctx.Error(http.StatusBadRequest, "PasswordIsRequired", err)
101+
return
102+
}
103+
104+
if !password.IsComplexEnough(form.Password) {
105+
err := errors.New("PasswordComplexity")
106+
ctx.Error(http.StatusBadRequest, "PasswordComplexity", err)
107+
return
108+
}
109+
110+
pwned, err := password.IsPwned(ctx, form.Password)
111+
if pwned {
112+
if err != nil {
113+
log.Error(err.Error())
114+
}
115+
ctx.Error(http.StatusBadRequest, "PasswordPwned", errors.New("PasswordPwned"))
116+
return
105117
}
106-
ctx.Error(http.StatusBadRequest, "PasswordPwned", errors.New("PasswordPwned"))
107-
return
108118
}
109119

110120
overwriteDefault := &user_model.CreateUserOverwriteOptions{

routers/web/repo/actions/actions.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"code.gitea.io/gitea/modules/context"
1919
"code.gitea.io/gitea/modules/git"
2020
"code.gitea.io/gitea/modules/setting"
21+
"code.gitea.io/gitea/modules/util"
2122
"code.gitea.io/gitea/routers/web/repo"
2223
"code.gitea.io/gitea/services/convert"
2324

@@ -77,6 +78,7 @@ func List(ctx *context.Context) {
7778
// Get all runner labels
7879
runners, err := db.Find[actions_model.ActionRunner](ctx, actions_model.FindRunnerOptions{
7980
RepoID: ctx.Repo.Repository.ID,
81+
IsOnline: util.OptionalBoolTrue,
8082
WithAvailable: true,
8183
})
8284
if err != nil {
@@ -113,7 +115,7 @@ func List(ctx *context.Context) {
113115
continue
114116
}
115117
if !allRunnerLabels.Contains(ro) {
116-
workflow.ErrMsg = ctx.Locale.Tr("actions.runs.no_matching_runner_helper", ro)
118+
workflow.ErrMsg = ctx.Locale.Tr("actions.runs.no_matching_online_runner_helper", ro)
117119
break
118120
}
119121
}

services/cron/tasks_test.go

+12-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package cron
55

66
import (
7+
"sort"
78
"strconv"
89
"testing"
910

@@ -22,9 +23,10 @@ func TestAddTaskToScheduler(t *testing.T) {
2223
},
2324
})
2425
assert.NoError(t, err)
25-
assert.Len(t, scheduler.Jobs(), 1)
26-
assert.Equal(t, "task 1", scheduler.Jobs()[0].Tags()[0])
27-
assert.Equal(t, "5 4 * * *", scheduler.Jobs()[0].Tags()[1])
26+
jobs := scheduler.Jobs()
27+
assert.Len(t, jobs, 1)
28+
assert.Equal(t, "task 1", jobs[0].Tags()[0])
29+
assert.Equal(t, "5 4 * * *", jobs[0].Tags()[1])
2830

2931
// with seconds
3032
err = addTaskToScheduler(&Task{
@@ -34,9 +36,13 @@ func TestAddTaskToScheduler(t *testing.T) {
3436
},
3537
})
3638
assert.NoError(t, err)
37-
assert.Len(t, scheduler.Jobs(), 2)
38-
assert.Equal(t, "task 2", scheduler.Jobs()[1].Tags()[0])
39-
assert.Equal(t, "30 5 4 * * *", scheduler.Jobs()[1].Tags()[1])
39+
jobs = scheduler.Jobs() // the item order is not guaranteed, so we need to sort it before "assert"
40+
sort.Slice(jobs, func(i, j int) bool {
41+
return jobs[i].Tags()[0] < jobs[j].Tags()[0]
42+
})
43+
assert.Len(t, jobs, 2)
44+
assert.Equal(t, "task 2", jobs[1].Tags()[0])
45+
assert.Equal(t, "30 5 4 * * *", jobs[1].Tags()[1])
4046
}
4147

4248
func TestScheduleHasSeconds(t *testing.T) {

services/migrations/error.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package migrations
77
import (
88
"errors"
99

10-
"github.com/google/go-github/v53/github"
10+
"github.com/google/go-github/v57/github"
1111
)
1212

1313
// ErrRepoNotCreated returns the error that repository not created

services/migrations/github.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"code.gitea.io/gitea/modules/proxy"
2121
"code.gitea.io/gitea/modules/structs"
2222

23-
"github.com/google/go-github/v53/github"
23+
"github.com/google/go-github/v57/github"
2424
"golang.org/x/oauth2"
2525
)
2626

@@ -135,7 +135,7 @@ func (g *GithubDownloaderV3) LogString() string {
135135
func (g *GithubDownloaderV3) addClient(client *http.Client, baseURL string) {
136136
githubClient := github.NewClient(client)
137137
if baseURL != "https://github.com" {
138-
githubClient, _ = github.NewEnterpriseClient(baseURL, baseURL, client)
138+
githubClient, _ = github.NewClient(client).WithEnterpriseURLs(baseURL, baseURL)
139139
}
140140
g.clients = append(g.clients, githubClient)
141141
g.rates = append(g.rates, nil)
@@ -168,14 +168,14 @@ func (g *GithubDownloaderV3) waitAndPickClient() {
168168

169169
err := g.RefreshRate()
170170
if err != nil {
171-
log.Error("g.getClient().RateLimits: %s", err)
171+
log.Error("g.getClient().RateLimit.Get: %s", err)
172172
}
173173
}
174174
}
175175

176176
// RefreshRate update the current rate (doesn't count in rate limit)
177177
func (g *GithubDownloaderV3) RefreshRate() error {
178-
rates, _, err := g.getClient().RateLimits(g.ctx)
178+
rates, _, err := g.getClient().RateLimit.Get(g.ctx)
179179
if err != nil {
180180
// if rate limit is not enabled, ignore it
181181
if strings.Contains(err.Error(), "404") {

templates/repo/migrate/migrating.tmpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@
7373
</label>
7474
</div>
7575
<div class="required field">
76-
<label for="repo_name">{{ctx.Locale.Tr "repo.repo_name"}}</label>
77-
<input id="repo_name" name="repo_name" required>
76+
<label for="repo_name_to_delete">{{ctx.Locale.Tr "repo.repo_name"}}</label>
77+
<input id="repo_name_to_delete" name="repo_name" required>
7878
</div>
7979

8080
<div class="text right actions">

templates/repo/settings/options.tmpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -921,8 +921,8 @@
921921
</label>
922922
</div>
923923
<div class="required field">
924-
<label for="repo_name">{{ctx.Locale.Tr "repo.repo_name"}}</label>
925-
<input id="repo_name" name="repo_name" required>
924+
<label for="repo_name_to_delete">{{ctx.Locale.Tr "repo.repo_name"}}</label>
925+
<input id="repo_name_to_delete" name="repo_name" required>
926926
</div>
927927

928928
<div class="text right actions">

templates/swagger/v1_json.tmpl

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/user/settings/keys_ssh.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
<input readonly="" value="{{$.TokenToSign}}">
7979
<div class="help">
8080
<p>{{ctx.Locale.Tr "settings.ssh_token_help"}}</p>
81-
<p><code>{{printf "echo -n '%s' | ssh-keygen -Y sign -n gitea -f /path_to_your_privkey" $.TokenToSign}}</code></p>
81+
<p><code>{{printf "echo -n '%s' | ssh-keygen -Y sign -n gitea -f /path_to_PrivateKey_or_RelatedPublicKey" $.TokenToSign}}</code></p>
8282
</div>
8383
<br>
8484
</div>

0 commit comments

Comments
 (0)