Skip to content
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ If you have multiple kickflip flows in the same workflow (for example deploying
kickflip github pull-request --repo <owner>/<repo> --ref <ref> --token <token> --action-name staging
kickflip github pull-request --repo <owner>/<repo> --ref <ref> --token <token> --action-name production

If you don't set `--action-name`, kickflip falls back to the `--deployment-path` to name each section. This means multiple flows deploying to different paths automatically keep their own section and no longer overwrite each other. Only flows sharing the same deployment path (and no explicit action name) will share a section.

When running inside GitHub Actions, kickflip also writes the deployment change summary to the [job summary](https://github.blog/2022-05-09-supercharging-github-actions-with-job-summaries/) so it appears on the workflow run page. This happens automatically whenever the `GITHUB_STEP_SUMMARY` environment variable is present (which GitHub Actions sets for every step), in addition to posting the pull request comment.

## Github Actions
Expand Down
35 changes: 35 additions & 0 deletions src/kickflip.Tests/PullRequestCommentComposerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,41 @@ public void Compose_IsIdempotentAcrossMultipleReuses()
Assert.Equal(1, CountOccurrences(body, PullRequestCommentComposer.CommentMarker));
}

[Fact]
public void ResolveSectionName_UsesExplicitActionName_WhenProvided()
{
Assert.Equal("staging", PullRequestCommentComposer.ResolveSectionName("staging", "/some/path"));
}

[Fact]
public void ResolveSectionName_FallsBackToDeploymentPath_WhenNoActionName()
{
Assert.Equal("/staging", PullRequestCommentComposer.ResolveSectionName(null, "/staging"));
Assert.Equal("/production", PullRequestCommentComposer.ResolveSectionName("default", "/production"));
}

[Fact]
public void ResolveSectionName_UsesDefault_WhenNoActionNameAndRootPath()
{
Assert.Equal("default", PullRequestCommentComposer.ResolveSectionName(null, "/"));
Assert.Equal("default", PullRequestCommentComposer.ResolveSectionName("default", null));
}

[Fact]
public void MultipleDefaultFlows_WithDifferentDeploymentPaths_KeepBothSections()
{
// Simulates two kickflip integrations in one workflow that don't set --action-name
// but deploy to different paths. Both sections must survive.
var stagingName = PullRequestCommentComposer.ResolveSectionName(null, "/staging");
var productionName = PullRequestCommentComposer.ResolveSectionName(null, "/production");

var first = PullRequestCommentComposer.Compose(null, stagingName, "staging-content");
var second = PullRequestCommentComposer.Compose(first, productionName, "production-content");

Assert.Contains("staging-content", second);
Assert.Contains("production-content", second);
}

private static int CountOccurrences(string haystack, string needle)
{
var count = 0;
Expand Down
3 changes: 2 additions & 1 deletion src/kickflip/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ private static async Task<int> HandleGithubPullRequest(string localPath, FindMod
Console.WriteLine(outputService.GetChangesConsole(changes));

var sectionContent = outputService.GetChangesMarkdown(changes);
var result = await gitHubService.PullRequestCommentChanges(repository, pullRequestReference, sectionContent, actionName);
var sectionName = PullRequestCommentComposer.ResolveSectionName(actionName, deploymentPath);
var result = await gitHubService.PullRequestCommentChanges(repository, pullRequestReference, sectionContent, sectionName);

if (!result)
{
Expand Down
27 changes: 27 additions & 0 deletions src/kickflip/Services/PullRequestCommentComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,33 @@ public static bool IsKickflipComment(string? body)
return body != null && body.Contains(CommentMarker, StringComparison.Ordinal);
}

/// <summary>
/// Resolves the section name that a kickflip flow owns within the shared
/// comment. When an explicit <paramref name="actionName"/> is provided it is
/// used verbatim. Otherwise the <paramref name="deploymentPath"/> is used so
/// that multiple flows in the same workflow (for example deploying to
/// different paths) keep their own section instead of all colliding on the
/// default name and overwriting each other.
/// </summary>
public static string ResolveSectionName(string? actionName, string? deploymentPath)
{
if (!string.IsNullOrWhiteSpace(actionName) && actionName.Trim() != DefaultActionName)
{
return actionName.Trim();
}

if (!string.IsNullOrWhiteSpace(deploymentPath))
{
var normalized = deploymentPath.Trim();
if (normalized != "/")
{
return normalized;
}
}

return DefaultActionName;
}

/// <summary>
/// Produces the full comment body for a kickflip comment, upserting the
/// section owned by <paramref name="actionName"/> with <paramref name="sectionContent"/>.
Expand Down
Loading