Skip to content

Commit 95dcedc

Browse files
committed
Merge remote-tracking branch 'upstream/main'
* upstream/main: Add some headings to repo views (go-gitea#22869) Fix style of actions rerun button (go-gitea#22835) Make issue and code search support camel case (go-gitea#22829) Revert "Fix notification and stopwatch empty states" (go-gitea#22876) Deduplicate findReadmeFile() (go-gitea#22177) Fix milestone title font problem (go-gitea#22863) Fix PR file tree folders no longer collapsing (go-gitea#22864) escape filename when assemble URL (go-gitea#22850) Fix notification and stopwatch empty states (go-gitea#22845) Fix .golangci.yml (go-gitea#22868) Fix migration issue. (go-gitea#22867) Add `/$count` endpoints for NuGet v2 (go-gitea#22855) Preview images for Issue cards in Project Board view (go-gitea#22112) Fix improper HTMLURL usages in Go code (go-gitea#22839) Use proxy for pull mirror (go-gitea#22771)
2 parents 3847a20 + c8093a1 commit 95dcedc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+459
-211
lines changed

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ linters:
2828
fast: false
2929

3030
run:
31-
go: 1.20
31+
go: "1.20"
3232
timeout: 10m
3333
skip-dirs:
3434
- node_modules

models/db/sql_postgres_with_schema.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ func (d *postgresSchemaDriver) Open(name string) (driver.Conn, error) {
3737
}
3838
schemaValue, _ := driver.String.ConvertValue(setting.Database.Schema)
3939

40-
if execer, ok := conn.(driver.Execer); ok {
40+
// golangci lint is incorrect here - there is no benefit to using driver.ExecerContext here
41+
// and in any case pq does not implement it
42+
if execer, ok := conn.(driver.Execer); ok { //nolint
4143
_, err := execer.Exec(`SELECT set_config(
4244
'search_path',
4345
$1 || ',' || current_setting('search_path'),
@@ -61,7 +63,8 @@ func (d *postgresSchemaDriver) Open(name string) (driver.Conn, error) {
6163

6264
// driver.String.ConvertValue will never return err for string
6365

64-
_, err = stmt.Exec([]driver.Value{schemaValue})
66+
// golangci lint is incorrect here - there is no benefit to using stmt.ExecWithContext here
67+
_, err = stmt.Exec([]driver.Value{schemaValue}) //nolint
6568
if err != nil {
6669
_ = conn.Close()
6770
return nil, err

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,8 @@ var migrations = []Migration{
455455
NewMigration("Add scope for access_token", v1_19.AddScopeForAccessTokens),
456456
// v240 -> v241
457457
NewMigration("Add actions tables", v1_19.AddActionsTables),
458+
// v241 -> v242
459+
NewMigration("Add card_type column to project table", v1_19.AddCardTypeToProjectTable),
458460
}
459461

460462
// GetCurrentDBVersion returns the current db version

models/migrations/v1_19/v241.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_19 //nolint
5+
6+
import (
7+
"xorm.io/xorm"
8+
)
9+
10+
// AddCardTypeToProjectTable: add CardType column, setting existing rows to CardTypeTextOnly
11+
func AddCardTypeToProjectTable(x *xorm.Engine) error {
12+
type Project struct {
13+
CardType int `xorm:"NOT NULL DEFAULT 0"`
14+
}
15+
16+
return x.Sync(new(Project))
17+
}

models/project/board.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ type (
1919
// BoardType is used to represent a project board type
2020
BoardType uint8
2121

22+
// CardType is used to represent a project board card type
23+
CardType uint8
24+
2225
// BoardList is a list of all project boards in a repository
2326
BoardList []*Board
2427
)
@@ -34,6 +37,14 @@ const (
3437
BoardTypeBugTriage
3538
)
3639

40+
const (
41+
// CardTypeTextOnly is a project board card type that is text only
42+
CardTypeTextOnly CardType = iota
43+
44+
// CardTypeImagesAndText is a project board card type that has images and text
45+
CardTypeImagesAndText
46+
)
47+
3748
// BoardColorPattern is a regexp witch can validate BoardColor
3849
var BoardColorPattern = regexp.MustCompile("^#[0-9a-fA-F]{6}$")
3950

@@ -85,6 +96,16 @@ func IsBoardTypeValid(p BoardType) bool {
8596
}
8697
}
8798

99+
// IsCardTypeValid checks if the project board card type is valid
100+
func IsCardTypeValid(p CardType) bool {
101+
switch p {
102+
case CardTypeTextOnly, CardTypeImagesAndText:
103+
return true
104+
default:
105+
return false
106+
}
107+
}
108+
88109
func createBoardsForProjectsType(ctx context.Context, project *Project) error {
89110
var items []string
90111

models/project/project.go

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,18 @@ import (
1919
)
2020

2121
type (
22-
// ProjectsConfig is used to identify the type of board that is being created
23-
ProjectsConfig struct {
22+
// BoardConfig is used to identify the type of board that is being created
23+
BoardConfig struct {
2424
BoardType BoardType
2525
Translation string
2626
}
2727

28+
// CardConfig is used to identify the type of board card that is being used
29+
CardConfig struct {
30+
CardType CardType
31+
Translation string
32+
}
33+
2834
// Type is used to identify the type of project in question and ownership
2935
Type uint8
3036
)
@@ -91,6 +97,7 @@ type Project struct {
9197
CreatorID int64 `xorm:"NOT NULL"`
9298
IsClosed bool `xorm:"INDEX"`
9399
BoardType BoardType
100+
CardType CardType
94101
Type Type
95102

96103
RenderedContent string `xorm:"-"`
@@ -145,15 +152,23 @@ func init() {
145152
db.RegisterModel(new(Project))
146153
}
147154

148-
// GetProjectsConfig retrieves the types of configurations projects could have
149-
func GetProjectsConfig() []ProjectsConfig {
150-
return []ProjectsConfig{
155+
// GetBoardConfig retrieves the types of configurations project boards could have
156+
func GetBoardConfig() []BoardConfig {
157+
return []BoardConfig{
151158
{BoardTypeNone, "repo.projects.type.none"},
152159
{BoardTypeBasicKanban, "repo.projects.type.basic_kanban"},
153160
{BoardTypeBugTriage, "repo.projects.type.bug_triage"},
154161
}
155162
}
156163

164+
// GetCardConfig retrieves the types of configurations project board cards could have
165+
func GetCardConfig() []CardConfig {
166+
return []CardConfig{
167+
{CardTypeTextOnly, "repo.projects.card_type.text_only"},
168+
{CardTypeImagesAndText, "repo.projects.card_type.images_and_text"},
169+
}
170+
}
171+
157172
// IsTypeValid checks if a project type is valid
158173
func IsTypeValid(p Type) bool {
159174
switch p {
@@ -237,6 +252,10 @@ func NewProject(p *Project) error {
237252
p.BoardType = BoardTypeNone
238253
}
239254

255+
if !IsCardTypeValid(p.CardType) {
256+
p.CardType = CardTypeTextOnly
257+
}
258+
240259
if !IsTypeValid(p.Type) {
241260
return util.NewInvalidArgumentErrorf("project type is not valid")
242261
}
@@ -280,9 +299,14 @@ func GetProjectByID(ctx context.Context, id int64) (*Project, error) {
280299

281300
// UpdateProject updates project properties
282301
func UpdateProject(ctx context.Context, p *Project) error {
302+
if !IsCardTypeValid(p.CardType) {
303+
p.CardType = CardTypeTextOnly
304+
}
305+
283306
_, err := db.GetEngine(ctx).ID(p.ID).Cols(
284307
"title",
285308
"description",
309+
"card_type",
286310
).Update(p)
287311
return err
288312
}

models/project/project_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func TestProject(t *testing.T) {
5353
project := &Project{
5454
Type: TypeRepository,
5555
BoardType: BoardTypeBasicKanban,
56+
CardType: CardTypeTextOnly,
5657
Title: "New Project",
5758
RepoID: 1,
5859
CreatedUnix: timeutil.TimeStampNow(),

models/repo/attachment.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,21 @@ func GetAttachmentsByIssueID(ctx context.Context, issueID int64) ([]*Attachment,
132132
return attachments, db.GetEngine(ctx).Where("issue_id = ? AND comment_id = 0", issueID).Find(&attachments)
133133
}
134134

135+
// GetAttachmentsByIssueIDImagesLatest returns the latest image attachments of an issue.
136+
func GetAttachmentsByIssueIDImagesLatest(ctx context.Context, issueID int64) ([]*Attachment, error) {
137+
attachments := make([]*Attachment, 0, 5)
138+
return attachments, db.GetEngine(ctx).Where(`issue_id = ? AND (name like '%.apng'
139+
OR name like '%.avif'
140+
OR name like '%.bmp'
141+
OR name like '%.gif'
142+
OR name like '%.jpg'
143+
OR name like '%.jpeg'
144+
OR name like '%.jxl'
145+
OR name like '%.png'
146+
OR name like '%.svg'
147+
OR name like '%.webp')`, issueID).Desc("comment_id").Limit(5).Find(&attachments)
148+
}
149+
135150
// GetAttachmentsByCommentID returns all attachments if comment by given ID.
136151
func GetAttachmentsByCommentID(ctx context.Context, commentID int64) ([]*Attachment, error) {
137152
attachments := make([]*Attachment, 0, 10)

models/repo/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ func (repo *Repository) CommitLink(commitID string) (result string) {
274274
if commitID == "" || commitID == "0000000000000000000000000000000000000000" {
275275
result = ""
276276
} else {
277-
result = repo.HTMLURL() + "/commit/" + url.PathEscape(commitID)
277+
result = repo.Link() + "/commit/" + url.PathEscape(commitID)
278278
}
279279
return result
280280
}

modules/context/repo.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -743,9 +743,9 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
743743

744744
if ctx.FormString("go-get") == "1" {
745745
ctx.Data["GoGetImport"] = ComposeGoGetImport(owner.Name, repo.Name)
746-
prefix := repo.HTMLURL() + "/src/branch/" + util.PathEscapeSegments(ctx.Repo.BranchName)
747-
ctx.Data["GoDocDirectory"] = prefix + "{/dir}"
748-
ctx.Data["GoDocFile"] = prefix + "{/dir}/{file}#L{line}"
746+
fullURLPrefix := repo.HTMLURL() + "/src/branch/" + util.PathEscapeSegments(ctx.Repo.BranchName)
747+
ctx.Data["GoDocDirectory"] = fullURLPrefix + "{/dir}"
748+
ctx.Data["GoDocFile"] = fullURLPrefix + "{/dir}/{file}#L{line}"
749749
}
750750
return cancel
751751
}

0 commit comments

Comments
 (0)