mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-21 03:23:26 +02:00
Merge remote-tracking branch 'upstream/main' into limit-repo-size
Resolved Conflicts: models/migrations/migrations.go services/forms/repo_form.go templates/admin/repo/list.tmpl templates/repo/settings/options.tmpl
This commit is contained in:
@@ -5,6 +5,7 @@ package activitypub
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/rsa"
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
@@ -61,14 +62,14 @@ type Client struct {
|
||||
}
|
||||
|
||||
// NewClient function
|
||||
func NewClient(user *user_model.User, pubID string) (c *Client, err error) {
|
||||
func NewClient(ctx context.Context, user *user_model.User, pubID string) (c *Client, err error) {
|
||||
if err = containsRequiredHTTPHeaders(http.MethodGet, setting.Federation.GetHeaders); err != nil {
|
||||
return nil, err
|
||||
} else if err = containsRequiredHTTPHeaders(http.MethodPost, setting.Federation.PostHeaders); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
priv, err := GetPrivateKey(user)
|
||||
priv, err := GetPrivateKey(ctx, user)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
@@ -22,7 +23,7 @@ func TestActivityPubSignedPost(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
||||
pubID := "https://example.com/pubID"
|
||||
c, err := NewClient(user, pubID)
|
||||
c, err := NewClient(db.DefaultContext, user, pubID)
|
||||
assert.NoError(t, err)
|
||||
|
||||
expected := "BODY"
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
package activitypub
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
@@ -15,7 +14,5 @@ import (
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m, &unittest.TestOptions{
|
||||
GiteaRootPath: filepath.Join("..", ".."),
|
||||
})
|
||||
unittest.MainTest(m)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
package activitypub
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
)
|
||||
@@ -11,19 +13,19 @@ import (
|
||||
const rsaBits = 3072
|
||||
|
||||
// GetKeyPair function returns a user's private and public keys
|
||||
func GetKeyPair(user *user_model.User) (pub, priv string, err error) {
|
||||
func GetKeyPair(ctx context.Context, user *user_model.User) (pub, priv string, err error) {
|
||||
var settings map[string]*user_model.Setting
|
||||
settings, err = user_model.GetSettings(user.ID, []string{user_model.UserActivityPubPrivPem, user_model.UserActivityPubPubPem})
|
||||
settings, err = user_model.GetSettings(ctx, user.ID, []string{user_model.UserActivityPubPrivPem, user_model.UserActivityPubPubPem})
|
||||
if err != nil {
|
||||
return pub, priv, err
|
||||
} else if len(settings) == 0 {
|
||||
if priv, pub, err = util.GenerateKeyPair(rsaBits); err != nil {
|
||||
return pub, priv, err
|
||||
}
|
||||
if err = user_model.SetUserSetting(user.ID, user_model.UserActivityPubPrivPem, priv); err != nil {
|
||||
if err = user_model.SetUserSetting(ctx, user.ID, user_model.UserActivityPubPrivPem, priv); err != nil {
|
||||
return pub, priv, err
|
||||
}
|
||||
if err = user_model.SetUserSetting(user.ID, user_model.UserActivityPubPubPem, pub); err != nil {
|
||||
if err = user_model.SetUserSetting(ctx, user.ID, user_model.UserActivityPubPubPem, pub); err != nil {
|
||||
return pub, priv, err
|
||||
}
|
||||
return pub, priv, err
|
||||
@@ -35,13 +37,13 @@ func GetKeyPair(user *user_model.User) (pub, priv string, err error) {
|
||||
}
|
||||
|
||||
// GetPublicKey function returns a user's public key
|
||||
func GetPublicKey(user *user_model.User) (pub string, err error) {
|
||||
pub, _, err = GetKeyPair(user)
|
||||
func GetPublicKey(ctx context.Context, user *user_model.User) (pub string, err error) {
|
||||
pub, _, err = GetKeyPair(ctx, user)
|
||||
return pub, err
|
||||
}
|
||||
|
||||
// GetPrivateKey function returns a user's private key
|
||||
func GetPrivateKey(user *user_model.User) (priv string, err error) {
|
||||
_, priv, err = GetKeyPair(user)
|
||||
func GetPrivateKey(ctx context.Context, user *user_model.User) (priv string, err error) {
|
||||
_, priv, err = GetKeyPair(ctx, user)
|
||||
return priv, err
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ package activitypub
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
|
||||
@@ -17,12 +18,12 @@ import (
|
||||
func TestUserSettings(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
||||
pub, priv, err := GetKeyPair(user1)
|
||||
pub, priv, err := GetKeyPair(db.DefaultContext, user1)
|
||||
assert.NoError(t, err)
|
||||
pub1, err := GetPublicKey(user1)
|
||||
pub1, err := GetPublicKey(db.DefaultContext, user1)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, pub, pub1)
|
||||
priv1, err := GetPrivateKey(user1)
|
||||
priv1, err := GetPrivateKey(db.DefaultContext, user1)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, priv, priv1)
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ func (u *User) WebAuthnIcon() string {
|
||||
|
||||
// WebAuthnCredentials implementns the webauthn.User interface
|
||||
func (u *User) WebAuthnCredentials() []webauthn.Credential {
|
||||
dbCreds, err := auth.GetWebAuthnCredentialsByUID(u.ID)
|
||||
dbCreds, err := auth.GetWebAuthnCredentialsByUID(db.DefaultContext, u.ID)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -101,6 +101,12 @@ type APIRedirect struct{}
|
||||
// swagger:response string
|
||||
type APIString string
|
||||
|
||||
// APIRepoArchivedError is an error that is raised when an archived repo should be modified
|
||||
// swagger:response repoArchivedError
|
||||
type APIRepoArchivedError struct {
|
||||
APIError
|
||||
}
|
||||
|
||||
// ServerError responds with error message, status is 500
|
||||
func (ctx *APIContext) ServerError(title string, err error) {
|
||||
ctx.Error(http.StatusInternalServerError, title, err)
|
||||
@@ -212,7 +218,7 @@ func (ctx *APIContext) CheckForOTP() {
|
||||
}
|
||||
|
||||
otpHeader := ctx.Req.Header.Get("X-Gitea-OTP")
|
||||
twofa, err := auth.GetTwoFactorByUID(ctx.Doer.ID)
|
||||
twofa, err := auth.GetTwoFactorByUID(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
if auth.IsErrTwoFactorNotEnrolled(err) {
|
||||
return // No 2FA enrollment for this user
|
||||
|
||||
@@ -46,7 +46,7 @@ func GetOrganizationByParams(ctx *Context) {
|
||||
ctx.Org.Organization, err = organization.GetOrgByName(ctx, orgName)
|
||||
if err != nil {
|
||||
if organization.IsErrOrgNotExist(err) {
|
||||
redirectUserID, err := user_model.LookupUserRedirect(orgName)
|
||||
redirectUserID, err := user_model.LookupUserRedirect(ctx, orgName)
|
||||
if err == nil {
|
||||
RedirectToUser(ctx.Base, orgName, redirectUserID)
|
||||
} else if user_model.IsErrUserRedirectNotExist(err) {
|
||||
@@ -128,7 +128,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
|
||||
ctx.Org.IsTeamAdmin = true
|
||||
ctx.Org.CanCreateOrgRepo = true
|
||||
} else if ctx.IsSigned {
|
||||
ctx.Org.IsOwner, err = org.IsOwnedBy(ctx.Doer.ID)
|
||||
ctx.Org.IsOwner, err = org.IsOwnedBy(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("IsOwnedBy", err)
|
||||
return
|
||||
@@ -140,12 +140,12 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
|
||||
ctx.Org.IsTeamAdmin = true
|
||||
ctx.Org.CanCreateOrgRepo = true
|
||||
} else {
|
||||
ctx.Org.IsMember, err = org.IsOrgMember(ctx.Doer.ID)
|
||||
ctx.Org.IsMember, err = org.IsOrgMember(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("IsOrgMember", err)
|
||||
return
|
||||
}
|
||||
ctx.Org.CanCreateOrgRepo, err = org.CanCreateOrgRepo(ctx.Doer.ID)
|
||||
ctx.Org.CanCreateOrgRepo, err = org.CanCreateOrgRepo(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("CanCreateOrgRepo", err)
|
||||
return
|
||||
@@ -165,7 +165,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
|
||||
ctx.Data["IsPackageEnabled"] = setting.Packages.Enabled
|
||||
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
|
||||
ctx.Data["IsPublicMember"] = func(uid int64) bool {
|
||||
is, _ := organization.IsPublicMembership(ctx.Org.Organization.ID, uid)
|
||||
is, _ := organization.IsPublicMembership(ctx, ctx.Org.Organization.ID, uid)
|
||||
return is
|
||||
}
|
||||
ctx.Data["CanCreateOrgRepo"] = ctx.Org.CanCreateOrgRepo
|
||||
@@ -179,7 +179,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
|
||||
OrgID: org.ID,
|
||||
PublicOnly: ctx.Org.PublicMemberOnly,
|
||||
}
|
||||
ctx.Data["NumMembers"], err = organization.CountOrgMembers(opts)
|
||||
ctx.Data["NumMembers"], err = organization.CountOrgMembers(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.ServerError("CountOrgMembers", err)
|
||||
return
|
||||
@@ -191,7 +191,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
|
||||
if ctx.Org.IsOwner {
|
||||
shouldSeeAllTeams = true
|
||||
} else {
|
||||
teams, err := org.GetUserTeams(ctx.Doer.ID)
|
||||
teams, err := org.GetUserTeams(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetUserTeams", err)
|
||||
return
|
||||
@@ -204,13 +204,13 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
|
||||
}
|
||||
}
|
||||
if shouldSeeAllTeams {
|
||||
ctx.Org.Teams, err = org.LoadTeams()
|
||||
ctx.Org.Teams, err = org.LoadTeams(ctx)
|
||||
if err != nil {
|
||||
ctx.ServerError("LoadTeams", err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
ctx.Org.Teams, err = org.GetUserTeams(ctx.Doer.ID)
|
||||
ctx.Org.Teams, err = org.GetUserTeams(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetUserTeams", err)
|
||||
return
|
||||
|
||||
@@ -109,7 +109,7 @@ func determineAccessMode(ctx *Base, pkg *Package, doer *user_model.User) (perm.A
|
||||
if doer != nil && !doer.IsGhost() {
|
||||
// 1. If user is logged in, check all team packages permissions
|
||||
var err error
|
||||
accessMode, err = org.GetOrgUserMaxAuthorizeLevel(doer.ID)
|
||||
accessMode, err = org.GetOrgUserMaxAuthorizeLevel(ctx, doer.ID)
|
||||
if err != nil {
|
||||
return accessMode, err
|
||||
}
|
||||
|
||||
+29
-6
@@ -456,7 +456,7 @@ func RepoAssignment(ctx *Context) context.CancelFunc {
|
||||
return nil
|
||||
}
|
||||
|
||||
if redirectUserID, err := user_model.LookupUserRedirect(userName); err == nil {
|
||||
if redirectUserID, err := user_model.LookupUserRedirect(ctx, userName); err == nil {
|
||||
RedirectToUser(ctx.Base, userName, redirectUserID)
|
||||
} else if user_model.IsErrUserRedirectNotExist(err) {
|
||||
ctx.NotFound("GetUserByName", nil)
|
||||
@@ -545,7 +545,10 @@ func RepoAssignment(ctx *Context) context.CancelFunc {
|
||||
ctx.ServerError("GetReleaseCountByRepoID", err)
|
||||
return nil
|
||||
}
|
||||
ctx.Data["NumReleases"], err = repo_model.GetReleaseCountByRepoID(ctx, ctx.Repo.Repository.ID, repo_model.FindReleasesOptions{})
|
||||
ctx.Data["NumReleases"], err = repo_model.GetReleaseCountByRepoID(ctx, ctx.Repo.Repository.ID, repo_model.FindReleasesOptions{
|
||||
// only show draft releases for users who can write, read-only users shouldn't see draft releases.
|
||||
IncludeDrafts: ctx.Repo.CanWrite(unit_model.TypeReleases),
|
||||
})
|
||||
if err != nil {
|
||||
ctx.ServerError("GetReleaseCountByRepoID", err)
|
||||
return nil
|
||||
@@ -561,7 +564,7 @@ func RepoAssignment(ctx *Context) context.CancelFunc {
|
||||
ctx.Data["CanWriteIssues"] = ctx.Repo.CanWrite(unit_model.TypeIssues)
|
||||
ctx.Data["CanWritePulls"] = ctx.Repo.CanWrite(unit_model.TypePullRequests)
|
||||
|
||||
canSignedUserFork, err := repo_module.CanUserForkRepo(ctx.Doer, ctx.Repo.Repository)
|
||||
canSignedUserFork, err := repo_module.CanUserForkRepo(ctx, ctx.Doer, ctx.Repo.Repository)
|
||||
if err != nil {
|
||||
ctx.ServerError("CanUserForkRepo", err)
|
||||
return nil
|
||||
@@ -598,7 +601,7 @@ func RepoAssignment(ctx *Context) context.CancelFunc {
|
||||
}
|
||||
|
||||
if ctx.IsSigned {
|
||||
ctx.Data["IsWatchingRepo"] = repo_model.IsWatching(ctx.Doer.ID, repo.ID)
|
||||
ctx.Data["IsWatchingRepo"] = repo_model.IsWatching(ctx, ctx.Doer.ID, repo.ID)
|
||||
ctx.Data["IsStaringRepo"] = repo_model.IsStaring(ctx, ctx.Doer.ID, repo.ID)
|
||||
}
|
||||
|
||||
@@ -703,7 +706,7 @@ func RepoAssignment(ctx *Context) context.CancelFunc {
|
||||
|
||||
// People who have push access or have forked repository can propose a new pull request.
|
||||
canPush := ctx.Repo.CanWrite(unit_model.TypeCode) ||
|
||||
(ctx.IsSigned && repo_model.HasForkedRepo(ctx.Doer.ID, ctx.Repo.Repository.ID))
|
||||
(ctx.IsSigned && repo_model.HasForkedRepo(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID))
|
||||
canCompare := false
|
||||
|
||||
// Pull request is allowed if this is a fork repository
|
||||
@@ -740,7 +743,7 @@ func RepoAssignment(ctx *Context) context.CancelFunc {
|
||||
|
||||
ctx.Data["RepoTransfer"] = repoTransfer
|
||||
if ctx.Doer != nil {
|
||||
ctx.Data["CanUserAcceptTransfer"] = repoTransfer.CanUserAcceptTransfer(ctx.Doer)
|
||||
ctx.Data["CanUserAcceptTransfer"] = repoTransfer.CanUserAcceptTransfer(ctx, ctx.Doer)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -773,6 +776,8 @@ const (
|
||||
RepoRefBlob
|
||||
)
|
||||
|
||||
const headRefName = "HEAD"
|
||||
|
||||
// RepoRef handles repository reference names when the ref name is not
|
||||
// explicitly given
|
||||
func RepoRef() func(*Context) context.CancelFunc {
|
||||
@@ -833,6 +838,14 @@ func getRefName(ctx *Base, repo *Repository, pathType RepoRefType) string {
|
||||
case RepoRefBranch:
|
||||
ref := getRefNameFromPath(ctx, repo, path, repo.GitRepo.IsBranchExist)
|
||||
if len(ref) == 0 {
|
||||
|
||||
// check if ref is HEAD
|
||||
parts := strings.Split(path, "/")
|
||||
if parts[0] == headRefName {
|
||||
repo.TreePath = strings.Join(parts[1:], "/")
|
||||
return repo.Repository.DefaultBranch
|
||||
}
|
||||
|
||||
// maybe it's a renamed branch
|
||||
return getRefNameFromPath(ctx, repo, path, func(s string) bool {
|
||||
b, exist, err := git_model.FindRenamedBranch(ctx, repo.Repository.ID, s)
|
||||
@@ -861,6 +874,16 @@ func getRefName(ctx *Base, repo *Repository, pathType RepoRefType) string {
|
||||
repo.TreePath = strings.Join(parts[1:], "/")
|
||||
return parts[0]
|
||||
}
|
||||
|
||||
if len(parts) > 0 && parts[0] == headRefName {
|
||||
// HEAD ref points to last default branch commit
|
||||
commit, err := repo.GitRepo.GetBranchCommit(repo.Repository.DefaultBranch)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
repo.TreePath = strings.Join(parts[1:], "/")
|
||||
return commit.ID.String()
|
||||
}
|
||||
case RepoRefBlob:
|
||||
_, err := repo.GitRepo.GetBlob(path)
|
||||
if err != nil {
|
||||
|
||||
@@ -33,7 +33,7 @@ func checkAuthorizedKeys(ctx context.Context, logger log.Logger, autofix bool) e
|
||||
return fmt.Errorf("Unable to open authorized_keys file. ERROR: %w", err)
|
||||
}
|
||||
logger.Warn("Unable to open authorized_keys. (ERROR: %v). Attempting to rewrite...", err)
|
||||
if err = asymkey_model.RewriteAllPublicKeys(); err != nil {
|
||||
if err = asymkey_model.RewriteAllPublicKeys(ctx); err != nil {
|
||||
logger.Critical("Unable to rewrite authorized_keys file. ERROR: %v", err)
|
||||
return fmt.Errorf("Unable to rewrite authorized_keys file. ERROR: %w", err)
|
||||
}
|
||||
@@ -76,7 +76,7 @@ func checkAuthorizedKeys(ctx context.Context, logger log.Logger, autofix bool) e
|
||||
return fmt.Errorf(`authorized_keys is out of date and should be regenerated with "gitea admin regenerate keys" or "gitea doctor --run authorized-keys --fix"`)
|
||||
}
|
||||
logger.Warn("authorized_keys is out of date. Attempting rewrite...")
|
||||
err = asymkey_model.RewriteAllPublicKeys()
|
||||
err = asymkey_model.RewriteAllPublicKeys(ctx)
|
||||
if err != nil {
|
||||
logger.Critical("Unable to rewrite authorized_keys file. ERROR: %v", err)
|
||||
return fmt.Errorf("Unable to rewrite authorized_keys file. ERROR: %w", err)
|
||||
|
||||
@@ -101,7 +101,7 @@ func checkDBConsistency(ctx context.Context, logger log.Logger, autofix bool) er
|
||||
},
|
||||
// find releases without existing repository
|
||||
genericOrphanCheck("Orphaned Releases without existing repository",
|
||||
"release", "repository", "release.repo_id=repository.id"),
|
||||
"release", "repository", "`release`.repo_id=repository.id"),
|
||||
// find pulls without existing issues
|
||||
genericOrphanCheck("Orphaned PullRequests without existing issue",
|
||||
"pull_request", "issue", "pull_request.issue_id=issue.id"),
|
||||
@@ -168,9 +168,9 @@ func checkDBConsistency(ctx context.Context, logger log.Logger, autofix bool) er
|
||||
// find protected branches without existing repository
|
||||
genericOrphanCheck("Protected Branches without existing repository",
|
||||
"protected_branch", "repository", "protected_branch.repo_id=repository.id"),
|
||||
// find deleted branches without existing repository
|
||||
genericOrphanCheck("Deleted Branches without existing repository",
|
||||
"deleted_branch", "repository", "deleted_branch.repo_id=repository.id"),
|
||||
// find branches without existing repository
|
||||
genericOrphanCheck("Branches without existing repository",
|
||||
"branch", "repository", "branch.repo_id=repository.id"),
|
||||
// find LFS locks without existing repository
|
||||
genericOrphanCheck("LFS locks without existing repository",
|
||||
"lfs_lock", "repository", "lfs_lock.repo_id=repository.id"),
|
||||
@@ -189,6 +189,9 @@ func checkDBConsistency(ctx context.Context, logger log.Logger, autofix bool) er
|
||||
// find action without repository
|
||||
genericOrphanCheck("Action entries without existing repository",
|
||||
"action", "repository", "action.repo_id=repository.id"),
|
||||
// find action without user
|
||||
genericOrphanCheck("Action entries without existing user",
|
||||
"action", "user", "action.act_user_id=`user`.id"),
|
||||
// find OAuth2Grant without existing user
|
||||
genericOrphanCheck("Orphaned OAuth2Grant without existing User",
|
||||
"oauth2_grant", "user", "oauth2_grant.user_id=`user`.id"),
|
||||
|
||||
@@ -290,7 +290,7 @@ func fixBrokenRepoUnits16961(ctx context.Context, logger log.Logger, autofix boo
|
||||
return nil
|
||||
}
|
||||
|
||||
return repo_model.UpdateRepoUnit(repoUnit)
|
||||
return repo_model.UpdateRepoUnit(ctx, repoUnit)
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
|
||||
@@ -29,7 +29,7 @@ func fixOwnerTeamCreateOrgRepo(ctx context.Context, logger log.Logger, autofix b
|
||||
return nil
|
||||
}
|
||||
|
||||
return models.UpdateTeam(team, false, false)
|
||||
return models.UpdateTeam(ctx, team, false, false)
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
|
||||
@@ -11,14 +11,14 @@ import (
|
||||
)
|
||||
|
||||
func checkUserType(ctx context.Context, logger log.Logger, autofix bool) error {
|
||||
count, err := user_model.CountWrongUserType()
|
||||
count, err := user_model.CountWrongUserType(ctx)
|
||||
if err != nil {
|
||||
logger.Critical("Error: %v whilst counting wrong user types")
|
||||
return err
|
||||
}
|
||||
if count > 0 {
|
||||
if autofix {
|
||||
if count, err = user_model.FixWrongUserType(); err != nil {
|
||||
if count, err = user_model.FixWrongUserType(ctx); err != nil {
|
||||
logger.Critical("Error: %v whilst fixing wrong user types")
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ loop:
|
||||
|
||||
now := timeutil.TimeStampNow().Add(-2)
|
||||
|
||||
uidCounts, err := activities_model.GetUIDsAndNotificationCounts(then, now)
|
||||
uidCounts, err := activities_model.GetUIDsAndNotificationCounts(ctx, then, now)
|
||||
if err != nil {
|
||||
log.Error("Unable to get UIDcounts: %v", err)
|
||||
}
|
||||
@@ -84,7 +84,7 @@ loop:
|
||||
then = now
|
||||
|
||||
if setting.Service.EnableTimetracking {
|
||||
usersStopwatches, err := issues_model.GetUIDsAndStopwatch()
|
||||
usersStopwatches, err := issues_model.GetUIDsAndStopwatch(ctx)
|
||||
if err != nil {
|
||||
log.Error("Unable to get GetUIDsAndStopwatch: %v", err)
|
||||
return
|
||||
|
||||
+56
-8
@@ -13,6 +13,7 @@ import (
|
||||
"regexp"
|
||||
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
)
|
||||
|
||||
// BlamePart represents block of blame - continuous lines with one sha
|
||||
@@ -23,12 +24,16 @@ type BlamePart struct {
|
||||
|
||||
// BlameReader returns part of file blame one by one
|
||||
type BlameReader struct {
|
||||
cmd *Command
|
||||
output io.WriteCloser
|
||||
reader io.ReadCloser
|
||||
bufferedReader *bufio.Reader
|
||||
done chan error
|
||||
lastSha *string
|
||||
ignoreRevsFile *string
|
||||
}
|
||||
|
||||
func (r *BlameReader) UsesIgnoreRevs() bool {
|
||||
return r.ignoreRevsFile != nil
|
||||
}
|
||||
|
||||
var shaLineRegex = regexp.MustCompile("^([a-z0-9]{40})")
|
||||
@@ -101,28 +106,44 @@ func (r *BlameReader) Close() error {
|
||||
r.bufferedReader = nil
|
||||
_ = r.reader.Close()
|
||||
_ = r.output.Close()
|
||||
if r.ignoreRevsFile != nil {
|
||||
_ = util.Remove(*r.ignoreRevsFile)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// CreateBlameReader creates reader for given repository, commit and file
|
||||
func CreateBlameReader(ctx context.Context, repoPath, commitID, file string) (*BlameReader, error) {
|
||||
cmd := NewCommandContextNoGlobals(ctx, "blame", "--porcelain").
|
||||
AddDynamicArguments(commitID).
|
||||
func CreateBlameReader(ctx context.Context, repoPath string, commit *Commit, file string, bypassBlameIgnore bool) (*BlameReader, error) {
|
||||
var ignoreRevsFile *string
|
||||
if CheckGitVersionAtLeast("2.23") == nil && !bypassBlameIgnore {
|
||||
ignoreRevsFile = tryCreateBlameIgnoreRevsFile(commit)
|
||||
}
|
||||
|
||||
cmd := NewCommandContextNoGlobals(ctx, "blame", "--porcelain")
|
||||
if ignoreRevsFile != nil {
|
||||
// Possible improvement: use --ignore-revs-file /dev/stdin on unix
|
||||
// There is no equivalent on Windows. May be implemented if Gitea uses an external git backend.
|
||||
cmd.AddOptionValues("--ignore-revs-file", *ignoreRevsFile)
|
||||
}
|
||||
cmd.AddDynamicArguments(commit.ID.String()).
|
||||
AddDashesAndList(file).
|
||||
SetDescription(fmt.Sprintf("GetBlame [repo_path: %s]", repoPath))
|
||||
reader, stdout, err := os.Pipe()
|
||||
if err != nil {
|
||||
if ignoreRevsFile != nil {
|
||||
_ = util.Remove(*ignoreRevsFile)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
done := make(chan error, 1)
|
||||
|
||||
go func(cmd *Command, dir string, stdout io.WriteCloser, done chan error) {
|
||||
go func() {
|
||||
stderr := bytes.Buffer{}
|
||||
// TODO: it doesn't work for directories (the directories shouldn't be "blamed"), and the "err" should be returned by "Read" but not by "Close"
|
||||
err := cmd.Run(&RunOpts{
|
||||
UseContextTimeout: true,
|
||||
Dir: dir,
|
||||
Dir: repoPath,
|
||||
Stdout: stdout,
|
||||
Stderr: &stderr,
|
||||
})
|
||||
@@ -131,15 +152,42 @@ func CreateBlameReader(ctx context.Context, repoPath, commitID, file string) (*B
|
||||
if err != nil {
|
||||
log.Error("Error running git blame (dir: %v): %v, stderr: %v", repoPath, err, stderr.String())
|
||||
}
|
||||
}(cmd, repoPath, stdout, done)
|
||||
}()
|
||||
|
||||
bufferedReader := bufio.NewReader(reader)
|
||||
|
||||
return &BlameReader{
|
||||
cmd: cmd,
|
||||
output: stdout,
|
||||
reader: reader,
|
||||
bufferedReader: bufferedReader,
|
||||
done: done,
|
||||
ignoreRevsFile: ignoreRevsFile,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func tryCreateBlameIgnoreRevsFile(commit *Commit) *string {
|
||||
entry, err := commit.GetTreeEntryByPath(".git-blame-ignore-revs")
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
r, err := entry.Blob().DataAsync()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
defer r.Close()
|
||||
|
||||
f, err := os.CreateTemp("", "gitea_git-blame-ignore-revs")
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err = io.Copy(f, r)
|
||||
_ = f.Close()
|
||||
if err != nil {
|
||||
_ = util.Remove(f.Name())
|
||||
return nil
|
||||
}
|
||||
|
||||
return util.ToPointer(f.Name())
|
||||
}
|
||||
|
||||
+122
-22
@@ -14,27 +14,127 @@ func TestReadingBlameOutput(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
blameReader, err := CreateBlameReader(ctx, "./tests/repos/repo5_pulls", "f32b0a9dfd09a60f616f29158f772cedd89942d2", "README.md")
|
||||
assert.NoError(t, err)
|
||||
defer blameReader.Close()
|
||||
|
||||
parts := []*BlamePart{
|
||||
{
|
||||
"72866af952e98d02a73003501836074b286a78f6",
|
||||
[]string{
|
||||
"# test_repo",
|
||||
"Test repository for testing migration from github to gitea",
|
||||
},
|
||||
},
|
||||
{
|
||||
"f32b0a9dfd09a60f616f29158f772cedd89942d2",
|
||||
[]string{"", "Do not make any changes to this repo it is used for unit testing"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, part := range parts {
|
||||
actualPart, err := blameReader.NextPart()
|
||||
t.Run("Without .git-blame-ignore-revs", func(t *testing.T) {
|
||||
repo, err := OpenRepository(ctx, "./tests/repos/repo5_pulls")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, part, actualPart)
|
||||
}
|
||||
defer repo.Close()
|
||||
|
||||
commit, err := repo.GetCommit("f32b0a9dfd09a60f616f29158f772cedd89942d2")
|
||||
assert.NoError(t, err)
|
||||
|
||||
parts := []*BlamePart{
|
||||
{
|
||||
"72866af952e98d02a73003501836074b286a78f6",
|
||||
[]string{
|
||||
"# test_repo",
|
||||
"Test repository for testing migration from github to gitea",
|
||||
},
|
||||
},
|
||||
{
|
||||
"f32b0a9dfd09a60f616f29158f772cedd89942d2",
|
||||
[]string{"", "Do not make any changes to this repo it is used for unit testing"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, bypass := range []bool{false, true} {
|
||||
blameReader, err := CreateBlameReader(ctx, "./tests/repos/repo5_pulls", commit, "README.md", bypass)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, blameReader)
|
||||
defer blameReader.Close()
|
||||
|
||||
assert.False(t, blameReader.UsesIgnoreRevs())
|
||||
|
||||
for _, part := range parts {
|
||||
actualPart, err := blameReader.NextPart()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, part, actualPart)
|
||||
}
|
||||
|
||||
// make sure all parts have been read
|
||||
actualPart, err := blameReader.NextPart()
|
||||
assert.Nil(t, actualPart)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("With .git-blame-ignore-revs", func(t *testing.T) {
|
||||
repo, err := OpenRepository(ctx, "./tests/repos/repo6_blame")
|
||||
assert.NoError(t, err)
|
||||
defer repo.Close()
|
||||
|
||||
full := []*BlamePart{
|
||||
{
|
||||
"af7486bd54cfc39eea97207ca666aa69c9d6df93",
|
||||
[]string{"line", "line"},
|
||||
},
|
||||
{
|
||||
"45fb6cbc12f970b04eacd5cd4165edd11c8d7376",
|
||||
[]string{"changed line"},
|
||||
},
|
||||
{
|
||||
"af7486bd54cfc39eea97207ca666aa69c9d6df93",
|
||||
[]string{"line", "line", ""},
|
||||
},
|
||||
}
|
||||
|
||||
cases := []struct {
|
||||
CommitID string
|
||||
UsesIgnoreRevs bool
|
||||
Bypass bool
|
||||
Parts []*BlamePart
|
||||
}{
|
||||
{
|
||||
CommitID: "544d8f7a3b15927cddf2299b4b562d6ebd71b6a7",
|
||||
UsesIgnoreRevs: true,
|
||||
Bypass: false,
|
||||
Parts: []*BlamePart{
|
||||
{
|
||||
"af7486bd54cfc39eea97207ca666aa69c9d6df93",
|
||||
[]string{"line", "line", "changed line", "line", "line", ""},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
CommitID: "544d8f7a3b15927cddf2299b4b562d6ebd71b6a7",
|
||||
UsesIgnoreRevs: false,
|
||||
Bypass: true,
|
||||
Parts: full,
|
||||
},
|
||||
{
|
||||
CommitID: "45fb6cbc12f970b04eacd5cd4165edd11c8d7376",
|
||||
UsesIgnoreRevs: false,
|
||||
Bypass: false,
|
||||
Parts: full,
|
||||
},
|
||||
{
|
||||
CommitID: "45fb6cbc12f970b04eacd5cd4165edd11c8d7376",
|
||||
UsesIgnoreRevs: false,
|
||||
Bypass: false,
|
||||
Parts: full,
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
commit, err := repo.GetCommit(c.CommitID)
|
||||
assert.NoError(t, err)
|
||||
|
||||
blameReader, err := CreateBlameReader(ctx, "./tests/repos/repo6_blame", commit, "blame.txt", c.Bypass)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, blameReader)
|
||||
defer blameReader.Close()
|
||||
|
||||
assert.Equal(t, c.UsesIgnoreRevs, blameReader.UsesIgnoreRevs())
|
||||
|
||||
for _, part := range c.Parts {
|
||||
actualPart, err := blameReader.NextPart()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, part, actualPart)
|
||||
}
|
||||
|
||||
// make sure all parts have been read
|
||||
actualPart, err := blameReader.NextPart()
|
||||
assert.Nil(t, actualPart)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
+2
-1
@@ -86,7 +86,8 @@ func (repo *Repository) IsEmpty() (bool, error) {
|
||||
Stdout: &output,
|
||||
Stderr: &errbuf,
|
||||
}); err != nil {
|
||||
if err.Error() == "exit status 1" && errbuf.String() == "" {
|
||||
if (err.Error() == "exit status 1" && strings.TrimSpace(errbuf.String()) == "") || err.Error() == "exit status 129" {
|
||||
// git 2.11 exits with 129 if the repo is empty
|
||||
return true, nil
|
||||
}
|
||||
return true, fmt.Errorf("check empty: %w - %s", err, errbuf.String())
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
ref: refs/heads/master
|
||||
@@ -0,0 +1,4 @@
|
||||
[core]
|
||||
repositoryformatversion = 0
|
||||
filemode = true
|
||||
bare = true
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
|
||||
544d8f7a3b15927cddf2299b4b562d6ebd71b6a7
|
||||
@@ -116,10 +116,10 @@ func (graph *Graph) LoadAndProcessCommits(ctx context.Context, repository *repo_
|
||||
c.Verification = asymkey_model.ParseCommitWithSignature(ctx, c.Commit)
|
||||
|
||||
_ = asymkey_model.CalculateTrustStatus(c.Verification, repository.GetTrustModel(), func(user *user_model.User) (bool, error) {
|
||||
return repo_model.IsOwnerMemberCollaborator(repository, user.ID)
|
||||
return repo_model.IsOwnerMemberCollaborator(ctx, repository, user.ID)
|
||||
}, &keyMap)
|
||||
|
||||
statuses, _, err := git_model.GetLatestCommitStatus(db.DefaultContext, repository.ID, c.Commit.ID.String(), db.ListOptions{})
|
||||
statuses, _, err := git_model.GetLatestCommitStatus(ctx, repository.ID, c.Commit.ID.String(), db.ListOptions{})
|
||||
if err != nil {
|
||||
log.Error("GetLatestCommitStatus: %v", err)
|
||||
} else {
|
||||
|
||||
@@ -6,7 +6,6 @@ package code
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
@@ -23,9 +22,7 @@ import (
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m, &unittest.TestOptions{
|
||||
GiteaRootPath: filepath.Join("..", "..", ".."),
|
||||
})
|
||||
unittest.MainTest(m)
|
||||
}
|
||||
|
||||
func testIndexer(name string, t *testing.T, indexer internal.Indexer) {
|
||||
|
||||
@@ -97,7 +97,7 @@ func ToDBOptions(ctx context.Context, options *internal.SearchOptions) (*issue_m
|
||||
|
||||
if len(options.IncludedLabelIDs) == 0 && len(options.IncludedAnyLabelIDs) > 0 {
|
||||
_ = ctx // issue_model.GetLabelsByIDs should be called with ctx, this line can be removed when it's done.
|
||||
labels, err := issue_model.GetLabelsByIDs(options.IncludedAnyLabelIDs, "name")
|
||||
labels, err := issue_model.GetLabelsByIDs(ctx, options.IncludedAnyLabelIDs, "name")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("GetLabelsByIDs: %v", err)
|
||||
}
|
||||
|
||||
@@ -5,14 +5,13 @@ package issues
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/indexer/issues/bleve"
|
||||
"code.gitea.io/gitea/modules/indexer/issues/internal"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
_ "code.gitea.io/gitea/models"
|
||||
_ "code.gitea.io/gitea/models/actions"
|
||||
@@ -22,71 +21,7 @@ import (
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m, &unittest.TestOptions{
|
||||
GiteaRootPath: filepath.Join("..", "..", ".."),
|
||||
})
|
||||
}
|
||||
|
||||
func TestBleveSearchIssues(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
setting.CfgProvider, _ = setting.NewConfigProviderFromData("")
|
||||
|
||||
tmpIndexerDir := t.TempDir()
|
||||
|
||||
setting.CfgProvider.Section("queue.issue_indexer").Key("DATADIR").MustString(path.Join(tmpIndexerDir, "issues.queue"))
|
||||
|
||||
oldIssuePath := setting.Indexer.IssuePath
|
||||
setting.Indexer.IssuePath = path.Join(tmpIndexerDir, "issues.queue")
|
||||
defer func() {
|
||||
setting.Indexer.IssuePath = oldIssuePath
|
||||
}()
|
||||
|
||||
setting.Indexer.IssueType = "bleve"
|
||||
setting.LoadQueueSettings()
|
||||
InitIssueIndexer(true)
|
||||
defer func() {
|
||||
if bleveIndexer, ok := (*globalIndexer.Load()).(*bleve.Indexer); ok {
|
||||
bleveIndexer.Close()
|
||||
}
|
||||
}()
|
||||
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
t.Run("issue2", func(t *testing.T) {
|
||||
ids, _, err := SearchIssues(context.TODO(), &SearchOptions{
|
||||
Keyword: "issue2",
|
||||
RepoIDs: []int64{1},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, []int64{2}, ids)
|
||||
})
|
||||
|
||||
t.Run("first", func(t *testing.T) {
|
||||
ids, _, err := SearchIssues(context.TODO(), &SearchOptions{
|
||||
Keyword: "first",
|
||||
RepoIDs: []int64{1},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, []int64{1}, ids)
|
||||
})
|
||||
|
||||
t.Run("for", func(t *testing.T) {
|
||||
ids, _, err := SearchIssues(context.TODO(), &SearchOptions{
|
||||
Keyword: "for",
|
||||
RepoIDs: []int64{1},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.ElementsMatch(t, []int64{1, 2, 3, 5, 11}, ids)
|
||||
})
|
||||
|
||||
t.Run("good", func(t *testing.T) {
|
||||
ids, _, err := SearchIssues(context.TODO(), &SearchOptions{
|
||||
Keyword: "good",
|
||||
RepoIDs: []int64{1},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, []int64{1}, ids)
|
||||
})
|
||||
unittest.MainTest(m)
|
||||
}
|
||||
|
||||
func TestDBSearchIssues(t *testing.T) {
|
||||
@@ -95,39 +30,390 @@ func TestDBSearchIssues(t *testing.T) {
|
||||
setting.Indexer.IssueType = "db"
|
||||
InitIssueIndexer(true)
|
||||
|
||||
t.Run("issue2", func(t *testing.T) {
|
||||
ids, _, err := SearchIssues(context.TODO(), &SearchOptions{
|
||||
Keyword: "issue2",
|
||||
RepoIDs: []int64{1},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, []int64{2}, ids)
|
||||
})
|
||||
|
||||
t.Run("first", func(t *testing.T) {
|
||||
ids, _, err := SearchIssues(context.TODO(), &SearchOptions{
|
||||
Keyword: "first",
|
||||
RepoIDs: []int64{1},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, []int64{1}, ids)
|
||||
})
|
||||
|
||||
t.Run("for", func(t *testing.T) {
|
||||
ids, _, err := SearchIssues(context.TODO(), &SearchOptions{
|
||||
Keyword: "for",
|
||||
RepoIDs: []int64{1},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.ElementsMatch(t, []int64{1, 2, 3, 5, 11}, ids)
|
||||
})
|
||||
|
||||
t.Run("good", func(t *testing.T) {
|
||||
ids, _, err := SearchIssues(context.TODO(), &SearchOptions{
|
||||
Keyword: "good",
|
||||
RepoIDs: []int64{1},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, []int64{1}, ids)
|
||||
})
|
||||
t.Run("search issues with keyword", searchIssueWithKeyword)
|
||||
t.Run("search issues in repo", searchIssueInRepo)
|
||||
t.Run("search issues by ID", searchIssueByID)
|
||||
t.Run("search issues is pr", searchIssueIsPull)
|
||||
t.Run("search issues is closed", searchIssueIsClosed)
|
||||
t.Run("search issues by milestone", searchIssueByMilestoneID)
|
||||
t.Run("search issues by label", searchIssueByLabelID)
|
||||
t.Run("search issues by time", searchIssueByTime)
|
||||
t.Run("search issues with order", searchIssueWithOrder)
|
||||
t.Run("search issues in project", searchIssueInProject)
|
||||
t.Run("search issues with paginator", searchIssueWithPaginator)
|
||||
}
|
||||
|
||||
func searchIssueWithKeyword(t *testing.T) {
|
||||
tests := []struct {
|
||||
opts SearchOptions
|
||||
expectedIDs []int64
|
||||
}{
|
||||
{
|
||||
SearchOptions{
|
||||
Keyword: "issue2",
|
||||
RepoIDs: []int64{1},
|
||||
},
|
||||
[]int64{2},
|
||||
},
|
||||
{
|
||||
SearchOptions{
|
||||
Keyword: "first",
|
||||
RepoIDs: []int64{1},
|
||||
},
|
||||
[]int64{1},
|
||||
},
|
||||
{
|
||||
SearchOptions{
|
||||
Keyword: "for",
|
||||
RepoIDs: []int64{1},
|
||||
},
|
||||
[]int64{11, 5, 3, 2, 1},
|
||||
},
|
||||
{
|
||||
SearchOptions{
|
||||
Keyword: "good",
|
||||
RepoIDs: []int64{1},
|
||||
},
|
||||
[]int64{1},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
issueIDs, _, err := SearchIssues(context.TODO(), &test.opts)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
assert.Equal(t, test.expectedIDs, issueIDs)
|
||||
}
|
||||
}
|
||||
|
||||
func searchIssueInRepo(t *testing.T) {
|
||||
tests := []struct {
|
||||
opts SearchOptions
|
||||
expectedIDs []int64
|
||||
}{
|
||||
{
|
||||
SearchOptions{
|
||||
RepoIDs: []int64{1},
|
||||
},
|
||||
[]int64{11, 5, 3, 2, 1},
|
||||
},
|
||||
{
|
||||
SearchOptions{
|
||||
RepoIDs: []int64{2},
|
||||
},
|
||||
[]int64{7, 4},
|
||||
},
|
||||
{
|
||||
SearchOptions{
|
||||
RepoIDs: []int64{3},
|
||||
},
|
||||
[]int64{12, 6},
|
||||
},
|
||||
{
|
||||
SearchOptions{
|
||||
RepoIDs: []int64{4},
|
||||
},
|
||||
[]int64{},
|
||||
},
|
||||
{
|
||||
SearchOptions{
|
||||
RepoIDs: []int64{5},
|
||||
},
|
||||
[]int64{15},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
issueIDs, _, err := SearchIssues(context.TODO(), &test.opts)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
assert.Equal(t, test.expectedIDs, issueIDs)
|
||||
}
|
||||
}
|
||||
|
||||
func searchIssueByID(t *testing.T) {
|
||||
int64Pointer := func(x int64) *int64 {
|
||||
return &x
|
||||
}
|
||||
tests := []struct {
|
||||
opts SearchOptions
|
||||
expectedIDs []int64
|
||||
}{
|
||||
{
|
||||
SearchOptions{
|
||||
PosterID: int64Pointer(1),
|
||||
},
|
||||
[]int64{11, 6, 3, 2, 1},
|
||||
},
|
||||
{
|
||||
SearchOptions{
|
||||
AssigneeID: int64Pointer(1),
|
||||
},
|
||||
[]int64{6, 1},
|
||||
},
|
||||
{
|
||||
SearchOptions{
|
||||
MentionID: int64Pointer(4),
|
||||
},
|
||||
[]int64{1},
|
||||
},
|
||||
{
|
||||
SearchOptions{
|
||||
ReviewedID: int64Pointer(1),
|
||||
},
|
||||
[]int64{},
|
||||
},
|
||||
{
|
||||
SearchOptions{
|
||||
ReviewRequestedID: int64Pointer(1),
|
||||
},
|
||||
[]int64{12},
|
||||
},
|
||||
{
|
||||
SearchOptions{
|
||||
SubscriberID: int64Pointer(1),
|
||||
},
|
||||
[]int64{11, 6, 5, 3, 2, 1},
|
||||
},
|
||||
{
|
||||
// issue 20 request user 15 and team 5 which user 15 belongs to
|
||||
// the review request number of issue 20 should be 1
|
||||
SearchOptions{
|
||||
ReviewRequestedID: int64Pointer(15),
|
||||
},
|
||||
[]int64{12, 20},
|
||||
},
|
||||
{
|
||||
// user 20 approved the issue 20, so return nothing
|
||||
SearchOptions{
|
||||
ReviewRequestedID: int64Pointer(20),
|
||||
},
|
||||
[]int64{},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
issueIDs, _, err := SearchIssues(context.TODO(), &test.opts)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
assert.Equal(t, test.expectedIDs, issueIDs)
|
||||
}
|
||||
}
|
||||
|
||||
func searchIssueIsPull(t *testing.T) {
|
||||
tests := []struct {
|
||||
opts SearchOptions
|
||||
expectedIDs []int64
|
||||
}{
|
||||
{
|
||||
SearchOptions{
|
||||
IsPull: util.OptionalBoolFalse,
|
||||
},
|
||||
[]int64{17, 16, 15, 14, 13, 6, 5, 18, 10, 7, 4, 1},
|
||||
},
|
||||
{
|
||||
SearchOptions{
|
||||
IsPull: util.OptionalBoolTrue,
|
||||
},
|
||||
[]int64{12, 11, 20, 19, 9, 8, 3, 2},
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
issueIDs, _, err := SearchIssues(context.TODO(), &test.opts)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
assert.Equal(t, test.expectedIDs, issueIDs)
|
||||
}
|
||||
}
|
||||
|
||||
func searchIssueIsClosed(t *testing.T) {
|
||||
tests := []struct {
|
||||
opts SearchOptions
|
||||
expectedIDs []int64
|
||||
}{
|
||||
{
|
||||
SearchOptions{
|
||||
IsClosed: util.OptionalBoolFalse,
|
||||
},
|
||||
[]int64{17, 16, 15, 14, 13, 12, 11, 20, 6, 19, 18, 10, 7, 9, 8, 3, 2, 1},
|
||||
},
|
||||
{
|
||||
SearchOptions{
|
||||
IsClosed: util.OptionalBoolTrue,
|
||||
},
|
||||
[]int64{5, 4},
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
issueIDs, _, err := SearchIssues(context.TODO(), &test.opts)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
assert.Equal(t, test.expectedIDs, issueIDs)
|
||||
}
|
||||
}
|
||||
|
||||
func searchIssueByMilestoneID(t *testing.T) {
|
||||
tests := []struct {
|
||||
opts SearchOptions
|
||||
expectedIDs []int64
|
||||
}{
|
||||
{
|
||||
SearchOptions{
|
||||
MilestoneIDs: []int64{1},
|
||||
},
|
||||
[]int64{2},
|
||||
},
|
||||
{
|
||||
SearchOptions{
|
||||
MilestoneIDs: []int64{3},
|
||||
},
|
||||
[]int64{3},
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
issueIDs, _, err := SearchIssues(context.TODO(), &test.opts)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
assert.Equal(t, test.expectedIDs, issueIDs)
|
||||
}
|
||||
}
|
||||
|
||||
func searchIssueByLabelID(t *testing.T) {
|
||||
tests := []struct {
|
||||
opts SearchOptions
|
||||
expectedIDs []int64
|
||||
}{
|
||||
{
|
||||
SearchOptions{
|
||||
IncludedLabelIDs: []int64{1},
|
||||
},
|
||||
[]int64{2, 1},
|
||||
},
|
||||
{
|
||||
SearchOptions{
|
||||
IncludedLabelIDs: []int64{4},
|
||||
},
|
||||
[]int64{2},
|
||||
},
|
||||
{
|
||||
SearchOptions{
|
||||
ExcludedLabelIDs: []int64{1},
|
||||
},
|
||||
[]int64{17, 16, 15, 14, 13, 12, 11, 20, 6, 5, 19, 18, 10, 7, 4, 9, 8, 3},
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
issueIDs, _, err := SearchIssues(context.TODO(), &test.opts)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
assert.Equal(t, test.expectedIDs, issueIDs)
|
||||
}
|
||||
}
|
||||
|
||||
func searchIssueByTime(t *testing.T) {
|
||||
int64Pointer := func(i int64) *int64 {
|
||||
return &i
|
||||
}
|
||||
tests := []struct {
|
||||
opts SearchOptions
|
||||
expectedIDs []int64
|
||||
}{
|
||||
{
|
||||
SearchOptions{
|
||||
UpdatedAfterUnix: int64Pointer(0),
|
||||
},
|
||||
[]int64{17, 16, 15, 14, 13, 12, 11, 20, 6, 5, 19, 18, 10, 7, 4, 9, 8, 3, 2, 1},
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
issueIDs, _, err := SearchIssues(context.TODO(), &test.opts)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
assert.Equal(t, test.expectedIDs, issueIDs)
|
||||
}
|
||||
}
|
||||
|
||||
func searchIssueWithOrder(t *testing.T) {
|
||||
tests := []struct {
|
||||
opts SearchOptions
|
||||
expectedIDs []int64
|
||||
}{
|
||||
{
|
||||
SearchOptions{
|
||||
SortBy: internal.SortByCreatedAsc,
|
||||
},
|
||||
[]int64{1, 2, 3, 8, 9, 4, 7, 10, 18, 19, 5, 6, 20, 11, 12, 13, 14, 15, 16, 17},
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
issueIDs, _, err := SearchIssues(context.TODO(), &test.opts)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
assert.Equal(t, test.expectedIDs, issueIDs)
|
||||
}
|
||||
}
|
||||
|
||||
func searchIssueInProject(t *testing.T) {
|
||||
int64Pointer := func(i int64) *int64 {
|
||||
return &i
|
||||
}
|
||||
tests := []struct {
|
||||
opts SearchOptions
|
||||
expectedIDs []int64
|
||||
}{
|
||||
{
|
||||
SearchOptions{
|
||||
ProjectID: int64Pointer(1),
|
||||
},
|
||||
[]int64{5, 3, 2, 1},
|
||||
},
|
||||
{
|
||||
SearchOptions{
|
||||
ProjectBoardID: int64Pointer(1),
|
||||
},
|
||||
[]int64{1},
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
issueIDs, _, err := SearchIssues(context.TODO(), &test.opts)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
assert.Equal(t, test.expectedIDs, issueIDs)
|
||||
}
|
||||
}
|
||||
|
||||
func searchIssueWithPaginator(t *testing.T) {
|
||||
tests := []struct {
|
||||
opts SearchOptions
|
||||
expectedIDs []int64
|
||||
expectedTotal int64
|
||||
}{
|
||||
{
|
||||
SearchOptions{
|
||||
Paginator: &db.ListOptions{
|
||||
PageSize: 5,
|
||||
},
|
||||
},
|
||||
[]int64{17, 16, 15, 14, 13},
|
||||
20,
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
issueIDs, total, err := SearchIssues(context.TODO(), &test.opts)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
assert.Equal(t, test.expectedIDs, issueIDs)
|
||||
assert.Equal(t, test.expectedTotal, total)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ package stats
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -23,9 +22,7 @@ import (
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m, &unittest.TestOptions{
|
||||
GiteaRootPath: filepath.Join("..", "..", ".."),
|
||||
})
|
||||
unittest.MainTest(m)
|
||||
}
|
||||
|
||||
func TestRepoStatsIndex(t *testing.T) {
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
|
||||
// FilesystemClient is used to read LFS data from a filesystem path
|
||||
type FilesystemClient struct {
|
||||
lfsdir string
|
||||
lfsDir string
|
||||
}
|
||||
|
||||
// BatchSize returns the preferred size of batchs to process
|
||||
@@ -25,16 +25,12 @@ func (c *FilesystemClient) BatchSize() int {
|
||||
|
||||
func newFilesystemClient(endpoint *url.URL) *FilesystemClient {
|
||||
path, _ := util.FileURLToPath(endpoint)
|
||||
|
||||
lfsdir := filepath.Join(path, "lfs", "objects")
|
||||
|
||||
client := &FilesystemClient{lfsdir}
|
||||
|
||||
return client
|
||||
lfsDir := filepath.Join(path, "lfs", "objects")
|
||||
return &FilesystemClient{lfsDir}
|
||||
}
|
||||
|
||||
func (c *FilesystemClient) objectPath(oid string) string {
|
||||
return filepath.Join(c.lfsdir, oid[0:2], oid[2:4], oid)
|
||||
return filepath.Join(c.lfsDir, oid[0:2], oid[2:4], oid)
|
||||
}
|
||||
|
||||
// Download reads the specific LFS object from the target path
|
||||
|
||||
+70
-34
@@ -8,6 +8,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
@@ -17,7 +18,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/proxy"
|
||||
)
|
||||
|
||||
const batchSize = 20
|
||||
const httpBatchSize = 20
|
||||
|
||||
// HTTPClient is used to communicate with the LFS server
|
||||
// https://github.com/git-lfs/git-lfs/blob/main/docs/api/batch.md
|
||||
@@ -29,7 +30,7 @@ type HTTPClient struct {
|
||||
|
||||
// BatchSize returns the preferred size of batchs to process
|
||||
func (c *HTTPClient) BatchSize() int {
|
||||
return batchSize
|
||||
return httpBatchSize
|
||||
}
|
||||
|
||||
func newHTTPClient(endpoint *url.URL, httpTransport *http.Transport) *HTTPClient {
|
||||
@@ -43,28 +44,25 @@ func newHTTPClient(endpoint *url.URL, httpTransport *http.Transport) *HTTPClient
|
||||
Transport: httpTransport,
|
||||
}
|
||||
|
||||
client := &HTTPClient{
|
||||
client: hc,
|
||||
endpoint: strings.TrimSuffix(endpoint.String(), "/"),
|
||||
transfers: make(map[string]TransferAdapter),
|
||||
}
|
||||
|
||||
basic := &BasicTransferAdapter{hc}
|
||||
|
||||
client.transfers[basic.Name()] = basic
|
||||
client := &HTTPClient{
|
||||
client: hc,
|
||||
endpoint: strings.TrimSuffix(endpoint.String(), "/"),
|
||||
transfers: map[string]TransferAdapter{
|
||||
basic.Name(): basic,
|
||||
},
|
||||
}
|
||||
|
||||
return client
|
||||
}
|
||||
|
||||
func (c *HTTPClient) transferNames() []string {
|
||||
keys := make([]string, len(c.transfers))
|
||||
|
||||
i := 0
|
||||
for k := range c.transfers {
|
||||
keys[i] = k
|
||||
i++
|
||||
}
|
||||
|
||||
return keys
|
||||
}
|
||||
|
||||
@@ -74,7 +72,6 @@ func (c *HTTPClient) batch(ctx context.Context, operation string, objects []Poin
|
||||
url := fmt.Sprintf("%s/objects/batch", c.endpoint)
|
||||
|
||||
request := &BatchRequest{operation, c.transferNames(), nil, objects}
|
||||
|
||||
payload := new(bytes.Buffer)
|
||||
err := json.NewEncoder(payload).Encode(request)
|
||||
if err != nil {
|
||||
@@ -82,32 +79,17 @@ func (c *HTTPClient) batch(ctx context.Context, operation string, objects []Poin
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Trace("Calling: %s", url)
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", url, payload)
|
||||
req, err := createRequest(ctx, http.MethodPost, url, map[string]string{"Content-Type": MediaType}, payload)
|
||||
if err != nil {
|
||||
log.Error("Error creating request: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Content-type", MediaType)
|
||||
req.Header.Set("Accept", MediaType)
|
||||
|
||||
res, err := c.client.Do(req)
|
||||
res, err := performRequest(ctx, c.client, req)
|
||||
if err != nil {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return nil, ctx.Err()
|
||||
default:
|
||||
}
|
||||
log.Error("Error while processing request: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
if res.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("Unexpected server response: %s", res.Status)
|
||||
}
|
||||
|
||||
var response BatchResponse
|
||||
err = json.NewDecoder(res.Body).Decode(&response)
|
||||
if err != nil {
|
||||
@@ -177,7 +159,7 @@ func (c *HTTPClient) performOperation(ctx context.Context, objects []Pointer, dc
|
||||
link, ok := object.Actions["upload"]
|
||||
if !ok {
|
||||
log.Debug("%+v", object)
|
||||
return errors.New("Missing action 'upload'")
|
||||
return errors.New("missing action 'upload'")
|
||||
}
|
||||
|
||||
content, err := uc(object.Pointer, nil)
|
||||
@@ -187,8 +169,6 @@ func (c *HTTPClient) performOperation(ctx context.Context, objects []Pointer, dc
|
||||
|
||||
err = transferAdapter.Upload(ctx, link, object.Pointer, content)
|
||||
|
||||
content.Close()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -203,7 +183,7 @@ func (c *HTTPClient) performOperation(ctx context.Context, objects []Pointer, dc
|
||||
link, ok := object.Actions["download"]
|
||||
if !ok {
|
||||
log.Debug("%+v", object)
|
||||
return errors.New("Missing action 'download'")
|
||||
return errors.New("missing action 'download'")
|
||||
}
|
||||
|
||||
content, err := transferAdapter.Download(ctx, link)
|
||||
@@ -219,3 +199,59 @@ func (c *HTTPClient) performOperation(ctx context.Context, objects []Pointer, dc
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// createRequest creates a new request, and sets the headers.
|
||||
func createRequest(ctx context.Context, method, url string, headers map[string]string, body io.Reader) (*http.Request, error) {
|
||||
log.Trace("createRequest: %s", url)
|
||||
req, err := http.NewRequestWithContext(ctx, method, url, body)
|
||||
if err != nil {
|
||||
log.Error("Error creating request: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for key, value := range headers {
|
||||
req.Header.Set(key, value)
|
||||
}
|
||||
req.Header.Set("Accept", MediaType)
|
||||
|
||||
return req, nil
|
||||
}
|
||||
|
||||
// performRequest sends a request, optionally performs a callback on the request and returns the response.
|
||||
// If the status code is 200, the response is returned, and it will contain a non-nil Body.
|
||||
// Otherwise, it will return an error, and the Body will be nil or closed.
|
||||
func performRequest(ctx context.Context, client *http.Client, req *http.Request) (*http.Response, error) {
|
||||
log.Trace("performRequest: %s", req.URL)
|
||||
res, err := client.Do(req)
|
||||
if err != nil {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return res, ctx.Err()
|
||||
default:
|
||||
}
|
||||
log.Error("Error while processing request: %v", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
if res.StatusCode != http.StatusOK {
|
||||
defer res.Body.Close()
|
||||
return res, handleErrorResponse(res)
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func handleErrorResponse(resp *http.Response) error {
|
||||
var er ErrorResponse
|
||||
err := json.NewDecoder(resp.Body).Decode(&er)
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
log.Error("Error decoding json: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
log.Trace("ErrorResponse: %v", er)
|
||||
return errors.New(er.Message)
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ func TestHTTPClientDownload(t *testing.T) {
|
||||
// case 0
|
||||
{
|
||||
endpoint: "https://status-not-ok.io",
|
||||
expectederror: "Unexpected server response: ",
|
||||
expectederror: io.ErrUnexpectedEOF.Error(),
|
||||
},
|
||||
// case 1
|
||||
{
|
||||
@@ -207,7 +207,7 @@ func TestHTTPClientDownload(t *testing.T) {
|
||||
// case 6
|
||||
{
|
||||
endpoint: "https://empty-actions-map.io",
|
||||
expectederror: "Missing action 'download'",
|
||||
expectederror: "missing action 'download'",
|
||||
},
|
||||
// case 7
|
||||
{
|
||||
@@ -217,27 +217,28 @@ func TestHTTPClientDownload(t *testing.T) {
|
||||
// case 8
|
||||
{
|
||||
endpoint: "https://upload-actions-map.io",
|
||||
expectederror: "Missing action 'download'",
|
||||
expectederror: "missing action 'download'",
|
||||
},
|
||||
// case 9
|
||||
{
|
||||
endpoint: "https://verify-actions-map.io",
|
||||
expectederror: "Missing action 'download'",
|
||||
expectederror: "missing action 'download'",
|
||||
},
|
||||
// case 10
|
||||
{
|
||||
endpoint: "https://unknown-actions-map.io",
|
||||
expectederror: "Missing action 'download'",
|
||||
expectederror: "missing action 'download'",
|
||||
},
|
||||
}
|
||||
|
||||
for n, c := range cases {
|
||||
client := &HTTPClient{
|
||||
client: hc,
|
||||
endpoint: c.endpoint,
|
||||
transfers: make(map[string]TransferAdapter),
|
||||
client: hc,
|
||||
endpoint: c.endpoint,
|
||||
transfers: map[string]TransferAdapter{
|
||||
"dummy": dummy,
|
||||
},
|
||||
}
|
||||
client.transfers["dummy"] = dummy
|
||||
|
||||
err := client.Download(context.Background(), []Pointer{p}, func(p Pointer, content io.ReadCloser, objectError error) error {
|
||||
if objectError != nil {
|
||||
@@ -284,7 +285,7 @@ func TestHTTPClientUpload(t *testing.T) {
|
||||
// case 0
|
||||
{
|
||||
endpoint: "https://status-not-ok.io",
|
||||
expectederror: "Unexpected server response: ",
|
||||
expectederror: io.ErrUnexpectedEOF.Error(),
|
||||
},
|
||||
// case 1
|
||||
{
|
||||
@@ -319,7 +320,7 @@ func TestHTTPClientUpload(t *testing.T) {
|
||||
// case 7
|
||||
{
|
||||
endpoint: "https://download-actions-map.io",
|
||||
expectederror: "Missing action 'upload'",
|
||||
expectederror: "missing action 'upload'",
|
||||
},
|
||||
// case 8
|
||||
{
|
||||
@@ -329,22 +330,23 @@ func TestHTTPClientUpload(t *testing.T) {
|
||||
// case 9
|
||||
{
|
||||
endpoint: "https://verify-actions-map.io",
|
||||
expectederror: "Missing action 'upload'",
|
||||
expectederror: "missing action 'upload'",
|
||||
},
|
||||
// case 10
|
||||
{
|
||||
endpoint: "https://unknown-actions-map.io",
|
||||
expectederror: "Missing action 'upload'",
|
||||
expectederror: "missing action 'upload'",
|
||||
},
|
||||
}
|
||||
|
||||
for n, c := range cases {
|
||||
client := &HTTPClient{
|
||||
client: hc,
|
||||
endpoint: c.endpoint,
|
||||
transfers: make(map[string]TransferAdapter),
|
||||
client: hc,
|
||||
endpoint: c.endpoint,
|
||||
transfers: map[string]TransferAdapter{
|
||||
"dummy": dummy,
|
||||
},
|
||||
}
|
||||
client.transfers["dummy"] = dummy
|
||||
|
||||
err := client.Upload(context.Background(), []Pointer{p}, func(p Pointer, objectError error) (io.ReadCloser, error) {
|
||||
return io.NopCloser(new(bytes.Buffer)), objectError
|
||||
|
||||
@@ -29,10 +29,10 @@ const (
|
||||
|
||||
var (
|
||||
// ErrMissingPrefix occurs if the content lacks the LFS prefix
|
||||
ErrMissingPrefix = errors.New("Content lacks the LFS prefix")
|
||||
ErrMissingPrefix = errors.New("content lacks the LFS prefix")
|
||||
|
||||
// ErrInvalidStructure occurs if the content has an invalid structure
|
||||
ErrInvalidStructure = errors.New("Content has an invalid structure")
|
||||
ErrInvalidStructure = errors.New("content has an invalid structure")
|
||||
|
||||
// ErrInvalidOIDFormat occurs if the oid has an invalid format
|
||||
ErrInvalidOIDFormat = errors.New("OID has an invalid format")
|
||||
|
||||
@@ -6,8 +6,6 @@ package lfs
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
@@ -15,7 +13,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
)
|
||||
|
||||
// TransferAdapter represents an adapter for downloading/uploading LFS objects
|
||||
// TransferAdapter represents an adapter for downloading/uploading LFS objects.
|
||||
type TransferAdapter interface {
|
||||
Name() string
|
||||
Download(ctx context.Context, l *Link) (io.ReadCloser, error)
|
||||
@@ -23,41 +21,48 @@ type TransferAdapter interface {
|
||||
Verify(ctx context.Context, l *Link, p Pointer) error
|
||||
}
|
||||
|
||||
// BasicTransferAdapter implements the "basic" adapter
|
||||
// BasicTransferAdapter implements the "basic" adapter.
|
||||
type BasicTransferAdapter struct {
|
||||
client *http.Client
|
||||
}
|
||||
|
||||
// Name returns the name of the adapter
|
||||
// Name returns the name of the adapter.
|
||||
func (a *BasicTransferAdapter) Name() string {
|
||||
return "basic"
|
||||
}
|
||||
|
||||
// Download reads the download location and downloads the data
|
||||
// Download reads the download location and downloads the data.
|
||||
func (a *BasicTransferAdapter) Download(ctx context.Context, l *Link) (io.ReadCloser, error) {
|
||||
resp, err := a.performRequest(ctx, "GET", l, nil, nil)
|
||||
req, err := createRequest(ctx, http.MethodGet, l.Href, l.Header, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := performRequest(ctx, a.client, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.Body, nil
|
||||
}
|
||||
|
||||
// Upload sends the content to the LFS server
|
||||
// Upload sends the content to the LFS server.
|
||||
func (a *BasicTransferAdapter) Upload(ctx context.Context, l *Link, p Pointer, r io.Reader) error {
|
||||
_, err := a.performRequest(ctx, "PUT", l, r, func(req *http.Request) {
|
||||
if len(req.Header.Get("Content-Type")) == 0 {
|
||||
req.Header.Set("Content-Type", "application/octet-stream")
|
||||
}
|
||||
|
||||
if req.Header.Get("Transfer-Encoding") == "chunked" {
|
||||
req.TransferEncoding = []string{"chunked"}
|
||||
}
|
||||
|
||||
req.ContentLength = p.Size
|
||||
})
|
||||
req, err := createRequest(ctx, http.MethodPut, l.Href, l.Header, r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if req.Header.Get("Content-Type") == "" {
|
||||
req.Header.Set("Content-Type", "application/octet-stream")
|
||||
}
|
||||
if req.Header.Get("Transfer-Encoding") == "chunked" {
|
||||
req.TransferEncoding = []string{"chunked"}
|
||||
}
|
||||
req.ContentLength = p.Size
|
||||
|
||||
res, err := performRequest(ctx, a.client, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -69,66 +74,15 @@ func (a *BasicTransferAdapter) Verify(ctx context.Context, l *Link, p Pointer) e
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = a.performRequest(ctx, "POST", l, bytes.NewReader(b), func(req *http.Request) {
|
||||
req.Header.Set("Content-Type", MediaType)
|
||||
})
|
||||
req, err := createRequest(ctx, http.MethodPost, l.Href, l.Header, bytes.NewReader(b))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Header.Set("Content-Type", MediaType)
|
||||
res, err := performRequest(ctx, a.client, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *BasicTransferAdapter) performRequest(ctx context.Context, method string, l *Link, body io.Reader, callback func(*http.Request)) (*http.Response, error) {
|
||||
log.Trace("Calling: %s %s", method, l.Href)
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, method, l.Href, body)
|
||||
if err != nil {
|
||||
log.Error("Error creating request: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
for key, value := range l.Header {
|
||||
req.Header.Set(key, value)
|
||||
}
|
||||
req.Header.Set("Accept", MediaType)
|
||||
|
||||
if callback != nil {
|
||||
callback(req)
|
||||
}
|
||||
|
||||
res, err := a.client.Do(req)
|
||||
if err != nil {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return res, ctx.Err()
|
||||
default:
|
||||
}
|
||||
log.Error("Error while processing request: %v", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
if res.StatusCode != http.StatusOK {
|
||||
return res, handleErrorResponse(res)
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func handleErrorResponse(resp *http.Response) error {
|
||||
defer resp.Body.Close()
|
||||
|
||||
er, err := decodeResponseError(resp.Body)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Request failed with status %s", resp.Status)
|
||||
}
|
||||
log.Trace("ErrorRespone: %v", er)
|
||||
return errors.New(er.Message)
|
||||
}
|
||||
|
||||
func decodeResponseError(r io.Reader) (ErrorResponse, error) {
|
||||
var er ErrorResponse
|
||||
err := json.NewDecoder(r).Decode(&er)
|
||||
if err != nil {
|
||||
log.Error("Error decoding json: %v", err)
|
||||
}
|
||||
return er, err
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"runtime"
|
||||
|
||||
activities_model "code.gitea.io/gitea/models/activities"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
@@ -232,7 +233,7 @@ func (c Collector) Describe(ch chan<- *prometheus.Desc) {
|
||||
|
||||
// Collect returns the metrics with values
|
||||
func (c Collector) Collect(ch chan<- prometheus.Metric) {
|
||||
stats := activities_model.GetStatistic()
|
||||
stats := activities_model.GetStatistic(db.DefaultContext)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.Accesses,
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
// - An item can be a simple value, such as an integer, or a more complex structure that has multiple fields.
|
||||
// Usually a item serves as a task or a message. Sets of items will be sent to a queue handler to be processed.
|
||||
// - It's represented as a JSON-marshaled binary slice in the queue
|
||||
// - Since the item is marshaled by JSON, and JSON doesn't have stable key-order/type support,
|
||||
// so the decoded handler item may not be the same as the original "pushed" one if you use map/any types,
|
||||
//
|
||||
// 2. Batch:
|
||||
// - A collection of items that are grouped together for processing. Each worker receives a batch of items.
|
||||
|
||||
@@ -244,7 +244,7 @@ func TestRepoPermissionPrivateOrgRepo(t *testing.T) {
|
||||
|
||||
// update team information and then check permission
|
||||
team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: 5})
|
||||
err = organization.UpdateTeamUnits(team, nil)
|
||||
err = organization.UpdateTeamUnits(db.DefaultContext, team, nil)
|
||||
assert.NoError(t, err)
|
||||
perm, err = access_model.GetUserRepoPermission(db.DefaultContext, repo, owner)
|
||||
assert.NoError(t, err)
|
||||
|
||||
@@ -4,24 +4,25 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"context"
|
||||
|
||||
"code.gitea.io/gitea/models/organization"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
)
|
||||
|
||||
// CanUserDelete returns true if user could delete the repository
|
||||
func CanUserDelete(repo *repo_model.Repository, user *user_model.User) (bool, error) {
|
||||
func CanUserDelete(ctx context.Context, repo *repo_model.Repository, user *user_model.User) (bool, error) {
|
||||
if user.IsAdmin || user.ID == repo.OwnerID {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
if err := repo.LoadOwner(db.DefaultContext); err != nil {
|
||||
if err := repo.LoadOwner(ctx); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if repo.Owner.IsOrganization() {
|
||||
isAdmin, err := organization.OrgFromUser(repo.Owner).IsOrgAdmin(user.ID)
|
||||
isAdmin, err := organization.OrgFromUser(repo.Owner).IsOrgAdmin(ctx, user.ID)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -4,25 +4,27 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"code.gitea.io/gitea/models/organization"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
)
|
||||
|
||||
// CanUserForkRepo returns true if specified user can fork repository.
|
||||
func CanUserForkRepo(user *user_model.User, repo *repo_model.Repository) (bool, error) {
|
||||
func CanUserForkRepo(ctx context.Context, user *user_model.User, repo *repo_model.Repository) (bool, error) {
|
||||
if user == nil {
|
||||
return false, nil
|
||||
}
|
||||
if repo.OwnerID != user.ID && !repo_model.HasForkedRepo(user.ID, repo.ID) {
|
||||
if repo.OwnerID != user.ID && !repo_model.HasForkedRepo(ctx, user.ID, repo.ID) {
|
||||
return true, nil
|
||||
}
|
||||
ownedOrgs, err := organization.GetOrgsCanCreateRepoByUserID(user.ID)
|
||||
ownedOrgs, err := organization.GetOrgsCanCreateRepoByUserID(ctx, user.ID)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
for _, org := range ownedOrgs {
|
||||
if repo.OwnerID != org.ID && !repo_model.HasForkedRepo(org.ID, repo.ID) {
|
||||
if repo.OwnerID != org.ID && !repo_model.HasForkedRepo(ctx, org.ID, repo.ID) {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
@@ -13,7 +12,5 @@ import (
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m, &unittest.TestOptions{
|
||||
GiteaRootPath: filepath.Join("..", ".."),
|
||||
})
|
||||
unittest.MainTest(m)
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User,
|
||||
// note: this will greatly improve release (tag) sync
|
||||
// for pull-mirrors with many tags
|
||||
repo.IsMirror = opts.Mirror
|
||||
if err = SyncReleasesWithTags(repo, gitRepo); err != nil {
|
||||
if err = SyncReleasesWithTags(ctx, repo, gitRepo); err != nil {
|
||||
log.Error("Failed to synchronize tags to releases for repository: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -180,12 +180,17 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User,
|
||||
defer committer.Close()
|
||||
|
||||
if opts.Mirror {
|
||||
remoteAddress, err := util.SanitizeURL(opts.CloneAddr)
|
||||
if err != nil {
|
||||
return repo, err
|
||||
}
|
||||
mirrorModel := repo_model.Mirror{
|
||||
RepoID: repo.ID,
|
||||
Interval: setting.Mirror.DefaultInterval,
|
||||
EnablePrune: true,
|
||||
NextUpdateUnix: timeutil.TimeStampNow().AddDuration(setting.Mirror.DefaultInterval),
|
||||
LFS: opts.LFS,
|
||||
RemoteAddress: remoteAddress,
|
||||
}
|
||||
if opts.LFS {
|
||||
mirrorModel.LFSEndpoint = opts.LFSEndpoint
|
||||
@@ -280,13 +285,13 @@ func CleanUpMigrateInfo(ctx context.Context, repo *repo_model.Repository) (*repo
|
||||
}
|
||||
|
||||
// SyncReleasesWithTags synchronizes release table with repository tags
|
||||
func SyncReleasesWithTags(repo *repo_model.Repository, gitRepo *git.Repository) error {
|
||||
func SyncReleasesWithTags(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository) error {
|
||||
log.Debug("SyncReleasesWithTags: in Repo[%d:%s/%s]", repo.ID, repo.OwnerName, repo.Name)
|
||||
|
||||
// optimized procedure for pull-mirrors which saves a lot of time (in
|
||||
// particular for repos with many tags).
|
||||
if repo.IsMirror {
|
||||
return pullMirrorReleaseSync(repo, gitRepo)
|
||||
return pullMirrorReleaseSync(ctx, repo, gitRepo)
|
||||
}
|
||||
|
||||
existingRelTags := make(container.Set[string])
|
||||
@@ -313,7 +318,7 @@ func SyncReleasesWithTags(repo *repo_model.Repository, gitRepo *git.Repository)
|
||||
return fmt.Errorf("unable to GetTagCommitID for %q in Repo[%d:%s/%s]: %w", rel.TagName, repo.ID, repo.OwnerName, repo.Name, err)
|
||||
}
|
||||
if git.IsErrNotExist(err) || commitID != rel.Sha1 {
|
||||
if err := repo_model.PushUpdateDeleteTag(repo, rel.TagName); err != nil {
|
||||
if err := repo_model.PushUpdateDeleteTag(ctx, repo, rel.TagName); err != nil {
|
||||
return fmt.Errorf("unable to PushUpdateDeleteTag: %q in Repo[%d:%s/%s]: %w", rel.TagName, repo.ID, repo.OwnerName, repo.Name, err)
|
||||
}
|
||||
} else {
|
||||
@@ -328,7 +333,7 @@ func SyncReleasesWithTags(repo *repo_model.Repository, gitRepo *git.Repository)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := PushUpdateAddTag(db.DefaultContext, repo, gitRepo, tagName, sha1, refname); err != nil {
|
||||
if err := PushUpdateAddTag(ctx, repo, gitRepo, tagName, sha1, refname); err != nil {
|
||||
return fmt.Errorf("unable to PushUpdateAddTag: %q to Repo[%d:%s/%s]: %w", tagName, repo.ID, repo.OwnerName, repo.Name, err)
|
||||
}
|
||||
|
||||
@@ -385,7 +390,7 @@ func PushUpdateAddTag(ctx context.Context, repo *repo_model.Repository, gitRepo
|
||||
rel.PublisherID = author.ID
|
||||
}
|
||||
|
||||
return repo_model.SaveOrUpdateTag(repo, &rel)
|
||||
return repo_model.SaveOrUpdateTag(ctx, repo, &rel)
|
||||
}
|
||||
|
||||
// StoreMissingLfsObjectsInRepository downloads missing LFS objects
|
||||
@@ -492,13 +497,13 @@ func StoreMissingLfsObjectsInRepository(ctx context.Context, repo *repo_model.Re
|
||||
// upstream. Hence, after each sync we want the pull-mirror release set to be
|
||||
// identical to the upstream tag set. This is much more efficient for
|
||||
// repositories like https://github.com/vim/vim (with over 13000 tags).
|
||||
func pullMirrorReleaseSync(repo *repo_model.Repository, gitRepo *git.Repository) error {
|
||||
func pullMirrorReleaseSync(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository) error {
|
||||
log.Trace("pullMirrorReleaseSync: rebuilding releases for pull-mirror Repo[%d:%s/%s]", repo.ID, repo.OwnerName, repo.Name)
|
||||
tags, numTags, err := gitRepo.GetTagInfos(0, 0)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to GetTagInfos in pull-mirror Repo[%d:%s/%s]: %w", repo.ID, repo.OwnerName, repo.Name, err)
|
||||
}
|
||||
err = db.WithTx(db.DefaultContext, func(ctx context.Context) error {
|
||||
err = db.WithTx(ctx, func(ctx context.Context) error {
|
||||
//
|
||||
// clear out existing releases
|
||||
//
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"code.gitea.io/gitea/models/auth"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"gitea.com/go-chi/session"
|
||||
@@ -71,7 +72,7 @@ func (s *DBStore) Release() error {
|
||||
return err
|
||||
}
|
||||
|
||||
return auth.UpdateSession(s.sid, data)
|
||||
return auth.UpdateSession(db.DefaultContext, s.sid, data)
|
||||
}
|
||||
|
||||
// Flush deletes all session data.
|
||||
@@ -97,7 +98,7 @@ func (p *DBProvider) Init(maxLifetime int64, connStr string) error {
|
||||
|
||||
// Read returns raw session store by session ID.
|
||||
func (p *DBProvider) Read(sid string) (session.RawStore, error) {
|
||||
s, err := auth.ReadSession(sid)
|
||||
s, err := auth.ReadSession(db.DefaultContext, sid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -117,7 +118,7 @@ func (p *DBProvider) Read(sid string) (session.RawStore, error) {
|
||||
|
||||
// Exist returns true if session with given ID exists.
|
||||
func (p *DBProvider) Exist(sid string) bool {
|
||||
has, err := auth.ExistSession(sid)
|
||||
has, err := auth.ExistSession(db.DefaultContext, sid)
|
||||
if err != nil {
|
||||
panic("session/DB: error checking existence: " + err.Error())
|
||||
}
|
||||
@@ -126,12 +127,12 @@ func (p *DBProvider) Exist(sid string) bool {
|
||||
|
||||
// Destroy deletes a session by session ID.
|
||||
func (p *DBProvider) Destroy(sid string) error {
|
||||
return auth.DestroySession(sid)
|
||||
return auth.DestroySession(db.DefaultContext, sid)
|
||||
}
|
||||
|
||||
// Regenerate regenerates a session store from old session ID to new one.
|
||||
func (p *DBProvider) Regenerate(oldsid, sid string) (_ session.RawStore, err error) {
|
||||
s, err := auth.RegenerateSession(oldsid, sid)
|
||||
s, err := auth.RegenerateSession(db.DefaultContext, oldsid, sid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -151,7 +152,7 @@ func (p *DBProvider) Regenerate(oldsid, sid string) (_ session.RawStore, err err
|
||||
|
||||
// Count counts and returns number of sessions.
|
||||
func (p *DBProvider) Count() int {
|
||||
total, err := auth.CountSessions()
|
||||
total, err := auth.CountSessions(db.DefaultContext)
|
||||
if err != nil {
|
||||
panic("session/DB: error counting records: " + err.Error())
|
||||
}
|
||||
@@ -160,7 +161,7 @@ func (p *DBProvider) Count() int {
|
||||
|
||||
// GC calls GC to clean expired sessions.
|
||||
func (p *DBProvider) GC() {
|
||||
if err := auth.CleanupSessions(p.maxLifetime); err != nil {
|
||||
if err := auth.CleanupSessions(db.DefaultContext, p.maxLifetime); err != nil {
|
||||
log.Printf("session/DB: error garbage collecting: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ package setting
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
)
|
||||
@@ -18,8 +19,11 @@ var (
|
||||
ArtifactRetentionDays int64 `ini:"ARTIFACT_RETENTION_DAYS"`
|
||||
Enabled bool
|
||||
DefaultActionsURL defaultActionsURL `ini:"DEFAULT_ACTIONS_URL"`
|
||||
ZombieTaskTimeout time.Duration `ini:"ZOMBIE_TASK_TIMEOUT"`
|
||||
EndlessTaskTimeout time.Duration `ini:"ENDLESS_TASK_TIMEOUT"`
|
||||
AbandonedJobTimeout time.Duration `ini:"ABANDONED_JOB_TIMEOUT"`
|
||||
}{
|
||||
Enabled: false,
|
||||
Enabled: true,
|
||||
DefaultActionsURL: defaultActionsURLGitHub,
|
||||
}
|
||||
)
|
||||
@@ -82,5 +86,9 @@ func loadActionsFrom(rootCfg ConfigProvider) error {
|
||||
Actions.ArtifactRetentionDays = 90
|
||||
}
|
||||
|
||||
Actions.ZombieTaskTimeout = sec.Key("ZOMBIE_TASK_TIMEOUT").MustDuration(10 * time.Minute)
|
||||
Actions.EndlessTaskTimeout = sec.Key("ENDLESS_TASK_TIMEOUT").MustDuration(3 * time.Hour)
|
||||
Actions.AbandonedJobTimeout = sec.Key("ABANDONED_JOB_TIMEOUT").MustDuration(24 * time.Hour)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -81,7 +81,6 @@ var (
|
||||
StaticCacheTime time.Duration
|
||||
EnableGzip bool
|
||||
LandingPageURL LandingPage
|
||||
LandingPageCustom string
|
||||
UnixSocketPermission uint32
|
||||
EnablePprof bool
|
||||
PprofDataPath string
|
||||
@@ -103,7 +102,6 @@ var (
|
||||
StaticURLPrefix string
|
||||
AbsoluteAssetURL string
|
||||
|
||||
HasRobotsTxt bool
|
||||
ManifestData string
|
||||
)
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
package structs
|
||||
|
||||
import "time"
|
||||
|
||||
// CreatePushMirrorOption represents need information to create a push mirror of a repository.
|
||||
type CreatePushMirrorOption struct {
|
||||
RemoteAddress string `json:"remote_address"`
|
||||
@@ -15,12 +17,14 @@ type CreatePushMirrorOption struct {
|
||||
// PushMirror represents information of a push mirror
|
||||
// swagger:model
|
||||
type PushMirror struct {
|
||||
RepoName string `json:"repo_name"`
|
||||
RemoteName string `json:"remote_name"`
|
||||
RemoteAddress string `json:"remote_address"`
|
||||
CreatedUnix string `json:"created"`
|
||||
LastUpdateUnix string `json:"last_update"`
|
||||
LastError string `json:"last_error"`
|
||||
Interval string `json:"interval"`
|
||||
SyncOnCommit bool `json:"sync_on_commit"`
|
||||
RepoName string `json:"repo_name"`
|
||||
RemoteName string `json:"remote_name"`
|
||||
RemoteAddress string `json:"remote_address"`
|
||||
// swagger:strfmt date-time
|
||||
CreatedUnix time.Time `json:"created"`
|
||||
// swagger:strfmt date-time
|
||||
LastUpdateUnix *time.Time `json:"last_update"`
|
||||
LastError string `json:"last_error"`
|
||||
Interval string `json:"interval"`
|
||||
SyncOnCommit bool `json:"sync_on_commit"`
|
||||
}
|
||||
|
||||
@@ -63,6 +63,7 @@ type Repository struct {
|
||||
Language string `json:"language"`
|
||||
LanguagesURL string `json:"languages_url"`
|
||||
HTMLURL string `json:"html_url"`
|
||||
URL string `json:"url"`
|
||||
Link string `json:"link"`
|
||||
SSHURL string `json:"ssh_url"`
|
||||
CloneURL string `json:"clone_url"`
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
@@ -14,8 +13,7 @@ import (
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m, &unittest.TestOptions{
|
||||
GiteaRootPath: filepath.Join("..", ".."),
|
||||
FixtureFiles: []string{""}, // load nothing
|
||||
FixtureFiles: []string{""}, // load nothing
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -58,11 +58,11 @@ func IsMultilineCommitMessage(msg string) bool {
|
||||
// Actioner describes an action
|
||||
type Actioner interface {
|
||||
GetOpType() activities_model.ActionType
|
||||
GetActUserName() string
|
||||
GetRepoUserName() string
|
||||
GetRepoName() string
|
||||
GetRepoPath() string
|
||||
GetRepoLink() string
|
||||
GetActUserName(ctx context.Context) string
|
||||
GetRepoUserName(ctx context.Context) string
|
||||
GetRepoName(ctx context.Context) string
|
||||
GetRepoPath(ctx context.Context) string
|
||||
GetRepoLink(ctx context.Context) string
|
||||
GetBranch() string
|
||||
GetContent() string
|
||||
GetCreate() time.Time
|
||||
|
||||
@@ -225,6 +225,7 @@ func isOSWindows() bool {
|
||||
var driveLetterRegexp = regexp.MustCompile("/[A-Za-z]:/")
|
||||
|
||||
// FileURLToPath extracts the path information from a file://... url.
|
||||
// It returns an error only if the URL is not a file URL.
|
||||
func FileURLToPath(u *url.URL) (string, error) {
|
||||
if u.Scheme != "file" {
|
||||
return "", errors.New("URL scheme is not 'file': " + u.String())
|
||||
|
||||
@@ -39,3 +39,12 @@ func URLJoin(base string, elems ...string) string {
|
||||
}
|
||||
return joinedURL
|
||||
}
|
||||
|
||||
func SanitizeURL(s string) (string, error) {
|
||||
u, err := url.Parse(s)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
u.User = nil
|
||||
return u.String(), nil
|
||||
}
|
||||
|
||||
@@ -47,8 +47,6 @@ func GetContextData(c context.Context) ContextData {
|
||||
|
||||
func CommonTemplateContextData() ContextData {
|
||||
return ContextData{
|
||||
"IsLandingPageHome": setting.LandingPageURL == setting.LandingPageHome,
|
||||
"IsLandingPageExplore": setting.LandingPageURL == setting.LandingPageExplore,
|
||||
"IsLandingPageOrganizations": setting.LandingPageURL == setting.LandingPageOrganizations,
|
||||
|
||||
"ShowRegistrationButton": setting.Service.ShowRegistrationButton,
|
||||
|
||||
Reference in New Issue
Block a user