Skip to content

Commit

Permalink
Reuse channel/platform serializers
Browse files Browse the repository at this point in the history
  • Loading branch information
atuchin-m committed Nov 20, 2024
1 parent ac905f2 commit ac7aeb4
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 61 deletions.
34 changes: 0 additions & 34 deletions src/core/serializers.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/seed_tools/utils/study_json_utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe('stringifyStudies', () => {
filter: {
start_date: Math.floor(startDate.getTime() / 1000),
channel: ['CANARY', 'BETA', 'STABLE'],
platform: ['PLATFORM_LINUX', 'PLATFORM_MAC'],
platform: ['LINUX', 'MAC'],
},
},
{ ignoreUnknownFields: false },
Expand All @@ -127,7 +127,7 @@ describe('stringifyStudies', () => {
filter: {
start_date: startDate.toISOString(),
channel: ['CANARY', 'BETA', 'STABLE'],
platform: ['PLATFORM_LINUX', 'PLATFORM_MAC'],
platform: ['LINUX', 'MAC'],
},
},
]);
Expand Down
49 changes: 29 additions & 20 deletions src/seed_tools/utils/study_json_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,29 @@ export function stringifyStudies(studies: Study[], options?: Options): string {
);
}

export function replaceChannels(
channels: string[] | undefined,
isChromium: boolean,
): string[] | undefined {
if (isChromium) return channels;

return channels?.map((channel) => {
switch (channel) {
case 'CANARY':
return 'NIGHTLY';
case 'STABLE':
return 'RELEASE';
}
return channel;
});
}

export function replacePlatforms(
platforms: string[] | undefined,
): string[] | undefined {
return platforms?.map((platform) => platform.replace(/^PLATFORM_/, ''));
}

function jsonStudyReplacer(
options: Options | undefined,
key: string,
Expand All @@ -96,26 +119,12 @@ function jsonStudyReplacer(
case 'end_date': {
return new Date(value * 1000).toISOString();
}
case 'channel':
if (options?.isChromium === true) {
return value;
}
return value.map((value: string): string => {
switch (value) {
case 'CANARY':
return 'NIGHTLY';
case 'STABLE':
return 'RELEASE';
}
return value;
});
case 'platform':
if (options?.isChromium === true) {
return value;
}
return value.map((value: string): string => {
return value.replace(/^PLATFORM_/, '');
});
case 'channel': {
return replaceChannels(value, options?.isChromium === true);
}
case 'platform': {
return replacePlatforms(value);
}
default:
return value;
}
Expand Down
25 changes: 20 additions & 5 deletions src/web/app/study_model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@
// You can obtain one at https://mozilla.org/MPL/2.0/.

import { SeedType } from '../../core/base_types';
import { getChannelName, getPlatfromName } from '../../core/serializers';
import {
type ProcessedStudy,
type StudyFilter,
type StudyPriority,
} from '../../core/study_processor';
import * as url_utils from '../../core/url_utils';
import { Study_Filter } from '../../proto/generated/study';
import {
Study_Channel,
Study_Filter,
Study_Platform,
} from '../../proto/generated/study';
import {
replaceChannels,
replacePlatforms,
} from '../../seed_tools/utils/study_json_utils';
import { ExperimentModel } from './experiment_model';

export class StudyModel {
Expand Down Expand Up @@ -55,12 +62,20 @@ export class StudyModel {
}

platforms(): string[] | undefined {
return this.filter()?.platform?.map((p) => getPlatfromName(p));
const string_platforms = this.filter()?.platform?.map(
(p) => Study_Platform[p],
);
return replacePlatforms(string_platforms);
}

channels(): string[] | undefined {
const isBraveSeed = this.seedType !== SeedType.UPSTREAM;
return this.filter()?.channel?.map((c) => getChannelName(c, isBraveSeed));
const string_channels = this.filter()?.channel?.map(
(c) => Study_Channel[c],
);
return replaceChannels(
string_channels,
this.seedType === SeedType.UPSTREAM,
);
}

getConfigUrl(): string {
Expand Down

0 comments on commit ac7aeb4

Please sign in to comment.