···2121 "xorm.io/builder"
2222)
23232424-// FindReposMapByIDs find repos as map
2525-func FindReposMapByIDs(ctx context.Context, repoIDs []int64, res map[int64]*Repository) error {
2626- return db.GetEngine(ctx).In("id", repoIDs).Find(&res)
2727-}
2828-2924// RepositoryListDefaultPageSize is the default number of repositories
3025// to load in memory when running administrative tasks on all (or almost
3126// all) of them.
-33
models/repo/topic.go
···5566import (
77 "context"
88- "fmt"
98 "regexp"
109 "strings"
11101211 "code.gitea.io/gitea/models/db"
1312 "code.gitea.io/gitea/modules/container"
1413 "code.gitea.io/gitea/modules/timeutil"
1515- "code.gitea.io/gitea/modules/util"
16141715 "xorm.io/builder"
1816)
···3937 TopicID int64 `xorm:"pk"`
4038}
41394242-// ErrTopicNotExist represents an error that a topic is not exist
4343-type ErrTopicNotExist struct {
4444- Name string
4545-}
4646-4747-// IsErrTopicNotExist checks if an error is an ErrTopicNotExist.
4848-func IsErrTopicNotExist(err error) bool {
4949- _, ok := err.(ErrTopicNotExist)
5050- return ok
5151-}
5252-5353-// Error implements error interface
5454-func (err ErrTopicNotExist) Error() string {
5555- return fmt.Sprintf("topic is not exist [name: %s]", err.Name)
5656-}
5757-5858-func (err ErrTopicNotExist) Unwrap() error {
5959- return util.ErrNotExist
6060-}
6161-6240// ValidateTopic checks a topic by length and match pattern rules
6341func ValidateTopic(topic string) bool {
6442 return len(topic) <= 35 && topicPattern.MatchString(topic)
···8967 }
90689169 return validTopics, invalidTopics
9292-}
9393-9494-// GetTopicByName retrieves topic by name
9595-func GetTopicByName(ctx context.Context, name string) (*Topic, error) {
9696- var topic Topic
9797- if has, err := db.GetEngine(ctx).Where("name = ?", name).Get(&topic); err != nil {
9898- return nil, err
9999- } else if !has {
100100- return nil, ErrTopicNotExist{name}
101101- }
102102- return &topic, nil
10370}
1047110572// addTopicByNameToRepo adds a topic name to a repo and increments the topic count.
···3434 }
3535}
36363737-// IsDetails returns true if the given node implements the Details interface,
3838-// otherwise false.
3939-func IsDetails(node ast.Node) bool {
4040- _, ok := node.(*Details)
4141- return ok
4242-}
4343-4437// Summary is a block that contains the summary of details block
4538type Summary struct {
4639 ast.BaseBlock
···6457 return &Summary{
6558 BaseBlock: ast.BaseBlock{},
6659 }
6767-}
6868-6969-// IsSummary returns true if the given node implements the Summary interface,
7070-// otherwise false.
7171-func IsSummary(node ast.Node) bool {
7272- _, ok := node.(*Summary)
7373- return ok
7460}
75617662// TaskCheckBoxListItem is a block that represents a list item of a markdown block with a checkbox
···10389 }
10490}
10591106106-// IsTaskCheckBoxListItem returns true if the given node implements the TaskCheckBoxListItem interface,
107107-// otherwise false.
108108-func IsTaskCheckBoxListItem(node ast.Node) bool {
109109- _, ok := node.(*TaskCheckBoxListItem)
110110- return ok
111111-}
112112-11392// Icon is an inline for a fomantic icon
11493type Icon struct {
11594 ast.BaseInline
···137116 BaseInline: ast.BaseInline{},
138117 Name: []byte(name),
139118 }
140140-}
141141-142142-// IsIcon returns true if the given node implements the Icon interface,
143143-// otherwise false.
144144-func IsIcon(node ast.Node) bool {
145145- _, ok := node.(*Icon)
146146- return ok
147119}
148120149121// ColorPreview is an inline for a color preview
-22
modules/markup/markdown/math/math.go
···3939 })
4040}
41414242-// WithInlineDollarParser enables or disables the parsing of $...$
4343-func WithInlineDollarParser(enable ...bool) Option {
4444- value := true
4545- if len(enable) > 0 {
4646- value = enable[0]
4747- }
4848- return extensionFunc(func(e *Extension) {
4949- e.parseDollarInline = value
5050- })
5151-}
5252-5353-// WithBlockDollarParser enables or disables the parsing of $$...$$
5454-func WithBlockDollarParser(enable ...bool) Option {
5555- value := true
5656- if len(enable) > 0 {
5757- value = enable[0]
5858- }
5959- return extensionFunc(func(e *Extension) {
6060- e.parseDollarBlock = value
6161- })
6262-}
6363-6442// Math represents a math extension with default rendered delimiters
6543var Math = &Extension{
6644 enabled: true,
···272272273273 // update team information and then check permission
274274 team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: 5})
275275- err = organization.UpdateTeamUnits(db.DefaultContext, team, nil)
276276- require.NoError(t, err)
275275+ unittest.AssertSuccessfulDelete(t, &organization.TeamUnit{TeamID: team.ID})
277276 perm, err = access_model.GetUserRepoPermission(db.DefaultContext, repo, owner)
278277 require.NoError(t, err)
279278 for _, unit := range repo.Units {
-19
modules/storage/storage.go
···1818// ErrURLNotSupported represents url is not supported
1919var ErrURLNotSupported = errors.New("url method not supported")
20202121-// ErrInvalidConfiguration is called when there is invalid configuration for a storage
2222-type ErrInvalidConfiguration struct {
2323- cfg any
2424- err error
2525-}
2626-2727-func (err ErrInvalidConfiguration) Error() string {
2828- if err.err != nil {
2929- return fmt.Sprintf("Invalid Configuration Argument: %v: Error: %v", err.cfg, err.err)
3030- }
3131- return fmt.Sprintf("Invalid Configuration Argument: %v", err.cfg)
3232-}
3333-3434-// IsErrInvalidConfiguration checks if an error is an ErrInvalidConfiguration
3535-func IsErrInvalidConfiguration(err error) bool {
3636- _, ok := err.(ErrInvalidConfiguration)
3737- return ok
3838-}
3939-4021type Type = setting.StorageType
41224223// NewStorageFunc is a function that creates a storage
-36
modules/structs/hook.go
···141141 return json.MarshalIndent(p, "", " ")
142142}
143143144144-// ParseCreateHook parses create event hook content.
145145-func ParseCreateHook(raw []byte) (*CreatePayload, error) {
146146- hook := new(CreatePayload)
147147- if err := json.Unmarshal(raw, hook); err != nil {
148148- return nil, err
149149- }
150150-151151- // it is possible the JSON was parsed, however,
152152- // was not from Gogs (maybe was from Bitbucket)
153153- // So we'll check to be sure certain key fields
154154- // were populated
155155- switch {
156156- case hook.Repo == nil:
157157- return nil, ErrInvalidReceiveHook
158158- case len(hook.Ref) == 0:
159159- return nil, ErrInvalidReceiveHook
160160- }
161161- return hook, nil
162162-}
163163-164144// ________ .__ __
165145// \______ \ ____ | | _____/ |_ ____
166146// | | \_/ __ \| | _/ __ \ __\/ __ \
···290270// JSONPayload FIXME
291271func (p *PushPayload) JSONPayload() ([]byte, error) {
292272 return json.MarshalIndent(p, "", " ")
293293-}
294294-295295-// ParsePushHook parses push event hook content.
296296-func ParsePushHook(raw []byte) (*PushPayload, error) {
297297- hook := new(PushPayload)
298298- if err := json.Unmarshal(raw, hook); err != nil {
299299- return nil, err
300300- }
301301-302302- switch {
303303- case hook.Repo == nil:
304304- return nil, ErrInvalidReceiveHook
305305- case len(hook.Ref) == 0:
306306- return nil, ErrInvalidReceiveHook
307307- }
308308- return hook, nil
309273}
310274311275// Branch returns branch name from a payload
-6
modules/web/middleware/locale.go
···5353func SetLocaleCookie(resp http.ResponseWriter, lang string, maxAge int) {
5454 SetSiteCookie(resp, "lang", lang, maxAge)
5555}
5656-5757-// DeleteLocaleCookie convenience function to delete the locale cookie consistently
5858-// Setting the lang cookie will trigger the middleware to reset the language to previous state.
5959-func DeleteLocaleCookie(resp http.ResponseWriter) {
6060- SetSiteCookie(resp, "lang", "", -1)
6161-}
-18
services/convert/secret.go
···11-// Copyright 2023 The Gitea Authors. All rights reserved.
22-// SPDX-License-Identifier: MIT
33-44-package convert
55-66-import (
77- secret_model "code.gitea.io/gitea/models/secret"
88- api "code.gitea.io/gitea/modules/structs"
99-)
1010-1111-// ToSecret converts Secret to API format
1212-func ToSecret(secret *secret_model.Secret) *api.Secret {
1313- result := &api.Secret{
1414- Name: secret.Name,
1515- }
1616-1717- return result
1818-}