Skip to content

Commit

Permalink
🐛 missing action type; clear notification email
Browse files Browse the repository at this point in the history
  • Loading branch information
ebullient committed Jun 18, 2024
1 parent 857e2a8 commit afe1ae8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.commonhaus.automation.github.context;

public enum ActionType {
added,
answered,
category_changed,
closed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public void handleApplicationComment(ScopedQueryContext qc, DataCommonItem issue
"""
.formatted(comment.body.replaceAll("::response::", "").trim());

String htmlBody = MarkdownConverter.toHtml(body);
ctx.sendEmail(qc.getLogId(),
"Commonhaus Foundation Membership Application",
Expand Down Expand Up @@ -176,6 +177,11 @@ && isValid(notificationEmail)) {
throw qc.bundleExceptions();
}

if (isValid(notificationEmail)) {
// Try to remove the notification email from the issue body
String updated = MembershipApplicationData.NOTIFICATION.matcher(item.body).replaceAll("");
qc.updateItemDescription(EventType.issue, item.id, updated, DataCommonItem.ISSUE_FIELDS);
}
qc.closeIssue(issue);
qc.removeLabels(item.id, List.of(MembershipApplicationData.NEW));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ public static String issueContent(MemberSession session, ApplicationPost applica
<!--NOTES::-->
%s
<!--::NOTES-->
<!-- notify::%s -->
%s
""".formatted(
session.login(),
session.url(),
STRIP_COMMENTS.matcher(applicationPost.contributions()).replaceAll(" "),
STRIP_COMMENTS.matcher(applicationPost.additionalNotes()).replaceAll(" "),
notificationEmail);
notificationEmail == null ? "" : "<!-- notify::%s -->".formatted(notificationEmail));
}

public static String createTitle(MemberSession session) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ void testApplicationApproved() throws Exception {
setLabels(issueId, Set.of());

Response removeLabel = mockResponse("src/test/resources/github/mutableRemoveLabelsFromLabelable.json");
Response updateIssue = mockResponse("src/test/resources/github/mutableUpdateIssue.json");

final GHContentBuilder builder = Mockito.mock(GHContentBuilder.class);

Expand All @@ -86,6 +87,10 @@ void testApplicationApproved() throws Exception {
when(mocks.installationGraphQLClient(datastoreInstallationId)
.executeSync(contains("removeLabelsFromLabelable("), anyMap()))
.thenReturn(removeLabel);

when(mocks.installationGraphQLClient(datastoreInstallationId)
.executeSync(contains("updateIssue(input: {"), anyMap()))
.thenReturn(updateIssue);
})
.when().payloadFromClasspath("/github/eventIssueLabeled-accepted.json")
.event(GHEvent.ISSUES)
Expand All @@ -109,6 +114,8 @@ void testApplicationApproved() throws Exception {
verify(mocks.issue(2345115049L)).close();

// 5) remove application/new
verify(mocks.installationGraphQLClient(datastoreInstallationId), timeout(500))
.executeSync(contains("updateIssue(input: {"), anyMap());
verify(mocks.installationGraphQLClient(datastoreInstallationId), timeout(500))
.executeSync(contains("removeLabelsFromLabelable("), anyMap());

Expand All @@ -130,6 +137,7 @@ void testApplicationDenied() throws Exception {
setLabels(issueId, Set.of());

Response removeLabel = mockResponse("src/test/resources/github/mutableRemoveLabelsFromLabelable.json");
Response updateIssue = mockResponse("src/test/resources/github/mutableUpdateIssue.json");

final GHContentBuilder builder = Mockito.mock(GHContentBuilder.class);

Expand All @@ -148,6 +156,9 @@ void testApplicationDenied() throws Exception {
when(mocks.installationGraphQLClient(datastoreInstallationId)
.executeSync(contains("removeLabelsFromLabelable("), anyMap()))
.thenReturn(removeLabel);
when(mocks.installationGraphQLClient(datastoreInstallationId)
.executeSync(contains("updateIssue(input: {"), anyMap()))
.thenReturn(updateIssue);
})
.when().payloadFromClasspath("/github/eventIssueLabeled-declined.json")
.event(GHEvent.ISSUES)
Expand All @@ -169,6 +180,8 @@ void testApplicationDenied() throws Exception {
verify(mocks.issue(2345115049L)).close();

// 5) remove application/new
verify(mocks.installationGraphQLClient(datastoreInstallationId), timeout(500))
.executeSync(contains("updateIssue(input: {"), anyMap());
verify(mocks.installationGraphQLClient(datastoreInstallationId), timeout(500))
.executeSync(contains("removeLabelsFromLabelable("), anyMap());

Expand Down

0 comments on commit afe1ae8

Please sign in to comment.