@@ -23,10 +23,14 @@ export interface SubmitOpts {
2323 quiet ?: boolean ;
2424 languages ?: string [ ] ;
2525 componentDetectionBinPath ?: string ; // optional path to component-detection executable
26+ lightDelayMs ?: number ;
2627}
2728
28- export async function getLanguageIntersection ( octokit : Octokit , owner : string , repo : string , languages : string [ ] | undefined , quiet : boolean = false ) : Promise < string [ ] > {
29+ export async function getLanguageIntersection ( octokit : Octokit , owner : string , repo : string , languages : string [ ] | undefined , quiet : boolean = false , lightDelayMs : number = 0 ) : Promise < string [ ] > {
2930 const langResp = await octokit . request ( 'GET /repos/{owner}/{repo}/languages' , { owner, repo } ) ;
31+
32+ await new Promise ( r => setTimeout ( r , lightDelayMs ) ) ;
33+
3034 const repoLangs = Object . keys ( langResp . data || { } ) ;
3135 const wanted = languages ;
3236 const intersect = wanted ? repoLangs . filter ( l => wanted . some ( w => w . toLowerCase ( ) === l . toLowerCase ( ) ) ) : repoLangs ;
@@ -37,7 +41,7 @@ export async function getLanguageIntersection(octokit: Octokit, owner: string, r
3741 return intersect ;
3842}
3943
40- export async function sparseCheckout ( owner : string , repo : string , branch : string , destDir : string , intersect : string [ ] , baseUrl ?: string ) {
44+ export async function sparseCheckout ( owner : string , repo : string , branch : string , destDir : string , intersect : string [ ] , baseUrl ?: string , lightDelayMs ?: number ) {
4145 const cwd = destDir ;
4246 const repoUrl = ( baseUrl && baseUrl . includes ( 'api/v3' ) )
4347 ? baseUrl . replace ( / \/ a p i \/ v 3 $ / , '' ) + `/${ owner } /${ repo } .git`
@@ -52,6 +56,8 @@ export async function sparseCheckout(owner: string, repo: string, branch: string
5256 await execGit ( [ 'fetch' , '--depth=1' , 'origin' , branch ] , { cwd } ) ;
5357 await execGit ( [ 'checkout' , 'FETCH_HEAD' ] , { cwd } ) ;
5458
59+ await new Promise ( r => setTimeout ( r , lightDelayMs ) ) ;
60+
5561 const { stdout : shaOut } = await execGit ( [ 'rev-parse' , 'HEAD' ] , { cwd : destDir } ) ;
5662 const sha = shaOut . trim ( ) ;
5763 console . debug ( `Checked out ${ owner } /${ repo } @${ branch } to ${ destDir } at commit ${ sha } ` ) ;
@@ -66,22 +72,22 @@ export async function submitSnapshotIfPossible(opts: SubmitOpts): Promise<boolea
6672 const tmp = await fs . promises . mkdtemp ( path . join ( os . tmpdir ( ) , 'cd-submission-' ) ) ;
6773
6874 try {
69- const intersect = await getLanguageIntersection ( opts . octokit , opts . owner , opts . repo , opts . languages ) ;
75+ const intersect = await getLanguageIntersection ( opts . octokit , opts . owner , opts . repo , opts . languages , opts . quiet , opts . lightDelayMs ) ;
7076 // Create temp dir and sparse checkout only manifest files according to selected languages
7177 if ( ! intersect . length ) {
7278 // No matching languages, skip submission
7379 return true ;
7480 }
7581 console . debug ( chalk . green ( `Sparse checkout into ${ tmp } for languages: ${ intersect . join ( ', ' ) } ` ) ) ;
7682
77- const sha = await sparseCheckout ( opts . owner , opts . repo , opts . branch , tmp , intersect , opts . baseUrl ) ;
83+ const sha = await sparseCheckout ( opts . owner , opts . repo , opts . branch , tmp , intersect , opts . baseUrl , opts . lightDelayMs ) ;
7884
7985 // Run the ComponentDetection module to detect components and submit snapshot
8086 if ( ! sha ) {
8187 if ( ! opts . quiet ) console . error ( chalk . red ( `Failed to determine SHA for ${ opts . owner } /${ opts . repo } on branch ${ opts . branch } ` ) ) ;
8288 return false ;
8389 }
84- return await run ( opts . octokit , tmp , opts . owner , opts . repo , sha , opts . branch , opts . componentDetectionBinPath ) ;
90+ return await runComponentDetectionAndSubmit ( opts . octokit , tmp , opts . owner , opts . repo , sha , opts . branch , opts . componentDetectionBinPath ) ;
8591
8692 } catch ( e ) {
8793 if ( ! opts . quiet ) console . error ( chalk . red ( `Component Detection failed: ${ ( e as Error ) . message } ` ) ) ;
@@ -150,7 +156,7 @@ async function execGit(args: string[], opts: { cwd: string, quiet?: boolean }):
150156 } ) ;
151157}
152158
153- export async function run ( octokit : Octokit , tmpDir : string , owner : string , repo : string , sha : string , ref : string , componentDetectionBinPath ?: string ) : Promise < boolean > {
159+ export async function runComponentDetectionAndSubmit ( octokit : Octokit , tmpDir : string , owner : string , repo : string , sha : string , ref : string , componentDetectionBinPath ?: string ) : Promise < boolean > {
154160
155161 const componentDetection = new ComponentDetection ( octokit , '' , componentDetectionBinPath ) ;
156162
0 commit comments