Skip to content
Permalink
Browse files
419: /issue add should allow project names in lower case
Reviewed-by: ehelin
  • Loading branch information
rwestberg committed Jun 17, 2020
1 parent 1f6b323 commit ca39c57bf150c55fce30c74e2756b7afb0aa0645
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
@@ -82,7 +82,7 @@ private List<Issue> parseIssueList(String allowedPrefix, String issueList) throw
.collect(Collectors.toList());
}
for (var issue : ret) {
if (issue.project().isPresent() && !issue.project().get().equals(allowedPrefix)) {
if (issue.project().isPresent() && !issue.project().get().equalsIgnoreCase(allowedPrefix)) {
throw new InvalidIssue(issue.id(), "This PR can only solve issues in the " + allowedPrefix + " project");
}
}
@@ -382,4 +382,71 @@ void issueInBody(TestInfo testInfo) throws IOException {
assertTrue(pr.body().contains("## Issues\n"));
}
}

@Test
void projectPrefix(TestInfo testInfo) throws IOException {
try (var credentials = new HostCredentials(testInfo);
var tempFolder = new TemporaryDirectory()) {
var author = credentials.getHostedRepository();
var integrator = credentials.getHostedRepository();

var issueProject = credentials.getIssueProject();
var censusBuilder = credentials.getCensusBuilder()
.addAuthor(author.forge().currentUser().id());
var prBot = PullRequestBot.newBuilder()
.repo(integrator)
.censusRepo(censusBuilder.build())
.issueProject(issueProject)
.build();

// Populate the projects repository
var localRepo = CheckableRepository.init(tempFolder.path(), author.repositoryType());
var masterHash = localRepo.resolve("master").orElseThrow();
assertFalse(CheckableRepository.hasBeenEdited(localRepo));
localRepo.push(masterHash, author.url(), "master", true);

// Create issues
var issue1 = credentials.createIssue(issueProject, "Issue 1");
var issue2 = credentials.createIssue(issueProject, "Issue 2");

// Make a change with a corresponding PR
var editHash = CheckableRepository.appendAndCommit(localRepo);
localRepo.push(editHash, author.url(), "edit", true);
var pr = credentials.createPullRequest(author, "master", "edit", issue1.id() + ": This is a pull request");
TestBotRunner.runPeriodicItems(prBot);

// Add variations of this issue
pr.addComment("/issue add " + issue2.id().toLowerCase());
TestBotRunner.runPeriodicItems(prBot);

// The bot should reply with a success message
assertLastCommentContains(pr,"Adding additional issue to issue list");

pr.addComment("/issue remove " + issue2.id().toLowerCase());
TestBotRunner.runPeriodicItems(prBot);

// The bot should reply with a success message
assertLastCommentContains(pr,"Removing additional issue from issue list");

// Add variations of this issue
pr.addComment("/issue add " + issue2.id().toUpperCase());
TestBotRunner.runPeriodicItems(prBot);

// The bot should reply with a success message
assertLastCommentContains(pr,"Adding additional issue to issue list");

pr.addComment("/issue remove " + issue2.id().toUpperCase());
TestBotRunner.runPeriodicItems(prBot);

// The bot should reply with a success message
assertLastCommentContains(pr,"Removing additional issue from issue list");

// Add variations of this issue
pr.addComment("/issue add " + issue2.id().split("-")[1]);
TestBotRunner.runPeriodicItems(prBot);

// The bot should reply with a success message
assertLastCommentContains(pr,"Adding additional issue to issue list");
}
}
}

1 comment on commit ca39c57

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on ca39c57 Jun 17, 2020

Choose a reason for hiding this comment

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

Please sign in to comment.