< prev index next >

bots/bridgekeeper/src/test/java/org/openjdk/skara/bots/bridgekeeper/PullRequestPrunerBotTests.java

Print this page

 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.bridgekeeper;
 24 
 25 import org.openjdk.skara.test.*;
 26 
 27 import org.junit.jupiter.api.*;
 28 
 29 import java.io.IOException;
 30 import java.time.Duration;
 31 
 32 import static org.junit.jupiter.api.Assertions.assertEquals;
 33 
 34 class PullRequestPrunerBotTests {
 35     @Test
 36     void close(TestInfo testInfo) throws IOException, InterruptedException {
 37         try (var credentials = new HostCredentials(testInfo);
 38              var tempFolder = new TemporaryDirectory()) {
 39             var author = credentials.getHostedRepository();
 40             var bot = new PullRequestPrunerBot(author, Duration.ofMillis(1));
 41 
 42             // Populate the projects repository
 43             var localRepo = CheckableRepository.init(tempFolder.path(), author.repositoryType());
 44             var masterHash = localRepo.resolve("master").orElseThrow();
 45             localRepo.push(masterHash, author.url(), "master", true);
 46 
 47             // Make a change with a corresponding PR
 48             var editHash = CheckableRepository.appendAndCommit(localRepo);
 49             localRepo.push(editHash, author.url(), "edit", true);
 50             var pr = credentials.createPullRequest(author, "master", "edit", "This is a pull request");
 51 
 52             // Make sure the timeout expires
 53             Thread.sleep(100);
 54 
 55             // Let the bot see it




















 56             TestBotRunner.runPeriodicItems(bot);
 57 
 58             // There should now be no open PRs
 59             var prs = author.pullRequests();
 60             assertEquals(0, prs.size());
 61         }
 62     }
 63 
 64     @Test
 65     void dontClose(TestInfo testInfo) throws IOException {
 66         try (var credentials = new HostCredentials(testInfo);
 67              var tempFolder = new TemporaryDirectory()) {
 68             var author = credentials.getHostedRepository();
 69             var bot = new PullRequestPrunerBot(author, Duration.ofDays(3));
 70 
 71             // Populate the projects repository
 72             var localRepo = CheckableRepository.init(tempFolder.path(), author.repositoryType());
 73             var masterHash = localRepo.resolve("master").orElseThrow();
 74             localRepo.push(masterHash, author.url(), "master", true);
 75 

 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.bridgekeeper;
 24 
 25 import org.openjdk.skara.test.*;
 26 
 27 import org.junit.jupiter.api.*;
 28 
 29 import java.io.IOException;
 30 import java.time.Duration;
 31 
 32 import static org.junit.jupiter.api.Assertions.*;
 33 
 34 class PullRequestPrunerBotTests {
 35     @Test
 36     void close(TestInfo testInfo) throws IOException, InterruptedException {
 37         try (var credentials = new HostCredentials(testInfo);
 38              var tempFolder = new TemporaryDirectory()) {
 39             var author = credentials.getHostedRepository();
 40             var bot = new PullRequestPrunerBot(author, Duration.ofMillis(1));
 41 
 42             // Populate the projects repository
 43             var localRepo = CheckableRepository.init(tempFolder.path(), author.repositoryType());
 44             var masterHash = localRepo.resolve("master").orElseThrow();
 45             localRepo.push(masterHash, author.url(), "master", true);
 46 
 47             // Make a change with a corresponding PR
 48             var editHash = CheckableRepository.appendAndCommit(localRepo);
 49             localRepo.push(editHash, author.url(), "edit", true);
 50             var pr = credentials.createPullRequest(author, "master", "edit", "This is a pull request");
 51 
 52             // Make sure the timeout expires
 53             Thread.sleep(100);
 54 
 55             // Let the bot see it - it should give a notice
 56             TestBotRunner.runPeriodicItems(bot);
 57 
 58             assertEquals(1, pr.comments().size());
 59             assertTrue(pr.comments().get(0).body().contains("will be automatically closed if"));
 60 
 61             pr.addComment("I'm still working on it!");
 62 
 63             // Make sure the timeout expires again
 64             Thread.sleep(100);
 65 
 66             // Let the bot see it - it should post a second notice
 67             TestBotRunner.runPeriodicItems(bot);
 68 
 69             assertEquals(3, pr.comments().size());
 70             assertTrue(pr.comments().get(2).body().contains("will be automatically closed if"));
 71 
 72             // Make sure the timeout expires again
 73             Thread.sleep(100);
 74 
 75             // The bot should now close it
 76             TestBotRunner.runPeriodicItems(bot);
 77 
 78             // There should now be no open PRs
 79             var prs = author.pullRequests();
 80             assertEquals(0, prs.size());
 81         }
 82     }
 83 
 84     @Test
 85     void dontClose(TestInfo testInfo) throws IOException {
 86         try (var credentials = new HostCredentials(testInfo);
 87              var tempFolder = new TemporaryDirectory()) {
 88             var author = credentials.getHostedRepository();
 89             var bot = new PullRequestPrunerBot(author, Duration.ofDays(3));
 90 
 91             // Populate the projects repository
 92             var localRepo = CheckableRepository.init(tempFolder.path(), author.repositoryType());
 93             var masterHash = localRepo.resolve("master").orElseThrow();
 94             localRepo.push(masterHash, author.url(), "master", true);
 95 
< prev index next >