Skip to content
Open
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
5 changes: 5 additions & 0 deletions apps/agent/src/mastra/workflows/github-notify-inactive-prs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,11 @@ const stepSendDiscordNotifications = new Step({
if (!description || !orgName || !channelId || !notificationsByRepo)
continue

// Skip sending notification if there are no inactive PRs
if (totalPRs === 0) {
continue
}

try {
await discordClient.sendMessageToChannel({
channelId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ const stepComposeMessages = new Step({
z.object({
repoData: repoDataSchema,
message: z.string(),
hasActivity: z.boolean(),
}),
),
}),
Expand All @@ -357,10 +358,18 @@ const stepComposeMessages = new Step({

for (const channelData of channelDataList) {
const repositoryMessages = channelData.repositories.map(
(repoData: RepoData) => ({
repoData,
message: generateRepositoryReport(repoData),
}),
(repoData: RepoData) => {
const message = generateRepositoryReport(repoData)
// Check if there's any activity in this repository
const hasActivity =
repoData.todayPRs.length > 0 || repoData.todayCommits.length > 0

return {
repoData,
message,
hasActivity,
}
},
)

messages.push({
Expand Down Expand Up @@ -397,17 +406,23 @@ const stepSendMessages = new Step({
const results = []

for (const { channelData, repositoryMessages } of messages) {
for (const { repoData, message } of repositoryMessages) {
// Check if any repository has activity
const reposWithActivity = repositoryMessages.filter(
({ hasActivity }: { hasActivity: boolean }) => hasActivity,
)

if (reposWithActivity.length === 0) {
// No activity in any repository - send a general message
try {
if (channelData.platform === 'discord') {
await discordClient.sendMessageToChannel({
channelId: channelData.channelId,
embed: {
title: `🤖 Daily report (${formatDate(new Date(), 'MMMM d, yyyy')}) for ${repoData.repoName}`,
description: message,
title: `🤖 Daily report (${formatDate(new Date(), 'MMMM d, yyyy')})`,
description: 'No new activity today in any repository.',
color: 3447003,
footer: {
text: `${channelData.orgName}/${repoData.repoName}`,
text: `${channelData.orgName}`,
},
},
})
Expand All @@ -417,21 +432,62 @@ const stepSendMessages = new Step({

results.push({
orgName: channelData.orgName,
repoName: repoData.repoName,
repoName: 'all-repositories',
channelId: channelData.channelId,
platform: channelData.platform,
success: true,
})
} catch (error) {
results.push({
orgName: channelData.orgName,
repoName: repoData.repoName,
repoName: 'all-repositories',
channelId: channelData.channelId,
platform: channelData.platform,
success: false,
error: error instanceof Error ? error.message : 'Unknown error',
})
}
} else {
// Send individual reports only for repositories with activity
for (const { repoData, message, hasActivity } of repositoryMessages) {
// Skip repositories with no activity
if (!hasActivity) continue

try {
if (channelData.platform === 'discord') {
await discordClient.sendMessageToChannel({
channelId: channelData.channelId,
embed: {
title: `🤖 Daily report (${formatDate(new Date(), 'MMMM d, yyyy')}) for ${repoData.repoName}`,
description: message,
color: 3447003,
footer: {
text: `${channelData.orgName}/${repoData.repoName}`,
},
},
})
} else {
throw new Error(`Unsupported platform ${channelData.platform}`)
}

results.push({
orgName: channelData.orgName,
repoName: repoData.repoName,
channelId: channelData.channelId,
platform: channelData.platform,
success: true,
})
} catch (error) {
results.push({
orgName: channelData.orgName,
repoName: repoData.repoName,
channelId: channelData.channelId,
platform: channelData.platform,
success: false,
error: error instanceof Error ? error.message : 'Unknown error',
})
}
}
}
}

Expand Down
Loading