Skip to content

Commit 26c0a78

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Fix EasyMDE error when input Enter (go-gitea#19004) Fix update hint bug (go-gitea#18996) Fix the editor height in review box (go-gitea#19003) Add a "admin user generate-access-token" subcommand (go-gitea#17722) Fix potential assignee query for repo (go-gitea#18994) Add config option to disable "Update branch by rebase" (go-gitea#18745) Update `go-enry` to v2.8.0 (go-gitea#18993) homebrew updates via cron ignore missing comment for user notifications (go-gitea#18954) allow overwrite artifacts for github releases (go-gitea#18987) fix & refactor (go-gitea#18973)
2 parents 802db34 + 3e28fa7 commit 26c0a78

File tree

22 files changed

+139
-26
lines changed

22 files changed

+139
-26
lines changed

.drone.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,11 +804,12 @@ steps:
804804
depends_on: [gpg-sign]
805805

806806
- name: github
807-
image: plugins/github-release:1
807+
image: plugins/github-release:latest
808808
pull: always
809809
settings:
810810
files:
811811
- "dist/release/*"
812+
file_exists: overwrite
812813
environment:
813814
GITHUB_TOKEN:
814815
from_secret: github_token

CONTRIBUTING.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,6 @@ be reviewed by two maintainers and must pass the automatic tests.
424424
* If needed send a frontport PR for the changelog to branch `main` and update the version in `docs/config.yaml` to refer to the new version.
425425
* Send PR to [blog repository](https://gitea.com/gitea/blog) announcing the release.
426426
* Verify all release assets were correctly published through CI on dl.gitea.io and GitHub releases. Once ACKed:
427-
* send a PR to the [homebrew repo](https://gitea.com/gitea/homebrew-gitea) analog to [this PR](https://gitea.com/gitea/homebrew-gitea/commit/1f9a3fe5eb75b64a96a5336665531abcbd0eef0c)
428427
* bump the version of https://dl.gitea.io/gitea/version.json
429428
* merge the blog post PR
430429
* announce the release in discord `#announcements`

cmd/admin.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ var (
5656
microcmdUserList,
5757
microcmdUserChangePassword,
5858
microcmdUserDelete,
59+
microcmdUserGenerateAccessToken,
5960
},
6061
}
6162

@@ -154,6 +155,27 @@ var (
154155
Action: runDeleteUser,
155156
}
156157

158+
microcmdUserGenerateAccessToken = cli.Command{
159+
Name: "generate-access-token",
160+
Usage: "Generate a access token for a specific user",
161+
Flags: []cli.Flag{
162+
cli.StringFlag{
163+
Name: "username,u",
164+
Usage: "Username",
165+
},
166+
cli.StringFlag{
167+
Name: "token-name,t",
168+
Usage: "Token name",
169+
Value: "gitea-admin",
170+
},
171+
cli.BoolFlag{
172+
Name: "raw",
173+
Usage: "Display only the token value",
174+
},
175+
},
176+
Action: runGenerateAccessToken,
177+
}
178+
157179
subcmdRepoSyncReleases = cli.Command{
158180
Name: "repo-sync-releases",
159181
Usage: "Synchronize repository releases with tags",
@@ -641,6 +663,41 @@ func runDeleteUser(c *cli.Context) error {
641663
return user_service.DeleteUser(user)
642664
}
643665

666+
func runGenerateAccessToken(c *cli.Context) error {
667+
if !c.IsSet("username") {
668+
return fmt.Errorf("You must provide the username to generate a token for them")
669+
}
670+
671+
ctx, cancel := installSignals()
672+
defer cancel()
673+
674+
if err := initDB(ctx); err != nil {
675+
return err
676+
}
677+
678+
user, err := user_model.GetUserByName(c.String("username"))
679+
if err != nil {
680+
return err
681+
}
682+
683+
t := &models.AccessToken{
684+
Name: c.String("token-name"),
685+
UID: user.ID,
686+
}
687+
688+
if err := models.NewAccessToken(t); err != nil {
689+
return err
690+
}
691+
692+
if c.Bool("raw") {
693+
fmt.Printf("%s\n", t.Token)
694+
} else {
695+
fmt.Printf("Access token was successfully created: %s\n", t.Token)
696+
}
697+
698+
return nil
699+
}
700+
644701
func runRepoSyncReleases(_ *cli.Context) error {
645702
ctx, cancel := installSignals()
646703
defer cancel()

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ require (
3939
github.com/go-asn1-ber/asn1-ber v1.5.3 // indirect
4040
github.com/go-chi/chi/v5 v5.0.4
4141
github.com/go-chi/cors v1.2.0
42-
github.com/go-enry/go-enry/v2 v2.7.1
42+
github.com/go-enry/go-enry/v2 v2.8.0
4343
github.com/go-git/go-billy/v5 v5.3.1
4444
github.com/go-git/go-git/v5 v5.4.3-0.20210630082519-b4368b2a2ca4
4545
github.com/go-ldap/ldap/v3 v3.3.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,8 @@ github.com/go-chi/chi/v5 v5.0.4 h1:5e494iHzsYBiyXQAHHuI4tyJS9M3V84OuX3ufIIGHFo=
326326
github.com/go-chi/chi/v5 v5.0.4/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
327327
github.com/go-chi/cors v1.2.0 h1:tV1g1XENQ8ku4Bq3K9ub2AtgG+p16SmzeMSGTwrOKdE=
328328
github.com/go-chi/cors v1.2.0/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58=
329-
github.com/go-enry/go-enry/v2 v2.7.1 h1:WCqtfyteIz61GYk9lRVy8HblvIv4cP9GIiwm/6txCbU=
330-
github.com/go-enry/go-enry/v2 v2.7.1/go.mod h1:GVzIiAytiS5uT/QiuakK7TF1u4xDab87Y8V5EJRpsIQ=
329+
github.com/go-enry/go-enry/v2 v2.8.0 h1:KMW4mSG+8uUF6FaD3iPkFqyfC5tF8gRrsYImq6yhHzo=
330+
github.com/go-enry/go-enry/v2 v2.8.0/go.mod h1:GVzIiAytiS5uT/QiuakK7TF1u4xDab87Y8V5EJRpsIQ=
331331
github.com/go-enry/go-oniguruma v1.2.1 h1:k8aAMuJfMrqm/56SG2lV9Cfti6tC4x8673aHCcBk+eo=
332332
github.com/go-enry/go-oniguruma v1.2.1/go.mod h1:bWDhYP+S6xZQgiRL7wlTScFYBe023B6ilRZbCAD5Hf4=
333333
github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4=

models/notification.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,14 +498,15 @@ func (n *Notification) APIURL() string {
498498
type NotificationList []*Notification
499499

500500
// LoadAttributes load Repo Issue User and Comment if not loaded
501-
func (nl NotificationList) LoadAttributes() (err error) {
501+
func (nl NotificationList) LoadAttributes() error {
502+
var err error
502503
for i := 0; i < len(nl); i++ {
503504
err = nl[i].LoadAttributes()
504505
if err != nil && !IsErrCommentNotExist(err) {
505-
return
506+
return err
506507
}
507508
}
508-
return
509+
return nil
509510
}
510511

511512
func (nl NotificationList) getPendingRepoIDs() []int64 {

models/repo.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func getRepoAssignees(ctx context.Context, repo *repo_model.Repository) (_ []*us
153153
userIDs := make([]int64, 0, 10)
154154
if err = e.Table("access").
155155
Where("repo_id = ? AND mode >= ?", repo.ID, perm.AccessModeWrite).
156-
Select("id").
156+
Select("user_id").
157157
Find(&userIDs); err != nil {
158158
return nil, err
159159
}
@@ -521,7 +521,7 @@ func CreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_
521521
units = append(units, repo_model.RepoUnit{
522522
RepoID: repo.ID,
523523
Type: tp,
524-
Config: &repo_model.PullRequestsConfig{AllowMerge: true, AllowRebase: true, AllowRebaseMerge: true, AllowSquash: true, DefaultMergeStyle: repo_model.MergeStyleMerge},
524+
Config: &repo_model.PullRequestsConfig{AllowMerge: true, AllowRebase: true, AllowRebaseMerge: true, AllowSquash: true, DefaultMergeStyle: repo_model.MergeStyleMerge, AllowRebaseUpdate: true},
525525
})
526526
} else {
527527
units = append(units, repo_model.RepoUnit{
@@ -956,28 +956,28 @@ func DeleteRepository(doer *user_model.User, uid, repoID int64) error {
956956
}
957957

958958
// Remove archives
959-
for i := range archivePaths {
960-
admin_model.RemoveStorageWithNotice(db.DefaultContext, storage.RepoArchives, "Delete repo archive file", archivePaths[i])
959+
for _, archive := range archivePaths {
960+
admin_model.RemoveStorageWithNotice(db.DefaultContext, storage.RepoArchives, "Delete repo archive file", archive)
961961
}
962962

963963
// Remove lfs objects
964-
for i := range lfsPaths {
965-
admin_model.RemoveStorageWithNotice(db.DefaultContext, storage.LFS, "Delete orphaned LFS file", lfsPaths[i])
964+
for _, lfsObj := range lfsPaths {
965+
admin_model.RemoveStorageWithNotice(db.DefaultContext, storage.LFS, "Delete orphaned LFS file", lfsObj)
966966
}
967967

968968
// Remove issue attachment files.
969-
for i := range attachmentPaths {
970-
admin_model.RemoveStorageWithNotice(db.DefaultContext, storage.Attachments, "Delete issue attachment", attachmentPaths[i])
969+
for _, attachment := range attachmentPaths {
970+
admin_model.RemoveStorageWithNotice(db.DefaultContext, storage.Attachments, "Delete issue attachment", attachment)
971971
}
972972

973973
// Remove release attachment files.
974-
for i := range releaseAttachments {
975-
admin_model.RemoveStorageWithNotice(db.DefaultContext, storage.Attachments, "Delete release attachment", releaseAttachments[i])
974+
for _, releaseAttachment := range releaseAttachments {
975+
admin_model.RemoveStorageWithNotice(db.DefaultContext, storage.Attachments, "Delete release attachment", releaseAttachment)
976976
}
977977

978978
// Remove attachment with no issue_id and release_id.
979-
for i := range newAttachmentPaths {
980-
admin_model.RemoveStorageWithNotice(db.DefaultContext, storage.Attachments, "Delete issue attachment", attachmentPaths[i])
979+
for _, newAttachment := range newAttachmentPaths {
980+
admin_model.RemoveStorageWithNotice(db.DefaultContext, storage.Attachments, "Delete issue attachment", newAttachment)
981981
}
982982

983983
if len(repo.Avatar) > 0 {

models/repo/repo_unit.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,15 @@ type PullRequestsConfig struct {
115115
AllowSquash bool
116116
AllowManualMerge bool
117117
AutodetectManualMerge bool
118+
AllowRebaseUpdate bool
118119
DefaultDeleteBranchAfterMerge bool
119120
DefaultMergeStyle MergeStyle
120121
}
121122

122123
// FromDB fills up a PullRequestsConfig from serialized format.
123124
func (cfg *PullRequestsConfig) FromDB(bs []byte) error {
125+
// AllowRebaseUpdate = true as default for existing PullRequestConfig in DB
126+
cfg.AllowRebaseUpdate = true
124127
return json.UnmarshalHandleDoubleEncode(bs, &cfg)
125128
}
126129

models/repo_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,21 @@ func TestLinkedRepository(t *testing.T) {
167167
})
168168
}
169169
}
170+
171+
func TestRepoAssignees(t *testing.T) {
172+
assert.NoError(t, unittest.PrepareTestDatabase())
173+
174+
repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2}).(*repo_model.Repository)
175+
users, err := GetRepoAssignees(repo2)
176+
assert.NoError(t, err)
177+
assert.Len(t, users, 1)
178+
assert.Equal(t, users[0].ID, int64(2))
179+
180+
repo21 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 21}).(*repo_model.Repository)
181+
users, err = GetRepoAssignees(repo21)
182+
assert.NoError(t, err)
183+
assert.Len(t, users, 3)
184+
assert.Equal(t, users[0].ID, int64(15))
185+
assert.Equal(t, users[1].ID, int64(18))
186+
assert.Equal(t, users[2].ID, int64(16))
187+
}

modules/structs/repo.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ type EditRepoOption struct {
177177
AllowManualMerge *bool `json:"allow_manual_merge,omitempty"`
178178
// either `true` to enable AutodetectManualMerge, or `false` to prevent it. `has_pull_requests` must be `true`, Note: In some special cases, misjudgments can occur.
179179
AutodetectManualMerge *bool `json:"autodetect_manual_merge,omitempty"`
180+
// either `true` to allow updating pull request branch by rebase, or `false` to prevent it. `has_pull_requests` must be `true`.
181+
AllowRebaseUpdate *bool `json:"allow_rebase_update,omitempty"`
180182
// set to `true` to delete pr branch after merge by default
181183
DefaultDeleteBranchAfterMerge *bool `json:"default_delete_branch_after_merge,omitempty"`
182184
// set to a merge style to be used by this repository: "merge", "rebase", "rebase-merge", or "squash". `has_pull_requests` must be `true`.

0 commit comments

Comments
 (0)