mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-25 14:02:47 +01:00
golint fixed for routers (#208)
This commit is contained in:
parent
3a3782bb7f
commit
3917ed45de
35 changed files with 354 additions and 155 deletions
|
@ -13,7 +13,8 @@ import (
|
|||
"code.gitea.io/gitea/routers/api/v1/user"
|
||||
)
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Administration-Organizations#create-a-new-organization
|
||||
// CreateOrg api for create organization
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Administration-Organizations#create-a-new-organization
|
||||
func CreateOrg(ctx *context.APIContext, form api.CreateOrgOption) {
|
||||
u := user.GetUserByParams(ctx)
|
||||
if ctx.Written() {
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/context"
|
||||
)
|
||||
|
||||
// GetRepositoryByParams api for getting repository by orgnizition ID and repo name
|
||||
func GetRepositoryByParams(ctx *context.APIContext) *models.Repository {
|
||||
repo, err := models.GetRepositoryByName(ctx.Org.Team.OrgID, ctx.Params(":reponame"))
|
||||
if err != nil {
|
||||
|
@ -22,6 +23,7 @@ func GetRepositoryByParams(ctx *context.APIContext) *models.Repository {
|
|||
return repo
|
||||
}
|
||||
|
||||
// AddTeamRepository api for adding a repository to a team
|
||||
func AddTeamRepository(ctx *context.APIContext) {
|
||||
repo := GetRepositoryByParams(ctx)
|
||||
if ctx.Written() {
|
||||
|
@ -35,6 +37,7 @@ func AddTeamRepository(ctx *context.APIContext) {
|
|||
ctx.Status(204)
|
||||
}
|
||||
|
||||
// RemoveTeamRepository api for removing a repository from a team
|
||||
func RemoveTeamRepository(ctx *context.APIContext) {
|
||||
repo := GetRepositoryByParams(ctx)
|
||||
if ctx.Written() {
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
"code.gitea.io/gitea/routers/api/v1/user"
|
||||
)
|
||||
|
||||
// CreateTeam api for create a team
|
||||
func CreateTeam(ctx *context.APIContext, form api.CreateTeamOption) {
|
||||
team := &models.Team{
|
||||
OrgID: ctx.Org.Organization.ID,
|
||||
|
@ -32,6 +33,7 @@ func CreateTeam(ctx *context.APIContext, form api.CreateTeamOption) {
|
|||
ctx.JSON(201, convert.ToTeam(team))
|
||||
}
|
||||
|
||||
// AddTeamMember api for add a member to a team
|
||||
func AddTeamMember(ctx *context.APIContext) {
|
||||
u := user.GetUserByParams(ctx)
|
||||
if ctx.Written() {
|
||||
|
@ -45,6 +47,7 @@ func AddTeamMember(ctx *context.APIContext) {
|
|||
ctx.Status(204)
|
||||
}
|
||||
|
||||
// RemoveTeamMember api for remove one member from a team
|
||||
func RemoveTeamMember(ctx *context.APIContext) {
|
||||
u := user.GetUserByParams(ctx)
|
||||
if ctx.Written() {
|
||||
|
|
|
@ -12,7 +12,8 @@ import (
|
|||
"code.gitea.io/gitea/routers/api/v1/user"
|
||||
)
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Administration-Repositories#create-a-new-repository
|
||||
// CreateRepo api for creating a repository
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Administration-Repositories#create-a-new-repository
|
||||
func CreateRepo(ctx *context.APIContext, form api.CreateRepoOption) {
|
||||
owner := user.GetUserByParams(ctx)
|
||||
if ctx.Written() {
|
||||
|
|
|
@ -34,7 +34,8 @@ func parseLoginSource(ctx *context.APIContext, u *models.User, sourceID int64, l
|
|||
u.LoginName = loginName
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Administration-Users#create-a-new-user
|
||||
// CreateUser api for creating a user
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Administration-Users#create-a-new-user
|
||||
func CreateUser(ctx *context.APIContext, form api.CreateUserOption) {
|
||||
u := &models.User{
|
||||
Name: form.Username,
|
||||
|
@ -71,7 +72,8 @@ func CreateUser(ctx *context.APIContext, form api.CreateUserOption) {
|
|||
ctx.JSON(201, u.APIFormat())
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Administration-Users#edit-an-existing-user
|
||||
// EditUser api for modifying a user's information
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Administration-Users#edit-an-existing-user
|
||||
func EditUser(ctx *context.APIContext, form api.EditUserOption) {
|
||||
u := user.GetUserByParams(ctx)
|
||||
if ctx.Written() {
|
||||
|
@ -123,6 +125,7 @@ func EditUser(ctx *context.APIContext, form api.EditUserOption) {
|
|||
ctx.JSON(200, u.APIFormat())
|
||||
}
|
||||
|
||||
// DeleteUser api for deleting a user
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Administration-Users#delete-a-user
|
||||
func DeleteUser(ctx *context.APIContext) {
|
||||
u := user.GetUserByParams(ctx)
|
||||
|
@ -144,7 +147,8 @@ func DeleteUser(ctx *context.APIContext) {
|
|||
ctx.Status(204)
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Administration-Users#create-a-public-key-for-user
|
||||
// CreatePublicKey api for creating a public key to a user
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Administration-Users#create-a-public-key-for-user
|
||||
func CreatePublicKey(ctx *context.APIContext, form api.CreateKeyOption) {
|
||||
u := user.GetUserByParams(ctx)
|
||||
if ctx.Written() {
|
||||
|
|
|
@ -9,12 +9,13 @@ import (
|
|||
|
||||
"github.com/Unknwon/com"
|
||||
|
||||
"code.gitea.io/git"
|
||||
api "code.gitea.io/sdk/gitea"
|
||||
|
||||
"code.gitea.io/git"
|
||||
"code.gitea.io/gitea/models"
|
||||
)
|
||||
|
||||
// ToEmail convert models.EmailAddress to api.Email
|
||||
func ToEmail(email *models.EmailAddress) *api.Email {
|
||||
return &api.Email{
|
||||
Email: email.Email,
|
||||
|
@ -23,6 +24,7 @@ func ToEmail(email *models.EmailAddress) *api.Email {
|
|||
}
|
||||
}
|
||||
|
||||
// ToBranch convert a commit and branch to an api.Branch
|
||||
func ToBranch(b *models.Branch, c *git.Commit) *api.Branch {
|
||||
return &api.Branch{
|
||||
Name: b.Name,
|
||||
|
@ -30,6 +32,7 @@ func ToBranch(b *models.Branch, c *git.Commit) *api.Branch {
|
|||
}
|
||||
}
|
||||
|
||||
// ToCommit convert a commit to api.PayloadCommit
|
||||
func ToCommit(c *git.Commit) *api.PayloadCommit {
|
||||
authorUsername := ""
|
||||
author, err := models.GetUserByEmail(c.Author.Email)
|
||||
|
@ -59,6 +62,7 @@ func ToCommit(c *git.Commit) *api.PayloadCommit {
|
|||
}
|
||||
}
|
||||
|
||||
// ToPublicKey convert models.PublicKey to api.PublicKey
|
||||
func ToPublicKey(apiLink string, key *models.PublicKey) *api.PublicKey {
|
||||
return &api.PublicKey{
|
||||
ID: key.ID,
|
||||
|
@ -69,6 +73,7 @@ func ToPublicKey(apiLink string, key *models.PublicKey) *api.PublicKey {
|
|||
}
|
||||
}
|
||||
|
||||
// ToHook convert models.Webhook to api.Hook
|
||||
func ToHook(repoLink string, w *models.Webhook) *api.Hook {
|
||||
config := map[string]string{
|
||||
"url": w.URL,
|
||||
|
@ -94,6 +99,7 @@ func ToHook(repoLink string, w *models.Webhook) *api.Hook {
|
|||
}
|
||||
}
|
||||
|
||||
// ToDeployKey convert models.DeployKey to api.DeployKey
|
||||
func ToDeployKey(apiLink string, key *models.DeployKey) *api.DeployKey {
|
||||
return &api.DeployKey{
|
||||
ID: key.ID,
|
||||
|
@ -105,6 +111,7 @@ func ToDeployKey(apiLink string, key *models.DeployKey) *api.DeployKey {
|
|||
}
|
||||
}
|
||||
|
||||
// ToOrganization convert models.User to api.Organization
|
||||
func ToOrganization(org *models.User) *api.Organization {
|
||||
return &api.Organization{
|
||||
ID: org.ID,
|
||||
|
@ -117,6 +124,7 @@ func ToOrganization(org *models.User) *api.Organization {
|
|||
}
|
||||
}
|
||||
|
||||
// ToTeam convert models.Team to api.Team
|
||||
func ToTeam(team *models.Team) *api.Team {
|
||||
return &api.Team{
|
||||
ID: team.ID,
|
||||
|
|
|
@ -11,7 +11,8 @@ import (
|
|||
"code.gitea.io/gitea/modules/markdown"
|
||||
)
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Miscellaneous#render-an-arbitrary-markdown-document
|
||||
// Markdown render markdown document to HTML
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Miscellaneous#render-an-arbitrary-markdown-document
|
||||
func Markdown(ctx *context.APIContext, form api.MarkdownOption) {
|
||||
if ctx.HasApiError() {
|
||||
ctx.Error(422, "", ctx.GetErrMsg())
|
||||
|
@ -31,7 +32,8 @@ func Markdown(ctx *context.APIContext, form api.MarkdownOption) {
|
|||
}
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Miscellaneous#render-a-markdown-document-in-raw-mode
|
||||
// MarkdownRaw render raw markdown HTML
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Miscellaneous#render-a-markdown-document-in-raw-mode
|
||||
func MarkdownRaw(ctx *context.APIContext) {
|
||||
body, err := ctx.Req.Body().Bytes()
|
||||
if err != nil {
|
||||
|
|
|
@ -26,12 +26,14 @@ func listUserOrgs(ctx *context.APIContext, u *models.User, all bool) {
|
|||
ctx.JSON(200, &apiOrgs)
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Organizations#list-your-organizations
|
||||
// ListMyOrgs list all my orgs
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Organizations#list-your-organizations
|
||||
func ListMyOrgs(ctx *context.APIContext) {
|
||||
listUserOrgs(ctx, ctx.User, true)
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Organizations#list-user-organizations
|
||||
// ListUserOrgs list user's orgs
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Organizations#list-user-organizations
|
||||
func ListUserOrgs(ctx *context.APIContext) {
|
||||
u := user.GetUserByParams(ctx)
|
||||
if ctx.Written() {
|
||||
|
@ -40,12 +42,14 @@ func ListUserOrgs(ctx *context.APIContext) {
|
|||
listUserOrgs(ctx, u, false)
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Organizations#get-an-organization
|
||||
// Get get an organization
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Organizations#get-an-organization
|
||||
func Get(ctx *context.APIContext) {
|
||||
ctx.JSON(200, convert.ToOrganization(ctx.Org.Organization))
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Organizations#edit-an-organization
|
||||
// Edit change an organization's information
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Organizations#edit-an-organization
|
||||
func Edit(ctx *context.APIContext, form api.EditOrgOption) {
|
||||
org := ctx.Org.Organization
|
||||
if !org.IsOwnedBy(ctx.User.ID) {
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"code.gitea.io/gitea/routers/api/v1/convert"
|
||||
)
|
||||
|
||||
// ListTeams list all the teams of an organization
|
||||
func ListTeams(ctx *context.APIContext) {
|
||||
org := ctx.Org.Organization
|
||||
if err := org.GetTeams(); err != nil {
|
||||
|
|
|
@ -11,7 +11,8 @@ import (
|
|||
"code.gitea.io/gitea/routers/api/v1/convert"
|
||||
)
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#get-branch
|
||||
// GetBranch get a branch of a repository
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories#get-branch
|
||||
func GetBranch(ctx *context.APIContext) {
|
||||
branch, err := ctx.Repo.Repository.GetBranch(ctx.Params(":branchname"))
|
||||
if err != nil {
|
||||
|
@ -28,7 +29,8 @@ func GetBranch(ctx *context.APIContext) {
|
|||
ctx.JSON(200, convert.ToBranch(branch, c))
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#list-branches
|
||||
// ListBranches list all the branches of a repository
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories#list-branches
|
||||
func ListBranches(ctx *context.APIContext) {
|
||||
branches, err := ctx.Repo.Repository.GetBranches()
|
||||
if err != nil {
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/context"
|
||||
)
|
||||
|
||||
// AddCollaborator add a collaborator of a repository
|
||||
func AddCollaborator(ctx *context.APIContext, form api.AddCollaboratorOption) {
|
||||
collaborator, err := models.GetUserByName(ctx.Params(":collaborator"))
|
||||
if err != nil {
|
||||
|
|
|
@ -12,7 +12,8 @@ import (
|
|||
"code.gitea.io/gitea/routers/repo"
|
||||
)
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Contents#download-raw-content
|
||||
// GetRawFile get a file by path on a repository
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories-Contents#download-raw-content
|
||||
func GetRawFile(ctx *context.APIContext) {
|
||||
if !ctx.Repo.HasAccess() {
|
||||
ctx.Status(404)
|
||||
|
@ -33,7 +34,8 @@ func GetRawFile(ctx *context.APIContext) {
|
|||
}
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Contents#download-archive
|
||||
// GetArchive get archive of a repository
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories-Contents#download-archive
|
||||
func GetArchive(ctx *context.APIContext) {
|
||||
repoPath := models.RepoPath(ctx.Params(":username"), ctx.Params(":reponame"))
|
||||
gitRepo, err := git.OpenRepository(repoPath)
|
||||
|
@ -46,6 +48,7 @@ func GetArchive(ctx *context.APIContext) {
|
|||
repo.Download(ctx.Context)
|
||||
}
|
||||
|
||||
// GetEditorconfig get editor config of a repository
|
||||
func GetEditorconfig(ctx *context.APIContext) {
|
||||
ec, err := ctx.Repo.GetEditorconfig()
|
||||
if err != nil {
|
||||
|
|
|
@ -16,7 +16,8 @@ import (
|
|||
"code.gitea.io/gitea/routers/api/v1/convert"
|
||||
)
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#list-hooks
|
||||
// ListHooks list all hooks of a repository
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories#list-hooks
|
||||
func ListHooks(ctx *context.APIContext) {
|
||||
hooks, err := models.GetWebhooksByRepoID(ctx.Repo.Repository.ID)
|
||||
if err != nil {
|
||||
|
@ -31,7 +32,8 @@ func ListHooks(ctx *context.APIContext) {
|
|||
ctx.JSON(200, &apiHooks)
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#create-a-hook
|
||||
// CreateHook create a hook for a repository
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories#create-a-hook
|
||||
func CreateHook(ctx *context.APIContext, form api.CreateHookOption) {
|
||||
if !models.IsValidHookTaskType(form.Type) {
|
||||
ctx.Error(422, "", "Invalid hook type")
|
||||
|
@ -97,7 +99,8 @@ func CreateHook(ctx *context.APIContext, form api.CreateHookOption) {
|
|||
ctx.JSON(201, convert.ToHook(ctx.Repo.RepoLink, w))
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#edit-a-hook
|
||||
// EditHook modify a hook of a repository
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories#edit-a-hook
|
||||
func EditHook(ctx *context.APIContext, form api.EditHookOption) {
|
||||
w, err := models.GetWebhookByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
|
@ -165,6 +168,7 @@ func EditHook(ctx *context.APIContext, form api.EditHookOption) {
|
|||
ctx.JSON(200, convert.ToHook(ctx.Repo.RepoLink, w))
|
||||
}
|
||||
|
||||
// DeleteHook delete a hook of a repository
|
||||
func DeleteHook(ctx *context.APIContext) {
|
||||
if err := models.DeleteWebhookByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")); err != nil {
|
||||
ctx.Error(500, "DeleteWebhookByRepoID", err)
|
||||
|
|
|
@ -15,6 +15,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/setting"
|
||||
)
|
||||
|
||||
// ListIssues list the issues of a repository
|
||||
func ListIssues(ctx *context.APIContext) {
|
||||
issues, err := models.Issues(&models.IssuesOptions{
|
||||
RepoID: ctx.Repo.Repository.ID,
|
||||
|
@ -39,6 +40,7 @@ func ListIssues(ctx *context.APIContext) {
|
|||
ctx.JSON(200, &apiIssues)
|
||||
}
|
||||
|
||||
// GetIssue get an issue of a repository
|
||||
func GetIssue(ctx *context.APIContext) {
|
||||
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
if err != nil {
|
||||
|
@ -52,6 +54,7 @@ func GetIssue(ctx *context.APIContext) {
|
|||
ctx.JSON(200, issue.APIFormat())
|
||||
}
|
||||
|
||||
// CreateIssue create an issue of a repository
|
||||
func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
|
||||
issue := &models.Issue{
|
||||
RepoID: ctx.Repo.Repository.ID,
|
||||
|
@ -101,6 +104,7 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
|
|||
ctx.JSON(201, issue.APIFormat())
|
||||
}
|
||||
|
||||
// EditIssue modify an issue of a repository
|
||||
func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
|
||||
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
if err != nil {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright 2015 The Gogs Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package repo
|
||||
|
||||
import (
|
||||
|
@ -12,6 +13,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/context"
|
||||
)
|
||||
|
||||
// ListIssueComments list all the comments of an issue
|
||||
func ListIssueComments(ctx *context.APIContext) {
|
||||
var since time.Time
|
||||
if len(ctx.Query("since")) > 0 {
|
||||
|
@ -38,6 +40,7 @@ func ListIssueComments(ctx *context.APIContext) {
|
|||
ctx.JSON(200, &apiComments)
|
||||
}
|
||||
|
||||
// CreateIssueComment create a comment for an issue
|
||||
func CreateIssueComment(ctx *context.APIContext, form api.CreateIssueCommentOption) {
|
||||
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
if err != nil {
|
||||
|
@ -54,6 +57,7 @@ func CreateIssueComment(ctx *context.APIContext, form api.CreateIssueCommentOpti
|
|||
ctx.JSON(201, comment.APIFormat())
|
||||
}
|
||||
|
||||
// EditIssueComment modify a comment of an issue
|
||||
func EditIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption) {
|
||||
comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/context"
|
||||
)
|
||||
|
||||
// ListIssueLabels list all the labels of an issue
|
||||
func ListIssueLabels(ctx *context.APIContext) {
|
||||
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
if err != nil {
|
||||
|
@ -29,6 +30,7 @@ func ListIssueLabels(ctx *context.APIContext) {
|
|||
ctx.JSON(200, &apiLabels)
|
||||
}
|
||||
|
||||
// AddIssueLabels add labels for an issue
|
||||
func AddIssueLabels(ctx *context.APIContext, form api.IssueLabelsOption) {
|
||||
if !ctx.Repo.IsWriter() {
|
||||
ctx.Status(403)
|
||||
|
@ -69,6 +71,7 @@ func AddIssueLabels(ctx *context.APIContext, form api.IssueLabelsOption) {
|
|||
ctx.JSON(200, &apiLabels)
|
||||
}
|
||||
|
||||
// DeleteIssueLabel delete a label for an issue
|
||||
func DeleteIssueLabel(ctx *context.APIContext) {
|
||||
if !ctx.Repo.IsWriter() {
|
||||
ctx.Status(403)
|
||||
|
@ -103,6 +106,7 @@ func DeleteIssueLabel(ctx *context.APIContext) {
|
|||
ctx.Status(204)
|
||||
}
|
||||
|
||||
// ReplaceIssueLabels replace labels for an issue
|
||||
func ReplaceIssueLabels(ctx *context.APIContext, form api.IssueLabelsOption) {
|
||||
if !ctx.Repo.IsWriter() {
|
||||
ctx.Status(403)
|
||||
|
@ -143,6 +147,7 @@ func ReplaceIssueLabels(ctx *context.APIContext, form api.IssueLabelsOption) {
|
|||
ctx.JSON(200, &apiLabels)
|
||||
}
|
||||
|
||||
// ClearIssueLabels delete all the labels for an issue
|
||||
func ClearIssueLabels(ctx *context.APIContext) {
|
||||
if !ctx.Repo.IsWriter() {
|
||||
ctx.Status(403)
|
||||
|
|
|
@ -19,7 +19,8 @@ func composeDeployKeysAPILink(repoPath string) string {
|
|||
return setting.AppUrl + "api/v1/repos/" + repoPath + "/keys/"
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#list-deploy-keys
|
||||
// ListDeployKeys list all the deploy keys of a repository
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#list-deploy-keys
|
||||
func ListDeployKeys(ctx *context.APIContext) {
|
||||
keys, err := models.ListDeployKeys(ctx.Repo.Repository.ID)
|
||||
if err != nil {
|
||||
|
@ -40,7 +41,8 @@ func ListDeployKeys(ctx *context.APIContext) {
|
|||
ctx.JSON(200, &apiKeys)
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#get-a-deploy-key
|
||||
// GetDeployKey get a deploy key by id
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#get-a-deploy-key
|
||||
func GetDeployKey(ctx *context.APIContext) {
|
||||
key, err := models.GetDeployKeyByID(ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
|
@ -61,6 +63,7 @@ func GetDeployKey(ctx *context.APIContext) {
|
|||
ctx.JSON(200, convert.ToDeployKey(apiLink, key))
|
||||
}
|
||||
|
||||
// HandleCheckKeyStringError handle check key error
|
||||
func HandleCheckKeyStringError(ctx *context.APIContext, err error) {
|
||||
if models.IsErrKeyUnableVerify(err) {
|
||||
ctx.Error(422, "", "Unable to verify key content")
|
||||
|
@ -69,6 +72,7 @@ func HandleCheckKeyStringError(ctx *context.APIContext, err error) {
|
|||
}
|
||||
}
|
||||
|
||||
// HandleAddKeyError handle add key error
|
||||
func HandleAddKeyError(ctx *context.APIContext, err error) {
|
||||
switch {
|
||||
case models.IsErrKeyAlreadyExist(err):
|
||||
|
@ -80,7 +84,8 @@ func HandleAddKeyError(ctx *context.APIContext, err error) {
|
|||
}
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#add-a-new-deploy-key
|
||||
// CreateDeployKey create deploy key for a repository
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#add-a-new-deploy-key
|
||||
func CreateDeployKey(ctx *context.APIContext, form api.CreateKeyOption) {
|
||||
content, err := models.CheckPublicKeyString(form.Key)
|
||||
if err != nil {
|
||||
|
@ -99,7 +104,8 @@ func CreateDeployKey(ctx *context.APIContext, form api.CreateKeyOption) {
|
|||
ctx.JSON(201, convert.ToDeployKey(apiLink, key))
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#remove-a-deploy-key
|
||||
// DeleteDeploykey delete deploy key for a repository
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#remove-a-deploy-key
|
||||
func DeleteDeploykey(ctx *context.APIContext) {
|
||||
if err := models.DeleteDeployKey(ctx.User, ctx.ParamsInt64(":id")); err != nil {
|
||||
if models.IsErrKeyAccessDenied(err) {
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/context"
|
||||
)
|
||||
|
||||
// ListLabels list all the labels of a repository
|
||||
func ListLabels(ctx *context.APIContext) {
|
||||
labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID)
|
||||
if err != nil {
|
||||
|
@ -25,6 +26,7 @@ func ListLabels(ctx *context.APIContext) {
|
|||
ctx.JSON(200, &apiLabels)
|
||||
}
|
||||
|
||||
// GetLabel get label by repository and label id
|
||||
func GetLabel(ctx *context.APIContext) {
|
||||
label, err := models.GetLabelInRepoByID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
|
@ -39,6 +41,7 @@ func GetLabel(ctx *context.APIContext) {
|
|||
ctx.JSON(200, label.APIFormat())
|
||||
}
|
||||
|
||||
// CreateLabel create a label for a repository
|
||||
func CreateLabel(ctx *context.APIContext, form api.CreateLabelOption) {
|
||||
if !ctx.Repo.IsWriter() {
|
||||
ctx.Status(403)
|
||||
|
@ -57,6 +60,7 @@ func CreateLabel(ctx *context.APIContext, form api.CreateLabelOption) {
|
|||
ctx.JSON(201, label.APIFormat())
|
||||
}
|
||||
|
||||
// EditLabel modify a label for a repository
|
||||
func EditLabel(ctx *context.APIContext, form api.EditLabelOption) {
|
||||
if !ctx.Repo.IsWriter() {
|
||||
ctx.Status(403)
|
||||
|
@ -86,6 +90,7 @@ func EditLabel(ctx *context.APIContext, form api.EditLabelOption) {
|
|||
ctx.JSON(200, label.APIFormat())
|
||||
}
|
||||
|
||||
// DeleteLabel delete a label for a repository
|
||||
func DeleteLabel(ctx *context.APIContext) {
|
||||
if !ctx.Repo.IsWriter() {
|
||||
ctx.Status(403)
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/context"
|
||||
)
|
||||
|
||||
// ListMilestones list all the milestones for a repository
|
||||
func ListMilestones(ctx *context.APIContext) {
|
||||
milestones, err := models.GetMilestonesByRepoID(ctx.Repo.Repository.ID)
|
||||
if err != nil {
|
||||
|
@ -27,6 +28,7 @@ func ListMilestones(ctx *context.APIContext) {
|
|||
ctx.JSON(200, &apiMilestones)
|
||||
}
|
||||
|
||||
// GetMilestone get a milestone for a repository
|
||||
func GetMilestone(ctx *context.APIContext) {
|
||||
milestone, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
|
@ -40,6 +42,7 @@ func GetMilestone(ctx *context.APIContext) {
|
|||
ctx.JSON(200, milestone.APIFormat())
|
||||
}
|
||||
|
||||
// CreateMilestone create a milestone for a repository
|
||||
func CreateMilestone(ctx *context.APIContext, form api.CreateMilestoneOption) {
|
||||
if form.Deadline == nil {
|
||||
defaultDeadline, _ := time.ParseInLocation("2006-01-02", "9999-12-31", time.Local)
|
||||
|
@ -60,6 +63,7 @@ func CreateMilestone(ctx *context.APIContext, form api.CreateMilestoneOption) {
|
|||
ctx.JSON(201, milestone.APIFormat())
|
||||
}
|
||||
|
||||
// EditMilestone modify a milestone for a repository
|
||||
func EditMilestone(ctx *context.APIContext, form api.EditMilestoneOption) {
|
||||
milestone, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
|
@ -88,6 +92,7 @@ func EditMilestone(ctx *context.APIContext, form api.EditMilestoneOption) {
|
|||
ctx.JSON(200, milestone.APIFormat())
|
||||
}
|
||||
|
||||
// DeleteMilestone delete a milestone for a repository
|
||||
func DeleteMilestone(ctx *context.APIContext) {
|
||||
if err := models.DeleteMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")); err != nil {
|
||||
ctx.Error(500, "DeleteMilestoneByRepoID", err)
|
||||
|
|
|
@ -17,7 +17,8 @@ import (
|
|||
"code.gitea.io/gitea/routers/api/v1/convert"
|
||||
)
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#search-repositories
|
||||
// Search repositories via options
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories#search-repositories
|
||||
func Search(ctx *context.APIContext) {
|
||||
opts := &models.SearchRepoOptions{
|
||||
Keyword: path.Base(ctx.Query("q")),
|
||||
|
@ -76,7 +77,8 @@ func Search(ctx *context.APIContext) {
|
|||
})
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#list-your-repositories
|
||||
// ListMyRepos list all my repositories
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories#list-your-repositories
|
||||
func ListMyRepos(ctx *context.APIContext) {
|
||||
ownRepos, err := models.GetUserRepositories(ctx.User.ID, true, 1, ctx.User.NumRepos)
|
||||
if err != nil {
|
||||
|
@ -109,6 +111,7 @@ func ListMyRepos(ctx *context.APIContext) {
|
|||
ctx.JSON(200, &repos)
|
||||
}
|
||||
|
||||
// CreateUserRepo create a repository for a user
|
||||
func CreateUserRepo(ctx *context.APIContext, owner *models.User, opt api.CreateRepoOption) {
|
||||
repo, err := models.CreateRepository(owner, models.CreateRepoOptions{
|
||||
Name: opt.Name,
|
||||
|
@ -138,7 +141,8 @@ func CreateUserRepo(ctx *context.APIContext, owner *models.User, opt api.CreateR
|
|||
ctx.JSON(201, repo.APIFormat(&api.Permission{true, true, true}))
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#create
|
||||
// Create create one repository of mine
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories#create
|
||||
func Create(ctx *context.APIContext, opt api.CreateRepoOption) {
|
||||
// Shouldn't reach this condition, but just in case.
|
||||
if ctx.User.IsOrganization() {
|
||||
|
@ -148,6 +152,7 @@ func Create(ctx *context.APIContext, opt api.CreateRepoOption) {
|
|||
CreateUserRepo(ctx, ctx.User, opt)
|
||||
}
|
||||
|
||||
// CreateOrgRepo create one repository of the organization
|
||||
func CreateOrgRepo(ctx *context.APIContext, opt api.CreateRepoOption) {
|
||||
org, err := models.GetOrgByName(ctx.Params(":org"))
|
||||
if err != nil {
|
||||
|
@ -166,7 +171,8 @@ func CreateOrgRepo(ctx *context.APIContext, opt api.CreateRepoOption) {
|
|||
CreateUserRepo(ctx, org, opt)
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#migrate
|
||||
// Migrate migrate remote git repository to gitea
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories#migrate
|
||||
func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) {
|
||||
ctxUser := ctx.User
|
||||
// Not equal means context user is an organization,
|
||||
|
@ -238,13 +244,15 @@ func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) {
|
|||
ctx.JSON(201, repo.APIFormat(&api.Permission{true, true, true}))
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#get
|
||||
// Get get one repository
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories#get
|
||||
func Get(ctx *context.APIContext) {
|
||||
repo := ctx.Repo.Repository
|
||||
ctx.JSON(200, repo.APIFormat(&api.Permission{true, true, true}))
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#delete
|
||||
// Delete delete one repository
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories#delete
|
||||
func Delete(ctx *context.APIContext) {
|
||||
owner := ctx.Repo.Owner
|
||||
repo := ctx.Repo.Repository
|
||||
|
|
|
@ -11,7 +11,8 @@ import (
|
|||
"code.gitea.io/gitea/modules/context"
|
||||
)
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Users#list-access-tokens-for-a-user
|
||||
// ListAccessTokens list all the access tokens
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Users#list-access-tokens-for-a-user
|
||||
func ListAccessTokens(ctx *context.APIContext) {
|
||||
tokens, err := models.ListAccessTokens(ctx.User.ID)
|
||||
if err != nil {
|
||||
|
@ -26,7 +27,8 @@ func ListAccessTokens(ctx *context.APIContext) {
|
|||
ctx.JSON(200, &apiTokens)
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Users#create-a-access-token
|
||||
// CreateAccessToken create access tokens
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Users#create-a-access-token
|
||||
func CreateAccessToken(ctx *context.APIContext, form api.CreateAccessTokenOption) {
|
||||
t := &models.AccessToken{
|
||||
UID: ctx.User.ID,
|
||||
|
|
|
@ -13,7 +13,8 @@ import (
|
|||
"code.gitea.io/gitea/routers/api/v1/convert"
|
||||
)
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Users-Emails#list-email-addresses-for-a-user
|
||||
// ListEmails list all the emails of mine
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Users-Emails#list-email-addresses-for-a-user
|
||||
func ListEmails(ctx *context.APIContext) {
|
||||
emails, err := models.GetEmailAddresses(ctx.User.ID)
|
||||
if err != nil {
|
||||
|
@ -27,7 +28,8 @@ func ListEmails(ctx *context.APIContext) {
|
|||
ctx.JSON(200, &apiEmails)
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Users-Emails#add-email-addresses
|
||||
// AddEmail add email for me
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Users-Emails#add-email-addresses
|
||||
func AddEmail(ctx *context.APIContext, form api.CreateEmailOption) {
|
||||
if len(form.Emails) == 0 {
|
||||
ctx.Status(422)
|
||||
|
@ -59,7 +61,8 @@ func AddEmail(ctx *context.APIContext, form api.CreateEmailOption) {
|
|||
ctx.JSON(201, &apiEmails)
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Users-Emails#delete-email-addresses
|
||||
// DeleteEmail delete email
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Users-Emails#delete-email-addresses
|
||||
func DeleteEmail(ctx *context.APIContext, form api.CreateEmailOption) {
|
||||
if len(form.Emails) == 0 {
|
||||
ctx.Status(204)
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/context"
|
||||
)
|
||||
|
||||
func responseApiUsers(ctx *context.APIContext, users []*models.User) {
|
||||
func responseAPIUsers(ctx *context.APIContext, users []*models.User) {
|
||||
apiUsers := make([]*api.User, len(users))
|
||||
for i := range users {
|
||||
apiUsers[i] = users[i].APIFormat()
|
||||
|
@ -25,14 +25,16 @@ func listUserFollowers(ctx *context.APIContext, u *models.User) {
|
|||
ctx.Error(500, "GetUserFollowers", err)
|
||||
return
|
||||
}
|
||||
responseApiUsers(ctx, users)
|
||||
responseAPIUsers(ctx, users)
|
||||
}
|
||||
|
||||
// ListMyFollowers list all my followers
|
||||
func ListMyFollowers(ctx *context.APIContext) {
|
||||
listUserFollowers(ctx, ctx.User)
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Users-Followers#list-followers-of-a-user
|
||||
// ListFollowers list user's followers
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Users-Followers#list-followers-of-a-user
|
||||
func ListFollowers(ctx *context.APIContext) {
|
||||
u := GetUserByParams(ctx)
|
||||
if ctx.Written() {
|
||||
|
@ -47,14 +49,16 @@ func listUserFollowing(ctx *context.APIContext, u *models.User) {
|
|||
ctx.Error(500, "GetFollowing", err)
|
||||
return
|
||||
}
|
||||
responseApiUsers(ctx, users)
|
||||
responseAPIUsers(ctx, users)
|
||||
}
|
||||
|
||||
// ListMyFollowing list all my followings
|
||||
func ListMyFollowing(ctx *context.APIContext) {
|
||||
listUserFollowing(ctx, ctx.User)
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Users-Followers#list-users-followed-by-another-user
|
||||
// ListFollowing list user's followings
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Users-Followers#list-users-followed-by-another-user
|
||||
func ListFollowing(ctx *context.APIContext) {
|
||||
u := GetUserByParams(ctx)
|
||||
if ctx.Written() {
|
||||
|
@ -71,7 +75,8 @@ func checkUserFollowing(ctx *context.APIContext, u *models.User, followID int64)
|
|||
}
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Users-Followers#check-if-you-are-following-a-user
|
||||
// CheckMyFollowing check if the repo is followed by me
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Users-Followers#check-if-you-are-following-a-user
|
||||
func CheckMyFollowing(ctx *context.APIContext) {
|
||||
target := GetUserByParams(ctx)
|
||||
if ctx.Written() {
|
||||
|
@ -80,7 +85,8 @@ func CheckMyFollowing(ctx *context.APIContext) {
|
|||
checkUserFollowing(ctx, ctx.User, target.ID)
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Users-Followers#check-if-one-user-follows-another
|
||||
// CheckFollowing check if the repo is followed by user
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Users-Followers#check-if-one-user-follows-another
|
||||
func CheckFollowing(ctx *context.APIContext) {
|
||||
u := GetUserByParams(ctx)
|
||||
if ctx.Written() {
|
||||
|
@ -93,7 +99,8 @@ func CheckFollowing(ctx *context.APIContext) {
|
|||
checkUserFollowing(ctx, u, target.ID)
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Users-Followers#follow-a-user
|
||||
// Follow follow one repository
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Users-Followers#follow-a-user
|
||||
func Follow(ctx *context.APIContext) {
|
||||
target := GetUserByParams(ctx)
|
||||
if ctx.Written() {
|
||||
|
@ -106,7 +113,8 @@ func Follow(ctx *context.APIContext) {
|
|||
ctx.Status(204)
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Users-Followers#unfollow-a-user
|
||||
// Unfollow unfollow one repository
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Users-Followers#unfollow-a-user
|
||||
func Unfollow(ctx *context.APIContext) {
|
||||
target := GetUserByParams(ctx)
|
||||
if ctx.Written() {
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
"code.gitea.io/gitea/routers/api/v1/repo"
|
||||
)
|
||||
|
||||
// GetUserByParamsName get user by name
|
||||
func GetUserByParamsName(ctx *context.APIContext, name string) *models.User {
|
||||
user, err := models.GetUserByName(ctx.Params(name))
|
||||
if err != nil {
|
||||
|
@ -52,12 +53,14 @@ func listPublicKeys(ctx *context.APIContext, uid int64) {
|
|||
ctx.JSON(200, &apiKeys)
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#list-your-public-keys
|
||||
// ListMyPublicKeys list all my public keys
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#list-your-public-keys
|
||||
func ListMyPublicKeys(ctx *context.APIContext) {
|
||||
listPublicKeys(ctx, ctx.User.ID)
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#list-public-keys-for-a-user
|
||||
// ListPublicKeys list all user's public keys
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#list-public-keys-for-a-user
|
||||
func ListPublicKeys(ctx *context.APIContext) {
|
||||
user := GetUserByParams(ctx)
|
||||
if ctx.Written() {
|
||||
|
@ -66,7 +69,8 @@ func ListPublicKeys(ctx *context.APIContext) {
|
|||
listPublicKeys(ctx, user.ID)
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#get-a-single-public-key
|
||||
// GetPublicKey get one public key
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#get-a-single-public-key
|
||||
func GetPublicKey(ctx *context.APIContext) {
|
||||
key, err := models.GetPublicKeyByID(ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
|
@ -99,12 +103,14 @@ func CreateUserPublicKey(ctx *context.APIContext, form api.CreateKeyOption, uid
|
|||
ctx.JSON(201, convert.ToPublicKey(apiLink, key))
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#create-a-public-key
|
||||
// CreatePublicKey create one public key for me
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#create-a-public-key
|
||||
func CreatePublicKey(ctx *context.APIContext, form api.CreateKeyOption) {
|
||||
CreateUserPublicKey(ctx, form, ctx.User.ID)
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#delete-a-public-key
|
||||
// DeletePublicKey delete one public key of mine
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#delete-a-public-key
|
||||
func DeletePublicKey(ctx *context.APIContext) {
|
||||
if err := models.DeletePublicKey(ctx.User, ctx.ParamsInt64(":id")); err != nil {
|
||||
if models.IsErrKeyAccessDenied(err) {
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/context"
|
||||
)
|
||||
|
||||
// Search search users
|
||||
func Search(ctx *context.APIContext) {
|
||||
opts := &models.SearchUserOptions{
|
||||
Keyword: ctx.Query("q"),
|
||||
|
@ -51,6 +52,7 @@ func Search(ctx *context.APIContext) {
|
|||
})
|
||||
}
|
||||
|
||||
// GetInfo get user's information
|
||||
func GetInfo(ctx *context.APIContext) {
|
||||
u, err := models.GetUserByName(ctx.Params(":username"))
|
||||
if err != nil {
|
||||
|
@ -69,6 +71,7 @@ func GetInfo(ctx *context.APIContext) {
|
|||
ctx.JSON(200, u.APIFormat())
|
||||
}
|
||||
|
||||
// GetAuthenticatedUser get curent user's information
|
||||
func GetAuthenticatedUser(ctx *context.APIContext) {
|
||||
ctx.JSON(200, ctx.User.APIFormat())
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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("*")
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in a new issue