summaryrefslogtreecommitdiffstats
path: root/routers/repo
diff options
context:
space:
mode:
Diffstat (limited to 'routers/repo')
-rw-r--r--routers/repo/commit.go29
-rw-r--r--routers/repo/download.go3
-rw-r--r--routers/repo/editor.go57
-rw-r--r--routers/repo/http.go12
-rw-r--r--routers/repo/issue.go79
-rw-r--r--routers/repo/pull.go46
-rw-r--r--routers/repo/release.go26
-rw-r--r--routers/repo/repo.go33
-rw-r--r--routers/repo/setting.go12
-rw-r--r--routers/repo/webhook.go20
10 files changed, 210 insertions, 107 deletions
diff --git a/routers/repo/commit.go b/routers/repo/commit.go
index 9706779ee5..7f41158633 100644
--- a/routers/repo/commit.go
+++ b/routers/repo/commit.go
@@ -17,10 +17,11 @@ import (
)
const (
- COMMITS base.TplName = "repo/commits"
- DIFF base.TplName = "repo/diff/page"
+ tplCommits base.TplName = "repo/commits"
+ tplDiff base.TplName = "repo/diff/page"
)
+// RefCommits render commits page
func RefCommits(ctx *context.Context) {
switch {
case len(ctx.Repo.TreePath) == 0:
@@ -32,7 +33,7 @@ func RefCommits(ctx *context.Context) {
}
}
-func RenderIssueLinks(oldCommits *list.List, repoLink string) *list.List {
+func renderIssueLinks(oldCommits *list.List, repoLink string) *list.List {
newCommits := list.New()
for e := oldCommits.Front(); e != nil; e = e.Next() {
c := e.Value.(*git.Commit)
@@ -41,6 +42,7 @@ func RenderIssueLinks(oldCommits *list.List, repoLink string) *list.List {
return newCommits
}
+// Commits render branch's commits
func Commits(ctx *context.Context) {
ctx.Data["PageIsCommits"] = true
@@ -62,7 +64,7 @@ func Commits(ctx *context.Context) {
ctx.Handle(500, "CommitsByRange", err)
return
}
- commits = RenderIssueLinks(commits, ctx.Repo.RepoLink)
+ commits = renderIssueLinks(commits, ctx.Repo.RepoLink)
commits = models.ValidateCommitsWithEmails(commits)
ctx.Data["Commits"] = commits
@@ -70,9 +72,10 @@ func Commits(ctx *context.Context) {
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
ctx.Data["CommitCount"] = commitsCount
ctx.Data["Branch"] = ctx.Repo.BranchName
- ctx.HTML(200, COMMITS)
+ ctx.HTML(200, tplCommits)
}
+// SearchCommits render commits filtered by keyword
func SearchCommits(ctx *context.Context) {
ctx.Data["PageIsCommits"] = true
@@ -87,7 +90,7 @@ func SearchCommits(ctx *context.Context) {
ctx.Handle(500, "SearchCommits", err)
return
}
- commits = RenderIssueLinks(commits, ctx.Repo.RepoLink)
+ commits = renderIssueLinks(commits, ctx.Repo.RepoLink)
commits = models.ValidateCommitsWithEmails(commits)
ctx.Data["Commits"] = commits
@@ -96,9 +99,10 @@ func SearchCommits(ctx *context.Context) {
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
ctx.Data["CommitCount"] = commits.Len()
ctx.Data["Branch"] = ctx.Repo.BranchName
- ctx.HTML(200, COMMITS)
+ ctx.HTML(200, tplCommits)
}
+// FileHistory show a file's reversions
func FileHistory(ctx *context.Context) {
ctx.Data["IsRepoToolbarCommits"] = true
@@ -129,7 +133,7 @@ func FileHistory(ctx *context.Context) {
ctx.Handle(500, "CommitsByFileAndRange", err)
return
}
- commits = RenderIssueLinks(commits, ctx.Repo.RepoLink)
+ commits = renderIssueLinks(commits, ctx.Repo.RepoLink)
commits = models.ValidateCommitsWithEmails(commits)
ctx.Data["Commits"] = commits
@@ -138,9 +142,10 @@ func FileHistory(ctx *context.Context) {
ctx.Data["FileName"] = fileName
ctx.Data["CommitCount"] = commitsCount
ctx.Data["Branch"] = branchName
- ctx.HTML(200, COMMITS)
+ ctx.HTML(200, tplCommits)
}
+// Diff show different from current commit to previous commit
func Diff(ctx *context.Context) {
ctx.Data["PageIsDiff"] = true
ctx.Data["RequireHighlightJS"] = true
@@ -194,9 +199,10 @@ func Diff(ctx *context.Context) {
ctx.Data["BeforeSourcePath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "src", parents[0])
}
ctx.Data["RawPath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "raw", commitID)
- ctx.HTML(200, DIFF)
+ ctx.HTML(200, tplDiff)
}
+// RawDiff dumps diff results of repository in given commit ID to io.Writer
func RawDiff(ctx *context.Context) {
if err := models.GetRawDiff(
models.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name),
@@ -209,6 +215,7 @@ func RawDiff(ctx *context.Context) {
}
}
+// CompareDiff show different from one commit to another commit
func CompareDiff(ctx *context.Context) {
ctx.Data["IsRepoToolbarCommits"] = true
ctx.Data["IsDiffCompare"] = true
@@ -253,5 +260,5 @@ func CompareDiff(ctx *context.Context) {
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)
+ ctx.HTML(200, tplDiff)
}
diff --git a/routers/repo/download.go b/routers/repo/download.go
index 654cc01399..3adab315d4 100644
--- a/routers/repo/download.go
+++ b/routers/repo/download.go
@@ -14,6 +14,7 @@ import (
"code.gitea.io/gitea/modules/context"
)
+// ServeData download file from io.Reader
func ServeData(ctx *context.Context, name string, reader io.Reader) error {
buf := make([]byte, 1024)
n, _ := reader.Read(buf)
@@ -34,6 +35,7 @@ func ServeData(ctx *context.Context, name string, reader io.Reader) error {
return err
}
+// ServeBlob download a git.Blob
func ServeBlob(ctx *context.Context, blob *git.Blob) error {
dataRc, err := blob.Data()
if err != nil {
@@ -43,6 +45,7 @@ func ServeBlob(ctx *context.Context, blob *git.Blob) error {
return ServeData(ctx, ctx.Repo.TreePath, dataRc)
}
+// SingleDownload download a file by repos path
func SingleDownload(ctx *context.Context) {
blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreePath)
if err != nil {
diff --git a/routers/repo/editor.go b/routers/repo/editor.go
index fca5430173..d0d528e250 100644
--- a/routers/repo/editor.go
+++ b/routers/repo/editor.go
@@ -22,10 +22,10 @@ import (
)
const (
- EDIT_FILE base.TplName = "repo/editor/edit"
- EDIT_DIFF_PREVIEW base.TplName = "repo/editor/diff_preview"
- DELETE_FILE base.TplName = "repo/editor/delete"
- UPLOAD_FILE base.TplName = "repo/editor/upload"
+ tplEditFile base.TplName = "repo/editor/edit"
+ tplEditDiffPreview base.TplName = "repo/editor/diff_preview"
+ tplDeleteFile base.TplName = "repo/editor/delete"
+ tplUploadFile base.TplName = "repo/editor/upload"
)
func editFile(ctx *context.Context, isNewFile bool) {
@@ -98,13 +98,15 @@ func editFile(ctx *context.Context, isNewFile bool) {
ctx.Data["PreviewableFileModes"] = strings.Join(setting.Repository.Editor.PreviewableFileModes, ",")
ctx.Data["EditorconfigURLPrefix"] = fmt.Sprintf("%s/api/v1/repos/%s/editorconfig/", setting.AppSubUrl, ctx.Repo.Repository.FullName())
- ctx.HTML(200, EDIT_FILE)
+ ctx.HTML(200, tplEditFile)
}
+// EditFile render edit file page
func EditFile(ctx *context.Context) {
editFile(ctx, false)
}
+// NewFile render create file page
func NewFile(ctx *context.Context) {
editFile(ctx, true)
}
@@ -146,20 +148,20 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
ctx.Data["PreviewableFileModes"] = strings.Join(setting.Repository.Editor.PreviewableFileModes, ",")
if ctx.HasError() {
- ctx.HTML(200, EDIT_FILE)
+ ctx.HTML(200, tplEditFile)
return
}
if len(form.TreePath) == 0 {
ctx.Data["Err_TreePath"] = true
- ctx.RenderWithErr(ctx.Tr("repo.editor.filename_cannot_be_empty"), EDIT_FILE, &form)
+ ctx.RenderWithErr(ctx.Tr("repo.editor.filename_cannot_be_empty"), tplEditFile, &form)
return
}
if oldBranchName != branchName {
if _, err := ctx.Repo.Repository.GetBranch(branchName); err == nil {
ctx.Data["Err_NewBranchName"] = true
- ctx.RenderWithErr(ctx.Tr("repo.editor.branch_already_exists", branchName), EDIT_FILE, &form)
+ ctx.RenderWithErr(ctx.Tr("repo.editor.branch_already_exists", branchName), tplEditFile, &form)
return
}
}
@@ -180,13 +182,13 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
if index != len(treeNames)-1 {
if !entry.IsDir() {
ctx.Data["Err_TreePath"] = true
- ctx.RenderWithErr(ctx.Tr("repo.editor.directory_is_a_file", part), EDIT_FILE, &form)
+ ctx.RenderWithErr(ctx.Tr("repo.editor.directory_is_a_file", part), tplEditFile, &form)
return
}
} else {
if entry.IsDir() {
ctx.Data["Err_TreePath"] = true
- ctx.RenderWithErr(ctx.Tr("repo.editor.filename_is_a_directory", part), EDIT_FILE, &form)
+ ctx.RenderWithErr(ctx.Tr("repo.editor.filename_is_a_directory", part), tplEditFile, &form)
return
}
}
@@ -197,7 +199,7 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
if err != nil {
if git.IsErrNotExist(err) {
ctx.Data["Err_TreePath"] = true
- ctx.RenderWithErr(ctx.Tr("repo.editor.file_editing_no_longer_exists", oldTreePath), EDIT_FILE, &form)
+ ctx.RenderWithErr(ctx.Tr("repo.editor.file_editing_no_longer_exists", oldTreePath), tplEditFile, &form)
} else {
ctx.Handle(500, "GetTreeEntryByPath", err)
}
@@ -212,7 +214,7 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
for _, file := range files {
if file == form.TreePath {
- ctx.RenderWithErr(ctx.Tr("repo.editor.file_changed_while_editing", ctx.Repo.RepoLink+"/compare/"+lastCommit+"..."+ctx.Repo.CommitID), EDIT_FILE, &form)
+ ctx.RenderWithErr(ctx.Tr("repo.editor.file_changed_while_editing", ctx.Repo.RepoLink+"/compare/"+lastCommit+"..."+ctx.Repo.CommitID), tplEditFile, &form)
return
}
}
@@ -230,7 +232,7 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
}
if entry != nil {
ctx.Data["Err_TreePath"] = true
- ctx.RenderWithErr(ctx.Tr("repo.editor.file_already_exists", form.TreePath), EDIT_FILE, &form)
+ ctx.RenderWithErr(ctx.Tr("repo.editor.file_already_exists", form.TreePath), tplEditFile, &form)
return
}
}
@@ -260,21 +262,24 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
IsNewFile: isNewFile,
}); err != nil {
ctx.Data["Err_TreePath"] = true
- ctx.RenderWithErr(ctx.Tr("repo.editor.fail_to_update_file", form.TreePath, err), EDIT_FILE, &form)
+ ctx.RenderWithErr(ctx.Tr("repo.editor.fail_to_update_file", form.TreePath, err), tplEditFile, &form)
return
}
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + branchName + "/" + strings.NewReplacer("%", "%25", "#", "%23", " ", "%20", "?", "%3F").Replace(form.TreePath))
}
+// EditFilePost response for editing file
func EditFilePost(ctx *context.Context, form auth.EditRepoFileForm) {
editFilePost(ctx, form, false)
}
+// NewFilePost response for creating file
func NewFilePost(ctx *context.Context, form auth.EditRepoFileForm) {
editFilePost(ctx, form, true)
}
+// DiffPreviewPost render preview diff page
func DiffPreviewPost(ctx *context.Context, form auth.EditPreviewDiffForm) {
treePath := ctx.Repo.TreePath
@@ -299,9 +304,10 @@ func DiffPreviewPost(ctx *context.Context, form auth.EditPreviewDiffForm) {
}
ctx.Data["File"] = diff.Files[0]
- ctx.HTML(200, EDIT_DIFF_PREVIEW)
+ ctx.HTML(200, tplEditDiffPreview)
}
+// DeleteFile render delete file page
func DeleteFile(ctx *context.Context) {
ctx.Data["PageIsDelete"] = true
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchName
@@ -310,9 +316,10 @@ func DeleteFile(ctx *context.Context) {
ctx.Data["commit_message"] = ""
ctx.Data["commit_choice"] = "direct"
ctx.Data["new_branch_name"] = ""
- ctx.HTML(200, DELETE_FILE)
+ ctx.HTML(200, tplDeleteFile)
}
+// DeleteFilePost response for deleting file
func DeleteFilePost(ctx *context.Context, form auth.DeleteRepoFileForm) {
ctx.Data["PageIsDelete"] = true
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchName
@@ -330,14 +337,14 @@ func DeleteFilePost(ctx *context.Context, form auth.DeleteRepoFileForm) {
ctx.Data["new_branch_name"] = branchName
if ctx.HasError() {
- ctx.HTML(200, DELETE_FILE)
+ ctx.HTML(200, tplDeleteFile)
return
}
if oldBranchName != branchName {
if _, err := ctx.Repo.Repository.GetBranch(branchName); err == nil {
ctx.Data["Err_NewBranchName"] = true
- ctx.RenderWithErr(ctx.Tr("repo.editor.branch_already_exists", branchName), DELETE_FILE, &form)
+ ctx.RenderWithErr(ctx.Tr("repo.editor.branch_already_exists", branchName), tplDeleteFile, &form)
return
}
}
@@ -374,6 +381,7 @@ func renderUploadSettings(ctx *context.Context) {
ctx.Data["UploadMaxFiles"] = setting.Repository.Upload.MaxFiles
}
+// UploadFile render upload file page
func UploadFile(ctx *context.Context) {
ctx.Data["PageIsUpload"] = true
renderUploadSettings(ctx)
@@ -391,9 +399,10 @@ func UploadFile(ctx *context.Context) {
ctx.Data["commit_choice"] = "direct"
ctx.Data["new_branch_name"] = ""
- ctx.HTML(200, UPLOAD_FILE)
+ ctx.HTML(200, tplUploadFile)
}
+// UploadFilePost response for uploading file
func UploadFilePost(ctx *context.Context, form auth.UploadRepoFileForm) {
ctx.Data["PageIsUpload"] = true
renderUploadSettings(ctx)
@@ -422,14 +431,14 @@ func UploadFilePost(ctx *context.Context, form auth.UploadRepoFileForm) {
ctx.Data["new_branch_name"] = branchName
if ctx.HasError() {
- ctx.HTML(200, UPLOAD_FILE)
+ ctx.HTML(200, tplUploadFile)
return
}
if oldBranchName != branchName {
if _, err := ctx.Repo.Repository.GetBranch(branchName); err == nil {
ctx.Data["Err_NewBranchName"] = true
- ctx.RenderWithErr(ctx.Tr("repo.editor.branch_already_exists", branchName), UPLOAD_FILE, &form)
+ ctx.RenderWithErr(ctx.Tr("repo.editor.branch_already_exists", branchName), tplUploadFile, &form)
return
}
}
@@ -451,7 +460,7 @@ func UploadFilePost(ctx *context.Context, form auth.UploadRepoFileForm) {
// User can only upload files to a directory.
if !entry.IsDir() {
ctx.Data["Err_TreePath"] = true
- ctx.RenderWithErr(ctx.Tr("repo.editor.directory_is_a_file", part), UPLOAD_FILE, &form)
+ ctx.RenderWithErr(ctx.Tr("repo.editor.directory_is_a_file", part), tplUploadFile, &form)
return
}
}
@@ -475,13 +484,14 @@ func UploadFilePost(ctx *context.Context, form auth.UploadRepoFileForm) {
Files: form.Files,
}); err != nil {
ctx.Data["Err_TreePath"] = true
- ctx.RenderWithErr(ctx.Tr("repo.editor.unable_to_upload_files", form.TreePath, err), UPLOAD_FILE, &form)
+ ctx.RenderWithErr(ctx.Tr("repo.editor.unable_to_upload_files", form.TreePath, err), tplUploadFile, &form)
return
}
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + branchName + "/" + form.TreePath)
}
+// UploadFileToServer upload file to server file dir not git
func UploadFileToServer(ctx *context.Context) {
file, header, err := ctx.Req.FormFile("file")
if err != nil {
@@ -525,6 +535,7 @@ func UploadFileToServer(ctx *context.Context) {
})
}
+// RemoveUploadFileFromServer remove file from server file dir
func RemoveUploadFileFromServer(ctx *context.Context, form auth.RemoveUploadFileForm) {
if len(form.File) == 0 {
ctx.Status(204)
diff --git a/routers/repo/http.go b/routers/repo/http.go
index a51fa9f176..91438812a6 100644
--- a/routers/repo/http.go
+++ b/routers/repo/http.go
@@ -29,6 +29,7 @@ import (
"code.gitea.io/gitea/modules/setting"
)
+// HTTP implmentation git smart HTTP protocol
func HTTP(ctx *context.Context) {
username := ctx.Params(":username")
reponame := strings.TrimSuffix(ctx.Params(":reponame"), ".git")
@@ -170,7 +171,7 @@ func HTTP(ctx *context.Context) {
return
}
- var lastLine int64 = 0
+ var lastLine int64
for {
head := input[lastLine : lastLine+2]
if head[0] == '0' && head[1] == '0' {
@@ -193,15 +194,15 @@ func HTTP(ctx *context.Context) {
fields := strings.Fields(string(line))
if len(fields) >= 3 {
- oldCommitId := fields[0][4:]
- newCommitId := fields[1]
+ oldCommitID := fields[0][4:]
+ newCommitID := fields[1]
refFullName := fields[2]
// FIXME: handle error.
if err = models.PushUpdate(models.PushUpdateOptions{
RefFullName: refFullName,
- OldCommitID: oldCommitId,
- NewCommitID: newCommitId,
+ OldCommitID: oldCommitID,
+ NewCommitID: newCommitID,
PusherID: authUser.ID,
PusherName: authUser.Name,
RepoUserName: username,
@@ -474,6 +475,7 @@ func getGitRepoPath(subdir string) (string, error) {
return fpath, nil
}
+// HTTPBackend middleware for git smart HTTP protocol
func HTTPBackend(ctx *context.Context, cfg *serviceConfig) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
for _, route := range routes {
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index 3b5abf8962..62bfd3a569 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -27,23 +27,25 @@ import (
)
const (
- ISSUES base.TplName = "repo/issue/list"
- ISSUE_NEW base.TplName = "repo/issue/new"
- ISSUE_VIEW base.TplName = "repo/issue/view"
+ tplIssues base.TplName = "repo/issue/list"
+ tplIssueNew base.TplName = "repo/issue/new"
+ tplIssueView base.TplName = "repo/issue/view"
- LABELS base.TplName = "repo/issue/labels"
+ tplLabels base.TplName = "repo/issue/labels"
- MILESTONE base.TplName = "repo/issue/milestones"
- MILESTONE_NEW base.TplName = "repo/issue/milestone_new"
- MILESTONE_EDIT base.TplName = "repo/issue/milestone_edit"
+ tplMilestone base.TplName = "repo/issue/milestones"
+ tplMilestoneNew base.TplName = "repo/issue/milestone_new"
+ tplMilestoneEdit base.TplName = "repo/issue/milestone_edit"
- ISSUE_TEMPLATE_KEY = "IssueTemplate"
+ issueTemplateKey = "IssueTemplate"
)
var (
+ // ErrFileTypeForbidden not allowed file type error
ErrFileTypeForbidden = errors.New("File type is not allowed")
- ErrTooManyFiles = errors.New("Maximum number of files to upload exceeded")
-
+ // ErrTooManyFiles upload too many files
+ ErrTooManyFiles = errors.New("Maximum number of files to upload exceeded")
+ // IssueTemplateCandidates issue templates
IssueTemplateCandidates = []string{
"ISSUE_TEMPLATE.md",
".gogs/ISSUE_TEMPLATE.md",
@@ -51,6 +53,7 @@ var (
}
)
+// MustEnableIssues check if repository enable internal issues
func MustEnableIssues(ctx *context.Context) {
if !ctx.Repo.Repository.EnableIssues {
ctx.Handle(404, "MustEnableIssues", nil)
@@ -63,6 +66,7 @@ func MustEnableIssues(ctx *context.Context) {
}
}
+// MustAllowPulls check if repository enable pull requests
func MustAllowPulls(ctx *context.Context) {
if !ctx.Repo.Repository.AllowsPulls() {
ctx.Handle(404, "MustAllowPulls", nil)
@@ -76,6 +80,7 @@ func MustAllowPulls(ctx *context.Context) {
}
}
+// RetrieveLabels find all the labels of a repository
func RetrieveLabels(ctx *context.Context) {
labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID)
if err != nil {
@@ -89,6 +94,7 @@ func RetrieveLabels(ctx *context.Context) {
ctx.Data["NumLabels"] = len(labels)
}
+// Issues render issues page
func Issues(ctx *context.Context) {
isPullList := ctx.Params(":type") == "pulls"
if isPullList {
@@ -244,7 +250,7 @@ func Issues(ctx *context.Context) {
ctx.Data["State"] = "open"
}
- ctx.HTML(200, ISSUES)
+ ctx.HTML(200, tplIssues)
}
func renderAttachmentSettings(ctx *context.Context) {
@@ -255,6 +261,7 @@ func renderAttachmentSettings(ctx *context.Context) {
ctx.Data["AttachmentMaxFiles"] = setting.AttachmentMaxFiles
}
+// RetrieveRepoMilestonesAndAssignees find all the milestones and assignees of a repository
func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *models.Repository) {
var err error
ctx.Data["OpenMilestones"], err = models.GetMilestones(repo.ID, -1, false)
@@ -275,6 +282,7 @@ func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *models.Repos
}
}
+// RetrieveRepoMetas find all the meta information of a repository
func RetrieveRepoMetas(ctx *context.Context, repo *models.Repository) []*models.Label {
if !ctx.Repo.IsWriter() {
return nil
@@ -332,12 +340,13 @@ func setTemplateIfExists(ctx *context.Context, ctxDataKey string, possibleFiles
}
}
+// NewIssue render createing issue page
func NewIssue(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.issues.new")
ctx.Data["PageIsIssueList"] = true
ctx.Data["RequireHighlightJS"] = true
ctx.Data["RequireSimpleMDE"] = true
- setTemplateIfExists(ctx, ISSUE_TEMPLATE_KEY, IssueTemplateCandidates)
+ setTemplateIfExists(ctx, issueTemplateKey, IssueTemplateCandidates)
renderAttachmentSettings(ctx)
RetrieveRepoMetas(ctx, ctx.Repo.Repository)
@@ -345,9 +354,10 @@ func NewIssue(ctx *context.Context) {
return
}
- ctx.HTML(200, ISSUE_NEW)
+ ctx.HTML(200, tplIssueNew)
}
+// ValidateRepoMetas check and returns repository's meta informations
func ValidateRepoMetas(ctx *context.Context, form auth.CreateIssueForm) ([]int64, int64, int64) {
var (
repo = ctx.Repo.Repository
@@ -402,6 +412,7 @@ func ValidateRepoMetas(ctx *context.Context, form auth.CreateIssueForm) ([]int64
return labelIDs, milestoneID, assigneeID
}
+// NewIssuePost response for creating new issue
func NewIssuePost(ctx *context.Context, form auth.CreateIssueForm) {
ctx.Data["Title"] = ctx.Tr("repo.issues.new")
ctx.Data["PageIsIssueList"] = true
@@ -424,7 +435,7 @@ func NewIssuePost(ctx *context.Context, form auth.CreateIssueForm) {
}
if ctx.HasError() {
- ctx.HTML(200, ISSUE_NEW)
+ ctx.HTML(200, tplIssueNew)
return
}
@@ -446,6 +457,7 @@ func NewIssuePost(ctx *context.Context, form auth.CreateIssueForm) {
ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + com.ToStr(issue.Index))
}
+// UploadIssueAttachment response for uploading issue's attachment
func UploadIssueAttachment(ctx *context.Context) {
if !setting.AttachmentEnabled {
ctx.Error(404, "attachment is not enabled")
@@ -493,6 +505,7 @@ func UploadIssueAttachment(ctx *context.Context) {
})
}
+// ViewIssue render issue view page
func ViewIssue(ctx *context.Context) {
ctx.Data["RequireHighlightJS"] = true
ctx.Data["RequireDropzone"] = true
@@ -639,7 +652,7 @@ func ViewIssue(ctx *context.Context) {
ctx.Data["Issue"] = issue
ctx.Data["IsIssueOwner"] = ctx.Repo.IsWriter() || (ctx.IsSigned && issue.IsPoster(ctx.User.ID))
ctx.Data["SignInLink"] = setting.AppSubUrl + "/user/login?redirect_to=" + ctx.Data["Link"].(string)
- ctx.HTML(200, ISSUE_VIEW)
+ ctx.HTML(200, tplIssueView)
}
func getActionIssue(ctx *context.Context) *models.Issue {
@@ -655,6 +668,7 @@ func getActionIssue(ctx *context.Context) *models.Issue {
return issue
}
+// UpdateIssueTitle change issue's title
func UpdateIssueTitle(ctx *context.Context) {
issue := getActionIssue(ctx)
if ctx.Written() {
@@ -682,6 +696,7 @@ func UpdateIssueTitle(ctx *context.Context) {
})
}
+// UpdateIssueContent change issue's content
func UpdateIssueContent(ctx *context.Context) {
issue := getActionIssue(ctx)
if ctx.Written() {
@@ -704,6 +719,7 @@ func UpdateIssueContent(ctx *context.Context) {
})
}
+// UpdateIssueLabel change issue's labels
func UpdateIssueLabel(ctx *context.Context) {
issue := getActionIssue(ctx)
if ctx.Written() {
@@ -745,6 +761,7 @@ func UpdateIssueLabel(ctx *context.Context) {
})
}
+// UpdateIssueMilestone change issue's milestone
func UpdateIssueMilestone(ctx *context.Context) {
issue := getActionIssue(ctx)
if ctx.Written() {
@@ -772,6 +789,7 @@ func UpdateIssueMilestone(ctx *context.Context) {
})
}
+// UpdateIssueAssignee change issue's assignee
func UpdateIssueAssignee(ctx *context.Context) {
issue := getActionIssue(ctx)
if ctx.Written() {
@@ -796,6 +814,7 @@ func UpdateIssueAssignee(ctx *context.Context) {
})
}
+// NewComment create a comment for issue
func NewComment(ctx *context.Context, form auth.CreateCommentForm) {
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
@@ -882,6 +901,7 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) {
log.Trace("Comment created: %d/%d/%d", ctx.Repo.Repository.ID, issue.ID, comment.ID)
}
+// UpdateCommentContent change comment of issue's content
func UpdateCommentContent(ctx *context.Context) {
comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
if err != nil {
@@ -914,6 +934,7 @@ func UpdateCommentContent(ctx *context.Context) {
})
}
+// DeleteComment delete comment of issue
func DeleteComment(ctx *context.Context) {
comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
if err != nil {
@@ -937,15 +958,17 @@ func DeleteComment(ctx *context.Context) {
ctx.Status(200)
}
+// Labels render issue's labels page
func Labels(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.labels")
ctx.Data["PageIsIssueList"] = true
ctx.Data["PageIsLabels"] = true
ctx.Data["RequireMinicolors"] = true
ctx.Data["LabelTemplates"] = models.LabelTemplates
- ctx.HTML(200, LABELS)
+ ctx.HTML(200, tplLabels)
}
+// InitializeLabels init labels for a repository
func InitializeLabels(ctx *context.Context, form auth.InitializeLabelsForm) {
if ctx.HasError() {
ctx.Redirect(ctx.Repo.RepoLink + "/labels")
@@ -973,6 +996,7 @@ func InitializeLabels(ctx *context.Context, form auth.InitializeLabelsForm) {
ctx.Redirect(ctx.Repo.RepoLink + "/labels")
}
+// NewLabel create new label for repository
func NewLabel(ctx *context.Context, form auth.CreateLabelForm) {
ctx.Data["Title"] = ctx.Tr("repo.labels")
ctx.Data["PageIsLabels"] = true
@@ -995,6 +1019,7 @@ func NewLabel(ctx *context.Context, form auth.CreateLabelForm) {
ctx.Redirect(ctx.Repo.RepoLink + "/labels")
}
+// UpdateLabel update a label's name and color
func UpdateLabel(ctx *context.Context, form auth.CreateLabelForm) {
l, err := models.GetLabelByID(form.ID)
if err != nil {
@@ -1016,6 +1041,7 @@ func UpdateLabel(ctx *context.Context, form auth.CreateLabelForm) {
ctx.Redirect(ctx.Repo.RepoLink + "/labels")
}
+// DeleteLabel delete a label
func DeleteLabel(ctx *context.Context) {
if err := models.DeleteLabel(ctx.Repo.Repository.ID, ctx.QueryInt64("id")); err != nil {
ctx.Flash.Error("DeleteLabel: " + err.Error())
@@ -1029,6 +1055,7 @@ func DeleteLabel(ctx *context.Context) {
return
}
+// Milestones render milestones page
func Milestones(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.milestones")
ctx.Data["PageIsIssueList"] = true
@@ -1069,18 +1096,20 @@ func Milestones(ctx *context.Context) {
}
ctx.Data["IsShowClosed"] = isShowClosed
- ctx.HTML(200, MILESTONE)
+ ctx.HTML(200, tplMilestone)
}
+// NewMilestone render creating milestone page
func NewMilestone(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.milestones.new")
ctx.Data["PageIsIssueList"] = true
ctx.Data["PageIsMilestones"] = true
ctx.Data["RequireDatetimepicker"] = true
ctx.Data["DateLang"] = setting.DateLang(ctx.Locale.Language())
- ctx.HTML(200, MILESTONE_NEW)
+ ctx.HTML(200, tplMilestoneNew)
}
+// NewMilestonePost response for creating milestone
func NewMilestonePost(ctx *context.Context, form auth.CreateMilestoneForm) {
ctx.Data["Title"] = ctx.Tr("repo.milestones.new")
ctx.Data["PageIsIssueList"] = true
@@ -1089,7 +1118,7 @@ func NewMilestonePost(ctx *context.Context, form auth.CreateMilestoneForm) {
ctx.Data["DateLang"] = setting.DateLang(ctx.Locale.Language())
if ctx.HasError() {
- ctx.HTML(200, MILESTONE_NEW)
+ ctx.HTML(200, tplMilestoneNew)
return
}
@@ -1099,7 +1128,7 @@ func NewMilestonePost(ctx *context.Context, form auth.CreateMilestoneForm) {
deadline, err := time.ParseInLocation("2006-01-02", form.Deadline, time.Local)
if err != nil {
ctx.Data["Err_Deadline"] = true
- ctx.RenderWithErr(ctx.Tr("repo.milestones.invalid_due_date_format"), MILESTONE_NEW, &form)
+ ctx.RenderWithErr(ctx.Tr("repo.milestones.invalid_due_date_format"), tplMilestoneNew, &form)
return
}
@@ -1117,6 +1146,7 @@ func NewMilestonePost(ctx *context.Context, form auth.CreateMilestoneForm) {
ctx.Redirect(ctx.Repo.RepoLink + "/milestones")
}
+// EditMilestone render edting milestone page
func EditMilestone(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.milestones.edit")
ctx.Data["PageIsMilestones"] = true
@@ -1138,9 +1168,10 @@ func EditMilestone(ctx *context.Context) {
if len(m.DeadlineString) > 0 {
ctx.Data["deadline"] = m.DeadlineString
}
- ctx.HTML(200, MILESTONE_NEW)
+ ctx.HTML(200, tplMilestoneNew)
}
+// EditMilestonePost response for edting milestone
func EditMilestonePost(ctx *context.Context, form auth.CreateMilestoneForm) {
ctx.Data["Title"] = ctx.Tr("repo.milestones.edit")
ctx.Data["PageIsMilestones"] = true
@@ -1149,7 +1180,7 @@ func EditMilestonePost(ctx *context.Context, form auth.CreateMilestoneForm) {
ctx.Data["DateLang"] = setting.DateLang(ctx.Locale.Language())
if ctx.HasError() {
- ctx.HTML(200, MILESTONE_NEW)
+ ctx.HTML(200, tplMilestoneNew)
return
}
@@ -1159,7 +1190,7 @@ func EditMilestonePost(ctx *context.Context, form auth.CreateMilestoneForm) {
deadline, err := time.ParseInLocation("2006-01-02", form.Deadline, time.Local)
if err != nil {
ctx.Data["Err_Deadline"] = true
- ctx.RenderWithErr(ctx.Tr("repo.milestones.invalid_due_date_format"), MILESTONE_NEW, &form)
+ ctx.RenderWithErr(ctx.Tr("repo.milestones.invalid_due_date_format"), tplMilestoneNew, &form)
return
}
@@ -1184,6 +1215,7 @@ func EditMilestonePost(ctx *context.Context, form auth.CreateMilestoneForm) {
ctx.Redirect(ctx.Repo.RepoLink + "/milestones")
}
+// ChangeMilestonStatus response for change a milestone's status
func ChangeMilestonStatus(ctx *context.Context) {
m, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
if err != nil {
@@ -1218,6 +1250,7 @@ func ChangeMilestonStatus(ctx *context.Context) {
}
}
+// DeleteMilestone delete a milestone
func DeleteMilestone(ctx *context.Context) {
if err := models.DeleteMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.QueryInt64("id")); err != nil {
ctx.Flash.Error("DeleteMilestoneByRepoID: " + err.Error())
diff --git a/routers/repo/pull.go b/routers/repo/pull.go
index 6e99dfaed0..c8969b98f2 100644
--- a/routers/repo/pull.go
+++ b/routers/repo/pull.go
@@ -21,16 +21,16 @@ import (
)
const (
- FORK base.TplName = "repo/pulls/fork"
- COMPARE_PULL base.TplName = "repo/pulls/compare"
- PULL_COMMITS base.TplName = "repo/pulls/commits"
- PULL_FILES base.TplName = "repo/pulls/files"
+ tplFork base.TplName = "repo/pulls/fork"
+ tplComparePull base.TplName = "repo/pulls/compare"
+ tplPullCommits base.TplName = "repo/pulls/commits"
+ tplPullFiles base.TplName = "repo/pulls/files"
- PULL_REQUEST_TEMPLATE_KEY = "PullRequestTemplate"
+ pullRequestTemplateKey = "PullRequestTemplate"
)
var (
- PullRequestTemplateCandidates = []string{
+ pullRequestTemplateCandidates = []string{
"PULL_REQUEST.md",
".gogs/PULL_REQUEST.md",
".github/PULL_REQUEST.md",
@@ -72,6 +72,7 @@ func getForkRepository(ctx *context.Context) *models.Repository {
return forkRepo
}
+// Fork render repository fork page
func Fork(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("new_fork")
@@ -81,9 +82,10 @@ func Fork(ctx *context.Context) {
}
ctx.Data["ContextUser"] = ctx.User
- ctx.HTML(200, FORK)
+ ctx.HTML(200, tplFork)
}
+// ForkPost response for forking a repository
func ForkPost(ctx *context.Context, form auth.CreateRepoForm) {
ctx.Data["Title"] = ctx.Tr("new_fork")
@@ -99,7 +101,7 @@ func ForkPost(ctx *context.Context, form auth.CreateRepoForm) {
ctx.Data["ContextUser"] = ctxUser
if ctx.HasError() {
- ctx.HTML(200, FORK)
+ ctx.HTML(200, tplFork)
return
}
@@ -122,11 +124,11 @@ func ForkPost(ctx *context.Context, form auth.CreateRepoForm) {
ctx.Data["Err_RepoName"] = true
switch {
case models.IsErrRepoAlreadyExist(err):
- ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), FORK, &form)
+ ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), tplFork, &form)
case models.IsErrNameReserved(err):
- ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(models.ErrNameReserved).Name), FORK, &form)
+ ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(models.ErrNameReserved).Name), tplFork, &form)
case models.IsErrNamePatternNotAllowed(err):
- ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), FORK, &form)
+ ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplFork, &form)
default:
ctx.Handle(500, "ForkPost", err)
}
@@ -171,6 +173,7 @@ func checkPullInfo(ctx *context.Context) *models.Issue {
return issue
}
+// PrepareMergedViewPullInfo show meta information for a merged pull request view page
func PrepareMergedViewPullInfo(ctx *context.Context, issue *models.Issue) {
pull := issue.PullRequest
ctx.Data["HasMerged"] = true
@@ -190,6 +193,7 @@ func PrepareMergedViewPullInfo(ctx *context.Context, issue *models.Issue) {
}
}
+// PrepareViewPullInfo show meta information for a pull request preview page
func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.PullRequestInfo {
repo := ctx.Repo.Repository
pull := issue.PullRequest
@@ -242,6 +246,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.PullReq
return prInfo
}
+// ViewPullCommits show commits for a pull request
func ViewPullCommits(ctx *context.Context) {
ctx.Data["PageIsPullList"] = true
ctx.Data["PageIsPullCommits"] = true
@@ -291,9 +296,10 @@ func ViewPullCommits(ctx *context.Context) {
ctx.Data["Commits"] = commits
ctx.Data["CommitCount"] = commits.Len()
- ctx.HTML(200, PULL_COMMITS)
+ ctx.HTML(200, tplPullCommits)
}
+// ViewPullFiles render pull request changed files list page
func ViewPullFiles(ctx *context.Context) {
ctx.Data["PageIsPullList"] = true
ctx.Data["PageIsPullFiles"] = true
@@ -375,9 +381,10 @@ func ViewPullFiles(ctx *context.Context) {
ctx.Data["RawPath"] = setting.AppSubUrl + "/" + path.Join(headTarget, "raw", endCommitID)
ctx.Data["RequireHighlightJS"] = true
- ctx.HTML(200, PULL_FILES)
+ ctx.HTML(200, tplPullFiles)
}
+// MergePullRequest response for merging pull request
func MergePullRequest(ctx *context.Context) {
issue := checkPullInfo(ctx)
if ctx.Written() {
@@ -414,6 +421,7 @@ func MergePullRequest(ctx *context.Context) {
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
}
+// ParseCompareInfo parse compare info between two commit for preparing pull request
func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, *git.Repository, *git.PullRequestInfo, string, string) {
baseRepo := ctx.Repo.Repository
@@ -520,6 +528,7 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, *
return headUser, headRepo, headGitRepo, prInfo, baseBranch, headBranch
}
+// PrepareCompareDiff render pull request preview diff page
func PrepareCompareDiff(
ctx *context.Context,
headUser *models.User,
@@ -578,12 +587,13 @@ func PrepareCompareDiff(
return false
}
+// CompareAndPullRequest render pull request preview page
func CompareAndPullRequest(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.pulls.compare_changes")
ctx.Data["PageIsComparePull"] = true
ctx.Data["IsDiffCompare"] = true
ctx.Data["RequireHighlightJS"] = true
- setTemplateIfExists(ctx, PULL_REQUEST_TEMPLATE_KEY, PullRequestTemplateCandidates)
+ setTemplateIfExists(ctx, pullRequestTemplateKey, pullRequestTemplateCandidates)
renderAttachmentSettings(ctx)
headUser, headRepo, headGitRepo, prInfo, baseBranch, headBranch := ParseCompareInfo(ctx)
@@ -600,7 +610,7 @@ func CompareAndPullRequest(ctx *context.Context) {
} else {
ctx.Data["HasPullRequest"] = true
ctx.Data["PullRequest"] = pr
- ctx.HTML(200, COMPARE_PULL)
+ ctx.HTML(200, tplComparePull)
return
}
@@ -617,9 +627,10 @@ func CompareAndPullRequest(ctx *context.Context) {
}
}
- ctx.HTML(200, COMPARE_PULL)
+ ctx.HTML(200, tplComparePull)
}
+// CompareAndPullRequestPost response for creating pull request
func CompareAndPullRequestPost(ctx *context.Context, form auth.CreateIssueForm) {
ctx.Data["Title"] = ctx.Tr("repo.pulls.compare_changes")
ctx.Data["PageIsComparePull"] = true
@@ -656,7 +667,7 @@ func CompareAndPullRequestPost(ctx *context.Context, form auth.CreateIssueForm)
return
}
- ctx.HTML(200, COMPARE_PULL)
+ ctx.HTML(200, tplComparePull)
return
}
@@ -702,6 +713,7 @@ func CompareAndPullRequestPost(ctx *context.Context, form auth.CreateIssueForm)
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pullIssue.Index))
}
+// TriggerTask response for a trigger task request
func TriggerTask(ctx *context.Context) {
pusherID := ctx.QueryInt64("pusher")
branch := ctx.Query("branch")
diff --git a/routers/repo/release.go b/routers/repo/release.go
index 187952c2e6..7616d9e79e 100644
--- a/routers/repo/release.go
+++ b/routers/repo/release.go
@@ -17,8 +17,8 @@ import (
)
const (
- RELEASES base.TplName = "repo/release/list"
- RELEASE_NEW base.TplName = "repo/release/new"
+ tplReleases base.TplName = "repo/release/list"
+ tplReleaseNew base.TplName = "repo/release/new"
)
// calReleaseNumCommitsBehind calculates given release has how many commits behind release target.
@@ -49,6 +49,7 @@ func calReleaseNumCommitsBehind(repoCtx *context.Repository, release *models.Rel
return nil
}
+// Releases render releases list page
func Releases(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.release.releases")
ctx.Data["PageIsReleaseList"] = true
@@ -150,27 +151,29 @@ func Releases(ctx *context.Context) {
ctx.Data["Page"] = pager
models.SortReleases(tags)
ctx.Data["Releases"] = tags
- ctx.HTML(200, RELEASES)
+ ctx.HTML(200, tplReleases)
}
+// NewRelease render creating release page
func NewRelease(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.release.new_release")
ctx.Data["PageIsReleaseList"] = true
ctx.Data["tag_target"] = ctx.Repo.Repository.DefaultBranch
- ctx.HTML(200, RELEASE_NEW)
+ ctx.HTML(200, tplReleaseNew)
}
+// NewReleasePost response for creating a release
func NewReleasePost(ctx *context.Context, form auth.NewReleaseForm) {
ctx.Data["Title"] = ctx.Tr("repo.release.new_release")
ctx.Data["PageIsReleaseList"] = true
if ctx.HasError() {
- ctx.HTML(200, RELEASE_NEW)
+ ctx.HTML(200, tplReleaseNew)
return
}
if !ctx.Repo.GitRepo.IsBranchExist(form.Target) {
- ctx.RenderWithErr(ctx.Tr("form.target_branch_not_exist"), RELEASE_NEW, &form)
+ ctx.RenderWithErr(ctx.Tr("form.target_branch_not_exist"), tplReleaseNew, &form)
return
}
@@ -213,9 +216,9 @@ func NewReleasePost(ctx *context.Context, form auth.NewReleaseForm) {
ctx.Data["Err_TagName"] = true
switch {
case models.IsErrReleaseAlreadyExist(err):
- ctx.RenderWithErr(ctx.Tr("repo.release.tag_name_already_exist"), RELEASE_NEW, &form)
+ ctx.RenderWithErr(ctx.Tr("repo.release.tag_name_already_exist"), tplReleaseNew, &form)
case models.IsErrInvalidTagName(err):
- ctx.RenderWithErr(ctx.Tr("repo.release.tag_name_invalid"), RELEASE_NEW, &form)
+ ctx.RenderWithErr(ctx.Tr("repo.release.tag_name_invalid"), tplReleaseNew, &form)
default:
ctx.Handle(500, "CreateRelease", err)
}
@@ -226,6 +229,7 @@ func NewReleasePost(ctx *context.Context, form auth.NewReleaseForm) {
ctx.Redirect(ctx.Repo.RepoLink + "/releases")
}
+// EditRelease render release edit page
func EditRelease(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.release.edit_release")
ctx.Data["PageIsReleaseList"] = true
@@ -249,9 +253,10 @@ func EditRelease(ctx *context.Context) {
ctx.Data["prerelease"] = rel.IsPrerelease
ctx.Data["IsDraft"] = rel.IsDraft
- ctx.HTML(200, RELEASE_NEW)
+ ctx.HTML(200, tplReleaseNew)
}
+// EditReleasePost response for edit release
func EditReleasePost(ctx *context.Context, form auth.EditReleaseForm) {
ctx.Data["Title"] = ctx.Tr("repo.release.edit_release")
ctx.Data["PageIsReleaseList"] = true
@@ -274,7 +279,7 @@ func EditReleasePost(ctx *context.Context, form auth.EditReleaseForm) {
ctx.Data["prerelease"] = rel.IsPrerelease
if ctx.HasError() {
- ctx.HTML(200, RELEASE_NEW)
+ ctx.HTML(200, tplReleaseNew)
return
}
@@ -289,6 +294,7 @@ func EditReleasePost(ctx *context.Context, form auth.EditReleaseForm) {
ctx.Redirect(ctx.Repo.RepoLink + "/releases")
}
+// DeleteRelease delete a release
func DeleteRelease(ctx *context.Context) {
if err := models.DeleteReleaseByID(ctx.QueryInt64("id")); err != nil {
ctx.Flash.Error("DeleteReleaseByID: " + err.Error())
diff --git a/routers/repo/repo.go b/routers/repo/repo.go
index c3e9faf499..fdf4cd5594 100644
--- a/routers/repo/repo.go
+++ b/routers/repo/repo.go
@@ -23,10 +23,11 @@ import (
)
const (
- CREATE base.TplName = "repo/create"
- MIGRATE base.TplName = "repo/migrate"
+ tplCreate base.TplName = "repo/create"
+ tplMigrate base.TplName = "repo/migrate"
)
+// MustBeNotBare render when a repo is a bare git dir
func MustBeNotBare(ctx *context.Context) {
if ctx.Repo.Repository.IsBare {
ctx.Handle(404, "MustBeNotBare", nil)
@@ -64,6 +65,7 @@ func checkContextUser(ctx *context.Context, uid int64) *models.User {
return org
}
+// Create render creating repository page
func Create(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("new_repo")
@@ -81,7 +83,7 @@ func Create(ctx *context.Context) {
}
ctx.Data["ContextUser"] = ctxUser
- ctx.HTML(200, CREATE)
+ ctx.HTML(200, tplCreate)
}
func handleCreateError(ctx *context.Context, owner *models.User, err error, name string, tpl base.TplName, form interface{}) {
@@ -102,6 +104,7 @@ func handleCreateError(ctx *context.Context, owner *models.User, err error, name
}
}
+// CreatePost response for creating repository
func CreatePost(ctx *context.Context, form auth.CreateRepoForm) {
ctx.Data["Title"] = ctx.Tr("new_repo")
@@ -116,7 +119,7 @@ func CreatePost(ctx *context.Context, form auth.CreateRepoForm) {
ctx.Data["ContextUser"] = ctxUser
if ctx.HasError() {
- ctx.HTML(200, CREATE)
+ ctx.HTML(200, tplCreate)
return
}
@@ -141,9 +144,10 @@ func CreatePost(ctx *context.Context, form auth.CreateRepoForm) {
}
}
- handleCreateError(ctx, ctxUser, err, "CreatePost", CREATE, &form)
+ handleCreateError(ctx, ctxUser, err, "CreatePost", tplCreate, &form)
}
+// Migrate render migration of repository page
func Migrate(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("new_migrate")
ctx.Data["private"] = ctx.User.LastRepoVisibility
@@ -156,9 +160,10 @@ func Migrate(ctx *context.Context) {
}
ctx.Data["ContextUser"] = ctxUser
- ctx.HTML(200, MIGRATE)
+ ctx.HTML(200, tplMigrate)
}
+// MigratePost response for migrating from external git repository
func MigratePost(ctx *context.Context, form auth.MigrateRepoForm) {
ctx.Data["Title"] = ctx.Tr("new_migrate")
@@ -169,7 +174,7 @@ func MigratePost(ctx *context.Context, form auth.MigrateRepoForm) {
ctx.Data["ContextUser"] = ctxUser
if ctx.HasError() {
- ctx.HTML(200, MIGRATE)
+ ctx.HTML(200, tplMigrate)
return
}
@@ -180,11 +185,11 @@ func MigratePost(ctx *context.Context, form auth.MigrateRepoForm) {
addrErr := err.(models.ErrInvalidCloneAddr)
switch {
case addrErr.IsURLError:
- ctx.RenderWithErr(ctx.Tr("form.url_error"), MIGRATE, &form)
+ ctx.RenderWithErr(ctx.Tr("form.url_error"), tplMigrate, &form)
case addrErr.IsPermissionDenied:
- ctx.RenderWithErr(ctx.Tr("repo.migrate.permission_denied"), MIGRATE, &form)
+ ctx.RenderWithErr(ctx.Tr("repo.migrate.permission_denied"), tplMigrate, &form)
case addrErr.IsInvalidPath:
- ctx.RenderWithErr(ctx.Tr("repo.migrate.invalid_local_path"), MIGRATE, &form)
+ ctx.RenderWithErr(ctx.Tr("repo.migrate.invalid_local_path"), tplMigrate, &form)
default:
ctx.Handle(500, "Unknown error", err)
}
@@ -216,17 +221,18 @@ func MigratePost(ctx *context.Context, form auth.MigrateRepoForm) {
if strings.Contains(err.Error(), "Authentication failed") ||
strings.Contains(err.Error(), "could not read Username") {
ctx.Data["Err_Auth"] = true
- ctx.RenderWithErr(ctx.Tr("form.auth_failed", models.HandleCloneUserCredentials(err.Error(), true)), MIGRATE, &form)
+ ctx.RenderWithErr(ctx.Tr("form.auth_failed", models.HandleCloneUserCredentials(err.Error(), true)), tplMigrate, &form)
return
} else if strings.Contains(err.Error(), "fatal:") {
ctx.Data["Err_CloneAddr"] = true
- ctx.RenderWithErr(ctx.Tr("repo.migrate.failed", models.HandleCloneUserCredentials(err.Error(), true)), MIGRATE, &form)
+ ctx.RenderWithErr(ctx.Tr("repo.migrate.failed", models.HandleCloneUserCredentials(err.Error(), true)), tplMigrate, &form)
return
}
- handleCreateError(ctx, ctxUser, err, "MigratePost", MIGRATE, &form)
+ handleCreateError(ctx, ctxUser, err, "MigratePost", tplMigrate, &form)
}
+// Action response for actions to a repository
func Action(ctx *context.Context) {
var err error
switch ctx.Params(":action") {
@@ -261,6 +267,7 @@ func Action(ctx *context.Context) {
ctx.Redirect(redirectTo)
}
+// Download download an archive of a repository
func Download(ctx *context.Context) {
var (
uri = ctx.Params("*")
diff --git a/routers/repo/setting.go b/routers/repo/setting.go
index 736a7fdf9a..2b8c5a2315 100644
--- a/routers/repo/setting.go
+++ b/routers/repo/setting.go
@@ -26,12 +26,14 @@ const (
tplDeployKeys base.TplName = "repo/settings/deploy_keys"
)
+// Settings show a repository's settings page
func Settings(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsOptions"] = true
ctx.HTML(200, tplSettingsOptions)
}
+// SettingsPost response for changes of a repository
func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsOptions"] = true
@@ -293,6 +295,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
}
}
+// Collaboration render a repository's collaboration page
func Collaboration(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsCollaboration"] = true
@@ -307,6 +310,7 @@ func Collaboration(ctx *context.Context) {
ctx.HTML(200, tplCollaboration)
}
+// CollaborationPost response for actions for a collaboration of a repository
func CollaborationPost(ctx *context.Context) {
name := strings.ToLower(ctx.Query("collaborator"))
if len(name) == 0 || ctx.Repo.Owner.LowerName == name {
@@ -352,6 +356,7 @@ func CollaborationPost(ctx *context.Context) {
ctx.Redirect(setting.AppSubUrl + ctx.Req.URL.Path)
}
+// ChangeCollaborationAccessMode response for changing access of a collaboration
func ChangeCollaborationAccessMode(ctx *context.Context) {
if err := ctx.Repo.Repository.ChangeCollaborationAccessMode(
ctx.QueryInt64("uid"),
@@ -360,6 +365,7 @@ func ChangeCollaborationAccessMode(ctx *context.Context) {
}
}
+// DeleteCollaboration delete a collaboration for a repository
func DeleteCollaboration(ctx *context.Context) {
if err := ctx.Repo.Repository.DeleteCollaboration(ctx.QueryInt64("id")); err != nil {
ctx.Flash.Error("DeleteCollaboration: " + err.Error())
@@ -396,6 +402,7 @@ func parseOwnerAndRepo(ctx *context.Context) (*models.User, *models.Repository)
return owner, repo
}
+// GitHooks hooks of a repository
func GitHooks(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings.githooks")
ctx.Data["PageIsSettingsGitHooks"] = true
@@ -410,6 +417,7 @@ func GitHooks(ctx *context.Context) {
ctx.HTML(200, tplGithooks)
}
+// GitHooksEdit render for editing a hook of repository page
func GitHooksEdit(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings.githooks")
ctx.Data["PageIsSettingsGitHooks"] = true
@@ -428,6 +436,7 @@ func GitHooksEdit(ctx *context.Context) {
ctx.HTML(200, tplGithookEdit)
}
+// GitHooksEditPost response for editing a git hook of a repository
func GitHooksEditPost(ctx *context.Context) {
name := ctx.Params(":name")
hook, err := ctx.Repo.GitRepo.GetHook(name)
@@ -447,6 +456,7 @@ func GitHooksEditPost(ctx *context.Context) {
ctx.Redirect(ctx.Repo.RepoLink + "/settings/hooks/git")
}
+// DeployKeys render the deploy keys list of a repository page
func DeployKeys(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings.deploy_keys")
ctx.Data["PageIsSettingsKeys"] = true
@@ -461,6 +471,7 @@ func DeployKeys(ctx *context.Context) {
ctx.HTML(200, tplDeployKeys)
}
+// DeployKeysPost response for adding a deploy key of a repository
func DeployKeysPost(ctx *context.Context, form auth.AddSSHKeyForm) {
ctx.Data["Title"] = ctx.Tr("repo.settings.deploy_keys")
ctx.Data["PageIsSettingsKeys"] = true
@@ -511,6 +522,7 @@ func DeployKeysPost(ctx *context.Context, form auth.AddSSHKeyForm) {
ctx.Redirect(ctx.Repo.RepoLink + "/settings/keys")
}
+// DeleteDeployKey response for deleting a deploy key
func DeleteDeployKey(ctx *context.Context) {
if err := models.DeleteDeployKey(ctx.User, ctx.QueryInt64("id")); err != nil {
ctx.Flash.Error("DeleteDeployKey: " + err.Error())
diff --git a/routers/repo/webhook.go b/routers/repo/webhook.go
index 3f292397b9..33ad834c95 100644
--- a/routers/repo/webhook.go
+++ b/routers/repo/webhook.go
@@ -28,6 +28,7 @@ const (
tplOrgHookNew base.TplName = "org/settings/hook_new"
)
+// Webhooks render web hooks list page
func Webhooks(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings.hooks")
ctx.Data["PageIsSettingsHooks"] = true
@@ -44,7 +45,7 @@ func Webhooks(ctx *context.Context) {
ctx.HTML(200, tplHooks)
}
-type OrgRepoCtx struct {
+type orgRepoCtx struct {
OrgID int64
RepoID int64
Link string
@@ -52,9 +53,9 @@ type OrgRepoCtx struct {
}
// getOrgRepoCtx determines whether this is a repo context or organization context.
-func getOrgRepoCtx(ctx *context.Context) (*OrgRepoCtx, error) {
+func getOrgRepoCtx(ctx *context.Context) (*orgRepoCtx, error) {
if len(ctx.Repo.RepoLink) > 0 {
- return &OrgRepoCtx{
+ return &orgRepoCtx{
RepoID: ctx.Repo.Repository.ID,
Link: ctx.Repo.RepoLink,
NewTemplate: tplHookNew,
@@ -62,7 +63,7 @@ func getOrgRepoCtx(ctx *context.Context) (*OrgRepoCtx, error) {
}
if len(ctx.Org.OrgLink) > 0 {
- return &OrgRepoCtx{
+ return &orgRepoCtx{
OrgID: ctx.Org.Organization.ID,
Link: ctx.Org.OrgLink,
NewTemplate: tplOrgHookNew,
@@ -81,6 +82,7 @@ func checkHookType(ctx *context.Context) string {
return hookType
}
+// WebhooksNew render creating webhook page
func WebhooksNew(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings.add_webhook")
ctx.Data["PageIsSettingsHooks"] = true
@@ -102,6 +104,7 @@ func WebhooksNew(ctx *context.Context) {
ctx.HTML(200, orCtx.NewTemplate)
}
+// ParseHookEvent convert web form content to models.HookEvent
func ParseHookEvent(form auth.WebhookForm) *models.HookEvent {
return &models.HookEvent{
PushOnly: form.PushOnly(),
@@ -115,6 +118,7 @@ func ParseHookEvent(form auth.WebhookForm) *models.HookEvent {
}
}
+// WebHooksNewPost response for creating webhook
func WebHooksNewPost(ctx *context.Context, form auth.NewWebhookForm) {
ctx.Data["Title"] = ctx.Tr("repo.settings.add_webhook")
ctx.Data["PageIsSettingsHooks"] = true
@@ -161,6 +165,7 @@ func WebHooksNewPost(ctx *context.Context, form auth.NewWebhookForm) {
ctx.Redirect(orCtx.Link + "/settings/hooks")
}
+// SlackHooksNewPost response for creating slack hook
func SlackHooksNewPost(ctx *context.Context, form auth.NewSlackHookForm) {
ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsHooks"] = true
@@ -211,7 +216,7 @@ func SlackHooksNewPost(ctx *context.Context, form auth.NewSlackHookForm) {
ctx.Redirect(orCtx.Link + "/settings/hooks")
}
-func checkWebhook(ctx *context.Context) (*OrgRepoCtx, *models.Webhook) {
+func checkWebhook(ctx *context.Context) (*orgRepoCtx, *models.Webhook) {
ctx.Data["RequireHighlightJS"] = true
orCtx, err := getOrgRepoCtx(ctx)
@@ -251,6 +256,7 @@ func checkWebhook(ctx *context.Context) (*OrgRepoCtx, *models.Webhook) {
return orCtx, w
}
+// WebHooksEdit render editing web hook page
func WebHooksEdit(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings.update_webhook")
ctx.Data["PageIsSettingsHooks"] = true
@@ -265,6 +271,7 @@ func WebHooksEdit(ctx *context.Context) {
ctx.HTML(200, orCtx.NewTemplate)
}
+// WebHooksEditPost response for editing web hook
func WebHooksEditPost(ctx *context.Context, form auth.NewWebhookForm) {
ctx.Data["Title"] = ctx.Tr("repo.settings.update_webhook")
ctx.Data["PageIsSettingsHooks"] = true
@@ -303,6 +310,7 @@ func WebHooksEditPost(ctx *context.Context, form auth.NewWebhookForm) {
ctx.Redirect(fmt.Sprintf("%s/settings/hooks/%d", orCtx.Link, w.ID))
}
+// SlackHooksEditPost reponse for editing slack hook
func SlackHooksEditPost(ctx *context.Context, form auth.NewSlackHookForm) {
ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsHooks"] = true
@@ -346,6 +354,7 @@ func SlackHooksEditPost(ctx *context.Context, form auth.NewSlackHookForm) {
ctx.Redirect(fmt.Sprintf("%s/settings/hooks/%d", orCtx.Link, w.ID))
}
+// TestWebhook test if web hook is work fine
func TestWebhook(ctx *context.Context) {
// Grab latest commit or fake one if it's empty repository.
commit := ctx.Repo.Commit
@@ -393,6 +402,7 @@ func TestWebhook(ctx *context.Context) {
}
}
+// DeleteWebhook delete a webhook
func DeleteWebhook(ctx *context.Context) {
if err := models.DeleteWebhookByRepoID(ctx.Repo.Repository.ID, ctx.QueryInt64("id")); err != nil {
ctx.Flash.Error("DeleteWebhookByRepoID: " + err.Error())