Skip to content

Commit 78db93b

Browse files
committed
chore: use text instead of blocks
1 parent d39a49c commit 78db93b

5 files changed

Lines changed: 38 additions & 85 deletions

File tree

.github/actions/activity/dist/new-issues/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/actions/activity/dist/popular-issues/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/actions/activity/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"private": true,
33
"license": "MIT",
44
"scripts": {
5-
"build:all": "pnpm build:typecheck && pnpm build:popular-issues:ncc && pnpm build:new-issues:ncc",
5+
"build": "pnpm build:typecheck && pnpm build:popular-issues:ncc && pnpm build:new-issues:ncc",
66
"build:new-issues:ncc": "ncc build src/new-issues.ts -m -o dist/new-issues",
77
"build:popular-issues:ncc": "ncc build src/popular-issues.ts -m -o dist/popular-issues",
88
"build:typecheck": "tsc",

.github/actions/activity/src/new-issues.ts

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,19 @@
1-
import { context, getOctokit } from '@actions/github'
21
import { info, setFailed } from '@actions/core'
2+
import { getOctokit } from '@actions/github'
33
import { WebClient } from '@slack/web-api'
4-
import { formattedDate, daysAgo } from './lib/utils'
4+
import { daysAgo } from './lib/utils'
55
import { SlimIssue } from './types'
66

7-
function generateBlocks(issues: SlimIssue[]) {
8-
const blocks = [
9-
{
10-
type: 'section',
11-
text: {
12-
type: 'mrkdwn',
13-
text: '*A list of issues opened in the last 7 days.',
14-
},
15-
},
16-
{
17-
type: 'divider',
18-
},
19-
]
7+
const DAYS_WINDOW = 7
208

21-
let text = ''
9+
function generateText(issues: SlimIssue[]) {
10+
let text = `*A list of issues opened in the last ${DAYS_WINDOW} days:*\n\n`
2211

23-
issues.forEach((issue, i) => {
24-
text += `${i + 1}. [<${issue.html_url}|#${issue.number}>, ${
25-
issue?.reactions?.total_count || 0
26-
} reactions, ${formattedDate(issue.created_at)}]: ${issue.title}\n`
12+
issues.forEach((issue) => {
13+
text += `• ${issue.title} - (<${issue.html_url}|#${issue.number}>)\n`
2714
})
2815

29-
blocks.push({
30-
type: 'section',
31-
text: {
32-
type: 'mrkdwn',
33-
text: text,
34-
},
35-
})
36-
37-
return blocks
16+
return text.trim()
3817
}
3918

4019
export async function run() {
@@ -45,11 +24,10 @@ export async function run() {
4524
const octoClient = getOctokit(process.env.GITHUB_TOKEN)
4625
const slackClient = new WebClient(process.env.SLACK_TOKEN)
4726

48-
const { owner, repo } = context.repo
4927
const { data } = await octoClient.rest.search.issuesAndPullRequests({
5028
order: 'desc',
5129
per_page: 15,
52-
q: `repo:${owner}/${repo} is:issue is:open created:>=${daysAgo(7)}`,
30+
q: `repo:payloadcms/payload is:issue is:open created:>=${daysAgo(DAYS_WINDOW)}`,
5331
sort: 'created',
5432
})
5533

@@ -58,18 +36,12 @@ export async function run() {
5836
return
5937
}
6038

61-
console.log(
62-
data.items
63-
.map(
64-
(i) =>
65-
`#${i.number}: ${i.title}, reactions: ${i.reactions?.total_count} - link: ${i.html_url}`,
66-
)
67-
.join('\n'),
68-
)
39+
const messageText = generateText(data.items)
40+
console.log(messageText)
6941

7042
await slackClient.chat.postMessage({
71-
blocks: generateBlocks(data.items),
72-
channel: '#test-notifications',
43+
text: generateText(data.items),
44+
channel: '#dev-feed',
7345
icon_emoji: ':github:',
7446
username: 'GitHub Notifier',
7547
})

.github/actions/activity/src/popular-issues.ts

Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,28 @@
1-
import { context, getOctokit } from '@actions/github'
21
import { info, setFailed } from '@actions/core'
2+
import { getOctokit } from '@actions/github'
33
import { WebClient } from '@slack/web-api'
4-
import { formattedDate, daysAgo } from './lib/utils'
4+
import { daysAgo } from './lib/utils'
55
import { SlimIssue } from './types'
66

7-
function generateBlocks(issues: SlimIssue[]) {
8-
const blocks = [
9-
{
10-
type: 'section',
11-
text: {
12-
type: 'mrkdwn',
13-
text: '*A list of the top 15 issues sorted by the most reactions over the last 30 days.',
14-
},
15-
},
16-
{
17-
type: 'divider',
18-
},
19-
]
7+
const DAYS_WINDOW = 60
208

21-
let text = ''
9+
function generateText(issues: SlimIssue[]) {
10+
let text = `*A list of the top 10 issues sorted by the most reactions over the last ${DAYS_WINDOW} days:*\n\n`
2211

23-
issues.forEach((issue, i) => {
24-
text += `${i + 1}. [<${issue.html_url}|#${issue.number}>, ${
25-
issue?.reactions?.total_count || 0
26-
} reactions, ${formattedDate(issue.created_at)}]: ${issue.title}\n`
27-
})
12+
// Format date as "X days ago"
13+
const formattedDaysAgo = (dateString: string) => {
14+
const date = new Date(dateString)
15+
const now = new Date()
16+
const diffTime = Math.abs(now.getTime() - date.getTime())
17+
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24))
18+
return `${diffDays} day${diffDays > 1 ? 's' : ''} ago`
19+
}
2820

29-
blocks.push({
30-
type: 'section',
31-
text: {
32-
type: 'mrkdwn',
33-
text: text,
34-
},
21+
issues.forEach((issue) => {
22+
text += `• ${issue?.reactions?.total_count || 0} 👍 ${issue.title} - <${issue.html_url}|#${issue.number}>, ${formattedDaysAgo(issue.created_at)}\n`
3523
})
3624

37-
return blocks
25+
return text.trim()
3826
}
3927

4028
export async function run() {
@@ -45,11 +33,10 @@ export async function run() {
4533
const octoClient = getOctokit(process.env.GITHUB_TOKEN)
4634
const slackClient = new WebClient(process.env.SLACK_TOKEN)
4735

48-
const { owner, repo } = context.repo
4936
const { data } = await octoClient.rest.search.issuesAndPullRequests({
5037
order: 'desc',
51-
per_page: 15,
52-
q: `repo:${owner}/${repo} is:issue is:open created:>=${daysAgo(30)}`,
38+
per_page: 10,
39+
q: `repo:payloadcms/payload is:issue is:open created:>=${daysAgo(DAYS_WINDOW)}`,
5340
sort: 'reactions',
5441
})
5542

@@ -58,18 +45,12 @@ export async function run() {
5845
return
5946
}
6047

61-
console.log(
62-
data.items
63-
.map(
64-
(i) =>
65-
`#${i.number}: ${i.title}, reactions: ${i.reactions?.total_count} - link: ${i.html_url}`,
66-
)
67-
.join('\n'),
68-
)
48+
const messageText = generateText(data.items)
49+
console.log(messageText)
6950

7051
await slackClient.chat.postMessage({
71-
blocks: generateBlocks(data.items),
72-
channel: '#test-notifications',
52+
text: messageText,
53+
channel: '#dev-feed',
7354
icon_emoji: ':github:',
7455
username: 'GitHub Notifier',
7556
})

0 commit comments

Comments
 (0)