From 371c56e3063848dab049b636085062b68ba6a280 Mon Sep 17 00:00:00 2001 From: Joe Chen Date: Thu, 2 Nov 2023 21:32:33 -0400 Subject: [PATCH] fixup --- internal/context/go_get.go | 2 +- internal/context/org.go | 2 +- internal/context/repo.go | 2 +- internal/db/actions.go | 6 +- internal/db/actions_test.go | 18 +- internal/db/db.go | 4 +- internal/db/mocks.go | 8 +- internal/db/models.go | 2 +- internal/db/org.go | 86 --- internal/db/org_team.go | 2 +- internal/db/{orgs.go => organizations.go} | 226 ++++-- .../{orgs_test.go => organizations_test.go} | 18 +- internal/db/repo.go | 14 +- internal/db/{repos.go => repositories.go} | 53 +- .../{repos_test.go => repositories_test.go} | 33 +- internal/db/users.go | 23 +- internal/db/users_test.go | 8 +- internal/route/admin/orgs.go | 12 +- internal/route/admin/repos.go | 2 +- internal/route/api/v1/api.go | 2 +- internal/route/api/v1/org/org.go | 32 +- internal/route/api/v1/repo/repo.go | 6 +- internal/route/home.go | 14 +- internal/route/lfs/mocks_test.go | 660 +++++++++--------- internal/route/lfs/route.go | 2 +- internal/route/lfs/route_test.go | 14 +- internal/route/org/members.go | 12 +- internal/route/org/org.go | 16 +- internal/route/repo/http.go | 2 +- internal/route/repo/issue.go | 2 +- internal/route/repo/pull.go | 4 +- internal/route/repo/tasks.go | 2 +- internal/route/user/home.go | 14 +- internal/route/user/setting.go | 2 +- mockgen.yaml | 2 +- 35 files changed, 689 insertions(+), 618 deletions(-) rename internal/db/{orgs.go => organizations.go} (67%) rename internal/db/{orgs_test.go => organizations_test.go} (92%) rename internal/db/{repos.go => repositories.go} (84%) rename internal/db/{repos_test.go => repositories_test.go} (91%) diff --git a/internal/context/go_get.go b/internal/context/go_get.go index b83eda83b..e05dcbc39 100644 --- a/internal/context/go_get.go +++ b/internal/context/go_get.go @@ -29,7 +29,7 @@ func ServeGoGet() macaron.Handler { owner, err := db.Users.GetByUsername(c.Req.Context(), ownerName) if err == nil { - repo, err := db.Repos.GetByName(c.Req.Context(), owner.ID, repoName) + repo, err := db.Repositories.GetByName(c.Req.Context(), owner.ID, repoName) if err == nil && repo.DefaultBranch != "" { branchName = repo.DefaultBranch } diff --git a/internal/context/org.go b/internal/context/org.go index 51256358a..1f2cdc515 100644 --- a/internal/context/org.go +++ b/internal/context/org.go @@ -74,7 +74,7 @@ func HandleOrgAssignment(c *Context, args ...bool) { c.Org.IsTeamMember = true c.Org.IsTeamAdmin = true } else { - c.Org.IsMember, _ = db.Orgs.HasMember(c.Req.Context(), org.ID, c.User.ID) + c.Org.IsMember, _ = db.Organizations.HasMember(c.Req.Context(), org.ID, c.User.ID) } } else { // Fake data. diff --git a/internal/context/repo.go b/internal/context/repo.go index 3c3462f0e..6e0c0b8b5 100644 --- a/internal/context/repo.go +++ b/internal/context/repo.go @@ -403,7 +403,7 @@ func RepoRef() macaron.Handler { c.Data["IsViewCommit"] = c.Repo.IsViewCommit // People who have push access or have forked repository can propose a new pull request. - if c.Repo.IsWriter() || (c.IsLogged && db.Repos.HasForkedBy(c.Req.Context(), c.Repo.Repository.ID, c.User.ID)) { + if c.Repo.IsWriter() || (c.IsLogged && db.Repositories.HasForkedBy(c.Req.Context(), c.Repo.Repository.ID, c.User.ID)) { // Pull request is allowed if this is a fork repository // and base repository accepts pull requests. if c.Repo.Repository.BaseRepo != nil { diff --git a/internal/db/actions.go b/internal/db/actions.go index a67cb0b8d..02e4c93e6 100644 --- a/internal/db/actions.go +++ b/internal/db/actions.go @@ -165,7 +165,7 @@ func (db *actions) ListByUser(ctx context.Context, userID, actorID, afterID int6 // notifyWatchers creates rows in action table for watchers who are able to see the action. func (db *actions) notifyWatchers(ctx context.Context, act *Action) error { - watches, err := NewReposStore(db.DB).ListWatches(ctx, act.RepoID) + watches, err := NewRepositoriesStore(db.DB).ListWatches(ctx, act.RepoID) if err != nil { return errors.Wrap(err, "list watches") } @@ -489,7 +489,7 @@ type CommitRepoOptions struct { } func (db *actions) CommitRepo(ctx context.Context, opts CommitRepoOptions) error { - err := NewReposStore(db.DB).Touch(ctx, opts.Repo.ID) + err := NewRepositoriesStore(db.DB).Touch(ctx, opts.Repo.ID) if err != nil { return errors.Wrap(err, "touch repository") } @@ -633,7 +633,7 @@ type PushTagOptions struct { } func (db *actions) PushTag(ctx context.Context, opts PushTagOptions) error { - err := NewReposStore(db.DB).Touch(ctx, opts.Repo.ID) + err := NewRepositoriesStore(db.DB).Touch(ctx, opts.Repo.ID) if err != nil { return errors.Wrap(err, "touch repository") } diff --git a/internal/db/actions_test.go b/internal/db/actions_test.go index 8bf20f697..03b547b7c 100644 --- a/internal/db/actions_test.go +++ b/internal/db/actions_test.go @@ -137,7 +137,7 @@ func TestActions(t *testing.T) { func actionsCommitRepo(t *testing.T, ctx context.Context, db *actions) { alice, err := NewUsersStore(db.DB).Create(ctx, "alice", "alice@example.com", CreateUserOptions{}) require.NoError(t, err) - repo, err := NewReposStore(db.DB).Create(ctx, + repo, err := NewRepositoriesStore(db.DB).Create(ctx, alice.ID, CreateRepoOptions{ Name: "example", @@ -440,7 +440,7 @@ func actionsListByUser(t *testing.T, ctx context.Context, db *actions) { func actionsMergePullRequest(t *testing.T, ctx context.Context, db *actions) { alice, err := NewUsersStore(db.DB).Create(ctx, "alice", "alice@example.com", CreateUserOptions{}) require.NoError(t, err) - repo, err := NewReposStore(db.DB).Create(ctx, + repo, err := NewRepositoriesStore(db.DB).Create(ctx, alice.ID, CreateRepoOptions{ Name: "example", @@ -485,7 +485,7 @@ func actionsMergePullRequest(t *testing.T, ctx context.Context, db *actions) { func actionsMirrorSyncCreate(t *testing.T, ctx context.Context, db *actions) { alice, err := NewUsersStore(db.DB).Create(ctx, "alice", "alice@example.com", CreateUserOptions{}) require.NoError(t, err) - repo, err := NewReposStore(db.DB).Create(ctx, + repo, err := NewRepositoriesStore(db.DB).Create(ctx, alice.ID, CreateRepoOptions{ Name: "example", @@ -526,7 +526,7 @@ func actionsMirrorSyncCreate(t *testing.T, ctx context.Context, db *actions) { func actionsMirrorSyncDelete(t *testing.T, ctx context.Context, db *actions) { alice, err := NewUsersStore(db.DB).Create(ctx, "alice", "alice@example.com", CreateUserOptions{}) require.NoError(t, err) - repo, err := NewReposStore(db.DB).Create(ctx, + repo, err := NewRepositoriesStore(db.DB).Create(ctx, alice.ID, CreateRepoOptions{ Name: "example", @@ -567,7 +567,7 @@ func actionsMirrorSyncDelete(t *testing.T, ctx context.Context, db *actions) { func actionsMirrorSyncPush(t *testing.T, ctx context.Context, db *actions) { alice, err := NewUsersStore(db.DB).Create(ctx, "alice", "alice@example.com", CreateUserOptions{}) require.NoError(t, err) - repo, err := NewReposStore(db.DB).Create(ctx, + repo, err := NewRepositoriesStore(db.DB).Create(ctx, alice.ID, CreateRepoOptions{ Name: "example", @@ -632,7 +632,7 @@ func actionsMirrorSyncPush(t *testing.T, ctx context.Context, db *actions) { func actionsNewRepo(t *testing.T, ctx context.Context, db *actions) { alice, err := NewUsersStore(db.DB).Create(ctx, "alice", "alice@example.com", CreateUserOptions{}) require.NoError(t, err) - repo, err := NewReposStore(db.DB).Create(ctx, + repo, err := NewRepositoriesStore(db.DB).Create(ctx, alice.ID, CreateRepoOptions{ Name: "example", @@ -711,7 +711,7 @@ func actionsPushTag(t *testing.T, ctx context.Context, db *actions) { alice, err := NewUsersStore(db.DB).Create(ctx, "alice", "alice@example.com", CreateUserOptions{}) require.NoError(t, err) - repo, err := NewReposStore(db.DB).Create(ctx, + repo, err := NewRepositoriesStore(db.DB).Create(ctx, alice.ID, CreateRepoOptions{ Name: "example", @@ -803,7 +803,7 @@ func actionsPushTag(t *testing.T, ctx context.Context, db *actions) { func actionsRenameRepo(t *testing.T, ctx context.Context, db *actions) { alice, err := NewUsersStore(db.DB).Create(ctx, "alice", "alice@example.com", CreateUserOptions{}) require.NoError(t, err) - repo, err := NewReposStore(db.DB).Create(ctx, + repo, err := NewRepositoriesStore(db.DB).Create(ctx, alice.ID, CreateRepoOptions{ Name: "example", @@ -842,7 +842,7 @@ func actionsTransferRepo(t *testing.T, ctx context.Context, db *actions) { require.NoError(t, err) bob, err := NewUsersStore(db.DB).Create(ctx, "bob", "bob@example.com", CreateUserOptions{}) require.NoError(t, err) - repo, err := NewReposStore(db.DB).Create(ctx, + repo, err := NewRepositoriesStore(db.DB).Create(ctx, alice.ID, CreateRepoOptions{ Name: "example", diff --git a/internal/db/db.go b/internal/db/db.go index e7dc31119..00f398479 100644 --- a/internal/db/db.go +++ b/internal/db/db.go @@ -127,9 +127,9 @@ func Init(w logger.Writer) (*gorm.DB, error) { LoginSources = &loginSources{DB: db, files: sourceFiles} LFS = &lfs{DB: db} Notices = NewNoticesStore(db) - Orgs = NewOrgsStore(db) + Organizations = NewOrganizationsStore(db) Perms = NewPermsStore(db) - Repos = NewReposStore(db) + Repositories = NewRepositoriesStore(db) TwoFactors = &twoFactors{DB: db} Users = NewUsersStore(db) diff --git a/internal/db/mocks.go b/internal/db/mocks.go index 89c3ed9c5..44aa01300 100644 --- a/internal/db/mocks.go +++ b/internal/db/mocks.go @@ -48,11 +48,11 @@ func SetMockPermsStore(t *testing.T, mock PermsStore) { }) } -func SetMockReposStore(t *testing.T, mock ReposStore) { - before := Repos - Repos = mock +func SetMockReposStore(t *testing.T, mock RepositoriesStore) { + before := Repositories + Repositories = mock t.Cleanup(func() { - Repos = before + Repositories = before }) } diff --git a/internal/db/models.go b/internal/db/models.go index ebbe5136d..f2082ee9d 100644 --- a/internal/db/models.go +++ b/internal/db/models.go @@ -211,7 +211,7 @@ type Statistic struct { func GetStatistic(ctx context.Context) (stats Statistic) { stats.Counter.User = Users.Count(ctx) - stats.Counter.Org = Orgs.Count(ctx) + stats.Counter.Org = Organizations.Count(ctx) stats.Counter.PublicKey, _ = x.Count(new(PublicKey)) stats.Counter.Repo = CountRepositories(true) stats.Counter.Watch, _ = x.Count(new(Watch)) diff --git a/internal/db/org.go b/internal/db/org.go index 4b780cdc6..f504993df 100644 --- a/internal/db/org.go +++ b/internal/db/org.go @@ -7,97 +7,11 @@ package db import ( "context" "fmt" - "os" - "strings" "xorm.io/builder" "xorm.io/xorm" - - "gogs.io/gogs/internal/errutil" - "gogs.io/gogs/internal/repoutil" - "gogs.io/gogs/internal/userutil" ) -// CreateOrganization creates record of a new organization. -func CreateOrganization(org, owner *User) (err error) { - if err = isUsernameAllowed(org.Name); err != nil { - return err - } - - if Users.IsUsernameUsed(context.TODO(), org.Name, 0) { - return ErrUserAlreadyExist{ - args: errutil.Args{ - "name": org.Name, - }, - } - } - - org.LowerName = strings.ToLower(org.Name) - if org.Rands, err = userutil.RandomSalt(); err != nil { - return err - } - if org.Salt, err = userutil.RandomSalt(); err != nil { - return err - } - org.UseCustomAvatar = true - org.MaxRepoCreation = -1 - org.NumTeams = 1 - org.NumMembers = 1 - - sess := x.NewSession() - defer sess.Close() - if err = sess.Begin(); err != nil { - return err - } - - if _, err = sess.Insert(org); err != nil { - return fmt.Errorf("insert organization: %v", err) - } - _ = userutil.GenerateRandomAvatar(org.ID, org.Name, org.Email) - - // Add initial creator to organization and owner team. - if _, err = sess.Insert(&OrgUser{ - UserID: owner.ID, - OrgID: org.ID, - IsOwner: true, - NumTeams: 1, - }); err != nil { - return fmt.Errorf("insert org-user relation: %v", err) - } - - // Create default owner team. - t := &Team{ - OrgID: org.ID, - LowerName: strings.ToLower(TeamNameOwners), - Name: TeamNameOwners, - Authorize: AccessModeOwner, - NumMembers: 1, - } - if _, err = sess.Insert(t); err != nil { - return fmt.Errorf("insert owner team: %v", err) - } - - if _, err = sess.Insert(&TeamUser{ - UID: owner.ID, - OrgID: org.ID, - TeamID: t.ID, - }); err != nil { - return fmt.Errorf("insert team-user relation: %v", err) - } - - if err = os.MkdirAll(repoutil.UserPath(org.Name), os.ModePerm); err != nil { - return fmt.Errorf("create directory: %v", err) - } - - return sess.Commit() -} - -// Organizations returns number of organizations in given page. -func Organizations(page, pageSize int) ([]*User, error) { - orgs := make([]*User, 0, pageSize) - return orgs, x.Limit(pageSize, (page-1)*pageSize).Where("type=1").Asc("id").Find(&orgs) -} - // deleteBeans deletes all given beans, beans should contain delete conditions. func deleteBeans(e Engine, beans ...any) (err error) { for i := range beans { diff --git a/internal/db/org_team.go b/internal/db/org_team.go index c79a38f33..05cbbf390 100644 --- a/internal/db/org_team.go +++ b/internal/db/org_team.go @@ -486,7 +486,7 @@ func AddTeamMember(orgID, teamID, userID int64) error { return nil } - if err := Orgs.AddMember(context.TODO(), orgID, userID); err != nil { + if err := Organizations.AddMember(context.TODO(), orgID, userID); err != nil { return err } diff --git a/internal/db/orgs.go b/internal/db/organizations.go similarity index 67% rename from internal/db/orgs.go rename to internal/db/organizations.go index 0550d07a3..8da12de71 100644 --- a/internal/db/orgs.go +++ b/internal/db/organizations.go @@ -7,6 +7,7 @@ package db import ( "context" "fmt" + "os" "strings" "github.com/pkg/errors" @@ -14,10 +15,32 @@ import ( "gogs.io/gogs/internal/dbutil" "gogs.io/gogs/internal/errutil" + "gogs.io/gogs/internal/repoutil" + "gogs.io/gogs/internal/userutil" ) -// OrgsStore is the persistent interface for organizations. -type OrgsStore interface { +// OrganizationsStore is the persistent interface for organizations. +type OrganizationsStore interface { + // Create creates a new organization with the initial owner and persists to + // database. It returns ErrNameNotAllowed if the given name or pattern of the + // name is not allowed as an organization name, or ErrOrganizationAlreadyExist + // when a user or an organization with same name already exists. + Create(ctx context.Context, name string, ownerID int64, opts CreateOrganizationOptions) (*Organization, error) + // GetByName returns the organization with given name. + GetByName(ctx context.Context, name string) (*Organization, error) + // SearchByName returns a list of organizations whose username or full name + // matches the given keyword case-insensitively. Results are paginated by given + // page and page size, and sorted by the given order (e.g. "id DESC"). A total + // count of all results is also returned. If the order is not given, it's up to + // the database to decide. + SearchByName(ctx context.Context, keyword string, page, pageSize int, orderBy string) ([]*Organization, int64, error) + // List returns a list of organizations filtered by options. + List(ctx context.Context, opts ListOrganizationsOptions) ([]*Organization, error) + // CountByUser returns the number of organizations the user is a member of. + CountByUser(ctx context.Context, userID int64) (int64, error) + // Count returns the total number of organizations. + Count(ctx context.Context) int64 + // AddMember adds a new member to the given organization. AddMember(ctx context.Context, orgID, userID int64) error // RemoveMember removes a member from the given organization. @@ -33,21 +56,6 @@ type OrgsStore interface { // SetMemberVisibility sets the visibility of the given user in the organization. SetMemberVisibility(ctx context.Context, orgID, userID int64, public bool) error - // GetByName returns the organization with given name. - GetByName(ctx context.Context, name string) (*Organization, error) - // SearchByName returns a list of organizations whose username or full name - // matches the given keyword case-insensitively. Results are paginated by given - // page and page size, and sorted by the given order (e.g. "id DESC"). A total - // count of all results is also returned. If the order is not given, it's up to - // the database to decide. - SearchByName(ctx context.Context, keyword string, page, pageSize int, orderBy string) ([]*Organization, int64, error) - // List returns a list of organizations filtered by options. - List(ctx context.Context, opts ListOrgsOptions) ([]*Organization, error) - // CountByUser returns the number of organizations the user is a member of. - CountByUser(ctx context.Context, userID int64) (int64, error) - // Count returns the total number of organizations. - Count(ctx context.Context) int64 - // GetTeamByName returns the team with given name under the given organization. // It returns ErrTeamNotExist whe not found. GetTeamByName(ctx context.Context, orgID int64, name string) (*Team, error) @@ -59,21 +67,21 @@ type OrgsStore interface { AccessibleRepositoriesByUser(ctx context.Context, orgID, userID int64, page, pageSize int, opts AccessibleRepositoriesByUserOptions) ([]*Repository, int64, error) } -var Orgs OrgsStore +var Organizations OrganizationsStore -var _ OrgsStore = (*orgs)(nil) +var _ OrganizationsStore = (*organizations)(nil) -type orgs struct { +type organizations struct { *gorm.DB } -// NewOrgsStore returns a persistent interface for orgs with given database -// connection. -func NewOrgsStore(db *gorm.DB) OrgsStore { - return &orgs{DB: db} +// NewOrganizationsStore returns a persistent interface for orgs with given +// database connection. +func NewOrganizationsStore(db *gorm.DB) OrganizationsStore { + return &organizations{DB: db} } -func (*orgs) recountMembers(tx *gorm.DB, orgID int64) error { +func (*organizations) recountMembers(tx *gorm.DB, orgID int64) error { /* Equivalent SQL for PostgreSQL: @@ -96,7 +104,7 @@ func (*orgs) recountMembers(tx *gorm.DB, orgID int64) error { return nil } -func (db *orgs) AddMember(ctx context.Context, orgID, userID int64) error { +func (db *organizations) AddMember(ctx context.Context, orgID, userID int64) error { return db.WithContext(ctx).Transaction(func(tx *gorm.DB) error { ou := &OrgUser{ UserID: userID, @@ -124,7 +132,7 @@ func (err ErrLastOrgOwner) Error() string { return fmt.Sprintf("user is the last owner of the organization: %v", err.args) } -func (db *orgs) RemoveMember(ctx context.Context, orgID, userID int64) error { +func (db *organizations) RemoveMember(ctx context.Context, orgID, userID int64) error { ou, err := db.getOrgUser(ctx, orgID, userID) if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { @@ -210,7 +218,7 @@ type accessibleRepositoriesByUserOptions struct { pageSize int } -func (*orgs) accessibleRepositoriesByUser(tx *gorm.DB, orgID, userID int64, opts accessibleRepositoriesByUserOptions) *gorm.DB { +func (*organizations) accessibleRepositoriesByUser(tx *gorm.DB, orgID, userID int64, opts accessibleRepositoriesByUserOptions) *gorm.DB { /* Equivalent SQL for PostgreSQL: @@ -252,7 +260,7 @@ type AccessibleRepositoriesByUserOptions struct { SkipCount bool } -func (db *orgs) AccessibleRepositoriesByUser(ctx context.Context, orgID, userID int64, page, pageSize int, opts AccessibleRepositoriesByUserOptions) ([]*Repository, int64, error) { +func (db *organizations) AccessibleRepositoriesByUser(ctx context.Context, orgID, userID int64, page, pageSize int, opts AccessibleRepositoriesByUserOptions) ([]*Repository, int64, error) { conds := db.accessibleRepositoriesByUser( db.DB, orgID, @@ -281,21 +289,21 @@ func (db *orgs) AccessibleRepositoriesByUser(ctx context.Context, orgID, userID return repos, count, nil } -func (db *orgs) getOrgUser(ctx context.Context, orgID, userID int64) (*OrgUser, error) { +func (db *organizations) getOrgUser(ctx context.Context, orgID, userID int64) (*OrgUser, error) { var ou OrgUser return &ou, db.WithContext(ctx).Where("org_id = ? AND uid = ?", orgID, userID).First(&ou).Error } -func (db *orgs) IsOwnedBy(ctx context.Context, orgID, userID int64) bool { +func (db *organizations) IsOwnedBy(ctx context.Context, orgID, userID int64) bool { ou, err := db.getOrgUser(ctx, orgID, userID) return err == nil && ou.IsOwner } -func (db *orgs) SetMemberVisibility(ctx context.Context, orgID, userID int64, public bool) error { +func (db *organizations) SetMemberVisibility(ctx context.Context, orgID, userID int64, public bool) error { return db.Table("org_user").Where("org_id = ? AND uid = ?", orgID, userID).UpdateColumn("is_public", public).Error } -func (db *orgs) HasMember(ctx context.Context, orgID, userID int64) (bool, bool) { +func (db *organizations) HasMember(ctx context.Context, orgID, userID int64) (bool, bool) { ou, err := db.getOrgUser(ctx, orgID, userID) return err == nil, ou != nil && ou.IsPublic } @@ -305,7 +313,7 @@ type ListOrgMembersOptions struct { Limit int } -func (db *orgs) ListMembers(ctx context.Context, orgID int64, opts ListOrgMembersOptions) ([]*User, error) { +func (db *organizations) ListMembers(ctx context.Context, orgID int64, opts ListOrgMembersOptions) ([]*User, error) { /* Equivalent SQL for PostgreSQL: @@ -327,14 +335,18 @@ func (db *orgs) ListMembers(ctx context.Context, orgID int64, opts ListOrgMember return users, conds.Find(&users).Error } -type ListOrgsOptions struct { +type ListOrganizationsOptions struct { // Filter by the membership with the given user ID. MemberID int64 // Whether to include private memberships. IncludePrivateMembers bool + // 1-based page number. + Page int + // Number of results per page. + PageSize int } -func (db *orgs) List(ctx context.Context, opts ListOrgsOptions) ([]*Organization, error) { +func (db *organizations) List(ctx context.Context, opts ListOrganizationsOptions) ([]*Organization, error) { if opts.MemberID <= 0 { return nil, errors.New("MemberID must be greater than 0") } @@ -343,24 +355,144 @@ func (db *orgs) List(ctx context.Context, opts ListOrgsOptions) ([]*Organization Equivalent SQL for PostgreSQL: SELECT * FROM "user" - JOIN org_user ON org_user.org_id = user.id + [JOIN org_user ON org_user.org_id = user.id] WHERE - org_user.uid = @memberID - [AND org_user.is_public = @includePrivateMembers] + type = @type + [AND org_user.uid = @memberID + AND org_user.is_public = @includePrivateMembers] ORDER BY user.id ASC + [LIMIT @limit OFFSET @offset] */ conds := db.WithContext(ctx). - Joins(dbutil.Quote("JOIN org_user ON org_user.org_id = %s.id", "user")). - Where("org_user.uid = ?", opts.MemberID). + Where("type = ?", UserTypeOrganization). Order(dbutil.Quote("%s.id ASC", "user")) + + if opts.MemberID > 0 || !opts.IncludePrivateMembers { + conds.Joins(dbutil.Quote("JOIN org_user ON org_user.org_id = %s.id", "user")) + } + if opts.MemberID > 0 { + conds.Where("org_user.uid = ?", opts.MemberID) + } if !opts.IncludePrivateMembers { conds.Where("org_user.is_public = ?", true) } + if opts.Page > 0 && opts.PageSize > 0 { + conds.Limit(opts.PageSize).Offset((opts.Page - 1) * opts.PageSize) + } var orgs []*Organization return orgs, conds.Find(&orgs).Error } +type CreateOrganizationOptions struct { + FullName string + Location string + Website string + Description string +} + +type ErrOrganizationAlreadyExist struct { + args errutil.Args +} + +// IsErrOrganizationAlreadyExist returns true if the underlying error has the +// type ErrOrganizationAlreadyExist. +func IsErrOrganizationAlreadyExist(err error) bool { + return errors.As(err, &ErrOrganizationAlreadyExist{}) +} + +func (err ErrOrganizationAlreadyExist) Error() string { + return fmt.Sprintf("organization already exists: %v", err.args) +} + +func (db *organizations) Create(ctx context.Context, name string, ownerID int64, opts CreateOrganizationOptions) (*Organization, error) { + err := isUsernameAllowed(name) + if err != nil { + return nil, err + } + + if Users.IsUsernameUsed(ctx, name, 0) { + return nil, ErrOrganizationAlreadyExist{ + args: errutil.Args{ + "name": name, + }, + } + } + + org := &Organization{ + LowerName: strings.ToLower(name), + Name: name, + FullName: opts.FullName, + Type: UserTypeOrganization, + Location: opts.Location, + Website: opts.Website, + MaxRepoCreation: -1, + IsActive: true, + UseCustomAvatar: true, + Description: opts.Description, + NumTeams: 1, // The default "owners" team + NumMembers: 1, // The initial owner + } + + org.Rands, err = userutil.RandomSalt() + if err != nil { + return nil, err + } + org.Salt, err = userutil.RandomSalt() + if err != nil { + return nil, err + } + + return org, db.WithContext(ctx).Transaction(func(tx *gorm.DB) error { + err := tx.Create(org).Error + if err != nil { + return errors.Wrap(err, "create organization") + } + + err = tx.Create(&OrgUser{ + UserID: ownerID, + OrgID: org.ID, + IsOwner: true, + NumTeams: 1, + }).Error + if err != nil { + return errors.Wrap(err, "create org-user relation") + } + + team := &Team{ + OrgID: org.ID, + LowerName: strings.ToLower(TeamNameOwners), + Name: TeamNameOwners, + Authorize: AccessModeOwner, + NumMembers: 1, + } + err = tx.Create(team).Error + if err != nil { + return errors.Wrap(err, "create owner team") + } + + err = tx.Create(&TeamUser{ + UID: ownerID, + OrgID: org.ID, + TeamID: team.ID, + }).Error + if err != nil { + return errors.Wrap(err, "create team-user relation") + } + + err = userutil.GenerateRandomAvatar(org.ID, org.Name, org.Email) + if err != nil { + return errors.Wrap(err, "generate organization avatar") + } + + err = os.MkdirAll(repoutil.UserPath(org.Name), os.ModePerm) + if err != nil { + return errors.Wrap(err, "create organization directory") + } + return nil + }) +} + var _ errutil.NotFound = (*ErrUserNotExist)(nil) type ErrOrganizationNotExist struct { @@ -381,7 +513,7 @@ func (ErrOrganizationNotExist) NotFound() bool { return true } -func (db *orgs) GetByName(ctx context.Context, name string) (*Organization, error) { +func (db *organizations) GetByName(ctx context.Context, name string) (*Organization, error) { org, err := getUserByUsername(ctx, db.DB, UserTypeOrganization, name) if err != nil { if IsErrUserNotExist(err) { @@ -392,16 +524,16 @@ func (db *orgs) GetByName(ctx context.Context, name string) (*Organization, erro return org, nil } -func (db *orgs) SearchByName(ctx context.Context, keyword string, page, pageSize int, orderBy string) ([]*Organization, int64, error) { +func (db *organizations) SearchByName(ctx context.Context, keyword string, page, pageSize int, orderBy string) ([]*Organization, int64, error) { return searchUserByName(ctx, db.DB, UserTypeOrganization, keyword, page, pageSize, orderBy) } -func (db *orgs) CountByUser(ctx context.Context, userID int64) (int64, error) { +func (db *organizations) CountByUser(ctx context.Context, userID int64) (int64, error) { var count int64 return count, db.WithContext(ctx).Model(&OrgUser{}).Where("uid = ?", userID).Count(&count).Error } -func (db *orgs) Count(ctx context.Context) int64 { +func (db *organizations) Count(ctx context.Context) int64 { var count int64 db.WithContext(ctx).Model(&User{}).Where("type = ?", UserTypeOrganization).Count(&count) return count @@ -425,7 +557,7 @@ func (ErrTeamNotExist) NotFound() bool { return true } -func (db *orgs) GetTeamByName(ctx context.Context, orgID int64, name string) (*Team, error) { +func (db *organizations) GetTeamByName(ctx context.Context, orgID int64, name string) (*Team, error) { var team Team err := db.WithContext(ctx).Where("org_id = ? AND lower_name = ?", orgID, strings.ToLower(name)).First(&team).Error if err != nil { @@ -448,7 +580,7 @@ func (u *Organization) TableName() string { // TODO(unknwon): This is also used in templates, which should be fixed by // having a dedicated type `template.Organization`. func (u *Organization) IsOwnedBy(userID int64) bool { - return Orgs.IsOwnedBy(context.TODO(), u.ID, userID) + return Organizations.IsOwnedBy(context.TODO(), u.ID, userID) } // OrgUser represents relations of organizations and their members. diff --git a/internal/db/orgs_test.go b/internal/db/organizations_test.go similarity index 92% rename from internal/db/orgs_test.go rename to internal/db/organizations_test.go index 64831c8a7..2ee0da09e 100644 --- a/internal/db/orgs_test.go +++ b/internal/db/organizations_test.go @@ -23,13 +23,13 @@ func TestOrgs(t *testing.T) { ctx := context.Background() tables := []any{new(User), new(EmailAddress), new(OrgUser)} - db := &orgs{ + db := &organizations{ DB: dbtest.NewDB(t, "orgs", tables...), } for _, tc := range []struct { name string - test func(t *testing.T, ctx context.Context, db *orgs) + test func(t *testing.T, ctx context.Context, db *organizations) }{ {"List", orgsList}, {"SearchByName", orgsSearchByName}, @@ -48,7 +48,7 @@ func TestOrgs(t *testing.T) { } } -func orgsList(t *testing.T, ctx context.Context, db *orgs) { +func orgsList(t *testing.T, ctx context.Context, db *organizations) { usersStore := NewUsersStore(db.DB) alice, err := usersStore.Create(ctx, "alice", "alice@example.com", CreateUserOptions{}) require.NoError(t, err) @@ -76,12 +76,12 @@ func orgsList(t *testing.T, ctx context.Context, db *orgs) { tests := []struct { name string - opts ListOrgsOptions + opts ListOrganizationsOptions wantOrgNames []string }{ { name: "only public memberships for a user", - opts: ListOrgsOptions{ + opts: ListOrganizationsOptions{ MemberID: alice.ID, IncludePrivateMembers: false, }, @@ -89,7 +89,7 @@ func orgsList(t *testing.T, ctx context.Context, db *orgs) { }, { name: "all memberships for a user", - opts: ListOrgsOptions{ + opts: ListOrganizationsOptions{ MemberID: alice.ID, IncludePrivateMembers: true, }, @@ -97,7 +97,7 @@ func orgsList(t *testing.T, ctx context.Context, db *orgs) { }, { name: "no membership for a non-existent user", - opts: ListOrgsOptions{ + opts: ListOrganizationsOptions{ MemberID: 404, IncludePrivateMembers: true, }, @@ -118,7 +118,7 @@ func orgsList(t *testing.T, ctx context.Context, db *orgs) { } } -func orgsSearchByName(t *testing.T, ctx context.Context, db *orgs) { +func orgsSearchByName(t *testing.T, ctx context.Context, db *organizations) { // TODO: Use Orgs.Create to replace SQL hack when the method is available. usersStore := NewUsersStore(db.DB) org1, err := usersStore.Create(ctx, "org1", "org1@example.com", CreateUserOptions{FullName: "Acme Corp"}) @@ -163,7 +163,7 @@ func orgsSearchByName(t *testing.T, ctx context.Context, db *orgs) { }) } -func orgsCountByUser(t *testing.T, ctx context.Context, db *orgs) { +func orgsCountByUser(t *testing.T, ctx context.Context, db *organizations) { // TODO: Use Orgs.Join to replace SQL hack when the method is available. err := db.Exec(`INSERT INTO org_user (uid, org_id) VALUES (?, ?)`, 1, 1).Error require.NoError(t, err) diff --git a/internal/db/repo.go b/internal/db/repo.go index 08040e5c9..184d9fb2e 100644 --- a/internal/db/repo.go +++ b/internal/db/repo.go @@ -798,7 +798,7 @@ func MigrateRepository(doer, owner *User, opts MigrateRepoOptions) (*Repository, wikiPath := WikiPath(owner.Name, opts.Name) if owner.IsOrganization() { - t, err := Orgs.GetTeamByName(context.TODO(), owner.ID, TeamNameOwners) + t, err := Organizations.GetTeamByName(context.TODO(), owner.ID, TeamNameOwners) if err != nil { return nil, err } @@ -1135,7 +1135,7 @@ func createRepository(e *xorm.Session, doer, owner *User, repo *Repository) (err if err != nil { return fmt.Errorf("IsRepositoryExist: %v", err) } else if has { - return ErrRepoAlreadyExist{args: errutil.Args{"ownerID": owner.ID, "name": repo.Name}} + return ErrRepositoryAlreadyExist{args: errutil.Args{"ownerID": owner.ID, "name": repo.Name}} } if _, err = e.Insert(repo); err != nil { @@ -1311,14 +1311,14 @@ func CountUserRepositories(userID int64, private bool) int64 { return countRepositories(userID, private) } -func Repositories(page, pageSize int) (_ []*Repository, err error) { +func ListRepositories(page, pageSize int) (_ []*Repository, err error) { repos := make([]*Repository, 0, pageSize) return repos, x.Limit(pageSize, (page-1)*pageSize).Asc("id").Find(&repos) } // RepositoriesWithUsers returns number of repos in given page. func RepositoriesWithUsers(page, pageSize int) (_ []*Repository, err error) { - repos, err := Repositories(page, pageSize) + repos, err := ListRepositories(page, pageSize) if err != nil { return nil, fmt.Errorf("Repositories: %v", err) } @@ -1379,7 +1379,7 @@ func TransferOwnership(doer *User, newOwnerName string, repo *Repository) error if err != nil { return fmt.Errorf("IsRepositoryExist: %v", err) } else if has { - return ErrRepoAlreadyExist{args: errutil.Args{"ownerName": newOwnerName, "name": repo.Name}} + return ErrRepositoryAlreadyExist{args: errutil.Args{"ownerName": newOwnerName, "name": repo.Name}} } sess := x.NewSession() @@ -1411,7 +1411,7 @@ func TransferOwnership(doer *User, newOwnerName string, repo *Repository) error for _, c := range collaborators { collaboration.UserID = c.ID if c.ID == newOwner.ID || - (newOwner.IsOrganization() && func() bool { member, _ := Orgs.HasMember(context.TODO(), newOwner.ID, c.ID); return member }()) { + (newOwner.IsOrganization() && func() bool { member, _ := Organizations.HasMember(context.TODO(), newOwner.ID, c.ID); return member }()) { if _, err = sess.Delete(collaboration); err != nil { return fmt.Errorf("remove collaborator '%d': %v", c.ID, err) } @@ -1552,7 +1552,7 @@ func ChangeRepositoryName(u *User, oldRepoName, newRepoName string) (err error) if err != nil { return fmt.Errorf("IsRepositoryExist: %v", err) } else if has { - return ErrRepoAlreadyExist{args: errutil.Args{"ownerID": u.ID, "name": newRepoName}} + return ErrRepositoryAlreadyExist{args: errutil.Args{"ownerID": u.ID, "name": newRepoName}} } repo, err := GetRepositoryByName(u.ID, oldRepoName) diff --git a/internal/db/repos.go b/internal/db/repositories.go similarity index 84% rename from internal/db/repos.go rename to internal/db/repositories.go index d7f53d612..c11a828b3 100644 --- a/internal/db/repos.go +++ b/internal/db/repositories.go @@ -18,11 +18,11 @@ import ( "gogs.io/gogs/internal/repoutil" ) -// ReposStore is the persistent interface for repositories. -type ReposStore interface { +// RepositoriesStore is the persistent interface for repositories. +type RepositoriesStore interface { // Create creates a new repository record in the database. It returns // ErrNameNotAllowed when the repository name is not allowed, or - // ErrRepoAlreadyExist when a repository with same name already exists for the + // ErrRepositoryAlreadyExist when a repository with same name already exists for the // owner. Create(ctx context.Context, ownerID int64, opts CreateRepoOptions) (*Repository, error) // GetByCollaboratorID returns a list of repositories that the given @@ -56,7 +56,7 @@ type ReposStore interface { HasForkedBy(ctx context.Context, repoID, userID int64) bool } -var Repos ReposStore +var Repositories RepositoriesStore // BeforeCreate implements the GORM create hook. func (r *Repository) BeforeCreate(tx *gorm.DB) error { @@ -119,28 +119,27 @@ func (r *Repository) APIFormat(owner *User, opts ...RepositoryAPIFormatOptions) } } -var _ ReposStore = (*repos)(nil) +var _ RepositoriesStore = (*repositories)(nil) -type repos struct { +type repositories struct { *gorm.DB } -// NewReposStore returns a persistent interface for repositories with given +// NewRepositoriesStore returns a persistent interface for repositories with given // database connection. -func NewReposStore(db *gorm.DB) ReposStore { - return &repos{DB: db} +func NewRepositoriesStore(db *gorm.DB) RepositoriesStore { + return &repositories{DB: db} } -type ErrRepoAlreadyExist struct { +type ErrRepositoryAlreadyExist struct { args errutil.Args } func IsErrRepoAlreadyExist(err error) bool { - _, ok := err.(ErrRepoAlreadyExist) - return ok + return errors.As(err, &ErrRepositoryAlreadyExist{}) } -func (err ErrRepoAlreadyExist) Error() string { +func (err ErrRepositoryAlreadyExist) Error() string { return fmt.Sprintf("repository already exists: %v", err.args) } @@ -157,7 +156,7 @@ type CreateRepoOptions struct { ForkID int64 } -func (db *repos) Create(ctx context.Context, ownerID int64, opts CreateRepoOptions) (*Repository, error) { +func (db *repositories) Create(ctx context.Context, ownerID int64, opts CreateRepoOptions) (*Repository, error) { err := isRepoNameAllowed(opts.Name) if err != nil { return nil, err @@ -165,7 +164,7 @@ func (db *repos) Create(ctx context.Context, ownerID int64, opts CreateRepoOptio _, err = db.GetByName(ctx, ownerID, opts.Name) if err == nil { - return nil, ErrRepoAlreadyExist{ + return nil, ErrRepositoryAlreadyExist{ args: errutil.Args{ "ownerID": ownerID, "name": opts.Name, @@ -195,7 +194,7 @@ func (db *repos) Create(ctx context.Context, ownerID int64, opts CreateRepoOptio return errors.Wrap(err, "create") } - err = NewReposStore(tx).Watch(ctx, ownerID, repo.ID) + err = NewRepositoriesStore(tx).Watch(ctx, ownerID, repo.ID) if err != nil { return errors.Wrap(err, "watch") } @@ -203,7 +202,7 @@ func (db *repos) Create(ctx context.Context, ownerID int64, opts CreateRepoOptio }) } -func (db *repos) GetByCollaboratorID(ctx context.Context, collaboratorID int64, limit int, orderBy string) ([]*Repository, error) { +func (db *repositories) GetByCollaboratorID(ctx context.Context, collaboratorID int64, limit int, orderBy string) ([]*Repository, error) { /* Equivalent SQL for PostgreSQL: @@ -223,7 +222,7 @@ func (db *repos) GetByCollaboratorID(ctx context.Context, collaboratorID int64, Error } -func (db *repos) GetByCollaboratorIDWithAccessMode(ctx context.Context, collaboratorID int64) (map[*Repository]AccessMode, error) { +func (db *repositories) GetByCollaboratorIDWithAccessMode(ctx context.Context, collaboratorID int64) (map[*Repository]AccessMode, error) { /* Equivalent SQL for PostgreSQL: @@ -274,7 +273,7 @@ func (ErrRepoNotExist) NotFound() bool { return true } -func (db *repos) GetByID(ctx context.Context, id int64) (*Repository, error) { +func (db *repositories) GetByID(ctx context.Context, id int64) (*Repository, error) { repo := new(Repository) err := db.WithContext(ctx).Where("id = ?", id).First(repo).Error if err != nil { @@ -286,7 +285,7 @@ func (db *repos) GetByID(ctx context.Context, id int64) (*Repository, error) { return repo, nil } -func (db *repos) GetByName(ctx context.Context, ownerID int64, name string) (*Repository, error) { +func (db *repositories) GetByName(ctx context.Context, ownerID int64, name string) (*Repository, error) { repo := new(Repository) err := db.WithContext(ctx). Where("owner_id = ? AND lower_name = ?", ownerID, strings.ToLower(name)). @@ -306,7 +305,7 @@ func (db *repos) GetByName(ctx context.Context, ownerID int64, name string) (*Re return repo, nil } -func (db *repos) recountStars(tx *gorm.DB, userID, repoID int64) error { +func (db *repositories) recountStars(tx *gorm.DB, userID, repoID int64) error { /* Equivalent SQL for PostgreSQL: @@ -349,7 +348,7 @@ func (db *repos) recountStars(tx *gorm.DB, userID, repoID int64) error { return nil } -func (db *repos) Star(ctx context.Context, userID, repoID int64) error { +func (db *repositories) Star(ctx context.Context, userID, repoID int64) error { return db.WithContext(ctx).Transaction(func(tx *gorm.DB) error { s := &Star{ UserID: userID, @@ -366,7 +365,7 @@ func (db *repos) Star(ctx context.Context, userID, repoID int64) error { }) } -func (db *repos) Touch(ctx context.Context, id int64) error { +func (db *repositories) Touch(ctx context.Context, id int64) error { return db.WithContext(ctx). Model(new(Repository)). Where("id = ?", id). @@ -377,12 +376,12 @@ func (db *repos) Touch(ctx context.Context, id int64) error { Error } -func (db *repos) ListWatches(ctx context.Context, repoID int64) ([]*Watch, error) { +func (db *repositories) ListWatches(ctx context.Context, repoID int64) ([]*Watch, error) { var watches []*Watch return watches, db.WithContext(ctx).Where("repo_id = ?", repoID).Find(&watches).Error } -func (db *repos) recountWatches(tx *gorm.DB, repoID int64) error { +func (db *repositories) recountWatches(tx *gorm.DB, repoID int64) error { /* Equivalent SQL for PostgreSQL: @@ -401,7 +400,7 @@ func (db *repos) recountWatches(tx *gorm.DB, repoID int64) error { Error } -func (db *repos) Watch(ctx context.Context, userID, repoID int64) error { +func (db *repositories) Watch(ctx context.Context, userID, repoID int64) error { return db.WithContext(ctx).Transaction(func(tx *gorm.DB) error { w := &Watch{ UserID: userID, @@ -418,7 +417,7 @@ func (db *repos) Watch(ctx context.Context, userID, repoID int64) error { }) } -func (db *repos) HasForkedBy(ctx context.Context, repoID, userID int64) bool { +func (db *repositories) HasForkedBy(ctx context.Context, repoID, userID int64) bool { var count int64 db.WithContext(ctx).Model(new(Repository)).Where("owner_id = ? AND fork_id = ?", userID, repoID).Count(&count) return count > 0 diff --git a/internal/db/repos_test.go b/internal/db/repositories_test.go similarity index 91% rename from internal/db/repos_test.go rename to internal/db/repositories_test.go index 7bb74f88a..ab0427ca0 100644 --- a/internal/db/repos_test.go +++ b/internal/db/repositories_test.go @@ -87,13 +87,13 @@ func TestRepos(t *testing.T) { ctx := context.Background() tables := []any{new(Repository), new(Access), new(Watch), new(User), new(EmailAddress), new(Star)} - db := &repos{ + db := &repositories{ DB: dbtest.NewDB(t, "repos", tables...), } for _, tc := range []struct { name string - test func(t *testing.T, ctx context.Context, db *repos) + test func(t *testing.T, ctx context.Context, db *repositories) }{ {"Create", reposCreate}, {"GetByCollaboratorID", reposGetByCollaboratorID}, @@ -119,7 +119,7 @@ func TestRepos(t *testing.T) { } } -func reposCreate(t *testing.T, ctx context.Context, db *repos) { +func reposCreate(t *testing.T, ctx context.Context, db *repositories) { t.Run("name not allowed", func(t *testing.T) { _, err := db.Create(ctx, 1, @@ -144,7 +144,7 @@ func reposCreate(t *testing.T, ctx context.Context, db *repos) { Name: "repo1", }, ) - wantErr := ErrRepoAlreadyExist{args: errutil.Args{"ownerID": int64(2), "name": "repo1"}} + wantErr := ErrRepositoryAlreadyExist{args: errutil.Args{"ownerID": int64(2), "name": "repo1"}} assert.Equal(t, wantErr, err) }) @@ -161,7 +161,7 @@ func reposCreate(t *testing.T, ctx context.Context, db *repos) { assert.Equal(t, 1, repo.NumWatches) // The owner is watching the repo by default. } -func reposGetByCollaboratorID(t *testing.T, ctx context.Context, db *repos) { +func reposGetByCollaboratorID(t *testing.T, ctx context.Context, db *repositories) { repo1, err := db.Create(ctx, 1, CreateRepoOptions{Name: "repo1"}) require.NoError(t, err) repo2, err := db.Create(ctx, 2, CreateRepoOptions{Name: "repo2"}) @@ -187,7 +187,7 @@ func reposGetByCollaboratorID(t *testing.T, ctx context.Context, db *repos) { }) } -func reposGetByCollaboratorIDWithAccessMode(t *testing.T, ctx context.Context, db *repos) { +func reposGetByCollaboratorIDWithAccessMode(t *testing.T, ctx context.Context, db *repositories) { repo1, err := db.Create(ctx, 1, CreateRepoOptions{Name: "repo1"}) require.NoError(t, err) repo2, err := db.Create(ctx, 2, CreateRepoOptions{Name: "repo2"}) @@ -215,7 +215,7 @@ func reposGetByCollaboratorIDWithAccessMode(t *testing.T, ctx context.Context, d assert.Equal(t, AccessModeAdmin, accessModes[repo2.ID]) } -func reposGetByID(t *testing.T, ctx context.Context, db *repos) { +func reposGetByID(t *testing.T, ctx context.Context, db *repositories) { repo1, err := db.Create(ctx, 1, CreateRepoOptions{Name: "repo1"}) require.NoError(t, err) @@ -228,7 +228,7 @@ func reposGetByID(t *testing.T, ctx context.Context, db *repos) { assert.Equal(t, wantErr, err) } -func reposGetByName(t *testing.T, ctx context.Context, db *repos) { +func reposGetByName(t *testing.T, ctx context.Context, db *repositories) { repo, err := db.Create(ctx, 1, CreateRepoOptions{ Name: "repo1", @@ -244,7 +244,7 @@ func reposGetByName(t *testing.T, ctx context.Context, db *repos) { assert.Equal(t, wantErr, err) } -func reposStar(t *testing.T, ctx context.Context, db *repos) { +func reposStar(t *testing.T, ctx context.Context, db *repositories) { repo1, err := db.Create(ctx, 1, CreateRepoOptions{Name: "repo1"}) require.NoError(t, err) usersStore := NewUsersStore(db.DB) @@ -263,7 +263,7 @@ func reposStar(t *testing.T, ctx context.Context, db *repos) { assert.Equal(t, 1, alice.NumStars) } -func reposTouch(t *testing.T, ctx context.Context, db *repos) { +func reposTouch(t *testing.T, ctx context.Context, db *repositories) { repo, err := db.Create(ctx, 1, CreateRepoOptions{ Name: "repo1", @@ -289,7 +289,7 @@ func reposTouch(t *testing.T, ctx context.Context, db *repos) { assert.False(t, got.IsBare) } -func reposListWatches(t *testing.T, ctx context.Context, db *repos) { +func reposListWatches(t *testing.T, ctx context.Context, db *repositories) { err := db.Watch(ctx, 1, 1) require.NoError(t, err) err = db.Watch(ctx, 2, 1) @@ -310,9 +310,8 @@ func reposListWatches(t *testing.T, ctx context.Context, db *repos) { assert.Equal(t, want, got) } -func reposWatch(t *testing.T, ctx context.Context, db *repos) { - reposStore := NewReposStore(db.DB) - repo1, err := reposStore.Create(ctx, 1, CreateRepoOptions{Name: "repo1"}) +func reposWatch(t *testing.T, ctx context.Context, db *repositories) { + repo1, err := db.Create(ctx, 1, CreateRepoOptions{Name: "repo1"}) require.NoError(t, err) err = db.Watch(ctx, 2, repo1.ID) @@ -322,16 +321,16 @@ func reposWatch(t *testing.T, ctx context.Context, db *repos) { err = db.Watch(ctx, 2, repo1.ID) require.NoError(t, err) - repo1, err = reposStore.GetByID(ctx, repo1.ID) + repo1, err = db.GetByID(ctx, repo1.ID) require.NoError(t, err) assert.Equal(t, 2, repo1.NumWatches) // The owner is watching the repo by default. } -func reposHasForkedBy(t *testing.T, ctx context.Context, db *repos) { +func reposHasForkedBy(t *testing.T, ctx context.Context, db *repositories) { has := db.HasForkedBy(ctx, 1, 2) assert.False(t, has) - _, err := NewReposStore(db.DB).Create( + _, err := NewRepositoriesStore(db.DB).Create( ctx, 2, CreateRepoOptions{ diff --git a/internal/db/users.go b/internal/db/users.go index d82d8727c..68170c943 100644 --- a/internal/db/users.go +++ b/internal/db/users.go @@ -48,8 +48,9 @@ type UsersStore interface { Authenticate(ctx context.Context, username, password string, loginSourceID int64) (*User, error) // Create creates a new user and persists to database. It returns // ErrNameNotAllowed if the given name or pattern of the name is not allowed as - // a username, or ErrUserAlreadyExist when a user with same name already exists, - // or ErrEmailAlreadyUsed if the email has been verified by another user. + // a username, or ErrUserAlreadyExist when a user or an organization with same + // name already exists, or ErrEmailAlreadyUsed if the email has been verified by + // another user. Create(ctx context.Context, username, email string, opts CreateUserOptions) (*User, error) // GetByEmail returns the user (not organization) with given email. It ignores @@ -362,8 +363,7 @@ type ErrUserAlreadyExist struct { // IsErrUserAlreadyExist returns true if the underlying error has the type // ErrUserAlreadyExist. func IsErrUserAlreadyExist(err error) bool { - _, ok := errors.Cause(err).(ErrUserAlreadyExist) - return ok + return errors.As(err, &ErrUserAlreadyExist{}) } func (err ErrUserAlreadyExist) Error() string { @@ -377,8 +377,7 @@ type ErrEmailAlreadyUsed struct { // IsErrEmailAlreadyUsed returns true if the underlying error has the type // ErrEmailAlreadyUsed. func IsErrEmailAlreadyUsed(err error) bool { - _, ok := errors.Cause(err).(ErrEmailAlreadyUsed) - return ok + return errors.As(err, &ErrEmailAlreadyUsed{}) } func (err ErrEmailAlreadyUsed) Email() string { @@ -880,11 +879,13 @@ func (db *users) IsUsernameUsed(ctx context.Context, username string, excludeUse if username == "" { return false } - return db.WithContext(ctx). + + err := db.WithContext(ctx). Select("id"). Where("lower_name = ? AND id != ?", strings.ToLower(username), excludeUserId). First(&User{}). - Error != gorm.ErrRecordNotFound + Error + return !errors.Is(err, gorm.ErrRecordNotFound) } func (db *users) List(ctx context.Context, page, pageSize int) ([]*User, error) { @@ -1479,7 +1480,7 @@ func (u *User) IsFollowing(followID int64) bool { // TODO(unknwon): This is also used in templates, which should be fixed by // having a dedicated type `template.User`. func (u *User) IsUserOrgOwner(orgID int64) bool { - return Orgs.IsOwnedBy(context.TODO(), orgID, u.ID) + return Organizations.IsOwnedBy(context.TODO(), orgID, u.ID) } // IsPublicMember returns true if the user has public membership of the given @@ -1488,7 +1489,7 @@ func (u *User) IsUserOrgOwner(orgID int64) bool { // TODO(unknwon): This is also used in templates, which should be fixed by // having a dedicated type `template.User`. func (u *User) IsPublicMember(orgID int64) bool { - _, public := Orgs.HasMember(context.TODO(), orgID, u.ID) + _, public := Organizations.HasMember(context.TODO(), orgID, u.ID) return public } @@ -1498,7 +1499,7 @@ func (u *User) IsPublicMember(orgID int64) bool { // TODO(unknwon): This is also used in templates, which should be fixed by // having a dedicated type `template.User`. func (u *User) GetOrganizationCount() (int64, error) { - return Orgs.CountByUser(context.TODO(), u.ID) + return Organizations.CountByUser(context.TODO(), u.ID) } // ShortName truncates and returns the username at most in given length. diff --git a/internal/db/users_test.go b/internal/db/users_test.go index b964a2c77..9e9a0f79c 100644 --- a/internal/db/users_test.go +++ b/internal/db/users_test.go @@ -299,7 +299,7 @@ func usersChangeUsername(t *testing.T, ctx context.Context, db *users) { require.NoError(t, err) defer func() { _ = os.RemoveAll(tempServerAppDataPath) }() - repo, err := NewReposStore(db.DB).Create( + repo, err := NewRepositoriesStore(db.DB).Create( ctx, alice.ID, CreateRepoOptions{ @@ -471,7 +471,7 @@ func usersDeleteCustomAvatar(t *testing.T, ctx context.Context, db *users) { } func usersDeleteByID(t *testing.T, ctx context.Context, db *users) { - reposStore := NewReposStore(db.DB) + reposStore := NewRepositoriesStore(db.DB) t.Run("user still has repository ownership", func(t *testing.T) { alice, err := db.Create(ctx, "alice", "alice@exmaple.com", CreateUserOptions{}) @@ -684,7 +684,7 @@ func usersDeleteInactivated(t *testing.T, ctx context.Context, db *users) { // User with repository ownership should be skipped alice, err := db.Create(ctx, "alice", "alice@exmaple.com", CreateUserOptions{}) require.NoError(t, err) - reposStore := NewReposStore(db.DB) + reposStore := NewRepositoriesStore(db.DB) _, err = reposStore.Create(ctx, alice.ID, CreateRepoOptions{Name: "repo1"}) require.NoError(t, err) @@ -815,7 +815,7 @@ func usersGetByUsername(t *testing.T, ctx context.Context, db *users) { }) t.Run("wrong user type", func(t *testing.T) { - // org1,err:=NewOrgsStore(db.DB).Create(ctx,"org1","// TODO: Use Orgs.Create + // org1,err:=NewOrganizationsStore(db.DB).Create(ctx,"org1","// TODO: Use Orgs.Create }) } diff --git a/internal/route/admin/orgs.go b/internal/route/admin/orgs.go index 46a26b422..b36276c91 100644 --- a/internal/route/admin/orgs.go +++ b/internal/route/admin/orgs.go @@ -24,9 +24,15 @@ func Organizations(c *context.Context) { route.RenderUserSearch(c, &route.UserSearchOptions{ Type: db.UserTypeOrganization, - Counter: db.Orgs.Count, - Ranger: func(_ gocontext.Context, page, pageSize int) ([]*db.User, error) { - return db.Organizations(page, pageSize) + Counter: db.Organizations.Count, + Ranger: func(ctx gocontext.Context, page, pageSize int) ([]*db.User, error) { + return db.Organizations.List( + ctx, + db.ListOrganizationsOptions{ + Page: page, + PageSize: pageSize, + }, + ) }, PageSize: conf.UI.Admin.OrgPagingNum, OrderBy: "id ASC", diff --git a/internal/route/admin/repos.go b/internal/route/admin/repos.go index 5ae8f7496..cbeb27d8b 100644 --- a/internal/route/admin/repos.go +++ b/internal/route/admin/repos.go @@ -35,7 +35,7 @@ func Repos(c *context.Context) { keyword := c.Query("q") if keyword == "" { - repos, err = db.Repositories(page, conf.UI.Admin.RepoPagingNum) + repos, err = db.ListRepositories(page, conf.UI.Admin.RepoPagingNum) if err != nil { c.Error(err, "list repositories") return diff --git a/internal/route/api/v1/api.go b/internal/route/api/v1/api.go index 79d346fe6..8cb877a6d 100644 --- a/internal/route/api/v1/api.go +++ b/internal/route/api/v1/api.go @@ -45,7 +45,7 @@ func repoAssignment() macaron.Handler { } c.Repo.Owner = owner - repo, err := db.Repos.GetByName(c.Req.Context(), owner.ID, reponame) + repo, err := db.Repositories.GetByName(c.Req.Context(), owner.ID, reponame) if err != nil { c.NotFoundOrError(err, "get repository by name") return diff --git a/internal/route/api/v1/org/org.go b/internal/route/api/v1/org/org.go index e6f2a192c..440ad5559 100644 --- a/internal/route/api/v1/org/org.go +++ b/internal/route/api/v1/org/org.go @@ -20,17 +20,19 @@ func CreateOrgForUser(c *context.APIContext, apiForm api.CreateOrgOption, user * return } - org := &db.User{ - Name: apiForm.UserName, - FullName: apiForm.FullName, - Description: apiForm.Description, - Website: apiForm.Website, - Location: apiForm.Location, - IsActive: true, - Type: db.UserTypeOrganization, - } - if err := db.CreateOrganization(org, user); err != nil { - if db.IsErrUserAlreadyExist(err) || + org, err := db.Organizations.Create( + c.Req.Context(), + apiForm.UserName, + user.ID, + db.CreateOrganizationOptions{ + FullName: apiForm.FullName, + Location: apiForm.Location, + Website: apiForm.Website, + Description: apiForm.Description, + }, + ) + if err != nil { + if db.IsErrOrganizationAlreadyExist(err) || db.IsErrNameNotAllowed(err) { c.ErrorStatus(http.StatusUnprocessableEntity, err) } else { @@ -39,13 +41,13 @@ func CreateOrgForUser(c *context.APIContext, apiForm api.CreateOrgOption, user * return } - c.JSON(201, convert.ToOrganization(org)) + c.JSON(http.StatusCreated, convert.ToOrganization(org)) } func listUserOrgs(c *context.APIContext, u *db.User, all bool) { - orgs, err := db.Orgs.List( + orgs, err := db.Organizations.List( c.Req.Context(), - db.ListOrgsOptions{ + db.ListOrganizationsOptions{ MemberID: u.ID, IncludePrivateMembers: all, }, @@ -104,7 +106,7 @@ func Edit(c *context.APIContext, form api.EditOrgOption) { return } - org, err = db.Orgs.GetByName(c.Req.Context(), org.Name) + org, err = db.Organizations.GetByName(c.Req.Context(), org.Name) if err != nil { c.Error(err, "get organization") return diff --git a/internal/route/api/v1/repo/repo.go b/internal/route/api/v1/repo/repo.go index d16ff84bb..bb14dfe80 100644 --- a/internal/route/api/v1/repo/repo.go +++ b/internal/route/api/v1/repo/repo.go @@ -87,7 +87,7 @@ func listUserRepositories(c *context.APIContext, username string) { // or an organization isn't a member of. var ownRepos []*db.Repository if user.IsOrganization() { - ownRepos, _, err = db.Orgs.AccessibleRepositoriesByUser( + ownRepos, _, err = db.Organizations.AccessibleRepositoriesByUser( c.Req.Context(), user.ID, c.User.ID, @@ -123,7 +123,7 @@ func listUserRepositories(c *context.APIContext, username string) { return } - accessibleRepos, err := db.Repos.GetByCollaboratorIDWithAccessMode(c.Req.Context(), user.ID) + accessibleRepos, err := db.Repositories.GetByCollaboratorIDWithAccessMode(c.Req.Context(), user.ID) if err != nil { c.Error(err, "get repositories accesses by collaborator") return @@ -198,7 +198,7 @@ func Create(c *context.APIContext, opt api.CreateRepoOption) { } func CreateOrgRepo(c *context.APIContext, opt api.CreateRepoOption) { - org, err := db.Orgs.GetByName(c.Req.Context(), c.Params(":org")) + org, err := db.Organizations.GetByName(c.Req.Context(), c.Params(":org")) if err != nil { c.NotFoundOrError(err, "get organization by name") return diff --git a/internal/route/home.go b/internal/route/home.go index 183222891..b1a5a7a9f 100644 --- a/internal/route/home.go +++ b/internal/route/home.go @@ -115,7 +115,7 @@ func RenderUserSearch(c *context.Context, opts *UserSearchOptions) { } else { search := db.Users.SearchByName if opts.Type == db.UserTypeOrganization { - search = db.Orgs.SearchByName + search = db.Organizations.SearchByName } users, count, err = search(c.Req.Context(), keyword, page, opts.PageSize, opts.OrderBy) if err != nil { @@ -153,9 +153,15 @@ func ExploreOrganizations(c *context.Context) { RenderUserSearch(c, &UserSearchOptions{ Type: db.UserTypeOrganization, - Counter: db.Orgs.Count, - Ranger: func(_ gocontext.Context, page, pageSize int) ([]*db.User, error) { - return db.Organizations(page, pageSize) + Counter: db.Organizations.Count, + Ranger: func(ctx gocontext.Context, page, pageSize int) ([]*db.User, error) { + return db.Organizations.List( + ctx, + db.ListOrganizationsOptions{ + Page: page, + PageSize: pageSize, + }, + ) }, PageSize: conf.UI.ExplorePagingNum, OrderBy: "updated_unix DESC", diff --git a/internal/route/lfs/mocks_test.go b/internal/route/lfs/mocks_test.go index b313ce553..5bf992554 100644 --- a/internal/route/lfs/mocks_test.go +++ b/internal/route/lfs/mocks_test.go @@ -1489,92 +1489,94 @@ func (c PermsStoreSetRepoPermsFuncCall) Results() []interface{} { return []interface{}{c.Result0} } -// MockReposStore is a mock implementation of the ReposStore interface (from -// the package gogs.io/gogs/internal/db) used for unit testing. -type MockReposStore struct { +// MockRepositoriesStore is a mock implementation of the RepositoriesStore +// interface (from the package gogs.io/gogs/internal/db) used for unit +// testing. +type MockRepositoriesStore struct { // CreateFunc is an instance of a mock function object controlling the // behavior of the method Create. - CreateFunc *ReposStoreCreateFunc + CreateFunc *RepositoriesStoreCreateFunc // GetByCollaboratorIDFunc is an instance of a mock function object // controlling the behavior of the method GetByCollaboratorID. - GetByCollaboratorIDFunc *ReposStoreGetByCollaboratorIDFunc + GetByCollaboratorIDFunc *RepositoriesStoreGetByCollaboratorIDFunc // GetByCollaboratorIDWithAccessModeFunc is an instance of a mock // function object controlling the behavior of the method // GetByCollaboratorIDWithAccessMode. - GetByCollaboratorIDWithAccessModeFunc *ReposStoreGetByCollaboratorIDWithAccessModeFunc + GetByCollaboratorIDWithAccessModeFunc *RepositoriesStoreGetByCollaboratorIDWithAccessModeFunc // GetByIDFunc is an instance of a mock function object controlling the // behavior of the method GetByID. - GetByIDFunc *ReposStoreGetByIDFunc + GetByIDFunc *RepositoriesStoreGetByIDFunc // GetByNameFunc is an instance of a mock function object controlling // the behavior of the method GetByName. - GetByNameFunc *ReposStoreGetByNameFunc + GetByNameFunc *RepositoriesStoreGetByNameFunc // HasForkedByFunc is an instance of a mock function object controlling // the behavior of the method HasForkedBy. - HasForkedByFunc *ReposStoreHasForkedByFunc + HasForkedByFunc *RepositoriesStoreHasForkedByFunc // ListWatchesFunc is an instance of a mock function object controlling // the behavior of the method ListWatches. - ListWatchesFunc *ReposStoreListWatchesFunc + ListWatchesFunc *RepositoriesStoreListWatchesFunc // StarFunc is an instance of a mock function object controlling the // behavior of the method Star. - StarFunc *ReposStoreStarFunc + StarFunc *RepositoriesStoreStarFunc // TouchFunc is an instance of a mock function object controlling the // behavior of the method Touch. - TouchFunc *ReposStoreTouchFunc + TouchFunc *RepositoriesStoreTouchFunc // WatchFunc is an instance of a mock function object controlling the // behavior of the method Watch. - WatchFunc *ReposStoreWatchFunc + WatchFunc *RepositoriesStoreWatchFunc } -// NewMockReposStore creates a new mock of the ReposStore interface. All -// methods return zero values for all results, unless overwritten. -func NewMockReposStore() *MockReposStore { - return &MockReposStore{ - CreateFunc: &ReposStoreCreateFunc{ +// NewMockRepositoriesStore creates a new mock of the RepositoriesStore +// interface. All methods return zero values for all results, unless +// overwritten. +func NewMockRepositoriesStore() *MockRepositoriesStore { + return &MockRepositoriesStore{ + CreateFunc: &RepositoriesStoreCreateFunc{ defaultHook: func(context.Context, int64, db.CreateRepoOptions) (r0 *db.Repository, r1 error) { return }, }, - GetByCollaboratorIDFunc: &ReposStoreGetByCollaboratorIDFunc{ + GetByCollaboratorIDFunc: &RepositoriesStoreGetByCollaboratorIDFunc{ defaultHook: func(context.Context, int64, int, string) (r0 []*db.Repository, r1 error) { return }, }, - GetByCollaboratorIDWithAccessModeFunc: &ReposStoreGetByCollaboratorIDWithAccessModeFunc{ + GetByCollaboratorIDWithAccessModeFunc: &RepositoriesStoreGetByCollaboratorIDWithAccessModeFunc{ defaultHook: func(context.Context, int64) (r0 map[*db.Repository]db.AccessMode, r1 error) { return }, }, - GetByIDFunc: &ReposStoreGetByIDFunc{ + GetByIDFunc: &RepositoriesStoreGetByIDFunc{ defaultHook: func(context.Context, int64) (r0 *db.Repository, r1 error) { return }, }, - GetByNameFunc: &ReposStoreGetByNameFunc{ + GetByNameFunc: &RepositoriesStoreGetByNameFunc{ defaultHook: func(context.Context, int64, string) (r0 *db.Repository, r1 error) { return }, }, - HasForkedByFunc: &ReposStoreHasForkedByFunc{ + HasForkedByFunc: &RepositoriesStoreHasForkedByFunc{ defaultHook: func(context.Context, int64, int64) (r0 bool) { return }, }, - ListWatchesFunc: &ReposStoreListWatchesFunc{ + ListWatchesFunc: &RepositoriesStoreListWatchesFunc{ defaultHook: func(context.Context, int64) (r0 []*db.Watch, r1 error) { return }, }, - StarFunc: &ReposStoreStarFunc{ + StarFunc: &RepositoriesStoreStarFunc{ defaultHook: func(context.Context, int64, int64) (r0 error) { return }, }, - TouchFunc: &ReposStoreTouchFunc{ + TouchFunc: &RepositoriesStoreTouchFunc{ defaultHook: func(context.Context, int64) (r0 error) { return }, }, - WatchFunc: &ReposStoreWatchFunc{ + WatchFunc: &RepositoriesStoreWatchFunc{ defaultHook: func(context.Context, int64, int64) (r0 error) { return }, @@ -1582,128 +1584,131 @@ func NewMockReposStore() *MockReposStore { } } -// NewStrictMockReposStore creates a new mock of the ReposStore interface. -// All methods panic on invocation, unless overwritten. -func NewStrictMockReposStore() *MockReposStore { - return &MockReposStore{ - CreateFunc: &ReposStoreCreateFunc{ +// NewStrictMockRepositoriesStore creates a new mock of the +// RepositoriesStore interface. All methods panic on invocation, unless +// overwritten. +func NewStrictMockRepositoriesStore() *MockRepositoriesStore { + return &MockRepositoriesStore{ + CreateFunc: &RepositoriesStoreCreateFunc{ defaultHook: func(context.Context, int64, db.CreateRepoOptions) (*db.Repository, error) { - panic("unexpected invocation of MockReposStore.Create") + panic("unexpected invocation of MockRepositoriesStore.Create") }, }, - GetByCollaboratorIDFunc: &ReposStoreGetByCollaboratorIDFunc{ + GetByCollaboratorIDFunc: &RepositoriesStoreGetByCollaboratorIDFunc{ defaultHook: func(context.Context, int64, int, string) ([]*db.Repository, error) { - panic("unexpected invocation of MockReposStore.GetByCollaboratorID") + panic("unexpected invocation of MockRepositoriesStore.GetByCollaboratorID") }, }, - GetByCollaboratorIDWithAccessModeFunc: &ReposStoreGetByCollaboratorIDWithAccessModeFunc{ + GetByCollaboratorIDWithAccessModeFunc: &RepositoriesStoreGetByCollaboratorIDWithAccessModeFunc{ defaultHook: func(context.Context, int64) (map[*db.Repository]db.AccessMode, error) { - panic("unexpected invocation of MockReposStore.GetByCollaboratorIDWithAccessMode") + panic("unexpected invocation of MockRepositoriesStore.GetByCollaboratorIDWithAccessMode") }, }, - GetByIDFunc: &ReposStoreGetByIDFunc{ + GetByIDFunc: &RepositoriesStoreGetByIDFunc{ defaultHook: func(context.Context, int64) (*db.Repository, error) { - panic("unexpected invocation of MockReposStore.GetByID") + panic("unexpected invocation of MockRepositoriesStore.GetByID") }, }, - GetByNameFunc: &ReposStoreGetByNameFunc{ + GetByNameFunc: &RepositoriesStoreGetByNameFunc{ defaultHook: func(context.Context, int64, string) (*db.Repository, error) { - panic("unexpected invocation of MockReposStore.GetByName") + panic("unexpected invocation of MockRepositoriesStore.GetByName") }, }, - HasForkedByFunc: &ReposStoreHasForkedByFunc{ + HasForkedByFunc: &RepositoriesStoreHasForkedByFunc{ defaultHook: func(context.Context, int64, int64) bool { - panic("unexpected invocation of MockReposStore.HasForkedBy") + panic("unexpected invocation of MockRepositoriesStore.HasForkedBy") }, }, - ListWatchesFunc: &ReposStoreListWatchesFunc{ + ListWatchesFunc: &RepositoriesStoreListWatchesFunc{ defaultHook: func(context.Context, int64) ([]*db.Watch, error) { - panic("unexpected invocation of MockReposStore.ListWatches") + panic("unexpected invocation of MockRepositoriesStore.ListWatches") }, }, - StarFunc: &ReposStoreStarFunc{ + StarFunc: &RepositoriesStoreStarFunc{ defaultHook: func(context.Context, int64, int64) error { - panic("unexpected invocation of MockReposStore.Star") + panic("unexpected invocation of MockRepositoriesStore.Star") }, }, - TouchFunc: &ReposStoreTouchFunc{ + TouchFunc: &RepositoriesStoreTouchFunc{ defaultHook: func(context.Context, int64) error { - panic("unexpected invocation of MockReposStore.Touch") + panic("unexpected invocation of MockRepositoriesStore.Touch") }, }, - WatchFunc: &ReposStoreWatchFunc{ + WatchFunc: &RepositoriesStoreWatchFunc{ defaultHook: func(context.Context, int64, int64) error { - panic("unexpected invocation of MockReposStore.Watch") + panic("unexpected invocation of MockRepositoriesStore.Watch") }, }, } } -// NewMockReposStoreFrom creates a new mock of the MockReposStore interface. -// All methods delegate to the given implementation, unless overwritten. -func NewMockReposStoreFrom(i db.ReposStore) *MockReposStore { - return &MockReposStore{ - CreateFunc: &ReposStoreCreateFunc{ +// NewMockRepositoriesStoreFrom creates a new mock of the +// MockRepositoriesStore interface. All methods delegate to the given +// implementation, unless overwritten. +func NewMockRepositoriesStoreFrom(i db.RepositoriesStore) *MockRepositoriesStore { + return &MockRepositoriesStore{ + CreateFunc: &RepositoriesStoreCreateFunc{ defaultHook: i.Create, }, - GetByCollaboratorIDFunc: &ReposStoreGetByCollaboratorIDFunc{ + GetByCollaboratorIDFunc: &RepositoriesStoreGetByCollaboratorIDFunc{ defaultHook: i.GetByCollaboratorID, }, - GetByCollaboratorIDWithAccessModeFunc: &ReposStoreGetByCollaboratorIDWithAccessModeFunc{ + GetByCollaboratorIDWithAccessModeFunc: &RepositoriesStoreGetByCollaboratorIDWithAccessModeFunc{ defaultHook: i.GetByCollaboratorIDWithAccessMode, }, - GetByIDFunc: &ReposStoreGetByIDFunc{ + GetByIDFunc: &RepositoriesStoreGetByIDFunc{ defaultHook: i.GetByID, }, - GetByNameFunc: &ReposStoreGetByNameFunc{ + GetByNameFunc: &RepositoriesStoreGetByNameFunc{ defaultHook: i.GetByName, }, - HasForkedByFunc: &ReposStoreHasForkedByFunc{ + HasForkedByFunc: &RepositoriesStoreHasForkedByFunc{ defaultHook: i.HasForkedBy, }, - ListWatchesFunc: &ReposStoreListWatchesFunc{ + ListWatchesFunc: &RepositoriesStoreListWatchesFunc{ defaultHook: i.ListWatches, }, - StarFunc: &ReposStoreStarFunc{ + StarFunc: &RepositoriesStoreStarFunc{ defaultHook: i.Star, }, - TouchFunc: &ReposStoreTouchFunc{ + TouchFunc: &RepositoriesStoreTouchFunc{ defaultHook: i.Touch, }, - WatchFunc: &ReposStoreWatchFunc{ + WatchFunc: &RepositoriesStoreWatchFunc{ defaultHook: i.Watch, }, } } -// ReposStoreCreateFunc describes the behavior when the Create method of the -// parent MockReposStore instance is invoked. -type ReposStoreCreateFunc struct { +// RepositoriesStoreCreateFunc describes the behavior when the Create method +// of the parent MockRepositoriesStore instance is invoked. +type RepositoriesStoreCreateFunc struct { defaultHook func(context.Context, int64, db.CreateRepoOptions) (*db.Repository, error) hooks []func(context.Context, int64, db.CreateRepoOptions) (*db.Repository, error) - history []ReposStoreCreateFuncCall + history []RepositoriesStoreCreateFuncCall mutex sync.Mutex } // Create delegates to the next hook function in the queue and stores the // parameter and result values of this invocation. -func (m *MockReposStore) Create(v0 context.Context, v1 int64, v2 db.CreateRepoOptions) (*db.Repository, error) { +func (m *MockRepositoriesStore) Create(v0 context.Context, v1 int64, v2 db.CreateRepoOptions) (*db.Repository, error) { r0, r1 := m.CreateFunc.nextHook()(v0, v1, v2) - m.CreateFunc.appendCall(ReposStoreCreateFuncCall{v0, v1, v2, r0, r1}) + m.CreateFunc.appendCall(RepositoriesStoreCreateFuncCall{v0, v1, v2, r0, r1}) return r0, r1 } // SetDefaultHook sets function that is called when the Create method of the -// parent MockReposStore instance is invoked and the hook queue is empty. -func (f *ReposStoreCreateFunc) SetDefaultHook(hook func(context.Context, int64, db.CreateRepoOptions) (*db.Repository, error)) { +// parent MockRepositoriesStore instance is invoked and the hook queue is +// empty. +func (f *RepositoriesStoreCreateFunc) SetDefaultHook(hook func(context.Context, int64, db.CreateRepoOptions) (*db.Repository, error)) { f.defaultHook = hook } // PushHook adds a function to the end of hook queue. Each invocation of the -// Create method of the parent MockReposStore instance invokes the hook at -// the front of the queue and discards it. After the queue is empty, the -// default hook function is invoked for any future action. -func (f *ReposStoreCreateFunc) PushHook(hook func(context.Context, int64, db.CreateRepoOptions) (*db.Repository, error)) { +// Create method of the parent MockRepositoriesStore instance invokes the +// hook at the front of the queue and discards it. After the queue is empty, +// the default hook function is invoked for any future action. +func (f *RepositoriesStoreCreateFunc) PushHook(hook func(context.Context, int64, db.CreateRepoOptions) (*db.Repository, error)) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -1711,20 +1716,20 @@ func (f *ReposStoreCreateFunc) PushHook(hook func(context.Context, int64, db.Cre // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. -func (f *ReposStoreCreateFunc) SetDefaultReturn(r0 *db.Repository, r1 error) { +func (f *RepositoriesStoreCreateFunc) SetDefaultReturn(r0 *db.Repository, r1 error) { f.SetDefaultHook(func(context.Context, int64, db.CreateRepoOptions) (*db.Repository, error) { return r0, r1 }) } // PushReturn calls PushHook with a function that returns the given values. -func (f *ReposStoreCreateFunc) PushReturn(r0 *db.Repository, r1 error) { +func (f *RepositoriesStoreCreateFunc) PushReturn(r0 *db.Repository, r1 error) { f.PushHook(func(context.Context, int64, db.CreateRepoOptions) (*db.Repository, error) { return r0, r1 }) } -func (f *ReposStoreCreateFunc) nextHook() func(context.Context, int64, db.CreateRepoOptions) (*db.Repository, error) { +func (f *RepositoriesStoreCreateFunc) nextHook() func(context.Context, int64, db.CreateRepoOptions) (*db.Repository, error) { f.mutex.Lock() defer f.mutex.Unlock() @@ -1737,26 +1742,26 @@ func (f *ReposStoreCreateFunc) nextHook() func(context.Context, int64, db.Create return hook } -func (f *ReposStoreCreateFunc) appendCall(r0 ReposStoreCreateFuncCall) { +func (f *RepositoriesStoreCreateFunc) appendCall(r0 RepositoriesStoreCreateFuncCall) { f.mutex.Lock() f.history = append(f.history, r0) f.mutex.Unlock() } -// History returns a sequence of ReposStoreCreateFuncCall objects describing -// the invocations of this function. -func (f *ReposStoreCreateFunc) History() []ReposStoreCreateFuncCall { +// History returns a sequence of RepositoriesStoreCreateFuncCall objects +// describing the invocations of this function. +func (f *RepositoriesStoreCreateFunc) History() []RepositoriesStoreCreateFuncCall { f.mutex.Lock() - history := make([]ReposStoreCreateFuncCall, len(f.history)) + history := make([]RepositoriesStoreCreateFuncCall, len(f.history)) copy(history, f.history) f.mutex.Unlock() return history } -// ReposStoreCreateFuncCall is an object that describes an invocation of -// method Create on an instance of MockReposStore. -type ReposStoreCreateFuncCall struct { +// RepositoriesStoreCreateFuncCall is an object that describes an invocation +// of method Create on an instance of MockRepositoriesStore. +type RepositoriesStoreCreateFuncCall struct { // Arg0 is the value of the 1st argument passed to this method // invocation. Arg0 context.Context @@ -1776,46 +1781,47 @@ type ReposStoreCreateFuncCall struct { // Args returns an interface slice containing the arguments of this // invocation. -func (c ReposStoreCreateFuncCall) Args() []interface{} { +func (c RepositoriesStoreCreateFuncCall) Args() []interface{} { return []interface{}{c.Arg0, c.Arg1, c.Arg2} } // Results returns an interface slice containing the results of this // invocation. -func (c ReposStoreCreateFuncCall) Results() []interface{} { +func (c RepositoriesStoreCreateFuncCall) Results() []interface{} { return []interface{}{c.Result0, c.Result1} } -// ReposStoreGetByCollaboratorIDFunc describes the behavior when the -// GetByCollaboratorID method of the parent MockReposStore instance is -// invoked. -type ReposStoreGetByCollaboratorIDFunc struct { +// RepositoriesStoreGetByCollaboratorIDFunc describes the behavior when the +// GetByCollaboratorID method of the parent MockRepositoriesStore instance +// is invoked. +type RepositoriesStoreGetByCollaboratorIDFunc struct { defaultHook func(context.Context, int64, int, string) ([]*db.Repository, error) hooks []func(context.Context, int64, int, string) ([]*db.Repository, error) - history []ReposStoreGetByCollaboratorIDFuncCall + history []RepositoriesStoreGetByCollaboratorIDFuncCall mutex sync.Mutex } // GetByCollaboratorID delegates to the next hook function in the queue and // stores the parameter and result values of this invocation. -func (m *MockReposStore) GetByCollaboratorID(v0 context.Context, v1 int64, v2 int, v3 string) ([]*db.Repository, error) { +func (m *MockRepositoriesStore) GetByCollaboratorID(v0 context.Context, v1 int64, v2 int, v3 string) ([]*db.Repository, error) { r0, r1 := m.GetByCollaboratorIDFunc.nextHook()(v0, v1, v2, v3) - m.GetByCollaboratorIDFunc.appendCall(ReposStoreGetByCollaboratorIDFuncCall{v0, v1, v2, v3, r0, r1}) + m.GetByCollaboratorIDFunc.appendCall(RepositoriesStoreGetByCollaboratorIDFuncCall{v0, v1, v2, v3, r0, r1}) return r0, r1 } // SetDefaultHook sets function that is called when the GetByCollaboratorID -// method of the parent MockReposStore instance is invoked and the hook -// queue is empty. -func (f *ReposStoreGetByCollaboratorIDFunc) SetDefaultHook(hook func(context.Context, int64, int, string) ([]*db.Repository, error)) { +// method of the parent MockRepositoriesStore instance is invoked and the +// hook queue is empty. +func (f *RepositoriesStoreGetByCollaboratorIDFunc) SetDefaultHook(hook func(context.Context, int64, int, string) ([]*db.Repository, error)) { f.defaultHook = hook } // PushHook adds a function to the end of hook queue. Each invocation of the -// GetByCollaboratorID method of the parent MockReposStore instance invokes -// the hook at the front of the queue and discards it. After the queue is -// empty, the default hook function is invoked for any future action. -func (f *ReposStoreGetByCollaboratorIDFunc) PushHook(hook func(context.Context, int64, int, string) ([]*db.Repository, error)) { +// GetByCollaboratorID method of the parent MockRepositoriesStore instance +// invokes the hook at the front of the queue and discards it. After the +// queue is empty, the default hook function is invoked for any future +// action. +func (f *RepositoriesStoreGetByCollaboratorIDFunc) PushHook(hook func(context.Context, int64, int, string) ([]*db.Repository, error)) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -1823,20 +1829,20 @@ func (f *ReposStoreGetByCollaboratorIDFunc) PushHook(hook func(context.Context, // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. -func (f *ReposStoreGetByCollaboratorIDFunc) SetDefaultReturn(r0 []*db.Repository, r1 error) { +func (f *RepositoriesStoreGetByCollaboratorIDFunc) SetDefaultReturn(r0 []*db.Repository, r1 error) { f.SetDefaultHook(func(context.Context, int64, int, string) ([]*db.Repository, error) { return r0, r1 }) } // PushReturn calls PushHook with a function that returns the given values. -func (f *ReposStoreGetByCollaboratorIDFunc) PushReturn(r0 []*db.Repository, r1 error) { +func (f *RepositoriesStoreGetByCollaboratorIDFunc) PushReturn(r0 []*db.Repository, r1 error) { f.PushHook(func(context.Context, int64, int, string) ([]*db.Repository, error) { return r0, r1 }) } -func (f *ReposStoreGetByCollaboratorIDFunc) nextHook() func(context.Context, int64, int, string) ([]*db.Repository, error) { +func (f *RepositoriesStoreGetByCollaboratorIDFunc) nextHook() func(context.Context, int64, int, string) ([]*db.Repository, error) { f.mutex.Lock() defer f.mutex.Unlock() @@ -1849,27 +1855,28 @@ func (f *ReposStoreGetByCollaboratorIDFunc) nextHook() func(context.Context, int return hook } -func (f *ReposStoreGetByCollaboratorIDFunc) appendCall(r0 ReposStoreGetByCollaboratorIDFuncCall) { +func (f *RepositoriesStoreGetByCollaboratorIDFunc) appendCall(r0 RepositoriesStoreGetByCollaboratorIDFuncCall) { f.mutex.Lock() f.history = append(f.history, r0) f.mutex.Unlock() } -// History returns a sequence of ReposStoreGetByCollaboratorIDFuncCall -// objects describing the invocations of this function. -func (f *ReposStoreGetByCollaboratorIDFunc) History() []ReposStoreGetByCollaboratorIDFuncCall { +// History returns a sequence of +// RepositoriesStoreGetByCollaboratorIDFuncCall objects describing the +// invocations of this function. +func (f *RepositoriesStoreGetByCollaboratorIDFunc) History() []RepositoriesStoreGetByCollaboratorIDFuncCall { f.mutex.Lock() - history := make([]ReposStoreGetByCollaboratorIDFuncCall, len(f.history)) + history := make([]RepositoriesStoreGetByCollaboratorIDFuncCall, len(f.history)) copy(history, f.history) f.mutex.Unlock() return history } -// ReposStoreGetByCollaboratorIDFuncCall is an object that describes an -// invocation of method GetByCollaboratorID on an instance of -// MockReposStore. -type ReposStoreGetByCollaboratorIDFuncCall struct { +// RepositoriesStoreGetByCollaboratorIDFuncCall is an object that describes +// an invocation of method GetByCollaboratorID on an instance of +// MockRepositoriesStore. +type RepositoriesStoreGetByCollaboratorIDFuncCall struct { // Arg0 is the value of the 1st argument passed to this method // invocation. Arg0 context.Context @@ -1892,47 +1899,47 @@ type ReposStoreGetByCollaboratorIDFuncCall struct { // Args returns an interface slice containing the arguments of this // invocation. -func (c ReposStoreGetByCollaboratorIDFuncCall) Args() []interface{} { +func (c RepositoriesStoreGetByCollaboratorIDFuncCall) Args() []interface{} { return []interface{}{c.Arg0, c.Arg1, c.Arg2, c.Arg3} } // Results returns an interface slice containing the results of this // invocation. -func (c ReposStoreGetByCollaboratorIDFuncCall) Results() []interface{} { +func (c RepositoriesStoreGetByCollaboratorIDFuncCall) Results() []interface{} { return []interface{}{c.Result0, c.Result1} } -// ReposStoreGetByCollaboratorIDWithAccessModeFunc describes the behavior -// when the GetByCollaboratorIDWithAccessMode method of the parent -// MockReposStore instance is invoked. -type ReposStoreGetByCollaboratorIDWithAccessModeFunc struct { +// RepositoriesStoreGetByCollaboratorIDWithAccessModeFunc describes the +// behavior when the GetByCollaboratorIDWithAccessMode method of the parent +// MockRepositoriesStore instance is invoked. +type RepositoriesStoreGetByCollaboratorIDWithAccessModeFunc struct { defaultHook func(context.Context, int64) (map[*db.Repository]db.AccessMode, error) hooks []func(context.Context, int64) (map[*db.Repository]db.AccessMode, error) - history []ReposStoreGetByCollaboratorIDWithAccessModeFuncCall + history []RepositoriesStoreGetByCollaboratorIDWithAccessModeFuncCall mutex sync.Mutex } // GetByCollaboratorIDWithAccessMode delegates to the next hook function in // the queue and stores the parameter and result values of this invocation. -func (m *MockReposStore) GetByCollaboratorIDWithAccessMode(v0 context.Context, v1 int64) (map[*db.Repository]db.AccessMode, error) { +func (m *MockRepositoriesStore) GetByCollaboratorIDWithAccessMode(v0 context.Context, v1 int64) (map[*db.Repository]db.AccessMode, error) { r0, r1 := m.GetByCollaboratorIDWithAccessModeFunc.nextHook()(v0, v1) - m.GetByCollaboratorIDWithAccessModeFunc.appendCall(ReposStoreGetByCollaboratorIDWithAccessModeFuncCall{v0, v1, r0, r1}) + m.GetByCollaboratorIDWithAccessModeFunc.appendCall(RepositoriesStoreGetByCollaboratorIDWithAccessModeFuncCall{v0, v1, r0, r1}) return r0, r1 } // SetDefaultHook sets function that is called when the -// GetByCollaboratorIDWithAccessMode method of the parent MockReposStore -// instance is invoked and the hook queue is empty. -func (f *ReposStoreGetByCollaboratorIDWithAccessModeFunc) SetDefaultHook(hook func(context.Context, int64) (map[*db.Repository]db.AccessMode, error)) { +// GetByCollaboratorIDWithAccessMode method of the parent +// MockRepositoriesStore instance is invoked and the hook queue is empty. +func (f *RepositoriesStoreGetByCollaboratorIDWithAccessModeFunc) SetDefaultHook(hook func(context.Context, int64) (map[*db.Repository]db.AccessMode, error)) { f.defaultHook = hook } // PushHook adds a function to the end of hook queue. Each invocation of the -// GetByCollaboratorIDWithAccessMode method of the parent MockReposStore -// instance invokes the hook at the front of the queue and discards it. -// After the queue is empty, the default hook function is invoked for any -// future action. -func (f *ReposStoreGetByCollaboratorIDWithAccessModeFunc) PushHook(hook func(context.Context, int64) (map[*db.Repository]db.AccessMode, error)) { +// GetByCollaboratorIDWithAccessMode method of the parent +// MockRepositoriesStore instance invokes the hook at the front of the queue +// and discards it. After the queue is empty, the default hook function is +// invoked for any future action. +func (f *RepositoriesStoreGetByCollaboratorIDWithAccessModeFunc) PushHook(hook func(context.Context, int64) (map[*db.Repository]db.AccessMode, error)) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -1940,20 +1947,20 @@ func (f *ReposStoreGetByCollaboratorIDWithAccessModeFunc) PushHook(hook func(con // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. -func (f *ReposStoreGetByCollaboratorIDWithAccessModeFunc) SetDefaultReturn(r0 map[*db.Repository]db.AccessMode, r1 error) { +func (f *RepositoriesStoreGetByCollaboratorIDWithAccessModeFunc) SetDefaultReturn(r0 map[*db.Repository]db.AccessMode, r1 error) { f.SetDefaultHook(func(context.Context, int64) (map[*db.Repository]db.AccessMode, error) { return r0, r1 }) } // PushReturn calls PushHook with a function that returns the given values. -func (f *ReposStoreGetByCollaboratorIDWithAccessModeFunc) PushReturn(r0 map[*db.Repository]db.AccessMode, r1 error) { +func (f *RepositoriesStoreGetByCollaboratorIDWithAccessModeFunc) PushReturn(r0 map[*db.Repository]db.AccessMode, r1 error) { f.PushHook(func(context.Context, int64) (map[*db.Repository]db.AccessMode, error) { return r0, r1 }) } -func (f *ReposStoreGetByCollaboratorIDWithAccessModeFunc) nextHook() func(context.Context, int64) (map[*db.Repository]db.AccessMode, error) { +func (f *RepositoriesStoreGetByCollaboratorIDWithAccessModeFunc) nextHook() func(context.Context, int64) (map[*db.Repository]db.AccessMode, error) { f.mutex.Lock() defer f.mutex.Unlock() @@ -1966,28 +1973,28 @@ func (f *ReposStoreGetByCollaboratorIDWithAccessModeFunc) nextHook() func(contex return hook } -func (f *ReposStoreGetByCollaboratorIDWithAccessModeFunc) appendCall(r0 ReposStoreGetByCollaboratorIDWithAccessModeFuncCall) { +func (f *RepositoriesStoreGetByCollaboratorIDWithAccessModeFunc) appendCall(r0 RepositoriesStoreGetByCollaboratorIDWithAccessModeFuncCall) { f.mutex.Lock() f.history = append(f.history, r0) f.mutex.Unlock() } // History returns a sequence of -// ReposStoreGetByCollaboratorIDWithAccessModeFuncCall objects describing -// the invocations of this function. -func (f *ReposStoreGetByCollaboratorIDWithAccessModeFunc) History() []ReposStoreGetByCollaboratorIDWithAccessModeFuncCall { +// RepositoriesStoreGetByCollaboratorIDWithAccessModeFuncCall objects +// describing the invocations of this function. +func (f *RepositoriesStoreGetByCollaboratorIDWithAccessModeFunc) History() []RepositoriesStoreGetByCollaboratorIDWithAccessModeFuncCall { f.mutex.Lock() - history := make([]ReposStoreGetByCollaboratorIDWithAccessModeFuncCall, len(f.history)) + history := make([]RepositoriesStoreGetByCollaboratorIDWithAccessModeFuncCall, len(f.history)) copy(history, f.history) f.mutex.Unlock() return history } -// ReposStoreGetByCollaboratorIDWithAccessModeFuncCall is an object that -// describes an invocation of method GetByCollaboratorIDWithAccessMode on an -// instance of MockReposStore. -type ReposStoreGetByCollaboratorIDWithAccessModeFuncCall struct { +// RepositoriesStoreGetByCollaboratorIDWithAccessModeFuncCall is an object +// that describes an invocation of method GetByCollaboratorIDWithAccessMode +// on an instance of MockRepositoriesStore. +type RepositoriesStoreGetByCollaboratorIDWithAccessModeFuncCall struct { // Arg0 is the value of the 1st argument passed to this method // invocation. Arg0 context.Context @@ -2004,45 +2011,45 @@ type ReposStoreGetByCollaboratorIDWithAccessModeFuncCall struct { // Args returns an interface slice containing the arguments of this // invocation. -func (c ReposStoreGetByCollaboratorIDWithAccessModeFuncCall) Args() []interface{} { +func (c RepositoriesStoreGetByCollaboratorIDWithAccessModeFuncCall) Args() []interface{} { return []interface{}{c.Arg0, c.Arg1} } // Results returns an interface slice containing the results of this // invocation. -func (c ReposStoreGetByCollaboratorIDWithAccessModeFuncCall) Results() []interface{} { +func (c RepositoriesStoreGetByCollaboratorIDWithAccessModeFuncCall) Results() []interface{} { return []interface{}{c.Result0, c.Result1} } -// ReposStoreGetByIDFunc describes the behavior when the GetByID method of -// the parent MockReposStore instance is invoked. -type ReposStoreGetByIDFunc struct { +// RepositoriesStoreGetByIDFunc describes the behavior when the GetByID +// method of the parent MockRepositoriesStore instance is invoked. +type RepositoriesStoreGetByIDFunc struct { defaultHook func(context.Context, int64) (*db.Repository, error) hooks []func(context.Context, int64) (*db.Repository, error) - history []ReposStoreGetByIDFuncCall + history []RepositoriesStoreGetByIDFuncCall mutex sync.Mutex } // GetByID delegates to the next hook function in the queue and stores the // parameter and result values of this invocation. -func (m *MockReposStore) GetByID(v0 context.Context, v1 int64) (*db.Repository, error) { +func (m *MockRepositoriesStore) GetByID(v0 context.Context, v1 int64) (*db.Repository, error) { r0, r1 := m.GetByIDFunc.nextHook()(v0, v1) - m.GetByIDFunc.appendCall(ReposStoreGetByIDFuncCall{v0, v1, r0, r1}) + m.GetByIDFunc.appendCall(RepositoriesStoreGetByIDFuncCall{v0, v1, r0, r1}) return r0, r1 } // SetDefaultHook sets function that is called when the GetByID method of -// the parent MockReposStore instance is invoked and the hook queue is -// empty. -func (f *ReposStoreGetByIDFunc) SetDefaultHook(hook func(context.Context, int64) (*db.Repository, error)) { +// the parent MockRepositoriesStore instance is invoked and the hook queue +// is empty. +func (f *RepositoriesStoreGetByIDFunc) SetDefaultHook(hook func(context.Context, int64) (*db.Repository, error)) { f.defaultHook = hook } // PushHook adds a function to the end of hook queue. Each invocation of the -// GetByID method of the parent MockReposStore instance invokes the hook at -// the front of the queue and discards it. After the queue is empty, the -// default hook function is invoked for any future action. -func (f *ReposStoreGetByIDFunc) PushHook(hook func(context.Context, int64) (*db.Repository, error)) { +// GetByID method of the parent MockRepositoriesStore instance invokes the +// hook at the front of the queue and discards it. After the queue is empty, +// the default hook function is invoked for any future action. +func (f *RepositoriesStoreGetByIDFunc) PushHook(hook func(context.Context, int64) (*db.Repository, error)) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -2050,20 +2057,20 @@ func (f *ReposStoreGetByIDFunc) PushHook(hook func(context.Context, int64) (*db. // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. -func (f *ReposStoreGetByIDFunc) SetDefaultReturn(r0 *db.Repository, r1 error) { +func (f *RepositoriesStoreGetByIDFunc) SetDefaultReturn(r0 *db.Repository, r1 error) { f.SetDefaultHook(func(context.Context, int64) (*db.Repository, error) { return r0, r1 }) } // PushReturn calls PushHook with a function that returns the given values. -func (f *ReposStoreGetByIDFunc) PushReturn(r0 *db.Repository, r1 error) { +func (f *RepositoriesStoreGetByIDFunc) PushReturn(r0 *db.Repository, r1 error) { f.PushHook(func(context.Context, int64) (*db.Repository, error) { return r0, r1 }) } -func (f *ReposStoreGetByIDFunc) nextHook() func(context.Context, int64) (*db.Repository, error) { +func (f *RepositoriesStoreGetByIDFunc) nextHook() func(context.Context, int64) (*db.Repository, error) { f.mutex.Lock() defer f.mutex.Unlock() @@ -2076,26 +2083,26 @@ func (f *ReposStoreGetByIDFunc) nextHook() func(context.Context, int64) (*db.Rep return hook } -func (f *ReposStoreGetByIDFunc) appendCall(r0 ReposStoreGetByIDFuncCall) { +func (f *RepositoriesStoreGetByIDFunc) appendCall(r0 RepositoriesStoreGetByIDFuncCall) { f.mutex.Lock() f.history = append(f.history, r0) f.mutex.Unlock() } -// History returns a sequence of ReposStoreGetByIDFuncCall objects +// History returns a sequence of RepositoriesStoreGetByIDFuncCall objects // describing the invocations of this function. -func (f *ReposStoreGetByIDFunc) History() []ReposStoreGetByIDFuncCall { +func (f *RepositoriesStoreGetByIDFunc) History() []RepositoriesStoreGetByIDFuncCall { f.mutex.Lock() - history := make([]ReposStoreGetByIDFuncCall, len(f.history)) + history := make([]RepositoriesStoreGetByIDFuncCall, len(f.history)) copy(history, f.history) f.mutex.Unlock() return history } -// ReposStoreGetByIDFuncCall is an object that describes an invocation of -// method GetByID on an instance of MockReposStore. -type ReposStoreGetByIDFuncCall struct { +// RepositoriesStoreGetByIDFuncCall is an object that describes an +// invocation of method GetByID on an instance of MockRepositoriesStore. +type RepositoriesStoreGetByIDFuncCall struct { // Arg0 is the value of the 1st argument passed to this method // invocation. Arg0 context.Context @@ -2112,45 +2119,45 @@ type ReposStoreGetByIDFuncCall struct { // Args returns an interface slice containing the arguments of this // invocation. -func (c ReposStoreGetByIDFuncCall) Args() []interface{} { +func (c RepositoriesStoreGetByIDFuncCall) Args() []interface{} { return []interface{}{c.Arg0, c.Arg1} } // Results returns an interface slice containing the results of this // invocation. -func (c ReposStoreGetByIDFuncCall) Results() []interface{} { +func (c RepositoriesStoreGetByIDFuncCall) Results() []interface{} { return []interface{}{c.Result0, c.Result1} } -// ReposStoreGetByNameFunc describes the behavior when the GetByName method -// of the parent MockReposStore instance is invoked. -type ReposStoreGetByNameFunc struct { +// RepositoriesStoreGetByNameFunc describes the behavior when the GetByName +// method of the parent MockRepositoriesStore instance is invoked. +type RepositoriesStoreGetByNameFunc struct { defaultHook func(context.Context, int64, string) (*db.Repository, error) hooks []func(context.Context, int64, string) (*db.Repository, error) - history []ReposStoreGetByNameFuncCall + history []RepositoriesStoreGetByNameFuncCall mutex sync.Mutex } // GetByName delegates to the next hook function in the queue and stores the // parameter and result values of this invocation. -func (m *MockReposStore) GetByName(v0 context.Context, v1 int64, v2 string) (*db.Repository, error) { +func (m *MockRepositoriesStore) GetByName(v0 context.Context, v1 int64, v2 string) (*db.Repository, error) { r0, r1 := m.GetByNameFunc.nextHook()(v0, v1, v2) - m.GetByNameFunc.appendCall(ReposStoreGetByNameFuncCall{v0, v1, v2, r0, r1}) + m.GetByNameFunc.appendCall(RepositoriesStoreGetByNameFuncCall{v0, v1, v2, r0, r1}) return r0, r1 } // SetDefaultHook sets function that is called when the GetByName method of -// the parent MockReposStore instance is invoked and the hook queue is -// empty. -func (f *ReposStoreGetByNameFunc) SetDefaultHook(hook func(context.Context, int64, string) (*db.Repository, error)) { +// the parent MockRepositoriesStore instance is invoked and the hook queue +// is empty. +func (f *RepositoriesStoreGetByNameFunc) SetDefaultHook(hook func(context.Context, int64, string) (*db.Repository, error)) { f.defaultHook = hook } // PushHook adds a function to the end of hook queue. Each invocation of the -// GetByName method of the parent MockReposStore instance invokes the hook -// at the front of the queue and discards it. After the queue is empty, the -// default hook function is invoked for any future action. -func (f *ReposStoreGetByNameFunc) PushHook(hook func(context.Context, int64, string) (*db.Repository, error)) { +// GetByName method of the parent MockRepositoriesStore instance invokes the +// hook at the front of the queue and discards it. After the queue is empty, +// the default hook function is invoked for any future action. +func (f *RepositoriesStoreGetByNameFunc) PushHook(hook func(context.Context, int64, string) (*db.Repository, error)) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -2158,20 +2165,20 @@ func (f *ReposStoreGetByNameFunc) PushHook(hook func(context.Context, int64, str // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. -func (f *ReposStoreGetByNameFunc) SetDefaultReturn(r0 *db.Repository, r1 error) { +func (f *RepositoriesStoreGetByNameFunc) SetDefaultReturn(r0 *db.Repository, r1 error) { f.SetDefaultHook(func(context.Context, int64, string) (*db.Repository, error) { return r0, r1 }) } // PushReturn calls PushHook with a function that returns the given values. -func (f *ReposStoreGetByNameFunc) PushReturn(r0 *db.Repository, r1 error) { +func (f *RepositoriesStoreGetByNameFunc) PushReturn(r0 *db.Repository, r1 error) { f.PushHook(func(context.Context, int64, string) (*db.Repository, error) { return r0, r1 }) } -func (f *ReposStoreGetByNameFunc) nextHook() func(context.Context, int64, string) (*db.Repository, error) { +func (f *RepositoriesStoreGetByNameFunc) nextHook() func(context.Context, int64, string) (*db.Repository, error) { f.mutex.Lock() defer f.mutex.Unlock() @@ -2184,26 +2191,26 @@ func (f *ReposStoreGetByNameFunc) nextHook() func(context.Context, int64, string return hook } -func (f *ReposStoreGetByNameFunc) appendCall(r0 ReposStoreGetByNameFuncCall) { +func (f *RepositoriesStoreGetByNameFunc) appendCall(r0 RepositoriesStoreGetByNameFuncCall) { f.mutex.Lock() f.history = append(f.history, r0) f.mutex.Unlock() } -// History returns a sequence of ReposStoreGetByNameFuncCall objects +// History returns a sequence of RepositoriesStoreGetByNameFuncCall objects // describing the invocations of this function. -func (f *ReposStoreGetByNameFunc) History() []ReposStoreGetByNameFuncCall { +func (f *RepositoriesStoreGetByNameFunc) History() []RepositoriesStoreGetByNameFuncCall { f.mutex.Lock() - history := make([]ReposStoreGetByNameFuncCall, len(f.history)) + history := make([]RepositoriesStoreGetByNameFuncCall, len(f.history)) copy(history, f.history) f.mutex.Unlock() return history } -// ReposStoreGetByNameFuncCall is an object that describes an invocation of -// method GetByName on an instance of MockReposStore. -type ReposStoreGetByNameFuncCall struct { +// RepositoriesStoreGetByNameFuncCall is an object that describes an +// invocation of method GetByName on an instance of MockRepositoriesStore. +type RepositoriesStoreGetByNameFuncCall struct { // Arg0 is the value of the 1st argument passed to this method // invocation. Arg0 context.Context @@ -2223,45 +2230,46 @@ type ReposStoreGetByNameFuncCall struct { // Args returns an interface slice containing the arguments of this // invocation. -func (c ReposStoreGetByNameFuncCall) Args() []interface{} { +func (c RepositoriesStoreGetByNameFuncCall) Args() []interface{} { return []interface{}{c.Arg0, c.Arg1, c.Arg2} } // Results returns an interface slice containing the results of this // invocation. -func (c ReposStoreGetByNameFuncCall) Results() []interface{} { +func (c RepositoriesStoreGetByNameFuncCall) Results() []interface{} { return []interface{}{c.Result0, c.Result1} } -// ReposStoreHasForkedByFunc describes the behavior when the HasForkedBy -// method of the parent MockReposStore instance is invoked. -type ReposStoreHasForkedByFunc struct { +// RepositoriesStoreHasForkedByFunc describes the behavior when the +// HasForkedBy method of the parent MockRepositoriesStore instance is +// invoked. +type RepositoriesStoreHasForkedByFunc struct { defaultHook func(context.Context, int64, int64) bool hooks []func(context.Context, int64, int64) bool - history []ReposStoreHasForkedByFuncCall + history []RepositoriesStoreHasForkedByFuncCall mutex sync.Mutex } // HasForkedBy delegates to the next hook function in the queue and stores // the parameter and result values of this invocation. -func (m *MockReposStore) HasForkedBy(v0 context.Context, v1 int64, v2 int64) bool { +func (m *MockRepositoriesStore) HasForkedBy(v0 context.Context, v1 int64, v2 int64) bool { r0 := m.HasForkedByFunc.nextHook()(v0, v1, v2) - m.HasForkedByFunc.appendCall(ReposStoreHasForkedByFuncCall{v0, v1, v2, r0}) + m.HasForkedByFunc.appendCall(RepositoriesStoreHasForkedByFuncCall{v0, v1, v2, r0}) return r0 } // SetDefaultHook sets function that is called when the HasForkedBy method -// of the parent MockReposStore instance is invoked and the hook queue is -// empty. -func (f *ReposStoreHasForkedByFunc) SetDefaultHook(hook func(context.Context, int64, int64) bool) { +// of the parent MockRepositoriesStore instance is invoked and the hook +// queue is empty. +func (f *RepositoriesStoreHasForkedByFunc) SetDefaultHook(hook func(context.Context, int64, int64) bool) { f.defaultHook = hook } // PushHook adds a function to the end of hook queue. Each invocation of the -// HasForkedBy method of the parent MockReposStore instance invokes the hook -// at the front of the queue and discards it. After the queue is empty, the -// default hook function is invoked for any future action. -func (f *ReposStoreHasForkedByFunc) PushHook(hook func(context.Context, int64, int64) bool) { +// HasForkedBy method of the parent MockRepositoriesStore instance invokes +// the hook at the front of the queue and discards it. After the queue is +// empty, the default hook function is invoked for any future action. +func (f *RepositoriesStoreHasForkedByFunc) PushHook(hook func(context.Context, int64, int64) bool) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -2269,20 +2277,20 @@ func (f *ReposStoreHasForkedByFunc) PushHook(hook func(context.Context, int64, i // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. -func (f *ReposStoreHasForkedByFunc) SetDefaultReturn(r0 bool) { +func (f *RepositoriesStoreHasForkedByFunc) SetDefaultReturn(r0 bool) { f.SetDefaultHook(func(context.Context, int64, int64) bool { return r0 }) } // PushReturn calls PushHook with a function that returns the given values. -func (f *ReposStoreHasForkedByFunc) PushReturn(r0 bool) { +func (f *RepositoriesStoreHasForkedByFunc) PushReturn(r0 bool) { f.PushHook(func(context.Context, int64, int64) bool { return r0 }) } -func (f *ReposStoreHasForkedByFunc) nextHook() func(context.Context, int64, int64) bool { +func (f *RepositoriesStoreHasForkedByFunc) nextHook() func(context.Context, int64, int64) bool { f.mutex.Lock() defer f.mutex.Unlock() @@ -2295,26 +2303,26 @@ func (f *ReposStoreHasForkedByFunc) nextHook() func(context.Context, int64, int6 return hook } -func (f *ReposStoreHasForkedByFunc) appendCall(r0 ReposStoreHasForkedByFuncCall) { +func (f *RepositoriesStoreHasForkedByFunc) appendCall(r0 RepositoriesStoreHasForkedByFuncCall) { f.mutex.Lock() f.history = append(f.history, r0) f.mutex.Unlock() } -// History returns a sequence of ReposStoreHasForkedByFuncCall objects -// describing the invocations of this function. -func (f *ReposStoreHasForkedByFunc) History() []ReposStoreHasForkedByFuncCall { +// History returns a sequence of RepositoriesStoreHasForkedByFuncCall +// objects describing the invocations of this function. +func (f *RepositoriesStoreHasForkedByFunc) History() []RepositoriesStoreHasForkedByFuncCall { f.mutex.Lock() - history := make([]ReposStoreHasForkedByFuncCall, len(f.history)) + history := make([]RepositoriesStoreHasForkedByFuncCall, len(f.history)) copy(history, f.history) f.mutex.Unlock() return history } -// ReposStoreHasForkedByFuncCall is an object that describes an invocation -// of method HasForkedBy on an instance of MockReposStore. -type ReposStoreHasForkedByFuncCall struct { +// RepositoriesStoreHasForkedByFuncCall is an object that describes an +// invocation of method HasForkedBy on an instance of MockRepositoriesStore. +type RepositoriesStoreHasForkedByFuncCall struct { // Arg0 is the value of the 1st argument passed to this method // invocation. Arg0 context.Context @@ -2331,45 +2339,46 @@ type ReposStoreHasForkedByFuncCall struct { // Args returns an interface slice containing the arguments of this // invocation. -func (c ReposStoreHasForkedByFuncCall) Args() []interface{} { +func (c RepositoriesStoreHasForkedByFuncCall) Args() []interface{} { return []interface{}{c.Arg0, c.Arg1, c.Arg2} } // Results returns an interface slice containing the results of this // invocation. -func (c ReposStoreHasForkedByFuncCall) Results() []interface{} { +func (c RepositoriesStoreHasForkedByFuncCall) Results() []interface{} { return []interface{}{c.Result0} } -// ReposStoreListWatchesFunc describes the behavior when the ListWatches -// method of the parent MockReposStore instance is invoked. -type ReposStoreListWatchesFunc struct { +// RepositoriesStoreListWatchesFunc describes the behavior when the +// ListWatches method of the parent MockRepositoriesStore instance is +// invoked. +type RepositoriesStoreListWatchesFunc struct { defaultHook func(context.Context, int64) ([]*db.Watch, error) hooks []func(context.Context, int64) ([]*db.Watch, error) - history []ReposStoreListWatchesFuncCall + history []RepositoriesStoreListWatchesFuncCall mutex sync.Mutex } // ListWatches delegates to the next hook function in the queue and stores // the parameter and result values of this invocation. -func (m *MockReposStore) ListWatches(v0 context.Context, v1 int64) ([]*db.Watch, error) { +func (m *MockRepositoriesStore) ListWatches(v0 context.Context, v1 int64) ([]*db.Watch, error) { r0, r1 := m.ListWatchesFunc.nextHook()(v0, v1) - m.ListWatchesFunc.appendCall(ReposStoreListWatchesFuncCall{v0, v1, r0, r1}) + m.ListWatchesFunc.appendCall(RepositoriesStoreListWatchesFuncCall{v0, v1, r0, r1}) return r0, r1 } // SetDefaultHook sets function that is called when the ListWatches method -// of the parent MockReposStore instance is invoked and the hook queue is -// empty. -func (f *ReposStoreListWatchesFunc) SetDefaultHook(hook func(context.Context, int64) ([]*db.Watch, error)) { +// of the parent MockRepositoriesStore instance is invoked and the hook +// queue is empty. +func (f *RepositoriesStoreListWatchesFunc) SetDefaultHook(hook func(context.Context, int64) ([]*db.Watch, error)) { f.defaultHook = hook } // PushHook adds a function to the end of hook queue. Each invocation of the -// ListWatches method of the parent MockReposStore instance invokes the hook -// at the front of the queue and discards it. After the queue is empty, the -// default hook function is invoked for any future action. -func (f *ReposStoreListWatchesFunc) PushHook(hook func(context.Context, int64) ([]*db.Watch, error)) { +// ListWatches method of the parent MockRepositoriesStore instance invokes +// the hook at the front of the queue and discards it. After the queue is +// empty, the default hook function is invoked for any future action. +func (f *RepositoriesStoreListWatchesFunc) PushHook(hook func(context.Context, int64) ([]*db.Watch, error)) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -2377,20 +2386,20 @@ func (f *ReposStoreListWatchesFunc) PushHook(hook func(context.Context, int64) ( // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. -func (f *ReposStoreListWatchesFunc) SetDefaultReturn(r0 []*db.Watch, r1 error) { +func (f *RepositoriesStoreListWatchesFunc) SetDefaultReturn(r0 []*db.Watch, r1 error) { f.SetDefaultHook(func(context.Context, int64) ([]*db.Watch, error) { return r0, r1 }) } // PushReturn calls PushHook with a function that returns the given values. -func (f *ReposStoreListWatchesFunc) PushReturn(r0 []*db.Watch, r1 error) { +func (f *RepositoriesStoreListWatchesFunc) PushReturn(r0 []*db.Watch, r1 error) { f.PushHook(func(context.Context, int64) ([]*db.Watch, error) { return r0, r1 }) } -func (f *ReposStoreListWatchesFunc) nextHook() func(context.Context, int64) ([]*db.Watch, error) { +func (f *RepositoriesStoreListWatchesFunc) nextHook() func(context.Context, int64) ([]*db.Watch, error) { f.mutex.Lock() defer f.mutex.Unlock() @@ -2403,26 +2412,26 @@ func (f *ReposStoreListWatchesFunc) nextHook() func(context.Context, int64) ([]* return hook } -func (f *ReposStoreListWatchesFunc) appendCall(r0 ReposStoreListWatchesFuncCall) { +func (f *RepositoriesStoreListWatchesFunc) appendCall(r0 RepositoriesStoreListWatchesFuncCall) { f.mutex.Lock() f.history = append(f.history, r0) f.mutex.Unlock() } -// History returns a sequence of ReposStoreListWatchesFuncCall objects -// describing the invocations of this function. -func (f *ReposStoreListWatchesFunc) History() []ReposStoreListWatchesFuncCall { +// History returns a sequence of RepositoriesStoreListWatchesFuncCall +// objects describing the invocations of this function. +func (f *RepositoriesStoreListWatchesFunc) History() []RepositoriesStoreListWatchesFuncCall { f.mutex.Lock() - history := make([]ReposStoreListWatchesFuncCall, len(f.history)) + history := make([]RepositoriesStoreListWatchesFuncCall, len(f.history)) copy(history, f.history) f.mutex.Unlock() return history } -// ReposStoreListWatchesFuncCall is an object that describes an invocation -// of method ListWatches on an instance of MockReposStore. -type ReposStoreListWatchesFuncCall struct { +// RepositoriesStoreListWatchesFuncCall is an object that describes an +// invocation of method ListWatches on an instance of MockRepositoriesStore. +type RepositoriesStoreListWatchesFuncCall struct { // Arg0 is the value of the 1st argument passed to this method // invocation. Arg0 context.Context @@ -2439,44 +2448,45 @@ type ReposStoreListWatchesFuncCall struct { // Args returns an interface slice containing the arguments of this // invocation. -func (c ReposStoreListWatchesFuncCall) Args() []interface{} { +func (c RepositoriesStoreListWatchesFuncCall) Args() []interface{} { return []interface{}{c.Arg0, c.Arg1} } // Results returns an interface slice containing the results of this // invocation. -func (c ReposStoreListWatchesFuncCall) Results() []interface{} { +func (c RepositoriesStoreListWatchesFuncCall) Results() []interface{} { return []interface{}{c.Result0, c.Result1} } -// ReposStoreStarFunc describes the behavior when the Star method of the -// parent MockReposStore instance is invoked. -type ReposStoreStarFunc struct { +// RepositoriesStoreStarFunc describes the behavior when the Star method of +// the parent MockRepositoriesStore instance is invoked. +type RepositoriesStoreStarFunc struct { defaultHook func(context.Context, int64, int64) error hooks []func(context.Context, int64, int64) error - history []ReposStoreStarFuncCall + history []RepositoriesStoreStarFuncCall mutex sync.Mutex } // Star delegates to the next hook function in the queue and stores the // parameter and result values of this invocation. -func (m *MockReposStore) Star(v0 context.Context, v1 int64, v2 int64) error { +func (m *MockRepositoriesStore) Star(v0 context.Context, v1 int64, v2 int64) error { r0 := m.StarFunc.nextHook()(v0, v1, v2) - m.StarFunc.appendCall(ReposStoreStarFuncCall{v0, v1, v2, r0}) + m.StarFunc.appendCall(RepositoriesStoreStarFuncCall{v0, v1, v2, r0}) return r0 } // SetDefaultHook sets function that is called when the Star method of the -// parent MockReposStore instance is invoked and the hook queue is empty. -func (f *ReposStoreStarFunc) SetDefaultHook(hook func(context.Context, int64, int64) error) { +// parent MockRepositoriesStore instance is invoked and the hook queue is +// empty. +func (f *RepositoriesStoreStarFunc) SetDefaultHook(hook func(context.Context, int64, int64) error) { f.defaultHook = hook } // PushHook adds a function to the end of hook queue. Each invocation of the -// Star method of the parent MockReposStore instance invokes the hook at the -// front of the queue and discards it. After the queue is empty, the default -// hook function is invoked for any future action. -func (f *ReposStoreStarFunc) PushHook(hook func(context.Context, int64, int64) error) { +// Star method of the parent MockRepositoriesStore instance invokes the hook +// at the front of the queue and discards it. After the queue is empty, the +// default hook function is invoked for any future action. +func (f *RepositoriesStoreStarFunc) PushHook(hook func(context.Context, int64, int64) error) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -2484,20 +2494,20 @@ func (f *ReposStoreStarFunc) PushHook(hook func(context.Context, int64, int64) e // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. -func (f *ReposStoreStarFunc) SetDefaultReturn(r0 error) { +func (f *RepositoriesStoreStarFunc) SetDefaultReturn(r0 error) { f.SetDefaultHook(func(context.Context, int64, int64) error { return r0 }) } // PushReturn calls PushHook with a function that returns the given values. -func (f *ReposStoreStarFunc) PushReturn(r0 error) { +func (f *RepositoriesStoreStarFunc) PushReturn(r0 error) { f.PushHook(func(context.Context, int64, int64) error { return r0 }) } -func (f *ReposStoreStarFunc) nextHook() func(context.Context, int64, int64) error { +func (f *RepositoriesStoreStarFunc) nextHook() func(context.Context, int64, int64) error { f.mutex.Lock() defer f.mutex.Unlock() @@ -2510,26 +2520,26 @@ func (f *ReposStoreStarFunc) nextHook() func(context.Context, int64, int64) erro return hook } -func (f *ReposStoreStarFunc) appendCall(r0 ReposStoreStarFuncCall) { +func (f *RepositoriesStoreStarFunc) appendCall(r0 RepositoriesStoreStarFuncCall) { f.mutex.Lock() f.history = append(f.history, r0) f.mutex.Unlock() } -// History returns a sequence of ReposStoreStarFuncCall objects describing -// the invocations of this function. -func (f *ReposStoreStarFunc) History() []ReposStoreStarFuncCall { +// History returns a sequence of RepositoriesStoreStarFuncCall objects +// describing the invocations of this function. +func (f *RepositoriesStoreStarFunc) History() []RepositoriesStoreStarFuncCall { f.mutex.Lock() - history := make([]ReposStoreStarFuncCall, len(f.history)) + history := make([]RepositoriesStoreStarFuncCall, len(f.history)) copy(history, f.history) f.mutex.Unlock() return history } -// ReposStoreStarFuncCall is an object that describes an invocation of -// method Star on an instance of MockReposStore. -type ReposStoreStarFuncCall struct { +// RepositoriesStoreStarFuncCall is an object that describes an invocation +// of method Star on an instance of MockRepositoriesStore. +type RepositoriesStoreStarFuncCall struct { // Arg0 is the value of the 1st argument passed to this method // invocation. Arg0 context.Context @@ -2546,44 +2556,45 @@ type ReposStoreStarFuncCall struct { // Args returns an interface slice containing the arguments of this // invocation. -func (c ReposStoreStarFuncCall) Args() []interface{} { +func (c RepositoriesStoreStarFuncCall) Args() []interface{} { return []interface{}{c.Arg0, c.Arg1, c.Arg2} } // Results returns an interface slice containing the results of this // invocation. -func (c ReposStoreStarFuncCall) Results() []interface{} { +func (c RepositoriesStoreStarFuncCall) Results() []interface{} { return []interface{}{c.Result0} } -// ReposStoreTouchFunc describes the behavior when the Touch method of the -// parent MockReposStore instance is invoked. -type ReposStoreTouchFunc struct { +// RepositoriesStoreTouchFunc describes the behavior when the Touch method +// of the parent MockRepositoriesStore instance is invoked. +type RepositoriesStoreTouchFunc struct { defaultHook func(context.Context, int64) error hooks []func(context.Context, int64) error - history []ReposStoreTouchFuncCall + history []RepositoriesStoreTouchFuncCall mutex sync.Mutex } // Touch delegates to the next hook function in the queue and stores the // parameter and result values of this invocation. -func (m *MockReposStore) Touch(v0 context.Context, v1 int64) error { +func (m *MockRepositoriesStore) Touch(v0 context.Context, v1 int64) error { r0 := m.TouchFunc.nextHook()(v0, v1) - m.TouchFunc.appendCall(ReposStoreTouchFuncCall{v0, v1, r0}) + m.TouchFunc.appendCall(RepositoriesStoreTouchFuncCall{v0, v1, r0}) return r0 } // SetDefaultHook sets function that is called when the Touch method of the -// parent MockReposStore instance is invoked and the hook queue is empty. -func (f *ReposStoreTouchFunc) SetDefaultHook(hook func(context.Context, int64) error) { +// parent MockRepositoriesStore instance is invoked and the hook queue is +// empty. +func (f *RepositoriesStoreTouchFunc) SetDefaultHook(hook func(context.Context, int64) error) { f.defaultHook = hook } // PushHook adds a function to the end of hook queue. Each invocation of the -// Touch method of the parent MockReposStore instance invokes the hook at -// the front of the queue and discards it. After the queue is empty, the -// default hook function is invoked for any future action. -func (f *ReposStoreTouchFunc) PushHook(hook func(context.Context, int64) error) { +// Touch method of the parent MockRepositoriesStore instance invokes the +// hook at the front of the queue and discards it. After the queue is empty, +// the default hook function is invoked for any future action. +func (f *RepositoriesStoreTouchFunc) PushHook(hook func(context.Context, int64) error) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -2591,20 +2602,20 @@ func (f *ReposStoreTouchFunc) PushHook(hook func(context.Context, int64) error) // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. -func (f *ReposStoreTouchFunc) SetDefaultReturn(r0 error) { +func (f *RepositoriesStoreTouchFunc) SetDefaultReturn(r0 error) { f.SetDefaultHook(func(context.Context, int64) error { return r0 }) } // PushReturn calls PushHook with a function that returns the given values. -func (f *ReposStoreTouchFunc) PushReturn(r0 error) { +func (f *RepositoriesStoreTouchFunc) PushReturn(r0 error) { f.PushHook(func(context.Context, int64) error { return r0 }) } -func (f *ReposStoreTouchFunc) nextHook() func(context.Context, int64) error { +func (f *RepositoriesStoreTouchFunc) nextHook() func(context.Context, int64) error { f.mutex.Lock() defer f.mutex.Unlock() @@ -2617,26 +2628,26 @@ func (f *ReposStoreTouchFunc) nextHook() func(context.Context, int64) error { return hook } -func (f *ReposStoreTouchFunc) appendCall(r0 ReposStoreTouchFuncCall) { +func (f *RepositoriesStoreTouchFunc) appendCall(r0 RepositoriesStoreTouchFuncCall) { f.mutex.Lock() f.history = append(f.history, r0) f.mutex.Unlock() } -// History returns a sequence of ReposStoreTouchFuncCall objects describing -// the invocations of this function. -func (f *ReposStoreTouchFunc) History() []ReposStoreTouchFuncCall { +// History returns a sequence of RepositoriesStoreTouchFuncCall objects +// describing the invocations of this function. +func (f *RepositoriesStoreTouchFunc) History() []RepositoriesStoreTouchFuncCall { f.mutex.Lock() - history := make([]ReposStoreTouchFuncCall, len(f.history)) + history := make([]RepositoriesStoreTouchFuncCall, len(f.history)) copy(history, f.history) f.mutex.Unlock() return history } -// ReposStoreTouchFuncCall is an object that describes an invocation of -// method Touch on an instance of MockReposStore. -type ReposStoreTouchFuncCall struct { +// RepositoriesStoreTouchFuncCall is an object that describes an invocation +// of method Touch on an instance of MockRepositoriesStore. +type RepositoriesStoreTouchFuncCall struct { // Arg0 is the value of the 1st argument passed to this method // invocation. Arg0 context.Context @@ -2650,44 +2661,45 @@ type ReposStoreTouchFuncCall struct { // Args returns an interface slice containing the arguments of this // invocation. -func (c ReposStoreTouchFuncCall) Args() []interface{} { +func (c RepositoriesStoreTouchFuncCall) Args() []interface{} { return []interface{}{c.Arg0, c.Arg1} } // Results returns an interface slice containing the results of this // invocation. -func (c ReposStoreTouchFuncCall) Results() []interface{} { +func (c RepositoriesStoreTouchFuncCall) Results() []interface{} { return []interface{}{c.Result0} } -// ReposStoreWatchFunc describes the behavior when the Watch method of the -// parent MockReposStore instance is invoked. -type ReposStoreWatchFunc struct { +// RepositoriesStoreWatchFunc describes the behavior when the Watch method +// of the parent MockRepositoriesStore instance is invoked. +type RepositoriesStoreWatchFunc struct { defaultHook func(context.Context, int64, int64) error hooks []func(context.Context, int64, int64) error - history []ReposStoreWatchFuncCall + history []RepositoriesStoreWatchFuncCall mutex sync.Mutex } // Watch delegates to the next hook function in the queue and stores the // parameter and result values of this invocation. -func (m *MockReposStore) Watch(v0 context.Context, v1 int64, v2 int64) error { +func (m *MockRepositoriesStore) Watch(v0 context.Context, v1 int64, v2 int64) error { r0 := m.WatchFunc.nextHook()(v0, v1, v2) - m.WatchFunc.appendCall(ReposStoreWatchFuncCall{v0, v1, v2, r0}) + m.WatchFunc.appendCall(RepositoriesStoreWatchFuncCall{v0, v1, v2, r0}) return r0 } // SetDefaultHook sets function that is called when the Watch method of the -// parent MockReposStore instance is invoked and the hook queue is empty. -func (f *ReposStoreWatchFunc) SetDefaultHook(hook func(context.Context, int64, int64) error) { +// parent MockRepositoriesStore instance is invoked and the hook queue is +// empty. +func (f *RepositoriesStoreWatchFunc) SetDefaultHook(hook func(context.Context, int64, int64) error) { f.defaultHook = hook } // PushHook adds a function to the end of hook queue. Each invocation of the -// Watch method of the parent MockReposStore instance invokes the hook at -// the front of the queue and discards it. After the queue is empty, the -// default hook function is invoked for any future action. -func (f *ReposStoreWatchFunc) PushHook(hook func(context.Context, int64, int64) error) { +// Watch method of the parent MockRepositoriesStore instance invokes the +// hook at the front of the queue and discards it. After the queue is empty, +// the default hook function is invoked for any future action. +func (f *RepositoriesStoreWatchFunc) PushHook(hook func(context.Context, int64, int64) error) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -2695,20 +2707,20 @@ func (f *ReposStoreWatchFunc) PushHook(hook func(context.Context, int64, int64) // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. -func (f *ReposStoreWatchFunc) SetDefaultReturn(r0 error) { +func (f *RepositoriesStoreWatchFunc) SetDefaultReturn(r0 error) { f.SetDefaultHook(func(context.Context, int64, int64) error { return r0 }) } // PushReturn calls PushHook with a function that returns the given values. -func (f *ReposStoreWatchFunc) PushReturn(r0 error) { +func (f *RepositoriesStoreWatchFunc) PushReturn(r0 error) { f.PushHook(func(context.Context, int64, int64) error { return r0 }) } -func (f *ReposStoreWatchFunc) nextHook() func(context.Context, int64, int64) error { +func (f *RepositoriesStoreWatchFunc) nextHook() func(context.Context, int64, int64) error { f.mutex.Lock() defer f.mutex.Unlock() @@ -2721,26 +2733,26 @@ func (f *ReposStoreWatchFunc) nextHook() func(context.Context, int64, int64) err return hook } -func (f *ReposStoreWatchFunc) appendCall(r0 ReposStoreWatchFuncCall) { +func (f *RepositoriesStoreWatchFunc) appendCall(r0 RepositoriesStoreWatchFuncCall) { f.mutex.Lock() f.history = append(f.history, r0) f.mutex.Unlock() } -// History returns a sequence of ReposStoreWatchFuncCall objects describing -// the invocations of this function. -func (f *ReposStoreWatchFunc) History() []ReposStoreWatchFuncCall { +// History returns a sequence of RepositoriesStoreWatchFuncCall objects +// describing the invocations of this function. +func (f *RepositoriesStoreWatchFunc) History() []RepositoriesStoreWatchFuncCall { f.mutex.Lock() - history := make([]ReposStoreWatchFuncCall, len(f.history)) + history := make([]RepositoriesStoreWatchFuncCall, len(f.history)) copy(history, f.history) f.mutex.Unlock() return history } -// ReposStoreWatchFuncCall is an object that describes an invocation of -// method Watch on an instance of MockReposStore. -type ReposStoreWatchFuncCall struct { +// RepositoriesStoreWatchFuncCall is an object that describes an invocation +// of method Watch on an instance of MockRepositoriesStore. +type RepositoriesStoreWatchFuncCall struct { // Arg0 is the value of the 1st argument passed to this method // invocation. Arg0 context.Context @@ -2757,13 +2769,13 @@ type ReposStoreWatchFuncCall struct { // Args returns an interface slice containing the arguments of this // invocation. -func (c ReposStoreWatchFuncCall) Args() []interface{} { +func (c RepositoriesStoreWatchFuncCall) Args() []interface{} { return []interface{}{c.Arg0, c.Arg1, c.Arg2} } // Results returns an interface slice containing the results of this // invocation. -func (c ReposStoreWatchFuncCall) Results() []interface{} { +func (c RepositoriesStoreWatchFuncCall) Results() []interface{} { return []interface{}{c.Result0} } diff --git a/internal/route/lfs/route.go b/internal/route/lfs/route.go index 3440c89b0..edd16b885 100644 --- a/internal/route/lfs/route.go +++ b/internal/route/lfs/route.go @@ -117,7 +117,7 @@ func authorize(mode db.AccessMode) macaron.Handler { return } - repo, err := db.Repos.GetByName(c.Req.Context(), owner.ID, reponame) + repo, err := db.Repositories.GetByName(c.Req.Context(), owner.ID, reponame) if err != nil { if db.IsErrRepoNotExist(err) { c.Status(http.StatusNotFound) diff --git a/internal/route/lfs/route_test.go b/internal/route/lfs/route_test.go index 9ce078465..5c640fbf8 100644 --- a/internal/route/lfs/route_test.go +++ b/internal/route/lfs/route_test.go @@ -192,7 +192,7 @@ func Test_authorize(t *testing.T) { name string authroize macaron.Handler mockUsersStore func() db.UsersStore - mockReposStore func() db.ReposStore + mockReposStore func() db.RepositoriesStore mockPermsStore func() db.PermsStore expStatusCode int expBody string @@ -217,8 +217,8 @@ func Test_authorize(t *testing.T) { }) return mock }, - mockReposStore: func() db.ReposStore { - mock := NewMockReposStore() + mockReposStore: func() db.RepositoriesStore { + mock := NewMockRepositoriesStore() mock.GetByNameFunc.SetDefaultReturn(nil, db.ErrRepoNotExist{}) return mock }, @@ -234,8 +234,8 @@ func Test_authorize(t *testing.T) { }) return mock }, - mockReposStore: func() db.ReposStore { - mock := NewMockReposStore() + mockReposStore: func() db.RepositoriesStore { + mock := NewMockRepositoriesStore() mock.GetByNameFunc.SetDefaultHook(func(ctx context.Context, ownerID int64, name string) (*db.Repository, error) { return &db.Repository{Name: name}, nil }) @@ -261,8 +261,8 @@ func Test_authorize(t *testing.T) { }) return mock }, - mockReposStore: func() db.ReposStore { - mock := NewMockReposStore() + mockReposStore: func() db.RepositoriesStore { + mock := NewMockRepositoriesStore() mock.GetByNameFunc.SetDefaultHook(func(ctx context.Context, ownerID int64, name string) (*db.Repository, error) { return &db.Repository{Name: name}, nil }) diff --git a/internal/route/org/members.go b/internal/route/org/members.go index a8f8417e4..85c6832af 100644 --- a/internal/route/org/members.go +++ b/internal/route/org/members.go @@ -23,7 +23,7 @@ func Members(c *context.Context) { c.Data["Title"] = org.FullName c.Data["PageIsOrgMembers"] = true - members, err := db.Orgs.ListMembers(c.Req.Context(), org.ID, db.ListOrgMembersOptions{}) + members, err := db.Organizations.ListMembers(c.Req.Context(), org.ID, db.ListOrgMembersOptions{}) if err != nil { c.Error(err, "list members") return @@ -48,26 +48,26 @@ func MembersAction(c *context.Context) { c.NotFound() return } - err = db.Orgs.SetMemberVisibility(c.Req.Context(), org.ID, uid, false) + err = db.Organizations.SetMemberVisibility(c.Req.Context(), org.ID, uid, false) case "public": if c.User.ID != uid && !c.Org.IsOwner { c.NotFound() return } - err = db.Orgs.SetMemberVisibility(c.Req.Context(), org.ID, uid, true) + err = db.Organizations.SetMemberVisibility(c.Req.Context(), org.ID, uid, true) case "remove": if !c.Org.IsOwner { c.NotFound() return } - err = db.Orgs.RemoveMember(c.Req.Context(), org.ID, uid) + err = db.Organizations.RemoveMember(c.Req.Context(), org.ID, uid) if db.IsErrLastOrgOwner(err) { c.Flash.Error(c.Tr("form.last_org_owner")) c.Redirect(c.Org.OrgLink + "/members") return } case "leave": - err = db.Orgs.RemoveMember(c.Req.Context(), org.ID, c.User.ID) + err = db.Organizations.RemoveMember(c.Req.Context(), org.ID, c.User.ID) if db.IsErrLastOrgOwner(err) { c.Flash.Error(c.Tr("form.last_org_owner")) c.Redirect(c.Org.OrgLink + "/members") @@ -109,7 +109,7 @@ func Invitation(c *context.Context) { return } - if err = db.Orgs.AddMember(c.Req.Context(), org.ID, u.ID); err != nil { + if err = db.Organizations.AddMember(c.Req.Context(), org.ID, u.ID); err != nil { c.Error(err, "add member") return } diff --git a/internal/route/org/org.go b/internal/route/org/org.go index badd0d81d..b413fa36e 100644 --- a/internal/route/org/org.go +++ b/internal/route/org/org.go @@ -29,16 +29,16 @@ func CreatePost(c *context.Context, f form.CreateOrg) { return } - org := &db.User{ - Name: f.OrgName, - IsActive: true, - Type: db.UserTypeOrganization, - } - - if err := db.CreateOrganization(org, c.User); err != nil { + org, err := db.Organizations.Create( + c.Req.Context(), + f.OrgName, + c.User.ID, + db.CreateOrganizationOptions{}, + ) + if err != nil { c.Data["Err_OrgName"] = true switch { - case db.IsErrUserAlreadyExist(err): + case db.IsErrOrganizationAlreadyExist(err): c.RenderWithErr(c.Tr("form.org_name_been_taken"), CREATE, &f) case db.IsErrNameNotAllowed(err): c.RenderWithErr(c.Tr("org.form.name_not_allowed", err.(db.ErrNameNotAllowed).Value()), CREATE, &f) diff --git a/internal/route/repo/http.go b/internal/route/repo/http.go index 96ac22e07..44a4e20f1 100644 --- a/internal/route/repo/http.go +++ b/internal/route/repo/http.go @@ -77,7 +77,7 @@ func HTTPContexter() macaron.Handler { return } - repo, err := db.Repos.GetByName(c.Req.Context(), owner.ID, repoName) + repo, err := db.Repositories.GetByName(c.Req.Context(), owner.ID, repoName) if err != nil { if db.IsErrRepoNotExist(err) { c.Status(http.StatusNotFound) diff --git a/internal/route/repo/issue.go b/internal/route/repo/issue.go index 7f8390455..95c74546e 100644 --- a/internal/route/repo/issue.go +++ b/internal/route/repo/issue.go @@ -68,7 +68,7 @@ func MustAllowPulls(c *context.Context) { } // User can send pull request if owns a forked repository. - if c.IsLogged && db.Repos.HasForkedBy(c.Req.Context(), c.Repo.Repository.ID, c.User.ID) { + if c.IsLogged && db.Repositories.HasForkedBy(c.Req.Context(), c.Repo.Repository.ID, c.User.ID) { c.Repo.PullRequest.Allowed = true c.Repo.PullRequest.HeadInfo = c.User.Name + ":" + c.Repo.BranchName } diff --git a/internal/route/repo/pull.go b/internal/route/repo/pull.go index 7eedcb3a9..721ee9607 100644 --- a/internal/route/repo/pull.go +++ b/internal/route/repo/pull.go @@ -69,9 +69,9 @@ func parseBaseRepository(c *context.Context) *db.Repository { } c.Data["ForkFrom"] = baseRepo.Owner.Name + "/" + baseRepo.Name - orgs, err := db.Orgs.List( + orgs, err := db.Organizations.List( c.Req.Context(), - db.ListOrgsOptions{ + db.ListOrganizationsOptions{ MemberID: c.User.ID, IncludePrivateMembers: true, }, diff --git a/internal/route/repo/tasks.go b/internal/route/repo/tasks.go index d92158856..767d0bdeb 100644 --- a/internal/route/repo/tasks.go +++ b/internal/route/repo/tasks.go @@ -44,7 +44,7 @@ func TriggerTask(c *macaron.Context) { return } - repo, err := db.Repos.GetByName(c.Req.Context(), owner.ID, reponame) + repo, err := db.Repositories.GetByName(c.Req.Context(), owner.ID, reponame) if err != nil { if db.IsErrRepoNotExist(err) { c.Error(http.StatusBadRequest, "Repository does not exist") diff --git a/internal/route/user/home.go b/internal/route/user/home.go index 6aa3f9a55..35e66fa9b 100644 --- a/internal/route/user/home.go +++ b/internal/route/user/home.go @@ -40,9 +40,9 @@ func getDashboardContextUser(c *context.Context) *db.User { } c.Data["ContextUser"] = ctxUser - orgs, err := db.Orgs.List( + orgs, err := db.Organizations.List( c.Req.Context(), - db.ListOrgsOptions{ + db.ListOrganizationsOptions{ MemberID: c.User.ID, IncludePrivateMembers: true, }, @@ -125,7 +125,7 @@ func Dashboard(c *context.Context) { // Only user can have collaborative repositories. if !ctxUser.IsOrganization() { - collaborateRepos, err := db.Repos.GetByCollaboratorID(c.Req.Context(), c.User.ID, conf.UI.User.RepoPagingNum, "updated_unix DESC") + collaborateRepos, err := db.Repositories.GetByCollaboratorID(c.Req.Context(), c.User.ID, conf.UI.User.RepoPagingNum, "updated_unix DESC") if err != nil { c.Error(err, "get accessible repositories by collaborator") return @@ -140,7 +140,7 @@ func Dashboard(c *context.Context) { var repos, mirrors []*db.Repository var repoCount int64 if ctxUser.IsOrganization() { - repos, repoCount, err = db.Orgs.AccessibleRepositoriesByUser( + repos, repoCount, err = db.Organizations.AccessibleRepositoriesByUser( c.Req.Context(), ctxUser.ID, c.User.ID, @@ -243,7 +243,7 @@ func Issues(c *context.Context) { showRepos = make([]*db.Repository, 0, 10) ) if ctxUser.IsOrganization() { - repos, _, err = db.Orgs.AccessibleRepositoriesByUser( + repos, _, err = db.Organizations.AccessibleRepositoriesByUser( c.Req.Context(), ctxUser.ID, c.User.ID, @@ -423,7 +423,7 @@ func showOrgProfile(c *context.Context) { err error ) if c.IsLogged && !c.User.IsAdmin { - repos, count, err = db.Orgs.AccessibleRepositoriesByUser( + repos, count, err = db.Organizations.AccessibleRepositoriesByUser( c.Req.Context(), org.ID, c.User.ID, @@ -453,7 +453,7 @@ func showOrgProfile(c *context.Context) { } c.Data["Page"] = paginater.New(int(count), conf.UI.User.RepoPagingNum, page, 5) - members, err := db.Orgs.ListMembers(c.Req.Context(), org.ID, db.ListOrgMembersOptions{Limit: 12}) + members, err := db.Organizations.ListMembers(c.Req.Context(), org.ID, db.ListOrgMembersOptions{Limit: 12}) if err != nil { c.Error(err, "list members") return diff --git a/internal/route/user/setting.go b/internal/route/user/setting.go index b1560c8e6..fd5d1ff16 100644 --- a/internal/route/user/setting.go +++ b/internal/route/user/setting.go @@ -566,7 +566,7 @@ func SettingsOrganizations(c *context.Context) { } func SettingsLeaveOrganization(c *context.Context) { - if err := db.Orgs.RemoveMember(c.Req.Context(), c.QueryInt64("id"), c.User.ID); err != nil { + if err := db.Organizations.RemoveMember(c.Req.Context(), c.QueryInt64("id"), c.User.ID); err != nil { if db.IsErrLastOrgOwner(err) { c.Flash.Error(c.Tr("form.last_org_owner")) } else { diff --git a/mockgen.yaml b/mockgen.yaml index 6a9a04ed9..703d89e89 100644 --- a/mockgen.yaml +++ b/mockgen.yaml @@ -40,5 +40,5 @@ mocks: - UsersStore - TwoFactorsStore - AccessTokensStore - - ReposStore + - RepositoriesStore - PermsStore