Skip to content

Commit

Permalink
Merge branch 'release/1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalberger committed Aug 19, 2021
2 parents 3294566 + 6431ca8 commit 777a586
Show file tree
Hide file tree
Showing 24 changed files with 182 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public override void ReportIssuesToBuildServer(
context.ReportIssuesToPullRequest(
context.State.Issues,
context.AppVeyorBuilds(),
context.State.BuildRootDirectory);
context.State.ProjectRootDirectory);
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public override void CreateSummaryIssuesReport(
context.CreateIssueReport(
context.State.Issues,
context.GenericIssueReportFormatFromContent(sr.ReadToEnd()),
context.State.BuildRootDirectory,
context.State.ProjectRootDirectory,
summaryFilePath);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public override void ReportIssuesToBuildServer(
context.ReportIssuesToPullRequest(
context.State.Issues,
context.GitHubActionsBuilds(),
context.State.BuildRootDirectory);
context.State.ProjectRootDirectory);
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ For recipe compatible with Cake Script Runners see Cake.Issues.Recipe.</Descript
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/cake-contrib/Cake.Issues.Recipe.git</RepositoryUrl>
<PackageReleaseNotes>https://github.com/cake-contrib/Cake.Issues.Recipe/releases/tag/1.1.0</PackageReleaseNotes>
<PackageReleaseNotes>https://github.com/cake-contrib/Cake.Issues.Recipe/releases/tag/1.2.0</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
using Cake.Issues;
using Cake.Issues.PullRequests;
using System.Collections.Generic;

namespace Cake.Frosting.Issues.Recipe
{
/// <summary>
Expand All @@ -11,6 +15,44 @@ public class IssuesParametersPullRequestSystem
/// </summary>
public bool ShouldReportIssuesToPullRequest { get; set; } = true;

/// <summary>
/// Gets or sets the global number of issues which should be posted at maximum over all
/// <see cref="IIssueProvider"/>.
/// Issues are filtered by <see cref="IIssue.Priority"/> and issues with an <see cref="IIssue.AffectedFileRelativePath"/>
/// are prioritized.
/// Default is <c>null</c> which won't set a global limit.
/// Use <see cref="MaxIssuesToPostAcrossRuns"/> to set a limit across multiple runs.
/// </summary>
public int? MaxIssuesToPost { get; set; }

/// <summary>
/// Gets or sets the global number of issues which should be posted at maximum over all
/// <see cref="IIssueProvider"/> and across multiple runs.
/// Issues are filtered by <see cref="IIssue.Priority"/> and issues with an <see cref="IIssue.AffectedFileRelativePath"/>
/// are prioritized.
/// Default is <c>null</c> which won't set a limit across multiple runs.
/// Use <see cref="MaxIssuesToPost"/> to set a limit for a single run.
/// </summary>
public int? MaxIssuesToPostAcrossRuns { get; set; }

/// <summary>
/// Gets or sets the number of issues which should be posted at maximum for each
/// <see cref="IIssueProvider"/>.
/// Issues are filtered by <see cref="IIssue.Priority"/> and issues with an <see cref="IIssue.AffectedFileRelativePath"/>
/// are prioritized.
/// <c>null</c> won't limit issues per issue provider.
/// Default is to filter to 100 issues for each issue provider.
/// Use <see cref="ProviderIssueLimits"/> to set limits for individual issue providers.
/// </summary>
public int? MaxIssuesToPostForEachIssueProvider { get; set; } = 100;

/// <summary>
/// Gets the issue limits for individual <see cref="IIssueProvider"/>.
/// The key must be the <see cref="IIssue.ProviderType"/> of a specific provider to which the limits should be applied to.
/// Use <see cref="MaxIssuesToPostForEachIssueProvider"/> to set the same limit to all issue providers.
/// </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.
/// Default value is <c>true</c>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public class IssuesState
/// </summary>
public DirectoryPath BuildRootDirectory { get; }

/// <summary>
/// Gets the root directory of the project.
/// Default value is the parent directory of the <see cref="BuildRootDirectory"/>.
/// </summary>
public DirectoryPath ProjectRootDirectory { get; set; }

/// <summary>
/// Gets the remote URL of the repository.
/// </summary>
Expand Down Expand Up @@ -85,6 +91,9 @@ public IssuesState(
this.BuildRootDirectory = context.MakeAbsolute(context.Directory("./"));
context.Information("Build script root directory: {0}", this.BuildRootDirectory);

this.ProjectRootDirectory = this.BuildRootDirectory.Combine("..").Collapse();
context.Information("Project root directory: {0}", this.ProjectRootDirectory);

this.RepositoryInfo = DetermineRepositoryInfoProvider(context, repositoryInfoProviderType);

this.RepositoryRootDirectory = this.RepositoryInfo.GetRepositoryRootDirectory(context, this.BuildRootDirectory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public override void Run(IssuesContext context)
context.CreateIssueReport(
context.State.Issues,
context.GenericIssueReportFormat(context.Parameters.Reporting.FullIssuesReportSettings),
context.State.BuildRootDirectory,
context.State.ProjectRootDirectory,
context.State.FullIssuesReport);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public override void ReportIssuesToPullRequest(IssuesContext context)
context.State.BuildServer.DetermineRepositoryRemoteUrl(context, context.State.RepositoryRootDirectory),
context.State.BuildServer.DeterminePullRequestId(context).Value,
context.AzureDevOpsAuthenticationOAuth(context.EnvironmentVariable("SYSTEM_ACCESSTOKEN"))),
context.State.BuildRootDirectory);
GetReportIssuesToPullRequestSettings(context));
#endregion
}

