Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 23 additions & 2 deletions apps/api/src/handlers/github/notifyPullRequestTerminalStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
taskPullRequests,
taskRuns,
tasks,
desc,
eq,
and,
inArray,
Expand Down Expand Up @@ -825,6 +826,7 @@ export async function notifyPullRequestTerminalStatus({
}),
db.query.taskRuns.findMany({
where: inArray(taskRuns.taskId, taskIds),
orderBy: [desc(taskRuns.createdAt)],
columns: {
taskId: true,
payload: true,
Expand All @@ -834,9 +836,27 @@ export async function notifyPullRequestTerminalStatus({

const slackTargets: SlackTarget[] = [];
const linearSessionIds: string[] = [];
const latestRunsByTaskId = new Map<string, (typeof linkedRuns)[number]>();
for (const run of linkedRuns) {
if (!latestRunsByTaskId.has(run.taskId)) {
latestRunsByTaskId.set(run.taskId, run);
}
}
// Fast/session-backed tasks receive terminal PR events through their parent
// session. Keep this webhook fan-out only for legacy/direct Slack tasks so
// it cannot add a second canned status post to the same conversation.
const fastTaskIds = new Set(
[...latestRunsByTaskId.values()]
.filter((run) => getFastAgentParentFromPayload(run.payload) !== null)
Comment thread
roomote-roomote[bot] marked this conversation as resolved.
.map((run) => run.taskId),
);

for (const task of linkedTasks) {
if (task.slackThreadTs && task.slackChannelId) {
if (
!fastTaskIds.has(task.id) &&
task.slackThreadTs &&
task.slackChannelId
) {
slackTargets.push({
taskId: task.id,
slackThreadTs: task.slackThreadTs,
Expand All @@ -850,7 +870,8 @@ export async function notifyPullRequestTerminalStatus({
}

slackTargets.push(
...linkedRuns
...[...latestRunsByTaskId.values()]
.filter((run) => !fastTaskIds.has(run.taskId))
.map((run) => getSlackTarget(run.taskId, run.payload))
.filter((target): target is SlackTarget => target !== null),
);
Expand Down
Loading