func RetrieveBaseRepo(ctx *Context, repo *models.Repository) { // Non-fork repository will not return error in this method. if err := repo.GetBaseRepo(); err != nil { if models.IsErrRepoNotExist(err) { repo.IsFork = false repo.ForkID = 0 return } ctx.Handle(500, "GetBaseRepo", err) return } else if err = 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] } } }
// ToApiRepository converts repository to API format. func ToApiRepository(owner *models.User, repo *models.Repository, permission api.Permission) *api.Repository { cl, err := repo.CloneLink() if err != nil { log.Error(4, "CloneLink: %v", err) } return &api.Repository{ Id: repo.ID, Owner: *ToApiUser(owner), FullName: owner.Name + "/" + repo.Name, Private: repo.IsPrivate, Fork: repo.IsFork, HtmlUrl: setting.AppUrl + owner.Name + "/" + repo.Name, CloneUrl: cl.HTTPS, SshUrl: cl.SSH, Permissions: permission, } }