feat(snippets): add the four fields the snippet entity sends to Snippet

What does this MR do?

The Snippet struct decodes both API::Entities::PersonalSnippet and API::Entities::ProjectSnippet, which are the same entity chain: Snippet < BasicSnippet. Four of the fields that chain exposes are not on the struct.

Read from gitlab-org/gitlab at commit e5d23f6d, the tip of master when this was written:

Field Exposed at Sent
ssh_url_to_repo basic_snippet.rb:24 once the snippet's repository exists, if: ->(snippet) { snippet.repository_exists? }
http_url_to_repo basic_snippet.rb:27 the same condition
imported snippet.rb:24 always
imported_from snippet.rb:25 always

The two clone URLs are placed after RawURL and the two import fields after Files, which is where the entity renders them, and no existing field moves.

The two clone URLs are largely missing from GitLab's own documentation as well, which I checked before writing this: on doc/api/snippets.md they are in three of the five response attribute tables and in two of the eight example snippets, and on doc/api/project_snippets.md they are in none of the four tables and none of the four examples. imported and imported_from are documented everywhere except the "List all public snippets" section. A documentation merge request for that goes with this one and I will link it here.

I found this while developing an MCP server on top of this library, https://github.com/jmrplens/gitlab-mcp-server, which currently reads all four keys out of the raw response beside the SDK decode.

Is this a breaking change?

No. Four additive fields on one response struct. Nothing is renamed, retyped, removed or moved.

ImportedFrom is worth the same sentence as on the events struct: GitLab sends the string "none" for a snippet that was not imported, not an empty string.

How was this tested?

TestProjectSnippetsService_GetSnippet carries all four keys in its fixture and asserts each decoded value, with imported: true and a real imported_from.

TestSnippetsService_GetSnippet does the same for a personal snippet and asserts the other side of the import pair, imported: false with imported_from: "none".

The remaining snippet tests keep fixtures without any of the four, so the case where a snippet has no repository yet still decodes to two empty strings.

go build ./..., go test . and golangci-lint run ./... all pass locally, and gofumpt -l reports nothing on the changed files.

Related to #2300

Merge request reports

Loading
Loading