Skip to content

Commit

Permalink
Use correct methods and URL to generate release notes (octokit#2592)
Browse files Browse the repository at this point in the history
  • Loading branch information
rdeago authored Oct 7, 2022
1 parent 971fa50 commit fa29939
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Octokit.Tests/Clients/ReleasesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public async Task RequestsCorrectUrl()

await releasesClient.GenerateReleaseNotes("fake", "repo", data);

client.Received().Post<GeneratedReleaseNotes>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/releases"),
client.Received().Post<GeneratedReleaseNotes>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/releases/generate-notes"),
data,
"application/vnd.github.v3");
}
Expand All @@ -45,7 +45,7 @@ public async Task RequestsCorrectUrlWithRepositoryId()

await releasesClient.GenerateReleaseNotes(1, data);

client.Received().Post<GeneratedReleaseNotes>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/releases"),
client.Received().Post<GeneratedReleaseNotes>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/releases/generate-notes"),
data,
"application/vnd.github.v3");
}
Expand Down
8 changes: 4 additions & 4 deletions Octokit/Clients/ReleasesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ public ReleasesClient(IApiConnection apiConnection) : base(apiConnection)
/// <param name="name">The repository's name</param>
/// <param name="data">The request for generating release notes</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
[ManualRoute("GET", "/repos/{owner}/{repo}/releases")]
[ManualRoute("POST", "/repos/{owner}/{repo}/releases/generate-notes")]
public Task<GeneratedReleaseNotes> 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<GeneratedReleaseNotes>(endpoint, data, AcceptHeaders.StableVersion);
}

Expand All @@ -50,12 +50,12 @@ public Task<GeneratedReleaseNotes> GenerateReleaseNotes(string owner, string nam
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="data">The request for generating release notes</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
[ManualRoute("GET", "/repos/{owner}/{repo}/releases")]
[ManualRoute("POST", "/repositories/{id}/releases/generate-notes")]
public Task<GeneratedReleaseNotes> GenerateReleaseNotes(long repositoryId, GenerateReleaseNotesRequest data)
{
Ensure.ArgumentNotNull(data, nameof(data));

var endpoint = ApiUrls.Releases(repositoryId);
var endpoint = ApiUrls.ReleasesGenerateNotes(repositoryId);
return ApiConnection.Post<GeneratedReleaseNotes>(endpoint, data, AcceptHeaders.StableVersion);
}

Expand Down
21 changes: 21 additions & 0 deletions Octokit/Helpers/ApiUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,17 @@ public static Uri Releases(string owner, string name)
return "repos/{0}/{1}/releases".FormatUri(owner, name);
}

/// <summary>
/// Returns the <see cref="Uri"/> that generates release notes for the specified repository.
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns>The <see cref="Uri"/> that generates release notes for the specified repository.</returns>
public static Uri ReleasesGenerateNotes(string owner, string name)
{
return "repos/{0}/{1}/releases/generate-notes".FormatUri(owner, name);
}

/// <summary>
/// Returns the <see cref="Uri"/> that returns a single release for the specified repository
/// </summary>
Expand Down Expand Up @@ -3441,6 +3452,16 @@ public static Uri Releases(long repositoryId)
return "repositories/{0}/releases".FormatUri(repositoryId);
}

/// <summary>
/// Returns the <see cref="Uri"/> that generates release notes for the specified repository.
/// </summary>
/// <param name="repositoryId">The Id of the repository</param>
/// <returns>The <see cref="Uri"/> that generates release notes for the specified repository.</returns>
public static Uri ReleasesGenerateNotes(long repositoryId)
{
return "repositories/{0}/releases/generate-notes".FormatUri(repositoryId);
}

/// <summary>
/// Returns the <see cref="Uri"/> that returns a single release for the specified repository
/// </summary>
Expand Down
14 changes: 10 additions & 4 deletions docs/releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit fa29939

Please sign in to comment.