Expand Down Expand Up @@ -87,7 +87,7 @@ public override FileLinkSettings GetFileLinkSettings(IssuesContext context)
{
context.NotNull(nameof(context));

var rootPath = context.State.RepositoryRootDirectory.GetRelativePath(context.State.BuildRootDirectory);
var rootPath = context.State.RepositoryRootDirectory.GetRelativePath(context.State.ProjectRootDirectory);

return context.IssueFileLinkSettingsForAzureDevOpsCommit(
context.State.RepositoryRemoteUrl,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Cake.Issues;
using Cake.Issues.PullRequests;

namespace Cake.Frosting.Issues.Recipe
{
Expand All @@ -18,5 +19,28 @@ public abstract void SetPullRequestIssuesState(
/// <inheritdoc />
public abstract FileLinkSettings GetFileLinkSettings(
IssuesContext context);

/// <summary>
/// Returns settings for reporting issues to pull requests.
/// </summary>
/// <param name="context">The Cake context.</param>
/// <returns>Settings for reporting issues to pull requests.</returns>
protected static IReportIssuesToPullRequestSettings GetReportIssuesToPullRequestSettings(IssuesContext context)
{
var settings =
new ReportIssuesToPullRequestSettings(context.State.ProjectRootDirectory)
{
MaxIssuesToPost = context.Parameters.PullRequestSystem.MaxIssuesToPost,
MaxIssuesToPostAcrossRuns = context.Parameters.PullRequestSystem.MaxIssuesToPostAcrossRuns,
MaxIssuesToPostForEachIssueProvider = context.Parameters.PullRequestSystem.MaxIssuesToPostForEachIssueProvider
};

foreach (var providerIssueLimit in context.Parameters.PullRequestSystem.ProviderIssueLimits)
{
settings.ProviderIssueLimits.Add(providerIssueLimit.Key, providerIssueLimit.Value);
}

return settings;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public override FileLinkSettings GetFileLinkSettings(IssuesContext context)
{
context.NotNull(nameof(context));

var rootPath = context.State.RepositoryRootDirectory.GetRelativePath(context.State.BuildRootDirectory);
var rootPath = context.State.RepositoryRootDirectory.GetRelativePath(context.State.ProjectRootDirectory);

return context.IssueFileLinkSettingsForGitHubCommit(
context.State.RepositoryRemoteUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public override void Run(IssuesContext context)
context.NotNull(nameof(context));

// Define default settings.
var defaultSettings = new ReadIssuesSettings(context.State.BuildRootDirectory);
var defaultSettings = new ReadIssuesSettings(context.State.ProjectRootDirectory);

if (context.State.PullRequestSystem != null)
{
Expand Down
4 changes: 2 additions & 2 deletions Cake.Issues.Recipe/Content/build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ IssuesBuildTasks.ReadIssuesTask = Task("Read-Issues")
.Does<IssuesData>((data) =>
{
// Define default settings.
var defaultSettings = new ReadIssuesSettings(data.BuildRootDirectory);
var defaultSettings = new ReadIssuesSettings(data.ProjectRootDirectory);

if (data.PullRequestSystem != null)
{
Expand Down Expand Up @@ -150,7 +150,7 @@ IssuesBuildTasks.CreateFullIssuesReportTask = Task("Create-FullIssuesReport")
CreateIssueReport(
data.Issues,
GenericIssueReportFormat(IssuesParameters.Reporting.FullIssuesReportSettings),
data.BuildRootDirectory,
data.ProjectRootDirectory,
data.FullIssuesReport);
});

Expand Down
9 changes: 9 additions & 0 deletions Cake.Issues.Recipe/Content/data/IssuesData.cake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ public class IssuesData
/// </summary>
public DirectoryPath BuildRootDirectory { get; }

/// <summary>
/// Gets the root directory of the project.
/// Default value is the <see cref="BuildRootDirectory"/>.
/// </summary>
public DirectoryPath ProjectRootDirectory { get; set; }

/// Gets the remote URL of the repository.
/// </summary>
public Uri RepositoryRemoteUrl { get; }
Expand Down Expand Up @@ -74,6 +80,9 @@ public class IssuesData
this.BuildRootDirectory = context.MakeAbsolute(context.Directory("./"));
context.Information("Build script root directory: {0}", this.BuildRootDirectory);

this.ProjectRootDirectory = this.BuildRootDirectory;
context.Information("Project root directory: {0}", this.ProjectRootDirectory);

this.RepositoryInfo = DetermineRepositoryInfoProvider(context, repositoryInfoProviderType);

this.RepositoryRootDirectory = context.GitFindRootFromPath(this.BuildRootDirectory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,44 @@ public class IssuesParametersPullRequestSystem
/// </summary>
public bool ShouldReportIssuesToPullRequest { get; set; } = true;

/// <summary>
/// Gets or sets the global number of issues which should be posted at maximum over all
/// <see cref="IIssueProvider"/>.
/// Issues are filtered by <see cref="IIssue.Priority"/> and issues with an <see cref="IIssue.AffectedFileRelativePath"/>
/// are prioritized.
/// Default is <c>null</c> which won't set a global limit.
/// Use <see cref="MaxIssuesToPostAcrossRuns"/> to set a limit across multiple runs.
/// </summary>
public int? MaxIssuesToPost { get; set; }

/// <summary>
/// Gets or sets the global number of issues which should be posted at maximum over all
/// <see cref="IIssueProvider"/> and across multiple runs.
/// Issues are filtered by <see cref="IIssue.Priority"/> and issues with an <see cref="IIssue.AffectedFileRelativePath"/>
/// are prioritized.
/// Default is <c>null</c> which won't set a limit across multiple runs.
/// Use <see cref="MaxIssuesToPost"/> to set a limit for a single run.
/// </summary>
public int? MaxIssuesToPostAcrossRuns { get; set; }

/// <summary>
/// Gets or sets the number of issues which should be posted at maximum for each
/// <see cref="IIssueProvider"/>.
/// Issues are filtered by <see cref="IIssue.Priority"/> and issues with an <see cref="IIssue.AffectedFileRelativePath"/>
/// are prioritized.
/// <c>null</c> won't limit issues per issue provider.
/// Default is to filter to 100 issues for each issue provider.
/// Use <see cref="ProviderIssueLimits"/> to set limits for individual issue providers.
/// </summary>
public int? MaxIssuesToPostForEachIssueProvider { get; set; } = 100;

/// <summary>
/// Gets the issue limits for individual <see cref="IIssueProvider"/>.
/// The key must be the <see cref="IIssue.ProviderType"/> of a specific provider to which the limits should be applied to.
/// Use <see cref="MaxIssuesToPostForEachIssueProvider"/> to set the same limit to all issue providers.
/// </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.
/// Default value is <c>true</c>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class AppVeyorBuildServer : BaseBuildServer
context.ReportIssuesToPullRequest(
data.Issues,
context.AppVeyorBuilds(),
data.BuildRootDirectory);
data.ProjectRootDirectory);
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public class AzureDevOpsBuildServer : BaseBuildServer
data.Issues,
context.GenericIssueReportFormatFromFilePath(
new FilePath(sourceFilePath).GetDirectory().Combine("tasks").Combine("buildservers").CombineWithFilePath("AzurePipelineSummary.cshtml")),
data.BuildRootDirectory,
data.ProjectRootDirectory,
summaryFilePath);

context.AzurePipelines().Commands.UploadTaskSummary(summaryFilePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class GitHubActionsBuildServer : BaseBuildServer
context.ReportIssuesToPullRequest(
data.Issues,
context.GitHubActionsBuilds(),
data.BuildRootDirectory);
data.ProjectRootDirectory);
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class AzureDevOpsPullRequestSystem : BasePullRequestSystem
data.BuildServer.DetermineRepositoryRemoteUrl(context, data.RepositoryRootDirectory),
data.BuildServer.DeterminePullRequestId(context).Value,
context.AzureDevOpsAuthenticationOAuth(context.EnvironmentVariable("SYSTEM_ACCESSTOKEN"))),
data.BuildRootDirectory);
GetReportIssuesToPullRequestSettings(data));
}

/// <inheritdoc />
Expand Down Expand Up @@ -71,7 +71,7 @@ public class AzureDevOpsPullRequestSystem : BasePullRequestSystem
context.NotNull(nameof(context));
data.NotNull(nameof(data));

var rootPath = data.RepositoryRootDirectory.GetRelativePath(data.BuildRootDirectory);
var rootPath = data.RepositoryRootDirectory.GetRelativePath(data.ProjectRootDirectory);

return context.IssueFileLinkSettingsForAzureDevOpsCommit(
data.RepositoryRemoteUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,25 @@ public abstract class BasePullRequestSystem : IIssuesPullRequestSystem
public abstract FileLinkSettings GetFileLinkSettings(
ICakeContext context,
IssuesData data);

/// <summary>
/// Returns settings for reporting issues to pull requests.
/// </summary>
/// <param name="context">The Cake context.</param>
/// <returns>Settings for reporting issues to pull requests.</returns>
protected static IReportIssuesToPullRequestSettings GetReportIssuesToPullRequestSettings(IssuesData data)
{
var settings =
new ReportIssuesToPullRequestSettings(data.ProjectRootDirectory)
{
MaxIssuesToPost = IssuesParameters.PullRequestSystem.MaxIssuesToPost,
MaxIssuesToPostAcrossRuns = IssuesParameters.PullRequestSystem.MaxIssuesToPostAcrossRuns,
MaxIssuesToPostForEachIssueProvider = IssuesParameters.PullRequestSystem.MaxIssuesToPostForEachIssueProvider
};
foreach (var providerIssueLimit in IssuesParameters.PullRequestSystem.ProviderIssueLimits)
{
settings.ProviderIssueLimits.Add(providerIssueLimit.Key, providerIssueLimit.Value);
}
return settings;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class GitHubPullRequestSystem : BasePullRequestSystem
context.NotNull(nameof(context));
data.NotNull(nameof(data));

var rootPath = data.RepositoryRootDirectory.GetRelativePath(data.BuildRootDirectory);
var rootPath = data.RepositoryRootDirectory.GetRelativePath(data.ProjectRootDirectory);

return context.IssueFileLinkSettingsForGitHubCommit(
data.RepositoryRemoteUrl,
Expand Down
7 changes: 3 additions & 4 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ jobs:
- powershell: ./build.ps1 --verbosity=diagnostic
workingDirectory: ./tests/frosting/net5.0
displayName: 'Run integration tests'
# TODO Requires Cake.Issues.Reporting.Generic working with Frosting https://github.com/cake-contrib/Cake.Issues.Reporting.Generic/issues/361
# - publish: $(Build.SourcesDirectory)/tests/script-runner/BuildArtifacts/output
# artifact: Integration Tests Script Runner Windows (.NET Core tool)
# displayName: 'Publish generated reports as build artifact'
- publish: $(Build.SourcesDirectory)/tests/frosting/net5.0/build/BuildArtifacts/output
artifact: Integration Tests Frosting Windows (.NET 5)
displayName: 'Publish generated reports as build artifact'
# Integration Tests Script Runner Windows (.NET Framework)
- job: Test_Script_Runner_Windows_DotNetFramework
displayName: 'Integration Tests Script Runner Windows (.NET Framework)'
Expand Down
Loading

0 comments on commit 777a586

Please sign in to comment.