Skip to content

Commit 43236bf

Browse files
committed
Merge remote-tracking branch 'upstream/main'
* upstream/main: Always go full width in PR view (go-gitea#22844) Increase Content field size of gpg_key_import to MEDIUMTEXT (go-gitea#22897) Fix context bug (go-gitea#22940) Allow custom "created" timestamps in user creation API (go-gitea#22549) Use "Title Case" for text "Reference in new issue" (go-gitea#22936) First step to refactor the `.hide` to `.gt-hidden` (go-gitea#22916) Add continue option to backport.go (go-gitea#22930) Add `title` to PR file tree items (go-gitea#22918) # Conflicts: # templates/repo/issue/view_content/comments.tmpl
2 parents aa5736b + d9c6cb7 commit 43236bf

File tree

19 files changed

+188
-41
lines changed

19 files changed

+188
-41
lines changed

contrib/backport/backport.go

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ func main() {
7979
Name: "no-xdg-open",
8080
Usage: "Set this flag to not use xdg-open to open the PR URL",
8181
},
82+
cli.BoolFlag{
83+
Name: "continue",
84+
Usage: "Set this flag to continue from a git cherry-pick that has broken",
85+
},
8286
}
8387
cli.AppHelpTemplate = `NAME:
8488
{{.Name}} - {{.Usage}}
@@ -104,7 +108,19 @@ func runBackport(c *cli.Context) error {
104108
ctx, cancel := installSignals()
105109
defer cancel()
106110

111+
continuing := c.Bool("continue")
112+
113+
var pr string
114+
107115
version := c.String("version")
116+
if version == "" && continuing {
117+
// determine version from current branch name
118+
var err error
119+
pr, version, err = readCurrentBranch(ctx)
120+
if err != nil {
121+
return err
122+
}
123+
}
108124
if version == "" {
109125
version = readVersion()
110126
}
@@ -135,13 +151,14 @@ func runBackport(c *cli.Context) error {
135151
localReleaseBranch := path.Join(upstream, upstreamReleaseBranch)
136152

137153
args := c.Args()
138-
if len(args) == 0 {
154+
if len(args) == 0 && pr == "" {
139155
return fmt.Errorf("no PR number provided\nProvide a PR number to backport")
140-
} else if len(args) != 1 {
156+
} else if len(args) != 1 && pr == "" {
141157
return fmt.Errorf("multiple PRs provided %v\nOnly a single PR can be backported at a time", args)
142158
}
143-
144-
pr := args[0]
159+
if pr == "" {
160+
pr = args[0]
161+
}
145162

146163
backportBranch := c.String("backport-branch")
147164
if backportBranch == "" {
@@ -168,8 +185,10 @@ func runBackport(c *cli.Context) error {
168185
}
169186
}
170187

171-
if err := checkoutBackportBranch(ctx, backportBranch, localReleaseBranch); err != nil {
172-
return err
188+
if !continuing {
189+
if err := checkoutBackportBranch(ctx, backportBranch, localReleaseBranch); err != nil {
190+
return err
191+
}
173192
}
174193

175194
if err := cherrypick(ctx, sha); err != nil {
@@ -353,6 +372,22 @@ func determineRemote(ctx context.Context, forkUser string) (string, string, erro
353372
return "", "", fmt.Errorf("unable to find appropriate remote in:\n%s", string(out))
354373
}
355374

375+
func readCurrentBranch(ctx context.Context) (pr, version string, err error) {
376+
out, err := exec.CommandContext(ctx, "git", "branch", "--show-current").Output()
377+
if err != nil {
378+
fmt.Fprintf(os.Stderr, "Unable to read current git branch:\n%s\n", string(out))
379+
return "", "", fmt.Errorf("unable to read current git branch: %w", err)
380+
}
381+
parts := strings.Split(strings.TrimSpace(string(out)), "-")
382+
383+
if len(parts) != 3 || parts[0] != "backport" {
384+
fmt.Fprintf(os.Stderr, "Unable to continue from git branch:\n%s\n", string(out))
385+
return "", "", fmt.Errorf("unable to continue from git branch:\n%s", string(out))
386+
}
387+
388+
return parts[1], parts[2], nil
389+
}
390+
356391
func readVersion() string {
357392
bs, err := os.ReadFile("docs/config.yaml")
358393
if err != nil {

models/asymkey/gpg_key_import.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import "code.gitea.io/gitea/models/db"
2323
// GPGKeyImport the original import of key
2424
type GPGKeyImport struct {
2525
KeyID string `xorm:"pk CHAR(16) NOT NULL"`
26-
Content string `xorm:"TEXT NOT NULL"`
26+
Content string `xorm:"MEDIUMTEXT NOT NULL"`
2727
}
2828

2929
func init() {

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,8 @@ var migrations = []Migration{
457457
NewMigration("Add actions tables", v1_19.AddActionsTables),
458458
// v241 -> v242
459459
NewMigration("Add card_type column to project table", v1_19.AddCardTypeToProjectTable),
460+
// v242 -> v243
461+
NewMigration("Alter gpg_key_import content TEXT field to MEDIUMTEXT", v1_19.AlterPublicGPGKeyImportContentFieldToMediumText),
460462
}
461463

462464
// GetCurrentDBVersion returns the current db version

models/migrations/v1_19/v242.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_19 //nolint
5+
6+
import (
7+
"code.gitea.io/gitea/modules/setting"
8+
9+
"xorm.io/xorm"
10+
)
11+
12+
// AlterPublicGPGKeyImportContentFieldToMediumText: set GPGKeyImport Content field to MEDIUMTEXT
13+
func AlterPublicGPGKeyImportContentFieldToMediumText(x *xorm.Engine) error {
14+
sess := x.NewSession()
15+
defer sess.Close()
16+
if err := sess.Begin(); err != nil {
17+
return err
18+
}
19+
20+
if setting.Database.UseMySQL {
21+
if _, err := sess.Exec("ALTER TABLE `gpg_key_import` CHANGE `content` `content` MEDIUMTEXT"); err != nil {
22+
return err
23+
}
24+
}
25+
return sess.Commit()
26+
}

models/user/user.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,11 @@ func CreateUser(u *User, overwriteDefault ...*CreateUserOverwriteOptions) (err e
640640
u.IsRestricted = setting.Service.DefaultUserIsRestricted
641641
u.IsActive = !(setting.Service.RegisterEmailConfirm || setting.Service.RegisterManualConfirm)
642642

643+
// Ensure consistency of the dates.
644+
if u.UpdatedUnix < u.CreatedUnix {
645+
u.UpdatedUnix = u.CreatedUnix
646+
}
647+
643648
// overwrite defaults if set
644649
if len(overwriteDefault) != 0 && overwriteDefault[0] != nil {
645650
overwrite := overwriteDefault[0]
@@ -717,7 +722,15 @@ func CreateUser(u *User, overwriteDefault ...*CreateUserOverwriteOptions) (err e
717722
return err
718723
}
719724

720-
if err = db.Insert(ctx, u); err != nil {
725+
if u.CreatedUnix == 0 {
726+
// Caller expects auto-time for creation & update timestamps.
727+
err = db.Insert(ctx, u)
728+
} else {
729+
// Caller sets the timestamps themselves. They are responsible for ensuring
730+
// both `CreatedUnix` and `UpdatedUnix` are set appropriately.
731+
_, err = db.GetEngine(ctx).NoAutoTime().Insert(u)
732+
}
733+
if err != nil {
721734
return err
722735
}
723736

models/user/user_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@
44
package user_test
55

66
import (
7+
"context"
78
"math/rand"
89
"strings"
910
"testing"
11+
"time"
1012

1113
"code.gitea.io/gitea/models/auth"
1214
"code.gitea.io/gitea/models/db"
1315
"code.gitea.io/gitea/models/unittest"
1416
user_model "code.gitea.io/gitea/models/user"
1517
"code.gitea.io/gitea/modules/setting"
1618
"code.gitea.io/gitea/modules/structs"
19+
"code.gitea.io/gitea/modules/timeutil"
1720
"code.gitea.io/gitea/modules/util"
1821

1922
"github.com/stretchr/testify/assert"
@@ -252,6 +255,58 @@ func TestCreateUserEmailAlreadyUsed(t *testing.T) {
252255
assert.True(t, user_model.IsErrEmailAlreadyUsed(err))
253256
}
254257

258+
func TestCreateUserCustomTimestamps(t *testing.T) {
259+
assert.NoError(t, unittest.PrepareTestDatabase())
260+
261+
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
262+
263+
// Add new user with a custom creation timestamp.
264+
var creationTimestamp timeutil.TimeStamp = 12345
265+
user.Name = "testuser"
266+
user.LowerName = strings.ToLower(user.Name)
267+
user.ID = 0
268+
user.Email = "[email protected]"
269+
user.CreatedUnix = creationTimestamp
270+
err := user_model.CreateUser(user)
271+
assert.NoError(t, err)
272+
273+
fetched, err := user_model.GetUserByID(context.Background(), user.ID)
274+
assert.NoError(t, err)
275+
assert.Equal(t, creationTimestamp, fetched.CreatedUnix)
276+
assert.Equal(t, creationTimestamp, fetched.UpdatedUnix)
277+
}
278+
279+
func TestCreateUserWithoutCustomTimestamps(t *testing.T) {
280+
assert.NoError(t, unittest.PrepareTestDatabase())
281+
282+
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
283+
284+
// There is no way to use a mocked time for the XORM auto-time functionality,
285+
// so use the real clock to approximate the expected timestamp.
286+
timestampStart := time.Now().Unix()
287+
288+
// Add new user without a custom creation timestamp.
289+
user.Name = "Testuser"
290+
user.LowerName = strings.ToLower(user.Name)
291+
user.ID = 0
292+
user.Email = "[email protected]"
293+
user.CreatedUnix = 0
294+
user.UpdatedUnix = 0
295+
err := user_model.CreateUser(user)
296+
assert.NoError(t, err)
297+
298+
timestampEnd := time.Now().Unix()
299+
300+
fetched, err := user_model.GetUserByID(context.Background(), user.ID)
301+
assert.NoError(t, err)
302+
303+
assert.LessOrEqual(t, timestampStart, fetched.CreatedUnix)
304+
assert.LessOrEqual(t, fetched.CreatedUnix, timestampEnd)
305+
306+
assert.LessOrEqual(t, timestampStart, fetched.UpdatedUnix)
307+
assert.LessOrEqual(t, fetched.UpdatedUnix, timestampEnd)
308+
}
309+
255310
func TestGetUserIDsByNames(t *testing.T) {
256311
assert.NoError(t, unittest.PrepareTestDatabase())
257312

modules/structs/admin_user.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
package structs
66

7+
import "time"
8+
79
// CreateUserOption create user options
810
type CreateUserOption struct {
911
SourceID int64 `json:"source_id"`
@@ -20,6 +22,11 @@ type CreateUserOption struct {
2022
SendNotify bool `json:"send_notify"`
2123
Restricted *bool `json:"restricted"`
2224
Visibility string `json:"visibility" binding:"In(,public,limited,private)"`
25+
26+
// For explicitly setting the user creation timestamp. Useful when users are
27+
// migrated from other systems. When omitted, the user's creation timestamp
28+
// will be set to "now".
29+
Created *time.Time `json:"created_at"`
2330
}
2431

2532
// EditUserOption edit user options

options/locale/locale_en-US.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ issues.commented_at = `commented <a href="#%s">%s</a>`
13611361
issues.delete_comment_confirm = Are you sure you want to delete this comment?
13621362
issues.context.copy_link = Copy Link
13631363
issues.context.quote_reply = Quote Reply
1364-
issues.context.reference_issue = Reference in new issue
1364+
issues.context.reference_issue = Reference in New Issue
13651365
issues.context.edit = Edit
13661366
issues.context.delete = Delete
13671367
issues.no_content = There is no content yet.

routers/api/v1/admin/user.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"code.gitea.io/gitea/modules/password"
2121
"code.gitea.io/gitea/modules/setting"
2222
api "code.gitea.io/gitea/modules/structs"
23+
"code.gitea.io/gitea/modules/timeutil"
2324
"code.gitea.io/gitea/modules/util"
2425
"code.gitea.io/gitea/modules/web"
2526
"code.gitea.io/gitea/routers/api/v1/user"
@@ -120,6 +121,14 @@ func CreateUser(ctx *context.APIContext) {
120121
overwriteDefault.Visibility = &visibility
121122
}
122123

124+
// Update the user creation timestamp. This can only be done after the user
125+
// record has been inserted into the database; the insert intself will always
126+
// set the creation timestamp to "now".
127+
if form.Created != nil {
128+
u.CreatedUnix = timeutil.TimeStamp(form.Created.Unix())
129+
u.UpdatedUnix = u.CreatedUnix
130+
}
131+
123132
if err := user_model.CreateUser(u, overwriteDefault); err != nil {
124133
if user_model.IsErrUserAlreadyExist(err) ||
125134
user_model.IsErrEmailAlreadyUsed(err) ||

templates/repo/commit_page.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{{template "base/head" .}}
22
<div role="main" aria-label="{{.Title}}" class="page-content repository diff">
33
{{template "repo/header" .}}
4-
<div class="ui container {{if .IsSplitStyle}}fluid padded{{end}}">
4+
<div class="ui container fluid padded">
55
{{$class := ""}}
66
{{if .Commit.Signature}}
77
{{$class = (printf "%s%s" $class " isSigned")}}

templates/repo/diff/compare.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{{template "base/head" .}}
22
<div role="main" aria-label="{{.Title}}" class="page-content repository diff {{if .PageIsComparePull}}compare pull{{end}}">
33
{{template "repo/header" .}}
4-
<div class="ui container {{if .IsSplitStyle}}fluid padded{{end}}">
4+
<div class="ui container fluid padded">
55

66
<h2 class="ui header">
77
{{if and $.PageIsComparePull $.IsSigned (not .Repository.IsArchived)}}

templates/repo/issue/view_content/comments.tmpl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,7 @@
213213
{{end}}
214214
</span>
215215
{{else}}
216-
<!-- Bug fix for user Assignee -->
217-
{{template "shared/user/avatarlink" Dict "Context" $.Context "user" .Assignee}}
216+
{{template "shared/user/avatarlink" Dict "Context" $.Context "user" .Assignee}}
218217
<span class="text grey muted-links">
219218
{{template "shared/user/authorlink" .Assignee}}
220219
{{if eq .Poster.ID .AssigneeID}}
@@ -486,15 +485,15 @@
486485
</div>
487486
<div>
488487
{{if or $invalid $resolved}}
489-
<button id="show-outdated-{{(index $comms 0).ID}}" data-comment="{{(index $comms 0).ID}}" class="{{if not $resolved}}hide {{end}}ui compact right labeled button show-outdated gt-df gt-ac">
488+
<button id="show-outdated-{{(index $comms 0).ID}}" data-comment="{{(index $comms 0).ID}}" class="{{if not $resolved}}gt-hidden {{end}}ui compact right labeled button show-outdated gt-df gt-ac">
490489
{{svg "octicon-unfold" 16 "gt-mr-3"}}
491490
{{if $resolved}}
492491
{{$.locale.Tr "repo.issues.review.show_resolved"}}
493492
{{else}}
494493
{{$.locale.Tr "repo.issues.review.show_outdated"}}
495494
{{end}}
496495
</button>
497-
<button id="hide-outdated-{{(index $comms 0).ID}}" data-comment="{{(index $comms 0).ID}}" class="{{if $resolved}}hide {{end}}ui compact right labeled button hide-outdated gt-df gt-ac">
496+
<button id="hide-outdated-{{(index $comms 0).ID}}" data-comment="{{(index $comms 0).ID}}" class="{{if $resolved}}gt-hidden {{end}}ui compact right labeled button hide-outdated gt-df gt-ac">
498497
{{svg "octicon-fold" 16 "gt-mr-3"}}
499498
{{if $resolved}}
500499
{{$.locale.Tr "repo.issues.review.hide_resolved"}}
@@ -508,7 +507,7 @@
508507
{{$diff := (CommentMustAsDiff (index $comms 0))}}
509508
{{if $diff}}
510509
{{$file := (index $diff.Files 0)}}
511-
<div id="code-preview-{{(index $comms 0).ID}}" class="ui table segment{{if $resolved}} hide{{end}}">
510+
<div id="code-preview-{{(index $comms 0).ID}}" class="ui table segment{{if $resolved}} gt-hidden{{end}}">
512511
<div class="diff-file-box diff-box file-content {{TabSizeClass $.Editorconfig $file.Name}}">
513512
<div class="file-body file-code code-view code-diff code-diff-unified unicode-escaped">
514513
<table>
@@ -520,7 +519,7 @@
520519
</div>
521520
</div>
522521
{{end}}
523-
<div id="code-comments-{{(index $comms 0).ID}}" class="comment-code-cloud ui segment{{if $resolved}} hide{{end}}">
522+
<div id="code-comments-{{(index $comms 0).ID}}" class="comment-code-cloud ui segment{{if $resolved}} gt-hidden{{end}}">
524523
<div class="ui comments gt-mb-0">
525524
{{range $comms}}
526525
{{$createdSubStr:= TimeSinceUnix .CreatedUnix $.locale}}

templates/repo/pulls/files.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<div role="main" aria-label="{{.Title}}" class="page-content repository view issue pull files diff">
77
{{template "repo/header" .}}
8-
<div class="ui container {{if .IsSplitStyle}}fluid padded{{end}}">
8+
<div class="ui container fluid padded">
99
<div class="navbar">
1010
{{template "repo/issue/navbar" .}}
1111
<div class="ui right">

templates/swagger/v1_json.tmpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15809,6 +15809,12 @@
1580915809
"password"
1581015810
],
1581115811
"properties": {
15812+
"created_at": {
15813+
"description": "For explicitly setting the user creation timestamp. Useful when users are\nmigrated from other systems. When omitted, the user's creation timestamp\nwill be set to \"now\".",
15814+
"type": "string",
15815+
"format": "date-time",
15816+
"x-go-name": "Created"
15817+
},
1581215818
"email": {
1581315819
"type": "string",
1581415820
"format": "email",

web_src/js/components/DiffFileTreeItem.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<template>
2-
<div v-show="show">
2+
<div v-show="show" class="tooltip" :title="item.name">
3+
<!--title instead of tooltip above as the tooltip needs too much work with the current methods, i.e. not being loaded or staying open for "too long"-->
34
<div class="item" :class="item.isFile ? 'filewrapper gt-p-1' : ''">
45
<!-- Files -->
56
<SvgIcon

0 commit comments

Comments
 (0)