feat: rewrite APK parser to use version as delimiter
- 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>
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
export type ApkEnvironment = 'dev' | 'sandbox' | 'product' | 'other';
|
||||
import { APK_TABS } from './constants';
|
||||
|
||||
export type ApkEnvironment = 'product' | 'dev' | 'sandbox' | 'other';
|
||||
|
||||
export interface ParsedApkMetadata {
|
||||
environment: ApkEnvironment;
|
||||
@@ -6,37 +8,55 @@ export interface ParsedApkMetadata {
|
||||
isValid: boolean;
|
||||
}
|
||||
|
||||
// Environment mapping based on filename patterns
|
||||
const ENVIRONMENT_MAP: Record<string, ApkEnvironment> = {
|
||||
'timeshift': 'dev',
|
||||
'lan': 'dev',
|
||||
'dev': 'dev',
|
||||
'sandbox': 'sandbox',
|
||||
};
|
||||
export function getApkTabs(): string[] {
|
||||
return APK_TABS;
|
||||
}
|
||||
|
||||
export function detectEnvironment(filename: string): ApkEnvironment {
|
||||
// Pattern: ft_[environment]_version_commit.apk
|
||||
// Extract the environment segment (alphabetic only) between first and second underscores
|
||||
const match = filename.match(/^ft_([a-z]+)_/i);
|
||||
export function detectEnvironment(prefix: string, configuredTabs: string[]): ApkEnvironment {
|
||||
// Empty prefix → other
|
||||
if (!prefix) {
|
||||
return 'other';
|
||||
}
|
||||
|
||||
if (!match) {
|
||||
// No environment suffix, default to product
|
||||
// No underscore means product (e.g., "ft")
|
||||
if (!prefix.includes('_')) {
|
||||
return 'product';
|
||||
}
|
||||
|
||||
const env = match[1].toLowerCase();
|
||||
return ENVIRONMENT_MAP[env] || 'other';
|
||||
// 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): ParsedApkMetadata {
|
||||
const environment = detectEnvironment(filename);
|
||||
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;
|
||||
const isValid = commit !== null;
|
||||
|
||||
return {
|
||||
environment,
|
||||
commit,
|
||||
isValid,
|
||||
isValid: commit !== null,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user