|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
@@ -1412,4 +1412,96 @@ void defer(TestInfo testInfo) throws IOException {
|
1412 | 1412 | assertFalse(authorPr.labelNames().contains("deferred"));
|
1413 | 1413 | }
|
1414 | 1414 | }
|
| 1415 | + |
| 1416 | + /** |
| 1417 | + * When an author types the command `/integrate`, the label `sponsor` should be added. |
| 1418 | + * If the author becomes a committer and types the command `/integrate` again, |
| 1419 | + * the label `sponsor` should be removed which is similar to the labels `rfr` and `ready`. |
| 1420 | + */ |
| 1421 | + @Test |
| 1422 | + void sponsor(TestInfo testInfo) throws IOException { |
| 1423 | + try (var credentials = new HostCredentials(testInfo); |
| 1424 | + var tempFolder = new TemporaryDirectory(); |
| 1425 | + var pushedFolder = new TemporaryDirectory()) { |
| 1426 | + |
| 1427 | + var botUser = credentials.getHostedRepository(); |
| 1428 | + var author = credentials.getHostedRepository(); |
| 1429 | + var reviewer = credentials.getHostedRepository(); |
| 1430 | + var censusBuilder = credentials.getCensusBuilder() |
| 1431 | + .addAuthor(author.forge().currentUser().id()) |
| 1432 | + .addReviewer(reviewer.forge().currentUser().id()); |
| 1433 | + var authorBot = PullRequestBot.newBuilder().repo(botUser).censusRepo(censusBuilder.build()).build(); |
| 1434 | + |
| 1435 | + // Populate the projects repository |
| 1436 | + var localRepo = CheckableRepository.init(tempFolder.path(), author.repositoryType()); |
| 1437 | + var masterHash = localRepo.resolve("master").orElseThrow(); |
| 1438 | + assertFalse(CheckableRepository.hasBeenEdited(localRepo)); |
| 1439 | + localRepo.push(masterHash, author.url(), "master", true); |
| 1440 | + |
| 1441 | + // Make a change with a corresponding PR |
| 1442 | + var editHash = CheckableRepository.appendAndCommit(localRepo); |
| 1443 | + localRepo.push(editHash, author.url(), "refs/heads/edit", true); |
| 1444 | + var authorPr = credentials.createPullRequest(author, "master", "edit", "This is a pull request"); |
| 1445 | + |
| 1446 | + // Approve it as another user |
| 1447 | + var reviewerPr = reviewer.pullRequest(authorPr.id()); |
| 1448 | + reviewerPr.addReview(Review.Verdict.APPROVED, "Approved"); |
| 1449 | + |
| 1450 | + // Issue an integrate command without being a Committer |
| 1451 | + authorPr.addComment("/integrate"); |
| 1452 | + TestBotRunner.runPeriodicItems(authorBot); |
| 1453 | + |
| 1454 | + // The bot should reply that a sponsor is required |
| 1455 | + var sponsor = authorPr.comments().stream() |
| 1456 | + .filter(comment -> comment.body().contains("sponsor")) |
| 1457 | + .filter(comment -> comment.body().contains("your change")) |
| 1458 | + .count(); |
| 1459 | + assertEquals(1, sponsor); |
| 1460 | + assertFalse(authorPr.labelNames().contains("integrated")); |
| 1461 | + assertTrue(authorPr.labelNames().contains("sponsor")); |
| 1462 | + assertTrue(authorPr.labelNames().contains("rfr")); |
| 1463 | + assertTrue(authorPr.labelNames().contains("ready")); |
| 1464 | + |
| 1465 | + // The bot should not have pushed the commit |
| 1466 | + var notPushed = authorPr.comments().stream() |
| 1467 | + .filter(comment -> comment.body().contains("Pushed as commit")) |
| 1468 | + .count(); |
| 1469 | + assertEquals(0, notPushed); |
| 1470 | + |
| 1471 | + // Mark the PR author a committer |
| 1472 | + var committerCensusBuilder = credentials.getCensusBuilder() |
| 1473 | + .addCommitter(author.forge().currentUser().id()) |
| 1474 | + .addReviewer(reviewer.forge().currentUser().id()); |
| 1475 | + var committerBot = PullRequestBot.newBuilder().repo(botUser).censusRepo(committerCensusBuilder.build()).build(); |
| 1476 | + |
| 1477 | + // Issue an integrate command while being a Committer |
| 1478 | + authorPr.addComment("/integrate"); |
| 1479 | + TestBotRunner.runPeriodicItems(committerBot); |
| 1480 | + |
| 1481 | + // The bot should have pushed the commit |
| 1482 | + var pushed = authorPr.comments().stream() |
| 1483 | + .filter(comment -> comment.body().contains("Pushed as commit")) |
| 1484 | + .count(); |
| 1485 | + assertEquals(1, pushed); |
| 1486 | + |
| 1487 | + // The corresponding labels should have been adjusted |
| 1488 | + assertTrue(authorPr.labelNames().contains("integrated")); |
| 1489 | + assertFalse(authorPr.labelNames().contains("sponsor")); |
| 1490 | + assertFalse(authorPr.labelNames().contains("rfr")); |
| 1491 | + assertFalse(authorPr.labelNames().contains("ready")); |
| 1492 | + |
| 1493 | + // The change should now be present on the master branch |
| 1494 | + var pushedRepo = Repository.materialize(pushedFolder.path(), author.url(), "master"); |
| 1495 | + assertTrue(CheckableRepository.hasBeenEdited(pushedRepo)); |
| 1496 | + |
| 1497 | + var headHash = pushedRepo.resolve("HEAD").orElseThrow(); |
| 1498 | + var headCommit = pushedRepo.commits(headHash.hex() + "^.." + headHash.hex()).asList().get(0); |
| 1499 | + |
| 1500 | + // Verify that the author and committer of the change are the correct users |
| 1501 | + assertEquals("Generated Committer 1", headCommit.author().name()); |
| 1502 | + assertEquals("integrationcommitter1@openjdk.java.net", headCommit.author().email()); |
| 1503 | + assertEquals("Generated Committer 1", headCommit.committer().name()); |
| 1504 | + assertEquals("integrationcommitter1@openjdk.java.net", headCommit.committer().email()); |
| 1505 | + } |
| 1506 | + } |
1415 | 1507 | }
|
1 commit comments
openjdk-notifier[bot] commentedon Feb 9, 2022
Review
Issues