-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Automatically assign Pull Requests to GitHub Milestones
When building a Pull Request in CI, automatically assign the Pull Request being built to a GitHub milestone for the current version. The name of the Milestone is determined from the version being built using the format 'v<MAJOR>.<MINOR>'. Pull-Request: #26
- Loading branch information
Showing
4 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
Submodule Cake.GitHub
updated
14 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Cake.Core.Diagnostics; | ||
using Cake.Frosting; | ||
using Cake.GitHub; | ||
using Cake.GitVersioning; | ||
|
||
namespace Grynwald.SharedBuild.Tasks | ||
{ | ||
[TaskName(TaskNames.SetGitHubMilestone)] | ||
public class SetGitHubMilestoneTask : AsyncFrostingTask<IBuildContext> | ||
{ | ||
public override bool ShouldRun(IBuildContext context) | ||
{ | ||
return context.IsRunningInCI && context.GitHub.PullRequest.IsPullRequest; | ||
} | ||
|
||
|
||
public override async Task RunAsync(IBuildContext context) | ||
{ | ||
var versionInfo = context.GitVersioningGetVersion(context.RootDirectory.FullPath); | ||
var milestoneTitle = $"v{versionInfo.Version.Major}.{versionInfo.Version.Minor}"; | ||
|
||
context.Log.Information($"Assinging Pull Request {context.GitHub.PullRequest.Number} to milestone {milestoneTitle}"); | ||
|
||
if (context.GitHub.TryGetAccessToken() is not string accessToken) | ||
{ | ||
throw new Exception("No GitHub access token specified. Cannot set Milestone for Pull Request"); | ||
} | ||
|
||
await context.GitHubSetMilestoneAsync( | ||
userName: null, | ||
accessToken, | ||
context.GitHub.RepositoryOwner, | ||
context.GitHub.RepositoryName, | ||
context.GitHub.PullRequest.Number, | ||
milestoneTitle, | ||
new GitHubSetMilestoneSettings() | ||
{ | ||
Overwrite = true, | ||
CreateMilestone = true | ||
}); | ||
} | ||
|
||
} | ||
} |