Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use correct methods and URL to generate release notes #2592

Merged
merged 4 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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