| 226 | } |
| 227 | |
| 228 | export default class API { |
| 229 | apiVersion: string; |
| 230 | token: string; |
| 231 | branch: string; |
| 232 | mergeStrategy: string; |
| 233 | endpointUrl: string; |
| 234 | initialWorkflowStatus: string; |
| 235 | cmsLabelPrefix: string; |
| 236 | |
| 237 | constructor(config: AzureApiConfig, token: string) { |
| 238 | const { repo } = config; |
| 239 | const apiRoot = trim(config.apiRoot, '/'); |
| 240 | this.endpointUrl = `${apiRoot}/${repo.org}/${repo.project}/_apis/git/repositories/${repo.repoName}`; |
| 241 | this.token = token; |
| 242 | this.branch = config.branch; |
| 243 | this.mergeStrategy = config.squashMerges ? 'squash' : 'noFastForward'; |
| 244 | this.initialWorkflowStatus = config.initialWorkflowStatus; |
| 245 | this.apiVersion = config.apiVersion; |
| 246 | this.cmsLabelPrefix = config.cmsLabelPrefix; |
| 247 | } |
| 248 | |
| 249 | withHeaders = (req: ApiRequest) => { |
| 250 | const withHeaders = unsentRequest.withHeaders( |
| 251 | { |
| 252 | Authorization: `Bearer ${this.token}`, |
| 253 | 'Content-Type': 'application/json; charset=utf-8', |
| 254 | }, |
| 255 | req, |
| 256 | ); |
| 257 | return withHeaders; |
| 258 | }; |
| 259 | |
| 260 | withAzureFeatures = (req: Map<string, Map<string, string>>) => { |
| 261 | if (req.hasIn(['params', API_VERSION])) { |
| 262 | return req; |
| 263 | } |
| 264 | const withParams = unsentRequest.withParams( |
| 265 | { |
| 266 | [API_VERSION]: `${this.apiVersion}`, |
| 267 | }, |
| 268 | req, |
| 269 | ); |
| 270 | |
| 271 | return withParams; |
| 272 | }; |
| 273 | |
| 274 | buildRequest = (req: ApiRequest) => { |
| 275 | const withHeaders = this.withHeaders(req); |
| 276 | const withAzureFeatures = this.withAzureFeatures(withHeaders); |
| 277 | if (withAzureFeatures.has('cache')) { |
| 278 | return withAzureFeatures; |
| 279 | } else { |
| 280 | const withNoCache = unsentRequest.withNoCache(withAzureFeatures); |
| 281 | return withNoCache; |
| 282 | } |
| 283 | }; |
| 284 | |
| 285 | request = (req: ApiRequest): Promise<Response> => { |
nothing calls this directly
no test coverage detected