Skip to content

Commit

Permalink
Allow to have overall status and status for every issue provider repo…
Browse files Browse the repository at this point in the history
…rted to pull request (#287)
  • Loading branch information
pascalberger authored Aug 24, 2022
1 parent 9f3eb99 commit 4bb7299
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,16 @@ public interface IIssuesParametersPullRequestSystem
Dictionary<string, IProviderIssueLimits> ProviderIssueLimits { get; }

/// <summary>
/// Gets or sets a value indicating whether a status on the pull request should be set.
/// Gets or sets a value indicating whether a status on the pull request should be set if there are any issues found.
/// The status is succeeded if there are no issues and fails as soon as issues from any issue provider or run have been found.
/// Use <see cref="ShouldSetSeparatePullRequestStatusForEachIssueProviderAndRun"/> to report additional status for issues of every issue provider and run.
/// Default value is <c>true</c>.
/// </summary>
bool ShouldSetPullRequestStatus { get; set; }

/// <summary>
/// Gets or sets a value indicating whether a separate status should be set for issues of every issue provider and run.
/// Use <see cref="ShouldSetPullRequestStatus"/> to report status across all issue providers and runs.
/// Default value is <c>false</c>.
/// </summary>
bool ShouldSetSeparatePullRequestStatusForEachIssueProviderAndRun { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ public override void SetPullRequestIssuesState(IIssuesContext context)
return;
}

// Set status across all issues
if (context.Parameters.PullRequestSystem.ShouldSetPullRequestStatus)
{
SetPullRequestStatus(
context,
context.State.Issues,
null);
}

// Set status for individual issue providers
if (context.Parameters.PullRequestSystem.ShouldSetSeparatePullRequestStatusForEachIssueProviderAndRun)
{
foreach (var providerGroup in context.State.Issues.GroupBy(x => x.ProviderType))
Expand All @@ -65,13 +75,6 @@ public override void SetPullRequestIssuesState(IIssuesContext context)
}
}
}
else
{
SetPullRequestStatus(
context,
context.State.Issues,
null);
}
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public override bool ShouldRun(IIssuesContext context)

return
!context.BuildSystem().IsLocalBuild &&
context.Parameters.PullRequestSystem.ShouldSetPullRequestStatus &&
(context.Parameters.PullRequestSystem.ShouldSetPullRequestStatus ||
context.Parameters.PullRequestSystem.ShouldSetSeparatePullRequestStatusForEachIssueProviderAndRun) &&
context.State.BuildServer != null && context.State.BuildServer.DetermineIfPullRequest(context);
}

Expand Down
4 changes: 3 additions & 1 deletion Cake.Issues.Recipe/Content/build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ IssuesBuildTasks.ReportIssuesToPullRequestTask = Task("Report-IssuesToPullReques
IssuesBuildTasks.SetPullRequestIssuesStateTask = Task("Set-PullRequestIssuesState")
.Description("Set pull request status.")
.WithCriteria(() => !BuildSystem.IsLocalBuild, "Not running on build server")
.WithCriteria(() => IssuesParameters.PullRequestSystem.ShouldSetPullRequestStatus, "Setting of pull request status is disabled")
.WithCriteria(() =>
IssuesParameters.PullRequestSystem.ShouldSetPullRequestStatus || IssuesParameters.PullRequestSystem.ShouldSetSeparatePullRequestStatusForEachIssueProviderAndRun,
"Setting of pull request status is disabled")
.WithCriteria<IssuesData>((context, data) => data.BuildServer != null ? data.BuildServer.DetermineIfPullRequest(context) : false, "Not a pull request build")
.IsDependentOn("Read-Issues")
.Does<IssuesData>((data) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ public class IssuesParametersPullRequestSystem
/// </summary>
public Dictionary<string, IProviderIssueLimits> ProviderIssueLimits { get; } = new Dictionary<string, IProviderIssueLimits>();

/// <summary>
/// Gets or sets a value indicating whether a status on the pull request should be set.
/// Gets or sets a value indicating whether a status on the pull request should be set if there are any issues found.
/// The status is succeeded if there are no issues and fails as soon as issues from any issue provider or run have been found.
/// Use <see cref="ShouldSetSeparatePullRequestStatusForEachIssueProviderAndRun"/> to report additional status for issues of every issue provider and run.
/// Default value is <c>true</c>.
/// </summary>
public bool ShouldSetPullRequestStatus { get; set; } = true;

/// <summary>
/// Gets or sets a value indicating whether a separate status should be set for issues of every issue provider and run.
/// Use <see cref="ShouldSetPullRequestStatus"/> to report status across all issue providers and runs.
/// Default value is <c>false</c>.
/// </summary>
public bool ShouldSetSeparatePullRequestStatusForEachIssueProviderAndRun { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ public class AzureDevOpsPullRequestSystem : BasePullRequestSystem
return;
}

// Set status across all issues
if (IssuesParameters.PullRequestSystem.ShouldSetPullRequestStatus)
{
SetPullRequestStatus(
context,
data,
data.Issues,
null);
}

// Set status for individual issue providers
if (IssuesParameters.PullRequestSystem.ShouldSetSeparatePullRequestStatusForEachIssueProviderAndRun)
{
foreach (var providerGroup in data.Issues.GroupBy(x => x.ProviderType))
Expand All @@ -56,14 +67,6 @@ public class AzureDevOpsPullRequestSystem : BasePullRequestSystem
}
}
}
else
{
SetPullRequestStatus(
context,
data,
data.Issues,
null);
}
}

