mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-02-23 11:55:48 -05:00
chore: Remove GetTopicByName
- Introduced in bec69f702b
and removed in
the same commit (only usage was in testing code).
This commit is contained in:
parent
5813244ff8
commit
a52b610eff
3 changed files with 1 additions and 39 deletions
|
@ -67,10 +67,6 @@ code.gitea.io/gitea/models/project
|
|||
code.gitea.io/gitea/models/repo
|
||||
DeleteAttachmentsByIssue
|
||||
FindReposMapByIDs
|
||||
IsErrTopicNotExist
|
||||
ErrTopicNotExist.Error
|
||||
ErrTopicNotExist.Unwrap
|
||||
GetTopicByName
|
||||
WatchRepoMode
|
||||
|
||||
code.gitea.io/gitea/models/user
|
||||
|
|
|
@ -5,14 +5,12 @@ package repo
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/container"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
@ -39,26 +37,6 @@ type RepoTopic struct { //revive:disable-line:exported
|
|||
TopicID int64 `xorm:"pk"`
|
||||
}
|
||||
|
||||
// ErrTopicNotExist represents an error that a topic is not exist
|
||||
type ErrTopicNotExist struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
// IsErrTopicNotExist checks if an error is an ErrTopicNotExist.
|
||||
func IsErrTopicNotExist(err error) bool {
|
||||
_, ok := err.(ErrTopicNotExist)
|
||||
return ok
|
||||
}
|
||||
|
||||
// Error implements error interface
|
||||
func (err ErrTopicNotExist) Error() string {
|
||||
return fmt.Sprintf("topic is not exist [name: %s]", err.Name)
|
||||
}
|
||||
|
||||
func (err ErrTopicNotExist) Unwrap() error {
|
||||
return util.ErrNotExist
|
||||
}
|
||||
|
||||
// ValidateTopic checks a topic by length and match pattern rules
|
||||
func ValidateTopic(topic string) bool {
|
||||
return len(topic) <= 35 && topicPattern.MatchString(topic)
|
||||
|
@ -91,17 +69,6 @@ func SanitizeAndValidateTopics(topics []string) (validTopics, invalidTopics []st
|
|||
return validTopics, invalidTopics
|
||||
}
|
||||
|
||||
// GetTopicByName retrieves topic by name
|
||||
func GetTopicByName(ctx context.Context, name string) (*Topic, error) {
|
||||
var topic Topic
|
||||
if has, err := db.GetEngine(ctx).Where("name = ?", name).Get(&topic); err != nil {
|
||||
return nil, err
|
||||
} else if !has {
|
||||
return nil, ErrTopicNotExist{name}
|
||||
}
|
||||
return &topic, nil
|
||||
}
|
||||
|
||||
// addTopicByNameToRepo adds a topic name to a repo and increments the topic count.
|
||||
// Returns topic after the addition
|
||||
func addTopicByNameToRepo(ctx context.Context, repoID int64, topicName string) (*Topic, error) {
|
||||
|
|
|
@ -52,8 +52,7 @@ func TestAddTopic(t *testing.T) {
|
|||
require.NoError(t, repo_model.SaveTopics(db.DefaultContext, 2, "golang", "gitea"))
|
||||
repo2NrOfTopics = 2
|
||||
totalNrOfTopics++
|
||||
topic, err := repo_model.GetTopicByName(db.DefaultContext, "gitea")
|
||||
require.NoError(t, err)
|
||||
topic := unittest.AssertExistsAndLoadBean(t, &repo_model.Topic{Name: "gitea"})
|
||||
assert.EqualValues(t, 1, topic.RepoCount)
|
||||
|
||||
topics, _, err = repo_model.FindTopics(db.DefaultContext, &repo_model.FindTopicOptions{})
|
||||
|
|
Loading…
Add table
Reference in a new issue