< prev index next >

bots/pr/src/test/java/org/openjdk/skara/bots/pr/CheckTests.java

Print this page

 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 package org.openjdk.skara.bots.pr;
 24 
 25 import org.openjdk.skara.host.*;
 26 import org.openjdk.skara.test.*;
 27 
 28 import org.junit.jupiter.api.*;
 29 
 30 import java.io.IOException;
 31 import java.nio.file.Files;
 32 import java.util.*;
 33 import java.util.regex.Pattern;
 34 
 35 import static org.junit.jupiter.api.Assertions.*;
 36 import static org.junit.jupiter.api.Assumptions.assumeTrue;
 37 
 38 class CheckTests {
 39     @Test
 40     void simpleCommit(TestInfo testInfo) throws IOException {
 41         try (var credentials = new HostCredentials(testInfo);
 42              var tempFolder = new TemporaryDirectory()) {
 43             var author = credentials.getHostedRepository();
 44             var reviewer = credentials.getHostedRepository();
 45 
 46             var censusBuilder = credentials.getCensusBuilder()
 47                                            .addAuthor(author.host().getCurrentUserDetails().id())
 48                                            .addReviewer(reviewer.host().getCurrentUserDetails().id());
 49             var checkBot = new PullRequestBot(author, censusBuilder.build(), "master");
 50 
 51             // Populate the projects repository

716 
717             // Check the status
718             TestBotRunner.runPeriodicItems(checkBot);
719 
720             // Verify that no checks have been run
721             var checks = pr.getChecks(editHash);
722             assertEquals(0, checks.size());
723 
724             // The PR should not yet be ready for review
725             assertFalse(pr.getLabels().contains("rfr"));
726 
727             // Check the status again
728             var reviewerPr = reviewer.getPullRequest(pr.getId());
729             reviewerPr.addComment("proceed");
730             TestBotRunner.runPeriodicItems(checkBot);
731 
732             // The PR should now be ready for review
733             assertTrue(pr.getLabels().contains("rfr"));
734         }
735     }















































736 }

 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 package org.openjdk.skara.bots.pr;
 24 
 25 import org.openjdk.skara.host.*;
 26 import org.openjdk.skara.test.*;
 27 
 28 import org.junit.jupiter.api.*;
 29 
 30 import java.io.IOException;
 31 import java.nio.file.*;
 32 import java.util.*;
 33 import java.util.regex.Pattern;
 34 
 35 import static org.junit.jupiter.api.Assertions.*;
 36 import static org.junit.jupiter.api.Assumptions.assumeTrue;
 37 
 38 class CheckTests {
 39     @Test
 40     void simpleCommit(TestInfo testInfo) throws IOException {
 41         try (var credentials = new HostCredentials(testInfo);
 42              var tempFolder = new TemporaryDirectory()) {
 43             var author = credentials.getHostedRepository();
 44             var reviewer = credentials.getHostedRepository();
 45 
 46             var censusBuilder = credentials.getCensusBuilder()
 47                                            .addAuthor(author.host().getCurrentUserDetails().id())
 48                                            .addReviewer(reviewer.host().getCurrentUserDetails().id());
 49             var checkBot = new PullRequestBot(author, censusBuilder.build(), "master");
 50 
 51             // Populate the projects repository

716 
717             // Check the status
718             TestBotRunner.runPeriodicItems(checkBot);
719 
720             // Verify that no checks have been run
721             var checks = pr.getChecks(editHash);
722             assertEquals(0, checks.size());
723 
724             // The PR should not yet be ready for review
725             assertFalse(pr.getLabels().contains("rfr"));
726 
727             // Check the status again
728             var reviewerPr = reviewer.getPullRequest(pr.getId());
729             reviewerPr.addComment("proceed");
730             TestBotRunner.runPeriodicItems(checkBot);
731 
732             // The PR should now be ready for review
733             assertTrue(pr.getLabels().contains("rfr"));
734         }
735     }
736 
737     @Test
738     void issueIssue(TestInfo testInfo) throws IOException {
739         try (var credentials = new HostCredentials(testInfo);
740              var tempFolder = new TemporaryDirectory()) {
741             var author = credentials.getHostedRepository();
742             var reviewer = credentials.getHostedRepository();
743 
744             var censusBuilder = credentials.getCensusBuilder()
745                                            .addAuthor(author.host().getCurrentUserDetails().id())
746                                            .addReviewer(reviewer.host().getCurrentUserDetails().id());
747             var checkBot = new PullRequestBot(author, censusBuilder.build(), "master", Map.of(), Map.of(),
748                                               Map.of(), Set.of(), Map.of());
749 
750             // Populate the projects repository
751             var localRepo = CheckableRepository.init(tempFolder.path(), author.getRepositoryType(), Path.of("appendable.txt"),
752                                                      Set.of("issues"));
753             var masterHash = localRepo.resolve("master").orElseThrow();
754             localRepo.push(masterHash, author.getUrl(), "master", true);
755 
756             // Make a change with a corresponding PR
757             var editHash = CheckableRepository.appendAndCommit(localRepo);
758             localRepo.push(editHash, author.getUrl(), "edit", true);
759             var pr = credentials.createPullRequest(author, "master", "edit", "This is a pull request");
760 
761             // Check the status
762             TestBotRunner.runPeriodicItems(checkBot);
763 
764             // Verify that the check failed
765             var checks = pr.getChecks(editHash);
766             assertEquals(1, checks.size());
767             var check = checks.get("jcheck");
768             assertEquals(CheckStatus.FAILURE, check.status());
769 
770             // Add an issue to the title
771             pr.setTitle("1234: This is a pull request");
772 
773             // Check the status again
774             TestBotRunner.runPeriodicItems(checkBot);
775 
776             // The check should now be successful
777             checks = pr.getChecks(editHash);
778             assertEquals(1, checks.size());
779             check = checks.get("jcheck");
780             assertEquals(CheckStatus.SUCCESS, check.status());
781         }
782     }
783 }
< prev index next >