code.gitea.io/gitea@v1.19.3/modules/structs/repo.go (about)

     1  // Copyright 2014 The Gogs Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package structs
     5  
     6  import (
     7  	"strings"
     8  	"time"
     9  )
    10  
    11  // Permission represents a set of permissions
    12  type Permission struct {
    13  	Admin bool `json:"admin"`
    14  	Push  bool `json:"push"`
    15  	Pull  bool `json:"pull"`
    16  }
    17  
    18  // InternalTracker represents settings for internal tracker
    19  // swagger:model
    20  type InternalTracker struct {
    21  	// Enable time tracking (Built-in issue tracker)
    22  	EnableTimeTracker bool `json:"enable_time_tracker"`
    23  	// Let only contributors track time (Built-in issue tracker)
    24  	AllowOnlyContributorsToTrackTime bool `json:"allow_only_contributors_to_track_time"`
    25  	// Enable dependencies for issues and pull requests (Built-in issue tracker)
    26  	EnableIssueDependencies bool `json:"enable_issue_dependencies"`
    27  }
    28  
    29  // ExternalTracker represents settings for external tracker
    30  // swagger:model
    31  type ExternalTracker struct {
    32  	// URL of external issue tracker.
    33  	ExternalTrackerURL string `json:"external_tracker_url"`
    34  	// External Issue Tracker URL Format. Use the placeholders {user}, {repo} and {index} for the username, repository name and issue index.
    35  	ExternalTrackerFormat string `json:"external_tracker_format"`
    36  	// External Issue Tracker Number Format, either `numeric`, `alphanumeric`, or `regexp`
    37  	ExternalTrackerStyle string `json:"external_tracker_style"`
    38  	// External Issue Tracker issue regular expression
    39  	ExternalTrackerRegexpPattern string `json:"external_tracker_regexp_pattern"`
    40  }
    41  
    42  // ExternalWiki represents setting for external wiki
    43  // swagger:model
    44  type ExternalWiki struct {
    45  	// URL of external wiki.
    46  	ExternalWikiURL string `json:"external_wiki_url"`
    47  }
    48  
    49  // Repository represents a repository
    50  type Repository struct {
    51  	ID            int64       `json:"id"`
    52  	Owner         *User       `json:"owner"`
    53  	Name          string      `json:"name"`
    54  	FullName      string      `json:"full_name"`
    55  	Description   string      `json:"description"`
    56  	Empty         bool        `json:"empty"`
    57  	Private       bool        `json:"private"`
    58  	Fork          bool        `json:"fork"`
    59  	Template      bool        `json:"template"`
    60  	Parent        *Repository `json:"parent"`
    61  	Mirror        bool        `json:"mirror"`
    62  	Size          int         `json:"size"`
    63  	Language      string      `json:"language"`
    64  	LanguagesURL  string      `json:"languages_url"`
    65  	HTMLURL       string      `json:"html_url"`
    66  	Link          string      `json:"link"`
    67  	SSHURL        string      `json:"ssh_url"`
    68  	CloneURL      string      `json:"clone_url"`
    69  	OriginalURL   string      `json:"original_url"`
    70  	Website       string      `json:"website"`
    71  	Stars         int         `json:"stars_count"`
    72  	Forks         int         `json:"forks_count"`
    73  	Watchers      int         `json:"watchers_count"`
    74  	OpenIssues    int         `json:"open_issues_count"`
    75  	OpenPulls     int         `json:"open_pr_counter"`
    76  	Releases      int         `json:"release_counter"`
    77  	DefaultBranch string      `json:"default_branch"`
    78  	Archived      bool        `json:"archived"`
    79  	// swagger:strfmt date-time
    80  	Created time.Time `json:"created_at"`
    81  	// swagger:strfmt date-time
    82  	Updated                       time.Time        `json:"updated_at"`
    83  	Permissions                   *Permission      `json:"permissions,omitempty"`
    84  	HasIssues                     bool             `json:"has_issues"`
    85  	InternalTracker               *InternalTracker `json:"internal_tracker,omitempty"`
    86  	ExternalTracker               *ExternalTracker `json:"external_tracker,omitempty"`
    87  	HasWiki                       bool             `json:"has_wiki"`
    88  	ExternalWiki                  *ExternalWiki    `json:"external_wiki,omitempty"`
    89  	HasPullRequests               bool             `json:"has_pull_requests"`
    90  	HasProjects                   bool             `json:"has_projects"`
    91  	IgnoreWhitespaceConflicts     bool             `json:"ignore_whitespace_conflicts"`
    92  	AllowMerge                    bool             `json:"allow_merge_commits"`
    93  	AllowRebase                   bool             `json:"allow_rebase"`
    94  	AllowRebaseMerge              bool             `json:"allow_rebase_explicit"`
    95  	AllowSquash                   bool             `json:"allow_squash_merge"`
    96  	AllowRebaseUpdate             bool             `json:"allow_rebase_update"`
    97  	DefaultDeleteBranchAfterMerge bool             `json:"default_delete_branch_after_merge"`
    98  	DefaultMergeStyle             string           `json:"default_merge_style"`
    99  	DefaultAllowMaintainerEdit    bool             `json:"default_allow_maintainer_edit"`
   100  	AvatarURL                     string           `json:"avatar_url"`
   101  	Internal                      bool             `json:"internal"`
   102  	MirrorInterval                string           `json:"mirror_interval"`
   103  	// swagger:strfmt date-time
   104  	MirrorUpdated time.Time     `json:"mirror_updated,omitempty"`
   105  	RepoTransfer  *RepoTransfer `json:"repo_transfer"`
   106  }
   107  
   108  // CreateRepoOption options when creating repository
   109  // swagger:model
   110  type CreateRepoOption struct {
   111  	// Name of the repository to create
   112  	//
   113  	// required: true
   114  	// unique: true
   115  	Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(100)"`
   116  	// Description of the repository to create
   117  	Description string `json:"description" binding:"MaxSize(2048)"`
   118  	// Whether the repository is private
   119  	Private bool `json:"private"`
   120  	// Label-Set to use
   121  	IssueLabels string `json:"issue_labels"`
   122  	// Whether the repository should be auto-initialized?
   123  	AutoInit bool `json:"auto_init"`
   124  	// Whether the repository is template
   125  	Template bool `json:"template"`
   126  	// Gitignores to use
   127  	Gitignores string `json:"gitignores"`
   128  	// License to use
   129  	License string `json:"license"`
   130  	// Readme of the repository to create
   131  	Readme string `json:"readme"`
   132  	// DefaultBranch of the repository (used when initializes and in template)
   133  	DefaultBranch string `json:"default_branch" binding:"GitRefName;MaxSize(100)"`
   134  	// TrustModel of the repository
   135  	// enum: default,collaborator,committer,collaboratorcommitter
   136  	TrustModel string `json:"trust_model"`
   137  }
   138  
   139  // EditRepoOption options when editing a repository's properties
   140  // swagger:model
   141  type EditRepoOption struct {
   142  	// name of the repository
   143  	// unique: true
   144  	Name *string `json:"name,omitempty" binding:"OmitEmpty;AlphaDashDot;MaxSize(100);"`
   145  	// a short description of the repository.
   146  	Description *string `json:"description,omitempty" binding:"MaxSize(2048)"`
   147  	// a URL with more information about the repository.
   148  	Website *string `json:"website,omitempty" binding:"MaxSize(1024)"`
   149  	// either `true` to make the repository private or `false` to make it public.
   150  	// Note: you will get a 422 error if the organization restricts changing repository visibility to organization
   151  	// owners and a non-owner tries to change the value of private.
   152  	Private *bool `json:"private,omitempty"`
   153  	// either `true` to make this repository a template or `false` to make it a normal repository
   154  	Template *bool `json:"template,omitempty"`
   155  	// either `true` to enable issues for this repository or `false` to disable them.
   156  	HasIssues *bool `json:"has_issues,omitempty"`
   157  	// set this structure to configure internal issue tracker
   158  	InternalTracker *InternalTracker `json:"internal_tracker,omitempty"`
   159  	// set this structure to use external issue tracker
   160  	ExternalTracker *ExternalTracker `json:"external_tracker,omitempty"`
   161  	// either `true` to enable the wiki for this repository or `false` to disable it.
   162  	HasWiki *bool `json:"has_wiki,omitempty"`
   163  	// set this structure to use external wiki instead of internal
   164  	ExternalWiki *ExternalWiki `json:"external_wiki,omitempty"`
   165  	// sets the default branch for this repository.
   166  	DefaultBranch *string `json:"default_branch,omitempty"`
   167  	// either `true` to allow pull requests, or `false` to prevent pull request.
   168  	HasPullRequests *bool `json:"has_pull_requests,omitempty"`
   169  	// either `true` to enable project unit, or `false` to disable them.
   170  	HasProjects *bool `json:"has_projects,omitempty"`
   171  	// either `true` to ignore whitespace for conflicts, or `false` to not ignore whitespace.
   172  	IgnoreWhitespaceConflicts *bool `json:"ignore_whitespace_conflicts,omitempty"`
   173  	// either `true` to allow merging pull requests with a merge commit, or `false` to prevent merging pull requests with merge commits.
   174  	AllowMerge *bool `json:"allow_merge_commits,omitempty"`
   175  	// either `true` to allow rebase-merging pull requests, or `false` to prevent rebase-merging.
   176  	AllowRebase *bool `json:"allow_rebase,omitempty"`
   177  	// either `true` to allow rebase with explicit merge commits (--no-ff), or `false` to prevent rebase with explicit merge commits.
   178  	AllowRebaseMerge *bool `json:"allow_rebase_explicit,omitempty"`
   179  	// either `true` to allow squash-merging pull requests, or `false` to prevent squash-merging.
   180  	AllowSquash *bool `json:"allow_squash_merge,omitempty"`
   181  	// either `true` to allow mark pr as merged manually, or `false` to prevent it.
   182  	AllowManualMerge *bool `json:"allow_manual_merge,omitempty"`
   183  	// either `true` to enable AutodetectManualMerge, or `false` to prevent it. Note: In some special cases, misjudgments can occur.
   184  	AutodetectManualMerge *bool `json:"autodetect_manual_merge,omitempty"`
   185  	// either `true` to allow updating pull request branch by rebase, or `false` to prevent it.
   186  	AllowRebaseUpdate *bool `json:"allow_rebase_update,omitempty"`
   187  	// set to `true` to delete pr branch after merge by default
   188  	DefaultDeleteBranchAfterMerge *bool `json:"default_delete_branch_after_merge,omitempty"`
   189  	// set to a merge style to be used by this repository: "merge", "rebase", "rebase-merge", or "squash".
   190  	DefaultMergeStyle *string `json:"default_merge_style,omitempty"`
   191  	// set to `true` to allow edits from maintainers by default
   192  	DefaultAllowMaintainerEdit *bool `json:"default_allow_maintainer_edit,omitempty"`
   193  	// set to `true` to archive this repository.
   194  	Archived *bool `json:"archived,omitempty"`
   195  	// set to a string like `8h30m0s` to set the mirror interval time
   196  	MirrorInterval *string `json:"mirror_interval,omitempty"`
   197  	// enable prune - remove obsolete remote-tracking references
   198  	EnablePrune *bool `json:"enable_prune,omitempty"`
   199  }
   200  
   201  // GenerateRepoOption options when creating repository using a template
   202  // swagger:model
   203  type GenerateRepoOption struct {
   204  	// The organization or person who will own the new repository
   205  	//
   206  	// required: true
   207  	Owner string `json:"owner"`
   208  	// Name of the repository to create
   209  	//
   210  	// required: true
   211  	// unique: true
   212  	Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(100)"`
   213  	// Default branch of the new repository
   214  	DefaultBranch string `json:"default_branch"`
   215  	// Description of the repository to create
   216  	Description string `json:"description" binding:"MaxSize(2048)"`
   217  	// Whether the repository is private
   218  	Private bool `json:"private"`
   219  	// include git content of default branch in template repo
   220  	GitContent bool `json:"git_content"`
   221  	// include topics in template repo
   222  	Topics bool `json:"topics"`
   223  	// include git hooks in template repo
   224  	GitHooks bool `json:"git_hooks"`
   225  	// include webhooks in template repo
   226  	Webhooks bool `json:"webhooks"`
   227  	// include avatar of the template repo
   228  	Avatar bool `json:"avatar"`
   229  	// include labels in template repo
   230  	Labels bool `json:"labels"`
   231  }
   232  
   233  // CreateBranchRepoOption options when creating a branch in a repository
   234  // swagger:model
   235  type CreateBranchRepoOption struct {
   236  	// Name of the branch to create
   237  	//
   238  	// required: true
   239  	// unique: true
   240  	BranchName string `json:"new_branch_name" binding:"Required;GitRefName;MaxSize(100)"`
   241  
   242  	// Name of the old branch to create from
   243  	//
   244  	// unique: true
   245  	OldBranchName string `json:"old_branch_name" binding:"GitRefName;MaxSize(100)"`
   246  }
   247  
   248  // TransferRepoOption options when transfer a repository's ownership
   249  // swagger:model
   250  type TransferRepoOption struct {
   251  	// required: true
   252  	NewOwner string `json:"new_owner"`
   253  	// ID of the team or teams to add to the repository. Teams can only be added to organization-owned repositories.
   254  	TeamIDs *[]int64 `json:"team_ids"`
   255  }
   256  
   257  // GitServiceType represents a git service
   258  type GitServiceType int
   259  
   260  // enumerate all GitServiceType
   261  const (
   262  	NotMigrated      GitServiceType = iota // 0 not migrated from external sites
   263  	PlainGitService                        // 1 plain git service
   264  	GithubService                          // 2 github.com
   265  	GiteaService                           // 3 gitea service
   266  	GitlabService                          // 4 gitlab service
   267  	GogsService                            // 5 gogs service
   268  	OneDevService                          // 6 onedev service
   269  	GitBucketService                       // 7 gitbucket service
   270  	CodebaseService                        // 8 codebase service
   271  )
   272  
   273  // Name represents the service type's name
   274  // WARNNING: the name have to be equal to that on goth's library
   275  func (gt GitServiceType) Name() string {
   276  	return strings.ToLower(gt.Title())
   277  }
   278  
   279  // Title represents the service type's proper title
   280  func (gt GitServiceType) Title() string {
   281  	switch gt {
   282  	case GithubService:
   283  		return "GitHub"
   284  	case GiteaService:
   285  		return "Gitea"
   286  	case GitlabService:
   287  		return "GitLab"
   288  	case GogsService:
   289  		return "Gogs"
   290  	case OneDevService:
   291  		return "OneDev"
   292  	case GitBucketService:
   293  		return "GitBucket"
   294  	case CodebaseService:
   295  		return "Codebase"
   296  	case PlainGitService:
   297  		return "Git"
   298  	}
   299  	return ""
   300  }
   301  
   302  // MigrateRepoOptions options for migrating repository's
   303  // this is used to interact with api v1
   304  type MigrateRepoOptions struct {
   305  	// required: true
   306  	CloneAddr string `json:"clone_addr" binding:"Required"`
   307  	// deprecated (only for backwards compatibility)
   308  	RepoOwnerID int64 `json:"uid"`
   309  	// Name of User or Organisation who will own Repo after migration
   310  	RepoOwner string `json:"repo_owner"`
   311  	// required: true
   312  	RepoName string `json:"repo_name" binding:"Required;AlphaDashDot;MaxSize(100)"`
   313  
   314  	// enum: git,github,gitea,gitlab
   315  	Service      string `json:"service"`
   316  	AuthUsername string `json:"auth_username"`
   317  	AuthPassword string `json:"auth_password"`
   318  	AuthToken    string `json:"auth_token"`
   319  
   320  	Mirror         bool   `json:"mirror"`
   321  	LFS            bool   `json:"lfs"`
   322  	LFSEndpoint    string `json:"lfs_endpoint"`
   323  	Private        bool   `json:"private"`
   324  	Description    string `json:"description" binding:"MaxSize(2048)"`
   325  	Wiki           bool   `json:"wiki"`
   326  	Milestones     bool   `json:"milestones"`
   327  	Labels         bool   `json:"labels"`
   328  	Issues         bool   `json:"issues"`
   329  	PullRequests   bool   `json:"pull_requests"`
   330  	Releases       bool   `json:"releases"`
   331  	MirrorInterval string `json:"mirror_interval"`
   332  }
   333  
   334  // TokenAuth represents whether a service type supports token-based auth
   335  func (gt GitServiceType) TokenAuth() bool {
   336  	switch gt {
   337  	case GithubService, GiteaService, GitlabService:
   338  		return true
   339  	}
   340  	return false
   341  }
   342  
   343  // SupportedFullGitService represents all git services supported to migrate issues/labels/prs and etc.
   344  // TODO: add to this list after new git service added
   345  var SupportedFullGitService = []GitServiceType{
   346  	GithubService,
   347  	GitlabService,
   348  	GiteaService,
   349  	GogsService,
   350  	OneDevService,
   351  	GitBucketService,
   352  	CodebaseService,
   353  }
   354  
   355  // RepoTransfer represents a pending repo transfer
   356  type RepoTransfer struct {
   357  	Doer      *User   `json:"doer"`
   358  	Recipient *User   `json:"recipient"`
   359  	Teams     []*Team `json:"teams"`
   360  }