diff --git a/src/Stack/Commands/PullRequests/CreatePullRequestsCommand.cs b/src/Stack/Commands/PullRequests/CreatePullRequestsCommand.cs index 2e41b55..258c547 100644 --- a/src/Stack/Commands/PullRequests/CreatePullRequestsCommand.cs +++ b/src/Stack/Commands/PullRequests/CreatePullRequestsCommand.cs @@ -49,16 +49,17 @@ public override async Task 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) { - 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($"Pull request title for branch [blue]{branch}[/] to [blue]{sourceBranch}[/]:")); console.MarkupLine($"Creating pull request for branch [blue]{branch}[/] to [blue]{sourceBranch}[/]"); @@ -73,15 +74,19 @@ public override async Task 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("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 = ""; @@ -90,8 +95,7 @@ public override async Task 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) { diff --git a/src/Stack/Config/StackConfig.cs b/src/Stack/Config/StackConfig.cs index 4f90cf4..0507238 100644 --- a/src/Stack/Config/StackConfig.cs +++ b/src/Stack/Config/StackConfig.cs @@ -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 Branches); +internal class Stack(string Name, string RemoteUri, string SourceBranch, List Branches) +{ + public string Name { get; private set; } = Name; + public string RemoteUri { get; private set; } = RemoteUri; + public string SourceBranch { get; private set; } = SourceBranch; + public List Branches { get; private set; } = Branches; + + [JsonInclude] + public string? PullRequestDescription { get; private set; } + + public void SetPullRequestDescription(string description) + { + this.PullRequestDescription = description; + } +} internal static class StackExtensionMethods {