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] } } }
func RetrieveRepoMetas(ctx *middleware.Context, repo *models.Repository) []*models.Label { if !ctx.Repo.IsAdmin() { return nil } labels, err := models.GetLabelsByRepoID(repo.ID) if err != nil { ctx.Handle(500, "GetLabelsByRepoID: %v", err) return nil } ctx.Data["Labels"] = labels ctx.Data["OpenMilestones"], err = models.GetMilestones(repo.ID, -1, false) if err != nil { ctx.Handle(500, "GetMilestones: %v", err) return nil } ctx.Data["ClosedMilestones"], err = models.GetMilestones(repo.ID, -1, true) if err != nil { ctx.Handle(500, "GetMilestones: %v", err) return nil } ctx.Data["Assignees"], err = repo.GetAssignees() if err != nil { ctx.Handle(500, "GetAssignees: %v", err) return nil } return labels }
// 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, } }