diff --git a/src/Stack.Tests/Commands/PullRequests/CreatePullRequestsCommandHandlerTests.cs b/src/Stack.Tests/Commands/PullRequests/CreatePullRequestsCommandHandlerTests.cs index 9a94ce74..de0c1d46 100644 --- a/src/Stack.Tests/Commands/PullRequests/CreatePullRequestsCommandHandlerTests.cs +++ b/src/Stack.Tests/Commands/PullRequests/CreatePullRequestsCommandHandlerTests.cs @@ -65,8 +65,8 @@ A custom description var expectedPullRequests = new Dictionary { - [branch1] = new GitHubPullRequest(1, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false, []), - [branch2] = new GitHubPullRequest(2, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false, []) + [branch1] = new GitHubPullRequest(1, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false), + [branch2] = new GitHubPullRequest(2, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false) }; gitHubClient.PullRequests.Should().BeEquivalentTo(expectedPullRequests, ExcludeUnimportantPullRequestProperties); @@ -238,8 +238,8 @@ A custom description var expectedPullRequests = new Dictionary { - [branch1] = new GitHubPullRequest(1, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false, []), - [branch2] = new GitHubPullRequest(2, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false, []) + [branch1] = new GitHubPullRequest(1, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false), + [branch2] = new GitHubPullRequest(2, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false) }; gitHubClient.PullRequests.Should().BeEquivalentTo(expectedPullRequests, ExcludeUnimportantPullRequestProperties); @@ -291,8 +291,8 @@ A custom description var expectedPullRequests = new Dictionary { - [branch1] = new GitHubPullRequest(1, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false, []), - [branch2] = new GitHubPullRequest(2, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false, []) + [branch1] = new GitHubPullRequest(1, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false), + [branch2] = new GitHubPullRequest(2, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false) }; gitHubClient.PullRequests.Should().BeEquivalentTo(expectedPullRequests, ExcludeUnimportantPullRequestProperties); @@ -391,8 +391,8 @@ A custom description var expectedPullRequests = new Dictionary { - [branch1] = new GitHubPullRequest(1, "PR Title", expectedPrBody, GitHubPullRequestStates.Merged, Some.HttpsUri(), false, []), - [branch2] = new GitHubPullRequest(2, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false, []) + [branch1] = new GitHubPullRequest(1, "PR Title", expectedPrBody, GitHubPullRequestStates.Merged, Some.HttpsUri(), false), + [branch2] = new GitHubPullRequest(2, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false) }; gitHubClient.PullRequests.Should().BeEquivalentTo(expectedPullRequests, ExcludeUnimportantPullRequestProperties); @@ -453,8 +453,8 @@ A custom description var expectedPullRequests = new Dictionary { - [branch1] = new GitHubPullRequest(1, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false, []), - [branch2] = new GitHubPullRequest(2, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false, []) + [branch1] = new GitHubPullRequest(1, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false), + [branch2] = new GitHubPullRequest(2, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false) }; gitHubClient.PullRequests.Should().BeEquivalentTo(expectedPullRequests, ExcludeUnimportantPullRequestProperties); @@ -510,7 +510,7 @@ public async Task WhenAPullRequestTemplateDoesNotExistInTheRepo_TheStackPrListMa var expectedPullRequests = new Dictionary { - [branch1] = new GitHubPullRequest(1, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false, []) + [branch1] = new GitHubPullRequest(1, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false) }; gitHubClient.PullRequests.Should().BeEquivalentTo(expectedPullRequests, ExcludeUnimportantPullRequestProperties); @@ -612,7 +612,7 @@ public async Task WhenOnlySelectingSomeBranchesToCreatePullRequestsFor_OnlyThose var expectedPullRequests = new Dictionary { - [branch1] = new GitHubPullRequest(1, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false, []) + [branch1] = new GitHubPullRequest(1, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false) }; gitHubClient.PullRequests.Should().BeEquivalentTo(expectedPullRequests, ExcludeUnimportantPullRequestProperties); @@ -671,140 +671,11 @@ A custom description var expectedPullRequests = new Dictionary { - [branch1] = new GitHubPullRequest(1, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false, []), - [branch2] = new GitHubPullRequest(2, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false, []) + [branch1] = new GitHubPullRequest(1, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false), + [branch2] = new GitHubPullRequest(2, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false) }; gitHubClient.PullRequests.Should().BeEquivalentTo(expectedPullRequests, ExcludeUnimportantPullRequestProperties); inputProvider.DidNotReceive().Text(Questions.PullRequestStackDescription, Arg.Any()); } - - [Fact] - public async Task WhenNoLabelsExistInTheRepo_DoesNotAskForLabels_AndNoLabelsAreAppliedToCreatedPullRequests() - { - // Arrange - var sourceBranch = Some.BranchName(); - var branch1 = Some.BranchName(); - var branch2 = Some.BranchName(); - using var repo = new TestGitRepositoryBuilder() - .WithBranch(sourceBranch, true) - .WithBranch(branch1, true) - .WithBranch(branch2, true) - .Build(); - - var gitHubClient = new TestGitHubRepositoryBuilder().Build(); - var stackConfig = Substitute.For(); - var inputProvider = Substitute.For(); - var logger = new TestLogger(testOutputHelper); - var fileOperations = new FileOperations(); - var gitClient = new GitClient(logger, repo.GitClientSettings); - var handler = new CreatePullRequestsCommandHandler(inputProvider, logger, gitClient, gitHubClient, fileOperations, stackConfig); - - var stack1 = new Config.Stack("Stack1", repo.RemoteUri, sourceBranch, [branch1, branch2]); - - var stacks = new List( - [ - stack1, - new("Stack2", repo.RemoteUri, sourceBranch, []) - ]); - stackConfig.Load().Returns(stacks); - stackConfig - .WhenForAnyArgs(s => s.Save(Arg.Any>())) - .Do(ci => stacks = ci.ArgAt>(0)); - - inputProvider.Select(Questions.SelectStack, Arg.Any()).Returns("Stack1"); - inputProvider - .MultiSelect(Questions.SelectPullRequestsToCreate, Arg.Any(), true, Arg.Any>()) - .Returns([new PullRequestCreateAction(branch1, sourceBranch), new PullRequestCreateAction(branch2, branch1)]); - inputProvider.Confirm(Questions.ConfirmCreatePullRequests).Returns(true); - inputProvider.Text(Questions.PullRequestTitle).Returns("PR Title"); - inputProvider.Text(Questions.PullRequestStackDescription, Arg.Any()).Returns("A custom description"); - - // Act - await handler.Handle(CreatePullRequestsCommandInputs.Empty); - - // Assert - var expectedPrBody = $@"{StackConstants.StackMarkerStart} -A custom description - -{string.Join(Environment.NewLine, gitHubClient.PullRequests.Values.Select(pr => $"- {pr.Url}"))} -{StackConstants.StackMarkerEnd}"; - - var expectedLabels = new List(["label1", "label2"]).Select(l => new GitHubLabel(l)).ToArray(); - - var expectedPullRequests = new Dictionary - { - [branch1] = new GitHubPullRequest(1, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false, []), - [branch2] = new GitHubPullRequest(2, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false, []) - }; - - gitHubClient.PullRequests.Should().BeEquivalentTo(expectedPullRequests, ExcludeUnimportantPullRequestProperties); - inputProvider.DidNotReceive().MultiSelect(Questions.PullRequestLabels, Arg.Any(), Arg.Any(), Arg.Any>()); - } - - [Fact] - public async Task WhenLabelsExistInTheRepo_AsksForLabels_AndAppliesToCreatedPullRequests() - { - // Arrange - var sourceBranch = Some.BranchName(); - var branch1 = Some.BranchName(); - var branch2 = Some.BranchName(); - using var repo = new TestGitRepositoryBuilder() - .WithBranch(sourceBranch, true) - .WithBranch(branch1, true) - .WithBranch(branch2, true) - .Build(); - - var gitHubClient = new TestGitHubRepositoryBuilder() - .WithLabel("label1") - .WithLabel("label2") - .Build(); - var stackConfig = Substitute.For(); - var inputProvider = Substitute.For(); - var logger = new TestLogger(testOutputHelper); - var fileOperations = new FileOperations(); - var gitClient = new GitClient(logger, repo.GitClientSettings); - var handler = new CreatePullRequestsCommandHandler(inputProvider, logger, gitClient, gitHubClient, fileOperations, stackConfig); - - var stack1 = new Config.Stack("Stack1", repo.RemoteUri, sourceBranch, [branch1, branch2]); - - var stacks = new List( - [ - stack1, - new("Stack2", repo.RemoteUri, sourceBranch, []) - ]); - stackConfig.Load().Returns(stacks); - stackConfig - .WhenForAnyArgs(s => s.Save(Arg.Any>())) - .Do(ci => stacks = ci.ArgAt>(0)); - - inputProvider.Select(Questions.SelectStack, Arg.Any()).Returns("Stack1"); - inputProvider - .MultiSelect(Questions.SelectPullRequestsToCreate, Arg.Any(), true, Arg.Any>()) - .Returns([new PullRequestCreateAction(branch1, sourceBranch), new PullRequestCreateAction(branch2, branch1)]); - inputProvider.Confirm(Questions.ConfirmCreatePullRequests).Returns(true); - inputProvider.Text(Questions.PullRequestTitle).Returns("PR Title"); - inputProvider.Text(Questions.PullRequestStackDescription, Arg.Any()).Returns("A custom description"); - inputProvider.MultiSelect(Questions.PullRequestLabels, Arg.Any(), Arg.Any(), Arg.Any>()).Returns(new List(["label1", "label2"]).ToArray()); - - // Act - await handler.Handle(CreatePullRequestsCommandInputs.Empty); - - // Assert - var expectedPrBody = $@"{StackConstants.StackMarkerStart} -A custom description - -{string.Join(Environment.NewLine, gitHubClient.PullRequests.Values.Select(pr => $"- {pr.Url}"))} -{StackConstants.StackMarkerEnd}"; - - var expectedLabels = new List(["label1", "label2"]).Select(l => new GitHubLabel(l)).ToArray(); - - var expectedPullRequests = new Dictionary - { - [branch1] = new GitHubPullRequest(1, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false, expectedLabels), - [branch2] = new GitHubPullRequest(2, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false, expectedLabels) - }; - - gitHubClient.PullRequests.Should().BeEquivalentTo(expectedPullRequests, ExcludeUnimportantPullRequestProperties); - } } diff --git a/src/Stack.Tests/Commands/PullRequests/OpenPullRequestsCommandHandlerTests.cs b/src/Stack.Tests/Commands/PullRequests/OpenPullRequestsCommandHandlerTests.cs index 4aa5db38..b4b440ce 100644 --- a/src/Stack.Tests/Commands/PullRequests/OpenPullRequestsCommandHandlerTests.cs +++ b/src/Stack.Tests/Commands/PullRequests/OpenPullRequestsCommandHandlerTests.cs @@ -44,12 +44,12 @@ public async Task WhenThereAreMultiplePullRequestsInAStack_OpensAllPullRequests( inputProvider.Select(Questions.SelectStack, Arg.Any()).Returns("Stack1"); - var prForBranch1 = new GitHubPullRequest(1, "PR Title", string.Empty, GitHubPullRequestStates.Open, Some.HttpsUri(), false, []); + var prForBranch1 = new GitHubPullRequest(1, "PR Title", string.Empty, GitHubPullRequestStates.Open, Some.HttpsUri(), false); gitHubClient .GetPullRequest(branch1) .Returns(prForBranch1); - var prForBranch2 = new GitHubPullRequest(2, "PR Title", string.Empty, GitHubPullRequestStates.Open, Some.HttpsUri(), false, []); + var prForBranch2 = new GitHubPullRequest(2, "PR Title", string.Empty, GitHubPullRequestStates.Open, Some.HttpsUri(), false); gitHubClient .GetPullRequest(branch2) .Returns(prForBranch2); @@ -95,12 +95,12 @@ public async Task WhenThereAreSomePullRequestsInAStack_OpensAllPullRequests() inputProvider.Select(Questions.SelectStack, Arg.Any()).Returns("Stack1"); - var prForBranch1 = new GitHubPullRequest(1, "PR Title", string.Empty, GitHubPullRequestStates.Open, Some.HttpsUri(), false, []); + var prForBranch1 = new GitHubPullRequest(1, "PR Title", string.Empty, GitHubPullRequestStates.Open, Some.HttpsUri(), false); gitHubClient .GetPullRequest(branch1) .Returns(prForBranch1); - var prForBranch2 = new GitHubPullRequest(2, "PR Title", string.Empty, GitHubPullRequestStates.Closed, Some.HttpsUri(), false, []); + var prForBranch2 = new GitHubPullRequest(2, "PR Title", string.Empty, GitHubPullRequestStates.Closed, Some.HttpsUri(), false); // Act await handler.Handle(OpenPullRequestsCommandInputs.Empty); @@ -138,12 +138,12 @@ public async Task WhenStackNameIsProvided_OpensAllPullRequestsForTheStack() ]); stackConfig.Load().Returns(stacks); - var prForBranch1 = new GitHubPullRequest(1, "PR Title", string.Empty, GitHubPullRequestStates.Open, Some.HttpsUri(), false, []); + var prForBranch1 = new GitHubPullRequest(1, "PR Title", string.Empty, GitHubPullRequestStates.Open, Some.HttpsUri(), false); gitHubClient .GetPullRequest(branch1) .Returns(prForBranch1); - var prForBranch2 = new GitHubPullRequest(2, "PR Title", string.Empty, GitHubPullRequestStates.Open, Some.HttpsUri(), false, []); + var prForBranch2 = new GitHubPullRequest(2, "PR Title", string.Empty, GitHubPullRequestStates.Open, Some.HttpsUri(), false); gitHubClient .GetPullRequest(branch2) .Returns(prForBranch2); @@ -183,12 +183,12 @@ public async Task WhenOnlyOneStackExists_DoesNotAskForStackName_OpensAllPullRequ ]); stackConfig.Load().Returns(stacks); - var prForBranch1 = new GitHubPullRequest(1, "PR Title", string.Empty, GitHubPullRequestStates.Open, Some.HttpsUri(), false, []); + var prForBranch1 = new GitHubPullRequest(1, "PR Title", string.Empty, GitHubPullRequestStates.Open, Some.HttpsUri(), false); gitHubClient .GetPullRequest(branch1) .Returns(prForBranch1); - var prForBranch2 = new GitHubPullRequest(2, "PR Title", string.Empty, GitHubPullRequestStates.Open, Some.HttpsUri(), false, []); + var prForBranch2 = new GitHubPullRequest(2, "PR Title", string.Empty, GitHubPullRequestStates.Open, Some.HttpsUri(), false); gitHubClient .GetPullRequest(branch2) .Returns(prForBranch2); diff --git a/src/Stack.Tests/Commands/Stack/StackStatusCommandHandlerTests.cs b/src/Stack.Tests/Commands/Stack/StackStatusCommandHandlerTests.cs index 94431a72..a750382d 100644 --- a/src/Stack.Tests/Commands/Stack/StackStatusCommandHandlerTests.cs +++ b/src/Stack.Tests/Commands/Stack/StackStatusCommandHandlerTests.cs @@ -46,7 +46,7 @@ public async Task WhenMultipleBranchesExistInAStack_AndOneHasAPullRequests_Retur .WhenForAnyArgs(o => o.Status(Arg.Any(), Arg.Any())) .Do(ci => ci.ArgAt(1)()); - var pr = new GitHubPullRequest(1, "PR title", "PR body", GitHubPullRequestStates.Open, Some.HttpsUri(), false, []); + var pr = new GitHubPullRequest(1, "PR title", "PR body", GitHubPullRequestStates.Open, Some.HttpsUri(), false); gitHubClient .GetPullRequest(branch1) @@ -106,7 +106,7 @@ public async Task WhenStackNameIsProvided_DoesNotAskForStack_ReturnsStatus() .WhenForAnyArgs(o => o.Status(Arg.Any(), Arg.Any())) .Do(ci => ci.ArgAt(1)()); - var pr = new GitHubPullRequest(1, "PR title", "PR body", GitHubPullRequestStates.Open, Some.HttpsUri(), false, []); + var pr = new GitHubPullRequest(1, "PR title", "PR body", GitHubPullRequestStates.Open, Some.HttpsUri(), false); gitHubClient .GetPullRequest(branch1) @@ -169,7 +169,7 @@ public async Task WhenAllStacksAreRequested_ReturnsStatusOfEachStack() .WhenForAnyArgs(o => o.Status(Arg.Any(), Arg.Any())) .Do(ci => ci.ArgAt(1)()); - var pr = new GitHubPullRequest(1, "PR title", "PR body", GitHubPullRequestStates.Open, Some.HttpsUri(), false, []); + var pr = new GitHubPullRequest(1, "PR title", "PR body", GitHubPullRequestStates.Open, Some.HttpsUri(), false); gitHubClient .GetPullRequest(branch1) @@ -239,7 +239,7 @@ public async Task WhenAllStacksAreRequested_WithStacksInMultipleRepositories_Ret .WhenForAnyArgs(o => o.Status(Arg.Any(), Arg.Any())) .Do(ci => ci.ArgAt(1)()); - var pr = new GitHubPullRequest(1, "PR title", "PR body", GitHubPullRequestStates.Open, Some.HttpsUri(), false, []); + var pr = new GitHubPullRequest(1, "PR title", "PR body", GitHubPullRequestStates.Open, Some.HttpsUri(), false); gitHubClient .GetPullRequest(branch1) @@ -342,7 +342,7 @@ public async Task WhenMultipleBranchesExistInAStack_AndOneNoLongerExistsOnTheRem .WhenForAnyArgs(o => o.Status(Arg.Any(), Arg.Any())) .Do(ci => ci.ArgAt(1)()); - var pr = new GitHubPullRequest(1, "PR title", "PR body", GitHubPullRequestStates.Open, Some.HttpsUri(), false, []); + var pr = new GitHubPullRequest(1, "PR title", "PR body", GitHubPullRequestStates.Open, Some.HttpsUri(), false); gitHubClient .GetPullRequest(branch2) @@ -399,7 +399,7 @@ public async Task WhenMultipleBranchesExistInAStack_AndOneNoLongerExistsOnTheRem .WhenForAnyArgs(o => o.Status(Arg.Any(), Arg.Any())) .Do(ci => ci.ArgAt(1)()); - var pr = new GitHubPullRequest(1, "PR title", "PR body", GitHubPullRequestStates.Open, Some.HttpsUri(), false, []); + var pr = new GitHubPullRequest(1, "PR title", "PR body", GitHubPullRequestStates.Open, Some.HttpsUri(), false); gitHubClient .GetPullRequest(branch2) @@ -456,7 +456,7 @@ public async Task WhenOnlyOneStackExists_DoesNotAskForStackName_ReturnsStatus() .WhenForAnyArgs(o => o.Status(Arg.Any(), Arg.Any())) .Do(ci => ci.ArgAt(1)()); - var pr = new GitHubPullRequest(1, "PR title", "PR body", GitHubPullRequestStates.Open, Some.HttpsUri(), false, []); + var pr = new GitHubPullRequest(1, "PR title", "PR body", GitHubPullRequestStates.Open, Some.HttpsUri(), false); gitHubClient .GetPullRequest(branch1) diff --git a/src/Stack.Tests/Commands/Stack/UpdateStackCommandHandlerTests.cs b/src/Stack.Tests/Commands/Stack/UpdateStackCommandHandlerTests.cs index 8d657d67..7b366b7f 100644 --- a/src/Stack.Tests/Commands/Stack/UpdateStackCommandHandlerTests.cs +++ b/src/Stack.Tests/Commands/Stack/UpdateStackCommandHandlerTests.cs @@ -120,7 +120,7 @@ public async Task WhenABranchInTheStackExistsOnTheRemote_ButThePullRequestIsMerg inputProvider.Select(Questions.SelectStack, Arg.Any()).Returns("Stack1"); - gitHubClient.GetPullRequest(branch1).Returns(new GitHubPullRequest(1, Some.Name(), Some.Name(), GitHubPullRequestStates.Merged, Some.HttpsUri(), false, [])); + gitHubClient.GetPullRequest(branch1).Returns(new GitHubPullRequest(1, Some.Name(), Some.Name(), GitHubPullRequestStates.Merged, Some.HttpsUri(), false)); // Act await handler.Handle(new UpdateStackCommandInputs(null, false, false)); diff --git a/src/Stack.Tests/Helpers/TestGitHubRepositoryBuilder.cs b/src/Stack.Tests/Helpers/TestGitHubRepositoryBuilder.cs index a3faf9df..c47ec92b 100644 --- a/src/Stack.Tests/Helpers/TestGitHubRepositoryBuilder.cs +++ b/src/Stack.Tests/Helpers/TestGitHubRepositoryBuilder.cs @@ -5,7 +5,6 @@ namespace Stack.Tests.Helpers; public class TestGitHubRepositoryBuilder { readonly Dictionary pullRequests = new(); - readonly List labels = []; public TestGitHubRepositoryBuilder WithPullRequest(string branch, Action? pullRequestBuilder = null) { @@ -15,15 +14,9 @@ public TestGitHubRepositoryBuilder WithPullRequest(string branch, Action new GitHubLabel(l))]); + return new GitHubPullRequest(number, title, body, state, url, draft); } } -public class TestGitHubRepository(Dictionary PullRequests, string[] Labels) : IGitHubClient +public class TestGitHubRepository(Dictionary PullRequests) : IGitHubClient { public Dictionary PullRequests { get; } = PullRequests; - public string[] Labels { get; } = Labels; public GitHubPullRequest CreatePullRequest( string headBranch, string baseBranch, string title, string bodyFilePath, - string[] labels, bool draft) { var prBody = File.ReadAllText(bodyFilePath).Trim(); - var pr = new GitHubPullRequest(Some.Int(), title, prBody, GitHubPullRequestStates.Open, Some.HttpsUri(), draft, [.. labels.Select(l => new GitHubLabel(l))]); + var pr = new GitHubPullRequest(Some.Int(), title, prBody, GitHubPullRequestStates.Open, Some.HttpsUri(), draft); PullRequests.Add(headBranch, pr); return pr; } @@ -99,9 +89,4 @@ public void EditPullRequest(int number, string body) public void OpenPullRequest(GitHubPullRequest pullRequest) { } - - public string[] GetLabels() - { - return Labels; - } } \ No newline at end of file diff --git a/src/Stack/Commands/Helpers/Questions.cs b/src/Stack/Commands/Helpers/Questions.cs index 53696d9c..64ea871b 100644 --- a/src/Stack/Commands/Helpers/Questions.cs +++ b/src/Stack/Commands/Helpers/Questions.cs @@ -19,7 +19,6 @@ public static class Questions public const string ConfirmCreatePullRequests = "Are you sure you want to create pull requests for branches in this stack?"; public const string PullRequestTitle = "Title:"; public const string PullRequestStackDescription = "Stack description for pull request:"; - public const string PullRequestLabels = "Labels to apply to pull request (optional):"; public const string OpenPullRequests = "Open new pull requests in a browser?"; public const string CreatePullRequestAsDraft = "Create pull request as draft?"; public const string EditPullRequestBody = "Edit pull request body? This will open a file in your default editor."; diff --git a/src/Stack/Commands/PullRequests/CreatePullRequestsCommand.cs b/src/Stack/Commands/PullRequests/CreatePullRequestsCommand.cs index a418a6a6..2c71b2ac 100644 --- a/src/Stack/Commands/PullRequests/CreatePullRequestsCommand.cs +++ b/src/Stack/Commands/PullRequests/CreatePullRequestsCommand.cs @@ -185,7 +185,6 @@ private static List CreatePullRequests( action.BaseBranch, action.Title!, action.BodyFilePath!, - action.Labels, action.Draft); if (pullRequest is not null) @@ -216,7 +215,7 @@ private static void OutputUpdatedStackStatus(ILogger logger, Config.Stack stack, var action = pullRequestCreateActions.FirstOrDefault(a => a.HeadBranch == branch); if (action is not null) { - branchDisplayItems.Add($"{StackHelpers.GetBranchStatusOutput(branch, parentBranch, branchDetail)} {$"*NEW* {action.Title}".Highlighted()}{(action.Draft == true ? " (draft)".Muted() : string.Empty)}{(action.Labels.Length > 0 ? Markup.Escape($" [{string.Join(", ", action.Labels)}]").Muted() : string.Empty)}"); + branchDisplayItems.Add($"{StackHelpers.GetBranchStatusOutput(branch, parentBranch, branchDetail)} {$"*NEW* {action.Title}".Highlighted()}{(action.Draft == true ? " (draft)".Muted() : string.Empty)}"); } else { @@ -251,8 +250,6 @@ private static List GetPullRequestInformation( logger.Information($"Found pull request template in repository, this will be used as the default body for each pull request."); } - var gitHubLabels = gitHubClient.GetLabels(); - foreach (var action in pullRequestCreateActions) { logger.NewLine(); @@ -279,17 +276,6 @@ private static List GetPullRequestInformation( gitClient.OpenFileInEditorAndWaitForClose(bodyFilePath); } - string[] labels = []; - - if (gitHubLabels.Length > 0) - { - labels = inputProvider.MultiSelect( - logger, - Questions.PullRequestLabels, - gitHubLabels, - false); - } - var draft = inputProvider.Confirm(Questions.CreatePullRequestAsDraft, false); pullRequestActions.Add(new PullRequestInformation( @@ -297,7 +283,6 @@ private static List GetPullRequestInformation( action.BaseBranch, title, bodyFilePath, - [.. labels], draft)); } @@ -309,7 +294,6 @@ record PullRequestInformation( string BaseBranch, string Title, string BodyFilePath, - string[] Labels, bool Draft); public record PullRequestCreateAction(string Branch, string BaseBranch); diff --git a/src/Stack/Git/GitHubClient.cs b/src/Stack/Git/GitHubClient.cs index 85f70871..1a3619e9 100644 --- a/src/Stack/Git/GitHubClient.cs +++ b/src/Stack/Git/GitHubClient.cs @@ -17,9 +17,7 @@ public static class GitHubPullRequestStates public const string Merged = "MERGED"; } -public record GitHubPullRequest(int Number, string Title, string Body, string State, Uri Url, bool IsDraft, GitHubLabel[] Labels); - -public record GitHubLabel(string Name); +public record GitHubPullRequest(int Number, string Title, string Body, string State, Uri Url, bool IsDraft); public static class GitHubPullRequestExtensionMethods { @@ -51,18 +49,16 @@ GitHubPullRequest CreatePullRequest( string baseBranch, string title, string bodyFilePath, - string[] labels, bool draft); void EditPullRequest(int number, string body); void OpenPullRequest(GitHubPullRequest pullRequest); - string[] GetLabels(); } public class GitHubClient(ILogger logger, GitHubClientSettings settings) : IGitHubClient { public GitHubPullRequest? GetPullRequest(string branch) { - var output = ExecuteGitHubCommandAndReturnOutput($"pr list --json title,number,body,state,url,isDraft,labels --head {branch} --state all"); + var output = ExecuteGitHubCommandAndReturnOutput($"pr list --json title,number,body,state,url,isDraft --head {branch} --state all"); var pullRequests = System.Text.Json.JsonSerializer.Deserialize>(output, new System.Text.Json.JsonSerializerOptions(System.Text.Json.JsonSerializerDefaults.Web))!; @@ -74,7 +70,6 @@ public GitHubPullRequest CreatePullRequest( string baseBranch, string title, string bodyFilePath, - string[] labels, bool draft) { var command = $"pr create --title \"{Sanitize(title)}\" --body-file \"{bodyFilePath}\" --base {baseBranch} --head {headBranch}"; @@ -84,11 +79,6 @@ public GitHubPullRequest CreatePullRequest( command += " --draft"; } - if (labels.Length > 0) - { - command += " --label " + string.Join(',', labels.Select(l => Sanitize(l))); - } - ExecuteGitHubCommand(command); return GetPullRequest(headBranch) ?? throw new Exception("Failed to create pull request."); @@ -104,15 +94,6 @@ public void OpenPullRequest(GitHubPullRequest pullRequest) ExecuteGitHubCommand($"pr view {pullRequest.Number} --web"); } - public string[] GetLabels() - { - var output = ExecuteGitHubCommandAndReturnOutput($"label list --limit {int.MaxValue} --json name"); - var labels = System.Text.Json.JsonSerializer.Deserialize>(output, - new System.Text.Json.JsonSerializerOptions(System.Text.Json.JsonSerializerDefaults.Web))!; - - return [.. labels.Select(l => l.Name)]; - } - private string ExecuteGitHubCommandAndReturnOutput(string command) { if (settings.Verbose)