diff options
author | Unknwon <u@gogs.io> | 2015-08-08 22:43:14 +0800 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-08-08 22:43:14 +0800 |
commit | dea3a8c6a42ea7e4921c0e4beee5d4fd0437dbe5 (patch) | |
tree | 773b28a72cee24e4a02f3d162de8a37a8f912f59 /models | |
parent | d015d951bd6959f9585d8a83acfe7bba07b7eaad (diff) | |
download | gitea-dea3a8c6a42ea7e4921c0e4beee5d4fd0437dbe5.tar.gz gitea-dea3a8c6a42ea7e4921c0e4beee5d4fd0437dbe5.zip |
WIP: create PR - choose branch
Diffstat (limited to 'models')
-rw-r--r-- | models/access.go | 14 | ||||
-rw-r--r-- | models/action.go | 16 | ||||
-rw-r--r-- | models/issue.go | 28 | ||||
-rw-r--r-- | models/oauth2.go | 2 | ||||
-rw-r--r-- | models/org.go | 30 | ||||
-rw-r--r-- | models/repo.go | 103 | ||||
-rw-r--r-- | models/update.go | 4 | ||||
-rw-r--r-- | models/user.go | 16 |
8 files changed, 106 insertions, 107 deletions
diff --git a/models/access.go b/models/access.go index 54d0f099c6..8d698f151d 100644 --- a/models/access.go +++ b/models/access.go @@ -37,11 +37,11 @@ func accessLevel(e Engine, u *User, repo *Repository) (AccessMode, error) { } if u != nil { - if u.Id == repo.OwnerId { + if u.Id == repo.OwnerID { return ACCESS_MODE_OWNER, nil } - a := &Access{UserID: u.Id, RepoID: repo.Id} + a := &Access{UserID: u.Id, RepoID: repo.ID} if has, err := e.Get(a); !has || err != nil { return mode, err } @@ -77,7 +77,7 @@ func (u *User) GetAccessibleRepositories() (map[*Repository]AccessMode, error) { repos := make(map[*Repository]AccessMode, len(accesses)) for _, access := range accesses { - repo, err := GetRepositoryById(access.RepoID) + repo, err := GetRepositoryByID(access.RepoID) if err != nil { if IsErrRepoNotExist(err) { log.Error(4, "%v", err) @@ -87,7 +87,7 @@ func (u *User) GetAccessibleRepositories() (map[*Repository]AccessMode, error) { } if err = repo.GetOwner(); err != nil { return nil, err - } else if repo.OwnerId == u.Id { + } else if repo.OwnerID == u.Id { continue } repos[repo] = access.Mode @@ -121,13 +121,13 @@ func (repo *Repository) refreshAccesses(e Engine, accessMap map[int64]AccessMode } newAccesses = append(newAccesses, Access{ UserID: userID, - RepoID: repo.Id, + RepoID: repo.ID, Mode: mode, }) } // Delete old accesses and insert new ones for repository. - if _, err = e.Delete(&Access{RepoID: repo.Id}); err != nil { + if _, err = e.Delete(&Access{RepoID: repo.ID}); err != nil { return fmt.Errorf("delete old accesses: %v", err) } else if _, err = e.Insert(newAccesses); err != nil { return fmt.Errorf("insert new accesses: %v", err) @@ -193,7 +193,7 @@ func (repo *Repository) recalculateTeamAccesses(e Engine, ignTeamID int64) (err // have relations with repository. if t.IsOwnerTeam() { t.Authorize = ACCESS_MODE_OWNER - } else if !t.hasRepository(e, repo.Id) { + } else if !t.hasRepository(e, repo.ID) { continue } diff --git a/models/action.go b/models/action.go index 99cd170918..4069cbca6f 100644 --- a/models/action.go +++ b/models/action.go @@ -348,7 +348,7 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string, // check if repo belongs to org and append additional webhooks if repo.Owner.IsOrganization() { // get hooks for org - orgws, err := GetActiveWebhooksByOrgId(repo.OwnerId) + orgws, err := GetActiveWebhooksByOrgId(repo.OwnerID) if err != nil { return errors.New("GetActiveWebhooksByOrgId: " + err.Error()) } @@ -388,7 +388,7 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string, Ref: refFullName, Commits: commits, Repo: &PayloadRepo{ - Id: repo.Id, + Id: repo.ID, Name: repo.LowerName, Url: repoLink, Description: repo.Description, @@ -431,7 +431,7 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string, } if err = CreateHookTask(&HookTask{ - RepoID: repo.Id, + RepoID: repo.ID, HookID: w.Id, Type: w.HookTaskType, Url: w.Url, @@ -453,12 +453,12 @@ func newRepoAction(e Engine, u *User, repo *Repository) (err error) { ActUserName: u.Name, ActEmail: u.Email, OpType: CREATE_REPO, - RepoID: repo.Id, + RepoID: repo.ID, RepoUserName: repo.Owner.Name, RepoName: repo.Name, IsPrivate: repo.IsPrivate, }); err != nil { - return fmt.Errorf("notify watchers '%d/%s'", u.Id, repo.Id) + return fmt.Errorf("notify watchers '%d/%s'", u.Id, repo.ID) } log.Trace("action.NewRepoAction: %s/%s", u.Name, repo.Name) @@ -476,19 +476,19 @@ func transferRepoAction(e Engine, actUser, oldOwner, newOwner *User, repo *Repos ActUserName: actUser.Name, ActEmail: actUser.Email, OpType: TRANSFER_REPO, - RepoID: repo.Id, + RepoID: repo.ID, RepoUserName: newOwner.Name, RepoName: repo.Name, IsPrivate: repo.IsPrivate, Content: path.Join(oldOwner.LowerName, repo.LowerName), } if err = notifyWatchers(e, action); err != nil { - return fmt.Errorf("notify watchers '%d/%s'", actUser.Id, repo.Id) + return fmt.Errorf("notify watchers '%d/%s'", actUser.Id, repo.ID) } // Remove watch for organization. if repo.Owner.IsOrganization() { - if err = watchRepo(e, repo.Owner.Id, repo.Id, false); err != nil { + if err = watchRepo(e, repo.Owner.Id, repo.ID, false); err != nil { return fmt.Errorf("watch repository: %v", err) } } diff --git a/models/issue.go b/models/issue.go index d423f05622..6617bd0537 100644 --- a/models/issue.go +++ b/models/issue.go @@ -68,7 +68,7 @@ func (i *Issue) AfterSet(colName string, _ xorm.Cell) { } func (i *Issue) GetPoster() (err error) { - i.Poster, err = GetUserById(i.PosterID) + i.Poster, err = GetUserByID(i.PosterID) if IsErrUserNotExist(err) { i.Poster = &User{Name: "FakeUser"} return nil @@ -104,7 +104,7 @@ func (i *Issue) GetAssignee() (err error) { return nil } - i.Assignee, err = GetUserById(i.AssigneeID) + i.Assignee, err = GetUserByID(i.AssigneeID) if IsErrUserNotExist(err) { return nil } @@ -170,7 +170,7 @@ func GetIssueByRef(ref string) (issue *Issue, err error) { return } - return GetIssueByIndex(repo.Id, issueNumber) + return GetIssueByIndex(repo.ID, issueNumber) } // GetIssueByIndex returns issue by given index in repository. @@ -304,7 +304,7 @@ func NewIssueUserPairs(repo *Repository, issueID, orgID, posterID, assigneeID in iu := &IssueUser{ IssueId: issueID, - RepoId: repo.Id, + RepoId: repo.ID, } isNeedAddPoster := true @@ -331,9 +331,9 @@ func NewIssueUserPairs(repo *Repository, issueID, orgID, posterID, assigneeID in } // Add owner's as well. - if repo.OwnerId != posterID { + if repo.OwnerID != posterID { iu.Id = 0 - iu.Uid = repo.OwnerId + iu.Uid = repo.OwnerID iu.IsAssigned = iu.Uid == assigneeID if _, err = x.Insert(iu); err != nil { return err @@ -760,7 +760,7 @@ func MilestoneStats(repoID int64) (open int64, closed int64) { // ChangeMilestoneStatus changes the milestone open/closed status. func ChangeMilestoneStatus(m *Milestone, isClosed bool) (err error) { - repo, err := GetRepositoryById(m.RepoID) + repo, err := GetRepositoryByID(m.RepoID) if err != nil { return err } @@ -776,9 +776,9 @@ func ChangeMilestoneStatus(m *Milestone, isClosed bool) (err error) { return err } - repo.NumMilestones = int(countRepoMilestones(sess, repo.Id)) - repo.NumClosedMilestones = int(countRepoClosedMilestones(sess, repo.Id)) - if _, err = sess.Id(repo.Id).AllCols().Update(repo); err != nil { + repo.NumMilestones = int(countRepoMilestones(sess, repo.ID)) + repo.NumClosedMilestones = int(countRepoClosedMilestones(sess, repo.ID)) + if _, err = sess.Id(repo.ID).AllCols().Update(repo); err != nil { return err } return sess.Commit() @@ -886,7 +886,7 @@ func DeleteMilestoneByID(mid int64) error { return err } - repo, err := GetRepositoryById(m.RepoID) + repo, err := GetRepositoryByID(m.RepoID) if err != nil { return err } @@ -901,9 +901,9 @@ func DeleteMilestoneByID(mid int64) error { return err } - repo.NumMilestones = int(countRepoMilestones(sess, repo.Id)) - repo.NumClosedMilestones = int(countRepoClosedMilestones(sess, repo.Id)) - if _, err = sess.Id(repo.Id).AllCols().Update(repo); err != nil { + repo.NumMilestones = int(countRepoMilestones(sess, repo.ID)) + repo.NumClosedMilestones = int(countRepoClosedMilestones(sess, repo.ID)) + if _, err = sess.Id(repo.ID).AllCols().Update(repo); err != nil { return err } diff --git a/models/oauth2.go b/models/oauth2.go index d19e248c12..a15f7b6f32 100644 --- a/models/oauth2.go +++ b/models/oauth2.go @@ -58,7 +58,7 @@ func GetOauth2(identity string) (oa *Oauth2, err error) { } else if oa.Uid == -1 { return oa, ErrOauth2NotAssociated } - oa.User, err = GetUserById(oa.Uid) + oa.User, err = GetUserByID(oa.Uid) return oa, err } diff --git a/models/org.go b/models/org.go index 3caed30bac..b8d1945672 100644 --- a/models/org.go +++ b/models/org.go @@ -66,7 +66,7 @@ func (org *User) GetMembers() error { org.Members = make([]*User, len(ous)) for i, ou := range ous { - org.Members[i], err = GetUserById(ou.Uid) + org.Members[i], err = GetUserByID(ou.Uid) if err != nil { return err } @@ -343,11 +343,11 @@ func RemoveOrgUser(orgId, uid int64) error { return nil } - u, err := GetUserById(uid) + u, err := GetUserByID(uid) if err != nil { return fmt.Errorf("GetUserById: %v", err) } - org, err := GetUserById(orgId) + org, err := GetUserByID(orgId) if err != nil { return fmt.Errorf("get organization: %v", err) } else if err = org.GetRepositories(); err != nil { @@ -380,10 +380,10 @@ func RemoveOrgUser(orgId, uid int64) error { // Delete all repository accesses. access := &Access{UserID: u.Id} for _, repo := range org.Repos { - access.RepoID = repo.Id + access.RepoID = repo.ID if _, err = sess.Delete(access); err != nil { return err - } else if err = watchRepo(sess, u.Id, repo.Id, false); err != nil { + } else if err = watchRepo(sess, u.Id, repo.ID, false); err != nil { return err } } @@ -443,7 +443,7 @@ func (t *Team) getRepositories(e Engine) (err error) { t.Repos = make([]*Repository, 0, len(teamRepos)) for i := range teamRepos { - repo, err := getRepositoryById(e, teamRepos[i].RepoID) + repo, err := getRepositoryByID(e, teamRepos[i].RepoID) if err != nil { return fmt.Errorf("getRepositoryById(%d): %v", teamRepos[i].RepoID, err) } @@ -487,7 +487,7 @@ func (t *Team) HasRepository(repoID int64) bool { } func (t *Team) addRepository(e Engine, repo *Repository) (err error) { - if err = addTeamRepo(e, t.OrgID, t.ID, repo.Id); err != nil { + if err = addTeamRepo(e, t.OrgID, t.ID, repo.ID); err != nil { return err } @@ -504,7 +504,7 @@ func (t *Team) addRepository(e Engine, repo *Repository) (err error) { return fmt.Errorf("getMembers: %v", err) } for _, u := range t.Members { - if err = watchRepo(e, u.Id, repo.Id, true); err != nil { + if err = watchRepo(e, u.Id, repo.ID, true); err != nil { return fmt.Errorf("watchRepo: %v", err) } } @@ -513,9 +513,9 @@ func (t *Team) addRepository(e Engine, repo *Repository) (err error) { // AddRepository adds new repository to team of organization. func (t *Team) AddRepository(repo *Repository) (err error) { - if repo.OwnerId != t.OrgID { + if repo.OwnerID != t.OrgID { return errors.New("Repository does not belong to organization") - } else if t.HasRepository(repo.Id) { + } else if t.HasRepository(repo.ID) { return nil } @@ -533,7 +533,7 @@ func (t *Team) AddRepository(repo *Repository) (err error) { } func (t *Team) removeRepository(e Engine, repo *Repository, recalculate bool) (err error) { - if err = removeTeamRepo(e, t.ID, repo.Id); err != nil { + if err = removeTeamRepo(e, t.ID, repo.ID); err != nil { return err } @@ -560,7 +560,7 @@ func (t *Team) removeRepository(e Engine, repo *Repository, recalculate bool) (e continue } - if err = watchRepo(e, u.Id, repo.Id, false); err != nil { + if err = watchRepo(e, u.Id, repo.ID, false); err != nil { return err } } @@ -574,7 +574,7 @@ func (t *Team) RemoveRepository(repoID int64) error { return nil } - repo, err := GetRepositoryById(repoID) + repo, err := GetRepositoryByID(repoID) if err != nil { return err } @@ -713,7 +713,7 @@ func DeleteTeam(t *Team) error { } // Get organization. - org, err := GetUserById(t.OrgID) + org, err := GetUserByID(t.OrgID) if err != nil { return err } @@ -903,7 +903,7 @@ func removeTeamMember(e Engine, orgId, teamId, uid int64) error { } // Get organization. - org, err := getUserById(e, orgId) + org, err := getUserByID(e, orgId) if err != nil { return err } diff --git a/models/repo.go b/models/repo.go index 8135bc57da..7355b5e8d2 100644 --- a/models/repo.go +++ b/models/repo.go @@ -129,8 +129,8 @@ func NewRepoContext() { // Repository represents a git repository. type Repository struct { - Id int64 - OwnerId int64 `xorm:"UNIQUE(s)"` + ID int64 `xorm:"pk autoincr"` + OwnerID int64 `xorm:"UNIQUE(s)"` Owner *User `xorm:"-"` LowerName string `xorm:"UNIQUE(s) INDEX NOT NULL"` Name string `xorm:"INDEX NOT NULL"` @@ -159,8 +159,8 @@ type Repository struct { *Mirror `xorm:"-"` IsFork bool `xorm:"NOT NULL DEFAULT false"` - ForkId int64 - ForkRepo *Repository `xorm:"-"` + ForkID int64 + BaseRepo *Repository `xorm:"-"` Created time.Time `xorm:"CREATED"` Updated time.Time `xorm:"UPDATED"` @@ -168,7 +168,7 @@ type Repository struct { func (repo *Repository) getOwner(e Engine) (err error) { if repo.Owner == nil { - repo.Owner, err = getUserById(e, repo.OwnerId) + repo.Owner, err = getUserByID(e, repo.OwnerID) } return err } @@ -178,16 +178,16 @@ func (repo *Repository) GetOwner() (err error) { } func (repo *Repository) GetMirror() (err error) { - repo.Mirror, err = GetMirror(repo.Id) + repo.Mirror, err = GetMirror(repo.ID) return err } -func (repo *Repository) GetForkRepo() (err error) { +func (repo *Repository) GetBaseRepo() (err error) { if !repo.IsFork { return nil } - repo.ForkRepo, err = GetRepositoryById(repo.ForkId) + repo.BaseRepo, err = GetRepositoryByID(repo.ForkID) return err } @@ -211,7 +211,7 @@ func (repo *Repository) HasAccess(u *User) bool { } func (repo *Repository) IsOwnedBy(u *User) bool { - return repo.OwnerId == u.Id + return repo.OwnerID == u.Id } // DescriptionHtml does special handles to description and return HTML string. @@ -224,7 +224,7 @@ func (repo *Repository) DescriptionHtml() template.HTML { func isRepositoryExist(e Engine, u *User, repoName string) (bool, error) { has, err := e.Get(&Repository{ - OwnerId: u.Id, + OwnerID: u.Id, LowerName: strings.ToLower(repoName), }) return has && com.IsDir(RepoPath(u.Name, repoName)), err @@ -287,8 +287,8 @@ func IsUsableName(name string) error { // Mirror represents a mirror information of repository. type Mirror struct { - Id int64 - RepoId int64 + ID int64 `xorm:"pk autoincr"` + RepoID int64 RepoName string // <user name>/<repo name> Interval int // Hour. Updated time.Time `xorm:"UPDATED"` @@ -296,7 +296,7 @@ type Mirror struct { } func getMirror(e Engine, repoId int64) (*Mirror, error) { - m := &Mirror{RepoId: repoId} + m := &Mirror{RepoID: repoId} has, err := e.Get(m) if err != nil { return nil, err @@ -312,7 +312,7 @@ func GetMirror(repoId int64) (*Mirror, error) { } func updateMirror(e Engine, m *Mirror) error { - _, err := e.Id(m.Id).Update(m) + _, err := e.Id(m.ID).Update(m) return err } @@ -330,7 +330,7 @@ func MirrorRepository(repoId int64, userName, repoName, repoPath, url string) er } if _, err = x.InsertOne(&Mirror{ - RepoId: repoId, + RepoID: repoId, RepoName: strings.ToLower(userName + "/" + repoName), Interval: 24, NextUpdate: time.Now().Add(24 * time.Hour), @@ -365,7 +365,7 @@ func MigrateRepository(u *User, name, desc string, private, mirror bool, url str repo.IsBare = false if mirror { - if err = MirrorRepository(repo.Id, u.Name, repo.Name, repoPath, url); err != nil { + if err = MirrorRepository(repo.ID, u.Name, repo.Name, repoPath, url); err != nil { return repo, err } repo.IsMirror = true @@ -517,7 +517,7 @@ func initRepository(e Engine, repoPath string, u *User, repo *Repository, initRe if len(fileName) == 0 { // Re-fetch the repository from database before updating it (else it would // override changes that were done earlier with sql) - if repo, err = getRepositoryById(e, repo.Id); err != nil { + if repo, err = getRepositoryByID(e, repo.ID); err != nil { return err } repo.IsBare = true @@ -562,7 +562,7 @@ func createRepository(e *xorm.Session, u *User, repo *Repository) (err error) { } } - if err = watchRepo(e, u.Id, repo.Id, true); err != nil { + if err = watchRepo(e, u.Id, repo.ID, true); err != nil { return fmt.Errorf("watchRepo: %v", err) } else if err = newRepoAction(e, u, repo); err != nil { return fmt.Errorf("newRepoAction: %v", err) @@ -574,7 +574,7 @@ func createRepository(e *xorm.Session, u *User, repo *Repository) (err error) { // CreateRepository creates a repository for given user or organization. func CreateRepository(u *User, name, desc, lang, license string, isPrivate, isMirror, initReadme bool) (_ *Repository, err error) { repo := &Repository{ - OwnerId: u.Id, + OwnerID: u.Id, Owner: u, Name: name, LowerName: strings.ToLower(name), @@ -630,12 +630,12 @@ func GetRepositoriesWithUsers(num, offset int) ([]*Repository, error) { } for _, repo := range repos { - repo.Owner = &User{Id: repo.OwnerId} + repo.Owner = &User{Id: repo.OwnerID} has, err := x.Get(repo.Owner) if err != nil { return nil, err } else if !has { - return nil, ErrUserNotExist{repo.OwnerId, ""} + return nil, ErrUserNotExist{repo.OwnerID, ""} } } @@ -672,11 +672,11 @@ func TransferOwnership(u *User, newOwnerName string, repo *Repository) error { // Note: we have to set value here to make sure recalculate accesses is based on // new owner. - repo.OwnerId = newOwner.Id + repo.OwnerID = newOwner.Id repo.Owner = newOwner // Update repository. - if _, err := sess.Id(repo.Id).Update(repo); err != nil { + if _, err := sess.Id(repo.ID).Update(repo); err != nil { return fmt.Errorf("update owner: %v", err) } @@ -687,7 +687,7 @@ func TransferOwnership(u *User, newOwnerName string, repo *Repository) error { } // Dummy object. - collaboration := &Collaboration{RepoID: repo.Id} + collaboration := &Collaboration{RepoID: repo.ID} for _, c := range collaborators { collaboration.UserID = c.Id if c.Id == newOwner.Id || newOwner.IsOrgMember(c.Id) { @@ -703,7 +703,7 @@ func TransferOwnership(u *User, newOwnerName string, repo *Repository) error { return fmt.Errorf("getTeams: %v", err) } for _, t := range owner.Teams { - if !t.hasRepository(sess, repo.Id) { + if !t.hasRepository(sess, repo.ID) { continue } @@ -713,7 +713,7 @@ func TransferOwnership(u *User, newOwnerName string, repo *Repository) error { } } - if err = owner.removeOrgRepo(sess, repo.Id); err != nil { + if err = owner.removeOrgRepo(sess, repo.ID); err != nil { return fmt.Errorf("removeOrgRepo: %v", err) } } @@ -739,7 +739,7 @@ func TransferOwnership(u *User, newOwnerName string, repo *Repository) error { return fmt.Errorf("decrease old owner repository count: %v", err) } - if err = watchRepo(sess, newOwner.Id, repo.Id, true); err != nil { + if err = watchRepo(sess, newOwner.Id, repo.ID, true); err != nil { return fmt.Errorf("watchRepo: %v", err) } else if err = transferRepoAction(sess, u, owner, newOwner, repo); err != nil { return fmt.Errorf("transferRepoAction: %v", err) @@ -747,7 +747,7 @@ func TransferOwnership(u *User, newOwnerName string, repo *Repository) error { // Update mirror information. if repo.IsMirror { - mirror, err := getMirror(sess, repo.Id) + mirror, err := getMirror(sess, repo.ID) if err != nil { return fmt.Errorf("getMirror: %v", err) } @@ -794,7 +794,7 @@ func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err e repo.Website = repo.Website[:255] } - if _, err = e.Id(repo.Id).AllCols().Update(repo); err != nil { + if _, err = e.Id(repo.ID).AllCols().Update(repo); err != nil { return fmt.Errorf("update: %v", err) } @@ -831,7 +831,7 @@ func UpdateRepository(repo *Repository, visibilityChanged bool) (err error) { // DeleteRepository deletes a repository for a user or organization. func DeleteRepository(uid, repoID int64, userName string) error { - repo := &Repository{Id: repoID, OwnerId: uid} + repo := &Repository{ID: repoID, OwnerID: uid} has, err := x.Get(repo) if err != nil { return err @@ -840,7 +840,7 @@ func DeleteRepository(uid, repoID int64, userName string) error { } // In case is a organization. - org, err := GetUserById(uid) + org, err := GetUserByID(uid) if err != nil { return err } @@ -866,15 +866,15 @@ func DeleteRepository(uid, repoID int64, userName string) error { } } - if _, err = sess.Delete(&Repository{Id: repoID}); err != nil { + if _, err = sess.Delete(&Repository{ID: repoID}); err != nil { return err - } else if _, err = sess.Delete(&Access{RepoID: repo.Id}); err != nil { + } else if _, err = sess.Delete(&Access{RepoID: repo.ID}); err != nil { return err - } else if _, err = sess.Delete(&Action{RepoID: repo.Id}); err != nil { + } else if _, err = sess.Delete(&Action{RepoID: repo.ID}); err != nil { return err } else if _, err = sess.Delete(&Watch{RepoID: repoID}); err != nil { return err - } else if _, err = sess.Delete(&Mirror{RepoId: repoID}); err != nil { + } else if _, err = sess.Delete(&Mirror{RepoID: repoID}); err != nil { return err } else if _, err = sess.Delete(&IssueUser{RepoId: repoID}); err != nil { return err @@ -902,7 +902,7 @@ func DeleteRepository(uid, repoID int64, userName string) error { } if repo.IsFork { - if _, err = sess.Exec("UPDATE `repository` SET num_forks=num_forks-1 WHERE id=?", repo.ForkId); err != nil { + if _, err = sess.Exec("UPDATE `repository` SET num_forks=num_forks-1 WHERE id=?", repo.ForkID); err != nil { return err } } @@ -946,7 +946,7 @@ func GetRepositoryByRef(ref string) (*Repository, error) { // GetRepositoryByName returns the repository by given name under user if exists. func GetRepositoryByName(uid int64, repoName string) (*Repository, error) { repo := &Repository{ - OwnerId: uid, + OwnerID: uid, LowerName: strings.ToLower(repoName), } has, err := x.Get(repo) @@ -958,7 +958,7 @@ func GetRepositoryByName(uid int64, repoName string) (*Repository, error) { return repo, err } -func getRepositoryById(e Engine, id int64) (*Repository, error) { +func getRepositoryByID(e Engine, id int64) (*Repository, error) { repo := new(Repository) has, err := e.Id(id).Get(repo) if err != nil { @@ -969,9 +969,9 @@ func getRepositoryById(e Engine, id int64) (*Repository, error) { return repo, nil } -// GetRepositoryById returns the repository by given id if exists. -func GetRepositoryById(id int64) (*Repository, error) { - return getRepositoryById(x, id) +// GetRepositoryByID returns the repository by given id if exists. +func GetRepositoryByID(id int64) (*Repository, error) { + return getRepositoryByID(x, id) } // GetRepositories returns a list of repositories of given user. @@ -982,8 +982,7 @@ func GetRepositories(uid int64, private bool) ([]*Repository, error) { sess.Where("is_private=?", false) } - err := sess.Find(&repos, &Repository{OwnerId: uid}) - return repos, err + return repos, sess.Find(&repos, &Repository{OwnerID: uid}) } // GetRecentUpdatedRepositories returns the list of repositories that are recently updated. @@ -993,8 +992,8 @@ func GetRecentUpdatedRepositories(num int) (repos []*Repository, err error) { } // GetRepositoryCount returns the total number of repositories of user. -func GetRepositoryCount(user *User) (int64, error) { - return x.Count(&Repository{OwnerId: user.Id}) +func GetRepositoryCount(u *User) (int64, error) { + return x.Count(&Repository{OwnerID: u.Id}) } type SearchOption struct { @@ -1199,7 +1198,7 @@ type Collaboration struct { // Add collaborator and accompanying access func (repo *Repository) AddCollaborator(u *User) error { collaboration := &Collaboration{ - RepoID: repo.Id, + RepoID: repo.ID, UserID: u.Id, } @@ -1238,13 +1237,13 @@ func (repo *Repository) AddCollaborator(u *User) error { func (repo *Repository) getCollaborators(e Engine) ([]*User, error) { collaborations := make([]*Collaboration, 0) - if err := e.Find(&collaborations, &Collaboration{RepoID: repo.Id}); err != nil { + if err := e.Find(&collaborations, &Collaboration{RepoID: repo.ID}); err != nil { return nil, err } users := make([]*User, len(collaborations)) for i, c := range collaborations { - user, err := getUserById(e, c.UserID) + user, err := getUserByID(e, c.UserID) if err != nil { return nil, err } @@ -1261,7 +1260,7 @@ func (repo *Repository) GetCollaborators() ([]*User, error) { // Delete collaborator and accompanying access func (repo *Repository) DeleteCollaborator(u *User) (err error) { collaboration := &Collaboration{ - RepoID: repo.Id, + RepoID: repo.ID, UserID: u.Id, } @@ -1430,14 +1429,14 @@ func HasForkedRepo(ownerID, repoID int64) (*Repository, bool) { func ForkRepository(u *User, oldRepo *Repository, name, desc string) (_ *Repository, err error) { repo := &Repository{ - OwnerId: u.Id, + OwnerID: u.Id, Owner: u, Name: name, LowerName: strings.ToLower(name), Description: desc, IsPrivate: oldRepo.IsPrivate, IsFork: true, - ForkId: oldRepo.Id, + ForkID: oldRepo.ID, } sess := x.NewSession() @@ -1450,7 +1449,7 @@ func ForkRepository(u *User, oldRepo *Repository, name, desc string) (_ *Reposit return nil, err } - if _, err = sess.Exec("UPDATE `repository` SET num_forks=num_forks+1 WHERE id=?", oldRepo.Id); err != nil { + if _, err = sess.Exec("UPDATE `repository` SET num_forks=num_forks+1 WHERE id=?", oldRepo.ID); err != nil { return nil, err } diff --git a/models/update.go b/models/update.go index 33b7733e18..f381d6fd07 100644 --- a/models/update.go +++ b/models/update.go @@ -105,7 +105,7 @@ func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName commit := &base.PushCommits{} if err = CommitRepoAction(userId, ru.Id, userName, actEmail, - repos.Id, repoUserName, repoName, refName, commit, oldCommitId, newCommitId); err != nil { + repos.ID, repoUserName, repoName, refName, commit, oldCommitId, newCommitId); err != nil { log.GitLogger.Fatal(4, "CommitRepoAction: %s/%s:%v", repoUserName, repoName, err) } return err @@ -154,7 +154,7 @@ func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName } if err = CommitRepoAction(userId, ru.Id, userName, actEmail, - repos.Id, repoUserName, repoName, refName, &base.PushCommits{l.Len(), commits, ""}, oldCommitId, newCommitId); err != nil { + repos.ID, repoUserName, repoName, refName, &base.PushCommits{l.Len(), commits, ""}, oldCommitId, newCommitId); err != nil { return fmt.Errorf("runUpdate.models.CommitRepoAction: %s/%s:%v", repoUserName, repoName, err) } return nil diff --git a/models/user.go b/models/user.go index 6dd31536fb..3100a45ade 100644 --- a/models/user.go +++ b/models/user.go @@ -226,7 +226,7 @@ func (u *User) GetOrganizations() error { u.Orgs = make([]*User, len(ous)) for i, ou := range ous { - u.Orgs[i], err = GetUserById(ou.OrgID) + u.Orgs[i], err = GetUserByID(ou.OrgID) if err != nil { return err } @@ -555,7 +555,7 @@ func GetUserByKeyId(keyId int64) (*User, error) { return user, nil } -func getUserById(e Engine, id int64) (*User, error) { +func getUserByID(e Engine, id int64) (*User, error) { u := new(User) has, err := e.Id(id).Get(u) if err != nil { @@ -566,9 +566,9 @@ func getUserById(e Engine, id int64) (*User, error) { return u, nil } -// GetUserById returns the user object by given ID if exists. -func GetUserById(id int64) (*User, error) { - return getUserById(x, id) +// GetUserByID returns the user object by given ID if exists. +func GetUserByID(id int64) (*User, error) { + return getUserByID(x, id) } // GetUserByName returns user by given name. @@ -620,7 +620,7 @@ func GetEmailAddresses(uid int64) ([]*EmailAddress, error) { return nil, err } - u, err := GetUserById(uid) + u, err := GetUserByID(uid) if err != nil { return nil, err } @@ -666,7 +666,7 @@ func (email *EmailAddress) Activate() error { return err } - if user, err := GetUserById(email.Uid); err != nil { + if user, err := GetUserByID(email.Uid); err != nil { return err } else { user.Rands = GetUserSalt() @@ -793,7 +793,7 @@ func GetUserByEmail(email string) (*User, error) { return nil, err } if has { - return GetUserById(emailAddress.Uid) + return GetUserByID(emailAddress.Uid) } return nil, ErrUserNotExist{0, "email"} |