Skip to content

Commit 4883a0d

Browse files
committed
refactor(gh-bugcop.tsx): convert lastLabeled function to a named function for better readability and maintainability
style(gh-bugcop.tsx): simplify listComments call by removing unnecessary line breaks for improved code clarity
1 parent cbeda0a commit 4883a0d

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

app/tasks/gh-bugcop/gh-bugcop.tsx

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,15 @@ async function processIssue(issue: GH["issue"]) {
189189
tlog("Found " + labelEvents.length + " unlabeled/labeled/commented events");
190190
await saveTask({ timeline: labelEvents as any });
191191

192-
const lastLabeled = (labelName: string) =>
193-
labelEvents
194-
.filter((e) => e.event === "labeled")
192+
function lastLabeled(labelName: string) {
193+
return labelEvents
194+
.filter((e) => e?.event === "labeled")
195195
.map((e) => e as GH["labeled-issue-event"])
196196
.filter((e) => e.label?.name === labelName)
197197
.sort(compareBy((e) => e.created_at))
198198
.reverse()[0];
199+
}
200+
199201
const latestLabeledEvent = lastLabeled(BUGCOP_ASKING_FOR_INFO) || lastLabeled(BUGCOP_ANSWERED);
200202
if (!latestLabeledEvent) {
201203
lastLabeled(BUGCOP_RESPONSE_RECEIVED) ||
@@ -211,9 +213,7 @@ async function processIssue(issue: GH["issue"]) {
211213
const hasNewComment = await (async function () {
212214
const labelLastAddedTime = new Date(latestLabeledEvent?.created_at);
213215
const newComments = await pageFlow(1, async (page) => {
214-
const { data: comments } = await hotMemo(gh.issues.listComments, [
215-
{ ...issueId, page, per_page: 100 },
216-
]);
216+
const { data: comments } = await hotMemo(gh.issues.listComments, [{ ...issueId, page, per_page: 100 }]);
217217
return { data: comments, next: comments.length >= 100 ? page + 1 : undefined };
218218
})
219219
.flat()
@@ -261,15 +261,6 @@ async function processIssue(issue: GH["issue"]) {
261261
lastChecked: new Date(),
262262
labels: union(task.labels || [], addLabels).filter((e) => !removeLabels.includes(e)),
263263
});
264-
265-
function lastLabeled(labelName: string) {
266-
return labelEvents
267-
.filter((e) => e.event === "labeled")
268-
.map((e) => e as GH["labeled-issue-event"])
269-
.filter((e) => e.label?.name === labelName)
270-
.sort(compareBy((e) => e.created_at))
271-
.reverse()[0];
272-
}
273264
}
274265

275266
async function fetchAllIssueTimeline(issueId: { owner: string; repo: string; issue_number: number }) {

0 commit comments

Comments
 (0)