|
| 1 | +name: Notify Scheduled Guests |
| 2 | + |
| 3 | +on: |
| 4 | + issues: |
| 5 | + types: [labeled] |
| 6 | + |
| 7 | +jobs: |
| 8 | + notify-scheduled-guest: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + if: github.event.label.name == 'scheduled' |
| 11 | + steps: |
| 12 | + - name: Comment on scheduled issue |
| 13 | + uses: actions/github-script@v7 |
| 14 | + with: |
| 15 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 16 | + script: | |
| 17 | + // Get the GitHub username directly from the issue author |
| 18 | + const githubHandle = context.payload.issue.user.login; |
| 19 | +
|
| 20 | + console.log('Processing issue #', context.issue.number, 'by author:', githubHandle); |
| 21 | +
|
| 22 | + if (githubHandle) { |
| 23 | + // Security: Enhanced validation function |
| 24 | + const isValidGitHubHandle = (handle) => { |
| 25 | + if (!handle || typeof handle !== 'string') return false; |
| 26 | + if (handle.length < 1 || handle.length > 39) return false; |
| 27 | +
|
| 28 | + // Must start and end with alphanumeric, can contain hyphens in middle |
| 29 | + return /^[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]$|^[a-zA-Z0-9]$/.test(handle); |
| 30 | + }; |
| 31 | +
|
| 32 | + if (isValidGitHubHandle(githubHandle)) { |
| 33 | + console.log('Creating comment for validated handle'); |
| 34 | +
|
| 35 | + // Security: Sanitize comment content |
| 36 | + const safeHandle = githubHandle.replace(/[<>'"&]/g, ''); |
| 37 | + const commentBody = `Hey @${safeHandle}, thank you for booking! ✨\n\nThe stream starts at 1:00 PM ET. Please join at 12:45 PM ET for prep and tech checks. Be ready with your demo—our audience strongly prefers technical demos.\n\nLet us know if you have any questions!\n\nKedasha, Andrea & Kevin 👯`; |
| 38 | +
|
| 39 | + const issueComment = { |
| 40 | + owner: context.repo.owner, |
| 41 | + repo: context.repo.repo, |
| 42 | + issue_number: context.issue.number, |
| 43 | + body: commentBody |
| 44 | + }; |
| 45 | +
|
| 46 | + try { |
| 47 | + const result = await github.rest.issues.createComment(issueComment); |
| 48 | + console.log('Comment created successfully, ID:', result.data.id); |
| 49 | + } catch (error) { |
| 50 | + // Security: Don't expose error details in logs |
| 51 | + console.error('Failed to create comment for issue #', context.issue.number); |
| 52 | + // Don't re-throw to prevent workflow failure from exposing internals |
| 53 | + } |
| 54 | + } else { |
| 55 | + console.log('Handle validation failed for issue #', context.issue.number); |
| 56 | + } |
| 57 | + } else { |
| 58 | + console.log('No GitHub handle found for issue #', context.issue.number); |
| 59 | + } |
0 commit comments