Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions .github/workflows/rfc-discussion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
<!-- RFC_CONTENT_START -->
${{ steps.get-rfc-content.outputs.content }}
<!-- RFC_CONTENT_END -->

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"

Expand Down
158 changes: 158 additions & 0 deletions .github/workflows/sync-rfc-discussion.yml
Original file line number Diff line number Diff line change
@@ -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,
'',
'<!-- 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}`);
}