MCPcopy Index your code
hub / github.com/sourcebot-dev/sourcebot / collectGitHubConfig

Function collectGitHubConfig

packages/setupWizard/src/github.ts:72–222  ·  view source on GitHub ↗
(connectionName: string)

Source from the content-addressed store, hash-verified

70}
71
72export async function collectGitHubConfig(connectionName: string): Promise<CollectResult> {
73 const env: EnvVars = {};
74 const config: GithubConnectionConfig = { type: 'github' };
75
76 const url = await input({
77 message: 'GitHub URL',
78 default: 'https://github.com',
79 theme: INPUT_THEME,
80 validate: (v) => {
81 if (!v?.trim()) {
82 return 'URL is required';
83 }
84 if (!/^https?:\/\//.test(v)) {
85 return 'Must start with http:// or https://';
86 }
87 return true;
88 },
89 });
90 if (url !== 'https://github.com') {
91 config.url = url;
92 }
93
94 note(
95 [
96 'Fine-grained PAT (recommended):',
97 ` ${url}/settings/personal-access-tokens/new`,
98 ' Required permissions: Contents (read), Metadata (read)',
99 '',
100 'Classic PAT:',
101 ` ${url}/settings/tokens/new`,
102 ' Required scope: repo',
103 ].join('\n'),
104 'Create a GitHub Personal Access Token',
105 );
106
107 const tokenEnvKey = toEnvKey(connectionName, 'TOKEN');
108 const token = await password({
109 message: `GitHub Personal Access Token (stored locally in .env as ${tokenEnvKey}, leave blank for public repos only)`,
110 mask: true,
111 });
112 if (token.trim()) {
113 env[tokenEnvKey] = token;
114 config.token = { env: tokenEnvKey };
115 }
116
117 const apiBase = githubApiBase(url);
118
119 const targets = await checkbox<string>({
120 message: 'What do you want to index?',
121 choices: [
122 { value: 'repos', name: 'Specific repositories', description: 'Hand-pick individual repos to index' },
123 { value: 'orgs', name: 'Organizations', description: 'Index every repo each chosen org owns' },
124 { value: 'users', name: 'Users', description: 'Index every repo each chosen user owns' },
125 ],
126 required: true,
127 });
128
129 if (targets.includes('repos')) {

Callers 1

mainFunction · 0.85

Calls 5

noteFunction · 0.85
toEnvKeyFunction · 0.85
githubApiBaseFunction · 0.85
searchGitHubFunction · 0.85

Tested by

no test coverage detected