From e2aa4603b3b0123f84dbb2373f99f03a1996c9a7 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 9 Nov 2020 01:44:56 +0100 Subject: [PATCH 1/4] Add TrustModel enum --- gitea/repo.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/gitea/repo.go b/gitea/repo.go index c432724..4073129 100644 --- a/gitea/repo.go +++ b/gitea/repo.go @@ -73,6 +73,20 @@ const ( RepoTypeMirror RepoType = "mirror" ) +// TrustModel represent how git signatures are handled in a repository +type TrustModel string + +const ( + // TrustModelDefault use TM set by global config + TrustModelDefault TrustModel = "default" + // TrustModelCollaborator gpg signature has to be owned by a repo collaborator + TrustModelCollaborator TrustModel = "collaborator" + // TrustModelCommitter gpg signature has to match committer + TrustModelCommitter TrustModel = "committer" + // TrustModelCollaboratorCommitter gpg signature has to match committer and owned by a repo collaborator + TrustModelCollaboratorCommitter TrustModel = "collaboratorcommitter" +) + // ListReposOptions options for listing repositories type ListReposOptions struct { ListOptions -- 2.40.1 From 212f876656d638afe6adf7c6aed793e9df58d7e5 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 9 Nov 2020 01:45:25 +0100 Subject: [PATCH 2/4] update CreateRepoOption struct --- gitea/repo.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gitea/repo.go b/gitea/repo.go index 4073129..32d9563 100644 --- a/gitea/repo.go +++ b/gitea/repo.go @@ -263,6 +263,8 @@ type CreateRepoOption struct { IssueLabels string `json:"issue_labels"` // Whether the repository should be auto-intialized? AutoInit bool `json:"auto_init"` + // Whether the repository is template + Template bool `json:"template"` // Gitignores to use Gitignores string `json:"gitignores"` // License to use @@ -271,6 +273,8 @@ type CreateRepoOption struct { Readme string `json:"readme"` // DefaultBranch of the repository (used when initializes and in template) DefaultBranch string `json:"default_branch"` + // TrustModel of the repository + TrustModel TrustModel `json:"trust_model"` } // Validate the CreateRepoOption struct -- 2.40.1 From fc2517c76ec0b60908dfaf519c286605144a92ea Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 9 Nov 2020 01:45:55 +0100 Subject: [PATCH 3/4] extend Validate() for CreateRepoOption --- gitea/repo.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/gitea/repo.go b/gitea/repo.go index 32d9563..9aa1378 100644 --- a/gitea/repo.go +++ b/gitea/repo.go @@ -278,16 +278,30 @@ type CreateRepoOption struct { } // Validate the CreateRepoOption struct -func (opt CreateRepoOption) Validate() error { +func (opt CreateRepoOption) Validate(c *Client) error { if len(strings.TrimSpace(opt.Name)) == 0 { return fmt.Errorf("name is empty") } + if len(opt.Name) > 100 { + return fmt.Errorf("name has more than 100 chars") + } + if len(opt.Description) > 255 { + return fmt.Errorf("name has more than 255 chars") + } + if len(opt.DefaultBranch) > 100 { + return fmt.Errorf("name has more than 100 chars") + } + if len(opt.TrustModel) != 0 { + if err := c.CheckServerVersionConstraint(">=1.13.0"); err != nil { + return err + } + } return nil } // CreateRepo creates a repository for authenticated user. func (c *Client) CreateRepo(opt CreateRepoOption) (*Repository, *Response, error) { - if err := opt.Validate(); err != nil { + if err := opt.Validate(c); err != nil { return nil, nil, err } body, err := json.Marshal(&opt) @@ -301,7 +315,7 @@ func (c *Client) CreateRepo(opt CreateRepoOption) (*Repository, *Response, error // CreateOrgRepo creates an organization repository for authenticated user. func (c *Client) CreateOrgRepo(org string, opt CreateRepoOption) (*Repository, *Response, error) { - if err := opt.Validate(); err != nil { + if err := opt.Validate(c); err != nil { return nil, nil, err } body, err := json.Marshal(&opt) -- 2.40.1 From aba3a7611c3065f6d0807a8affa0827e1baca9de Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 9 Nov 2020 02:13:42 +0100 Subject: [PATCH 4/4] update test data --- gitea/repo_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitea/repo_test.go b/gitea/repo_test.go index c2a1f72..0131505 100644 --- a/gitea/repo_test.go +++ b/gitea/repo_test.go @@ -66,7 +66,7 @@ func TestRepoMigrateAndLanguages(t *testing.T) { assert.NoError(t, err) assert.Len(t, lang, 2) assert.True(t, 217441 < lang["Go"]) - assert.EqualValues(t, 3578, lang["Makefile"]) + assert.EqualValues(t, 3614, lang["Makefile"]) } func TestSearchRepo(t *testing.T) { -- 2.40.1