Skip to content

Commit

Permalink
Add support for the latest release endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
janos committed Nov 30, 2022
1 parent 8d8e035 commit 7a82ea7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ This client implements all NewReleases API features.
- Delete project
- List projects releases
- Get project release
- Get latest non-excluded project release
- Get project release note
- Get tracked providers
- Get added Slack Channels
Expand Down
17 changes: 17 additions & 0 deletions releases.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,23 @@ func (s *ReleasesService) get(ctx context.Context, projectRef, version string) (
return release, err
}

// GetLatestByProjectID returns the latest non-excluded version release for a project referenced by
// its ID.
func (s *ReleasesService) GetLatestByProjectID(ctx context.Context, projectID string) (release *Release, err error) {
return s.getLatest(ctx, projectID)
}

// GetLatestByProjectName returns the latest non-excluded version release for a project referenced
// by its provider and name.
func (s *ReleasesService) GetLatestByProjectName(ctx context.Context, provider, projectName string) (release *Release, err error) {
return s.getLatest(ctx, provider+"/"+projectName)
}

func (s *ReleasesService) getLatest(ctx context.Context, projectRef string) (release *Release, err error) {
err = s.client.request(ctx, http.MethodGet, "v1/projects/"+projectRef+"/latest-release", nil, &release)
return release, err
}

// ReleaseNote holds information about an additional note for a specific
// version.
type ReleaseNote struct {
Expand Down
28 changes: 28 additions & 0 deletions releases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,34 @@ func TestReleasesService_GetByProjectName(t *testing.T) {
assertEqual(t, "", got, releasesServiceGetWant)
}

func TestReleasesService_GetLatestByProjectID(t *testing.T) {
client, mux, _, teardown := newClient(t, "")
defer teardown()

mux.HandleFunc("/v1/projects/8wdvh4w9bhsvzclz4ynaqpcpvg/latest-release", requireMethod("GET", newStaticHandler(releasesServiceGet)))

got, err := client.Releases.GetLatestByProjectID(context.Background(), "8wdvh4w9bhsvzclz4ynaqpcpvg")
if err != nil {
t.Fatal(err)
}

assertEqual(t, "", got, releasesServiceGetWant)
}

func TestReleasesService_GetLatestByProjectName(t *testing.T) {
client, mux, _, teardown := newClient(t, "")
defer teardown()

mux.HandleFunc("/v1/projects/github/nodejs/node/latest-release", requireMethod("GET", newStaticHandler(releasesServiceGet)))

got, err := client.Releases.GetLatestByProjectName(context.Background(), "github", "nodejs/node")
if err != nil {
t.Fatal(err)
}

assertEqual(t, "", got, releasesServiceGetWant)
}

var (
releasesServiceGet = `
{
Expand Down

0 comments on commit 7a82ea7

Please sign in to comment.