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
}

modules/git/repo.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,8 @@ func CloneWithArgs(ctx context.Context, args TrustedCmdArgs, from, to string, op
163163

164164
envs := os.Environ()
165165
u, err := url.Parse(from)
166-
if err == nil && (strings.EqualFold(u.Scheme, "http") || strings.EqualFold(u.Scheme, "https")) {
167-
if proxy.Match(u.Host) {
168-
envs = append(envs, fmt.Sprintf("https_proxy=%s", proxy.GetProxyURL()))
169-
}
166+
if err == nil {
167+
envs = proxy.EnvWithProxy(u)
170168
}
171169

172170
stderr := new(bytes.Buffer)

modules/git/tree_entry.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ func (te *TreeEntry) FollowLinks() (*TreeEntry, error) {
101101
return entry, nil
102102
}
103103

104+
// returns the subtree, or nil if this is not a tree
105+
func (te *TreeEntry) Tree() *Tree {
106+
t, err := te.ptree.repo.getTree(te.ID)
107+
if err != nil {
108+
return nil
109+
}
110+
return t
111+
}
112+
104113
// GetSubJumpablePathName return the full path of subdirectory jumpable ( contains only one directory )
105114
func (te *TreeEntry) GetSubJumpablePathName() string {
106115
if te.IsSubModule() || !te.IsDir() {

modules/indexer/code/bleve.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/blevesearch/bleve/v2"
2828
analyzer_custom "github.com/blevesearch/bleve/v2/analysis/analyzer/custom"
2929
analyzer_keyword "github.com/blevesearch/bleve/v2/analysis/analyzer/keyword"
30+
"github.com/blevesearch/bleve/v2/analysis/token/camelcase"
3031
"github.com/blevesearch/bleve/v2/analysis/token/lowercase"
3132
"github.com/blevesearch/bleve/v2/analysis/token/unicodenorm"
3233
"github.com/blevesearch/bleve/v2/analysis/tokenizer/unicode"
@@ -107,7 +108,7 @@ func (d *RepoIndexerData) Type() string {
107108
const (
108109
repoIndexerAnalyzer = "repoIndexerAnalyzer"
109110
repoIndexerDocType = "repoIndexerDocType"
110-
repoIndexerLatestVersion = 5
111+
repoIndexerLatestVersion = 6
111112
)
112113

113114
// createBleveIndexer create a bleve repo indexer if one does not already exist
@@ -138,7 +139,7 @@ func createBleveIndexer(path string, latestVersion int) (bleve.Index, error) {
138139
"type": analyzer_custom.Name,
139140
"char_filters": []string{},
140141
"tokenizer": unicode.Name,
141-
"token_filters": []string{unicodeNormalizeName, lowercase.Name},
142+
"token_filters": []string{unicodeNormalizeName, camelcase.Name, lowercase.Name},
142143
}); err != nil {
143144
return nil, err
144145
}

modules/indexer/issues/bleve.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
"github.com/blevesearch/bleve/v2"
1717
"github.com/blevesearch/bleve/v2/analysis/analyzer/custom"
18+
"github.com/blevesearch/bleve/v2/analysis/token/camelcase"
1819
"github.com/blevesearch/bleve/v2/analysis/token/lowercase"
1920
"github.com/blevesearch/bleve/v2/analysis/token/unicodenorm"
2021
"github.com/blevesearch/bleve/v2/analysis/tokenizer/unicode"
@@ -27,7 +28,7 @@ import (
2728
const (
2829
issueIndexerAnalyzer = "issueIndexer"
2930
issueIndexerDocType = "issueIndexerDocType"
30-
issueIndexerLatestVersion = 1
31+
issueIndexerLatestVersion = 2
3132
)
3233

3334
// indexerID a bleve-compatible unique identifier for an integer id
@@ -134,7 +135,7 @@ func createIssueIndexer(path string, latestVersion int) (bleve.Index, error) {
134135
"type": custom.Name,
135136
"char_filters": []string{},
136137
"tokenizer": unicode.Name,
137-
"token_filters": []string{unicodeNormalizeName, lowercase.Name},
138+
"token_filters": []string{unicodeNormalizeName, camelcase.Name, lowercase.Name},
138139
}); err != nil {
139140
return nil, err
140141
}

modules/lfs/endpoint.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
package lfs
55

66
import (
7-
"fmt"
87
"net/url"
98
"os"
109
"path"
1110
"path/filepath"
1211
"strings"
1312

1413
"code.gitea.io/gitea/modules/log"
14+
"code.gitea.io/gitea/modules/util"
1515
)
1616

1717
// DetermineEndpoint determines an endpoint from the clone url or uses the specified LFS url.
@@ -95,7 +95,7 @@ func endpointFromLocalPath(path string) *url.URL {
9595
return nil
9696
}
9797

98-
path = fmt.Sprintf("file://%s%s", slash, filepath.ToSlash(path))
98+
path = "file://" + slash + util.PathEscapeSegments(filepath.ToSlash(path))
9999

100100
u, _ := url.Parse(path)
101101

modules/proxy/proxy.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/http"
88
"net/url"
99
"os"
10+
"strings"
1011
"sync"
1112

1213
"code.gitea.io/gitea/modules/log"
@@ -82,3 +83,16 @@ func Proxy() func(req *http.Request) (*url.URL, error) {
8283
return http.ProxyFromEnvironment(req)
8384
}
8485
}
86+
87+
// EnvWithProxy returns os.Environ(), with a https_proxy env, if the given url
88+
// needs to be proxied.
89+
func EnvWithProxy(u *url.URL) []string {
90+
envs := os.Environ()
91+
if strings.EqualFold(u.Scheme, "http") || strings.EqualFold(u.Scheme, "https") {
92+
if Match(u.Host) {
93+
envs = append(envs, "https_proxy="+GetProxyURL())
94+
}
95+
}
96+
97+
return envs
98+
}

options/locale/locale_en-US.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,9 @@ projects.board.color = "Color"
12311231
projects.open = Open
12321232
projects.close = Close
12331233
projects.board.assigned_to = Assigned to
1234+
projects.card_type.desc = "Card Previews"
1235+
projects.card_type.images_and_text = "Images and Text"
1236+
projects.card_type.text_only = "Text Only"
12341237
12351238
issues.desc = Organize bug reports, tasks and milestones.
12361239
issues.filter_assignees = Filter Assignee

routers/api/packages/api.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,18 @@ func CommonRoutes(ctx gocontext.Context) *web.Route {
286286
}, reqPackageAccess(perm.AccessModeWrite))
287287
r.Get("/symbols/{filename}/{guid:[0-9a-fA-F]{32}[fF]{8}}/{filename2}", nuget.DownloadSymbolFile)
288288
r.Get("/Packages(Id='{id:[^']+}',Version='{version:[^']+}')", nuget.RegistrationLeafV2)
289-
r.Get("/Packages()", nuget.SearchServiceV2)
290-
r.Get("/FindPackagesById()", nuget.EnumeratePackageVersionsV2)
291-
r.Get("/Search()", nuget.SearchServiceV2)
289+
r.Group("/Packages()", func() {
290+
r.Get("", nuget.SearchServiceV2)
291+
r.Get("/$count", nuget.SearchServiceV2Count)
292+
})
293+
r.Group("/FindPackagesById()", func() {
294+
r.Get("", nuget.EnumeratePackageVersionsV2)
295+
r.Get("/$count", nuget.EnumeratePackageVersionsV2Count)
296+
})
297+
r.Group("/Search()", func() {
298+
r.Get("", nuget.SearchServiceV2)
299+
r.Get("/$count", nuget.SearchServiceV2Count)
300+
})
292301
}, reqPackageAccess(perm.AccessModeRead))
293302
})
294303
r.Group("/npm", func() {

0 commit comments

Comments
 (0)