1717// - Both tokens must have the 'repo' scope
1818// - Dependencies installed via `npm i octokit`
1919//
20+ // Optional Environment Variables:
21+ // - SOURCE_API_URL: API endpoint for source (defaults to https://api.github.com)
22+ // - TARGET_API_URL: API endpoint for target (defaults to https://api.github.com)
23+ //
2024// Note: This script copies discussion content, comments, replies, polls, reactions, locked status,
2125// and pinned status. Reactions are copied as read-only summaries.
2226// Attachments (images and files) will not copy over - they need manual handling.
@@ -42,13 +46,24 @@ if (args.includes('--help') || args.includes('-h')) {
4246 console . log ( ' target_org Target organization name' ) ;
4347 console . log ( ' target_repo Target repository name' ) ;
4448 console . log ( '' ) ;
45- console . log ( 'Environment Variables:' ) ;
46- console . log ( ' SOURCE_TOKEN GitHub token with read access to source repository discussions' ) ;
47- console . log ( ' TARGET_TOKEN GitHub token with write access to target repository discussions' ) ;
49+ console . log ( 'Environment Variables (Required):' ) ;
50+ console . log ( ' SOURCE_TOKEN GitHub token with read access to source repository discussions' ) ;
51+ console . log ( ' TARGET_TOKEN GitHub token with write access to target repository discussions' ) ;
52+ console . log ( '' ) ;
53+ console . log ( 'Environment Variables (Optional):' ) ;
54+ console . log ( ' SOURCE_API_URL API endpoint for source (defaults to https://api.github.com)' ) ;
55+ console . log ( ' TARGET_API_URL API endpoint for target (defaults to https://api.github.com)' ) ;
4856 console . log ( '' ) ;
4957 console . log ( 'Example:' ) ;
5058 console . log ( ' node copy-discussions.js source-org repo1 target-org repo2' ) ;
5159 console . log ( '' ) ;
60+ console . log ( 'Example with GHES:' ) ;
61+ console . log ( ' SOURCE_API_URL=https://github.mycompany.com/api/v3 \\' ) ;
62+ console . log ( ' TARGET_API_URL=https://api.github.com \\' ) ;
63+ console . log ( ' SOURCE_TOKEN=ghp_xxx \\' ) ;
64+ console . log ( ' TARGET_TOKEN=ghp_yyy \\' ) ;
65+ console . log ( ' node copy-discussions.js source-org repo1 target-org repo2' ) ;
66+ console . log ( '' ) ;
5267 console . log ( 'Note:' ) ;
5368 console . log ( ' - Both tokens must have the "repo" scope' ) ;
5469 console . log ( ' - This script copies discussion content, comments, replies, polls, reactions,' ) ;
@@ -78,13 +93,19 @@ if (!process.env.TARGET_TOKEN) {
7893 process . exit ( 1 ) ;
7994}
8095
96+ // Get API endpoints from environment variables (optional)
97+ const SOURCE_API_URL = process . env . SOURCE_API_URL || 'https://api.github.com' ;
98+ const TARGET_API_URL = process . env . TARGET_API_URL || 'https://api.github.com' ;
99+
81100// Initialize Octokit instances
82101const sourceOctokit = new Octokit ( {
83- auth : process . env . SOURCE_TOKEN
102+ auth : process . env . SOURCE_TOKEN ,
103+ baseUrl : SOURCE_API_URL
84104} ) ;
85105
86106const targetOctokit = new Octokit ( {
87- auth : process . env . TARGET_TOKEN
107+ auth : process . env . TARGET_TOKEN ,
108+ baseUrl : TARGET_API_URL
88109} ) ;
89110
90111// Tracking variables
0 commit comments