@@ -8,16 +8,18 @@ const { countClosedIssuesByAssignee } = require('../api/github-api');
88
99// Fast path: user has already completed ≥1 issue at this level or higher
1010async function passesBypassCheck ( github , homeRepo , username , candidate ) {
11- const atOrAbove = CONFIG . skillHierarchy . slice ( CONFIG . skillHierarchy . indexOf ( candidate ) ) ;
11+ const idx = CONFIG . skillHierarchy . indexOf ( candidate ) ;
12+ if ( idx === - 1 ) return false ;
13+ const atOrAbove = CONFIG . skillHierarchy . slice ( idx ) ;
1214
13- const counts = await Promise . all (
14- atOrAbove . map ( key => countClosedIssuesByAssignee (
15+ for ( const key of atOrAbove ) {
16+ const count = await countClosedIssuesByAssignee (
1517 github , homeRepo . owner , homeRepo . repo , username ,
1618 repoLabelFor ( homeRepo , key ) , 1 ,
17- ) )
18- ) ;
19-
20- return counts . some ( count => count !== null && count >= 1 ) ;
19+ ) ;
20+ if ( count !== null && count >= 1 ) return true ;
21+ }
22+ return false ;
2123}
2224
2325/**
@@ -49,7 +51,7 @@ async function passesNormalCheck(github, homeRepo, username, prereq) {
4951 * @param {object } homeRepo - Home repo entry from CONFIG.repos.
5052 * @param {string } username - GitHub login of the contributor.
5153 * @param {string } candidate - Canonical level key being evaluated.
52- * @returns {Promise<boolean|null > } True if eligible, false if not, null on API failure .
54+ * @returns {Promise<boolean> } True if eligible, false otherwise (API failures treated as false) .
5355 */
5456async function isEligibleFor ( github , homeRepo , username , candidate ) {
5557 const prereq = CONFIG . skillPrerequisites [ candidate ] ;
@@ -84,10 +86,10 @@ async function isEligibleFor(github, homeRepo, username, candidate) {
8486async function resolveEligibleLevel ( github , homeRepo , username ) {
8587 for ( const candidate of [ ...CONFIG . skillHierarchy ] . reverse ( ) ) {
8688 const eligible = await isEligibleFor ( github , homeRepo , username , candidate ) ;
87- // eligible === null means API failure — skip conservatively.
89+ // false includes API failures (treated conservatively as ineligible)
8890 if ( eligible === true ) return candidate ;
8991 }
90- return 'gfi' ;
92+ return CONFIG . skillHierarchy [ 0 ] ;
9193}
9294
9395/**
@@ -131,8 +133,10 @@ function adjustEligibilityForCurrentPR(completedKey, eligibleKey) {
131133async function detectUnlockedLevel ( github , homeRepo , username , currentLevelKey ) {
132134 const hierarchy = CONFIG . skillHierarchy ;
133135 const currentIndex = hierarchy . indexOf ( currentLevelKey ) ;
134- const nextKey = hierarchy [ currentIndex + 1 ] ?? null ;
135136
137+ if ( currentIndex === - 1 ) return null ;
138+
139+ const nextKey = hierarchy [ currentIndex + 1 ] ?? null ;
136140 if ( ! nextKey ) return null ;
137141
138142 const nextPrereq = CONFIG . skillPrerequisites [ nextKey ] ;
@@ -144,6 +148,7 @@ async function detectUnlockedLevel(github, homeRepo, username, currentLevelKey)
144148 ) ;
145149
146150 if ( count === null ) return null ;
151+ // NOTE: count is derived from first-page results only; safe because requiredCount is small.
147152 return count === nextPrereq . requiredCount ? nextKey : null ;
148153}
149154
0 commit comments