Discussion Automated Processing #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Discussion Automated Processing | |
| on: | |
| discussion: | |
| types: [created, edited] | |
| workflow_dispatch: | |
| inputs: | |
| discussion_number: | |
| description: 'Discussion number to process' | |
| required: true | |
| type: number | |
| permissions: | |
| discussions: write | |
| pull-requests: read | |
| contents: read | |
| jobs: | |
| discussion-response: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - uses: pnpm/action-setup@v4 | |
| with: | |
| version: 10 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: 20 | |
| - name: Install dependencies | |
| run: | | |
| pnpm i | |
| pnpm add openai @antv/mcp-server-antv -w | |
| - name: Process Discussion | |
| uses: actions/github-script@v7 | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| // 1. Get discussion object from context | |
| let discussion = context.payload.discussion; | |
| // 2. Handle manual trigger case | |
| if (context.eventName === 'workflow_dispatch') { | |
| console.log('Manual trigger mode, fetching Discussion details via GraphQL...'); | |
| const discussionNumber = parseInt(context.payload.inputs.discussion_number, 10); | |
| // Use GraphQL query instead of REST API | |
| const { repository } = await github.graphql( | |
| `query($owner: String!, $repo: String!, $number: Int!) { | |
| repository(owner: $owner, name: $repo) { | |
| discussion(number: $number) { | |
| id | |
| number | |
| title | |
| body | |
| author { | |
| login | |
| } | |
| } | |
| } | |
| }`, | |
| { | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| number: discussionNumber, | |
| } | |
| ); | |
| // Adjust the returned data structure to match webhook payload for compatibility with subsequent scripts | |
| discussion = { | |
| ...repository.discussion, | |
| node_id: repository.discussion.id, // GraphQL returns `id`, which is `node_id` | |
| user: repository.discussion.author // GraphQL returns `author`, map it to `user` | |
| }; | |
| if (!discussion) { | |
| throw new Error(`Could not find Discussion #${discussionNumber}`); | |
| } | |
| console.log(`Successfully retrieved data for Discussion #${discussionNumber}.`); | |
| } | |
| console.log('Discussion object to be processed:', discussion); | |
| // 3. Call external JS script and pass the discussion object (this part remains unchanged) | |
| const script = require('./.github/workflows/scripts/discussion-automated.js'); | |
| await script({ | |
| github, | |
| core, | |
| context, | |
| discussion // Pass discussion object | |
| }); |