({ inputs }, context)
| 136 | ], |
| 137 | }, |
| 138 | async execute({ inputs }, context) { |
| 139 | const { organization, teamSlug, userIdentifier, connectionId } = inputSchema.parse(inputs); |
| 140 | |
| 141 | const trimmedConnectionId = connectionId.trim(); |
| 142 | |
| 143 | if (trimmedConnectionId.length === 0) { |
| 144 | throw new ConfigurationError( |
| 145 | 'GitHub connection ID is required when using an existing connection.', |
| 146 | { |
| 147 | configKey: 'connectionId', |
| 148 | }, |
| 149 | ); |
| 150 | } |
| 151 | |
| 152 | context.emitProgress( |
| 153 | `Retrieving GitHub access token from connection ${trimmedConnectionId}...`, |
| 154 | ); |
| 155 | const connectionToken = await fetchConnectionAccessToken(trimmedConnectionId, context); |
| 156 | const accessToken = connectionToken.accessToken; |
| 157 | const tokenType = connectionToken.tokenType ?? 'Bearer'; |
| 158 | const tokenScope = |
| 159 | Array.isArray(connectionToken.scopes) && connectionToken.scopes.length > 0 |
| 160 | ? connectionToken.scopes.join(' ') |
| 161 | : undefined; |
| 162 | |
| 163 | const authorizationScheme = |
| 164 | tokenType && tokenType.trim().length > 0 ? tokenType.trim() : 'Bearer'; |
| 165 | |
| 166 | const headers = { |
| 167 | // Use token obtained via selected authentication mode |
| 168 | Authorization: `${authorizationScheme} ${accessToken}`, |
| 169 | Accept: 'application/vnd.github+json', |
| 170 | 'User-Agent': 'shipsecai-worker/1.0', |
| 171 | 'X-GitHub-Api-Version': '2022-11-28', |
| 172 | }; |
| 173 | |
| 174 | const login = await resolveLogin(userIdentifier, headers, context); |
| 175 | |
| 176 | let teamRemovalStatus: 'removed' | 'not_found' | 'skipped' = 'skipped'; |
| 177 | let removedFromTeam = false; |
| 178 | |
| 179 | if (teamSlug) { |
| 180 | context.emitProgress(`Removing ${login} from team ${teamSlug}...`); |
| 181 | let teamResponse: Response; |
| 182 | try { |
| 183 | teamResponse = await context.http.fetch( |
| 184 | `https://api.github.com/orgs/${encodeURIComponent(organization)}/teams/${encodeURIComponent(teamSlug)}/memberships/${encodeURIComponent(login)}`, |
| 185 | { |
| 186 | method: 'DELETE', |
| 187 | headers, |
| 188 | }, |
| 189 | ); |
| 190 | } catch (error) { |
| 191 | throw new NetworkError( |
| 192 | `GitHub API request failed while removing ${login} from team ${teamSlug}: ${(error as Error).message}`, |
| 193 | { cause: error as Error }, |
| 194 | ); |
| 195 | } |
nothing calls this directly
no test coverage detected