Commit 43875f1c by Lin Wang

feat: send message to the slack channel

parent 14dc04f9
......@@ -4,16 +4,12 @@ import { basename } from 'path';
export async function sendSlackMessage(webhookUrl: string, params: {
issue: string,
displayName: string,
language: string,
siteEditor: string
details?: string,
}) {
const text = [
`Issue: ${params.issue}`,
`Display Name: ${params.displayName}`,
`Language: ${params.language}`,
`Site editor: ${params.siteEditor}`
].join('\n');
const parts: string[] = [];
parts.push(`Issue: ${params.issue}`);
if (params.details) parts.push(`Details: ${params.details}`);
const text = parts.join('\n');
const res = await fetch(webhookUrl, {
method: "POST",
......@@ -50,12 +46,4 @@ export async function sendSlackFile(
if (!response.ok) {
throw new Error(`Slack 文件上传失败: ${response.error}`);
}
}
// 示例用法
// sendSlackMessage('https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX', {
// issue: 'Theme color missing',
// displayName: 'Lavender',
// language: 'en',
// siteEditor: 'https://www.strikingly.com/s/sites/12572142/edit'
// });
\ No newline at end of file
}
\ No newline at end of file
......@@ -2,6 +2,7 @@
import { google } from 'googleapis';
import { readdirSync, readFileSync } from 'fs';
import { join } from 'path';
import { sendSlackMessage } from '../clients/slack';
async function uploadAllToSheets() {
const useAiSelectors = process.env.USE_AI_SELECTORS === 'true';
......@@ -61,7 +62,24 @@ async function uploadAllToSheets() {
}
}
uploadAllToSheets().catch(err => {
console.error('Error uploading to Google Sheets:', err);
process.exit(1);
});
async function notifySlack() {
const webhookUrl = process.env.SLACK_WEBHOOK!;
const nonAiUrl = `https://docs.google.com/spreadsheets/d/${process.env.GOOGLE_SHEET_ID}/edit`;
const aiUrl = `https://docs.google.com/spreadsheets/d/${process.env.GOOGLE_SHEET_AI_ID}/edit`;
await sendSlackMessage(webhookUrl, {
issue: 'Inconsistencies are detected in i18n master section template',
details: `Google Sheet Links:\n- Non-AI selectors: ${nonAiUrl}\n- AI selectors: ${aiUrl}`
});
}
async function main() {
try {
await uploadAllToSheets();
await notifySlack();
} catch (err) {
console.error('Error in task:gsheet workflow:', err);
process.exit(1);
}
}
main();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment