Skip to content

Commit e6c210b

Browse files
committed
Move Codex repo branch logic to func
1 parent 0f68d56 commit e6c210b

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

pixel.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,21 @@ function removeFolder( relativePath ) {
162162
fs.rmSync( `${__dirname}/${relativePath}`, { recursive: true, force: true } );
163163
}
164164

165+
async function updateCodexRepoBranchIfNecessary( opts, mwBranch ) {
166+
// If the user hasn't specified a '--repo-branch' for codex
167+
// determine which version the MW branch wants and use it
168+
if ( !opts.repoBranch?.some( ( branch ) => branch.startsWith( 'design/codex:' ) ) ) {
169+
let codexVersion;
170+
try {
171+
codexVersion = await getCodexVersionForMWBranch( mwBranch );
172+
} catch ( error ) {
173+
codexVersion = await getLatestCodexVersion();
174+
console.log( `\x1b[33m${error.message}Falling back to latest Codex version ${codexVersion}\x1b[0m` );
175+
}
176+
opts.repoBranch = [ ...( opts.repoBranch ?? [] ), `design/codex:${codexVersion}` ];
177+
}
178+
}
179+
165180
/**
166181
* @typedef {Object} CommandOptions
167182
* @property {string[]} [changeId]
@@ -183,26 +198,12 @@ async function processCommand( type, opts, runSilently = false ) {
183198

184199
setEnvironmentFlagIfGroup( 'ENABLE_WIKILAMBDA', 'wikilambda', group );
185200

186-
const activeBranch = await getActiveBranch( opts );
187-
188-
// If the user hasn't specified a '--repo-branch' for codex
189-
// determine which version the MW branch wants and use it
190-
if ( !opts.repoBranch?.some( ( branch ) => branch.startsWith( 'design/codex:' ) ) ) {
191-
let codexVersion;
192-
try {
193-
codexVersion = await getCodexVersionForMWBranch( activeBranch );
194-
} catch ( error ) {
195-
codexVersion = await getLatestCodexVersion();
196-
console.log( `\x1b[33m${error.message}Falling back to latest Codex version ${codexVersion}\x1b[0m` );
197-
}
198-
opts.repoBranch = [ ...( opts.repoBranch ?? [] ), `design/codex:${codexVersion}` ];
199-
}
200-
console.log( 'repoBranch:' );
201-
console.log( opts.repoBranch );
202-
// process.exit ( 1 )
201+
const activeMWBranch = await getActiveBranch( opts );
202+
203+
await updateCodexRepoBranchIfNecessary( opts, activeMWBranch );
203204

204205
const description = getDescription( opts );
205-
updateContext( group, type, activeBranch, description );
206+
updateContext( group, type, activeMWBranch, description );
206207

207208
await prepareDockerEnvironment( opts );
208209
const { stdout: stdout1 } = await simpleSpawn.exec( './purgeParserCache.sh' );

0 commit comments

Comments
 (0)