mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-18 23:34:52 +02:00
chore: update golangci-lint to v2.13.0
Migrate the deprecated gofumpt `extra-rules` to `extra.group-params`, as the alias now also enables the new `clothe-returns` and `balance-calls` rules. Disable SA4023, which hangs on go 1.27, see https://github.com/golangci/golangci-lint/issues/6732. Apply the resulting modernize fixes, mostly flattening embedded struct literals and switching errors.As to errors.AsType. Assisted-by: Claude:Opus 5
This commit is contained in:
@@ -52,15 +52,13 @@ func CreateAuthorizationToken(taskID, runID, jobID int64) (string, error) {
|
||||
}
|
||||
|
||||
claims := actionsClaims{
|
||||
RegisteredClaims: jwt.RegisteredClaims{
|
||||
ExpiresAt: jwt.NewNumericDate(now.Add(1*time.Hour + setting.Actions.EndlessTaskTimeout)),
|
||||
NotBefore: jwt.NewNumericDate(now),
|
||||
},
|
||||
Scp: fmt.Sprintf("Actions.Results:%d:%d", runID, jobID),
|
||||
Ac: string(ac),
|
||||
TaskID: taskID,
|
||||
RunID: runID,
|
||||
JobID: jobID,
|
||||
ExpiresAt: jwt.NewNumericDate(now.Add(1*time.Hour + setting.Actions.EndlessTaskTimeout)),
|
||||
NotBefore: jwt.NewNumericDate(now),
|
||||
Scp: fmt.Sprintf("Actions.Results:%d:%d", runID, jobID),
|
||||
Ac: string(ac),
|
||||
TaskID: taskID,
|
||||
RunID: runID,
|
||||
JobID: jobID,
|
||||
}
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"time"
|
||||
|
||||
actions_model "gitea.dev/models/actions"
|
||||
"gitea.dev/models/db"
|
||||
"gitea.dev/models/organization"
|
||||
perm_model "gitea.dev/models/perm"
|
||||
access_model "gitea.dev/models/perm/access"
|
||||
@@ -41,11 +40,9 @@ func startTasks(ctx context.Context) error {
|
||||
for page := 1; ; page++ {
|
||||
// Retrieve the specs for the current page
|
||||
specs, _, err := actions_model.FindSpecs(ctx, actions_model.FindSpecOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
Page: page,
|
||||
PageSize: pageSize,
|
||||
},
|
||||
Next: now.Unix(),
|
||||
Page: page,
|
||||
PageSize: pageSize,
|
||||
Next: now.Unix(),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("find specs: %w", err)
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"uuid"
|
||||
|
||||
"gitea.dev/models/db"
|
||||
repo_model "gitea.dev/models/repo"
|
||||
@@ -17,8 +18,6 @@ import (
|
||||
"gitea.dev/modules/storage"
|
||||
"gitea.dev/modules/util"
|
||||
"gitea.dev/services/context/upload"
|
||||
|
||||
"uuid"
|
||||
)
|
||||
|
||||
// NewAttachment creates a new attachment object, but do not verify.
|
||||
@@ -85,8 +84,7 @@ func uploadAttachment(ctx context.Context, file *UploaderFile, allowedTypes stri
|
||||
}
|
||||
|
||||
attach, err := NewAttachment(ctx, attach, io.MultiReader(bytes.NewReader(buf), src), file.size)
|
||||
var maxBytesError *http.MaxBytesError
|
||||
if errors.As(err, &maxBytesError) {
|
||||
if _, ok := errors.AsType[*http.MaxBytesError](err); ok {
|
||||
return nil, util.ErrorWrap(util.ErrContentTooLarge, "attachment exceeds limit %d", maxFileSize)
|
||||
}
|
||||
return attach, err
|
||||
|
||||
@@ -25,8 +25,7 @@ func (e ErrUserAuthMessage) Error() string {
|
||||
}
|
||||
|
||||
func ErrAsUserAuthMessage(err error) (string, bool) {
|
||||
var msg ErrUserAuthMessage
|
||||
if errors.As(err, &msg) {
|
||||
if msg, ok := errors.AsType[ErrUserAuthMessage](err); ok {
|
||||
return msg.Error(), true
|
||||
}
|
||||
return "", false
|
||||
|
||||
@@ -7,14 +7,13 @@ package auth
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"uuid"
|
||||
|
||||
user_model "gitea.dev/models/user"
|
||||
"gitea.dev/modules/log"
|
||||
"gitea.dev/modules/optional"
|
||||
"gitea.dev/modules/session"
|
||||
"gitea.dev/modules/setting"
|
||||
|
||||
"uuid"
|
||||
)
|
||||
|
||||
// Ensure the struct implements the interface.
|
||||
|
||||
@@ -17,4 +17,4 @@ type sourceInterface interface {
|
||||
auth_model.Config
|
||||
}
|
||||
|
||||
var _ (sourceInterface) = &db.Source{}
|
||||
var _ sourceInterface = &db.Source{}
|
||||
|
||||
@@ -22,4 +22,4 @@ type sourceInterface interface {
|
||||
auth_model.UseTLSer
|
||||
}
|
||||
|
||||
var _ (sourceInterface) = &ldap.Source{}
|
||||
var _ sourceInterface = &ldap.Source{}
|
||||
|
||||
@@ -18,4 +18,4 @@ type sourceInterface interface {
|
||||
auth.PasswordAuthenticator
|
||||
}
|
||||
|
||||
var _ (sourceInterface) = &oauth2.Source{}
|
||||
var _ sourceInterface = &oauth2.Source{}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"encoding/gob"
|
||||
"net/http"
|
||||
"sync"
|
||||
"uuid"
|
||||
|
||||
"gitea.dev/models/auth"
|
||||
"gitea.dev/models/db"
|
||||
@@ -17,7 +18,6 @@ import (
|
||||
|
||||
"github.com/gorilla/sessions"
|
||||
"github.com/markbates/goth/gothic"
|
||||
"uuid"
|
||||
)
|
||||
|
||||
var gothRWMutex = sync.RWMutex{}
|
||||
|
||||
@@ -40,10 +40,8 @@ func (c *CustomProvider) CreateGothProvider(providerName, callbackURL string, so
|
||||
// NewCustomProvider is a constructor function for custom providers
|
||||
func NewCustomProvider(name, displayName string, customURLSetting *CustomURLSettings, newFn CustomProviderNewFn) *CustomProvider {
|
||||
return &CustomProvider{
|
||||
BaseProvider: BaseProvider{
|
||||
name: name,
|
||||
displayName: displayName,
|
||||
},
|
||||
name: name,
|
||||
displayName: displayName,
|
||||
customURLSettings: customURLSetting,
|
||||
newFn: newFn,
|
||||
}
|
||||
|
||||
@@ -39,12 +39,10 @@ func (c *SimpleProvider) CreateGothProvider(providerName, callbackURL string, so
|
||||
// NewSimpleProvider is a constructor function for simple providers
|
||||
func NewSimpleProvider(name, displayName string, scopes []string, newFn SimpleProviderNewFn) *SimpleProvider {
|
||||
return &SimpleProvider{
|
||||
BaseProvider: BaseProvider{
|
||||
name: name,
|
||||
displayName: displayName,
|
||||
},
|
||||
scopes: scopes,
|
||||
newFn: newFn,
|
||||
name: name,
|
||||
displayName: displayName,
|
||||
scopes: scopes,
|
||||
newFn: newFn,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,14 +18,12 @@ func TestSource(t *testing.T) {
|
||||
|
||||
source := &Source{
|
||||
Provider: "fake",
|
||||
ConfigBase: auth.ConfigBase{
|
||||
AuthSource: &auth.Source{
|
||||
ID: 12,
|
||||
Type: auth.OAuth2,
|
||||
Name: "fake",
|
||||
IsActive: true,
|
||||
IsSyncEnabled: true,
|
||||
},
|
||||
AuthSource: &auth.Source{
|
||||
ID: 12,
|
||||
Type: auth.OAuth2,
|
||||
Name: "fake",
|
||||
IsActive: true,
|
||||
IsSyncEnabled: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -94,4 +94,4 @@ func (s *sizeWriter) Write(data []byte) (int, error) {
|
||||
return len(data), nil
|
||||
}
|
||||
|
||||
var _ (sessions.Store) = &SessionsStore{}
|
||||
var _ sessions.Store = &SessionsStore{}
|
||||
|
||||
@@ -17,4 +17,4 @@ type sourceInterface interface {
|
||||
auth_model.Config
|
||||
}
|
||||
|
||||
var _ (sourceInterface) = &pam.Source{}
|
||||
var _ sourceInterface = &pam.Source{}
|
||||
|
||||
@@ -7,14 +7,13 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"uuid"
|
||||
|
||||
"gitea.dev/models/auth"
|
||||
user_model "gitea.dev/models/user"
|
||||
"gitea.dev/modules/auth/pam"
|
||||
"gitea.dev/modules/optional"
|
||||
"gitea.dev/modules/setting"
|
||||
|
||||
"uuid"
|
||||
)
|
||||
|
||||
// Authenticate queries if login/password is valid against the PAM,
|
||||
|
||||
@@ -20,4 +20,4 @@ type sourceInterface interface {
|
||||
auth_model.UseTLSer
|
||||
}
|
||||
|
||||
var _ (sourceInterface) = &smtp.Source{}
|
||||
var _ sourceInterface = &smtp.Source{}
|
||||
|
||||
@@ -15,4 +15,4 @@ type sourceInterface interface {
|
||||
auth.Config
|
||||
}
|
||||
|
||||
var _ (sourceInterface) = &sspi.Source{}
|
||||
var _ sourceInterface = &sspi.Source{}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"uuid"
|
||||
|
||||
"gitea.dev/models/auth"
|
||||
"gitea.dev/models/db"
|
||||
@@ -19,8 +20,6 @@ import (
|
||||
"gitea.dev/modules/templates"
|
||||
"gitea.dev/services/auth/source/sspi"
|
||||
gitea_context "gitea.dev/services/context"
|
||||
|
||||
"uuid"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -170,7 +170,7 @@ func ToBranchProtection(ctx context.Context, bp *git_model.ProtectedBranch, repo
|
||||
}
|
||||
|
||||
return &api.BranchProtection{
|
||||
BranchName: branchName,
|
||||
BranchName: branchName, //nolint:staticcheck // deprecated field
|
||||
RuleName: bp.RuleName,
|
||||
Priority: bp.Priority,
|
||||
EnablePush: bp.CanPush,
|
||||
|
||||
@@ -20,11 +20,9 @@ import (
|
||||
// ToCommitUser convert a git.Signature to an api.CommitUser
|
||||
func ToCommitUser(sig *git.Signature) *api.CommitUser {
|
||||
return &api.CommitUser{
|
||||
Identity: api.Identity{
|
||||
Name: sig.Name,
|
||||
Email: sig.Email,
|
||||
},
|
||||
Date: sig.When.UTC().Format(time.RFC3339),
|
||||
Name: sig.Name,
|
||||
Email: sig.Email,
|
||||
Date: sig.When.UTC().Format(time.RFC3339),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,18 +155,14 @@ func ToCommit(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Rep
|
||||
RepoCommit: &api.RepoCommit{
|
||||
URL: repo.APIURL() + "/git/commits/" + url.PathEscape(commit.ID.String()),
|
||||
Author: &api.CommitUser{
|
||||
Identity: api.Identity{
|
||||
Name: commit.Author.Name,
|
||||
Email: commit.Author.Email,
|
||||
},
|
||||
Date: commit.Author.When.Format(time.RFC3339),
|
||||
Name: commit.Author.Name,
|
||||
Email: commit.Author.Email,
|
||||
Date: commit.Author.When.Format(time.RFC3339),
|
||||
},
|
||||
Committer: &api.CommitUser{
|
||||
Identity: api.Identity{
|
||||
Name: commit.Committer.Name,
|
||||
Email: commit.Committer.Email,
|
||||
},
|
||||
Date: commit.Committer.When.Format(time.RFC3339),
|
||||
Name: commit.Committer.Name,
|
||||
Email: commit.Committer.Email,
|
||||
Date: commit.Committer.When.Format(time.RFC3339),
|
||||
},
|
||||
Message: commit.MessageUTF8(),
|
||||
Tree: &api.CommitMeta{
|
||||
|
||||
@@ -21,12 +21,12 @@ func TestToCommitMeta(t *testing.T) {
|
||||
sha1 := git.Sha1ObjectFormat
|
||||
signature := &git.Signature{Name: "Test Signature", Email: "test@email.com", When: time.Unix(0, 0)}
|
||||
tag := &git.Tag{
|
||||
Name: "Test Tag",
|
||||
ID: sha1.EmptyObjectID(),
|
||||
Object: sha1.EmptyObjectID(),
|
||||
Type: "Test Type",
|
||||
Tagger: signature,
|
||||
CommitMessage: git.CommitMessage{MessageRaw: "Test Message"},
|
||||
Name: "Test Tag",
|
||||
ID: sha1.EmptyObjectID(),
|
||||
Object: sha1.EmptyObjectID(),
|
||||
Type: "Test Type",
|
||||
Tagger: signature,
|
||||
MessageRaw: "Test Message",
|
||||
}
|
||||
|
||||
commitMeta := ToCommitMeta(headRepo, tag)
|
||||
|
||||
@@ -130,9 +130,9 @@ func toProject(ctx context.Context, p *project_model.Project, doer *user_model.U
|
||||
Description: p.Description,
|
||||
OwnerID: p.OwnerID,
|
||||
RepoID: p.RepoID,
|
||||
CreatorID: p.CreatorID,
|
||||
CreatorID: p.CreatorID, //nolint:staticcheck // deprecated field
|
||||
State: state,
|
||||
IsClosed: p.IsClosed,
|
||||
IsClosed: p.IsClosed, //nolint:staticcheck // deprecated field
|
||||
TemplateType: projectTemplateTypeToString(p.TemplateType),
|
||||
CardType: projectCardTypeToString(p.CardType),
|
||||
Type: projectTypeToString(p.Type),
|
||||
|
||||
@@ -15,18 +15,14 @@ func ToWikiCommit(commit *git.Commit) *api.WikiCommit {
|
||||
return &api.WikiCommit{
|
||||
ID: commit.ID.String(),
|
||||
Author: &api.CommitUser{
|
||||
Identity: api.Identity{
|
||||
Name: commit.Author.Name,
|
||||
Email: commit.Author.Email,
|
||||
},
|
||||
Date: commit.Author.When.UTC().Format(time.RFC3339),
|
||||
Name: commit.Author.Name,
|
||||
Email: commit.Author.Email,
|
||||
Date: commit.Author.When.UTC().Format(time.RFC3339),
|
||||
},
|
||||
Committer: &api.CommitUser{
|
||||
Identity: api.Identity{
|
||||
Name: commit.Committer.Name,
|
||||
Email: commit.Committer.Email,
|
||||
},
|
||||
Date: commit.Committer.When.UTC().Format(time.RFC3339),
|
||||
Name: commit.Committer.Name,
|
||||
Email: commit.Committer.Email,
|
||||
Date: commit.Committer.When.UTC().Format(time.RFC3339),
|
||||
},
|
||||
Message: commit.MessageUTF8(),
|
||||
}
|
||||
|
||||
@@ -29,13 +29,11 @@ func registerUpdateMirrorTask() {
|
||||
}
|
||||
|
||||
RegisterTaskFatal("update_mirrors", &UpdateMirrorTaskConfig{
|
||||
BaseConfig: BaseConfig{
|
||||
Enabled: true,
|
||||
RunAtStart: false,
|
||||
Schedule: "@every 10m",
|
||||
},
|
||||
PullLimit: 50,
|
||||
PushLimit: 50,
|
||||
Enabled: true,
|
||||
RunAtStart: false,
|
||||
Schedule: "@every 10m",
|
||||
PullLimit: 50,
|
||||
PushLimit: 50,
|
||||
}, func(ctx context.Context, _ *user_model.User, cfg *UpdateMirrorTaskConfig) error {
|
||||
return mirror_service.Update(ctx, cfg.PullLimit, cfg.PushLimit)
|
||||
})
|
||||
@@ -48,13 +46,11 @@ func registerRepoHealthCheck() {
|
||||
Args []string `delim:" "`
|
||||
}
|
||||
RegisterTaskFatal("repo_health_check", &RepoHealthCheckConfig{
|
||||
BaseConfig: BaseConfig{
|
||||
Enabled: true,
|
||||
RunAtStart: false,
|
||||
Schedule: "@midnight",
|
||||
},
|
||||
Timeout: time.Duration(setting.Git.Timeout.GC) * time.Second,
|
||||
Args: []string{},
|
||||
Enabled: true,
|
||||
RunAtStart: false,
|
||||
Schedule: "@midnight",
|
||||
Timeout: time.Duration(setting.Git.Timeout.GC) * time.Second,
|
||||
Args: []string{},
|
||||
}, func(ctx context.Context, _ *user_model.User, config *RepoHealthCheckConfig) error {
|
||||
// the git args are set by config, they can be safe to be trusted
|
||||
return repo_service.GitFsckRepos(ctx, config.Timeout, gitcmd.ToTrustedCmdArgs(config.Args))
|
||||
@@ -73,12 +69,10 @@ func registerCheckRepoStats() {
|
||||
|
||||
func registerArchiveCleanup() {
|
||||
RegisterTaskFatal("archive_cleanup", &OlderThanConfig{
|
||||
BaseConfig: BaseConfig{
|
||||
Enabled: true,
|
||||
RunAtStart: true,
|
||||
Schedule: "@midnight",
|
||||
},
|
||||
OlderThan: 24 * time.Hour,
|
||||
Enabled: true,
|
||||
RunAtStart: true,
|
||||
Schedule: "@midnight",
|
||||
OlderThan: 24 * time.Hour,
|
||||
}, func(ctx context.Context, _ *user_model.User, config *OlderThanConfig) error {
|
||||
return archiver_service.DeleteOldRepositoryArchives(ctx, config.OlderThan)
|
||||
})
|
||||
@@ -86,11 +80,9 @@ func registerArchiveCleanup() {
|
||||
|
||||
func registerSyncExternalUsers() {
|
||||
RegisterTaskFatal("sync_external_users", &UpdateExistingConfig{
|
||||
BaseConfig: BaseConfig{
|
||||
Enabled: true,
|
||||
RunAtStart: false,
|
||||
Schedule: "@midnight",
|
||||
},
|
||||
Enabled: true,
|
||||
RunAtStart: false,
|
||||
Schedule: "@midnight",
|
||||
UpdateExisting: true,
|
||||
}, func(ctx context.Context, _ *user_model.User, config *UpdateExistingConfig) error {
|
||||
return auth.SyncExternalUsers(ctx, config.UpdateExisting)
|
||||
@@ -99,12 +91,10 @@ func registerSyncExternalUsers() {
|
||||
|
||||
func registerDeletedBranchesCleanup() {
|
||||
RegisterTaskFatal("deleted_branches_cleanup", &OlderThanConfig{
|
||||
BaseConfig: BaseConfig{
|
||||
Enabled: true,
|
||||
RunAtStart: true,
|
||||
Schedule: "@midnight",
|
||||
},
|
||||
OlderThan: 24 * time.Hour,
|
||||
Enabled: true,
|
||||
RunAtStart: true,
|
||||
Schedule: "@midnight",
|
||||
OlderThan: 24 * time.Hour,
|
||||
}, func(ctx context.Context, _ *user_model.User, config *OlderThanConfig) error {
|
||||
git_model.RemoveOldDeletedBranches(ctx, config.OlderThan)
|
||||
return nil
|
||||
@@ -123,11 +113,9 @@ func registerUpdateMigrationPosterID() {
|
||||
|
||||
func registerCleanupHookTaskTable() {
|
||||
RegisterTaskFatal("cleanup_hook_task_table", &CleanupHookTaskConfig{
|
||||
BaseConfig: BaseConfig{
|
||||
Enabled: true,
|
||||
RunAtStart: false,
|
||||
Schedule: "@midnight",
|
||||
},
|
||||
Enabled: true,
|
||||
RunAtStart: false,
|
||||
Schedule: "@midnight",
|
||||
CleanupType: "OlderThan",
|
||||
OlderThan: 168 * time.Hour,
|
||||
NumberToKeep: 10,
|
||||
@@ -138,12 +126,10 @@ func registerCleanupHookTaskTable() {
|
||||
|
||||
func registerCleanupPackages() {
|
||||
RegisterTaskFatal("cleanup_packages", &OlderThanConfig{
|
||||
BaseConfig: BaseConfig{
|
||||
Enabled: true,
|
||||
RunAtStart: true,
|
||||
Schedule: "@midnight",
|
||||
},
|
||||
OlderThan: 24 * time.Hour,
|
||||
Enabled: true,
|
||||
RunAtStart: true,
|
||||
Schedule: "@midnight",
|
||||
OlderThan: 24 * time.Hour,
|
||||
}, func(ctx context.Context, _ *user_model.User, config *OlderThanConfig) error {
|
||||
return packages_cleanup_service.CleanupTask(ctx, config.OlderThan)
|
||||
})
|
||||
|
||||
@@ -22,12 +22,10 @@ import (
|
||||
|
||||
func registerDeleteInactiveUsers() {
|
||||
RegisterTaskFatal("delete_inactive_accounts", &OlderThanConfig{
|
||||
BaseConfig: BaseConfig{
|
||||
Enabled: false,
|
||||
RunAtStart: false,
|
||||
Schedule: "@annually",
|
||||
},
|
||||
OlderThan: time.Minute * time.Duration(setting.Service.ActiveCodeLives),
|
||||
Enabled: false,
|
||||
RunAtStart: false,
|
||||
Schedule: "@annually",
|
||||
OlderThan: time.Minute * time.Duration(setting.Service.ActiveCodeLives),
|
||||
}, func(ctx context.Context, _ *user_model.User, config *OlderThanConfig) error {
|
||||
return user_service.DeleteInactiveUsers(ctx, config.OlderThan)
|
||||
})
|
||||
@@ -50,13 +48,11 @@ func registerGarbageCollectRepositories() {
|
||||
Args []string `delim:" "`
|
||||
}
|
||||
RegisterTaskFatal("git_gc_repos", &RepoHealthCheckConfig{
|
||||
BaseConfig: BaseConfig{
|
||||
Enabled: false,
|
||||
RunAtStart: false,
|
||||
Schedule: "@every 72h",
|
||||
},
|
||||
Timeout: time.Duration(setting.Git.Timeout.GC) * time.Second,
|
||||
Args: setting.Git.GCArgs,
|
||||
Enabled: false,
|
||||
RunAtStart: false,
|
||||
Schedule: "@every 72h",
|
||||
Timeout: time.Duration(setting.Git.Timeout.GC) * time.Second,
|
||||
Args: setting.Git.GCArgs,
|
||||
}, func(ctx context.Context, _ *user_model.User, config *RepoHealthCheckConfig) error {
|
||||
// the git args are set by config, they can be safe to be trusted
|
||||
return repo_service.GitGcRepos(ctx, config.Timeout, gitcmd.ToTrustedCmdArgs(config.Args))
|
||||
@@ -125,12 +121,10 @@ func registerRemoveRandomAvatars() {
|
||||
|
||||
func registerDeleteOldActions() {
|
||||
RegisterTaskFatal("delete_old_actions", &OlderThanConfig{
|
||||
BaseConfig: BaseConfig{
|
||||
Enabled: false,
|
||||
RunAtStart: false,
|
||||
Schedule: "@every 168h",
|
||||
},
|
||||
OlderThan: 365 * 24 * time.Hour,
|
||||
Enabled: false,
|
||||
RunAtStart: false,
|
||||
Schedule: "@every 168h",
|
||||
OlderThan: 365 * 24 * time.Hour,
|
||||
}, func(ctx context.Context, _ *user_model.User, config *OlderThanConfig) error {
|
||||
return activities_model.DeleteOldActions(ctx, config.OlderThan)
|
||||
})
|
||||
@@ -142,11 +136,9 @@ func registerUpdateGiteaChecker() {
|
||||
HTTPEndpoint string
|
||||
}
|
||||
RegisterTaskFatal("update_checker", &UpdateCheckerConfig{
|
||||
BaseConfig: BaseConfig{
|
||||
Enabled: true,
|
||||
RunAtStart: false,
|
||||
Schedule: "@every 168h",
|
||||
},
|
||||
Enabled: true,
|
||||
RunAtStart: false,
|
||||
Schedule: "@every 168h",
|
||||
HTTPEndpoint: "https://dl.gitea.com/gitea/version.json",
|
||||
}, func(ctx context.Context, _ *user_model.User, config *UpdateCheckerConfig) error {
|
||||
return updatechecker.GiteaUpdateChecker(config.HTTPEndpoint)
|
||||
@@ -155,12 +147,10 @@ func registerUpdateGiteaChecker() {
|
||||
|
||||
func registerDeleteOldSystemNotices() {
|
||||
RegisterTaskFatal("delete_old_system_notices", &OlderThanConfig{
|
||||
BaseConfig: BaseConfig{
|
||||
Enabled: false,
|
||||
RunAtStart: false,
|
||||
Schedule: "@every 168h",
|
||||
},
|
||||
OlderThan: 365 * 24 * time.Hour,
|
||||
Enabled: false,
|
||||
RunAtStart: false,
|
||||
Schedule: "@every 168h",
|
||||
OlderThan: 365 * 24 * time.Hour,
|
||||
}, func(ctx context.Context, _ *user_model.User, config *OlderThanConfig) error {
|
||||
return system.DeleteOldSystemNotices(ctx, config.OlderThan)
|
||||
})
|
||||
@@ -180,11 +170,9 @@ func registerGCLFS() {
|
||||
}
|
||||
|
||||
RegisterTaskFatal("gc_lfs", &GCLFSConfig{
|
||||
BaseConfig: BaseConfig{
|
||||
Enabled: false,
|
||||
RunAtStart: false,
|
||||
Schedule: "@every 24h",
|
||||
},
|
||||
Enabled: false,
|
||||
RunAtStart: false,
|
||||
Schedule: "@every 24h",
|
||||
// Only attempt to garbage collect lfs meta objects older than a week as the order of git lfs upload
|
||||
// and git object upload is not necessarily guaranteed. It's possible to imagine a situation whereby
|
||||
// an LFS object is uploaded but the git branch is not uploaded immediately, or there are some rapid
|
||||
|
||||
@@ -28,11 +28,9 @@ PROPORTION_TO_CHECK_PER_REPO = 0.1
|
||||
defer test.MockVariableValue(&setting.CfgProvider, cfg)()
|
||||
|
||||
config := &GCLFSConfig{
|
||||
BaseConfig: BaseConfig{
|
||||
Enabled: false,
|
||||
RunAtStart: false,
|
||||
Schedule: "@every 24h",
|
||||
},
|
||||
Enabled: false,
|
||||
RunAtStart: false,
|
||||
Schedule: "@every 24h",
|
||||
OlderThan: 24 * time.Hour * 7,
|
||||
LastUpdatedMoreThanAgo: 24 * time.Hour * 3,
|
||||
NumberToCheckPerRepo: 100,
|
||||
|
||||
@@ -1198,7 +1198,7 @@ func parseHunks(ctx context.Context, curFile *DiffFile, maxLines, maxLineCharact
|
||||
} else if curFileLFSPrefix && strings.HasPrefix(line[1:], lfs.MetaFileOidPrefix) {
|
||||
oid := strings.TrimPrefix(line[1:], lfs.MetaFileOidPrefix)
|
||||
if len(oid) == 64 {
|
||||
m := &git_model.LFSMetaObject{Pointer: lfs.Pointer{Oid: oid}}
|
||||
m := &git_model.LFSMetaObject{Oid: oid}
|
||||
count, err := db.CountByBean(ctx, m)
|
||||
|
||||
if err == nil && count > 0 {
|
||||
|
||||
@@ -64,13 +64,11 @@ type AuthTokenOptions struct {
|
||||
func GetLFSAuthTokenWithBearer(opts AuthTokenOptions) (string, error) {
|
||||
now := time.Now()
|
||||
claims := Claims{
|
||||
RegisteredClaims: jwt.RegisteredClaims{
|
||||
ExpiresAt: jwt.NewNumericDate(now.Add(setting.LFS.HTTPAuthExpiry)),
|
||||
NotBefore: jwt.NewNumericDate(now),
|
||||
},
|
||||
RepoID: opts.RepoID,
|
||||
Op: opts.Op,
|
||||
UserID: opts.UserID,
|
||||
ExpiresAt: jwt.NewNumericDate(now.Add(setting.LFS.HTTPAuthExpiry)),
|
||||
NotBefore: jwt.NewNumericDate(now),
|
||||
RepoID: opts.RepoID,
|
||||
Op: opts.Op,
|
||||
UserID: opts.UserID,
|
||||
}
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
||||
|
||||
|
||||
@@ -576,8 +576,8 @@ func TestMailPullRequestPush(t *testing.T) {
|
||||
SignCommit: &asymkey.SignCommit{
|
||||
UserCommit: &gituser.UserCommit{
|
||||
GitCommit: &git.Commit{
|
||||
CommitMessage: git.CommitMessage{MessageRaw: "test commit msg"},
|
||||
ID: git.Sha1ObjectFormat.EmptyObjectID(),
|
||||
MessageRaw: "test commit msg",
|
||||
ID: git.Sha1ObjectFormat.EmptyObjectID(),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"uuid"
|
||||
|
||||
user_model "gitea.dev/models/user"
|
||||
"gitea.dev/modules/git"
|
||||
@@ -26,7 +27,6 @@ import (
|
||||
"gitea.dev/modules/structs"
|
||||
|
||||
"go.yaml.in/yaml/v4"
|
||||
"uuid"
|
||||
)
|
||||
|
||||
var _ base.Uploader = &RepositoryDumper{}
|
||||
|
||||
@@ -176,11 +176,9 @@ func (g *GiteaDownloader) GetMilestones(ctx context.Context) ([]*base.Milestone,
|
||||
}
|
||||
|
||||
ms, _, err := g.client.Repositories.ListMilestones(g.ctx, g.repoOwner, g.repoName, gitea_sdk.ListMilestoneOption{
|
||||
ListOptions: gitea_sdk.ListOptions{
|
||||
PageSize: g.maxPerPage,
|
||||
Page: i,
|
||||
},
|
||||
State: gitea_sdk.StateAll,
|
||||
PageSize: g.maxPerPage,
|
||||
Page: i,
|
||||
State: gitea_sdk.StateAll,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -240,10 +238,10 @@ func (g *GiteaDownloader) GetLabels(ctx context.Context) ([]*base.Label, error)
|
||||
default:
|
||||
}
|
||||
|
||||
ls, _, err := g.client.Repositories.ListRepoLabels(g.ctx, g.repoOwner, g.repoName, gitea_sdk.ListLabelsOptions{ListOptions: gitea_sdk.ListOptions{
|
||||
ls, _, err := g.client.Repositories.ListRepoLabels(g.ctx, g.repoOwner, g.repoName, gitea_sdk.ListLabelsOptions{
|
||||
PageSize: g.maxPerPage,
|
||||
Page: i,
|
||||
}})
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -328,10 +326,10 @@ func (g *GiteaDownloader) GetReleases(ctx context.Context) ([]*base.Release, err
|
||||
default:
|
||||
}
|
||||
|
||||
rl, _, err := g.client.Releases.ListReleases(g.ctx, g.repoOwner, g.repoName, gitea_sdk.ListReleasesOptions{ListOptions: gitea_sdk.ListOptions{
|
||||
rl, _, err := g.client.Releases.ListReleases(g.ctx, g.repoOwner, g.repoName, gitea_sdk.ListReleasesOptions{
|
||||
PageSize: g.maxPerPage,
|
||||
Page: i,
|
||||
}})
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -362,10 +360,10 @@ func (g *GiteaDownloader) getIssueReactions(ctx context.Context, index int64) ([
|
||||
default:
|
||||
}
|
||||
|
||||
reactions, _, err := g.client.Issues.ListIssueReactions(g.ctx, g.repoOwner, g.repoName, index, gitea_sdk.ListIssueReactionsOptions{ListOptions: gitea_sdk.ListOptions{
|
||||
reactions, _, err := g.client.Issues.ListIssueReactions(g.ctx, g.repoOwner, g.repoName, index, gitea_sdk.ListIssueReactionsOptions{
|
||||
PageSize: g.maxPerPage,
|
||||
Page: i,
|
||||
}})
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -414,9 +412,9 @@ func (g *GiteaDownloader) GetIssues(ctx context.Context, page, perPage int) ([]*
|
||||
allIssues := make([]*base.Issue, 0, perPage)
|
||||
|
||||
issues, _, err := g.client.Issues.ListRepoIssues(g.ctx, g.repoOwner, g.repoName, gitea_sdk.ListIssueOption{
|
||||
ListOptions: gitea_sdk.ListOptions{Page: page, PageSize: perPage},
|
||||
State: gitea_sdk.StateAll,
|
||||
Type: gitea_sdk.IssueTypeIssue,
|
||||
Page: page, PageSize: perPage,
|
||||
State: gitea_sdk.StateAll,
|
||||
Type: gitea_sdk.IssueTypeIssue,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("error while listing issues: %w", err)
|
||||
@@ -481,10 +479,10 @@ func (g *GiteaDownloader) GetComments(ctx context.Context, commentable base.Comm
|
||||
default:
|
||||
}
|
||||
|
||||
comments, _, err := g.client.Issues.ListIssueComments(g.ctx, g.repoOwner, g.repoName, commentable.GetForeignIndex(), gitea_sdk.ListIssueCommentOptions{ListOptions: gitea_sdk.ListOptions{
|
||||
comments, _, err := g.client.Issues.ListIssueComments(g.ctx, g.repoOwner, g.repoName, commentable.GetForeignIndex(), gitea_sdk.ListIssueCommentOptions{
|
||||
PageSize: g.maxPerPage,
|
||||
Page: i,
|
||||
}})
|
||||
})
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("error while listing comments for issue #%d. Error: %w", commentable.GetForeignIndex(), err)
|
||||
}
|
||||
@@ -523,11 +521,9 @@ func (g *GiteaDownloader) GetPullRequests(ctx context.Context, page, perPage int
|
||||
allPRs := make([]*base.PullRequest, 0, perPage)
|
||||
|
||||
prs, _, err := g.client.PullRequests.ListRepoPullRequests(g.ctx, g.repoOwner, g.repoName, gitea_sdk.ListPullRequestsOptions{
|
||||
ListOptions: gitea_sdk.ListOptions{
|
||||
Page: page,
|
||||
PageSize: perPage,
|
||||
},
|
||||
State: gitea_sdk.StateAll,
|
||||
Page: page,
|
||||
PageSize: perPage,
|
||||
State: gitea_sdk.StateAll,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("error while listing pull requests (page: %d, pagesize: %d). Error: %w", page, perPage, err)
|
||||
@@ -652,10 +648,10 @@ func (g *GiteaDownloader) GetReviews(ctx context.Context, reviewable base.Review
|
||||
default:
|
||||
}
|
||||
|
||||
prl, _, err := g.client.PullRequests.ListPullReviews(g.ctx, g.repoOwner, g.repoName, reviewable.GetForeignIndex(), gitea_sdk.ListPullReviewsOptions{ListOptions: gitea_sdk.ListOptions{
|
||||
prl, _, err := g.client.PullRequests.ListPullReviews(g.ctx, g.repoOwner, g.repoName, reviewable.GetForeignIndex(), gitea_sdk.ListPullReviewsOptions{
|
||||
Page: i,
|
||||
PageSize: g.maxPerPage,
|
||||
}})
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"uuid"
|
||||
|
||||
"gitea.dev/models/db"
|
||||
issues_model "gitea.dev/models/issues"
|
||||
@@ -32,8 +33,6 @@ import (
|
||||
"gitea.dev/modules/util"
|
||||
"gitea.dev/services/pull"
|
||||
repo_service "gitea.dev/services/repository"
|
||||
|
||||
"uuid"
|
||||
)
|
||||
|
||||
var _ base.Uploader = &GiteaLocalUploader{}
|
||||
|
||||
@@ -80,10 +80,8 @@ func TestGiteaUploadRepo(t *testing.T) {
|
||||
assert.Len(t, labels, 12)
|
||||
|
||||
releases, err := db.Find[repo_model.Release](t.Context(), repo_model.FindReleasesOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
PageSize: 10,
|
||||
Page: 0,
|
||||
},
|
||||
PageSize: 10,
|
||||
Page: 0,
|
||||
IncludeTags: true,
|
||||
RepoID: repo.ID,
|
||||
})
|
||||
@@ -91,10 +89,8 @@ func TestGiteaUploadRepo(t *testing.T) {
|
||||
assert.Len(t, releases, 8)
|
||||
|
||||
releases, err = db.Find[repo_model.Release](t.Context(), repo_model.FindReleasesOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
PageSize: 10,
|
||||
Page: 0,
|
||||
},
|
||||
PageSize: 10,
|
||||
Page: 0,
|
||||
IncludeTags: false,
|
||||
RepoID: repo.ID,
|
||||
})
|
||||
|
||||
@@ -244,11 +244,9 @@ func (g *GithubDownloaderV3) GetMilestones(ctx context.Context) ([]*base.Milesto
|
||||
g.waitAndPickClient(ctx)
|
||||
ms, resp, err := g.getClient().Issues.ListMilestones(ctx, g.repoOwner, g.repoName,
|
||||
&github.MilestoneListOptions{
|
||||
State: "all",
|
||||
ListOptions: github.ListOptions{
|
||||
Page: i,
|
||||
PerPage: perPage,
|
||||
},
|
||||
State: "all",
|
||||
Page: i,
|
||||
PerPage: perPage,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -459,10 +457,8 @@ func (g *GithubDownloaderV3) GetIssues(ctx context.Context, page, perPage int) (
|
||||
for i := 1; ; i++ {
|
||||
g.waitAndPickClient(ctx)
|
||||
res, resp, err := g.getClient().Reactions.ListIssueReactions(ctx, g.repoOwner, g.repoName, issue.GetNumber(), &github.ListReactionOptions{
|
||||
ListOptions: github.ListOptions{
|
||||
Page: i,
|
||||
PerPage: perPage,
|
||||
},
|
||||
Page: i,
|
||||
PerPage: perPage,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
@@ -529,9 +525,7 @@ func (g *GithubDownloaderV3) getComments(ctx context.Context, commentable base.C
|
||||
opt := &github.IssueListCommentsOptions{
|
||||
Sort: &created,
|
||||
Direction: &asc,
|
||||
ListOptions: github.ListOptions{
|
||||
PerPage: g.maxPerPage,
|
||||
},
|
||||
PerPage: g.maxPerPage,
|
||||
}
|
||||
for {
|
||||
g.waitAndPickClient(ctx)
|
||||
@@ -547,10 +541,8 @@ func (g *GithubDownloaderV3) getComments(ctx context.Context, commentable base.C
|
||||
for i := 1; ; i++ {
|
||||
g.waitAndPickClient(ctx)
|
||||
res, resp, err := g.getClient().Reactions.ListIssueCommentReactions(ctx, g.repoOwner, g.repoName, comment.GetID(), &github.ListReactionOptions{
|
||||
ListOptions: github.ListOptions{
|
||||
Page: i,
|
||||
PerPage: g.maxPerPage,
|
||||
},
|
||||
Page: i,
|
||||
PerPage: g.maxPerPage,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -602,10 +594,8 @@ func (g *GithubDownloaderV3) GetAllComments(ctx context.Context, page, perPage i
|
||||
opt := &github.IssueListCommentsOptions{
|
||||
Sort: &created,
|
||||
Direction: &asc,
|
||||
ListOptions: github.ListOptions{
|
||||
Page: page,
|
||||
PerPage: perPage,
|
||||
},
|
||||
Page: page,
|
||||
PerPage: perPage,
|
||||
}
|
||||
|
||||
g.waitAndPickClient(ctx)
|
||||
@@ -624,10 +614,8 @@ func (g *GithubDownloaderV3) GetAllComments(ctx context.Context, page, perPage i
|
||||
for i := 1; ; i++ {
|
||||
g.waitAndPickClient(ctx)
|
||||
res, resp, err := g.getClient().Reactions.ListIssueCommentReactions(ctx, g.repoOwner, g.repoName, comment.GetID(), &github.ListReactionOptions{
|
||||
ListOptions: github.ListOptions{
|
||||
Page: i,
|
||||
PerPage: g.maxPerPage,
|
||||
},
|
||||
Page: i,
|
||||
PerPage: g.maxPerPage,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
@@ -672,10 +660,8 @@ func (g *GithubDownloaderV3) GetPullRequests(ctx context.Context, page, perPage
|
||||
Sort: "created",
|
||||
Direction: "asc",
|
||||
State: "all",
|
||||
ListOptions: github.ListOptions{
|
||||
PerPage: perPage,
|
||||
Page: page,
|
||||
},
|
||||
PerPage: perPage,
|
||||
Page: page,
|
||||
}
|
||||
allPRs := make([]*base.PullRequest, 0, perPage)
|
||||
g.waitAndPickClient(ctx)
|
||||
@@ -697,10 +683,8 @@ func (g *GithubDownloaderV3) GetPullRequests(ctx context.Context, page, perPage
|
||||
for i := 1; ; i++ {
|
||||
g.waitAndPickClient(ctx)
|
||||
res, resp, err := g.getClient().Reactions.ListIssueReactions(ctx, g.repoOwner, g.repoName, pr.GetNumber(), &github.ListReactionOptions{
|
||||
ListOptions: github.ListOptions{
|
||||
Page: i,
|
||||
PerPage: perPage,
|
||||
},
|
||||
Page: i,
|
||||
PerPage: perPage,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
@@ -786,10 +770,8 @@ func (g *GithubDownloaderV3) convertGithubReviewComments(ctx context.Context, cs
|
||||
for i := 1; ; i++ {
|
||||
g.waitAndPickClient(ctx)
|
||||
res, resp, err := g.getClient().Reactions.ListPullRequestCommentReactions(ctx, g.repoOwner, g.repoName, c.GetID(), &github.ListReactionOptions{
|
||||
ListOptions: github.ListOptions{
|
||||
Page: i,
|
||||
PerPage: g.maxPerPage,
|
||||
},
|
||||
Page: i,
|
||||
PerPage: g.maxPerPage,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -210,11 +210,9 @@ func (g *GitlabDownloader) GetMilestones(ctx context.Context) ([]*base.Milestone
|
||||
milestones := make([]*base.Milestone, 0, perPage)
|
||||
for i := 1; ; i++ {
|
||||
ms, _, err := g.client.Milestones.ListMilestones(g.repoID, &gitlab.ListMilestonesOptions{
|
||||
State: &state,
|
||||
ListOptions: gitlab.ListOptions{
|
||||
Page: int64(i),
|
||||
PerPage: int64(perPage),
|
||||
},
|
||||
State: &state,
|
||||
Page: int64(i),
|
||||
PerPage: int64(perPage),
|
||||
}, nil, gitlab.WithContext(ctx))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -280,10 +278,10 @@ func (g *GitlabDownloader) GetLabels(ctx context.Context) ([]*base.Label, error)
|
||||
perPage := g.maxPerPage
|
||||
labels := make([]*base.Label, 0, perPage)
|
||||
for i := 1; ; i++ {
|
||||
ls, _, err := g.client.Labels.ListLabels(g.repoID, &gitlab.ListLabelsOptions{ListOptions: gitlab.ListOptions{
|
||||
ls, _, err := g.client.Labels.ListLabels(g.repoID, &gitlab.ListLabelsOptions{
|
||||
Page: int64(i),
|
||||
PerPage: int64(perPage),
|
||||
}}, nil, gitlab.WithContext(ctx))
|
||||
}, nil, gitlab.WithContext(ctx))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -358,10 +356,8 @@ func (g *GitlabDownloader) GetReleases(ctx context.Context) ([]*base.Release, er
|
||||
releases := make([]*base.Release, 0, perPage)
|
||||
for i := 1; ; i++ {
|
||||
ls, _, err := g.client.Releases.ListReleases(g.repoID, &gitlab.ListReleasesOptions{
|
||||
ListOptions: gitlab.ListOptions{
|
||||
Page: int64(i),
|
||||
PerPage: int64(perPage),
|
||||
},
|
||||
Page: int64(i),
|
||||
PerPage: int64(perPage),
|
||||
}, nil, gitlab.WithContext(ctx))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -393,12 +389,10 @@ func (g *GitlabDownloader) GetIssues(ctx context.Context, page, perPage int) ([]
|
||||
}
|
||||
|
||||
opt := &gitlab.ListProjectIssuesOptions{
|
||||
State: &state,
|
||||
Sort: &sort,
|
||||
ListOptions: gitlab.ListOptions{
|
||||
PerPage: int64(perPage),
|
||||
Page: int64(page),
|
||||
},
|
||||
State: &state,
|
||||
Sort: &sort,
|
||||
PerPage: int64(perPage),
|
||||
Page: int64(page),
|
||||
}
|
||||
|
||||
allIssues := make([]*base.Issue, 0, perPage)
|
||||
@@ -423,7 +417,7 @@ func (g *GitlabDownloader) GetIssues(ctx context.Context, page, perPage int) ([]
|
||||
var reactions []*gitlab.AwardEmoji
|
||||
awardPage := 1
|
||||
for {
|
||||
awards, _, err := g.client.AwardEmoji.ListIssueAwardEmoji(g.repoID, issue.IID, &gitlab.ListAwardEmojiOptions{ListOptions: gitlab.ListOptions{Page: int64(awardPage), PerPage: int64(perPage)}}, gitlab.WithContext(ctx))
|
||||
awards, _, err := g.client.AwardEmoji.ListIssueAwardEmoji(g.repoID, issue.IID, &gitlab.ListAwardEmojiOptions{Page: int64(awardPage), PerPage: int64(perPage)}, gitlab.WithContext(ctx))
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("error while listing issue awards: %w", err)
|
||||
}
|
||||
@@ -480,17 +474,13 @@ func (g *GitlabDownloader) GetComments(ctx context.Context, commentable base.Com
|
||||
var err error
|
||||
if !context.IsMergeRequest {
|
||||
comments, resp, err = g.client.Discussions.ListIssueDiscussions(g.repoID, commentable.GetForeignIndex(), &gitlab.ListIssueDiscussionsOptions{
|
||||
ListOptions: gitlab.ListOptions{
|
||||
Page: page,
|
||||
PerPage: int64(g.maxPerPage),
|
||||
},
|
||||
Page: page,
|
||||
PerPage: int64(g.maxPerPage),
|
||||
}, nil, gitlab.WithContext(ctx))
|
||||
} else {
|
||||
comments, resp, err = g.client.Discussions.ListMergeRequestDiscussions(g.repoID, commentable.GetForeignIndex(), &gitlab.ListMergeRequestDiscussionsOptions{
|
||||
ListOptions: gitlab.ListOptions{
|
||||
Page: page,
|
||||
PerPage: int64(g.maxPerPage),
|
||||
},
|
||||
Page: page,
|
||||
PerPage: int64(g.maxPerPage),
|
||||
}, nil, gitlab.WithContext(ctx))
|
||||
}
|
||||
|
||||
@@ -515,17 +505,13 @@ func (g *GitlabDownloader) GetComments(ctx context.Context, commentable base.Com
|
||||
var err error
|
||||
if context.IsMergeRequest {
|
||||
stateEvents, resp, err = g.client.ResourceStateEvents.ListMergeStateEvents(g.repoID, commentable.GetForeignIndex(), &gitlab.ListStateEventsOptions{
|
||||
ListOptions: gitlab.ListOptions{
|
||||
Page: page,
|
||||
PerPage: int64(g.maxPerPage),
|
||||
},
|
||||
Page: page,
|
||||
PerPage: int64(g.maxPerPage),
|
||||
}, nil, gitlab.WithContext(ctx))
|
||||
} else {
|
||||
stateEvents, resp, err = g.client.ResourceStateEvents.ListIssueStateEvents(g.repoID, commentable.GetForeignIndex(), &gitlab.ListStateEventsOptions{
|
||||
ListOptions: gitlab.ListOptions{
|
||||
Page: page,
|
||||
PerPage: int64(g.maxPerPage),
|
||||
},
|
||||
Page: page,
|
||||
PerPage: int64(g.maxPerPage),
|
||||
}, nil, gitlab.WithContext(ctx))
|
||||
}
|
||||
if err != nil {
|
||||
@@ -606,11 +592,9 @@ func (g *GitlabDownloader) GetPullRequests(ctx context.Context, page, perPage in
|
||||
|
||||
view := "simple"
|
||||
opt := &gitlab.ListProjectMergeRequestsOptions{
|
||||
ListOptions: gitlab.ListOptions{
|
||||
PerPage: int64(perPage),
|
||||
Page: int64(page),
|
||||
},
|
||||
View: &view,
|
||||
PerPage: int64(perPage),
|
||||
Page: int64(page),
|
||||
View: &view,
|
||||
}
|
||||
|
||||
allPRs := make([]*base.PullRequest, 0, perPage)
|
||||
@@ -668,7 +652,7 @@ func (g *GitlabDownloader) GetPullRequests(ctx context.Context, page, perPage in
|
||||
var reactions []*gitlab.AwardEmoji
|
||||
awardPage := 1
|
||||
for {
|
||||
awards, _, err := g.client.AwardEmoji.ListMergeRequestAwardEmoji(g.repoID, pr.IID, &gitlab.ListAwardEmojiOptions{ListOptions: gitlab.ListOptions{Page: int64(awardPage), PerPage: int64(perPage)}}, gitlab.WithContext(ctx))
|
||||
awards, _, err := g.client.AwardEmoji.ListMergeRequestAwardEmoji(g.repoID, pr.IID, &gitlab.ListAwardEmojiOptions{Page: int64(awardPage), PerPage: int64(perPage)}, gitlab.WithContext(ctx))
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("error while listing merge requests awards: %w", err)
|
||||
}
|
||||
|
||||
@@ -45,10 +45,8 @@ func updateMigrationPosterIDByGitService(ctx context.Context, tp structs.GitServ
|
||||
}
|
||||
|
||||
users, err := db.Find[user_model.ExternalLoginUser](ctx, user_model.FindExternalUserOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
PageSize: batchSize,
|
||||
Page: page,
|
||||
},
|
||||
PageSize: batchSize,
|
||||
Page: page,
|
||||
Provider: provider,
|
||||
OrderBy: "login_source_id ASC, external_id ASC",
|
||||
})
|
||||
|
||||
@@ -138,11 +138,9 @@ func NewAccessTokenResponse(ctx context.Context, grant *auth.OAuth2Grant, server
|
||||
// generate access token to access the API
|
||||
expirationDate := timeutil.TimeStampNow().Add(setting.OAuth2.AccessTokenExpirationTime)
|
||||
accessToken := &Token{
|
||||
GrantID: grant.ID,
|
||||
Kind: KindAccessToken,
|
||||
RegisteredClaims: jwt.RegisteredClaims{
|
||||
ExpiresAt: jwt.NewNumericDate(expirationDate.AsTime()),
|
||||
},
|
||||
GrantID: grant.ID,
|
||||
Kind: KindAccessToken,
|
||||
ExpiresAt: jwt.NewNumericDate(expirationDate.AsTime()),
|
||||
}
|
||||
signedAccessToken, err := accessToken.SignToken(serverKey)
|
||||
if err != nil {
|
||||
@@ -155,12 +153,10 @@ func NewAccessTokenResponse(ctx context.Context, grant *auth.OAuth2Grant, server
|
||||
// generate refresh token to request an access token after it expired later
|
||||
refreshExpirationDate := timeutil.TimeStampNow().Add(setting.OAuth2.RefreshTokenExpirationTime * 60 * 60).AsTime()
|
||||
refreshToken := &Token{
|
||||
GrantID: grant.ID,
|
||||
Counter: grant.Counter,
|
||||
Kind: KindRefreshToken,
|
||||
RegisteredClaims: jwt.RegisteredClaims{
|
||||
ExpiresAt: jwt.NewNumericDate(refreshExpirationDate),
|
||||
},
|
||||
GrantID: grant.ID,
|
||||
Counter: grant.Counter,
|
||||
Kind: KindRefreshToken,
|
||||
ExpiresAt: jwt.NewNumericDate(refreshExpirationDate),
|
||||
}
|
||||
signedRefreshToken, err := refreshToken.SignToken(serverKey)
|
||||
if err != nil {
|
||||
|
||||
@@ -333,10 +333,8 @@ func buildPackagesIndex(ctx context.Context, ownerID int64, repoVersion *package
|
||||
ctx,
|
||||
repoVersion,
|
||||
&packages_service.PackageFileCreationInfo{
|
||||
PackageFileInfo: packages_service.PackageFileInfo{
|
||||
Filename: IndexArchiveFilename,
|
||||
CompositeKey: fmt.Sprintf("%s|%s|%s", branch, repository, architecture),
|
||||
},
|
||||
Filename: IndexArchiveFilename,
|
||||
CompositeKey: fmt.Sprintf("%s|%s|%s", branch, repository, architecture),
|
||||
Creator: user_model.NewGhostUser(),
|
||||
Data: signedIndexContent,
|
||||
IsLead: false,
|
||||
|
||||
@@ -328,10 +328,8 @@ func buildPackagesIndex(ctx context.Context, ownerID int64, repoVersion *package
|
||||
ctx,
|
||||
repoVersion,
|
||||
&packages_service.PackageFileCreationInfo{
|
||||
PackageFileInfo: packages_service.PackageFileInfo{
|
||||
Filename: IndexArchiveFilename,
|
||||
CompositeKey: fmt.Sprintf("%s|%s", repository, architecture),
|
||||
},
|
||||
Filename: IndexArchiveFilename,
|
||||
CompositeKey: fmt.Sprintf("%s|%s", repository, architecture),
|
||||
Creator: user_model.NewGhostUser(),
|
||||
Data: indexContent,
|
||||
IsLead: false,
|
||||
|
||||
@@ -33,15 +33,11 @@ func CreateAuthorizationToken(u *user_model.User, packageScope auth_model.Access
|
||||
|
||||
actionsUserTaskID, _ := user_model.GetActionsUserTaskID(u)
|
||||
claims := packageClaims{
|
||||
RegisteredClaims: jwt.RegisteredClaims{
|
||||
ExpiresAt: jwt.NewNumericDate(now.Add(24 * time.Hour)),
|
||||
NotBefore: jwt.NewNumericDate(now),
|
||||
},
|
||||
PackageMeta: PackageMeta{
|
||||
UserID: u.ID,
|
||||
Scope: packageScope,
|
||||
ActionsUserTaskID: actionsUserTaskID,
|
||||
},
|
||||
ExpiresAt: jwt.NewNumericDate(now.Add(24 * time.Hour)),
|
||||
NotBefore: jwt.NewNumericDate(now),
|
||||
UserID: u.ID,
|
||||
Scope: packageScope,
|
||||
ActionsUserTaskID: actionsUserTaskID,
|
||||
}
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
||||
|
||||
|
||||
@@ -248,10 +248,8 @@ func buildPackagesIndices(ctx context.Context, ownerID int64, repoVersion *packa
|
||||
ctx,
|
||||
repoVersion,
|
||||
&packages_service.PackageFileCreationInfo{
|
||||
PackageFileInfo: packages_service.PackageFileInfo{
|
||||
Filename: file.Name,
|
||||
CompositeKey: fmt.Sprintf("%s|%s|%s", distribution, component, architecture),
|
||||
},
|
||||
Filename: file.Name,
|
||||
CompositeKey: fmt.Sprintf("%s|%s|%s", distribution, component, architecture),
|
||||
Creator: user_model.NewGhostUser(),
|
||||
Data: file.Data,
|
||||
IsLead: false,
|
||||
@@ -400,10 +398,8 @@ func buildReleaseFiles(ctx context.Context, ownerID int64, repoVersion *packages
|
||||
ctx,
|
||||
repoVersion,
|
||||
&packages_service.PackageFileCreationInfo{
|
||||
PackageFileInfo: packages_service.PackageFileInfo{
|
||||
Filename: file.Name,
|
||||
CompositeKey: distribution,
|
||||
},
|
||||
Filename: file.Name,
|
||||
CompositeKey: distribution,
|
||||
Creator: user_model.NewGhostUser(),
|
||||
Data: file.Data,
|
||||
IsLead: false,
|
||||
|
||||
@@ -317,10 +317,8 @@ func buildRepomd(ctx context.Context, pv *packages_model.PackageVersion, ownerID
|
||||
ctx,
|
||||
pv,
|
||||
&packages_service.PackageFileCreationInfo{
|
||||
PackageFileInfo: packages_service.PackageFileInfo{
|
||||
Filename: file.Name,
|
||||
CompositeKey: group,
|
||||
},
|
||||
Filename: file.Name,
|
||||
CompositeKey: group,
|
||||
Creator: user_model.NewGhostUser(),
|
||||
Data: file.Data,
|
||||
IsLead: false,
|
||||
@@ -700,10 +698,8 @@ func addDataAsFileToRepo(ctx context.Context, pv *packages_model.PackageVersion,
|
||||
ctx,
|
||||
pv,
|
||||
&packages_service.PackageFileCreationInfo{
|
||||
PackageFileInfo: packages_service.PackageFileInfo{
|
||||
Filename: filename,
|
||||
CompositeKey: group,
|
||||
},
|
||||
Filename: filename,
|
||||
CompositeKey: group,
|
||||
Creator: user_model.NewGhostUser(),
|
||||
Data: content,
|
||||
IsLead: false,
|
||||
|
||||
@@ -21,14 +21,14 @@ import (
|
||||
// TODO TestPullRequest_PushToBaseRepo
|
||||
|
||||
func TestPullRequest_FormatSquashMergeCommitMessages(t *testing.T) {
|
||||
oldest := &git.Commit{CommitMessage: git.CommitMessage{MessageRaw: "commit msg 1"}}
|
||||
newest := &git.Commit{CommitMessage: git.CommitMessage{MessageRaw: "commit msg 2\n\nCommit description."}}
|
||||
oldest := &git.Commit{MessageRaw: "commit msg 1"}
|
||||
newest := &git.Commit{MessageRaw: "commit msg 2\n\nCommit description."}
|
||||
|
||||
defer test.MockVariableValue(&setting.Repository.PullRequest.DefaultMergeMessageSize, 0)()
|
||||
|
||||
assert.Equal(t, "* commit msg 1\n\n* commit msg 2\n\nCommit description.\n\n", formatSquashMergeCommitMessages([]*git.Commit{newest, oldest}))
|
||||
|
||||
utf8Msg := &git.Commit{CommitMessage: git.CommitMessage{MessageRaw: "🌞"}}
|
||||
utf8Msg := &git.Commit{MessageRaw: "🌞"}
|
||||
setting.Repository.PullRequest.DefaultMergeMessageSize = 3
|
||||
assert.Equal(t, "* ...\n\n", formatSquashMergeCommitMessages([]*git.Commit{utf8Msg}))
|
||||
setting.Repository.PullRequest.DefaultMergeMessageSize = 4
|
||||
|
||||
@@ -229,10 +229,8 @@ func createCodeComment(ctx context.Context, doer *user_model.User, repo *repo_mo
|
||||
Line: line,
|
||||
TreePath: treePath,
|
||||
Type: issues_model.CommentTypeCode,
|
||||
ListOptions: db.ListOptions{
|
||||
PageSize: 1,
|
||||
Page: 1,
|
||||
},
|
||||
PageSize: 1,
|
||||
Page: 1,
|
||||
})
|
||||
if err == nil && len(first) > 0 {
|
||||
commitID = first[0].CommitSHA
|
||||
|
||||
@@ -265,12 +265,10 @@ func checkUnadoptedRepositories(ctx context.Context, userName string, repoNamesT
|
||||
return err
|
||||
}
|
||||
repos, _, err := repo_model.GetUserRepositories(ctx, repo_model.SearchRepoOptions{
|
||||
Actor: ctxUser,
|
||||
Private: true,
|
||||
ListOptions: db.ListOptions{
|
||||
Page: 1,
|
||||
PageSize: len(repoNamesToCheck),
|
||||
}, LowerNames: repoNamesToCheck,
|
||||
Actor: ctxUser,
|
||||
Private: true,
|
||||
Page: 1,
|
||||
PageSize: len(repoNamesToCheck), LowerNames: repoNamesToCheck,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -318,10 +318,8 @@ func DeleteOldRepositoryArchives(ctx context.Context, olderThan time.Duration) e
|
||||
|
||||
for {
|
||||
archivers, err := db.Find[repo_model.RepoArchiver](ctx, repo_model.FindRepoArchiversOption{
|
||||
ListOptions: db.ListOptions{
|
||||
PageSize: 100,
|
||||
Page: 1,
|
||||
},
|
||||
PageSize: 100,
|
||||
Page: 1,
|
||||
OlderThan: olderThan,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -65,12 +65,10 @@ func LoadBranches(ctx context.Context, repo *repo_model.Repository, gitRepo *git
|
||||
}
|
||||
|
||||
branchOpts := git_model.FindBranchOptions{
|
||||
RepoID: repo.ID,
|
||||
IsDeletedBranch: isDeletedBranch,
|
||||
ListOptions: db.ListOptions{
|
||||
Page: page,
|
||||
PageSize: pageSize,
|
||||
},
|
||||
RepoID: repo.ID,
|
||||
IsDeletedBranch: isDeletedBranch,
|
||||
Page: page,
|
||||
PageSize: pageSize,
|
||||
Keyword: keyword,
|
||||
ExcludeBranchNames: []string{repo.DefaultBranch},
|
||||
}
|
||||
|
||||
@@ -167,11 +167,9 @@ func getExtendedCommitStats(ctx context.Context, repo *git.Repository, revision
|
||||
|
||||
res := &ExtendedCommitStats{
|
||||
Author: &api.CommitUser{
|
||||
Identity: api.Identity{
|
||||
Name: authorName,
|
||||
Email: authorEmail,
|
||||
},
|
||||
Date: date,
|
||||
Name: authorName,
|
||||
Email: authorEmail,
|
||||
Date: date,
|
||||
},
|
||||
Stats: &commitStats,
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import (
|
||||
actions_module "gitea.dev/modules/actions"
|
||||
"gitea.dev/modules/git"
|
||||
"gitea.dev/modules/graceful"
|
||||
"gitea.dev/modules/lfs"
|
||||
"gitea.dev/modules/log"
|
||||
"gitea.dev/modules/storage"
|
||||
actions_service "gitea.dev/services/actions"
|
||||
@@ -241,7 +240,7 @@ func DeleteRepositoryDirectly(ctx context.Context, repoID int64, ignoreOrgTeams
|
||||
|
||||
lfsPaths := make([]string, 0, len(lfsObjects))
|
||||
for _, v := range lfsObjects {
|
||||
count, err := db.CountByBean(ctx, &git_model.LFSMetaObject{Pointer: lfs.Pointer{Oid: v.Oid}})
|
||||
count, err := db.CountByBean(ctx, &git_model.LFSMetaObject{Oid: v.Oid})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -389,13 +388,11 @@ func DeleteRepositoryDirectly(ctx context.Context, repoID int64, ignoreOrgTeams
|
||||
func DeleteOwnerRepositoriesDirectly(ctx context.Context, owner *user_model.User) error {
|
||||
for {
|
||||
repos, _, err := repo_model.GetUserRepositories(ctx, repo_model.SearchRepoOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
PageSize: repo_model.RepositoryListDefaultPageSize,
|
||||
Page: 1,
|
||||
},
|
||||
Private: true,
|
||||
OwnerID: owner.ID,
|
||||
Actor: owner,
|
||||
PageSize: repo_model.RepositoryListDefaultPageSize,
|
||||
Page: 1,
|
||||
Private: true,
|
||||
OwnerID: owner.ID,
|
||||
Actor: owner,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetUserRepositories: %w", err)
|
||||
|
||||
@@ -91,24 +91,18 @@ func GetFileCommitResponse(ctx context.Context, repo *repo_model.Repository, git
|
||||
}
|
||||
commitHTMLURL, _ := url.Parse(repo.HTMLURL() + "/commit/" + url.PathEscape(commit.ID.String()))
|
||||
fileCommit := &api.FileCommitResponse{
|
||||
CommitMeta: api.CommitMeta{
|
||||
SHA: commit.ID.String(),
|
||||
URL: commitURL.String(),
|
||||
},
|
||||
SHA: commit.ID.String(),
|
||||
URL: commitURL.String(),
|
||||
HTMLURL: commitHTMLURL.String(),
|
||||
Author: &api.CommitUser{
|
||||
Identity: api.Identity{
|
||||
Name: commit.Author.Name,
|
||||
Email: commit.Author.Email,
|
||||
},
|
||||
Date: commit.Author.When.UTC().Format(time.RFC3339),
|
||||
Name: commit.Author.Name,
|
||||
Email: commit.Author.Email,
|
||||
Date: commit.Author.When.UTC().Format(time.RFC3339),
|
||||
},
|
||||
Committer: &api.CommitUser{
|
||||
Identity: api.Identity{
|
||||
Name: commit.Committer.Name,
|
||||
Email: commit.Committer.Email,
|
||||
},
|
||||
Date: commit.Committer.When.UTC().Format(time.RFC3339),
|
||||
Name: commit.Committer.Name,
|
||||
Email: commit.Committer.Email,
|
||||
Date: commit.Committer.When.UTC().Format(time.RFC3339),
|
||||
},
|
||||
Message: commit.MessageUTF8(),
|
||||
Tree: &api.CommitMeta{
|
||||
|
||||
+8
-16
@@ -134,10 +134,8 @@ func BlockUser(ctx context.Context, doer, blocker, blockee *user_model.User, not
|
||||
|
||||
func unstarRepos(ctx context.Context, starrer, repoOwner *user_model.User) error {
|
||||
opts := &repo_model.StarredReposOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
Page: 1,
|
||||
PageSize: 25,
|
||||
},
|
||||
Page: 1,
|
||||
PageSize: 25,
|
||||
StarrerID: starrer.ID,
|
||||
RepoOwnerID: repoOwner.ID,
|
||||
}
|
||||
@@ -164,10 +162,8 @@ func unstarRepos(ctx context.Context, starrer, repoOwner *user_model.User) error
|
||||
|
||||
func unwatchRepos(ctx context.Context, watcher, repoOwner *user_model.User) error {
|
||||
opts := &repo_model.WatchedReposOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
Page: 1,
|
||||
PageSize: 25,
|
||||
},
|
||||
Page: 1,
|
||||
PageSize: 25,
|
||||
WatcherID: watcher.ID,
|
||||
RepoOwnerID: repoOwner.ID,
|
||||
}
|
||||
@@ -212,10 +208,8 @@ func cancelRepositoryTransfers(ctx context.Context, doer, sender, recipient *use
|
||||
|
||||
func unassignIssues(ctx context.Context, assignee, repoOwner *user_model.User) error {
|
||||
opts := &issues_model.AssignedIssuesOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
Page: 1,
|
||||
PageSize: 25,
|
||||
},
|
||||
Page: 1,
|
||||
PageSize: 25,
|
||||
AssigneeID: assignee.ID,
|
||||
RepoOwnerID: repoOwner.ID,
|
||||
}
|
||||
@@ -246,10 +240,8 @@ func unassignIssues(ctx context.Context, assignee, repoOwner *user_model.User) e
|
||||
|
||||
func removeCollaborations(ctx context.Context, repoOwner, collaborator *user_model.User) error {
|
||||
opts := &repo_model.FindCollaborationOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
Page: 1,
|
||||
PageSize: 25,
|
||||
},
|
||||
Page: 1,
|
||||
PageSize: 25,
|
||||
CollaboratorID: collaborator.ID,
|
||||
RepoOwnerID: repoOwner.ID,
|
||||
}
|
||||
|
||||
@@ -171,10 +171,8 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) error {
|
||||
// but such a function would likely get out of date
|
||||
for {
|
||||
orgs, err := db.Find[organization.Organization](ctx, organization.FindOrgOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
PageSize: repo_model.RepositoryListDefaultPageSize,
|
||||
Page: 1,
|
||||
},
|
||||
PageSize: repo_model.RepositoryListDefaultPageSize,
|
||||
Page: 1,
|
||||
UserID: u.ID,
|
||||
IncludeVisibility: structs.VisibleTypePrivate,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user