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
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ A custom description

var expectedPullRequests = new Dictionary<string, GitHubPullRequest>
{
[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, branch1),
[branch2] = new GitHubPullRequest(2, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false, branch2)
};

gitHubClient.PullRequests.Should().BeEquivalentTo(expectedPullRequests, ExcludeUnimportantPullRequestProperties);
Expand Down Expand Up @@ -170,7 +170,6 @@ public async Task WhenAPullRequestExistForABranch_AndNoneForAnotherBranch_Create
var gitClient = new GitClient(logger, repo.GitClientSettings);
var handler = new CreatePullRequestsCommandHandler(inputProvider, logger, gitClient, gitHubClient, fileOperations, stackConfig);


inputProvider.Select(Questions.SelectStack, Arg.Any<string[]>()).Returns("Stack1");
inputProvider
.MultiSelect(Questions.SelectPullRequestsToCreate, Arg.Any<PullRequestCreateAction[]>(), true, Arg.Any<Func<PullRequestCreateAction, string>>())
Expand Down Expand Up @@ -246,8 +245,8 @@ A custom description

var expectedPullRequests = new Dictionary<string, GitHubPullRequest>
{
[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, branch1),
[branch2] = new GitHubPullRequest(2, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false, branch2)
};

gitHubClient.PullRequests.Should().BeEquivalentTo(expectedPullRequests, ExcludeUnimportantPullRequestProperties);
Expand Down Expand Up @@ -301,8 +300,8 @@ A custom description

var expectedPullRequests = new Dictionary<string, GitHubPullRequest>
{
[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, branch1),
[branch2] = new GitHubPullRequest(2, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false, branch2)
};

gitHubClient.PullRequests.Should().BeEquivalentTo(expectedPullRequests, ExcludeUnimportantPullRequestProperties);
Expand Down Expand Up @@ -408,8 +407,8 @@ A custom description

var expectedPullRequests = new Dictionary<string, GitHubPullRequest>
{
[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, branch1),
[branch2] = new GitHubPullRequest(2, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false, branch2)
};

gitHubClient.PullRequests.Should().BeEquivalentTo(expectedPullRequests, ExcludeUnimportantPullRequestProperties);
Expand Down Expand Up @@ -472,8 +471,8 @@ A custom description

var expectedPullRequests = new Dictionary<string, GitHubPullRequest>
{
[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, branch1),
[branch2] = new GitHubPullRequest(2, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false, branch2)
};

gitHubClient.PullRequests.Should().BeEquivalentTo(expectedPullRequests, ExcludeUnimportantPullRequestProperties);
Expand Down Expand Up @@ -530,7 +529,7 @@ public async Task WhenAPullRequestTemplateDoesNotExistInTheRepo_TheStackPrListMa

var expectedPullRequests = new Dictionary<string, GitHubPullRequest>
{
[branch1] = new GitHubPullRequest(1, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false)
[branch1] = new GitHubPullRequest(1, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false, branch1)
};

gitHubClient.PullRequests.Should().BeEquivalentTo(expectedPullRequests, ExcludeUnimportantPullRequestProperties);
Expand Down Expand Up @@ -636,7 +635,7 @@ public async Task WhenOnlySelectingSomeBranchesToCreatePullRequestsFor_OnlyThose

var expectedPullRequests = new Dictionary<string, GitHubPullRequest>
{
[branch1] = new GitHubPullRequest(1, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false)
[branch1] = new GitHubPullRequest(1, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false, branch1)
};

gitHubClient.PullRequests.Should().BeEquivalentTo(expectedPullRequests, ExcludeUnimportantPullRequestProperties);
Expand Down Expand Up @@ -694,8 +693,8 @@ A custom description

var expectedPullRequests = new Dictionary<string, GitHubPullRequest>
{
[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, branch1),
[branch2] = new GitHubPullRequest(2, "PR Title", expectedPrBody, GitHubPullRequestStates.Open, Some.HttpsUri(), false, branch2)
};

gitHubClient.PullRequests.Should().BeEquivalentTo(expectedPullRequests, ExcludeUnimportantPullRequestProperties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ public async Task WhenThereAreMultiplePullRequestsInAStack_OpensAllPullRequests(

inputProvider.Select(Questions.SelectStack, Arg.Any<string[]>()).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, branch1);
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, branch2);
gitHubClient
.GetPullRequest(branch2)
.Returns(prForBranch2);
Expand Down Expand Up @@ -98,12 +98,12 @@ public async Task WhenThereAreSomePullRequestsInAStack_OpensAllPullRequests()

inputProvider.Select(Questions.SelectStack, Arg.Any<string[]>()).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, branch1);
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, branch2);

