Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for a specific description of the stack PR list #26

Merged
merged 27 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ae78d2a
wip creating GitHub PRs for a stack
geofflamrock Nov 11, 2024
7594399
More changes
geofflamrock Nov 11, 2024
365b9d2
Fix PR creation command
geofflamrock Nov 11, 2024
2bdae6f
Check if PR exists first
geofflamrock Nov 11, 2024
43fa41a
Show PR details
geofflamrock Nov 11, 2024
88fc74d
Merge branch 'main' into create-github-prs
geofflamrock Nov 11, 2024
d1c0ce5
Merge branch 'main' into create-github-prs
geofflamrock Nov 11, 2024
7993e1d
Remove static AnsiConsole usage
geofflamrock Nov 11, 2024
c90f829
Add stack list to PR description
geofflamrock Nov 11, 2024
435a11b
Open PRs in the browser
geofflamrock Nov 11, 2024
5649d58
Move command to bottom and mark experimental
geofflamrock Nov 11, 2024
d15aa04
Adds command to open PRs in a browser
geofflamrock Nov 11, 2024
cab9720
Fix option description
geofflamrock Nov 11, 2024
726b1dd
Merge branch 'create-github-prs' into open-prs-in-browser
geofflamrock Nov 11, 2024
a3fe9c4
Highlight experimental callout
geofflamrock Nov 11, 2024
b756df9
Merge branch 'create-github-prs' into open-prs-in-browser
geofflamrock Nov 11, 2024
5040db7
Revert back to `pr` command group
geofflamrock Nov 12, 2024
860f875
Merge branch 'main' into create-github-prs
geofflamrock Nov 12, 2024
d286552
Merge branch 'create-github-prs' into open-prs-in-browser
geofflamrock Nov 12, 2024
715d924
Merge branch 'main' into create-github-prs
geofflamrock Nov 12, 2024
7e64519
Merge branch 'create-github-prs' into open-prs-in-browser
geofflamrock Nov 12, 2024
e998a64
Fix logic for working out which branch for the PR
geofflamrock Nov 13, 2024
3fc6108
Merge branch 'create-github-prs' into open-prs-in-browser
geofflamrock Nov 13, 2024
71c68a0
Merge branch 'main' into open-prs-in-browser
geofflamrock Nov 13, 2024
e59daea
Merge branch 'main' into set-pr-stack-description
geofflamrock Nov 13, 2024
09685f1
Add support for a specific PR description for the stack
geofflamrock Nov 13, 2024
b5a45ae
Fix issue with creating PR when one is already open
geofflamrock Nov 13, 2024
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
34 changes: 19 additions & 15 deletions src/Stack/Commands/PullRequests/CreatePullRequestsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,17 @@ public override async Task<int> ExecuteAsync(CommandContext context, CreatePullR

foreach (var branch in stack.Branches)
{
if (gitOperations.DoesRemoteBranchExist(branch, settings.GetGitOperationSettings()))
var existingPullRequest = gitHubOperations.GetPullRequest(branch, settings.GetGitHubOperationSettings());

if (existingPullRequest is not null && existingPullRequest.State != GitHubPullRequestStates.Closed)
Copy link
Owner Author

@geofflamrock geofflamrock Nov 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes an issue where PRs already existed so would get skipped, meaning we wouldn't set descriptions properly

{
var existingPullRequest = gitHubOperations.GetPullRequest(branch, settings.GetGitHubOperationSettings());
console.MarkupLine($"Pull request {existingPullRequest.GetPullRequestDisplay()} already exists for branch [blue]{branch}[/] to [blue]{sourceBranch}[/]. Skipping...");
pullRequestsInStack.Add(existingPullRequest);
}

if (existingPullRequest is not null && existingPullRequest.State != GitHubPullRequestStates.Closed)
{
console.MarkupLine($"Pull request {existingPullRequest.GetPullRequestDisplay()} already exists for branch [blue]{branch}[/] to [blue]{sourceBranch}[/]. Skipping...");
pullRequestsInStack.Add(existingPullRequest);
}
else
if (gitOperations.DoesRemoteBranchExist(branch, settings.GetGitOperationSettings()))
{
if (existingPullRequest is null || existingPullRequest.State == GitHubPullRequestStates.Closed)
{
var prTitle = console.Prompt(new TextPrompt<string>($"Pull request title for branch [blue]{branch}[/] to [blue]{sourceBranch}[/]:"));
console.MarkupLine($"Creating pull request for branch [blue]{branch}[/] to [blue]{sourceBranch}[/]");
Expand All @@ -73,15 +74,19 @@ public override async Task<int> ExecuteAsync(CommandContext context, CreatePullR

sourceBranch = branch;
}
else
{
// Remote branch no longer exists, skip over
console.MarkupLine($"[red]Branch '{branch}' no longer exists on the remote repository. Skipping...[/]");
}
}

if (pullRequestsInStack.Count > 1)
{
var defaultStackDescription = stack.PullRequestDescription ?? $"This PR is part of a stack **{stack.Name}**:";
var stackDescription = console.Prompt(new TextPrompt<string>("Stack description for PR:").DefaultValue(defaultStackDescription));

if (stackDescription != stack.PullRequestDescription)
{
stack.SetPullRequestDescription(stackDescription);
stackConfig.Save(stacks);
}

// Edit each PR and add to the top of the description
// the details of each PR in the stack
var stackMarkerStart = "<!-- stack-pr-list -->";
Expand All @@ -90,8 +95,7 @@ public override async Task<int> ExecuteAsync(CommandContext context, CreatePullR
.Select(pr => $"- {pr.Url}")
.ToList();
var prListMarkdown = string.Join("\n", prList);
var prListHeader = $"This PR is part of a stack **{stack.Name}**:";
var prBodyMarkdown = $"{stackMarkerStart}\n{prListHeader}\n\n{prListMarkdown}\n{stackMarkerEnd}";
var prBodyMarkdown = $"{stackMarkerStart}\n{stackDescription}\n\n{prListMarkdown}\n{stackMarkerEnd}";

foreach (var pullRequest in pullRequestsInStack)
{
Expand Down
17 changes: 16 additions & 1 deletion src/Stack/Config/StackConfig.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Stack.Config;

internal record Stack(string Name, string RemoteUri, string SourceBranch, List<string> Branches);
internal class Stack(string Name, string RemoteUri, string SourceBranch, List<string> Branches)
{
public string Name { get; private set; } = Name;
public string RemoteUri { get; private set; } = RemoteUri;
public string SourceBranch { get; private set; } = SourceBranch;
public List<string> Branches { get; private set; } = Branches;

[JsonInclude]
public string? PullRequestDescription { get; private set; }

public void SetPullRequestDescription(string description)
{
this.PullRequestDescription = description;
}
}

internal static class StackExtensionMethods
{
Expand Down
Loading