Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

feat(snippets): Add files array to snippet creation #1375

Merged
merged 1 commit into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions project_snippets.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ type CreateProjectSnippetOptions struct {
Description *string `url:"description,omitempty" json:"description,omitempty"`
Content *string `url:"content,omitempty" json:"content,omitempty"`
Visibility *VisibilityValue `url:"visibility,omitempty" json:"visibility,omitempty"`
Files *[]*SnippetFile `url:"files,omitempty" json:"files,omitempty"`
}

// CreateSnippet creates a new project snippet. The user must have permission
Expand Down
17 changes: 16 additions & 1 deletion project_snippets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,13 @@ func TestProjectSnippetsService_CreateSnippet(t *testing.T) {
},
"project_id": 1,
"web_url": "http://example.com/example/example/snippets/1",
"raw_url": "http://example.com/example/example/snippets/1/raw"
"raw_url": "http://example.com/example/example/snippets/1/raw",
"files": [
{
"path": "add.rb",
"raw_url": "http://example.com/example/example/-/snippets/1/raw/main/add.rb"
}
]
}
`)
})
Expand All @@ -198,6 +204,15 @@ func TestProjectSnippetsService_CreateSnippet(t *testing.T) {
},
WebURL: "http://example.com/example/example/snippets/1",
RawURL: "http://example.com/example/example/snippets/1/raw",
Files: []struct {
Path string `json:"path"`
RawURL string `json:"raw_url"`
}{
{
Path: "add.rb",
RawURL: "http://example.com/example/example/-/snippets/1/raw/main/add.rb",
},
},
}

s, resp, err := client.ProjectSnippets.CreateSnippet(1, nil, nil, nil)
Expand Down
14 changes: 14 additions & 0 deletions snippets.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ type Snippet struct {
CreatedAt *time.Time `json:"created_at"`
WebURL string `json:"web_url"`
RawURL string `json:"raw_url"`
Files []struct {
Path string `json:"path"`
RawURL string `json:"raw_url"`
} `json:"files"`
}

func (s Snippet) String() string {
Expand Down Expand Up @@ -101,6 +105,15 @@ func (s *SnippetsService) GetSnippet(snippet int, options ...RequestOptionFunc)
return ps, resp, err
}

// SnippetFile represents the object that is used to create snippets
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/snippets.html#create-new-snippet
type SnippetFile struct {
FilePath *string `url:"file_path,omitempty" json:"file_path,omitempty"`
Content *string `url:"content,omitempty" json:"content,omitempty"`
}

// CreateSnippetOptions represents the available CreateSnippet() options.
//
// GitLab API docs:
Expand All @@ -111,6 +124,7 @@ type CreateSnippetOptions struct {
Description *string `url:"description,omitempty" json:"description,omitempty"`
Content *string `url:"content,omitempty" json:"content,omitempty"`
Visibility *VisibilityValue `url:"visibility,omitempty" json:"visibility,omitempty"`
Files *[]*SnippetFile `url:"files,omitempty" json:"files,omitempty"`
}

// CreateSnippet creates a new snippet. The user must have permission
Expand Down