diff --git a/.deadcode-out b/.deadcode-out
index 70a74128eb..403a6e40d2 100644
--- a/.deadcode-out
+++ b/.deadcode-out
@@ -10,20 +10,10 @@ code.gitea.io/gitea/cmd/forgejo
ContextSetStdin
code.gitea.io/gitea/models
- IsErrUpdateTaskNotExist
- ErrUpdateTaskNotExist.Error
- ErrUpdateTaskNotExist.Unwrap
IsErrSHANotFound
IsErrMergeDivergingFastForwardOnly
-code.gitea.io/gitea/models/actions
- ScheduleList.GetUserIDs
- ScheduleList.GetRepoIDs
- ScheduleList.LoadTriggerUser
- ScheduleList.LoadRepos
-
code.gitea.io/gitea/models/auth
- GetSourceByName
WebAuthnCredentials
code.gitea.io/gitea/models/db
@@ -52,25 +42,12 @@ code.gitea.io/gitea/models/issues
IsErrIssueWasClosed
code.gitea.io/gitea/models/organization
- GetTeamNamesByID
- UpdateTeamUnits
SearchMembersOptions.ToConds
- UsersInTeamsCount
code.gitea.io/gitea/models/perm/access
GetRepoWriters
-code.gitea.io/gitea/models/project
- UpdateColumnSorting
- ChangeProjectStatus
-
code.gitea.io/gitea/models/repo
- DeleteAttachmentsByIssue
- FindReposMapByIDs
- IsErrTopicNotExist
- ErrTopicNotExist.Error
- ErrTopicNotExist.Unwrap
- GetTopicByName
WatchRepoMode
code.gitea.io/gitea/models/user
@@ -103,9 +80,6 @@ code.gitea.io/gitea/modules/cache
WithNoCacheContext
RemoveContextData
-code.gitea.io/gitea/modules/charset
- BreakWriter.Write
-
code.gitea.io/gitea/modules/emoji
ReplaceCodes
@@ -127,10 +101,7 @@ code.gitea.io/gitea/modules/git
CommitChangesWithArgs
SetUpdateHook
openRepositoryWithDefaultContext
- IsTagExist
ToEntryMode
- LimitedReaderCloser.Read
- LimitedReaderCloser.Close
code.gitea.io/gitea/modules/gitgraph
Parser.Reset
@@ -171,16 +142,8 @@ code.gitea.io/gitea/modules/markup/console
RenderString
code.gitea.io/gitea/modules/markup/markdown
- IsDetails
- IsSummary
- IsTaskCheckBoxListItem
- IsIcon
RenderRawString
-code.gitea.io/gitea/modules/markup/markdown/math
- WithInlineDollarParser
- WithBlockDollarParser
-
code.gitea.io/gitea/modules/markup/mdstripper
stripRenderer.AddOptions
StripMarkdown
@@ -188,9 +151,6 @@ code.gitea.io/gitea/modules/markup/mdstripper
code.gitea.io/gitea/modules/markup/orgmode
RenderString
-code.gitea.io/gitea/modules/private
- ActionsRunnerRegister
-
code.gitea.io/gitea/modules/process
Manager.ExecTimeout
@@ -213,14 +173,6 @@ code.gitea.io/gitea/modules/setting
GitConfigType.GetOption
InitLoggersForTest
-code.gitea.io/gitea/modules/storage
- ErrInvalidConfiguration.Error
- IsErrInvalidConfiguration
-
-code.gitea.io/gitea/modules/structs
- ParseCreateHook
- ParsePushHook
-
code.gitea.io/gitea/modules/sync
StatusTable.Start
StatusTable.IsRunning
@@ -252,9 +204,6 @@ code.gitea.io/gitea/modules/web
RouteMock
RouteMockReset
-code.gitea.io/gitea/modules/web/middleware
- DeleteLocaleCookie
-
code.gitea.io/gitea/modules/zstd
NewWriter
Writer.Write
@@ -269,23 +218,11 @@ code.gitea.io/gitea/routers/web/org
code.gitea.io/gitea/services/context
GetPrivateContext
-code.gitea.io/gitea/services/convert
- ToSecret
-
-code.gitea.io/gitea/services/forms
- DeadlineForm.Validate
-
-code.gitea.io/gitea/services/pull
- IsCommitStatusContextSuccess
-
code.gitea.io/gitea/services/repository
IsErrForkAlreadyExist
code.gitea.io/gitea/services/repository/files
ContentType.String
- GetFileResponseFromCommit
- TemporaryUploadRepository.GetLastCommit
- TemporaryUploadRepository.GetLastCommitByRef
code.gitea.io/gitea/services/webhook
NewNotifier
diff --git a/models/actions/schedule.go b/models/actions/schedule.go
index 8b7e6ec44f..f14625c740 100644
--- a/models/actions/schedule.go
+++ b/models/actions/schedule.go
@@ -14,6 +14,8 @@ import (
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
webhook_module "code.gitea.io/gitea/modules/webhook"
+
+ "xorm.io/builder"
)
// ActionSchedule represents a schedule of a workflow file
@@ -140,3 +142,25 @@ func CleanRepoScheduleTasks(ctx context.Context, repo *repo_model.Repository, ca
}
return nil
}
+
+type FindScheduleOptions struct {
+ db.ListOptions
+ RepoID int64
+ OwnerID int64
+}
+
+func (opts FindScheduleOptions) ToConds() builder.Cond {
+ cond := builder.NewCond()
+ if opts.RepoID > 0 {
+ cond = cond.And(builder.Eq{"repo_id": opts.RepoID})
+ }
+ if opts.OwnerID > 0 {
+ cond = cond.And(builder.Eq{"owner_id": opts.OwnerID})
+ }
+
+ return cond
+}
+
+func (opts FindScheduleOptions) ToOrders() string {
+ return "`id` DESC"
+}
diff --git a/models/actions/schedule_list.go b/models/actions/schedule_list.go
deleted file mode 100644
index 5361b94801..0000000000
--- a/models/actions/schedule_list.go
+++ /dev/null
@@ -1,83 +0,0 @@
-// Copyright 2023 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-package actions
-
-import (
- "context"
-
- "code.gitea.io/gitea/models/db"
- repo_model "code.gitea.io/gitea/models/repo"
- user_model "code.gitea.io/gitea/models/user"
- "code.gitea.io/gitea/modules/container"
-
- "xorm.io/builder"
-)
-
-type ScheduleList []*ActionSchedule
-
-// GetUserIDs returns a slice of user's id
-func (schedules ScheduleList) GetUserIDs() []int64 {
- return container.FilterSlice(schedules, func(schedule *ActionSchedule) (int64, bool) {
- return schedule.TriggerUserID, true
- })
-}
-
-func (schedules ScheduleList) GetRepoIDs() []int64 {
- return container.FilterSlice(schedules, func(schedule *ActionSchedule) (int64, bool) {
- return schedule.RepoID, true
- })
-}
-
-func (schedules ScheduleList) LoadTriggerUser(ctx context.Context) error {
- userIDs := schedules.GetUserIDs()
- users := make(map[int64]*user_model.User, len(userIDs))
- if err := db.GetEngine(ctx).In("id", userIDs).Find(&users); err != nil {
- return err
- }
- for _, schedule := range schedules {
- if schedule.TriggerUserID == user_model.ActionsUserID {
- schedule.TriggerUser = user_model.NewActionsUser()
- } else {
- schedule.TriggerUser = users[schedule.TriggerUserID]
- if schedule.TriggerUser == nil {
- schedule.TriggerUser = user_model.NewGhostUser()
- }
- }
- }
- return nil
-}
-
-func (schedules ScheduleList) LoadRepos(ctx context.Context) error {
- repoIDs := schedules.GetRepoIDs()
- repos, err := repo_model.GetRepositoriesMapByIDs(ctx, repoIDs)
- if err != nil {
- return err
- }
- for _, schedule := range schedules {
- schedule.Repo = repos[schedule.RepoID]
- }
- return nil
-}
-
-type FindScheduleOptions struct {
- db.ListOptions
- RepoID int64
- OwnerID int64
-}
-
-func (opts FindScheduleOptions) ToConds() builder.Cond {
- cond := builder.NewCond()
- if opts.RepoID > 0 {
- cond = cond.And(builder.Eq{"repo_id": opts.RepoID})
- }
- if opts.OwnerID > 0 {
- cond = cond.And(builder.Eq{"owner_id": opts.OwnerID})
- }
-
- return cond
-}
-
-func (opts FindScheduleOptions) ToOrders() string {
- return "`id` DESC"
-}
diff --git a/models/auth/source.go b/models/auth/source.go
index d03d4975dc..214eb3afa0 100644
--- a/models/auth/source.go
+++ b/models/auth/source.go
@@ -299,17 +299,6 @@ func GetSourceByID(ctx context.Context, id int64) (*Source, error) {
return source, nil
}
-func GetSourceByName(ctx context.Context, name string) (*Source, error) {
- source := &Source{}
- has, err := db.GetEngine(ctx).Where("name = ?", name).Get(source)
- if err != nil {
- return nil, err
- } else if !has {
- return nil, ErrSourceNotExist{}
- }
- return source, nil
-}
-
// UpdateSource updates a Source record in DB.
func UpdateSource(ctx context.Context, source *Source) error {
var originalSource *Source
diff --git a/models/error.go b/models/error.go
index 75c53245de..658bdc165c 100644
--- a/models/error.go
+++ b/models/error.go
@@ -151,25 +151,6 @@ func (err *ErrInvalidCloneAddr) Unwrap() error {
return util.ErrInvalidArgument
}
-// ErrUpdateTaskNotExist represents a "UpdateTaskNotExist" kind of error.
-type ErrUpdateTaskNotExist struct {
- UUID string
-}
-
-// IsErrUpdateTaskNotExist checks if an error is a ErrUpdateTaskNotExist.
-func IsErrUpdateTaskNotExist(err error) bool {
- _, ok := err.(ErrUpdateTaskNotExist)
- return ok
-}
-
-func (err ErrUpdateTaskNotExist) Error() string {
- return fmt.Sprintf("update task does not exist [uuid: %s]", err.UUID)
-}
-
-func (err ErrUpdateTaskNotExist) Unwrap() error {
- return util.ErrNotExist
-}
-
// ErrInvalidTagName represents a "InvalidTagName" kind of error.
type ErrInvalidTagName struct {
TagName string
diff --git a/models/organization/team.go b/models/organization/team.go
index ddff32cb8c..5065a1a1d5 100644
--- a/models/organization/team.go
+++ b/models/organization/team.go
@@ -247,22 +247,6 @@ func GetTeamByID(ctx context.Context, teamID int64) (*Team, error) {
return t, nil
}
-// GetTeamNamesByID returns team's lower name from a list of team ids.
-func GetTeamNamesByID(ctx context.Context, teamIDs []int64) ([]string, error) {
- if len(teamIDs) == 0 {
- return []string{}, nil
- }
-
- var teamNames []string
- err := db.GetEngine(ctx).Table("team").
- Select("lower_name").
- In("id", teamIDs).
- Asc("name").
- Find(&teamNames)
-
- return teamNames, err
-}
-
// IncrTeamRepoNum increases the number of repos for the given team by 1
func IncrTeamRepoNum(ctx context.Context, teamID int64) error {
_, err := db.GetEngine(ctx).Incr("num_repos").ID(teamID).Update(new(Team))
diff --git a/models/organization/team_test.go b/models/organization/team_test.go
index 601d136d87..64cc68b064 100644
--- a/models/organization/team_test.go
+++ b/models/organization/team_test.go
@@ -188,20 +188,6 @@ func TestHasTeamRepo(t *testing.T) {
test(2, 5, false)
}
-func TestUsersInTeamsCount(t *testing.T) {
- require.NoError(t, unittest.PrepareTestDatabase())
-
- test := func(teamIDs, userIDs []int64, expected int64) {
- count, err := organization.UsersInTeamsCount(db.DefaultContext, teamIDs, userIDs)
- require.NoError(t, err)
- assert.Equal(t, expected, count)
- }
-
- test([]int64{2}, []int64{1, 2, 3, 4}, 1) // only userid 2
- test([]int64{1, 2, 3, 4, 5}, []int64{2, 5}, 2) // userid 2,4
- test([]int64{1, 2, 3, 4, 5}, []int64{2, 3, 5}, 3) // userid 2,4,5
-}
-
func TestInconsistentOwnerTeam(t *testing.T) {
defer unittest.OverrideFixtures(
unittest.FixturesOptions{
diff --git a/models/organization/team_unit.go b/models/organization/team_unit.go
index 3087b70770..b5237c2c58 100644
--- a/models/organization/team_unit.go
+++ b/models/organization/team_unit.go
@@ -28,24 +28,3 @@ func (t *TeamUnit) Unit() unit.Unit {
func getUnitsByTeamID(ctx context.Context, teamID int64) (units []*TeamUnit, err error) {
return units, db.GetEngine(ctx).Where("team_id = ?", teamID).Find(&units)
}
-
-// UpdateTeamUnits updates a teams's units
-func UpdateTeamUnits(ctx context.Context, team *Team, units []TeamUnit) (err error) {
- ctx, committer, err := db.TxContext(ctx)
- if err != nil {
- return err
- }
- defer committer.Close()
-
- if _, err = db.GetEngine(ctx).Where("team_id = ?", team.ID).Delete(new(TeamUnit)); err != nil {
- return err
- }
-
- if len(units) > 0 {
- if err = db.Insert(ctx, units); err != nil {
- return err
- }
- }
-
- return committer.Commit()
-}
diff --git a/models/organization/team_user.go b/models/organization/team_user.go
index ab767db200..f7fa136498 100644
--- a/models/organization/team_user.go
+++ b/models/organization/team_user.go
@@ -76,14 +76,3 @@ func GetTeamMembers(ctx context.Context, opts *SearchMembersOptions) ([]*user_mo
func IsUserInTeams(ctx context.Context, userID int64, teamIDs []int64) (bool, error) {
return db.GetEngine(ctx).Where("uid=?", userID).In("team_id", teamIDs).Exist(new(TeamUser))
}
-
-// UsersInTeamsCount counts the number of users which are in userIDs and teamIDs
-func UsersInTeamsCount(ctx context.Context, userIDs, teamIDs []int64) (int64, error) {
- var ids []int64
- if err := db.GetEngine(ctx).In("uid", userIDs).In("team_id", teamIDs).
- Table("team_user").
- Cols("uid").GroupBy("uid").Find(&ids); err != nil {
- return 0, err
- }
- return int64(len(ids)), nil
-}
diff --git a/models/project/column.go b/models/project/column.go
index 222f448599..b30aab4699 100644
--- a/models/project/column.go
+++ b/models/project/column.go
@@ -305,20 +305,6 @@ func SetDefaultColumn(ctx context.Context, projectID, columnID int64) error {
})
}
-// UpdateColumnSorting update project column sorting
-func UpdateColumnSorting(ctx context.Context, cl ColumnList) error {
- return db.WithTx(ctx, func(ctx context.Context) error {
- for i := range cl {
- if _, err := db.GetEngine(ctx).ID(cl[i].ID).Cols(
- "sorting",
- ).Update(cl[i]); err != nil {
- return err
- }
- }
- return nil
- })
-}
-
func GetColumnsByIDs(ctx context.Context, projectID int64, columnsIDs []int64) (ColumnList, error) {
columns := make([]*Column, 0, 5)
if err := db.GetEngine(ctx).
diff --git a/models/project/project.go b/models/project/project.go
index beffffcdfc..6c2b02487d 100644
--- a/models/project/project.go
+++ b/models/project/project.go
@@ -368,21 +368,6 @@ func ChangeProjectStatusByRepoIDAndID(ctx context.Context, repoID, projectID int
return committer.Commit()
}
-// ChangeProjectStatus toggle a project between opened and closed
-func ChangeProjectStatus(ctx context.Context, p *Project, isClosed bool) error {
- ctx, committer, err := db.TxContext(ctx)
- if err != nil {
- return err
- }
- defer committer.Close()
-
- if err := changeProjectStatus(ctx, p, isClosed); err != nil {
- return err
- }
-
- return committer.Commit()
-}
-
func changeProjectStatus(ctx context.Context, p *Project, isClosed bool) error {
p.IsClosed = isClosed
p.ClosedDateUnix = timeutil.TimeStampNow()
diff --git a/models/project/project_test.go b/models/project/project_test.go
index 8c660b929a..cef2ea17bd 100644
--- a/models/project/project_test.go
+++ b/models/project/project_test.go
@@ -75,7 +75,7 @@ func TestProject(t *testing.T) {
assert.Equal(t, project.Title, projectFromDB.Title)
- require.NoError(t, ChangeProjectStatus(db.DefaultContext, project, true))
+ require.NoError(t, ChangeProjectStatusByRepoIDAndID(db.DefaultContext, project.RepoID, project.ID, true))
// Retrieve from DB afresh to check if it is truly closed
projectFromDB, err = GetProjectByID(db.DefaultContext, project.ID)
diff --git a/models/repo/attachment.go b/models/repo/attachment.go
index 128bcebb60..b95d785fa5 100644
--- a/models/repo/attachment.go
+++ b/models/repo/attachment.go
@@ -219,16 +219,6 @@ func DeleteAttachments(ctx context.Context, attachments []*Attachment, remove bo
return int(cnt), nil
}
-// DeleteAttachmentsByIssue deletes all attachments associated with the given issue.
-func DeleteAttachmentsByIssue(ctx context.Context, issueID int64, remove bool) (int, error) {
- attachments, err := GetAttachmentsByIssueID(ctx, issueID)
- if err != nil {
- return 0, err
- }
-
- return DeleteAttachments(ctx, attachments, remove)
-}
-
// DeleteAttachmentsByComment deletes all attachments associated with the given comment.
func DeleteAttachmentsByComment(ctx context.Context, commentID int64, remove bool) (int, error) {
attachments, err := GetAttachmentsByCommentID(ctx, commentID)
diff --git a/models/repo/attachment_test.go b/models/repo/attachment_test.go
index 23945ba1d3..881a40c3e7 100644
--- a/models/repo/attachment_test.go
+++ b/models/repo/attachment_test.go
@@ -46,11 +46,7 @@ func TestGetByCommentOrIssueID(t *testing.T) {
func TestDeleteAttachments(t *testing.T) {
require.NoError(t, unittest.PrepareTestDatabase())
- count, err := repo_model.DeleteAttachmentsByIssue(db.DefaultContext, 4, false)
- require.NoError(t, err)
- assert.Equal(t, 2, count)
-
- count, err = repo_model.DeleteAttachmentsByComment(db.DefaultContext, 2, false)
+ count, err := repo_model.DeleteAttachmentsByComment(db.DefaultContext, 2, false)
require.NoError(t, err)
assert.Equal(t, 2, count)
diff --git a/models/repo/repo_list.go b/models/repo/repo_list.go
index 693f8f12af..25329ae712 100644
--- a/models/repo/repo_list.go
+++ b/models/repo/repo_list.go
@@ -21,11 +21,6 @@ import (
"xorm.io/builder"
)
-// FindReposMapByIDs find repos as map
-func FindReposMapByIDs(ctx context.Context, repoIDs []int64, res map[int64]*Repository) error {
- return db.GetEngine(ctx).In("id", repoIDs).Find(&res)
-}
-
// RepositoryListDefaultPageSize is the default number of repositories
// to load in memory when running administrative tasks on all (or almost
// all) of them.
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{})
diff --git a/modules/charset/breakwriter.go b/modules/charset/breakwriter.go
deleted file mode 100644
index a87e846466..0000000000
--- a/modules/charset/breakwriter.go
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright 2022 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-package charset
-
-import (
- "bytes"
- "io"
-)
-
-// BreakWriter wraps an io.Writer to always write '\n' as '
'
-type BreakWriter struct {
- io.Writer
-}
-
-// Write writes the provided byte slice transparently replacing '\n' with '
'
-func (b *BreakWriter) Write(bs []byte) (n int, err error) {
- pos := 0
- for pos < len(bs) {
- idx := bytes.IndexByte(bs[pos:], '\n')
- if idx < 0 {
- wn, err := b.Writer.Write(bs[pos:])
- return n + wn, err
- }
-
- if idx > 0 {
- wn, err := b.Writer.Write(bs[pos : pos+idx])
- n += wn
- if err != nil {
- return n, err
- }
- }
-
- if _, err = b.Writer.Write([]byte("
")); err != nil {
- return n, err
- }
- pos += idx + 1
-
- n++
- }
-
- return n, err
-}
diff --git a/modules/charset/breakwriter_test.go b/modules/charset/breakwriter_test.go
deleted file mode 100644
index 5eeeedc4e2..0000000000
--- a/modules/charset/breakwriter_test.go
+++ /dev/null
@@ -1,68 +0,0 @@
-// Copyright 2022 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-package charset
-
-import (
- "strings"
- "testing"
-)
-
-func TestBreakWriter_Write(t *testing.T) {
- tests := []struct {
- name string
- kase string
- expect string
- wantErr bool
- }{
- {
- name: "noline",
- kase: "abcdefghijklmnopqrstuvwxyz",
- expect: "abcdefghijklmnopqrstuvwxyz",
- },
- {
- name: "endline",
- kase: "abcdefghijklmnopqrstuvwxyz\n",
- expect: "abcdefghijklmnopqrstuvwxyz
",
- },
- {
- name: "startline",
- kase: "\nabcdefghijklmnopqrstuvwxyz",
- expect: "
abcdefghijklmnopqrstuvwxyz",
- },
- {
- name: "onlyline",
- kase: "\n\n\n",
- expect: "
",
- },
- {
- name: "empty",
- kase: "",
- expect: "",
- },
- {
- name: "midline",
- kase: "\nabc\ndefghijkl\nmnopqrstuvwxy\nz",
- expect: "
abc
defghijkl
mnopqrstuvwxy
z",
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- buf := &strings.Builder{}
- b := &BreakWriter{
- Writer: buf,
- }
- n, err := b.Write([]byte(tt.kase))
- if (err != nil) != tt.wantErr {
- t.Errorf("BreakWriter.Write() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- if n != len(tt.kase) {
- t.Errorf("BreakWriter.Write() = %v, want %v", n, len(tt.kase))
- }
- if buf.String() != tt.expect {
- t.Errorf("BreakWriter.Write() wrote %q, want %v", buf.String(), tt.expect)
- }
- })
- }
-}
diff --git a/modules/git/repo_tag.go b/modules/git/repo_tag.go
index 3b48b1fb9b..4466d8e5c0 100644
--- a/modules/git/repo_tag.go
+++ b/modules/git/repo_tag.go
@@ -5,7 +5,6 @@
package git
import (
- "context"
"errors"
"fmt"
"io"
@@ -20,11 +19,6 @@ import (
// TagPrefix tags prefix path on the repository
const TagPrefix = "refs/tags/"
-// IsTagExist returns true if given tag exists in the repository.
-func IsTagExist(ctx context.Context, repoPath, name string) bool {
- return IsReferenceExist(ctx, repoPath, TagPrefix+name)
-}
-
// CreateTag create one tag in the repository
func (repo *Repository) CreateTag(name, revision string) error {
_, _, err := NewCommand(repo.Ctx, "tag").AddDashesAndList(name, revision).RunStdString(&RunOpts{Dir: repo.Path})
diff --git a/modules/git/utils.go b/modules/git/utils.go
index 53211c6451..b84df47916 100644
--- a/modules/git/utils.go
+++ b/modules/git/utils.go
@@ -7,7 +7,6 @@ import (
"crypto/sha1"
"encoding/hex"
"fmt"
- "io"
"os"
"strconv"
"strings"
@@ -105,32 +104,6 @@ func ParseBool(value string) (result, valid bool) {
return intValue != 0, true
}
-// LimitedReaderCloser is a limited reader closer
-type LimitedReaderCloser struct {
- R io.Reader
- C io.Closer
- N int64
-}
-
-// Read implements io.Reader
-func (l *LimitedReaderCloser) Read(p []byte) (n int, err error) {
- if l.N <= 0 {
- _ = l.C.Close()
- return 0, io.EOF
- }
- if int64(len(p)) > l.N {
- p = p[0:l.N]
- }
- n, err = l.R.Read(p)
- l.N -= int64(n)
- return n, err
-}
-
-// Close implements io.Closer
-func (l *LimitedReaderCloser) Close() error {
- return l.C.Close()
-}
-
func HashFilePathForWebUI(s string) string {
h := sha1.New()
_, _ = h.Write([]byte(s))
diff --git a/modules/markup/markdown/ast.go b/modules/markup/markdown/ast.go
index 7f0ac6a92c..c2fbbe6692 100644
--- a/modules/markup/markdown/ast.go
+++ b/modules/markup/markdown/ast.go
@@ -34,13 +34,6 @@ func NewDetails() *Details {
}
}
-// IsDetails returns true if the given node implements the Details interface,
-// otherwise false.
-func IsDetails(node ast.Node) bool {
- _, ok := node.(*Details)
- return ok
-}
-
// Summary is a block that contains the summary of details block
type Summary struct {
ast.BaseBlock
@@ -66,13 +59,6 @@ func NewSummary() *Summary {
}
}
-// IsSummary returns true if the given node implements the Summary interface,
-// otherwise false.
-func IsSummary(node ast.Node) bool {
- _, ok := node.(*Summary)
- return ok
-}
-
// TaskCheckBoxListItem is a block that represents a list item of a markdown block with a checkbox
type TaskCheckBoxListItem struct {
*ast.ListItem
@@ -103,13 +89,6 @@ func NewTaskCheckBoxListItem(listItem *ast.ListItem) *TaskCheckBoxListItem {
}
}
-// IsTaskCheckBoxListItem returns true if the given node implements the TaskCheckBoxListItem interface,
-// otherwise false.
-func IsTaskCheckBoxListItem(node ast.Node) bool {
- _, ok := node.(*TaskCheckBoxListItem)
- return ok
-}
-
// Icon is an inline for a fomantic icon
type Icon struct {
ast.BaseInline
@@ -139,13 +118,6 @@ func NewIcon(name string) *Icon {
}
}
-// IsIcon returns true if the given node implements the Icon interface,
-// otherwise false.
-func IsIcon(node ast.Node) bool {
- _, ok := node.(*Icon)
- return ok
-}
-
// ColorPreview is an inline for a color preview
type ColorPreview struct {
ast.BaseInline
diff --git a/modules/markup/markdown/math/math.go b/modules/markup/markdown/math/math.go
index 3d9f376bc6..4126dc9ad6 100644
--- a/modules/markup/markdown/math/math.go
+++ b/modules/markup/markdown/math/math.go
@@ -39,28 +39,6 @@ func Enabled(enable ...bool) Option {
})
}
-// WithInlineDollarParser enables or disables the parsing of $...$
-func WithInlineDollarParser(enable ...bool) Option {
- value := true
- if len(enable) > 0 {
- value = enable[0]
- }
- return extensionFunc(func(e *Extension) {
- e.parseDollarInline = value
- })
-}
-
-// WithBlockDollarParser enables or disables the parsing of $$...$$
-func WithBlockDollarParser(enable ...bool) Option {
- value := true
- if len(enable) > 0 {
- value = enable[0]
- }
- return extensionFunc(func(e *Extension) {
- e.parseDollarBlock = value
- })
-}
-
// Math represents a math extension with default rendered delimiters
var Math = &Extension{
enabled: true,
diff --git a/modules/private/forgejo_actions.go b/modules/private/forgejo_actions.go
deleted file mode 100644
index 133d5e253f..0000000000
--- a/modules/private/forgejo_actions.go
+++ /dev/null
@@ -1,32 +0,0 @@
-// SPDX-License-Identifier: MIT
-
-package private
-
-import (
- "context"
-
- "code.gitea.io/gitea/modules/setting"
-)
-
-type ActionsRunnerRegisterRequest struct {
- Token string
- Scope string
- Labels []string
- Name string
- Version string
-}
-
-func ActionsRunnerRegister(ctx context.Context, token, scope string, labels []string, name, version string) (string, ResponseExtra) {
- reqURL := setting.LocalURL + "api/internal/actions/register"
-
- req := newInternalRequest(ctx, reqURL, "POST", ActionsRunnerRegisterRequest{
- Token: token,
- Scope: scope,
- Labels: labels,
- Name: name,
- Version: version,
- })
-
- resp, extra := requestJSONResp(req, &ResponseText{})
- return resp.Text, extra
-}
diff --git a/modules/repository/collaborator_test.go b/modules/repository/collaborator_test.go
index 3844197bf1..63352e33e8 100644
--- a/modules/repository/collaborator_test.go
+++ b/modules/repository/collaborator_test.go
@@ -272,8 +272,7 @@ func TestRepoPermissionPrivateOrgRepo(t *testing.T) {
// update team information and then check permission
team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: 5})
- err = organization.UpdateTeamUnits(db.DefaultContext, team, nil)
- require.NoError(t, err)
+ unittest.AssertSuccessfulDelete(t, &organization.TeamUnit{TeamID: team.ID})
perm, err = access_model.GetUserRepoPermission(db.DefaultContext, repo, owner)
require.NoError(t, err)
for _, unit := range repo.Units {
diff --git a/modules/storage/storage.go b/modules/storage/storage.go
index d944b8618f..453d755fbb 100644
--- a/modules/storage/storage.go
+++ b/modules/storage/storage.go
@@ -18,25 +18,6 @@ import (
// ErrURLNotSupported represents url is not supported
var ErrURLNotSupported = errors.New("url method not supported")
-// ErrInvalidConfiguration is called when there is invalid configuration for a storage
-type ErrInvalidConfiguration struct {
- cfg any
- err error
-}
-
-func (err ErrInvalidConfiguration) Error() string {
- if err.err != nil {
- return fmt.Sprintf("Invalid Configuration Argument: %v: Error: %v", err.cfg, err.err)
- }
- return fmt.Sprintf("Invalid Configuration Argument: %v", err.cfg)
-}
-
-// IsErrInvalidConfiguration checks if an error is an ErrInvalidConfiguration
-func IsErrInvalidConfiguration(err error) bool {
- _, ok := err.(ErrInvalidConfiguration)
- return ok
-}
-
type Type = setting.StorageType
// NewStorageFunc is a function that creates a storage
diff --git a/modules/structs/hook.go b/modules/structs/hook.go
index a41e172253..10b3a9db9b 100644
--- a/modules/structs/hook.go
+++ b/modules/structs/hook.go
@@ -141,26 +141,6 @@ func (p *CreatePayload) JSONPayload() ([]byte, error) {
return json.MarshalIndent(p, "", " ")
}
-// ParseCreateHook parses create event hook content.
-func ParseCreateHook(raw []byte) (*CreatePayload, error) {
- hook := new(CreatePayload)
- if err := json.Unmarshal(raw, hook); err != nil {
- return nil, err
- }
-
- // it is possible the JSON was parsed, however,
- // was not from Gogs (maybe was from Bitbucket)
- // So we'll check to be sure certain key fields
- // were populated
- switch {
- case hook.Repo == nil:
- return nil, ErrInvalidReceiveHook
- case len(hook.Ref) == 0:
- return nil, ErrInvalidReceiveHook
- }
- return hook, nil
-}
-
// ________ .__ __
// \______ \ ____ | | _____/ |_ ____
// | | \_/ __ \| | _/ __ \ __\/ __ \
@@ -292,22 +272,6 @@ func (p *PushPayload) JSONPayload() ([]byte, error) {
return json.MarshalIndent(p, "", " ")
}
-// ParsePushHook parses push event hook content.
-func ParsePushHook(raw []byte) (*PushPayload, error) {
- hook := new(PushPayload)
- if err := json.Unmarshal(raw, hook); err != nil {
- return nil, err
- }
-
- switch {
- case hook.Repo == nil:
- return nil, ErrInvalidReceiveHook
- case len(hook.Ref) == 0:
- return nil, ErrInvalidReceiveHook
- }
- return hook, nil
-}
-
// Branch returns branch name from a payload
func (p *PushPayload) Branch() string {
return strings.ReplaceAll(p.Ref, "refs/heads/", "")
diff --git a/modules/web/middleware/locale.go b/modules/web/middleware/locale.go
index 1f37407201..9653a6f349 100644
--- a/modules/web/middleware/locale.go
+++ b/modules/web/middleware/locale.go
@@ -53,9 +53,3 @@ func Locale(resp http.ResponseWriter, req *http.Request) translation.Locale {
func SetLocaleCookie(resp http.ResponseWriter, lang string, maxAge int) {
SetSiteCookie(resp, "lang", lang, maxAge)
}
-
-// DeleteLocaleCookie convenience function to delete the locale cookie consistently
-// Setting the lang cookie will trigger the middleware to reset the language to previous state.
-func DeleteLocaleCookie(resp http.ResponseWriter) {
- SetSiteCookie(resp, "lang", "", -1)
-}
diff --git a/services/convert/secret.go b/services/convert/secret.go
deleted file mode 100644
index dd7b9f0a6a..0000000000
--- a/services/convert/secret.go
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright 2023 The Gitea Authors. All rights reserved.
-// SPDX-License-Identifier: MIT
-
-package convert
-
-import (
- secret_model "code.gitea.io/gitea/models/secret"
- api "code.gitea.io/gitea/modules/structs"
-)
-
-// ToSecret converts Secret to API format
-func ToSecret(secret *secret_model.Secret) *api.Secret {
- result := &api.Secret{
- Name: secret.Name,
- }
-
- return result
-}
diff --git a/services/forms/repo_form.go b/services/forms/repo_form.go
index 1ce9b298ad..8253a8957b 100644
--- a/services/forms/repo_form.go
+++ b/services/forms/repo_form.go
@@ -740,17 +740,6 @@ type SaveTopicForm struct {
Topics []string `binding:"topics;Required;"`
}
-// DeadlineForm hold the validation rules for deadlines
-type DeadlineForm struct {
- DateString string `form:"date" binding:"Required;Size(10)"`
-}
-
-// Validate validates the fields
-func (f *DeadlineForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetValidateContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
type CommitNotesForm struct {
Notes string
}
diff --git a/services/pull/commit_status.go b/services/pull/commit_status.go
index 0d4763a838..2c77d9cf4e 100644
--- a/services/pull/commit_status.go
+++ b/services/pull/commit_status.go
@@ -71,36 +71,6 @@ func MergeRequiredContextsCommitStatus(commitStatuses []*git_model.CommitStatus,
return returnedStatus
}
-// IsCommitStatusContextSuccess returns true if all required status check contexts succeed.
-func IsCommitStatusContextSuccess(commitStatuses []*git_model.CommitStatus, requiredContexts []string) bool {
- // If no specific context is required, require that last commit status is a success
- if len(requiredContexts) == 0 {
- status := git_model.CalcCommitStatus(commitStatuses)
- if status == nil || status.State != structs.CommitStatusSuccess {
- return false
- }
- return true
- }
-
- for _, ctx := range requiredContexts {
- var found bool
- for _, commitStatus := range commitStatuses {
- if commitStatus.Context == ctx {
- if commitStatus.State != structs.CommitStatusSuccess {
- return false
- }
-
- found = true
- break
- }
- }
- if !found {
- return false
- }
- }
- return true
-}
-
// IsPullCommitStatusPass returns if all required status checks PASS
func IsPullCommitStatusPass(ctx context.Context, pr *issues_model.PullRequest) (bool, error) {
pb, err := git_model.GetFirstMatchProtectedBranchRule(ctx, pr.BaseRepoID, pr.BaseBranch)
diff --git a/services/repository/files/file.go b/services/repository/files/file.go
index 852cca0371..7884d880e0 100644
--- a/services/repository/files/file.go
+++ b/services/repository/files/file.go
@@ -33,19 +33,6 @@ func GetFilesResponseFromCommit(ctx context.Context, repo *repo_model.Repository
return filesResponse, nil
}
-// GetFileResponseFromCommit Constructs a FileResponse from a Commit object
-func GetFileResponseFromCommit(ctx context.Context, repo *repo_model.Repository, commit *git.Commit, branch, treeName string) (*api.FileResponse, error) {
- fileContents, _ := GetContents(ctx, repo, treeName, branch, false) // ok if fails, then will be nil
- fileCommitResponse, _ := GetFileCommitResponse(repo, commit) // ok if fails, then will be nil
- verification := GetPayloadCommitVerification(ctx, commit)
- fileResponse := &api.FileResponse{
- Content: fileContents,
- Commit: fileCommitResponse,
- Verification: verification,
- }
- return fileResponse, nil
-}
-
// constructs a FileResponse with the file at the index from FilesResponse
func GetFileResponseFromFilesResponse(filesResponse *api.FilesResponse, index int) *api.FileResponse {
content := &api.ContentsResponse{}
diff --git a/services/repository/files/file_test.go b/services/repository/files/file_test.go
index 7c387e2dd5..db2f4403f4 100644
--- a/services/repository/files/file_test.go
+++ b/services/repository/files/file_test.go
@@ -6,15 +6,7 @@ package files
import (
"testing"
- "code.gitea.io/gitea/models/db"
- repo_model "code.gitea.io/gitea/models/repo"
- "code.gitea.io/gitea/models/unittest"
- "code.gitea.io/gitea/modules/gitrepo"
- "code.gitea.io/gitea/modules/setting"
- api "code.gitea.io/gitea/modules/structs"
-
"github.com/stretchr/testify/assert"
- "github.com/stretchr/testify/require"
)
func TestCleanUploadFileName(t *testing.T) {
@@ -32,84 +24,3 @@ func TestCleanUploadFileName(t *testing.T) {
assert.EqualValues(t, expectedCleanName, cleanName)
})
}
-
-func getExpectedFileResponse() *api.FileResponse {
- treePath := "README.md"
- sha := "4b4851ad51df6a7d9f25c979345979eaeb5b349f"
- encoding := "base64"
- content := "IyByZXBvMQoKRGVzY3JpcHRpb24gZm9yIHJlcG8x"
- selfURL := setting.AppURL + "api/v1/repos/user2/repo1/contents/" + treePath + "?ref=master"
- htmlURL := setting.AppURL + "user2/repo1/src/branch/master/" + treePath
- gitURL := setting.AppURL + "api/v1/repos/user2/repo1/git/blobs/" + sha
- downloadURL := setting.AppURL + "user2/repo1/raw/branch/master/" + treePath
- return &api.FileResponse{
- Content: &api.ContentsResponse{
- Name: treePath,
- Path: treePath,
- SHA: sha,
- LastCommitSHA: "65f1bf27bc3bf70f64657658635e66094edbcb4d",
- Type: "file",
- Size: 30,
- Encoding: &encoding,
- Content: &content,
- URL: &selfURL,
- HTMLURL: &htmlURL,
- GitURL: &gitURL,
- DownloadURL: &downloadURL,
- Links: &api.FileLinksResponse{
- Self: &selfURL,
- GitURL: &gitURL,
- HTMLURL: &htmlURL,
- },
- },
- Commit: &api.FileCommitResponse{
- CommitMeta: api.CommitMeta{
- URL: "https://try.gitea.io/api/v1/repos/user2/repo1/git/commits/65f1bf27bc3bf70f64657658635e66094edbcb4d",
- SHA: "65f1bf27bc3bf70f64657658635e66094edbcb4d",
- },
- HTMLURL: "https://try.gitea.io/user2/repo1/commit/65f1bf27bc3bf70f64657658635e66094edbcb4d",
- Author: &api.CommitUser{
- Identity: api.Identity{
- Name: "user1",
- Email: "address1@example.com",
- },
- Date: "2017-03-19T20:47:59Z",
- },
- Committer: &api.CommitUser{
- Identity: api.Identity{
- Name: "Ethan Koenig",
- Email: "ethantkoenig@gmail.com",
- },
- Date: "2017-03-19T20:47:59Z",
- },
- Parents: []*api.CommitMeta{},
- Message: "Initial commit\n",
- Tree: &api.CommitMeta{
- URL: "https://try.gitea.io/api/v1/repos/user2/repo1/git/trees/2a2f1d4670728a2e10049e345bd7a276468beab6",
- SHA: "2a2f1d4670728a2e10049e345bd7a276468beab6",
- },
- },
- Verification: &api.PayloadCommitVerification{
- Verified: false,
- Reason: "gpg.error.not_signed_commit",
- Signature: "",
- Payload: "",
- },
- }
-}
-
-func TestGetFileResponseFromCommit(t *testing.T) {
- unittest.PrepareTestEnv(t)
-
- repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
- branch := repo.DefaultBranch
- treePath := "README.md"
- gitRepo, _ := gitrepo.OpenRepository(db.DefaultContext, repo)
- defer gitRepo.Close()
- commit, _ := gitRepo.GetBranchCommit(branch)
- expectedFileResponse := getExpectedFileResponse()
-
- fileResponse, err := GetFileResponseFromCommit(db.DefaultContext, repo, commit, branch, treePath)
- require.NoError(t, err)
- assert.EqualValues(t, expectedFileResponse, fileResponse)
-}
diff --git a/services/repository/files/temp_repo.go b/services/repository/files/temp_repo.go
index 6e7570b82c..30d95ba9ab 100644
--- a/services/repository/files/temp_repo.go
+++ b/services/repository/files/temp_repo.go
@@ -212,24 +212,6 @@ func (t *TemporaryUploadRepository) WriteTree() (string, error) {
return strings.TrimSpace(stdout), nil
}
-// GetLastCommit gets the last commit ID SHA of the repo
-func (t *TemporaryUploadRepository) GetLastCommit() (string, error) {
- return t.GetLastCommitByRef("HEAD")
-}
-
-// GetLastCommitByRef gets the last commit ID SHA of the repo by ref
-func (t *TemporaryUploadRepository) GetLastCommitByRef(ref string) (string, error) {
- if ref == "" {
- ref = "HEAD"
- }
- stdout, _, err := git.NewCommand(t.ctx, "rev-parse").AddDynamicArguments(ref).RunStdString(&git.RunOpts{Dir: t.basePath})
- if err != nil {
- log.Error("Unable to get last ref for %s in temporary repo: %s(%s): Error: %v", ref, t.repo.FullName(), t.basePath, err)
- return "", fmt.Errorf("Unable to rev-parse %s in temporary repo for: %s Error: %w", ref, t.repo.FullName(), err)
- }
- return strings.TrimSpace(stdout), nil
-}
-
// CommitTree creates a commit from a given tree for the user with provided message
func (t *TemporaryUploadRepository) CommitTree(parent string, author, committer *user_model.User, treeHash, message string, signoff bool) (string, error) {
return t.CommitTreeWithDate(parent, author, committer, treeHash, message, signoff, time.Now(), time.Now())
diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go
index 06d2586d1c..7866d297e2 100644
--- a/tests/integration/integration_test.go
+++ b/tests/integration/integration_test.go
@@ -298,9 +298,7 @@ func addAuthSource(t *testing.T, payload map[string]string) *auth.Source {
payload["_csrf"] = GetCSRF(t, session, "/admin/auths/new")
req := NewRequestWithValues(t, "POST", "/admin/auths/new", payload)
session.MakeRequest(t, req, http.StatusSeeOther)
- source, err := auth.GetSourceByName(context.Background(), payload["name"])
- require.NoError(t, err)
- return source
+ return unittest.AssertExistsAndLoadBean(t, &auth.Source{Name: payload["name"]})
}
func authSourcePayloadOAuth2(name string) map[string]string {
@@ -358,9 +356,7 @@ func createRemoteAuthSource(t *testing.T, name, url, matchingSource string) *aut
MatchingSource: matchingSource,
},
}))
- source, err := auth.GetSourceByName(context.Background(), name)
- require.NoError(t, err)
- return source
+ return unittest.AssertExistsAndLoadBean(t, &auth.Source{Name: name})
}
func createUser(ctx context.Context, t testing.TB, user *user_model.User) func() {