code.gitea.io/gitea@v1.22.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"` // Admin indicates if the user is an administrator of the repository.
    14  	Push  bool `json:"push"`  // Push indicates if the user can push code to the repository.
    15  	Pull  bool `json:"pull"`  // Pull indicates if the user can pull code from the repository.
    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  	URL           string      `json:"url"`
    67  	Link          string      `json:"link"`
    68  	SSHURL        string      `json:"ssh_url"`
    69  	CloneURL      string      `json:"clone_url"`
    70  	OriginalURL   string      `json:"original_url"`
    71  	Website       string      `json:"website"`
    72  	Stars         int         `json:"stars_count"`
    73  	Forks         int         `json:"forks_count"`
    74  	Watchers      int         `json:"watchers_count"`
    75  	OpenIssues    int         `json:"open_issues_count"`
    76  	OpenPulls     int         `json:"open_pr_counter"`
    77  	Releases      int         `json:"release_counter"`
    78  	DefaultBranch string      `json:"default_branch"`
    79  	Archived      bool        `json:"archived"`
    80  	// swagger:strfmt date-time
    81  	Created time.Time `json:"created_at"`
    82  	// swagger:strfmt date-time
    83  	Updated                       time.Time        `json:"updated_at"`
    84  	ArchivedAt                    time.Time        `json:"archived_at"`
    85  	Permissions                   *Permission      `json:"permissions,omitempty"`
    86  	HasIssues                     bool             `json:"has_issues"`
    87  	InternalTracker               *InternalTracker `json:"internal_tracker,omitempty"`
    88  	ExternalTracker               *ExternalTracker `json:"external_tracker,omitempty"`
    89  	HasWiki                       bool             `json:"has_wiki"`
    90  	ExternalWiki                  *ExternalWiki    `json:"external_wiki,omitempty"`
    91  	HasPullRequests               bool             `json:"has_pull_requests"`
    92  	HasProjects                   bool             `json:"has_projects"`
    93  	ProjectsMode                  string           `json:"projects_mode"`
    94  	HasReleases                   bool             `json:"has_releases"`
    95  	HasPackages                   bool             `json:"has_packages"`
    96  	HasActions                    bool             `json:"has_actions"`
    97  	IgnoreWhitespaceConflicts     bool             `json:"ignore_whitespace_conflicts"`
    98  	AllowMerge                    bool             `json:"allow_merge_commits"`
    99  	AllowRebase                   bool             `json:"allow_rebase"`
   100  	AllowRebaseMerge              bool             `json:"allow_rebase_explicit"`
   101  	AllowSquash                   bool             `json:"allow_squash_merge"`
   102  	AllowFastForwardOnly          bool             `json:"allow_fast_forward_only_merge"`
   103  	AllowRebaseUpdate             bool             `json:"allow_rebase_update"`
   104  	DefaultDeleteBranchAfterMerge bool             `json:"default_delete_branch_after_merge"`
   105  	DefaultMergeStyle             string           `json:"default_merge_style"`
   106  	DefaultAllowMaintainerEdit    bool             `json:"default_allow_maintainer_edit"`
   107  	AvatarURL                     string           `json:"avatar_url"`
   108  	Internal                      bool             `json:"internal"`
   109  	MirrorInterval                string           `json:"mirror_interval"`
   110  	// ObjectFormatName of the underlying git repository
   111  	// enum: sha1,sha256
   112  	ObjectFormatName string `json:"object_format_name"`
   113  	// swagger:strfmt date-time
   114  	MirrorUpdated time.Time     `json:"mirror_updated,omitempty"`
   115  	RepoTransfer  *RepoTransfer `json:"repo_transfer"`
   116  }
   117  
   118  // CreateRepoOption options when creating repository
   119  // swagger:model
   120  type CreateRepoOption struct {
   121  	// Name of the repository to create
   122  	//
   123  	// required: true
   124  	// unique: true
   125  	Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(100)"`
   126  	// Description of the repository to create
   127  	Description string `json:"description" binding:"MaxSize(2048)"`
   128  	// Whether the repository is private
   129  	Private bool `json:"private"`
   130  	// Label-Set to use
   131  	IssueLabels string `json:"issue_labels"`
   132  	// Whether the repository should be auto-initialized?
   133  	AutoInit bool `json:"auto_init"`
   134  	// Whether the repository is template
   135  	Template bool `json:"template"`
   136  	// Gitignores to use
   137  	Gitignores string `json:"gitignores"`
   138  	// License to use
   139  	License string `json:"license"`
   140  	// Readme of the repository to create
   141  	Readme string `json:"readme"`
   142  	// DefaultBranch of the repository (used when initializes and in template)
   143  	DefaultBranch string `json:"default_branch" binding:"GitRefName;MaxSize(100)"`
   144  	// TrustModel of the repository
   145  	// enum: default,collaborator,committer,collaboratorcommitter
   146  	TrustModel string `json:"trust_model"`
   147  	// ObjectFormatName of the underlying git repository
   148  	// enum: sha1,sha256
   149  	ObjectFormatName string `json:"object_format_name" binding:"MaxSize(6)"`
   150  }
   151  
   152  // EditRepoOption options when editing a repository's properties
   153  // swagger:model
   154  type EditRepoOption struct {
   155  	// name of the repository
   156  	// unique: true
   157  	Name *string `json:"name,omitempty" binding:"OmitEmpty;AlphaDashDot;MaxSize(100);"`
   158  	// a short description of the repository.
   159  	Description *string `json:"description,omitempty" binding:"MaxSize(2048)"`
   160  	// a URL with more information about the repository.
   161  	Website *string `json:"website,omitempty" binding:"MaxSize(1024)"`
   162  	// either `true` to make the repository private or `false` to make it public.
   163  	// Note: you will get a 422 error if the organization restricts changing repository visibility to organization
   164  	// owners and a non-owner tries to change the value of private.
   165  	Private *bool `json:"private,omitempty"`
   166  	// either `true` to make this repository a template or `false` to make it a normal repository
   167  	Template *bool `json:"template,omitempty"`
   168  	// either `true` to enable issues for this repository or `false` to disable them.
   169  	HasIssues *bool `json:"has_issues,omitempty"`
   170  	// set this structure to configure internal issue tracker
   171  	InternalTracker *InternalTracker `json:"internal_tracker,omitempty"`
   172  	// set this structure to use external issue tracker
   173  	ExternalTracker *ExternalTracker `json:"external_tracker,omitempty"`
   174  	// either `true` to enable the wiki for this repository or `false` to disable it.
   175  	HasWiki *bool `json:"has_wiki,omitempty"`
   176  	// set this structure to use external wiki instead of internal
   177  	ExternalWiki *ExternalWiki `json:"external_wiki,omitempty"`
   178  	// sets the default branch for this repository.
   179  	DefaultBranch *string `json:"default_branch,omitempty"`
   180  	// either `true` to allow pull requests, or `false` to prevent pull request.
   181  	HasPullRequests *bool `json:"has_pull_requests,omitempty"`
   182  	// either `true` to enable project unit, or `false` to disable them.
   183  	HasProjects *bool `json:"has_projects,omitempty"`
   184  	// `repo` to only allow repo-level projects, `owner` to only allow owner projects, `all` to allow both.
   185  	ProjectsMode *string `json:"projects_mode,omitempty" binding:"In(repo,owner,all)"`
   186  	// either `true` to enable releases unit, or `false` to disable them.
   187  	HasReleases *bool `json:"has_releases,omitempty"`
   188  	// either `true` to enable packages unit, or `false` to disable them.
   189  	HasPackages *bool `json:"has_packages,omitempty"`
   190  	// either `true` to enable actions unit, or `false` to disable them.
   191  	HasActions *bool `json:"has_actions,omitempty"`
   192  	// either `true` to ignore whitespace for conflicts, or `false` to not ignore whitespace.
   193  	IgnoreWhitespaceConflicts *bool `json:"ignore_whitespace_conflicts,omitempty"`
   194  	// either `true` to allow merging pull requests with a merge commit, or `false` to prevent merging pull requests with merge commits.
   195  	AllowMerge *bool `json:"allow_merge_commits,omitempty"`
   196  	// either `true` to allow rebase-merging pull requests, or `false` to prevent rebase-merging.
   197  	AllowRebase *bool `json:"allow_rebase,omitempty"`
   198  	// either `true` to allow rebase with explicit merge commits (--no-ff), or `false` to prevent rebase with explicit merge commits.
   199  	AllowRebaseMerge *bool `json:"allow_rebase_explicit,omitempty"`
   200  	// either `true` to allow squash-merging pull requests, or `false` to prevent squash-merging.
   201  	AllowSquash *bool `json:"allow_squash_merge,omitempty"`
   202  	// either `true` to allow fast-forward-only merging pull requests, or `false` to prevent fast-forward-only merging.
   203  	AllowFastForwardOnly *bool `json:"allow_fast_forward_only_merge,omitempty"`
   204  	// either `true` to allow mark pr as merged manually, or `false` to prevent it.
   205  	AllowManualMerge *bool `json:"allow_manual_merge,omitempty"`
   206  	// either `true` to enable AutodetectManualMerge, or `false` to prevent it. Note: In some special cases, misjudgments can occur.
   207  	AutodetectManualMerge *bool `json:"autodetect_manual_merge,omitempty"`
   208  	// either `true` to allow updating pull request branch by rebase, or `false` to prevent it.
   209  	AllowRebaseUpdate *bool `json:"allow_rebase_update,omitempty"`
   210  	// set to `true` to delete pr branch after merge by default
   211  	DefaultDeleteBranchAfterMerge *bool `json:"default_delete_branch_after_merge,omitempty"`
   212  	// set to a merge style to be used by this repository: "merge", "rebase", "rebase-merge", "squash", or "fast-forward-only".
   213  	DefaultMergeStyle *string `json:"default_merge_style,omitempty"`
   214  	// set to `true` to allow edits from maintainers by default
   215  	DefaultAllowMaintainerEdit *bool `json:"default_allow_maintainer_edit,omitempty"`
   216  	// set to `true` to archive this repository.
   217  	Archived *bool `json:"archived,omitempty"`
   218  	// set to a string like `8h30m0s` to set the mirror interval time
   219  	MirrorInterval *string `json:"mirror_interval,omitempty"`
   220  	// enable prune - remove obsolete remote-tracking references when mirroring
   221  	EnablePrune *bool `json:"enable_prune,omitempty"`
   222  }
   223  
   224  // GenerateRepoOption options when creating repository using a template
   225  // swagger:model
   226  type GenerateRepoOption struct {
   227  	// The organization or person who will own the new repository
   228  	//
   229  	// required: true
   230  	Owner string `json:"owner"`
   231  	// Name of the repository to create
   232  	//
   233  	// required: true
   234  	// unique: true
   235  	Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(100)"`
   236  	// Default branch of the new repository
   237  	DefaultBranch string `json:"default_branch"`
   238  	// Description of the repository to create
   239  	Description string `json:"description" binding:"MaxSize(2048)"`
   240  	// Whether the repository is private
   241  	Private bool `json:"private"`
   242  	// include git content of default branch in template repo
   243  	GitContent bool `json:"git_content"`
   244  	// include topics in template repo
   245  	Topics bool `json:"topics"`
   246  	// include git hooks in template repo
   247  	GitHooks bool `json:"git_hooks"`
   248  	// include webhooks in template repo
   249  	Webhooks bool `json:"webhooks"`
   250  	// include avatar of the template repo
   251  	Avatar bool `json:"avatar"`
   252  	// include labels in template repo
   253  	Labels bool `json:"labels"`
   254  	// include protected branches in template repo
   255  	ProtectedBranch bool `json:"protected_branch"`
   256  }
   257  
   258  // CreateBranchRepoOption options when creating a branch in a repository
   259  // swagger:model
   260  type CreateBranchRepoOption struct {
   261  	// Name of the branch to create
   262  	//
   263  	// required: true
   264  	// unique: true
   265  	BranchName string `json:"new_branch_name" binding:"Required;GitRefName;MaxSize(100)"`
   266  
   267  	// Deprecated: true
   268  	// Name of the old branch to create from
   269  	//
   270  	// unique: true
   271  	OldBranchName string `json:"old_branch_name" binding:"GitRefName;MaxSize(100)"`
   272  
   273  	// Name of the old branch/tag/commit to create from
   274  	//
   275  	// unique: true
   276  	OldRefName string `json:"old_ref_name" binding:"GitRefName;MaxSize(100)"`
   277  }
   278  
   279  // TransferRepoOption options when transfer a repository's ownership
   280  // swagger:model
   281  type TransferRepoOption struct {
   282  	// required: true
   283  	NewOwner string `json:"new_owner"`
   284  	// ID of the team or teams to add to the repository. Teams can only be added to organization-owned repositories.
   285  	TeamIDs *[]int64 `json:"team_ids"`
   286  }
   287  
   288  // GitServiceType represents a git service
   289  type GitServiceType int
   290  
   291  // enumerate all GitServiceType
   292  const (
   293  	NotMigrated      GitServiceType = iota // 0 not migrated from external sites
   294  	PlainGitService                        // 1 plain git service
   295  	GithubService                          // 2 github.com
   296  	GiteaService                           // 3 gitea service
   297  	GitlabService                          // 4 gitlab service
   298  	GogsService                            // 5 gogs service
   299  	OneDevService                          // 6 onedev service
   300  	GitBucketService                       // 7 gitbucket service
   301  	CodebaseService                        // 8 codebase service
   302  )
   303  
   304  // Name represents the service type's name
   305  // WARNNING: the name have to be equal to that on goth's library
   306  func (gt GitServiceType) Name() string {
   307  	return strings.ToLower(gt.Title())
   308  }
   309  
   310  // Title represents the service type's proper title
   311  func (gt GitServiceType) Title() string {
   312  	switch gt {
   313  	case GithubService:
   314  		return "GitHub"
   315  	case GiteaService:
   316  		return "Gitea"
   317  	case GitlabService:
   318  		return "GitLab"
   319  	case GogsService:
   320  		return "Gogs"
   321  	case OneDevService:
   322  		return "OneDev"
   323  	case GitBucketService:
   324  		return "GitBucket"
   325  	case CodebaseService:
   326  		return "Codebase"
   327  	case PlainGitService:
   328  		return "Git"
   329  	}
   330  	return ""
   331  }
   332  
   333  // MigrateRepoOptions options for migrating repository's
   334  // this is used to interact with api v1
   335  type MigrateRepoOptions struct {
   336  	// required: true
   337  	CloneAddr string `json:"clone_addr" binding:"Required"`
   338  	// deprecated (only for backwards compatibility)
   339  	RepoOwnerID int64 `json:"uid"`
   340  	// Name of User or Organisation who will own Repo after migration
   341  	RepoOwner string `json:"repo_owner"`
   342  	// required: true
   343  	RepoName string `json:"repo_name" binding:"Required;AlphaDashDot;MaxSize(100)"`
   344  
   345  	// enum: git,github,gitea,gitlab,gogs,onedev,gitbucket,codebase
   346  	Service      string `json:"service"`
   347  	AuthUsername string `json:"auth_username"`
   348  	AuthPassword string `json:"auth_password"`
   349  	AuthToken    string `json:"auth_token"`
   350  
   351  	Mirror         bool   `json:"mirror"`
   352  	LFS            bool   `json:"lfs"`
   353  	LFSEndpoint    string `json:"lfs_endpoint"`
   354  	Private        bool   `json:"private"`
   355  	Description    string `json:"description" binding:"MaxSize(2048)"`
   356  	Wiki           bool   `json:"wiki"`
   357  	Milestones     bool   `json:"milestones"`
   358  	Labels         bool   `json:"labels"`
   359  	Issues         bool   `json:"issues"`
   360  	PullRequests   bool   `json:"pull_requests"`
   361  	Releases       bool   `json:"releases"`
   362  	MirrorInterval string `json:"mirror_interval"`
   363  }
   364  
   365  // TokenAuth represents whether a service type supports token-based auth
   366  func (gt GitServiceType) TokenAuth() bool {
   367  	switch gt {
   368  	case GithubService, GiteaService, GitlabService:
   369  		return true
   370  	}
   371  	return false
   372  }
   373  
   374  // SupportedFullGitService represents all git services supported to migrate issues/labels/prs and etc.
   375  // TODO: add to this list after new git service added
   376  var SupportedFullGitService = []GitServiceType{
   377  	GithubService,
   378  	GitlabService,
   379  	GiteaService,
   380  	GogsService,
   381  	OneDevService,
   382  	GitBucketService,
   383  	CodebaseService,
   384  }
   385  
   386  // RepoTransfer represents a pending repo transfer
   387  type RepoTransfer struct {
   388  	Doer      *User   `json:"doer"`
   389  	Recipient *User   `json:"recipient"`
   390  	Teams     []*Team `json:"teams"`
   391  }
   392  
   393  // NewIssuePinsAllowed represents an API response that says if new Issue Pins are allowed
   394  type NewIssuePinsAllowed struct {
   395  	Issues       bool `json:"issues"`
   396  	PullRequests bool `json:"pull_requests"`
   397  }
   398  
   399  // UpdateRepoAvatarUserOption options when updating the repo avatar
   400  type UpdateRepoAvatarOption struct {
   401  	// image must be base64 encoded
   402  	Image string `json:"image" binding:"Required"`
   403  }