Skip to content

Commit 5610b6b

Browse files
committed
fix: improve help message and clarify environment variable usage in copy-discussions.js
1 parent 8335272 commit 5610b6b

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

scripts/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,22 @@ npm i octokit
5454
node ./copy-discussions.js source-org source-repo target-org target-repo
5555
```
5656

57+
Optional environment variables:
58+
59+
- `SOURCE_API_URL` - API endpoint for source (defaults to `https://api.github.com`)
60+
- `TARGET_API_URL` - API endpoint for target (defaults to `https://api.github.com`)
61+
62+
Example with GitHub Enterprise Server:
63+
64+
```bash
65+
export SOURCE_API_URL=https://github.mycompany.com/api/v3
66+
export TARGET_API_URL=https://api.github.com
67+
export SOURCE_TOKEN=ghp_abc
68+
export TARGET_TOKEN=ghp_xyz
69+
npm i octokit
70+
node ./copy-discussions.js source-org source-repo target-org target-repo
71+
```
72+
5773
Features:
5874

5975
- Automatically creates missing discussion categories in the target repository

scripts/copy-discussions.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
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
82101
const sourceOctokit = new Octokit({
83-
auth: process.env.SOURCE_TOKEN
102+
auth: process.env.SOURCE_TOKEN,
103+
baseUrl: SOURCE_API_URL
84104
});
85105

86106
const 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

Comments
 (0)