Skip to content

Commit b220ade

Browse files
committed
update reopen logic
1 parent 56b4390 commit b220ade

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

policy.js

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -138,34 +138,42 @@ async function annotationCommentExists(options, issue_number, annotation) {
138138

139139
// Helper function to process annotations and determine action
140140
function processAnnotations(annotations) {
141-
const mostRecent = getMostRecentAnnotation(annotations);
142-
143-
if (!mostRecent) {
141+
if (!annotations || annotations.length === 0) {
144142
return { action: 'none', annotations: [] };
145143
}
146144

147145
// Sort all annotations by created date (most recent first)
148146
const sortedAnnotations = annotations.sort((a, b) => new Date(b.created) - new Date(a.created));
149147

150-
if (mostRecent.action === 'APPROVED') {
151-
return {
152-
action: 'close',
153-
annotations: sortedAnnotations,
154-
mostRecent: mostRecent
155-
};
156-
} else if (mostRecent.action === 'REJECTED') {
157-
return {
158-
action: 'reopen',
159-
annotations: sortedAnnotations,
160-
mostRecent: mostRecent
161-
};
162-
} else {
163-
return {
164-
action: 'update',
165-
annotations: sortedAnnotations,
166-
mostRecent: mostRecent
167-
};
148+
// Find the most recent APPROVED or REJECTED annotation (these take precedence)
149+
const mostRecentApprovedOrRejected = sortedAnnotations.find(ann =>
150+
ann.action === 'APPROVED' || ann.action === 'REJECTED'
151+
);
152+
153+
// If we have an APPROVED or REJECTED annotation, use it to determine the action
154+
if (mostRecentApprovedOrRejected) {
155+
if (mostRecentApprovedOrRejected.action === 'APPROVED') {
156+
return {
157+
action: 'close',
158+
annotations: sortedAnnotations,
159+
mostRecent: mostRecentApprovedOrRejected
160+
};
161+
} else if (mostRecentApprovedOrRejected.action === 'REJECTED') {
162+
return {
163+
action: 'reopen',
164+
annotations: sortedAnnotations,
165+
mostRecent: mostRecentApprovedOrRejected
166+
};
167+
}
168168
}
169+
170+
// If no APPROVED or REJECTED annotations, use the most recent annotation for update
171+
const mostRecent = sortedAnnotations[0];
172+
return {
173+
action: 'update',
174+
annotations: sortedAnnotations,
175+
mostRecent: mostRecent
176+
};
169177
}
170178

171179
// Process existing issue with annotations (new workflow)

0 commit comments

Comments
 (0)