// Act
await handler.Handle(OpenPullRequestsCommandInputs.Empty);
Expand Down Expand Up @@ -145,12 +145,12 @@ public async Task WhenStackNameIsProvided_OpensAllPullRequestsForTheStack()
var gitClient = new GitClient(logger, repo.GitClientSettings);
var handler = new OpenPullRequestsCommandHandler(inputProvider, logger, gitClient, gitHubClient, stackConfig);

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, branch1);
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, branch2);
gitHubClient
.GetPullRequest(branch2)
.Returns(prForBranch2);
Expand Down Expand Up @@ -191,12 +191,12 @@ public async Task WhenOnlyOneStackExists_DoesNotAskForStackName_OpensAllPullRequ
var gitClient = new GitClient(logger, repo.GitClientSettings);
var handler = new OpenPullRequestsCommandHandler(inputProvider, logger, gitClient, gitHubClient, stackConfig);

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, branch1);
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, branch2);
gitHubClient
.GetPullRequest(branch2)
.Returns(prForBranch2);
Expand Down
14 changes: 7 additions & 7 deletions src/Stack.Tests/Commands/Stack/StackStatusCommandHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public async Task WhenMultipleBranchesExistInAStack_AndOneHasAPullRequests_Retur

inputProvider.Select(Questions.SelectStack, Arg.Any<string[]>()).Returns("Stack1");

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, branch1);

gitHubClient.GetPullRequest(branch1).Returns(pr);

Expand Down Expand Up @@ -112,7 +112,7 @@ public async Task WhenStackNameIsProvided_DoesNotAskForStack_ReturnsStatus()

inputProvider.Select(Questions.SelectStack, Arg.Any<string[]>()).Returns("Stack1");

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, branch1);

gitHubClient.GetPullRequest(branch1).Returns(pr);

Expand Down Expand Up @@ -180,7 +180,7 @@ public async Task WhenAllStacksAreRequested_ReturnsStatusOfEachStack()
var gitHubClient = Substitute.For<IGitHubClient>();
var handler = new StackStatusCommandHandler(inputProvider, logger, gitClient, gitHubClient, stackConfig);

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, branch1);

gitHubClient
.GetPullRequest(branch1)
Expand Down Expand Up @@ -261,7 +261,7 @@ public async Task WhenAllStacksAreRequested_WithStacksInMultipleRepositories_Ret
var gitHubClient = Substitute.For<IGitHubClient>();
var handler = new StackStatusCommandHandler(inputProvider, logger, gitClient, gitHubClient, stackConfig);

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, branch1);

gitHubClient.GetPullRequest(branch1).Returns(pr);

Expand Down Expand Up @@ -376,7 +376,7 @@ public async Task WhenMultipleBranchesExistInAStack_AndOneNoLongerExistsOnTheRem

inputProvider.Select(Questions.SelectStack, Arg.Any<string[]>()).Returns("Stack1");

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, branch2);

gitHubClient
.GetPullRequest(branch2)
Expand Down Expand Up @@ -440,7 +440,7 @@ public async Task WhenMultipleBranchesExistInAStack_AndOneNoLongerExistsOnTheRem

inputProvider.Select(Questions.SelectStack, Arg.Any<string[]>()).Returns("Stack1");

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, branch2);

gitHubClient
.GetPullRequest(branch2)
Expand Down Expand Up @@ -497,7 +497,7 @@ public async Task WhenOnlyOneStackExists_DoesNotAskForStackName_ReturnsStatus()
var gitHubClient = Substitute.For<IGitHubClient>();
var handler = new StackStatusCommandHandler(inputProvider, logger, gitClient, gitHubClient, stackConfig);

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, branch1);

gitHubClient
.GetPullRequest(branch1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public async Task WhenABranchInTheStackExistsOnTheRemote_ButThePullRequestIsMerg

inputProvider.Select(Questions.SelectStack, Arg.Any<string[]>()).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, branch1));

// Act
await handler.Handle(new UpdateStackCommandInputs(null, false, true));
Expand Down
14 changes: 11 additions & 3 deletions src/Stack.Tests/Helpers/TestGitHubRepositoryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ public class TestGitHubRepositoryBuilder

public TestGitHubRepositoryBuilder WithPullRequest(string branch, Action<TestGitHubPullRequestBuilder>? pullRequestBuilder = null)
{
var builder = new TestGitHubPullRequestBuilder();
var builder = new TestGitHubPullRequestBuilder()
.WithHeadRefName(branch);
pullRequestBuilder?.Invoke(builder);
pullRequests.Add(branch, builder.Build());
return this;
Expand All @@ -28,6 +29,7 @@ public class TestGitHubPullRequestBuilder
string state = GitHubPullRequestStates.Open;
Uri url = Some.HttpsUri();
bool draft = false;
string headRefName = Some.Name();

public TestGitHubPullRequestBuilder WithTitle(string title)
{
Expand All @@ -47,9 +49,15 @@ public TestGitHubPullRequestBuilder Merged()
return this;
}

public TestGitHubPullRequestBuilder WithHeadRefName(string headRefName)
{
this.headRefName = headRefName;
return this;
}

public GitHubPullRequest Build()
{
return new GitHubPullRequest(number, title, body, state, url, draft);
return new GitHubPullRequest(number, title, body, state, url, draft, headRefName);
}
}

Expand All @@ -65,7 +73,7 @@ public GitHubPullRequest CreatePullRequest(
bool draft)
{
var prBody = File.ReadAllText(bodyFilePath).Trim();
var pr = new GitHubPullRequest(Some.Int(), title, prBody, GitHubPullRequestStates.Open, Some.HttpsUri(), draft);
var pr = new GitHubPullRequest(Some.Int(), title, prBody, GitHubPullRequestStates.Open, Some.HttpsUri(), draft, headBranch);
PullRequests.Add(headBranch, pr);
return pr;
}
Expand Down
Loading
Loading