- Changed parseApkFilename to accept version parameter - New parsing logic splits filename by version string to extract prefix - detectEnvironment now takes prefix and configured tabs as arguments - Environments not in APK_TABS are mapped to 'other' instead of hardcoded mapping - Added getApkTabs helper function to expose configured tabs - Updated all tests to use new API with version parameter Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
63 lines
1.5 KiB
TypeScript
63 lines
1.5 KiB
TypeScript
import { APK_TABS } from './constants';
|
|
|
|
export type ApkEnvironment = 'product' | 'dev' | 'sandbox' | 'other';
|
|
|
|
export interface ParsedApkMetadata {
|
|
environment: ApkEnvironment;
|
|
commit: string | null;
|
|
isValid: boolean;
|
|
}
|
|
|
|
export function getApkTabs(): string[] {
|
|
return APK_TABS;
|
|
}
|
|
|
|
export function detectEnvironment(prefix: string, configuredTabs: string[]): ApkEnvironment {
|
|
// Empty prefix → other
|
|
if (!prefix) {
|
|
return 'other';
|
|
}
|
|
|
|
// No underscore means product (e.g., "ft")
|
|
if (!prefix.includes('_')) {
|
|
return 'product';
|
|
}
|
|
|
|
// Extract environment from last segment after underscore
|
|
const lastUnderscoreIndex = prefix.lastIndexOf('_');
|
|
const env = prefix.substring(lastUnderscoreIndex + 1);
|
|
|
|
// Check if environment is configured
|
|
if (configuredTabs.includes(env)) {
|
|
return env as ApkEnvironment;
|
|
}
|
|
|
|
return 'other';
|
|
}
|
|
|
|
export function parseApkFilename(filename: string, version: string): ParsedApkMetadata {
|
|
// Use version as delimiter (with leading underscore)
|
|
const delimiter = `_${version}`;
|
|
const delimiterIndex = filename.indexOf(delimiter);
|
|
|
|
let prefix: string;
|
|
if (delimiterIndex > 0) {
|
|
prefix = filename.substring(0, delimiterIndex);
|
|
} else {
|
|
// Fallback: can't find version delimiter
|
|
prefix = '';
|
|
}
|
|
|
|
const environment = detectEnvironment(prefix, APK_TABS);
|
|
|
|
// Extract commit ID
|
|
const commitMatch = filename.match(/([a-f0-9]{7,})\.apk$/);
|
|
const commit = commitMatch ? commitMatch[1] : null;
|
|
|
|
return {
|
|
environment,
|
|
commit,
|
|
isValid: commit !== null,
|
|
};
|
|
}
|