From fa29939f50bbb2b1c114bab211272492b549bbe6 Mon Sep 17 00:00:00 2001 From: Riccardo De Agostini Date: Fri, 7 Oct 2022 20:06:53 +0200 Subject: [PATCH] Use correct methods and URL to generate release notes (#2592) --- Octokit.Tests/Clients/ReleasesClientTests.cs | 4 ++-- Octokit/Clients/ReleasesClient.cs | 8 ++++---- Octokit/Helpers/ApiUrls.cs | 21 ++++++++++++++++++++ docs/releases.md | 14 +++++++++---- 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/Octokit.Tests/Clients/ReleasesClientTests.cs b/Octokit.Tests/Clients/ReleasesClientTests.cs index 903d8115e9..151734580a 100644 --- a/Octokit.Tests/Clients/ReleasesClientTests.cs +++ b/Octokit.Tests/Clients/ReleasesClientTests.cs @@ -31,7 +31,7 @@ public async Task RequestsCorrectUrl() await releasesClient.GenerateReleaseNotes("fake", "repo", data); - client.Received().Post(Arg.Is(u => u.ToString() == "repos/fake/repo/releases"), + client.Received().Post(Arg.Is(u => u.ToString() == "repos/fake/repo/releases/generate-notes"), data, "application/vnd.github.v3"); } @@ -45,7 +45,7 @@ public async Task RequestsCorrectUrlWithRepositoryId() await releasesClient.GenerateReleaseNotes(1, data); - client.Received().Post(Arg.Is(u => u.ToString() == "repositories/1/releases"), + client.Received().Post(Arg.Is(u => u.ToString() == "repositories/1/releases/generate-notes"), data, "application/vnd.github.v3"); } diff --git a/Octokit/Clients/ReleasesClient.cs b/Octokit/Clients/ReleasesClient.cs index 435bd36882..0ab33084ec 100644 --- a/Octokit/Clients/ReleasesClient.cs +++ b/Octokit/Clients/ReleasesClient.cs @@ -30,14 +30,14 @@ public ReleasesClient(IApiConnection apiConnection) : base(apiConnection) /// The repository's name /// The request for generating release notes /// Thrown when a general API error occurs. - [ManualRoute("GET", "/repos/{owner}/{repo}/releases")] + [ManualRoute("POST", "/repos/{owner}/{repo}/releases/generate-notes")] public Task GenerateReleaseNotes(string owner, string name, GenerateReleaseNotesRequest data) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(data, nameof(data)); - var endpoint = ApiUrls.Releases(owner, name); + var endpoint = ApiUrls.ReleasesGenerateNotes(owner, name); return ApiConnection.Post(endpoint, data, AcceptHeaders.StableVersion); } @@ -50,12 +50,12 @@ public Task GenerateReleaseNotes(string owner, string nam /// The Id of the repository /// The request for generating release notes /// Thrown when a general API error occurs. - [ManualRoute("GET", "/repos/{owner}/{repo}/releases")] + [ManualRoute("POST", "/repositories/{id}/releases/generate-notes")] public Task GenerateReleaseNotes(long repositoryId, GenerateReleaseNotesRequest data) { Ensure.ArgumentNotNull(data, nameof(data)); - var endpoint = ApiUrls.Releases(repositoryId); + var endpoint = ApiUrls.ReleasesGenerateNotes(repositoryId); return ApiConnection.Post(endpoint, data, AcceptHeaders.StableVersion); } diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index b8a7cbe88f..e24de63a42 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -191,6 +191,17 @@ public static Uri Releases(string owner, string name) return "repos/{0}/{1}/releases".FormatUri(owner, name); } + /// + /// Returns the that generates release notes for the specified repository. + /// + /// The owner of the repository + /// The name of the repository + /// The that generates release notes for the specified repository. + public static Uri ReleasesGenerateNotes(string owner, string name) + { + return "repos/{0}/{1}/releases/generate-notes".FormatUri(owner, name); + } + /// /// Returns the that returns a single release for the specified repository /// @@ -3441,6 +3452,16 @@ public static Uri Releases(long repositoryId) return "repositories/{0}/releases".FormatUri(repositoryId); } + /// + /// Returns the that generates release notes for the specified repository. + /// + /// The Id of the repository + /// The that generates release notes for the specified repository. + public static Uri ReleasesGenerateNotes(long repositoryId) + { + return "repositories/{0}/releases/generate-notes".FormatUri(repositoryId); + } + /// /// Returns the that returns a single release for the specified repository /// diff --git a/docs/releases.md b/docs/releases.md index 3f9e9582c3..e863e950e0 100644 --- a/docs/releases.md +++ b/docs/releases.md @@ -30,19 +30,25 @@ Console.WriteLine("Created release id {0}", result.Id); Note that the `Draft` flag is used to indicate when a release should be published to the world, whereas the `PreRelease` flag is used to indicate whether a release is unofficial or preview release. -#### Generate release notes +### Generate release notes -Additionally, you can ask GitHub to generate a name and body before creating a new release. +GitHub can generate a name and body for a new release [automatically](https://github.blog/2021-10-04-beta-github-releases-improving-release-experience/#introducing-auto-generated-release-notes), based upon merged pull requests. +[This is an example](https://github.com/MylesBorins/release-notes-test/releases/tag/v2.0.0) of automatically generated text. ```csharp -var generationRequest = new GenerateReleaseNotesRequest("v2.0.0"); +var newTag = "v1.5.7"; +var generationRequest = new GenerateReleaseNotesRequest(newTag); +generationRequest.TargetCommitish = "main"; // Optional, can be a branch, tag, or SHA; defaults to the main branch. +generationRequest.PreviousTagName = "v1.5.6"; // Optional; default is automagically determined, based on existing tags. var releaseNotes = await client.Repository.Release.GenerateReleaseNotes("octokit", "octokit.net", generationRequest); -var newRelease = new NewRelease("v1.0.0"); +var newRelease = new NewRelease(newTag); // Use the same tag as before, because it now appears in generated text. newRelease.Name = releaseNotes.Name; newRelease.Body = releaseNotes.Body; ``` +This feature can be customized at the repository level, by following [these instructions](https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes#configuring-automatically-generated-release-notes). + ### Update Once the release is ready for the public, you can apply an update to the release: