code.gitea.io/gitea@v1.22.3/services/forms/repo_form.go (about)

     1  // Copyright 2014 The Gogs Authors. All rights reserved.
     2  // Copyright 2017 The Gitea Authors. All rights reserved.
     3  // SPDX-License-Identifier: MIT
     4  
     5  package forms
     6  
     7  import (
     8  	"net/http"
     9  	"net/url"
    10  	"strings"
    11  
    12  	"code.gitea.io/gitea/models"
    13  	issues_model "code.gitea.io/gitea/models/issues"
    14  	project_model "code.gitea.io/gitea/models/project"
    15  	"code.gitea.io/gitea/modules/setting"
    16  	"code.gitea.io/gitea/modules/structs"
    17  	"code.gitea.io/gitea/modules/web/middleware"
    18  	"code.gitea.io/gitea/services/context"
    19  	"code.gitea.io/gitea/services/webhook"
    20  
    21  	"gitea.com/go-chi/binding"
    22  )
    23  
    24  // CreateRepoForm form for creating repository
    25  type CreateRepoForm struct {
    26  	UID           int64  `binding:"Required"`
    27  	RepoName      string `binding:"Required;AlphaDashDot;MaxSize(100)"`
    28  	Private       bool
    29  	Description   string `binding:"MaxSize(2048)"`
    30  	DefaultBranch string `binding:"GitRefName;MaxSize(100)"`
    31  	AutoInit      bool
    32  	Gitignores    string
    33  	IssueLabels   string
    34  	License       string
    35  	Readme        string
    36  	Template      bool
    37  
    38  	RepoTemplate    int64
    39  	GitContent      bool
    40  	Topics          bool
    41  	GitHooks        bool
    42  	Webhooks        bool
    43  	Avatar          bool
    44  	Labels          bool
    45  	ProtectedBranch bool
    46  
    47  	ForkSingleBranch string
    48  	ObjectFormatName string
    49  }
    50  
    51  // Validate validates the fields
    52  func (f *CreateRepoForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
    53  	ctx := context.GetValidateContext(req)
    54  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
    55  }
    56  
    57  // MigrateRepoForm form for migrating repository
    58  // this is used to interact with web ui
    59  type MigrateRepoForm struct {
    60  	// required: true
    61  	CloneAddr    string                 `json:"clone_addr" binding:"Required"`
    62  	Service      structs.GitServiceType `json:"service"`
    63  	AuthUsername string                 `json:"auth_username"`
    64  	AuthPassword string                 `json:"auth_password"`
    65  	AuthToken    string                 `json:"auth_token"`
    66  	// required: true
    67  	UID int64 `json:"uid" binding:"Required"`
    68  	// required: true
    69  	RepoName       string `json:"repo_name" binding:"Required;AlphaDashDot;MaxSize(100)"`
    70  	Mirror         bool   `json:"mirror"`
    71  	LFS            bool   `json:"lfs"`
    72  	LFSEndpoint    string `json:"lfs_endpoint"`
    73  	Private        bool   `json:"private"`
    74  	Description    string `json:"description" binding:"MaxSize(2048)"`
    75  	Wiki           bool   `json:"wiki"`
    76  	Milestones     bool   `json:"milestones"`
    77  	Labels         bool   `json:"labels"`
    78  	Issues         bool   `json:"issues"`
    79  	PullRequests   bool   `json:"pull_requests"`
    80  	Releases       bool   `json:"releases"`
    81  	MirrorInterval string `json:"mirror_interval"`
    82  }
    83  
    84  // Validate validates the fields
    85  func (f *MigrateRepoForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
    86  	ctx := context.GetValidateContext(req)
    87  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
    88  }
    89  
    90  // ParseRemoteAddr checks if given remote address is valid,
    91  // and returns composed URL with needed username and password.
    92  func ParseRemoteAddr(remoteAddr, authUsername, authPassword string) (string, error) {
    93  	remoteAddr = strings.TrimSpace(remoteAddr)
    94  	// Remote address can be HTTP/HTTPS/Git URL or local path.
    95  	if strings.HasPrefix(remoteAddr, "http://") ||
    96  		strings.HasPrefix(remoteAddr, "https://") ||
    97  		strings.HasPrefix(remoteAddr, "git://") {
    98  		u, err := url.Parse(remoteAddr)
    99  		if err != nil {
   100  			return "", &models.ErrInvalidCloneAddr{IsURLError: true, Host: remoteAddr}
   101  		}
   102  		if len(authUsername)+len(authPassword) > 0 {
   103  			u.User = url.UserPassword(authUsername, authPassword)
   104  		}
   105  		remoteAddr = u.String()
   106  	}
   107  
   108  	return remoteAddr, nil
   109  }
   110  
   111  // RepoSettingForm form for changing repository settings
   112  type RepoSettingForm struct {
   113  	RepoName               string `binding:"Required;AlphaDashDot;MaxSize(100)"`
   114  	Description            string `binding:"MaxSize(2048)"`
   115  	Website                string `binding:"ValidUrl;MaxSize(1024)"`
   116  	Interval               string
   117  	MirrorAddress          string
   118  	MirrorUsername         string
   119  	MirrorPassword         string
   120  	LFS                    bool   `form:"mirror_lfs"`
   121  	LFSEndpoint            string `form:"mirror_lfs_endpoint"`
   122  	PushMirrorID           string
   123  	PushMirrorAddress      string
   124  	PushMirrorUsername     string
   125  	PushMirrorPassword     string
   126  	PushMirrorSyncOnCommit bool
   127  	PushMirrorInterval     string
   128  	Private                bool
   129  	Template               bool
   130  	EnablePrune            bool
   131  
   132  	// Advanced settings
   133  	EnableCode                            bool
   134  	EnableWiki                            bool
   135  	EnableExternalWiki                    bool
   136  	DefaultWikiBranch                     string
   137  	DefaultWikiEveryoneAccess             string
   138  	ExternalWikiURL                       string
   139  	EnableIssues                          bool
   140  	EnableExternalTracker                 bool
   141  	ExternalTrackerURL                    string
   142  	TrackerURLFormat                      string
   143  	TrackerIssueStyle                     string
   144  	ExternalTrackerRegexpPattern          string
   145  	EnableCloseIssuesViaCommitInAnyBranch bool
   146  	EnableProjects                        bool
   147  	ProjectsMode                          string
   148  	EnableReleases                        bool
   149  	EnablePackages                        bool
   150  	EnablePulls                           bool
   151  	EnableActions                         bool
   152  	PullsIgnoreWhitespace                 bool
   153  	PullsAllowMerge                       bool
   154  	PullsAllowRebase                      bool
   155  	PullsAllowRebaseMerge                 bool
   156  	PullsAllowSquash                      bool
   157  	PullsAllowFastForwardOnly             bool
   158  	PullsAllowManualMerge                 bool
   159  	PullsDefaultMergeStyle                string
   160  	EnableAutodetectManualMerge           bool
   161  	PullsAllowRebaseUpdate                bool
   162  	DefaultDeleteBranchAfterMerge         bool
   163  	DefaultAllowMaintainerEdit            bool
   164  	EnableTimetracker                     bool
   165  	AllowOnlyContributorsToTrackTime      bool
   166  	EnableIssueDependencies               bool
   167  	IsArchived                            bool
   168  
   169  	// Signing Settings
   170  	TrustModel string
   171  
   172  	// Admin settings
   173  	EnableHealthCheck  bool
   174  	RequestReindexType string
   175  }
   176  
   177  // Validate validates the fields
   178  func (f *RepoSettingForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
   179  	ctx := context.GetValidateContext(req)
   180  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
   181  }
   182  
   183  // __________                             .__
   184  // \______   \____________    ____   ____ |  |__
   185  //  |    |  _/\_  __ \__  \  /    \_/ ___\|  |  \
   186  //  |    |   \ |  | \// __ \|   |  \  \___|   Y  \
   187  //  |______  / |__|  (____  /___|  /\___  >___|  /
   188  //         \/             \/     \/     \/     \/
   189  
   190  // ProtectBranchForm form for changing protected branch settings
   191  type ProtectBranchForm struct {
   192  	RuleName                      string `binding:"Required"`
   193  	RuleID                        int64
   194  	EnablePush                    string
   195  	WhitelistUsers                string
   196  	WhitelistTeams                string
   197  	WhitelistDeployKeys           bool
   198  	EnableMergeWhitelist          bool
   199  	MergeWhitelistUsers           string
   200  	MergeWhitelistTeams           string
   201  	EnableStatusCheck             bool
   202  	StatusCheckContexts           string
   203  	RequiredApprovals             int64
   204  	EnableApprovalsWhitelist      bool
   205  	ApprovalsWhitelistUsers       string
   206  	ApprovalsWhitelistTeams       string
   207  	BlockOnRejectedReviews        bool
   208  	BlockOnOfficialReviewRequests bool
   209  	BlockOnOutdatedBranch         bool
   210  	DismissStaleApprovals         bool
   211  	IgnoreStaleApprovals          bool
   212  	RequireSignedCommits          bool
   213  	ProtectedFilePatterns         string
   214  	UnprotectedFilePatterns       string
   215  }
   216  
   217  // Validate validates the fields
   218  func (f *ProtectBranchForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
   219  	ctx := context.GetValidateContext(req)
   220  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
   221  }
   222  
   223  //  __      __      ___.   .__                   __
   224  // /  \    /  \ ____\_ |__ |  |__   ____   ____ |  | __
   225  // \   \/\/   // __ \| __ \|  |  \ /  _ \ /  _ \|  |/ /
   226  //  \        /\  ___/| \_\ \   Y  (  <_> |  <_> )    <
   227  //   \__/\  /  \___  >___  /___|  /\____/ \____/|__|_ \
   228  //        \/       \/    \/     \/                   \/
   229  
   230  // WebhookForm form for changing web hook
   231  type WebhookForm struct {
   232  	Events                   string
   233  	Create                   bool
   234  	Delete                   bool
   235  	Fork                     bool
   236  	Issues                   bool
   237  	IssueAssign              bool
   238  	IssueLabel               bool
   239  	IssueMilestone           bool
   240  	IssueComment             bool
   241  	Release                  bool
   242  	Push                     bool
   243  	PullRequest              bool
   244  	PullRequestAssign        bool
   245  	PullRequestLabel         bool
   246  	PullRequestMilestone     bool
   247  	PullRequestComment       bool
   248  	PullRequestReview        bool
   249  	PullRequestSync          bool
   250  	PullRequestReviewRequest bool
   251  	Wiki                     bool
   252  	Repository               bool
   253  	Package                  bool
   254  	Active                   bool
   255  	BranchFilter             string `binding:"GlobPattern"`
   256  	AuthorizationHeader      string
   257  }
   258  
   259  // PushOnly if the hook will be triggered when push
   260  func (f WebhookForm) PushOnly() bool {
   261  	return f.Events == "push_only"
   262  }
   263  
   264  // SendEverything if the hook will be triggered any event
   265  func (f WebhookForm) SendEverything() bool {
   266  	return f.Events == "send_everything"
   267  }
   268  
   269  // ChooseEvents if the hook will be triggered choose events
   270  func (f WebhookForm) ChooseEvents() bool {
   271  	return f.Events == "choose_events"
   272  }
   273  
   274  // NewWebhookForm form for creating web hook
   275  type NewWebhookForm struct {
   276  	PayloadURL  string `binding:"Required;ValidUrl"`
   277  	HTTPMethod  string `binding:"Required;In(POST,GET)"`
   278  	ContentType int    `binding:"Required"`
   279  	Secret      string
   280  	WebhookForm
   281  }
   282  
   283  // Validate validates the fields
   284  func (f *NewWebhookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
   285  	ctx := context.GetValidateContext(req)
   286  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
   287  }
   288  
   289  // NewGogshookForm form for creating gogs hook
   290  type NewGogshookForm struct {
   291  	PayloadURL  string `binding:"Required;ValidUrl"`
   292  	ContentType int    `binding:"Required"`
   293  	Secret      string
   294  	WebhookForm
   295  }
   296  
   297  // Validate validates the fields
   298  func (f *NewGogshookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
   299  	ctx := context.GetValidateContext(req)
   300  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
   301  }
   302  
   303  // NewSlackHookForm form for creating slack hook
   304  type NewSlackHookForm struct {
   305  	PayloadURL string `binding:"Required;ValidUrl"`
   306  	Channel    string `binding:"Required"`
   307  	Username   string
   308  	IconURL    string
   309  	Color      string
   310  	WebhookForm
   311  }
   312  
   313  // Validate validates the fields
   314  func (f *NewSlackHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
   315  	ctx := context.GetValidateContext(req)
   316  	if !webhook.IsValidSlackChannel(strings.TrimSpace(f.Channel)) {
   317  		errs = append(errs, binding.Error{
   318  			FieldNames:     []string{"Channel"},
   319  			Classification: "",
   320  			Message:        ctx.Locale.TrString("repo.settings.add_webhook.invalid_channel_name"),
   321  		})
   322  	}
   323  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
   324  }
   325  
   326  // NewDiscordHookForm form for creating discord hook
   327  type NewDiscordHookForm struct {
   328  	PayloadURL string `binding:"Required;ValidUrl"`
   329  	Username   string
   330  	IconURL    string
   331  	WebhookForm
   332  }
   333  
   334  // Validate validates the fields
   335  func (f *NewDiscordHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
   336  	ctx := context.GetValidateContext(req)
   337  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
   338  }
   339  
   340  // NewDingtalkHookForm form for creating dingtalk hook
   341  type NewDingtalkHookForm struct {
   342  	PayloadURL string `binding:"Required;ValidUrl"`
   343  	WebhookForm
   344  }
   345  
   346  // Validate validates the fields
   347  func (f *NewDingtalkHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
   348  	ctx := context.GetValidateContext(req)
   349  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
   350  }
   351  
   352  // NewTelegramHookForm form for creating telegram hook
   353  type NewTelegramHookForm struct {
   354  	BotToken string `binding:"Required"`
   355  	ChatID   string `binding:"Required"`
   356  	ThreadID string
   357  	WebhookForm
   358  }
   359  
   360  // Validate validates the fields
   361  func (f *NewTelegramHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
   362  	ctx := context.GetValidateContext(req)
   363  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
   364  }
   365  
   366  // NewMatrixHookForm form for creating Matrix hook
   367  type NewMatrixHookForm struct {
   368  	HomeserverURL string `binding:"Required;ValidUrl"`
   369  	RoomID        string `binding:"Required"`
   370  	MessageType   int
   371  	WebhookForm
   372  }
   373  
   374  // Validate validates the fields
   375  func (f *NewMatrixHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
   376  	ctx := context.GetValidateContext(req)
   377  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
   378  }
   379  
   380  // NewMSTeamsHookForm form for creating MS Teams hook
   381  type NewMSTeamsHookForm struct {
   382  	PayloadURL string `binding:"Required;ValidUrl"`
   383  	WebhookForm
   384  }
   385  
   386  // Validate validates the fields
   387  func (f *NewMSTeamsHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
   388  	ctx := context.GetValidateContext(req)
   389  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
   390  }
   391  
   392  // NewFeishuHookForm form for creating feishu hook
   393  type NewFeishuHookForm struct {
   394  	PayloadURL string `binding:"Required;ValidUrl"`
   395  	WebhookForm
   396  }
   397  
   398  // Validate validates the fields
   399  func (f *NewFeishuHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
   400  	ctx := context.GetValidateContext(req)
   401  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
   402  }
   403  
   404  // NewWechatWorkHookForm form for creating wechatwork hook
   405  type NewWechatWorkHookForm struct {
   406  	PayloadURL string `binding:"Required;ValidUrl"`
   407  	WebhookForm
   408  }
   409  
   410  // Validate validates the fields
   411  func (f *NewWechatWorkHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
   412  	ctx := context.GetValidateContext(req)
   413  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
   414  }
   415  
   416  // NewPackagistHookForm form for creating packagist hook
   417  type NewPackagistHookForm struct {
   418  	Username   string `binding:"Required"`
   419  	APIToken   string `binding:"Required"`
   420  	PackageURL string `binding:"Required;ValidUrl"`
   421  	WebhookForm
   422  }
   423  
   424  // Validate validates the fields
   425  func (f *NewPackagistHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
   426  	ctx := context.GetValidateContext(req)
   427  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
   428  }
   429  
   430  // .___
   431  // |   | ______ ________ __   ____
   432  // |   |/  ___//  ___/  |  \_/ __ \
   433  // |   |\___ \ \___ \|  |  /\  ___/
   434  // |___/____  >____  >____/  \___  >
   435  //          \/     \/            \/
   436  
   437  // CreateIssueForm form for creating issue
   438  type CreateIssueForm struct {
   439  	Title               string `binding:"Required;MaxSize(255)"`
   440  	LabelIDs            string `form:"label_ids"`
   441  	AssigneeIDs         string `form:"assignee_ids"`
   442  	Ref                 string `form:"ref"`
   443  	MilestoneID         int64
   444  	ProjectID           int64
   445  	AssigneeID          int64
   446  	Content             string
   447  	Files               []string
   448  	AllowMaintainerEdit bool
   449  }
   450  
   451  // Validate validates the fields
   452  func (f *CreateIssueForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
   453  	ctx := context.GetValidateContext(req)
   454  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
   455  }
   456  
   457  // CreateCommentForm form for creating comment
   458  type CreateCommentForm struct {
   459  	Content string
   460  	Status  string `binding:"OmitEmpty;In(reopen,close)"`
   461  	Files   []string
   462  }
   463  
   464  // Validate validates the fields
   465  func (f *CreateCommentForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
   466  	ctx := context.GetValidateContext(req)
   467  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
   468  }
   469  
   470  // ReactionForm form for adding and removing reaction
   471  type ReactionForm struct {
   472  	Content string `binding:"Required"`
   473  }
   474  
   475  // Validate validates the fields
   476  func (f *ReactionForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
   477  	ctx := context.GetValidateContext(req)
   478  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
   479  }
   480  
   481  // IssueLockForm form for locking an issue
   482  type IssueLockForm struct {
   483  	Reason string `binding:"Required"`
   484  }
   485  
   486  // Validate validates the fields
   487  func (i *IssueLockForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
   488  	ctx := context.GetValidateContext(req)
   489  	return middleware.Validate(errs, ctx.Data, i, ctx.Locale)
   490  }
   491  
   492  // HasValidReason checks to make sure that the reason submitted in
   493  // the form matches any of the values in the config
   494  func (i IssueLockForm) HasValidReason() bool {
   495  	if strings.TrimSpace(i.Reason) == "" {
   496  		return true
   497  	}
   498  
   499  	for _, v := range setting.Repository.Issue.LockReasons {
   500  		if v == i.Reason {
   501  			return true
   502  		}
   503  	}
   504  
   505  	return false
   506  }
   507  
   508  // __________                   __               __
   509  // \______   \_______  ____    |__| ____   _____/  |_  ______
   510  //  |     ___/\_  __ \/  _ \   |  |/ __ \_/ ___\   __\/  ___/
   511  //  |    |     |  | \(  <_> )  |  \  ___/\  \___|  |  \___ \
   512  //  |____|     |__|   \____/\__|  |\___  >\___  >__| /____  >
   513  //                         \______|    \/     \/          \/
   514  
   515  // CreateProjectForm form for creating a project
   516  type CreateProjectForm struct {
   517  	Title     string `binding:"Required;MaxSize(100)"`
   518  	Content   string
   519  	BoardType project_model.BoardType
   520  	CardType  project_model.CardType
   521  }
   522  
   523  // UserCreateProjectForm is a from for creating an individual or organization
   524  // form.
   525  type UserCreateProjectForm struct {
   526  	Title     string `binding:"Required;MaxSize(100)"`
   527  	Content   string
   528  	BoardType project_model.BoardType
   529  	CardType  project_model.CardType
   530  	UID       int64 `binding:"Required"`
   531  }
   532  
   533  // EditProjectBoardForm is a form for editing a project board
   534  type EditProjectBoardForm struct {
   535  	Title   string `binding:"Required;MaxSize(100)"`
   536  	Sorting int8
   537  	Color   string `binding:"MaxSize(7)"`
   538  }
   539  
   540  //    _____  .__.__                   __
   541  //   /     \ |__|  |   ____   _______/  |_  ____   ____   ____
   542  //  /  \ /  \|  |  | _/ __ \ /  ___/\   __\/  _ \ /    \_/ __ \
   543  // /    Y    \  |  |_\  ___/ \___ \  |  | (  <_> )   |  \  ___/
   544  // \____|__  /__|____/\___  >____  > |__|  \____/|___|  /\___  >
   545  //         \/             \/     \/                   \/     \/
   546  
   547  // CreateMilestoneForm form for creating milestone
   548  type CreateMilestoneForm struct {
   549  	Title    string `binding:"Required;MaxSize(50)"`
   550  	Content  string
   551  	Deadline string
   552  }
   553  
   554  // Validate validates the fields
   555  func (f *CreateMilestoneForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
   556  	ctx := context.GetValidateContext(req)
   557  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
   558  }
   559  
   560  // .____          ___.          .__
   561  // |    |   _____ \_ |__   ____ |  |
   562  // |    |   \__  \ | __ \_/ __ \|  |
   563  // |    |___ / __ \| \_\ \  ___/|  |__
   564  // |_______ (____  /___  /\___  >____/
   565  //         \/    \/    \/     \/
   566  
   567  // CreateLabelForm form for creating label
   568  type CreateLabelForm struct {
   569  	ID          int64
   570  	Title       string `binding:"Required;MaxSize(50)" locale:"repo.issues.label_title"`
   571  	Exclusive   bool   `form:"exclusive"`
   572  	IsArchived  bool   `form:"is_archived"`
   573  	Description string `binding:"MaxSize(200)" locale:"repo.issues.label_description"`
   574  	Color       string `binding:"Required;MaxSize(7)" locale:"repo.issues.label_color"`
   575  }
   576  
   577  // Validate validates the fields
   578  func (f *CreateLabelForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
   579  	ctx := context.GetValidateContext(req)
   580  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
   581  }
   582  
   583  // InitializeLabelsForm form for initializing labels
   584  type InitializeLabelsForm struct {
   585  	TemplateName string `binding:"Required"`
   586  }
   587  
   588  // Validate validates the fields
   589  func (f *InitializeLabelsForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
   590  	ctx := context.GetValidateContext(req)
   591  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
   592  }
   593  
   594  // __________      .__  .__    __________                                     __
   595  // \______   \__ __|  | |  |   \______   \ ____  ________ __   ____   _______/  |_
   596  //  |     ___/  |  \  | |  |    |       _// __ \/ ____/  |  \_/ __ \ /  ___/\   __\
   597  //  |    |   |  |  /  |_|  |__  |    |   \  ___< <_|  |  |  /\  ___/ \___ \  |  |
   598  //  |____|   |____/|____/____/  |____|_  /\___  >__   |____/  \___  >____  > |__|
   599  //                                     \/     \/   |__|           \/     \/
   600  
   601  // MergePullRequestForm form for merging Pull Request
   602  // swagger:model MergePullRequestOption
   603  type MergePullRequestForm struct {
   604  	// required: true
   605  	// enum: merge,rebase,rebase-merge,squash,fast-forward-only,manually-merged
   606  	Do                     string `binding:"Required;In(merge,rebase,rebase-merge,squash,fast-forward-only,manually-merged)"`
   607  	MergeTitleField        string
   608  	MergeMessageField      string
   609  	MergeCommitID          string // only used for manually-merged
   610  	HeadCommitID           string `json:"head_commit_id,omitempty"`
   611  	ForceMerge             bool   `json:"force_merge,omitempty"`
   612  	MergeWhenChecksSucceed bool   `json:"merge_when_checks_succeed,omitempty"`
   613  	DeleteBranchAfterMerge bool   `json:"delete_branch_after_merge,omitempty"`
   614  }
   615  
   616  // Validate validates the fields
   617  func (f *MergePullRequestForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
   618  	ctx := context.GetValidateContext(req)
   619  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
   620  }
   621  
   622  // CodeCommentForm form for adding code comments for PRs
   623  type CodeCommentForm struct {
   624  	Origin         string `binding:"Required;In(timeline,diff)"`
   625  	Content        string `binding:"Required"`
   626  	Side           string `binding:"Required;In(previous,proposed)"`
   627  	Line           int64
   628  	TreePath       string `form:"path" binding:"Required"`
   629  	SingleReview   bool   `form:"single_review"`
   630  	Reply          int64  `form:"reply"`
   631  	LatestCommitID string
   632  	Files          []string
   633  }
   634  
   635  // Validate validates the fields
   636  func (f *CodeCommentForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
   637  	ctx := context.GetValidateContext(req)
   638  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
   639  }
   640  
   641  // SubmitReviewForm for submitting a finished code review
   642  type SubmitReviewForm struct {
   643  	Content  string
   644  	Type     string
   645  	CommitID string
   646  	Files    []string
   647  }
   648  
   649  // Validate validates the fields
   650  func (f *SubmitReviewForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
   651  	ctx := context.GetValidateContext(req)
   652  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
   653  }
   654  
   655  // ReviewType will return the corresponding ReviewType for type
   656  func (f SubmitReviewForm) ReviewType() issues_model.ReviewType {
   657  	switch f.Type {
   658  	case "approve":
   659  		return issues_model.ReviewTypeApprove
   660  	case "comment":
   661  		return issues_model.ReviewTypeComment
   662  	case "reject":
   663  		return issues_model.ReviewTypeReject
   664  	case "":
   665  		return issues_model.ReviewTypeComment // default to comment when doing quick-submit (Ctrl+Enter) on the review form
   666  	default:
   667  		return issues_model.ReviewTypeUnknown
   668  	}
   669  }
   670  
   671  // HasEmptyContent checks if the content of the review form is empty.
   672  func (f SubmitReviewForm) HasEmptyContent() bool {
   673  	reviewType := f.ReviewType()
   674  
   675  	return (reviewType == issues_model.ReviewTypeComment || reviewType == issues_model.ReviewTypeReject) &&
   676  		len(strings.TrimSpace(f.Content)) == 0
   677  }
   678  
   679  // DismissReviewForm for dismissing stale review by repo admin
   680  type DismissReviewForm struct {
   681  	ReviewID int64 `binding:"Required"`
   682  	Message  string
   683  }
   684  
   685  // UpdateAllowEditsForm form for changing if PR allows edits from maintainers
   686  type UpdateAllowEditsForm struct {
   687  	AllowMaintainerEdit bool
   688  }
   689  
   690  // __________       .__
   691  // \______   \ ____ |  |   ____ _____    ______ ____
   692  //  |       _// __ \|  | _/ __ \\__  \  /  ___// __ \
   693  //  |    |   \  ___/|  |_\  ___/ / __ \_\___ \\  ___/
   694  //  |____|_  /\___  >____/\___  >____  /____  >\___  >
   695  //         \/     \/          \/     \/     \/     \/
   696  
   697  // NewReleaseForm form for creating release
   698  type NewReleaseForm struct {
   699  	TagName    string `binding:"Required;GitRefName;MaxSize(255)"`
   700  	Target     string `form:"tag_target" binding:"Required;MaxSize(255)"`
   701  	Title      string `binding:"MaxSize(255)"`
   702  	Content    string
   703  	Draft      string
   704  	TagOnly    string
   705  	Prerelease bool
   706  	AddTagMsg  bool
   707  	Files      []string
   708  }
   709  
   710  // Validate validates the fields
   711  func (f *NewReleaseForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
   712  	ctx := context.GetValidateContext(req)
   713  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
   714  }
   715  
   716  // EditReleaseForm form for changing release
   717  type EditReleaseForm struct {
   718  	Title      string `form:"title" binding:"Required;MaxSize(255)"`
   719  	Content    string `form:"content"`
   720  	Draft      string `form:"draft"`
   721  	Prerelease bool   `form:"prerelease"`
   722  	Files      []string
   723  }
   724  
   725  // Validate validates the fields
   726  func (f *EditReleaseForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
   727  	ctx := context.GetValidateContext(req)
   728  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
   729  }
   730  
   731  //  __      __.__ __   .__
   732  // /  \    /  \__|  | _|__|
   733  // \   \/\/   /  |  |/ /  |
   734  //  \        /|  |    <|  |
   735  //   \__/\  / |__|__|_ \__|
   736  //        \/          \/
   737  
   738  // NewWikiForm form for creating wiki
   739  type NewWikiForm struct {
   740  	Title   string `binding:"Required"`
   741  	Content string `binding:"Required"`
   742  	Message string
   743  }
   744  
   745  // Validate validates the fields
   746  // FIXME: use code generation to generate this method.
   747  func (f *NewWikiForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
   748  	ctx := context.GetValidateContext(req)
   749  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
   750  }
   751  
   752  // ___________    .___.__  __
   753  // \_   _____/  __| _/|__|/  |_
   754  //  |    __)_  / __ | |  \   __\
   755  //  |        \/ /_/ | |  ||  |
   756  // /_______  /\____ | |__||__|
   757  //         \/      \/
   758  
   759  // EditRepoFileForm form for changing repository file
   760  type EditRepoFileForm struct {
   761  	TreePath      string `binding:"Required;MaxSize(500)"`
   762  	Content       string
   763  	CommitSummary string `binding:"MaxSize(100)"`
   764  	CommitMessage string
   765  	CommitChoice  string `binding:"Required;MaxSize(50)"`
   766  	NewBranchName string `binding:"GitRefName;MaxSize(100)"`
   767  	LastCommit    string
   768  	Signoff       bool
   769  }
   770  
   771  // Validate validates the fields
   772  func (f *EditRepoFileForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
   773  	ctx := context.GetValidateContext(req)
   774  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
   775  }
   776  
   777  // EditPreviewDiffForm form for changing preview diff
   778  type EditPreviewDiffForm struct {
   779  	Content string
   780  }
   781  
   782  // Validate validates the fields
   783  func (f *EditPreviewDiffForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
   784  	ctx := context.GetValidateContext(req)
   785  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
   786  }
   787  
   788  // _________ .__                                 __________.__        __
   789  // \_   ___ \|  |__   __________________ ___.__. \______   \__| ____ |  | __
   790  // /    \  \/|  |  \_/ __ \_  __ \_  __ <   |  |  |     ___/  |/ ___\|  |/ /
   791  // \     \___|   Y  \  ___/|  | \/|  | \/\___  |  |    |   |  \  \___|    <
   792  //  \______  /___|  /\___  >__|   |__|   / ____|  |____|   |__|\___  >__|_ \
   793  //         \/     \/     \/              \/                        \/     \/
   794  
   795  // CherryPickForm form for changing repository file
   796  type CherryPickForm struct {
   797  	CommitSummary string `binding:"MaxSize(100)"`
   798  	CommitMessage string
   799  	CommitChoice  string `binding:"Required;MaxSize(50)"`
   800  	NewBranchName string `binding:"GitRefName;MaxSize(100)"`
   801  	LastCommit    string
   802  	Revert        bool
   803  	Signoff       bool
   804  }
   805  
   806  // Validate validates the fields
   807  func (f *CherryPickForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
   808  	ctx := context.GetValidateContext(req)
   809  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
   810  }
   811  
   812  //  ____ ___        .__                    .___
   813  // |    |   \______ |  |   _________     __| _/
   814  // |    |   /\____ \|  |  /  _ \__  \   / __ |
   815  // |    |  / |  |_> >  |_(  <_> ) __ \_/ /_/ |
   816  // |______/  |   __/|____/\____(____  /\____ |
   817  //           |__|                   \/      \/
   818  //
   819  
   820  // UploadRepoFileForm form for uploading repository file
   821  type UploadRepoFileForm struct {
   822  	TreePath      string `binding:"MaxSize(500)"`
   823  	CommitSummary string `binding:"MaxSize(100)"`
   824  	CommitMessage string
   825  	CommitChoice  string `binding:"Required;MaxSize(50)"`
   826  	NewBranchName string `binding:"GitRefName;MaxSize(100)"`
   827  	Files         []string
   828  	Signoff       bool
   829  }
   830  
   831  // Validate validates the fields
   832  func (f *UploadRepoFileForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
   833  	ctx := context.GetValidateContext(req)
   834  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
   835  }
   836  
   837  // RemoveUploadFileForm form for removing uploaded file
   838  type RemoveUploadFileForm struct {
   839  	File string `binding:"Required;MaxSize(50)"`
   840  }
   841  
   842  // Validate validates the fields
   843  func (f *RemoveUploadFileForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
   844  	ctx := context.GetValidateContext(req)
   845  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
   846  }
   847  
   848  // ________         .__          __
   849  // \______ \   ____ |  |   _____/  |_  ____
   850  // |    |  \_/ __ \|  | _/ __ \   __\/ __ \
   851  // |    `   \  ___/|  |_\  ___/|  | \  ___/
   852  // /_______  /\___  >____/\___  >__|  \___  >
   853  //         \/     \/          \/          \/
   854  
   855  // DeleteRepoFileForm form for deleting repository file
   856  type DeleteRepoFileForm struct {
   857  	CommitSummary string `binding:"MaxSize(100)"`
   858  	CommitMessage string
   859  	CommitChoice  string `binding:"Required;MaxSize(50)"`
   860  	NewBranchName string `binding:"GitRefName;MaxSize(100)"`
   861  	LastCommit    string
   862  	Signoff       bool
   863  }
   864  
   865  // Validate validates the fields
   866  func (f *DeleteRepoFileForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
   867  	ctx := context.GetValidateContext(req)
   868  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
   869  }
   870  
   871  // ___________.__                 ___________                     __
   872  // \__    ___/|__| _____   ____   \__    ___/___________    ____ |  | __ ___________
   873  // |    |   |  |/     \_/ __ \    |    |  \_  __ \__  \ _/ ___\|  |/ // __ \_  __ \
   874  // |    |   |  |  Y Y  \  ___/    |    |   |  | \// __ \\  \___|    <\  ___/|  | \/
   875  // |____|   |__|__|_|  /\___  >   |____|   |__|  (____  /\___  >__|_ \\___  >__|
   876  // \/     \/                        \/     \/     \/    \/
   877  
   878  // AddTimeManuallyForm form that adds spent time manually.
   879  type AddTimeManuallyForm struct {
   880  	Hours   int `binding:"Range(0,1000)"`
   881  	Minutes int `binding:"Range(0,1000)"`
   882  }
   883  
   884  // Validate validates the fields
   885  func (f *AddTimeManuallyForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
   886  	ctx := context.GetValidateContext(req)
   887  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
   888  }
   889  
   890  // SaveTopicForm form for save topics for repository
   891  type SaveTopicForm struct {
   892  	Topics []string `binding:"topics;Required;"`
   893  }
   894  
   895  // DeadlineForm hold the validation rules for deadlines
   896  type DeadlineForm struct {
   897  	DateString string `form:"date" binding:"Required;Size(10)"`
   898  }
   899  
   900  // Validate validates the fields
   901  func (f *DeadlineForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
   902  	ctx := context.GetValidateContext(req)
   903  	return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
   904  }