From 6ec8874f43a60dd1b155e237e4fe31a82e0217e0 Mon Sep 17 00:00:00 2001 From: Lisa Ugray Date: Fri, 22 Sep 2023 13:39:29 -0400 Subject: [PATCH] Add a function to access the latest release endpoint --- releases.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/releases.go b/releases.go index 86308c5a9..3d6a89772 100644 --- a/releases.go +++ b/releases.go @@ -133,6 +133,31 @@ func (s *ReleasesService) GetRelease(pid interface{}, tagName string, options .. return r, resp, nil } +// GetLatestRelease returns the latest release for the project. +// +// GitLab API docs: +// https://docs.gitlab.com/ee/api/releases/#get-the-latest-release +func (s *ReleasesService) GetLatestRelease(pid interface{}, options ...RequestOptionFunc) (*Release, *Response, error) { + project, err := parseID(pid) + if err != nil { + return nil, nil, err + } + u := fmt.Sprintf("projects/%s/releases/permalink/latest", PathEscape(project)) + + req, err := s.client.NewRequest(http.MethodGet, u, nil, options) + if err != nil { + return nil, nil, err + } + + r := new(Release) + resp, err := s.client.Do(req, r) + if err != nil { + return nil, resp, err + } + + return r, resp, err +} + // CreateReleaseOptions represents CreateRelease() options. // // GitLab API docs: