WIP: create PR - choose branch

This commit is contained in:
Unknwon 2015-08-08 22:43:14 +08:00
parent d015d951bd
commit dea3a8c6a4
34 changed files with 396 additions and 212 deletions

View file

@ -54,7 +54,7 @@ func SignedInId(req *http.Request, sess session.Store) int64 {
return 0
}
if id, ok := uid.(int64); ok {
if _, err := models.GetUserById(id); err != nil {
if _, err := models.GetUserByID(id); err != nil {
if !models.IsErrUserNotExist(err) {
log.Error(4, "GetUserById: %v", err)
}
@ -127,7 +127,7 @@ func SignedInUser(req *http.Request, sess session.Store) (*models.User, bool) {
return nil, false
}
u, err := models.GetUserById(uid)
u, err := models.GetUserByID(uid)
if err != nil {
log.Error(4, "GetUserById: %v", err)
return nil, false

File diff suppressed because one or more lines are too long

View file

@ -156,7 +156,7 @@ func SendResetPasswdMail(r macaron.Render, u *models.User) {
// SendIssueNotifyMail sends mail notification of all watchers of repository.
func SendIssueNotifyMail(u, owner *models.User, repo *models.Repository, issue *models.Issue) ([]string, error) {
ws, err := models.GetWatchers(repo.Id)
ws, err := models.GetWatchers(repo.ID)
if err != nil {
return nil, errors.New("mail.NotifyWatchers(GetWatchers): " + err.Error())
}
@ -167,7 +167,7 @@ func SendIssueNotifyMail(u, owner *models.User, repo *models.Repository, issue *
if u.Id == uid {
continue
}
u, err := models.GetUserById(uid)
u, err := models.GetUserByID(uid)
if err != nil {
return nil, errors.New("mail.NotifyWatchers(GetUserById): " + err.Error())
}

View file

@ -257,7 +257,7 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler {
ctx.Data["HasAccess"] = true
if repo.IsMirror {
ctx.Repo.Mirror, err = models.GetMirror(repo.Id)
ctx.Repo.Mirror, err = models.GetMirror(repo.ID)
if err != nil {
ctx.Handle(500, "GetMirror", err)
return
@ -291,10 +291,34 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler {
ctx.Data["Tags"] = tags
ctx.Repo.Repository.NumTags = len(tags)
// Non-fork repository will not return error in this method.
if err = repo.GetForkRepo(); err != nil {
ctx.Handle(500, "GetForkRepo", err)
return
if repo.IsFork {
// Non-fork repository will not return error in this method.
if err = repo.GetBaseRepo(); err != nil {
ctx.Handle(500, "GetBaseRepo", err)
return
} else if repo.BaseRepo.GetOwner(); err != nil {
ctx.Handle(500, "BaseRepo.GetOwner", err)
return
}
bsaeRepo := repo.BaseRepo
baseGitRepo, err := git.OpenRepository(models.RepoPath(bsaeRepo.Owner.Name, bsaeRepo.Name))
if err != nil {
ctx.Handle(500, "OpenRepository", err)
return
}
if len(bsaeRepo.DefaultBranch) > 0 && baseGitRepo.IsBranchExist(bsaeRepo.DefaultBranch) {
ctx.Data["BaseDefaultBranch"] = bsaeRepo.DefaultBranch
} else {
baseBranches, err := baseGitRepo.GetBranches()
if err != nil {
ctx.Handle(500, "GetBranches", err)
return
}
if len(baseBranches) > 0 {
ctx.Data["BaseDefaultBranch"] = baseBranches[0]
}
}
}
ctx.Data["Title"] = u.Name + "/" + repo.Name
@ -327,8 +351,8 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler {
}
if ctx.IsSigned {
ctx.Data["IsWatchingRepo"] = models.IsWatching(ctx.User.Id, repo.Id)
ctx.Data["IsStaringRepo"] = models.IsStaring(ctx.User.Id, repo.Id)
ctx.Data["IsWatchingRepo"] = models.IsWatching(ctx.User.Id, repo.ID)
ctx.Data["IsStaringRepo"] = models.IsStaring(ctx.User.Id, repo.ID)
}
ctx.Data["TagName"] = ctx.Repo.TagName
@ -342,8 +366,8 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler {
// If not branch selected, try default one.
// If default branch doesn't exists, fall back to some other branch.
if ctx.Repo.BranchName == "" {
if ctx.Repo.Repository.DefaultBranch != "" && gitRepo.IsBranchExist(ctx.Repo.Repository.DefaultBranch) {
if len(ctx.Repo.BranchName) == 0 {
if len(ctx.Repo.Repository.DefaultBranch) > 0 && gitRepo.IsBranchExist(ctx.Repo.Repository.DefaultBranch) {
ctx.Repo.BranchName = ctx.Repo.Repository.DefaultBranch
} else if len(brs) > 0 {
ctx.Repo.BranchName = brs[0]