diff --git a/.github/workflows/rfc-discussion.yml b/.github/workflows/rfc-discussion.yml index 11af50c..8fad1e1 100644 --- a/.github/workflows/rfc-discussion.yml +++ b/.github/workflows/rfc-discussion.yml @@ -34,6 +34,22 @@ jobs: core.info('Found markdown file: ' + mdFile.filename); core.setOutput('filename', mdFile.filename); + - name: Get RFC Content + id: get-rfc-content + uses: actions/github-script@v7 + with: + script: | + const mdFile = '${{ steps.changed-files.outputs.filename }}'; + const { data: fileContent } = await github.rest.repos.getContent({ + owner: context.repo.owner, + repo: context.repo.repo, + path: mdFile, + ref: context.payload.pull_request.head.sha + }); + + const content = Buffer.from(fileContent.content, 'base64').toString('utf8'); + core.setOutput('content', content); + - name: Create a new GitHub Discussion id: create-discussion uses: abirismyname/create-discussion@v1.x @@ -42,11 +58,28 @@ jobs: with: title: "RFC Discussion: ${{ github.event.pull_request.title }}" body: | - This is the discussion thread for RFC PR #${{ github.event.pull_request.number }}. + # RFC Discussion: ${{ github.event.pull_request.title }} + + **Author:** @${{ github.event.pull_request.user.login }} | **Status:** 🟡 Under Review + + ## 📋 Quick Links + - 🔧 [Source PR #${{ github.event.pull_request.number }}](${{ github.event.pull_request.html_url }}) + - 📝 [View Changes](${{ github.event.pull_request.html_url }}/files) + - 📖 [Rendered Proposal](https://github.com/${{ github.repository }}/blob/${{ github.event.pull_request.head.ref }}/${{ steps.changed-files.outputs.filename }}) + + --- + + ## 📄 Current Proposal + + > **Last Updated:** ${{ github.event.pull_request.updated_at }} + > **Commit:** [`${{ github.event.pull_request.head.sha }}`](${{ github.event.pull_request.head.repo.html_url }}/commit/${{ github.event.pull_request.head.sha }}) - Please provide feedback and discuss the RFC here rather than in the PR comments. + + ${{ steps.get-rfc-content.outputs.content }} + - PR Link: ${{ github.event.pull_request.html_url }} + --- + **💬 Discussion Guidelines:** Share feedback, concerns, and suggestions below. Use reply threads to keep conversations organized. repository-id: "R_kgDONlIMAA" category-id: "DIC_kwDONlIMAM4Cl3Tj" diff --git a/.github/workflows/sync-rfc-discussion.yml b/.github/workflows/sync-rfc-discussion.yml new file mode 100644 index 0000000..62e2dca --- /dev/null +++ b/.github/workflows/sync-rfc-discussion.yml @@ -0,0 +1,158 @@ +name: Sync RFC Discussion + +on: + pull_request_target: + types: [synchronize] + paths: + - 'rfcs/**.md' + +jobs: + sync-discussion: + runs-on: ubuntu-latest + permissions: + discussions: write + pull-requests: read + + steps: + - name: Get Changed Files + id: changed-files + uses: actions/github-script@v7 + with: + script: | + const { data: files } = await github.rest.pulls.listFiles({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.issue.number + }); + + const mdFile = files.find(file => file.filename.startsWith('rfcs/') && file.filename.endsWith('.md')); + if (!mdFile) { + core.info('No RFC markdown file found, skipping sync'); + return; + } + core.setOutput('filename', mdFile.filename); + + - name: Get RFC Content + id: get-rfc-content + if: steps.changed-files.outputs.filename + uses: actions/github-script@v7 + with: + script: | + const mdFile = '${{ steps.changed-files.outputs.filename }}'; + const { data: fileContent } = await github.rest.repos.getContent({ + owner: context.repo.owner, + repo: context.repo.repo, + path: mdFile, + ref: context.payload.pull_request.head.sha + }); + + const content = Buffer.from(fileContent.content, 'base64').toString('utf8'); + core.setOutput('content', content); + + - name: Find Discussion + id: find-discussion + if: steps.changed-files.outputs.filename + uses: actions/github-script@v7 + with: + script: | + const query = ` + query($owner: String!, $repo: String!) { + repository(owner: $owner, name: $repo) { + discussions(first: 50, orderBy: {field: CREATED_AT, direction: DESC}) { + nodes { + id + title + body + } + } + } + } + `; + + const variables = { + owner: context.repo.owner, + repo: context.repo.repo + }; + + const result = await github.graphql(query, variables); + const discussion = result.repository.discussions.nodes.find(d => + d.title === `RFC Discussion: ${context.payload.pull_request.title}` + ); + + if (discussion) { + core.setOutput('discussion_id', discussion.id); + core.info(`Found discussion: ${discussion.id}`); + } else { + core.info('Discussion not found'); + } + + - name: Update Discussion Content + if: steps.find-discussion.outputs.discussion_id && steps.changed-files.outputs.filename + uses: actions/github-script@v7 + with: + script: | + const discussionId = '${{ steps.find-discussion.outputs.discussion_id }}'; + const rfcContent = '${{ steps.get-rfc-content.outputs.content }}'; + const mdFile = '${{ steps.changed-files.outputs.filename }}'; + + // Build the body content parts + const title = `# RFC Discussion: ${{ github.event.pull_request.title }}`; + const author = `**Author:** @${{ github.event.pull_request.user.login }} | **Status:** 🟡 Under Review`; + const links = `## 📋 Quick Links + - 🔧 [Source PR #${{ github.event.pull_request.number }}](${{ github.event.pull_request.html_url }}) + - 📝 [View Changes](${{ github.event.pull_request.html_url }}/files) + - 📖 [Rendered Proposal](https://github.com/${{ github.repository }}/blob/${{ github.event.pull_request.head.ref }}/${mdFile})`; + + const proposalHeader = `## 📄 Current Proposal`; + const metadata = `> **Last Updated:** ${{ github.event.pull_request.updated_at }} + > **Commit:** [\`${{ github.event.pull_request.head.sha }}\`](${{ github.event.pull_request.head.repo.html_url }}/commit/${{ github.event.pull_request.head.sha }})`; + + const guidelines = `**💬 Discussion Guidelines:** Share feedback, concerns, and suggestions below. Use reply threads to keep conversations organized.`; + + // Combine all parts + const newBody = [ + title, + '', + author, + '', + links, + '', + '---', + '', + proposalHeader, + '', + metadata, + '', + '', + rfcContent, + '', + '', + '---', + guidelines + ].join('\n'); + + const mutation = ` + mutation($discussionId: ID!, $body: String!) { + updateDiscussion(input: { + discussionId: $discussionId, + body: $body + }) { + discussion { + id + title + } + } + } + `; + + const variables = { + discussionId: discussionId, + body: newBody + }; + + try { + const result = await github.graphql(mutation, variables); + core.info(`Successfully updated discussion: ${result.updateDiscussion.discussion.id}`); + } catch (error) { + core.setFailed(`Failed to update discussion: ${error.message}`); + } \ No newline at end of file