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`.

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,6 +1786,7 @@ settings.pulls.allow_rebase_merge_commit = Enable Rebasing with explicit merge c
17861786
settings.pulls.allow_squash_commits = Enable Squashing to Merge Commits
17871787
settings.pulls.allow_manual_merge = Enable Mark PR as manually merged
17881788
settings.pulls.enable_autodetect_manual_merge = Enable autodetect manual merge (Note: In some special cases, misjudgments can occur)
1789+
settings.pulls.allow_rebase_update = Enable updating pull request branch by rebase
17891790
settings.pulls.default_delete_branch_after_merge = Delete pull request branch after merge by default
17901791
settings.projects_desc = Enable Repository Projects
17911792
settings.admin_settings = Administrator Settings

routers/api/v1/notify/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func ListRepoNotifications(ctx *context.APIContext) {
121121
return
122122
}
123123
err = nl.LoadAttributes()
124-
if err != nil && !models.IsErrCommentNotExist(err) {
124+
if err != nil {
125125
ctx.InternalServerError(err)
126126
return
127127
}

routers/api/v1/repo/repo.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
860860
AllowSquash: true,
861861
AllowManualMerge: true,
862862
AutodetectManualMerge: false,
863+
AllowRebaseUpdate: true,
863864
DefaultDeleteBranchAfterMerge: false,
864865
DefaultMergeStyle: repo_model.MergeStyleMerge,
865866
}
@@ -888,6 +889,9 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
888889
if opts.AutodetectManualMerge != nil {
889890
config.AutodetectManualMerge = *opts.AutodetectManualMerge
890891
}
892+
if opts.AllowRebaseUpdate != nil {
893+
config.AllowRebaseUpdate = *opts.AllowRebaseUpdate
894+
}
891895
if opts.DefaultDeleteBranchAfterMerge != nil {
892896
config.DefaultDeleteBranchAfterMerge = *opts.DefaultDeleteBranchAfterMerge
893897
}

routers/web/repo/setting.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ func SettingsPost(ctx *context.Context) {
472472
AllowSquash: form.PullsAllowSquash,
473473
AllowManualMerge: form.PullsAllowManualMerge,
474474
AutodetectManualMerge: form.EnableAutodetectManualMerge,
475+
AllowRebaseUpdate: form.PullsAllowRebaseUpdate,
475476
DefaultDeleteBranchAfterMerge: form.DefaultDeleteBranchAfterMerge,
476477
DefaultMergeStyle: repo_model.MergeStyle(form.PullsDefaultMergeStyle),
477478
},

services/forms/repo_form.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ type RepoSettingForm struct {
151151
PullsAllowManualMerge bool
152152
PullsDefaultMergeStyle string
153153
EnableAutodetectManualMerge bool
154+
PullsAllowRebaseUpdate bool
154155
DefaultDeleteBranchAfterMerge bool
155156
EnableTimetracker bool
156157
AllowOnlyContributorsToTrackTime bool

services/pull/update.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"code.gitea.io/gitea/models"
1212
repo_model "code.gitea.io/gitea/models/repo"
13+
"code.gitea.io/gitea/models/unit"
1314
user_model "code.gitea.io/gitea/models/user"
1415
"code.gitea.io/gitea/modules/git"
1516
"code.gitea.io/gitea/modules/log"
@@ -97,7 +98,12 @@ func IsUserAllowedToUpdate(pull *models.PullRequest, user *user_model.User) (mer
9798

9899
// can't do rebase on protected branch because need force push
99100
if pr.ProtectedBranch == nil {
100-
rebaseAllowed = true
101+
prUnit, err := pr.BaseRepo.GetUnit(unit.TypePullRequests)
102+
if err != nil {
103+
log.Error("pr.BaseRepo.GetUnit(unit.TypePullRequests): %v", err)
104+
return false, false, err
105+
}
106+
rebaseAllowed = prUnit.PullRequestsConfig().AllowRebaseUpdate
101107
}
102108

103109
// Update function need push permission

templates/admin/dashboard.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{{template "base/alert" .}}
66
{{if .NeedUpdate}}
77
<div class="ui negative message flash-error">
8-
<p>{{.i18n.Tr "admin.dashboard.new_version_hint" (.RemoteVersion | Str2html) (AppVer | Str2html)}}</p>
8+
<p>{{(.i18n.Tr "admin.dashboard.new_version_hint" .RemoteVersion AppVer) | Str2html}}</p>
99
</div>
1010
{{end}}
1111
<h4 class="ui top attached header">

templates/repo/settings/options.tmpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,12 @@
448448
<label>{{.i18n.Tr "repo.settings.pulls.enable_autodetect_manual_merge"}}</label>
449449
</div>
450450
</div>
451+
<div class="field">
452+
<div class="ui checkbox">
453+
<input name="pulls_allow_rebase_update" type="checkbox" {{if or (not $pullRequestEnabled) ($prUnit.PullRequestsConfig.AllowRebaseUpdate)}}checked{{end}}>
454+
<label>{{.i18n.Tr "repo.settings.pulls.allow_rebase_update"}}</label>
455+
</div>
456+
</div>
451457
<div class="field">
452458
<div class="ui checkbox">
453459
<input name="default_delete_branch_after_merge" type="checkbox" {{if or (not $pullRequestEnabled) ($prUnit.PullRequestsConfig.DefaultDeleteBranchAfterMerge)}}checked{{end}}>

templates/swagger/v1_json.tmpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14809,6 +14809,11 @@
1480914809
"type": "boolean",
1481014810
"x-go-name": "AllowRebaseMerge"
1481114811
},
14812+
"allow_rebase_update": {
14813+
"description": "either `true` to allow updating pull request branch by rebase, or `false` to prevent it. `has_pull_requests` must be `true`.",
14814+
"type": "boolean",
14815+
"x-go-name": "AllowRebaseUpdate"
14816+
},
1481214817
"allow_squash_merge": {
1481314818
"description": "either `true` to allow squash-merging pull requests, or `false` to prevent squash-merging. `has_pull_requests` must be `true`.",
1481414819
"type": "boolean",

web_src/js/features/comp/EasyMDE.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ export async function createCommentEasyMDE(textarea, easyMDEOptions = {}) {
7474
const inputField = easyMDE.codemirror.getInputField();
7575
inputField.classList.add('js-quick-submit');
7676
easyMDE.codemirror.setOption('extraKeys', {
77-
Enter: () => {
77+
Enter: (cm) => {
7878
const tributeContainer = document.querySelector('.tribute-container');
7979
if (!tributeContainer || tributeContainer.style.display === 'none') {
80-
return window.CodeMirror.Pass;
80+
cm.execCommand('newlineAndIndent');
8181
}
8282
},
8383
Backspace: (cm) => {

web_src/js/features/repo-issue.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,8 @@ export function initRepoPullRequestReview() {
462462
(async () => {
463463
// the editor's height is too large in some cases, and the panel cannot be scrolled with page now because there is `.repository .diff-detail-box.sticky { position: sticky; }`
464464
// the temporary solution is to make the editor's height smaller (about 4 lines). GitHub also only show 4 lines for default. We can improve the UI (including Dropzone area) in future
465-
await createCommentEasyMDE($reviewBox.find('textarea'), {minHeight: '80px', maxHeight: 'calc(100vh - 360px)'});
465+
// EasyMDE's options can not handle minHeight & maxHeight together correctly, we have to set max-height for .CodeMirror-scroll in CSS.
466+
await createCommentEasyMDE($reviewBox.find('textarea'), {minHeight: '80px'});
466467
initCompImagePaste($reviewBox);
467468
})();
468469
}

web_src/less/_review.less

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,13 @@ a.blob-excerpt:hover {
197197
color: #fff;
198198
}
199199

200+
// See the comment of createCommentEasyMDE() for the review editor
201+
// EasyMDE's options can not handle minHeight & maxHeight together correctly, we have to set minHeight in JS code
202+
#review-box .CodeMirror-scroll {
203+
min-height: 80px;
204+
max-height: calc(100vh - 360px);
205+
}
206+
200207
@media @mediaSm {
201208
#review-box > .menu {
202209
> .ui.segment {

0 commit comments

Comments
 (0)