diff options
author | Unknwon <u@gogs.io> | 2015-08-31 16:24:28 +0900 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-08-31 16:24:28 +0900 |
commit | 1ca257ad9f90084f4140bd1df4692f9a56c83ad4 (patch) | |
tree | 124a621e8f2d60eea02215e949142bcdd684b791 /routers | |
parent | cb381078ffa9f9a6178110be304dfcac5715e323 (diff) | |
download | gitea-1ca257ad9f90084f4140bd1df4692f9a56c83ad4.tar.gz gitea-1ca257ad9f90084f4140bd1df4692f9a56c83ad4.zip |
rename fields
Diffstat (limited to 'routers')
-rw-r--r-- | routers/repo/commit.go | 34 | ||||
-rw-r--r-- | routers/repo/issue.go | 88 | ||||
-rw-r--r-- | routers/repo/pull.go | 21 |
3 files changed, 74 insertions, 69 deletions
diff --git a/routers/repo/commit.go b/routers/repo/commit.go index 3dd1843c2a..59a2a0d094 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -193,12 +193,12 @@ func Diff(ctx *middleware.Context) { userName := ctx.Repo.Owner.Name repoName := ctx.Repo.Repository.Name - commitId := ctx.Repo.CommitId + commitID := ctx.Repo.CommitID commit := ctx.Repo.Commit commit.CommitMessage = commit.CommitMessage diff, err := models.GetDiffCommit(models.RepoPath(userName, repoName), - commitId, setting.Git.MaxGitDiffLines) + commitID, setting.Git.MaxGitDiffLines) if err != nil { ctx.Handle(404, "GetDiffCommit", err) return @@ -236,17 +236,17 @@ func Diff(ctx *middleware.Context) { ctx.Data["Username"] = userName ctx.Data["Reponame"] = repoName ctx.Data["IsImageFile"] = isImageFile - ctx.Data["Title"] = commit.Summary() + " · " + base.ShortSha(commitId) + ctx.Data["Title"] = commit.Summary() + " · " + base.ShortSha(commitID) ctx.Data["Commit"] = commit ctx.Data["Author"] = models.ValidateCommitWithEmail(commit) ctx.Data["Diff"] = diff ctx.Data["Parents"] = parents ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0 - ctx.Data["SourcePath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "src", commitId) + ctx.Data["SourcePath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "src", commitID) if commit.ParentCount() > 0 { ctx.Data["BeforeSourcePath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "src", parents[0]) } - ctx.Data["RawPath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "raw", commitId) + ctx.Data["RawPath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "raw", commitID) ctx.HTML(200, DIFF) } @@ -255,17 +255,17 @@ func CompareDiff(ctx *middleware.Context) { ctx.Data["IsDiffCompare"] = true userName := ctx.Repo.Owner.Name repoName := ctx.Repo.Repository.Name - beforeCommitId := ctx.Params(":before") - afterCommitId := ctx.Params(":after") + beforeCommitID := ctx.Params(":before") + afterCommitID := ctx.Params(":after") - commit, err := ctx.Repo.GitRepo.GetCommit(afterCommitId) + commit, err := ctx.Repo.GitRepo.GetCommit(afterCommitID) if err != nil { ctx.Handle(404, "GetCommit", err) return } - diff, err := models.GetDiffRange(models.RepoPath(userName, repoName), beforeCommitId, - afterCommitId, setting.Git.MaxGitDiffLines) + diff, err := models.GetDiffRange(models.RepoPath(userName, repoName), beforeCommitID, + afterCommitID, setting.Git.MaxGitDiffLines) if err != nil { ctx.Handle(404, "GetDiffRange", err) return @@ -290,7 +290,7 @@ func CompareDiff(ctx *middleware.Context) { return isImage } - commits, err := commit.CommitsBeforeUntil(beforeCommitId) + commits, err := commit.CommitsBeforeUntil(beforeCommitID) if err != nil { ctx.Handle(500, "CommitsBeforeUntil", err) return @@ -299,17 +299,17 @@ func CompareDiff(ctx *middleware.Context) { ctx.Data["Commits"] = commits ctx.Data["CommitCount"] = commits.Len() - ctx.Data["BeforeCommitId"] = beforeCommitId - ctx.Data["AfterCommitId"] = afterCommitId + ctx.Data["BeforeCommitID"] = beforeCommitID + ctx.Data["AfterCommitID"] = afterCommitID ctx.Data["Username"] = userName ctx.Data["Reponame"] = repoName ctx.Data["IsImageFile"] = isImageFile - ctx.Data["Title"] = "Comparing " + base.ShortSha(beforeCommitId) + "..." + base.ShortSha(afterCommitId) + " · " + userName + "/" + repoName + ctx.Data["Title"] = "Comparing " + base.ShortSha(beforeCommitID) + "..." + base.ShortSha(afterCommitID) + " · " + userName + "/" + repoName ctx.Data["Commit"] = commit ctx.Data["Diff"] = diff ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0 - ctx.Data["SourcePath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "src", afterCommitId) - ctx.Data["BeforeSourcePath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "src", beforeCommitId) - ctx.Data["RawPath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "raw", afterCommitId) + ctx.Data["SourcePath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "src", afterCommitID) + ctx.Data["BeforeSourcePath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "src", beforeCommitID) + ctx.Data["RawPath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "raw", afterCommitID) ctx.HTML(200, DIFF) } diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 5e76cd04c1..8485a617b8 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -190,39 +190,46 @@ func renderAttachmentSettings(ctx *middleware.Context) { ctx.Data["AttachmentMaxFiles"] = setting.AttachmentMaxFiles } +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 +} + func NewIssue(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("repo.issues.new") ctx.Data["PageIsIssueList"] = true ctx.Data["RequireDropzone"] = true renderAttachmentSettings(ctx) - if ctx.Repo.IsAdmin() { - var ( - repo = ctx.Repo.Repository - err error - ) - ctx.Data["Labels"], err = models.GetLabelsByRepoID(repo.ID) - if err != nil { - ctx.Handle(500, "GetLabelsByRepoID: %v", err) - return - } - - ctx.Data["OpenMilestones"], err = models.GetMilestones(repo.ID, -1, false) - if err != nil { - ctx.Handle(500, "GetMilestones: %v", err) - return - } - ctx.Data["ClosedMilestones"], err = models.GetMilestones(repo.ID, -1, true) - if err != nil { - ctx.Handle(500, "GetMilestones: %v", err) - return - } - - ctx.Data["Assignees"], err = repo.GetAssignees() - if err != nil { - ctx.Handle(500, "GetAssignees: %v", err) - return - } + RetrieveRepoMetas(ctx, ctx.Repo.Repository) + if ctx.Written() { + return } ctx.HTML(200, ISSUE_NEW) @@ -240,16 +247,18 @@ func NewIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) { milestoneID int64 assigneeID int64 attachments []string + err error ) + if ctx.Repo.IsAdmin() { + labels := RetrieveRepoMetas(ctx, repo) + if ctx.Written() { + return + } + // Check labels. labelIDs = base.StringsToInt64s(strings.Split(form.LabelIDs, ",")) labelIDMark := base.Int64sToMap(labelIDs) - labels, err := models.GetLabelsByRepoID(repo.ID) - if err != nil { - ctx.Handle(500, "GetLabelsByRepoID: %v", err) - return - } hasSelected := false for i := range labels { if labelIDMark[labels[i].ID] { @@ -264,16 +273,6 @@ func NewIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) { // Check milestone. milestoneID = form.MilestoneID if milestoneID > 0 { - ctx.Data["OpenMilestones"], err = models.GetMilestones(repo.ID, -1, false) - if err != nil { - ctx.Handle(500, "GetMilestones: %v", err) - return - } - ctx.Data["ClosedMilestones"], err = models.GetMilestones(repo.ID, -1, true) - if err != nil { - ctx.Handle(500, "GetMilestones: %v", err) - return - } ctx.Data["Milestone"], err = repo.GetMilestoneByID(milestoneID) if err != nil { ctx.Handle(500, "GetMilestoneByID: %v", err) @@ -285,11 +284,6 @@ func NewIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) { // Check assignee. assigneeID = form.AssigneeID if assigneeID > 0 { - ctx.Data["Assignees"], err = repo.GetAssignees() - if err != nil { - ctx.Handle(500, "GetAssignees: %v", err) - return - } ctx.Data["Assignee"], err = repo.GetAssigneeByID(assigneeID) if err != nil { ctx.Handle(500, "GetAssigneeByID: %v", err) diff --git a/routers/repo/pull.go b/routers/repo/pull.go index c035cc8cba..d2aea3d27a 100644 --- a/routers/repo/pull.go +++ b/routers/repo/pull.go @@ -99,15 +99,13 @@ func ForkPost(ctx *middleware.Context, form auth.CreateRepoForm) { repo, err := models.ForkRepository(ctxUser, forkRepo, form.RepoName, form.Description) if err != nil { + ctx.Data["Err_RepoName"] = true switch { case models.IsErrRepoAlreadyExist(err): - ctx.Data["Err_RepoName"] = true ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), FORK, &form) case models.IsErrNameReserved(err): - ctx.Data["Err_RepoName"] = true ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(models.ErrNameReserved).Name), FORK, &form) case models.IsErrNamePatternNotAllowed(err): - ctx.Data["Err_RepoName"] = true ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), FORK, &form) default: ctx.Handle(500, "ForkPost", err) @@ -120,7 +118,12 @@ func ForkPost(ctx *middleware.Context, form auth.CreateRepoForm) { } func CompareAndPullRequest(ctx *middleware.Context) { - // Get compare information. + ctx.Data["Title"] = ctx.Tr("repo.pulls.compare_changes") + ctx.Data["PageIsComparePull"] = true + + repo := ctx.Repo.Repository + + // Get compare branch information. infos := strings.Split(ctx.Params("*"), "...") if len(infos) != 2 { ctx.Handle(404, "CompareAndPullRequest", nil) @@ -144,7 +147,7 @@ func CompareAndPullRequest(ctx *middleware.Context) { // TODO: add organization support // Check if current user has fork of repository. - headRepo, has := models.HasForkedRepo(ctx.User.Id, ctx.Repo.Repository.ID) + headRepo, has := models.HasForkedRepo(ctx.User.Id, repo.ID) if !has { ctx.Handle(404, "HasForkedRepo", nil) return @@ -162,6 +165,14 @@ func CompareAndPullRequest(ctx *middleware.Context) { } ctx.Data["HeadBranches"] = headBranches + // Setup information for new form. + RetrieveRepoMetas(ctx, ctx.Repo.Repository) + if ctx.Written() { + return + } + + // Get diff information. + ctx.HTML(200, COMPARE_PULL) } |