Skip to content

Conversation

joshjohanning
Copy link
Owner

@joshjohanning joshjohanning commented Oct 1, 2025

Creating script to copy/migrate discussions between GitHub orgs/repos. Started with a shell script, so including that for now, but ultimately because it's so long/complex, moving to node.

TODO

  • copy discussions
  • apply labels
  • apply categories (note we cannot re-create categories they need to be done ahead of time!!)
  • copy comments
  • copy child comments
  • including source metadata as expandable drodpown
  • Use / recommend GitHub App instead of personal access token
  • Polls don't copy options - probably nothing can be done here
  • See if we can migrate the polls "statically" somehow; perhaps even using Mermaid!
  • document polls and mermaid chart - their is a const if you want to or not copy the poll results as mermaid
  • Mark as answers
  • migrate discussion state (copying/migrating discussions as closed)
  • Migrate reactions (statically)
  • Better arguments/options usage and --help with yargs (don't want to take another dependency with yargs)
  • Ability to pick up from a certain discussion post / post ID in recovery/restart scenarios
  • Add API endpoint inputs for source and target
  • Adds rate limit throttling with configurable delays (0.5s per API call, 5s between processing discussions)
  • detect if secondary rate limit has been hit and progressively backoff
  • adjust discussion processing delay to comply with GitHub's rate limit recommendations (wait 3 seconds after every discussion and comment creation)
  • track and output primary and secondary rate limit hits for improved monitoring
  • enhance rate limit handling with Octokit throttling (Retry-After) and remove manual retry logic

NOTES

  • Secondary rate limits when creating discussions are a thing. This app uses progressive backoffs when secondary rate limits are hit.
  • Pinning of discussions is not possible
  • Creating discussion categories is not possible

Usage

For right now, have both Bash and Node.

export SOURCE_TOKEN=ghp_...
export TARGET_TOKEN=ghp_...
# export SOURCE_API_URL= # if GHES
# export TARGET_API_URL= # if GHES/ghe.com
cd ./scripts/migrate-discussions
npm i
node ./migrate-discussions.js source-org source-repo target-org target-repo

Example

Final output

[2025-10-02 19:38:44] ============================================================
[2025-10-02 19:38:44] Discussion copy completed!
[2025-10-02 19:38:44] Total discussions found: 10
[2025-10-02 19:38:44] Discussions created: 10
[2025-10-02 19:38:44] Discussions skipped: 0
[2025-10-02 19:38:44] Total comments found: 9
[2025-10-02 19:38:44] Comments copied: 9
[2025-10-02 19:38:44] Primary rate limits hit: 0
[2025-10-02 19:38:44] Secondary rate limits hit: 2
[2025-10-02 19:38:44] WARNING: 
The following categories were missing and need to be created manually:
[2025-10-02 19:38:44] WARNING:   - Blog posts!
[2025-10-02 19:38:44] WARNING: 
[2025-10-02 19:38:44] WARNING: To create categories manually:
[2025-10-02 19:38:44] WARNING: 1. Go to https://github.com/joshjohanning-emu/discussions-test/discussions
[2025-10-02 19:38:44] WARNING: 2. Click 'New discussion'
[2025-10-02 19:38:44] WARNING: 3. Look for category management options
[2025-10-02 19:38:44] WARNING: 4. Create the missing categories with appropriate names and descriptions
[2025-10-02 19:38:44] 
All done! ✨

SOURCE

Discussion list (note locked and closed translate):
image

Discussion with comments and child comments:
image

Discussion with answer:
image

Discussion with reactions:
image

Discussion with poll:
image

TARGET

Discussion list (note locked and closed translate):
image

Discussion with comments and child comments:
image

Discussion with answer:
image

Discussion with reactions:
image

Discussion with poll:
image

Copy link

github-actions bot commented Oct 1, 2025

📋 Lint Results

⚡ ./gh-cli scripts

✅ No issues found.

🔧 ./scripts scripts

✅ No issues found.

Lint results updated at Mon Oct 6 18:32:53 UTC 2025

…-discussions

- Move script to migrate-discussions/ subdirectory structure
- Rename from copy-discussions.js to migrate-discussions.js
- Update documentation to reflect migration terminology
- Add package.json with octokit dependency
- Enhance README with rate limiting and resume features
- Update .gitignore to allow nested package.json files
@joshjohanning joshjohanning changed the title copy/migrate discussions script feat: add discussions-migration script Oct 2, 2025
@joshjohanning joshjohanning marked this pull request as ready for review October 6, 2025 18:24
@joshjohanning joshjohanning requested a review from Copilot October 6, 2025 18:25
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a comprehensive Node.js script for migrating GitHub Discussions between repositories across different GitHub instances. The script supports cross-enterprise migrations with automatic rate limit handling, resume capabilities, and preserves discussion content including comments, reactions, polls, and metadata.

Key changes:

  • Adds a complete discussions migration solution with Node.js implementation
  • Includes comprehensive rate limiting and retry logic with Octokit throttling
  • Supports resume functionality and cross-instance migrations

Reviewed Changes

Copilot reviewed 4 out of 6 changed files in this pull request and generated 8 comments.

File Description
scripts/migrate-discussions/package.json Package configuration for the Node.js migration script with Octokit dependency
scripts/migrate-discussions/migrate-discussions.js Main migration script with GraphQL queries, rate limiting, and comprehensive discussion copying logic
scripts/migrate-discussions/README.md Detailed documentation covering usage, features, configuration options, and examples
scripts/README.md Updated main scripts README to reference the new migrate-discussions script
Files not reviewed (1)
  • scripts/migrate-discussions/package-lock.json: Language not supported

@joshjohanning joshjohanning merged commit d527b88 into main Oct 6, 2025
7 checks passed
@joshjohanning joshjohanning deleted the copy-discussions branch October 6, 2025 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant