Skip to content

[test] Add TEST RFC to verify enhanced discussion workflow #5

[test] Add TEST RFC to verify enhanced discussion workflow

[test] Add TEST RFC to verify enhanced discussion workflow #5

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
env:
DISCUSSION_ID: ${{ steps.find-discussion.outputs.discussion_id }}
RFC_CONTENT: ${{ steps.get-rfc-content.outputs.content }}
MD_FILE: ${{ steps.changed-files.outputs.filename }}
PR_TITLE: ${{ github.event.pull_request.title }}
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_URL: ${{ github.event.pull_request.html_url }}
REPO_NAME: ${{ github.repository }}
HEAD_REF: ${{ github.event.pull_request.head.ref }}
UPDATED_AT: ${{ github.event.pull_request.updated_at }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
HEAD_REPO_URL: ${{ github.event.pull_request.head.repo.html_url }}
with:
script: |
const discussionId = process.env.DISCUSSION_ID;
const rfcContent = process.env.RFC_CONTENT;
const mdFile = process.env.MD_FILE;
// Build the body content parts
const title = `# RFC Discussion: ${process.env.PR_TITLE}`;
const author = `**Author:** @${process.env.PR_AUTHOR} | **Status:** 🟡 Under Review`;
const links = `## 📋 Quick Links
- 🔧 [Source PR #${process.env.PR_NUMBER}](${process.env.PR_URL})
- 📝 [View Changes](${process.env.PR_URL}/files)
- 📖 [Rendered Proposal](https://github.com/${process.env.REPO_NAME}/blob/${process.env.HEAD_REF}/${mdFile})`;
const proposalHeader = `## 📄 Current Proposal`;
const metadata = `> **Last Updated:** ${process.env.UPDATED_AT}
> **Commit:** [\`${process.env.HEAD_SHA}\`](${process.env.HEAD_REPO_URL}/commit/${process.env.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,
'',
'<!-- RFC_CONTENT_START -->',
rfcContent,
'<!-- RFC_CONTENT_END -->',
'',
'---',
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}`);
}