本文整理汇总了Golang中github.com/pecastro/gogs/modules/middleware.Context.Written方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Written方法的具体用法?Golang Context.Written怎么用?Golang Context.Written使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pecastro/gogs/modules/middleware.Context
的用法示例。
在下文中一共展示了Context.Written方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: UpdateIssueMilestone
func UpdateIssueMilestone(ctx *middleware.Context) {
issue := getActionIssue(ctx)
if ctx.Written() {
return
}
oldMid := issue.MilestoneID
mid := ctx.QueryInt64("id")
if oldMid == mid {
ctx.JSON(200, map[string]interface{}{
"ok": true,
})
return
}
// Not check for invalid milestone id and give responsibility to owners.
issue.MilestoneID = mid
if err := models.ChangeMilestoneAssign(oldMid, issue); err != nil {
ctx.Handle(500, "ChangeMilestoneAssign", err)
return
}
ctx.JSON(200, map[string]interface{}{
"ok": true,
})
}
示例2: UpdateIssueTitle
func UpdateIssueTitle(ctx *middleware.Context) {
issue := getActionIssue(ctx)
if ctx.Written() {
return
}
if !ctx.IsSigned || (ctx.User.Id != issue.PosterID && !ctx.Repo.IsAdmin()) {
ctx.Error(403)
return
}
issue.Name = ctx.Query("title")
if len(issue.Name) == 0 {
ctx.Error(204)
return
}
if err := models.UpdateIssue(issue); err != nil {
ctx.Handle(500, "UpdateIssue", err)
return
}
ctx.JSON(200, map[string]interface{}{
"title": issue.Name,
})
}
示例3: UpdateIssueAssignee
func UpdateIssueAssignee(ctx *middleware.Context) {
issue := getActionIssue(ctx)
if ctx.Written() {
return
}
aid := ctx.QueryInt64("id")
if issue.AssigneeID == aid {
ctx.JSON(200, map[string]interface{}{
"ok": true,
})
return
}
// Not check for invalid assignee id and give responsibility to owners.
issue.AssigneeID = aid
if err := models.UpdateIssueUserByAssignee(issue); err != nil {
ctx.Handle(500, "UpdateIssueUserByAssignee: %v", err)
return
}
ctx.JSON(200, map[string]interface{}{
"ok": true,
})
}
示例4: MigratePost
func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) {
ctx.Data["Title"] = ctx.Tr("new_migrate")
ctxUser := checkContextUser(ctx, form.Uid)
if ctx.Written() {
return
}
ctx.Data["ContextUser"] = ctxUser
if ctx.HasError() {
ctx.HTML(200, MIGRATE)
return
}
// Remote address can be HTTP/HTTPS/Git URL or local path.
// Note: remember to change api/v1/repo.go: MigrateRepo
// FIXME: merge these two functions with better error handling
remoteAddr := form.CloneAddr
if strings.HasPrefix(form.CloneAddr, "http://") ||
strings.HasPrefix(form.CloneAddr, "https://") ||
strings.HasPrefix(form.CloneAddr, "git://") {
u, err := url.Parse(form.CloneAddr)
if err != nil {
ctx.Data["Err_CloneAddr"] = true
ctx.RenderWithErr(ctx.Tr("form.url_error"), MIGRATE, &form)
return
}
if len(form.AuthUsername) > 0 || len(form.AuthPassword) > 0 {
u.User = url.UserPassword(form.AuthUsername, form.AuthPassword)
}
remoteAddr = u.String()
} else if !com.IsDir(remoteAddr) {
ctx.Data["Err_CloneAddr"] = true
ctx.RenderWithErr(ctx.Tr("repo.migrate.invalid_local_path"), MIGRATE, &form)
return
}
repo, err := models.MigrateRepository(ctxUser, form.RepoName, form.Description, form.Private, form.Mirror, remoteAddr)
if err == nil {
log.Trace("Repository migrated: %s/%s", ctxUser.Name, form.RepoName)
ctx.Redirect(setting.AppSubUrl + "/" + ctxUser.Name + "/" + form.RepoName)
return
}
if repo != nil {
if errDelete := models.DeleteRepository(ctxUser.Id, repo.ID); errDelete != nil {
log.Error(4, "DeleteRepository: %v", errDelete)
}
}
if strings.Contains(err.Error(), "Authentication failed") ||
strings.Contains(err.Error(), " not found") {
ctx.Data["Err_Auth"] = true
ctx.RenderWithErr(ctx.Tr("form.auth_failed", strings.Replace(err.Error(), ":"+form.AuthPassword+"@", ":<password>@", 1)), MIGRATE, &form)
return
}
handleCreateError(ctx, err, "MigratePost", MIGRATE, &form)
}
示例5: CompareAndPullRequest
func CompareAndPullRequest(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("repo.pulls.compare_changes")
ctx.Data["PageIsComparePull"] = true
repo := ctx.Repo.Repository
// Get compare branch information.
infos := strings.Split(ctx.Params("*"), "...")
if len(infos) != 2 {
ctx.Handle(404, "CompareAndPullRequest", nil)
return
}
baseBranch := infos[0]
ctx.Data["BaseBranch"] = baseBranch
headInfos := strings.Split(infos[1], ":")
if len(headInfos) != 2 {
ctx.Handle(404, "CompareAndPullRequest", nil)
return
}
headUser := headInfos[0]
headBranch := headInfos[1]
ctx.Data["HeadBranch"] = headBranch
// TODO: check if branches are valid.
fmt.Println(baseBranch, headUser, headBranch)
// TODO: add organization support
// Check if current user has fork of repository.
headRepo, has := models.HasForkedRepo(ctx.User.Id, repo.ID)
if !has {
ctx.Handle(404, "HasForkedRepo", nil)
return
}
headGitRepo, err := git.OpenRepository(models.RepoPath(ctx.User.Name, headRepo.Name))
if err != nil {
ctx.Handle(500, "OpenRepository", err)
return
}
headBranches, err := headGitRepo.GetBranches()
if err != nil {
ctx.Handle(500, "GetBranches", err)
return
}
ctx.Data["HeadBranches"] = headBranches
// Setup information for new form.
RetrieveRepoMetas(ctx, ctx.Repo.Repository)
if ctx.Written() {
return
}
// Get diff information.
ctx.HTML(200, COMPARE_PULL)
}
示例6: Fork
func Fork(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("new_fork")
getForkRepository(ctx)
if ctx.Written() {
return
}
ctx.Data["ContextUser"] = ctx.User
ctx.HTML(200, FORK)
}
示例7: Migrate
func Migrate(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("new_migrate")
ctx.Data["private"] = ctx.User.LastRepoVisibility
ctxUser := checkContextUser(ctx, ctx.QueryInt64("org"))
if ctx.Written() {
return
}
ctx.Data["ContextUser"] = ctxUser
ctx.HTML(200, MIGRATE)
}
示例8: ForkPost
func ForkPost(ctx *middleware.Context, form auth.CreateRepoForm) {
ctx.Data["Title"] = ctx.Tr("new_fork")
forkRepo := getForkRepository(ctx)
if ctx.Written() {
return
}
ctxUser := checkContextUser(ctx, form.Uid)
if ctx.Written() {
return
}
ctx.Data["ContextUser"] = ctxUser
if ctx.HasError() {
ctx.HTML(200, FORK)
return
}
repo, has := models.HasForkedRepo(ctxUser.Id, forkRepo.ID)
if has {
ctx.Redirect(setting.AppSubUrl + "/" + ctxUser.Name + "/" + repo.Name)
return
}
// Check ownership of organization.
if ctxUser.IsOrganization() {
if !ctxUser.IsOwnedBy(ctx.User.Id) {
ctx.Error(403)
return
}
}
repo, err := models.ForkRepository(ctxUser, forkRepo, form.RepoName, form.Description)
if err != nil {
ctx.Data["Err_RepoName"] = true
switch {
case models.IsErrRepoAlreadyExist(err):
ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), FORK, &form)
case models.IsErrNameReserved(err):
ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(models.ErrNameReserved).Name), FORK, &form)
case models.IsErrNamePatternNotAllowed(err):
ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), FORK, &form)
default:
ctx.Handle(500, "ForkPost", err)
}
return
}
log.Trace("Repository forked[%d]: %s/%s", forkRepo.ID, ctxUser.Name, repo.Name)
ctx.Redirect(setting.AppSubUrl + "/" + ctxUser.Name + "/" + repo.Name)
}
示例9: WebHooksEdit
func WebHooksEdit(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings.update_webhook")
ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksEdit"] = true
orCtx, w := checkWebhook(ctx)
if ctx.Written() {
return
}
ctx.Data["Webhook"] = w
ctx.HTML(200, orCtx.NewTemplate)
}
示例10: NewIssue
func NewIssue(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("repo.issues.new")
ctx.Data["PageIsIssueList"] = true
ctx.Data["RequireDropzone"] = true
renderAttachmentSettings(ctx)
RetrieveRepoMetas(ctx, ctx.Repo.Repository)
if ctx.Written() {
return
}
ctx.HTML(200, ISSUE_NEW)
}
示例11: Create
func Create(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("new_repo")
// Give default value for template to render.
ctx.Data["Gitignores"] = models.Gitignores
ctx.Data["Licenses"] = models.Licenses
ctx.Data["Readmes"] = models.Readmes
ctx.Data["readme"] = "Default"
ctx.Data["private"] = ctx.User.LastRepoVisibility
ctxUser := checkContextUser(ctx, ctx.QueryInt64("org"))
if ctx.Written() {
return
}
ctx.Data["ContextUser"] = ctxUser
ctx.HTML(200, CREATE)
}
示例12: SlackHooksEditPost
func SlackHooksEditPost(ctx *middleware.Context, form auth.NewSlackHookForm) {
ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksEdit"] = true
orCtx, w := checkWebhook(ctx)
if ctx.Written() {
return
}
ctx.Data["Webhook"] = w
if ctx.HasError() {
ctx.HTML(200, orCtx.NewTemplate)
return
}
meta, err := json.Marshal(&models.SlackMeta{
Channel: form.Channel,
Username: form.Username,
IconURL: form.IconURL,
Color: form.Color,
})
if err != nil {
ctx.Handle(500, "Marshal", err)
return
}
w.URL = form.PayloadURL
w.Meta = string(meta)
w.HookEvent = ParseHookEvent(form.WebhookForm)
w.IsActive = form.Active
if err := w.UpdateEvent(); err != nil {
ctx.Handle(500, "UpdateEvent", err)
return
} else if err := models.UpdateWebhook(w); err != nil {
ctx.Handle(500, "UpdateWebhook", err)
return
}
ctx.Flash.Success(ctx.Tr("repo.settings.update_hook_success"))
ctx.Redirect(fmt.Sprintf("%s/settings/hooks/%d", orCtx.Link, w.ID))
}
示例13: WebhooksNew
func WebhooksNew(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings.add_webhook")
ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksNew"] = true
ctx.Data["Webhook"] = models.Webhook{HookEvent: &models.HookEvent{}}
orCtx, err := getOrgRepoCtx(ctx)
if err != nil {
ctx.Handle(500, "getOrgRepoCtx", err)
return
}
ctx.Data["HookType"] = checkHookType(ctx)
if ctx.Written() {
return
}
ctx.Data["BaseLink"] = orCtx.Link
ctx.HTML(200, orCtx.NewTemplate)
}
示例14: CreatePost
func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) {
ctx.Data["Title"] = ctx.Tr("new_repo")
ctx.Data["Gitignores"] = models.Gitignores
ctx.Data["Licenses"] = models.Licenses
ctx.Data["Readmes"] = models.Readmes
ctxUser := checkContextUser(ctx, form.Uid)
if ctx.Written() {
return
}
ctx.Data["ContextUser"] = ctxUser
if ctx.HasError() {
ctx.HTML(200, CREATE)
return
}
repo, err := models.CreateRepository(ctxUser, models.CreateRepoOptions{
Name: form.RepoName,
Description: form.Description,
Gitignores: form.Gitignores,
License: form.License,
Readme: form.Readme,
IsPrivate: form.Private,
AutoInit: form.AutoInit,
})
if err == nil {
log.Trace("Repository created: %s/%s", ctxUser.Name, repo.Name)
ctx.Redirect(setting.AppSubUrl + "/" + ctxUser.Name + "/" + repo.Name)
return
}
if repo != nil {
if errDelete := models.DeleteRepository(ctxUser.Id, repo.ID); errDelete != nil {
log.Error(4, "DeleteRepository: %v", errDelete)
}
}
handleCreateError(ctx, err, "CreatePost", CREATE, &form)
}
示例15: UpdateIssueContent
func UpdateIssueContent(ctx *middleware.Context) {
issue := getActionIssue(ctx)
if ctx.Written() {
return
}
if !ctx.IsSigned || (ctx.User.Id != issue.PosterID && !ctx.Repo.IsAdmin()) {
ctx.Error(403)
return
}
issue.Content = ctx.Query("content")
if err := models.UpdateIssue(issue); err != nil {
ctx.Handle(500, "UpdateIssue", err)
return
}
ctx.JSON(200, map[string]interface{}{
"content": string(base.RenderMarkdown([]byte(issue.Content), ctx.Query("context"))),
})
}