Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix error comments
  • Loading branch information
lunny committed Aug 24, 2022
commit ad13de5bd958ec9780c97730baee799a01d06340
2 changes: 1 addition & 1 deletion models/org_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func addAllRepositories(ctx context.Context, t *organization.Team) error {
for _, repo := range orgRepos {
if !organization.HasTeamRepo(ctx, t.OrgID, t.ID, repo.ID) {
if err := AddRepository(ctx, t, repo); err != nil {
return fmt.Errorf("addRepository: %v", err)
return fmt.Errorf("AddRepository: %v", err)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions models/organization/mini_org.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import (
"xorm.io/builder"
)

// MinimalOrg represents a simple orgnization with only needed columns
// MinimalOrg represents a simple organization with only the needed columns
type MinimalOrg = Organization

// GetUserOrgsList returns one user's all orgs list
// GetUserOrgsList returns all organizations the given user has access to
func GetUserOrgsList(user *user_model.User) ([]*MinimalOrg, error) {
schema, err := db.TableInfo(new(user_model.User))
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions models/organization/org_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
)

// GetOrgRepositories get repos belonging to the given organization
func GetOrgRepositories(ctx context.Context, orgID int64) ([]*repo_model.Repository, error) {
var orgRepos []*repo_model.Repository
return orgRepos, db.GetEngine(ctx).Where("owner_id = ?", orgID).Find(&orgRepos)
Expand Down
1 change: 1 addition & 0 deletions models/organization/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ func GetRepoTeams(ctx context.Context, repo *repo_model.Repository) (teams []*Te
Find(&teams)
}

// IncrTeamRepoNum increases the number of repos for the given team by 1
func IncrTeamRepoNum(ctx context.Context, teamID int64) error {
_, err := db.GetEngine(ctx).Incr("num_repos").ID(teamID).Update(new(Team))
return err
Expand Down
2 changes: 1 addition & 1 deletion models/perm/access/repo_permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ func CheckRepoUnitUser(ctx context.Context, repo *repo_model.Repository, user *u
}
perm, err := GetUserRepoPermission(ctx, repo, user)
if err != nil {
log.Error("GetUserRepoPermission(): %v", err)
log.Error("GetUserRepoPermission: %w", err)
return false
}

Expand Down
2 changes: 1 addition & 1 deletion models/repo_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func TransferOwnership(doer *user_model.User, newOwnerName string, repo *repo_mo
for _, t := range teams {
if t.IncludesAllRepositories {
if err := AddRepository(ctx, t, repo); err != nil {
return fmt.Errorf("addRepository: %v", err)
return fmt.Errorf("AddRepository: %v", err)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/context/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ type CanCommitToBranchResults struct {

// CanCommitToBranch returns true if repository is editable and user has proper access level
//
//and branch is not protected for push
// and branch is not protected for push
func (r *Repository) CanCommitToBranch(ctx context.Context, doer *user_model.User) (CanCommitToBranchResults, error) {
protectedBranch, err := git_model.GetProtectedBranchBy(ctx, r.Repository.ID, r.BranchName)
if err != nil {
Expand Down
14 changes: 3 additions & 11 deletions modules/repository/collaborator.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,7 @@ func addCollaborator(ctx context.Context, repo *repo_model.Repository, u *user_m

// AddCollaborator adds new collaboration to a repository with default access mode.
func AddCollaborator(repo *repo_model.Repository, u *user_model.User) error {
ctx, committer, err := db.TxContext()
if err != nil {
return err
}
defer committer.Close()

if err := addCollaborator(ctx, repo, u); err != nil {
return err
}

return committer.Commit()
return db.WithTx(func(ctx context.Context) error {
return addCollaborator(ctx, repo, u)
})
}
22 changes: 11 additions & 11 deletions modules/repository/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,52 +101,52 @@ func CreateRepositoryByExample(ctx context.Context, doer, u *user_model.User, re
// Remember visibility preference.
u.LastRepoVisibility = repo.IsPrivate
if err = user_model.UpdateUserCols(ctx, u, "last_repo_visibility"); err != nil {
return fmt.Errorf("updateUser: %v", err)
return fmt.Errorf("UpdateUserCols: %v", err)
}

if err = user_model.IncrUserRepoNum(ctx, u.ID); err != nil {
return fmt.Errorf("increment user total_repos: %v", err)
return fmt.Errorf("IncrUserRepoNum: %v", err)
}
u.NumRepos++

// Give access to all members in teams with access to all repositories.
if u.IsOrganization() {
teams, err := organization.FindOrgTeams(ctx, u.ID)
if err != nil {
return fmt.Errorf("loadTeams: %v", err)
return fmt.Errorf("FindOrgTeams: %v", err)
}
for _, t := range teams {
if t.IncludesAllRepositories {
if err := models.AddRepository(ctx, t, repo); err != nil {
return fmt.Errorf("addRepository: %v", err)
return fmt.Errorf("AddRepository: %v", err)
}
}
}

if isAdmin, err := access_model.IsUserRepoAdmin(ctx, repo, doer); err != nil {
return fmt.Errorf("IsUserRepoAdminCtx: %v", err)
return fmt.Errorf("IsUserRepoAdmin: %v", err)
} else if !isAdmin {
// Make creator repo admin if it wasn't assigned automatically
if err = addCollaborator(ctx, repo, doer); err != nil {
return fmt.Errorf("AddCollaborator: %v", err)
return fmt.Errorf("addCollaborator: %v", err)
}
if err = repo_model.ChangeCollaborationAccessModeCtx(ctx, repo, doer.ID, perm.AccessModeAdmin); err != nil {
return fmt.Errorf("ChangeCollaborationAccessMode: %v", err)
return fmt.Errorf("ChangeCollaborationAccessModeCtx: %v", err)
}
}
} else if err = access_model.RecalculateAccesses(ctx, repo); err != nil {
// Organization automatically called this in addRepository method.
return fmt.Errorf("recalculateAccesses: %v", err)
// Organization automatically called this in AddRepository method.
return fmt.Errorf("RecalculateAccesses: %v", err)
}

if setting.Service.AutoWatchNewRepos {
if err = repo_model.WatchRepo(ctx, doer.ID, repo.ID, true); err != nil {
return fmt.Errorf("watchRepo: %v", err)
return fmt.Errorf("WatchRepo: %v", err)
}
}

if err = webhook.CopyDefaultWebhooksToRepo(ctx, repo.ID); err != nil {
return fmt.Errorf("copyDefaultWebhooksToRepo: %v", err)
return fmt.Errorf("CopyDefaultWebhooksToRepo: %v", err)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion routers/api/v1/org/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ func AddTeamRepository(ctx *context.APIContext) {
return
}
if err := org_service.TeamAddRepository(ctx.Org.Team, repo); err != nil {
ctx.Error(http.StatusInternalServerError, "AddRepository", err)
ctx.Error(http.StatusInternalServerError, "TeamAddRepository", err)
return
}
ctx.Status(http.StatusNoContent)
Expand Down
2 changes: 1 addition & 1 deletion routers/web/repo/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ func AddTeamPost(ctx *context.Context) {
}

if err = org_service.TeamAddRepository(team, ctx.Repo.Repository); err != nil {
ctx.ServerError("team.AddRepository", err)
ctx.ServerError("TeamAddRepository", err)
return
}

Expand Down
17 changes: 5 additions & 12 deletions services/org/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package org

import (
"context"
"errors"

"code.gitea.io/gitea/models"
Expand All @@ -16,20 +17,12 @@ import (
// TeamAddRepository adds new repository to team of organization.
func TeamAddRepository(t *organization.Team, repo *repo_model.Repository) (err error) {
if repo.OwnerID != t.OrgID {
return errors.New("Repository does not belong to organization")
return errors.New("repository does not belong to organization")
} else if models.HasRepository(t, repo.ID) {
return nil
}

ctx, committer, err := db.TxContext()
if err != nil {
return err
}
defer committer.Close()

if err = models.AddRepository(ctx, t, repo); err != nil {
return err
}

return committer.Commit()
return db.WithTx(func(ctx context.Context) error {
return models.AddRepository(ctx, t, repo)
})
}