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.junit.jupiter.api.*;
26 import org.openjdk.skara.forge.Review;
27 import org.openjdk.skara.issuetracker.Comment;
28 import org.openjdk.skara.test.*;
29 import org.openjdk.skara.vcs.Repository;
30
31 import java.io.IOException;
32 import java.util.List;
33
34 import static org.junit.jupiter.api.Assertions.*;
35 import static org.openjdk.skara.bots.pr.PullRequestAsserts.assertLastCommentContains;
36
37 class SolvesTests {
38 @Test
39 void simple(TestInfo testInfo) throws IOException {
40 try (var credentials = new HostCredentials(testInfo);
41 var tempFolder = new TemporaryDirectory()) {
42 var author = credentials.getHostedRepository();
43 var integrator = credentials.getHostedRepository();
44
45 var censusBuilder = credentials.getCensusBuilder()
46 .addReviewer(integrator.forge().currentUser().id())
47 .addCommitter(author.forge().currentUser().id());
48 var prBot = new PullRequestBot(integrator, censusBuilder.build(), "master");
49
50 // Populate the projects repository
51 var localRepoFolder = tempFolder.path().resolve("localrepo");
52 var localRepo = CheckableRepository.init(localRepoFolder, author.repositoryType());
174
175 // Issue a solves command not as the PR author
176 var externalPr = external.pullRequest(pr.id());
177 externalPr.addComment("/solves 1234: an issue");
178 TestBotRunner.runPeriodicItems(mergeBot);
179
180 // The bot should reply with an error message
181 var error = pr.comments().stream()
182 .filter(comment -> comment.body().contains("Only the author"))
183 .count();
184 assertEquals(1, error);
185 }
186 }
187
188 @Test
189 void issueInTitle(TestInfo testInfo) throws IOException {
190 try (var credentials = new HostCredentials(testInfo);
191 var tempFolder = new TemporaryDirectory()) {
192 var author = credentials.getHostedRepository();
193 var integrator = credentials.getHostedRepository();
194 var external = credentials.getHostedRepository();
195
196 var censusBuilder = credentials.getCensusBuilder()
197 .addAuthor(author.forge().currentUser().id());
198 var prBot = new PullRequestBot(integrator, censusBuilder.build(), "master");
199
200 // Populate the projects repository
201 var localRepo = CheckableRepository.init(tempFolder.path(), author.repositoryType());
202 var masterHash = localRepo.resolve("master").orElseThrow();
203 assertFalse(CheckableRepository.hasBeenEdited(localRepo));
204 localRepo.push(masterHash, author.url(), "master", true);
205
206 // Make a change with a corresponding PR
207 var editHash = CheckableRepository.appendAndCommit(localRepo);
208 localRepo.push(editHash, author.url(), "edit", true);
209 var pr = credentials.createPullRequest(author, "master", "edit", "This is a pull request");
210
211 // Add an issue
212 pr.addComment("/solves 1234: An issue");
213 TestBotRunner.runPeriodicItems(prBot);
214
215 // The bot should reply with a success message
216 assertLastCommentContains(pr,"current title");
217
218 var updatedPr = author.pullRequest(pr.id());
219 assertEquals("1234: An issue", updatedPr.title());
220
221 // Update the issue description
222 pr.addComment("/solves 1234: Yes this is an issue");
223 TestBotRunner.runPeriodicItems(prBot);
224
225 // The bot should reply with a success message
226 assertLastCommentContains(pr,"will now be updated");
227
228 updatedPr = author.pullRequest(pr.id());
229 assertEquals("1234: Yes this is an issue", updatedPr.title());
230 }
231 }
232 }
|
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.junit.jupiter.api.*;
26 import org.openjdk.skara.forge.Review;
27 import org.openjdk.skara.issuetracker.Comment;
28 import org.openjdk.skara.test.*;
29 import org.openjdk.skara.vcs.Repository;
30
31 import java.io.IOException;
32 import java.util.*;
33
34 import static org.junit.jupiter.api.Assertions.*;
35 import static org.openjdk.skara.bots.pr.PullRequestAsserts.assertLastCommentContains;
36
37 class SolvesTests {
38 @Test
39 void simple(TestInfo testInfo) throws IOException {
40 try (var credentials = new HostCredentials(testInfo);
41 var tempFolder = new TemporaryDirectory()) {
42 var author = credentials.getHostedRepository();
43 var integrator = credentials.getHostedRepository();
44
45 var censusBuilder = credentials.getCensusBuilder()
46 .addReviewer(integrator.forge().currentUser().id())
47 .addCommitter(author.forge().currentUser().id());
48 var prBot = new PullRequestBot(integrator, censusBuilder.build(), "master");
49
50 // Populate the projects repository
51 var localRepoFolder = tempFolder.path().resolve("localrepo");
52 var localRepo = CheckableRepository.init(localRepoFolder, author.repositoryType());
174
175 // Issue a solves command not as the PR author
176 var externalPr = external.pullRequest(pr.id());
177 externalPr.addComment("/solves 1234: an issue");
178 TestBotRunner.runPeriodicItems(mergeBot);
179
180 // The bot should reply with an error message
181 var error = pr.comments().stream()
182 .filter(comment -> comment.body().contains("Only the author"))
183 .count();
184 assertEquals(1, error);
185 }
186 }
187
188 @Test
189 void issueInTitle(TestInfo testInfo) throws IOException {
190 try (var credentials = new HostCredentials(testInfo);
191 var tempFolder = new TemporaryDirectory()) {
192 var author = credentials.getHostedRepository();
193 var integrator = credentials.getHostedRepository();
194
195 var censusBuilder = credentials.getCensusBuilder()
196 .addAuthor(author.forge().currentUser().id());
197 var prBot = new PullRequestBot(integrator, censusBuilder.build(), "master");
198
199 // Populate the projects repository
200 var localRepo = CheckableRepository.init(tempFolder.path(), author.repositoryType());
201 var masterHash = localRepo.resolve("master").orElseThrow();
202 assertFalse(CheckableRepository.hasBeenEdited(localRepo));
203 localRepo.push(masterHash, author.url(), "master", true);
204
205 // Make a change with a corresponding PR
206 var editHash = CheckableRepository.appendAndCommit(localRepo);
207 localRepo.push(editHash, author.url(), "edit", true);
208 var pr = credentials.createPullRequest(author, "master", "edit", "This is a pull request");
209
210 // Add an issue
211 pr.addComment("/solves 1234: An issue");
212 TestBotRunner.runPeriodicItems(prBot);
213
214 // The bot should reply with a success message
215 assertLastCommentContains(pr,"current title");
216
217 var updatedPr = author.pullRequest(pr.id());
218 assertEquals("1234: An issue", updatedPr.title());
219
220 // Update the issue description
221 pr.addComment("/solves 1234: Yes this is an issue");
222 TestBotRunner.runPeriodicItems(prBot);
223
224 // The bot should reply with a success message
225 assertLastCommentContains(pr,"will now be updated");
226
227 updatedPr = author.pullRequest(pr.id());
228 assertEquals("1234: Yes this is an issue", updatedPr.title());
229 }
230 }
231
232 @Test
233 void issueInBody(TestInfo testInfo) throws IOException {
234 try (var credentials = new HostCredentials(testInfo);
235 var tempFolder = new TemporaryDirectory()) {
236 var author = credentials.getHostedRepository();
237 var integrator = credentials.getHostedRepository();
238 var issues = credentials.getIssueProject();
239
240 var censusBuilder = credentials.getCensusBuilder()
241 .addAuthor(author.forge().currentUser().id());
242 var prBot = new PullRequestBot(integrator, censusBuilder.build(), "master",
243 Map.of(), Map.of(), Map.of(), Set.of(), Map.of(), issues);
244
245 // Populate the projects repository
246 var localRepo = CheckableRepository.init(tempFolder.path(), author.repositoryType());
247 var masterHash = localRepo.resolve("master").orElseThrow();
248 assertFalse(CheckableRepository.hasBeenEdited(localRepo));
249 localRepo.push(masterHash, author.url(), "master", true);
250
251 // Make a change with a corresponding PR
252 var editHash = CheckableRepository.appendAndCommit(localRepo);
253 localRepo.push(editHash, author.url(), "edit", true);
254 var issue1 = issues.createIssue("First", List.of("Hello"));
255 var pr = credentials.createPullRequest(author, "master", "edit",
256 issue1.id() + ": This is a pull request");
257
258 // First check
259 TestBotRunner.runPeriodicItems(prBot);
260 assertTrue(pr.body().contains(issue1.id()));
261 assertTrue(pr.body().contains("First"));
262 assertTrue(pr.body().contains("## Issue\n"));
263
264 // Add an extra issue
265 var issue2 = issues.createIssue("Second", List.of("There"));
266 pr.addComment("/solves " + issue2.id() + ": Description");
267
268 // Check that the body was updated
269 TestBotRunner.runPeriodicItems(prBot);
270 TestBotRunner.runPeriodicItems(prBot);
271 assertTrue(pr.body().contains(issue1.id()));
272 assertTrue(pr.body().contains("First"));
273 assertTrue(pr.body().contains(issue2.id()));
274 assertTrue(pr.body().contains("Second"));
275 assertFalse(pr.body().contains("## Issue\n"));
276 assertTrue(pr.body().contains("## Issues\n"));
277 }
278 }
279 }
|