Skip to content

Commit 43abb98

Browse files
Refactor welcome.yml for consistency and clarity
1 parent ac0e08e commit 43abb98

1 file changed

Lines changed: 82 additions & 83 deletions

File tree

.github/workflows/welcome.yml

Lines changed: 82 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
name: Guest Welcome Bot
22

33
on:
4-
issues:
5-
types: [labeled]
4+
issues:
5+
types: [labeled]
66
workflow_dispatch:
77
inputs:
8-
issue_number:
8+
issue_number:
99
description: 'Issue number to test with'
1010
required: true
11-
type: number
11+
type: number
1212

13-
jobs:
13+
jobs:
1414
generate-prep:
15-
if: github.event.label. name == 'scheduled' || github.event_name == 'workflow_dispatch'
15+
if: github. event.label.name == 'scheduled' || github.event_name == 'workflow_dispatch'
1616
runs-on: ubuntu-latest
1717

1818
steps:
@@ -38,102 +38,101 @@ jobs:
3838
let issue;
3939
4040
if (context.eventName === 'workflow_dispatch') {
41-
issueNumber = ${{ github.event.inputs.issue_number }};
42-
const response = await github. rest.issues.get({
41+
issueNumber = ${{ github.event.inputs.issue_number || 0 }};
42+
const response = await github.rest.issues.get({
4343
owner: context.repo.owner,
44-
repo: context.repo. repo,
45-
issue_number: issueNumber
44+
repo: context.repo.repo,
45+
issue_number: issueNumber
4646
});
4747
issue = response.data;
4848
} else {
4949
issue = context.payload.issue;
50-
issueNumber = issue.number;
50+
issueNumber = issue. number;
5151
}
5252
53-
core. setOutput('issue_number', issueNumber);
54-
core.setOutput('issue_body', issue. body || '');
53+
core.setOutput('issue_number', issueNumber);
54+
core.setOutput('issue_body', issue.body || '');
5555
5656
- name: Generate personalized prep
5757
id: personalize
58-
uses: actions/github-script@v7
5958
env:
60-
GH_TOKEN: ${{ secrets.COPILOT_PAT }}
61-
ISSUE_BODY: ${{ steps.get-issue.outputs.issue_body }}
62-
with:
63-
script: |
64-
const { CopilotClient } = require('@github/copilot-sdk');
59+
GH_TOKEN: ${{ secrets.COPILOT_PAT }}
60+
ISSUE_BODY: ${{ steps. get-issue.outputs.issue_body }}
61+
run: |
62+
cat << 'EOF' > generate-welcome. mjs
63+
import { CopilotClient } from '@github/copilot-sdk';
6564
66-
const body = process.env.ISSUE_BODY || '';
65+
const body = process.env.ISSUE_BODY || '';
6766
68-
const nameMatch = body.match(/Name\s*\n\s*([^\n]+)/);
69-
const projectMatch = body.match(/Project Name\s*\n\s*([^\n]+)/);
70-
const repoMatch = body.match(/Project Repo Link\s*\n\s*([^\n]+)/);
71-
const descMatch = body.match(/Tell us about yourself\s*\n\s*([\s\S]*?)(?=\n###|\n##|$)/);
67+
const nameMatch = body.match(/Name\s*\n\s*([^\n]+)/);
68+
const projectMatch = body.match(/Project Name\s*\n\s*([^\n]+)/);
69+
const repoMatch = body.match(/Project Repo Link\s*\n\s*([^\n]+)/);
70+
const descMatch = body.match(/Tell us about yourself\s*\n\s*([\s\S]*?)(?=\n###|\n##|$)/);
7271
73-
const guestName = nameMatch ? nameMatch[1].trim() : 'Guest';
74-
const projectName = projectMatch ? projectMatch[1]. trim() : 'their project';
75-
const projectRepo = repoMatch ? repoMatch[1]. trim() : '';
76-
const guestBackground = descMatch ? descMatch[1].trim() : '';
72+
const guestName = nameMatch ? nameMatch[1].trim() : 'Guest';
73+
const projectName = projectMatch ? projectMatch[1].trim() : 'their project';
74+
const projectRepo = repoMatch ? repoMatch[1].trim() : '';
75+
const guestBackground = descMatch ? descMatch[1].trim() : '';
7776
78-
const prompt = [
79-
'You are a helpful stream coordinator for Open Source Friday.',
80-
'Create a 2-3 sentence personalized welcome message for this guest:',
81-
'',
82-
'Guest Name: ' + guestName,
83-
'Project: ' + projectName,
84-
'Project Repo: ' + projectRepo,
85-
'Guest Background: ' + guestBackground,
86-
'',
87-
'Write a warm, encouraging message that acknowledges their specific project.',
88-
'Show genuine excitement to have them on the stream.',
89-
'Keep it concise and authentic.',
90-
'Do not use markdown formatting or special characters.'
91-
]. join('\n');
92-
93-
let personalizedMessage = '';
94-
let client;
95-
96-
try {
97-
client = new CopilotClient();
98-
await client.start();
99-
100-
const session = await client.createSession({ model: 'gpt-5' });
101-
const response = await session.sendAndWait({ prompt });
102-
103-
if (response?.data?. content) {
104-
personalizedMessage = response.data.content;
105-
} else {
106-
throw new Error('No response content received');
107-
}
108-
109-
await session.destroy();
110-
111-
} catch (error) {
112-
console.log('Copilot SDK error: ' + error.message);
113-
personalizedMessage = 'We are thrilled to have ' + guestName + ' joining us to talk about ' + projectName + '! This is going to be a fantastic session. ';
114-
115-
} finally {
116-
if (client) {
117-
await client.stop().catch(function(e) { console.log('Cleanup error:', e.message); });
118-
}
77+
const prompt = `You are a helpful stream coordinator for Open Source Friday. Create a 2-3 sentence personalized welcome message for this guest:
78+
79+
Guest Name: ${guestName}
80+
Project: ${projectName}
81+
Project Repo: ${projectRepo}
82+
Guest Background: ${guestBackground}
83+
84+
Write a warm, encouraging message that acknowledges their specific project and shows genuine excitement to have them on the stream. Keep it concise and authentic. Do not use markdown formatting or special characters. `;
85+
86+
let personalizedMessage = '';
87+
let client;
88+
89+
try {
90+
client = new CopilotClient();
91+
await client.start();
92+
93+
const session = await client.createSession({ model: 'gpt-5' });
94+
const response = await session. sendAndWait({ prompt });
95+
96+
if (response?.data?. content) {
97+
personalizedMessage = response.data.content;
98+
} else {
99+
throw new Error('No response content received');
100+
}
101+
102+
await session.destroy();
103+
104+
} catch (error) {
105+
console.error('Copilot SDK error:', error.message);
106+
personalizedMessage = `We are thrilled to have ${guestName} joining us to talk about ${projectName}! This is going to be a fantastic session.`;
107+
108+
} finally {
109+
if (client) {
110+
await client. stop().catch(e => console.error('Cleanup error:', e.message));
119111
}
112+
}
113+
114+
// Output for GitHub Actions
115+
const fs = await import('fs');
116+
const outputFile = process.env.GITHUB_OUTPUT;
117+
fs.appendFileSync(outputFile, `personalized_message<<EOFMSG\n${personalizedMessage}\nEOFMSG\n`);
118+
fs.appendFileSync(outputFile, `guest_name=${guestName}\n`);
119+
EOF
120120
121-
core.setOutput('personalized_message', personalizedMessage);
122-
core.setOutput('guest_name', guestName);
121+
node generate-welcome.mjs
123122
124123
- name: Post personalized prep comment
125-
uses: actions/github-script@v7
124+
uses: actions/github-script@v7
126125
env:
127-
GITHUB_TOKEN: ${{ secrets. GITHUB_TOKEN }}
128-
PERSONALIZED_MESSAGE: ${{ steps. personalize.outputs.personalized_message }}
129-
GUEST_NAME: ${{ steps.personalize.outputs.guest_name }}
130-
ISSUE_NUMBER: ${{ steps. get-issue.outputs.issue_number }}
126+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
127+
PERSONALIZED_MESSAGE: ${{ steps.personalize. outputs.personalized_message }}
128+
GUEST_NAME: ${{ steps.personalize.outputs.guest_name }}
129+
ISSUE_NUMBER: ${{ steps.get-issue.outputs.issue_number }}
131130
with:
132-
script: |
131+
script: |
133132
const personalizedMessage = process.env.PERSONALIZED_MESSAGE;
134-
const guestName = process.env. GUEST_NAME;
135-
const issueNumber = parseInt(process.env.ISSUE_NUMBER, 10);
136-
const repoUrl = context.payload.repository.html_url;
133+
const guestName = process.env.GUEST_NAME;
134+
const issueNumber = parseInt(process.env. ISSUE_NUMBER, 10);
135+
const repoUrl = context. payload.repository.html_url;
137136
const guideUrl = repoUrl + '/blob/main/admin/approved-guest.md';
138137
139138
const comment = [
@@ -152,8 +151,8 @@ jobs:
152151
].join('\n');
153152
154153
await github.rest.issues.createComment({
155-
issue_number: issueNumber,
156-
owner: context.repo.owner,
157-
repo: context.repo. repo,
154+
issue_number: issueNumber,
155+
owner: context.repo.owner,
156+
repo: context.repo.repo,
158157
body: comment
159158
});

0 commit comments

Comments
 (0)