| 227 | let migrationNotified = false; |
| 228 | |
| 229 | export default class API { |
| 230 | apiRoot: string; |
| 231 | token: string; |
| 232 | tokenKeyword: string; |
| 233 | branch: string; |
| 234 | useOpenAuthoring?: boolean; |
| 235 | repo: string; |
| 236 | originRepo: string; |
| 237 | repoOwner: string; |
| 238 | repoName: string; |
| 239 | originRepoOwner: string; |
| 240 | originRepoName: string; |
| 241 | repoURL: string; |
| 242 | originRepoURL: string; |
| 243 | mergeMethod: string; |
| 244 | initialWorkflowStatus: string; |
| 245 | cmsLabelPrefix: string; |
| 246 | baseUrl?: string; |
| 247 | getUser: ({ token }: { token: string }) => Promise<GitHubUser>; |
| 248 | _userPromise?: Promise<GitHubUser>; |
| 249 | _metadataSemaphore?: Semaphore; |
| 250 | |
| 251 | commitAuthor?: {}; |
| 252 | |
| 253 | constructor(config: Config) { |
| 254 | this.apiRoot = config.apiRoot || 'https://api.github.com'; |
| 255 | this.token = config.token || ''; |
| 256 | this.tokenKeyword = config.tokenKeyword || 'token'; |
| 257 | this.branch = config.branch || 'master'; |
| 258 | this.useOpenAuthoring = config.useOpenAuthoring; |
| 259 | this.repo = config.repo || ''; |
| 260 | this.originRepo = config.originRepo || this.repo; |
| 261 | this.repoURL = `/repos/${this.repo}`; |
| 262 | // when not in 'useOpenAuthoring' mode originRepoURL === repoURL |
| 263 | this.originRepoURL = `/repos/${this.originRepo}`; |
| 264 | |
| 265 | const [repoParts, originRepoParts] = [this.repo.split('/'), this.originRepo.split('/')]; |
| 266 | this.repoOwner = repoParts[0]; |
| 267 | this.repoName = repoParts[1]; |
| 268 | |
| 269 | this.originRepoOwner = originRepoParts[0]; |
| 270 | this.originRepoName = originRepoParts[1]; |
| 271 | |
| 272 | this.mergeMethod = config.squashMerges ? 'squash' : 'merge'; |
| 273 | this.cmsLabelPrefix = config.cmsLabelPrefix; |
| 274 | this.initialWorkflowStatus = config.initialWorkflowStatus; |
| 275 | this.baseUrl = config.baseUrl; |
| 276 | this.getUser = config.getUser; |
| 277 | } |
| 278 | |
| 279 | static DEFAULT_COMMIT_MESSAGE = 'Automatically generated by Decap CMS'; |
| 280 | |
| 281 | user(): Promise<{ name: string; login: string; email?: string }> { |
| 282 | if (!this._userPromise) { |
| 283 | this._userPromise = this.getUser({ token: this.token }); |
| 284 | } |
| 285 | return this._userPromise.then(user => ({ |
| 286 | name: user.name || 'Unknown', |
nothing calls this directly
no test coverage detected