mirror of https://github.com/gogits/gogs.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
409 lines
12 KiB
409 lines
12 KiB
11 years ago
|
// Copyright 2014 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.
|
||
|
|
||
8 years ago
|
package form
|
||
11 years ago
|
|
||
|
import (
|
||
9 years ago
|
"net/url"
|
||
|
"strings"
|
||
|
|
||
|
"github.com/Unknwon/com"
|
||
9 years ago
|
"github.com/go-macaron/binding"
|
||
|
"gopkg.in/macaron.v1"
|
||
9 years ago
|
|
||
|
"github.com/gogits/gogs/models"
|
||
11 years ago
|
)
|
||
|
|
||
|
// _______________________________________ _________.______________________ _______________.___.
|
||
|
// \______ \_ _____/\______ \_____ \ / _____/| \__ ___/\_____ \\______ \__ | |
|
||
|
// | _/| __)_ | ___// | \ \_____ \ | | | | / | \| _// | |
|
||
|
// | | \| \ | | / | \/ \| | | | / | \ | \\____ |
|
||
|
// |____|_ /_______ / |____| \_______ /_______ /|___| |____| \_______ /____|_ // ______|
|
||
|
// \/ \/ \/ \/ \/ \/ \/
|
||
|
|
||
8 years ago
|
type CreateRepo struct {
|
||
8 years ago
|
UserID int64 `binding:"Required"`
|
||
9 years ago
|
RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"`
|
||
|
Private bool
|
||
|
Description string `binding:"MaxSize(255)"`
|
||
9 years ago
|
AutoInit bool
|
||
|
Gitignores string
|
||
|
License string
|
||
|
Readme string
|
||
11 years ago
|
}
|
||
|
|
||
8 years ago
|
func (f *CreateRepo) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
|
||
10 years ago
|
return validate(errs, ctx.Data, f, ctx.Locale)
|
||
11 years ago
|
}
|
||
|
|
||
8 years ago
|
type MigrateRepo struct {
|
||
9 years ago
|
CloneAddr string `json:"clone_addr" binding:"Required"`
|
||
|
AuthUsername string `json:"auth_username"`
|
||
|
AuthPassword string `json:"auth_password"`
|
||
|
Uid int64 `json:"uid" binding:"Required"`
|
||
|
RepoName string `json:"repo_name" binding:"Required;AlphaDashDot;MaxSize(100)"`
|
||
9 years ago
|
Mirror bool `json:"mirror"`
|
||
|
Private bool `json:"private"`
|
||
9 years ago
|
Description string `json:"description" binding:"MaxSize(255)"`
|
||
11 years ago
|
}
|
||
|
|
||
8 years ago
|
func (f *MigrateRepo) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
|
||
10 years ago
|
return validate(errs, ctx.Data, f, ctx.Locale)
|
||
11 years ago
|
}
|
||
|
|
||
9 years ago
|
// ParseRemoteAddr checks if given remote address is valid,
|
||
8 years ago
|
// and returns composed URL with needed username and password.
|
||
9 years ago
|
// It also checks if given user has permission when remote address
|
||
|
// is actually a local path.
|
||
8 years ago
|
func (f MigrateRepo) ParseRemoteAddr(user *models.User) (string, error) {
|
||
9 years ago
|
remoteAddr := strings.TrimSpace(f.CloneAddr)
|
||
9 years ago
|
|
||
|
// Remote address can be HTTP/HTTPS/Git URL or local path.
|
||
|
if strings.HasPrefix(remoteAddr, "http://") ||
|
||
|
strings.HasPrefix(remoteAddr, "https://") ||
|
||
|
strings.HasPrefix(remoteAddr, "git://") {
|
||
|
u, err := url.Parse(remoteAddr)
|
||
|
if err != nil {
|
||
|
return "", models.ErrInvalidCloneAddr{IsURLError: true}
|
||
|
}
|
||
|
if len(f.AuthUsername)+len(f.AuthPassword) > 0 {
|
||
|
u.User = url.UserPassword(f.AuthUsername, f.AuthPassword)
|
||
|
}
|
||
|
remoteAddr = u.String()
|
||
|
} else if !user.CanImportLocal() {
|
||
|
return "", models.ErrInvalidCloneAddr{IsPermissionDenied: true}
|
||
|
} else if !com.IsDir(remoteAddr) {
|
||
|
return "", models.ErrInvalidCloneAddr{IsInvalidPath: true}
|
||
|
}
|
||
|
|
||
|
return remoteAddr, nil
|
||
|
}
|
||
|
|
||
8 years ago
|
type RepoSetting struct {
|
||
9 years ago
|
RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"`
|
||
|
Description string `binding:"MaxSize(255)"`
|
||
|
Website string `binding:"Url;MaxSize(100)"`
|
||
|
Branch string
|
||
|
Interval int
|
||
|
MirrorAddress string
|
||
|
Private bool
|
||
9 years ago
|
EnablePrune bool
|
||
9 years ago
|
|
||
|
// Advanced settings
|
||
|
EnableWiki bool
|
||
8 years ago
|
AllowPublicWiki bool
|
||
9 years ago
|
EnableExternalWiki bool
|
||
|
ExternalWikiURL string
|
||
9 years ago
|
EnableIssues bool
|
||
8 years ago
|
AllowPublicIssues bool
|
||
9 years ago
|
EnableExternalTracker bool
|
||
8 years ago
|
ExternalTrackerURL string
|
||
9 years ago
|
TrackerURLFormat string
|
||
9 years ago
|
TrackerIssueStyle string
|
||
9 years ago
|
EnablePulls bool
|
||
11 years ago
|
}
|
||
|
|
||
8 years ago
|
func (f *RepoSetting) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
|
||
10 years ago
|
return validate(errs, ctx.Data, f, ctx.Locale)
|
||
11 years ago
|
}
|
||
|
|
||
8 years ago
|
// __________ .__
|
||
|
// \______ \____________ ____ ____ | |__
|
||
|
// | | _/\_ __ \__ \ / \_/ ___\| | \
|
||
|
// | | \ | | \// __ \| | \ \___| Y \
|
||
|
// |______ / |__| (____ /___| /\___ >___| /
|
||
|
// \/ \/ \/ \/ \/
|
||
|
|
||
8 years ago
|
type ProtectBranch struct {
|
||
8 years ago
|
Protected bool
|
||
|
RequirePullRequest bool
|
||
8 years ago
|
EnableWhitelist bool
|
||
|
WhitelistUsers string
|
||
|
WhitelistTeams string
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
func (f *ProtectBranch) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
|
||
8 years ago
|
return validate(errs, ctx.Data, f, ctx.Locale)
|
||
|
}
|
||
|
|
||
11 years ago
|
// __ __ ___. .__ .__ __
|
||
|
// / \ / \ ____\_ |__ | |__ | |__ ____ | | __
|
||
|
// \ \/\/ // __ \| __ \| | \| | \ / _ \| |/ /
|
||
|
// \ /\ ___/| \_\ \ Y \ Y ( <_> ) <
|
||
|
// \__/\ / \___ >___ /___| /___| /\____/|__|_ \
|
||
|
// \/ \/ \/ \/ \/ \/
|
||
|
|
||
8 years ago
|
type Webhook struct {
|
||
8 years ago
|
Events string
|
||
|
Create bool
|
||
|
Delete bool
|
||
|
Fork bool
|
||
|
Push bool
|
||
|
Issues bool
|
||
|
IssueComment bool
|
||
|
PullRequest bool
|
||
8 years ago
|
Release bool
|
||
8 years ago
|
Active bool
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
func (f Webhook) PushOnly() bool {
|
||
9 years ago
|
return f.Events == "push_only"
|
||
|
}
|
||
|
|
||
8 years ago
|
func (f Webhook) SendEverything() bool {
|
||
9 years ago
|
return f.Events == "send_everything"
|
||
|
}
|
||
|
|
||
8 years ago
|
func (f Webhook) ChooseEvents() bool {
|
||
9 years ago
|
return f.Events == "choose_events"
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
type NewWebhook struct {
|
||
9 years ago
|
PayloadURL string `binding:"Required;Url"`
|
||
|
ContentType int `binding:"Required"`
|
||
|
Secret string
|
||
8 years ago
|
Webhook
|
||
11 years ago
|
}
|
||
|
|
||
8 years ago
|
func (f *NewWebhook) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
|
||
10 years ago
|
return validate(errs, ctx.Data, f, ctx.Locale)
|
||
11 years ago
|
}
|
||
|
|
||
8 years ago
|
type NewSlackHook struct {
|
||
9 years ago
|
PayloadURL string `binding:"Required;Url"`
|
||
9 years ago
|
Channel string `binding:"Required"`
|
||
9 years ago
|
Username string
|
||
|
IconURL string
|
||
|
Color string
|
||
8 years ago
|
Webhook
|
||
10 years ago
|
}
|
||
|
|
||
8 years ago
|
func (f *NewSlackHook) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
|
||
10 years ago
|
return validate(errs, ctx.Data, f, ctx.Locale)
|
||
10 years ago
|
}
|
||
|
|
||
8 years ago
|
type NewDiscordHook struct {
|
||
8 years ago
|
PayloadURL string `binding:"Required;Url"`
|
||
|
Username string
|
||
|
IconURL string
|
||
8 years ago
|
Color string
|
||
8 years ago
|
Webhook
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
func (f *NewDiscordHook) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
|
||
8 years ago
|
return validate(errs, ctx.Data, f, ctx.Locale)
|
||
|
}
|
||
|
|
||
11 years ago
|
// .___
|
||
|
// | | ______ ________ __ ____
|
||
|
// | |/ ___// ___/ | \_/ __ \
|
||
|
// | |\___ \ \___ \| | /\ ___/
|
||
|
// |___/____ >____ >____/ \___ >
|
||
|
// \/ \/ \/
|
||
|
|
||
8 years ago
|
type NewIssue struct {
|
||
10 years ago
|
Title string `binding:"Required;MaxSize(255)"`
|
||
|
LabelIDs string `form:"label_ids"`
|
||
10 years ago
|
MilestoneID int64
|
||
|
AssigneeID int64
|
||
|
Content string
|
||
8 years ago
|
Files []string
|
||
11 years ago
|
}
|
||
|
|
||
8 years ago
|
func (f *NewIssue) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
|
||
10 years ago
|
return validate(errs, ctx.Data, f, ctx.Locale)
|
||
11 years ago
|
}
|
||
|
|
||
8 years ago
|
type CreateComment struct {
|
||
8 years ago
|
Content string
|
||
|
Status string `binding:"OmitEmpty;In(reopen,close)"`
|
||
|
Files []string
|
||
10 years ago
|
}
|
||
|
|
||
8 years ago
|
func (f *CreateComment) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
|
||
10 years ago
|
return validate(errs, ctx.Data, f, ctx.Locale)
|
||
|
}
|
||
|
|
||
11 years ago
|
// _____ .__.__ __
|
||
|
// / \ |__| | ____ _______/ |_ ____ ____ ____
|
||
|
// / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \
|
||
|
// / Y \ | |_\ ___/ \___ \ | | ( <_> ) | \ ___/
|
||
|
// \____|__ /__|____/\___ >____ > |__| \____/|___| /\___ >
|
||
|
// \/ \/ \/ \/ \/
|
||
|
|
||
8 years ago
|
type CreateMilestone struct {
|
||
10 years ago
|
Title string `binding:"Required;MaxSize(50)"`
|
||
|
Content string
|
||
|
Deadline string
|
||
11 years ago
|
}
|
||
|
|
||
8 years ago
|
func (f *CreateMilestone) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
|
||
10 years ago
|
return validate(errs, ctx.Data, f, ctx.Locale)
|
||
11 years ago
|
}
|
||
|
|
||
|
// .____ ___. .__
|
||
|
// | | _____ \_ |__ ____ | |
|
||
|
// | | \__ \ | __ \_/ __ \| |
|
||
|
// | |___ / __ \| \_\ \ ___/| |__
|
||
|
// |_______ (____ /___ /\___ >____/
|
||
|
// \/ \/ \/ \/
|
||
|
|
||
8 years ago
|
type CreateLabel struct {
|
||
10 years ago
|
ID int64
|
||
10 years ago
|
Title string `binding:"Required;MaxSize(50)" locale:"repo.issues.label_name"`
|
||
|
Color string `binding:"Required;Size(7)" locale:"repo.issues.label_color"`
|
||
11 years ago
|
}
|
||
|
|
||
8 years ago
|
func (f *CreateLabel) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
|
||
10 years ago
|
return validate(errs, ctx.Data, f, ctx.Locale)
|
||
11 years ago
|
}
|
||
|
|
||
8 years ago
|
type InitializeLabels struct {
|
||
8 years ago
|
TemplateName string `binding:"Required"`
|
||
|
}
|
||
|
|
||
8 years ago
|
func (f *InitializeLabels) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
|
||
8 years ago
|
return validate(errs, ctx.Data, f, ctx.Locale)
|
||
|
}
|
||
|
|
||
11 years ago
|
// __________ .__
|
||
|
// \______ \ ____ | | ____ _____ ______ ____
|
||
|
// | _// __ \| | _/ __ \\__ \ / ___// __ \
|
||
|
// | | \ ___/| |_\ ___/ / __ \_\___ \\ ___/
|
||
|
// |____|_ /\___ >____/\___ >____ /____ >\___ >
|
||
|
// \/ \/ \/ \/ \/ \/
|
||
|
|
||
8 years ago
|
type NewRelease struct {
|
||
9 years ago
|
TagName string `binding:"Required"`
|
||
11 years ago
|
Target string `form:"tag_target" binding:"Required"`
|
||
9 years ago
|
Title string `binding:"Required"`
|
||
|
Content string
|
||
|
Draft string
|
||
|
Prerelease bool
|
||
8 years ago
|
Files []string
|
||
11 years ago
|
}
|
||
|
|
||
8 years ago
|
func (f *NewRelease) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
|
||
10 years ago
|
return validate(errs, ctx.Data, f, ctx.Locale)
|
||
11 years ago
|
}
|
||
|
|
||
8 years ago
|
type EditRelease struct {
|
||
|
Title string `binding:"Required"`
|
||
|
Content string
|
||
|
Draft string
|
||
|
Prerelease bool
|
||
8 years ago
|
Files []string
|
||
11 years ago
|
}
|
||
|
|
||
8 years ago
|
func (f *EditRelease) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
|
||
10 years ago
|
return validate(errs, ctx.Data, f, ctx.Locale)
|
||
11 years ago
|
}
|
||
9 years ago
|
|
||
|
// __ __.__ __ .__
|
||
|
// / \ / \__| | _|__|
|
||
|
// \ \/\/ / | |/ / |
|
||
|
// \ /| | <| |
|
||
|
// \__/\ / |__|__|_ \__|
|
||
|
// \/ \/
|
||
|
|
||
8 years ago
|
type NewWiki struct {
|
||
9 years ago
|
OldTitle string
|
||
|
Title string `binding:"Required"`
|
||
|
Content string `binding:"Required"`
|
||
|
Message string
|
||
9 years ago
|
}
|
||
|
|
||
|
// FIXME: use code generation to generate this method.
|
||
8 years ago
|
func (f *NewWiki) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
|
||
9 years ago
|
return validate(errs, ctx.Data, f, ctx.Locale)
|
||
|
}
|
||
8 years ago
|
|
||
|
// ___________ .___.__ __
|
||
|
// \_ _____/ __| _/|__|/ |_
|
||
|
// | __)_ / __ | | \ __\
|
||
|
// | \/ /_/ | | || |
|
||
|
// /_______ /\____ | |__||__|
|
||
|
// \/ \/
|
||
|
|
||
8 years ago
|
type EditRepoFile struct {
|
||
8 years ago
|
TreePath string `binding:"Required;MaxSize(500)"`
|
||
8 years ago
|
Content string `binding:"Required"`
|
||
|
CommitSummary string `binding:"MaxSize(100)`
|
||
|
CommitMessage string
|
||
|
CommitChoice string `binding:"Required;MaxSize(50)"`
|
||
8 years ago
|
NewBranchName string `binding:"AlphaDashDotSlash;MaxSize(100)"`
|
||
8 years ago
|
LastCommit string
|
||
|
}
|
||
|
|
||
8 years ago
|
func (f *EditRepoFile) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
|
||
8 years ago
|
return validate(errs, ctx.Data, f, ctx.Locale)
|
||
|
}
|
||
|
|
||
8 years ago
|
func (f *EditRepoFile) IsNewBrnach() bool {
|
||
8 years ago
|
return f.CommitChoice == "commit-to-new-branch"
|
||
|
}
|
||
|
|
||
8 years ago
|
type EditPreviewDiff struct {
|
||
8 years ago
|
Content string
|
||
|
}
|
||
|
|
||
8 years ago
|
func (f *EditPreviewDiff) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
|
||
8 years ago
|
return validate(errs, ctx.Data, f, ctx.Locale)
|
||
|
}
|
||
|
|
||
|
// ____ ___ .__ .___
|
||
|
// | | \______ | | _________ __| _/
|
||
|
// | | /\____ \| | / _ \__ \ / __ |
|
||
|
// | | / | |_> > |_( <_> ) __ \_/ /_/ |
|
||
|
// |______/ | __/|____/\____(____ /\____ |
|
||
|
// |__| \/ \/
|
||
|
//
|
||
|
|
||
8 years ago
|
type UploadRepoFile struct {
|
||
8 years ago
|
TreePath string `binding:MaxSize(500)"`
|
||
8 years ago
|
CommitSummary string `binding:"MaxSize(100)`
|
||
|
CommitMessage string
|
||
|
CommitChoice string `binding:"Required;MaxSize(50)"`
|
||
|
NewBranchName string `binding:"AlphaDashDot;MaxSize(100)"`
|
||
|
Files []string
|
||
|
}
|
||
|
|
||
8 years ago
|
func (f *UploadRepoFile) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
|
||
8 years ago
|
return validate(errs, ctx.Data, f, ctx.Locale)
|
||
|
}
|
||
|
|
||
8 years ago
|
func (f *UploadRepoFile) IsNewBrnach() bool {
|
||
8 years ago
|
return f.CommitChoice == "commit-to-new-branch"
|
||
|
}
|
||
|
|
||
8 years ago
|
type RemoveUploadFile struct {
|
||
8 years ago
|
File string `binding:"Required;MaxSize(50)"`
|
||
|
}
|
||
|
|
||
8 years ago
|
func (f *RemoveUploadFile) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
|
||
8 years ago
|
return validate(errs, ctx.Data, f, ctx.Locale)
|
||
|
}
|
||
|
|
||
|
// ________ .__ __
|
||
|
// \______ \ ____ | | _____/ |_ ____
|
||
|
// | | \_/ __ \| | _/ __ \ __\/ __ \
|
||
|
// | ` \ ___/| |_\ ___/| | \ ___/
|
||
|
// /_______ /\___ >____/\___ >__| \___ >
|
||
|
// \/ \/ \/ \/
|
||
|
|
||
8 years ago
|
type DeleteRepoFile struct {
|
||
8 years ago
|
CommitSummary string `binding:"MaxSize(100)`
|
||
8 years ago
|
CommitMessage string
|
||
|
CommitChoice string `binding:"Required;MaxSize(50)"`
|
||
|
NewBranchName string `binding:"AlphaDashDot;MaxSize(100)"`
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
func (f *DeleteRepoFile) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
|
||
8 years ago
|
return validate(errs, ctx.Data, f, ctx.Locale)
|
||
|
}
|
||
8 years ago
|
|
||
8 years ago
|
func (f *DeleteRepoFile) IsNewBrnach() bool {
|
||
8 years ago
|
return f.CommitChoice == "commit-to-new-branch"
|
||
|
}
|