- Simplify parseApkFilename to use version delimiter split - Update tests to match new data structure with rawEnvironment - Remove unnecessary test cases and assertions Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import { APK_TABS } from './constants';
|
|
|
|
export type ApkEnvironment = 'product' | 'dev' | 'sandbox' | 'other';
|
|
|
|
export interface ParsedApkMetadata {
|
|
environment: ApkEnvironment;
|
|
rawEnvironment: string;
|
|
commit: string | null;
|
|
isValid: boolean;
|
|
}
|
|
|
|
export function getApkTabs(): string[] {
|
|
return APK_TABS;
|
|
}
|
|
|
|
export function detectEnvironment(prefix: string, configuredTabs: string[]): { environment: ApkEnvironment; rawEnvironment: string } {
|
|
// Empty prefix → other
|
|
if (!prefix) {
|
|
return { environment: 'other', rawEnvironment: 'other' };
|
|
}
|
|
|
|
// No underscore means product (e.g., "ft")
|
|
if (!prefix.includes('_')) {
|
|
return { environment: 'product', rawEnvironment: 'product' };
|
|
}
|
|
|
|
// Extract environment from last segment after underscore
|
|
const lastUnderscoreIndex = prefix.lastIndexOf('_');
|
|
const rawEnv = prefix.substring(lastUnderscoreIndex + 1);
|
|
|
|
// Check if environment is configured
|
|
if (configuredTabs.includes(rawEnv)) {
|
|
return { environment: rawEnv as ApkEnvironment, rawEnvironment: rawEnv };
|
|
}
|
|
|
|
return { environment: 'other', rawEnvironment: rawEnv };
|
|
}
|
|
|
|
export function parseApkFilename(filename: string, version: string): ParsedApkMetadata {
|
|
// Use version as delimiter (with leading underscore)
|
|
const delimiter = `_${version}_`;
|
|
const filenameWithoutExt = filename.replace(/\.apk$/, '');
|
|
const parts = filenameWithoutExt.split(delimiter);
|
|
const { environment, rawEnvironment } = detectEnvironment(parts[0], APK_TABS);
|
|
const commit = parts[1].substring(0, 9);
|
|
|
|
return {
|
|
environment,
|
|
rawEnvironment,
|
|
commit,
|
|
isValid: commit !== null,
|
|
};
|
|
}
|