Skip to content

Commit

Permalink
🐛 recover from missed label events
Browse files Browse the repository at this point in the history
  • Loading branch information
ebullient committed Oct 16, 2024
1 parent 3a71645 commit efc0575
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ public static boolean isUserFeedback(String body) {
return body.contains("::response::");
}

public static boolean isNew(DataLabel label) {
return NEW.equals(label.name);
}

public static boolean isAccepted(DataLabel label) {
return ACCEPTED.equals(label.name);
}
Expand All @@ -152,6 +156,10 @@ public static boolean isDeclined(DataLabel label) {
return DECLINED.equals(label.name);
}

public static boolean isComplete(DataLabel label) {
return isAccepted(label) || isDeclined(label);
}

public static boolean isNewer(DataCommonComment x, Date issueMostRecent) {
Log.debugf("isNewer: %s %s", x.mostRecentEdit(), issueMostRecent);
return x.mostRecentEdit().after(issueMostRecent);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.commonhaus.automation.admin.github;

import java.util.Collection;

import jakarta.inject.Inject;
import jakarta.json.JsonObject;

Expand Down Expand Up @@ -93,10 +95,22 @@ public void updateApplicationComments(GitHubEvent event, GitHub github, DynamicG

DatastoreQueryContext dqc = ctx.getDatastoreContext();
DataCommonComment comment = JsonAttribute.comment.commonCommentFrom(data);

Collection<DataLabel> labels = dqc.getLabels(issue.id);
boolean hasNew = labels.stream().anyMatch(l -> MembershipApplicationData.isNew(l));
DataLabel finishLabel = labels.stream()
.filter(l -> MembershipApplicationData.isComplete(l))
.findFirst().orElse(null);
try {
applicationProcess.handleApplicationComment(dqc, issue, comment);
} catch (Exception e) {
dqc.logAndSendEmail("Error with issue label event", e);

// Handle missed label event
if (hasNew && finishLabel != null) {
dqc.getLabels(dqc.getRepositoryId()); // pre-fetch
applicationProcess.handleApplicationLabelAdded(dqc, eventPayload.getIssue(), issue, finishLabel);
}
} catch (Throwable e) {
dqc.logAndSendEmail("Error with issue comment event", e);
} finally {
dqc.clearErrors();
}
Expand Down

0 comments on commit efc0575

Please sign in to comment.