Skip to content

Commit 2afc684

Browse files
authored
Wait for fork to become available (#6635)
Fixes #6492
1 parent 7daa11a commit 2afc684

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/github/githubRepository.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ export class GitHubRepository extends Disposable {
441441
Logger.debug('Fetch pull request templates - done', this.id);
442442
return result.data.repository.pullRequestTemplates.map(template => template.body);
443443
} catch (e) {
444-
Logger.error(`Fetching pull request templates failed: ${e}`, this.id);
444+
// The template was not found.
445445
}
446446
}
447447

@@ -837,6 +837,24 @@ export class GitHubRepository extends Disposable {
837837
owner: remote.owner,
838838
repo: remote.repositoryName,
839839
});
840+
Logger.debug(`Fork repository - done`, this.id);
841+
// GitHub can say the fork succeeded but it isn't actually ready yet.
842+
// So we wait up to 5 seconds for the fork to be ready
843+
const start = Date.now();
844+
let exists = async () => {
845+
try {
846+
await octokit.call(octokit.api.repos.get, { owner: result.data.owner.login, repo: result.data.name });
847+
Logger.appendLine('Fork ready', this.id);
848+
return true;
849+
} catch (e) {
850+
Logger.appendLine('Fork not ready yet', this.id);
851+
return false;
852+
}
853+
};
854+
while (!(await exists()) && ((Date.now() - start) < 5000)) {
855+
await new Promise(resolve => setTimeout(resolve, 500));
856+
}
857+
840858
return result.data.clone_url;
841859
} catch (e) {
842860
Logger.error(`GitHubRepository> Forking repository failed: ${e}`, this.id);

0 commit comments

Comments
 (0)