/// <inheritdoc />
Expand Down
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ By default [Cake.Git addin] will be used.
| `IssuesParameters.PullRequestSystem.`<br/>&nbsp;&nbsp;&nbsp;&nbsp;`MaxIssuesToPostAcrossRuns` | `IssuesContext.Parameters.PullRequestSystem.`<br/>&nbsp;&nbsp;&nbsp;&nbsp;`MaxIssuesToPostAcrossRuns` | `null` | Global number of issues which should be posted at maximum over all issue providers and across multiple runs. Issues are filtered by priority and issues with a file path are prioritized. `null` won't set a limit across multiple runs. |
| `IssuesParameters.PullRequestSystem.`<br/>&nbsp;&nbsp;&nbsp;&nbsp;`MaxIssuesToPostForEachIssueProvider` | `IssuesContext.Parameters.PullRequestSystem.`<br/>&nbsp;&nbsp;&nbsp;&nbsp;`MaxIssuesToPostForEachIssueProvider` | `100` | Number of issues which should be posted at maximum for each issue provider. Issues are filtered by priority and issues with a file path are prioritized. `null` won't limit issues per issue provider. |
| `IssuesParameters.PullRequestSystem.`<br/>&nbsp;&nbsp;&nbsp;&nbsp;`ProviderIssueLimits` | `IssuesContext.Parameters.PullRequestSystem.`<br/>&nbsp;&nbsp;&nbsp;&nbsp;`ProviderIssueLimits` | Empty | Issue limits for individual issue provider. The key must be the `IIssue.ProviderType` of a specific provider to which the limits should be applied to. |
| `IssuesParameters.PullRequestSystem.`<br/>&nbsp;&nbsp;&nbsp;&nbsp;`ShouldSetPullRequestStatus` | `IssuesContext.Parameters.PullRequestSystem.`<br/>&nbsp;&nbsp;&nbsp;&nbsp;`ShouldSetPullRequestStatus` | `true` | Indicates whether a status on the pull request should be set. |
| `IssuesParameters.PullRequestSystem.`<br/>&nbsp;&nbsp;&nbsp;&nbsp;`ShouldSetPullRequestStatus` | `IssuesContext.Parameters.PullRequestSystem.`<br/>&nbsp;&nbsp;&nbsp;&nbsp;`ShouldSetPullRequestStatus` | `true` | Indicates whether a status on the pull request should be set if there are any issues found. |
| `IssuesParameters.PullRequestSystem.`<br/>&nbsp;&nbsp;&nbsp;&nbsp;`ShouldSetSeparatePullRequestStatusForEachIssueProviderAndRun` | `IssuesContext.Parameters.PullRequestSystem.`<br/>&nbsp;&nbsp;&nbsp;&nbsp;`ShouldSetSeparatePullRequestStatusForEachIssueProviderAndRun` | `false` | Indicates whether a separate status should be set for issues of every issue provider and run. |

[Cake.Git addin]: https://cakebuild.net/extensions/cake-git/

0 comments on commit 4bb7299

Please sign in to comment.