({ token, url }: { token?: string, url?: string })
| 101 | } |
| 102 | |
| 103 | export const createOctokitFromToken = async ({ token, url }: { token?: string, url?: string }): Promise<{ octokit: Octokit, isAuthenticated: boolean }> => { |
| 104 | const isGitHubCloud = url ? new URL(url).hostname === GITHUB_CLOUD_HOSTNAME : true; |
| 105 | const octokit = new Octokit({ |
| 106 | auth: token, |
| 107 | ...(url && !isGitHubCloud ? { |
| 108 | baseUrl: `${url}/api/v3` |
| 109 | } : {}), |
| 110 | }); |
| 111 | |
| 112 | return { |
| 113 | octokit, |
| 114 | isAuthenticated: !!token, |
| 115 | }; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Helper function to get an authenticated Octokit instance using GitHub App if available, |
no outgoing calls
no test coverage detected