()
| 163 | * @returns true if GitHub token is synced, false otherwise |
| 164 | */ |
| 165 | export async function checkGithubTokenSynced(): Promise<boolean> { |
| 166 | try { |
| 167 | let accessToken: string |
| 168 | let orgUUID: string |
| 169 | try { |
| 170 | const capability = await resolveManagedRemoteCapability() |
| 171 | accessToken = capability.accessToken |
| 172 | orgUUID = capability.orgUUID |
| 173 | } catch { |
| 174 | logForDebugging( |
| 175 | 'checkGithubTokenSynced: Managed remote auth unavailable', |
| 176 | ) |
| 177 | return false |
| 178 | } |
| 179 | |
| 180 | const url = buildNoumenaPlatformUrl( |
| 181 | `/api/oauth/organizations/${orgUUID}/sync/github/auth`, |
| 182 | ) |
| 183 | const headers = { |
| 184 | ...getOAuthHeaders(accessToken), |
| 185 | 'x-organization-uuid': orgUUID, |
| 186 | } |
| 187 | |
| 188 | logForDebugging('Checking if GitHub token is synced via web-setup') |
| 189 | |
| 190 | const response = await axios.get(url, { |
| 191 | headers, |
| 192 | timeout: 15000, |
| 193 | }) |
| 194 | |
| 195 | const synced = |
| 196 | response.status === 200 && response.data?.is_authenticated === true |
| 197 | logForDebugging( |
| 198 | `GitHub token synced: ${synced} (status=${response.status}, data=${JSON.stringify(response.data)})`, |
| 199 | ) |
| 200 | return synced |
| 201 | } catch (error) { |
| 202 | if (axios.isAxiosError(error)) { |
| 203 | const status = error.response?.status |
| 204 | if (status && status >= 400 && status < 500) { |
| 205 | logForDebugging( |
| 206 | `checkGithubTokenSynced: Got ${status}, token not synced`, |
| 207 | ) |
| 208 | return false |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | logForDebugging(`checkGithubTokenSynced error: ${errorMessage(error)}`) |
| 213 | return false |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | type RepoAccessMethod = 'github-app' | 'token-sync' | 'none' |
| 218 |
no test coverage detected