Skip to content

Commit

Permalink
Support fetching Jira issues with only a partial id
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin Westberg committed Oct 4, 2019
1 parent 1bf3e51 commit fb7a04b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
19 changes: 19 additions & 0 deletions bots/pr/src/test/java/org/openjdk/skara/bots/pr/CheckTests.java
Expand Up @@ -831,6 +831,25 @@ void issueInSummary(TestInfo testInfo) throws IOException {
assertFalse(pr.getBody().contains("My first issue"));
assertTrue(pr.getBody().contains("My second issue"));

// Use an invalid issue key
var issueKey = issue1.getId().replace("TEST", "BADPROJECT");
pr.setTitle(issueKey + ": This is a pull request");

// Check the status again
TestBotRunner.runPeriodicItems(checkBot);
assertFalse(pr.getBody().contains("My first issue"));
assertFalse(pr.getBody().contains("My second issue"));
assertTrue(pr.getBody().contains("Failed to retrieve"));

// Now drop the issue key
issueKey = issue1.getId().replace("TEST-", "");
pr.setTitle(issueKey + ": This is a pull request");

// The body should now contain the updated issue title
TestBotRunner.runPeriodicItems(checkBot);
assertTrue(pr.getBody().contains("My first issue"));
assertFalse(pr.getBody().contains("My second issue"));

// Now enter an invalid issue id
pr.setTitle("2384848: This is a pull request");

Expand Down
Expand Up @@ -57,6 +57,9 @@ public Issue createIssue(String title, List<String> body) {

@Override
public Optional<Issue> getIssue(String id) {
if (id.indexOf('-') < 0) {
id = projectName.toUpperCase() + "-" + id;
}
var issue = request.get("issue/" + id)
.onError(r -> r.statusCode() == 404 ? JSON.object().put("NOT_FOUND", true) : null)
.execute();
Expand Down
2 changes: 1 addition & 1 deletion test/src/main/java/org/openjdk/skara/test/TestHost.java
Expand Up @@ -161,7 +161,7 @@ List<TestPullRequest> getPullRequests(TestHostedRepository repository) {
}

TestIssue createIssue(TestIssueProject issueProject, String title, List<String> body) {
var id = String.valueOf(data.issues.size() + 1);
var id = issueProject.projectName().toUpperCase() + "-" + (data.issues.size() + 1);
var issue = TestIssue.createNew(issueProject, id, title, body);
data.issues.put(id ,issue);
return issue;
Expand Down
Expand Up @@ -32,6 +32,10 @@ public class TestIssueProject implements IssueProject {
private final String projectName;
private final TestHost host;

String projectName() {
return projectName;
}

@Override
public Host host() {
return host;
Expand All @@ -54,6 +58,10 @@ public Issue createIssue(String title, List<String> body) {

@Override
public Optional<Issue> getIssue(String id) {
if (id.indexOf('-') < 0) {
id = projectName.toUpperCase() + "-" + id;
}

return Optional.ofNullable(host.getIssue(this, id));
}

Expand Down

0 comments on commit fb7a04b

Please sign in to comment.