diff --git a/.deadcode-out b/.deadcode-out index 70a74128eb..59f82f0167 100644 --- a/.deadcode-out +++ b/.deadcode-out @@ -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 diff --git a/models/repo/topic.go b/models/repo/topic.go index 6db6c8aef8..2f14ff7f62 100644 --- a/models/repo/topic.go +++ b/models/repo/topic.go @@ -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) { diff --git a/models/repo/topic_test.go b/models/repo/topic_test.go index 45cee524b6..f87ef2bcdf 100644 --- a/models/repo/topic_test.go +++ b/models/repo/topic_test.go @@ -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{})