Skip to content

Commit

Permalink
Added IPullRequest.Issues (#9) (#10)
Browse files Browse the repository at this point in the history
Promoted `IPullRequest.DeleteLocalOnSuccess` to a parameter
Promoted `IPullRequest.Draft` to a parameter

Added keyword computation to link a PR to issues that are resolved (#9)
  • Loading branch information
candoumbe committed Jan 20, 2023
1 parent 2b4877f commit bbb4949
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
15 changes: 15 additions & 0 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@
"type": "boolean",
"description": "Indicates to continue a previously failed build attempt"
},
"DeleteLocalOnSuccess": {
"type": "boolean",
"description": "Should the local branch be deleted after the pull request was created successfully ?"
},
"Description": {
"type": "string",
"description": "Description of the pull request"
},
"Draft": {
"type": "boolean",
"description": "Indicates to open the pull request as 'draft'"
},
"GitHubToken": {
"type": "string",
"description": "Token used to create a new release in GitHub",
Expand Down Expand Up @@ -56,6 +64,13 @@
"type": "boolean",
"description": "Ignore unreachable sources during Restore"
},
"Issues": {
"type": "array",
"description": "Issues that will be closed once the pull request is merged",
"items": {
"type": "string"
}
},
"Major": {
"type": "boolean",
"description": "Hint to create a major release"
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Moved `ICreateGitHubRelease` to `Candoumbe.Pipelines.Components.GitHub` namespace

### New features

- Added `IPullRequest.Issues` parameter which allows to specify issues a pull request fixes ([#9](https://github.com/candoumbe/pipelines/issues/9))
- Added execution of `IPublish.Publish` target on `integration` workflow
- Added `IHaveReport` component that can be used by pipelines that output reports of any kind (code coverage, performance tests, ...)
- Added `IUnitTest.UnitTestsResultsDirectory` which defines where to output unit test result files
- Added `IMutationTest.MutationTestResultsDirectory` which defines where to output mutation test result files
- Added `IBenchmark.BenchmarkTestResultsDirectory` which defines where to output benchmarks test result files
- Added `IPullRequest` component which extends `IGitFlow` and create pull requests instead or merging back to `develop` (respectiveley `main`) when finishing a feature / coldfix (resp. release / hotfix) branch.
- Added `IHaveGitHubRepository` which extends `IHaveGitRepository` and specific properties related to GitHub repositories.
- Promoted `IPullRequest.DeleteLocalOnSuccess` as parameter
- Promoted `IPullRequest.Draft` as parameter

### Fixes

Expand Down
33 changes: 26 additions & 7 deletions src/Candoumbe.Pipelines/Components/GitHub/IPullRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
using Octokit;

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;

using static Nuke.Common.Tools.Git.GitTasks;
Expand Down Expand Up @@ -46,7 +49,8 @@ public interface IPullRequest : IGitFlow, IHaveGitHubRepository
/// <summary>
/// Should the local branch be deleted after the pull request was created successfully ?
/// </summary>
public bool DeleteLocalOnSuccess => false;
[Parameter("Should the local branch be deleted after the pull request was created successfully ?")]
bool DeleteLocalOnSuccess => false;

/// <summary>
/// Defines, when set to <see langword="true"/>, to open the pull request as draft.
Expand All @@ -57,12 +61,16 @@ public interface IPullRequest : IGitFlow, IHaveGitHubRepository
/// <summary>
/// The issue ID for witch pull request will be created.
/// </summary>
[Parameter("The issue ID for witch pull request will be created.")]
uint? Issue => null;
[Parameter("Issues that will be closed once the pull request is merged.")]
uint[] Issues => Array.Empty<uint>();

///<inheritdoc/>
async ValueTask IGitFlow.FinishFeature()
{
string linkToIssueKeyWord = Issues.AtLeastOnce()
? string.Join(',', Issues.Select(issueNumber => $"Resolves #{issueNumber}").ToArray())
: null;

// Push to the remote branch
GitPushToRemote();

Expand All @@ -87,13 +95,17 @@ async ValueTask IGitFlow.FinishFeature()
NewPullRequest newPullRequest = new(title, branchName, DevelopBranch)
{
Draft = Draft,
Body = Description
Body = linkToIssueKeyWord is not null
? $"{Description}{Environment.NewLine}{Environment.NewLine}{linkToIssueKeyWord}"
: Description
};

PullRequest pullRequest = await gitHubClient.PullRequest.Create(owner, repositoryName, newPullRequest);

Information("PR {PullRequestUrl} created successfully", pullRequest.HtmlUrl);
DeleteLocalBranchIf(DeleteLocalOnSuccess, branchName, switchToBranchName: DevelopBranch);
Information("PR {PullRequestUrl} created successfully", pullRequest.HtmlUrl);

Process.Start(pullRequest.HtmlUrl);
}
}

Expand Down Expand Up @@ -140,8 +152,15 @@ async ValueTask IGitFlow.FinishReleaseOrHotfix()
{
Credentials = new Credentials(token)
};
NewPullRequest newPullRequest = new(Title, GitRepository.Branch, MainBranchName);

NewPullRequest newPullRequest = new(Title, GitRepository.Branch, MainBranchName)
{
Draft = Draft,
Body = Issues.AtLeastOnce() switch
{
true => $"{Description}{Environment.NewLine}{Environment.NewLine}",
_ => Description
}
};
PullRequest pullRequest = await gitHubClient.PullRequest.Create(GitRepository.GetGitHubOwner(), repositoryName, newPullRequest);

Information("PR {PullRequestUrl} created successfully", pullRequest.HtmlUrl);
Expand Down

0 comments on commit bbb4949

Please sign in to comment.