mock debug and refactor mapping function

This commit is contained in:
Moritz Schmitz von Hülst 2020-11-17 13:22:00 +01:00
parent 243e30c098
commit a4b921efd9
2 changed files with 9 additions and 4 deletions

View File

@ -60,12 +60,16 @@ export function getLatestPrereleaseTag(
export function mapCustomReleaseRules(customReleaseTypes: string) {
return customReleaseTypes
.split(',')
.map((part) => {
.filter((part) => {
const custom = part.split(':');
if (custom.length !== 2) {
core.warning(`${part} is not a valid custom release definition.`);
return null;
return false;
}
return true;
})
.map((part) => {
const custom = part.split(':');
const [keyword, release] = custom;
return {
type: keyword,
@ -73,10 +77,10 @@ export function mapCustomReleaseRules(customReleaseTypes: string) {
};
})
.filter((customRelease) => {
if (DEFAULT_RELEASE_TYPES.includes(customRelease?.release)) {
if (DEFAULT_RELEASE_TYPES.includes(customRelease.release)) {
return true;
}
core.warning(`${customRelease} is not a valid release type.`);
core.warning(`${customRelease.release} is not a valid release type.`);
return false;
});
}

View File

@ -4,6 +4,7 @@ import * as core from '@actions/core';
import * as github from '../src/github';
jest.spyOn(core, 'debug').mockImplementation(() => {});
jest.spyOn(core, 'warning').mockImplementation(() => {});
describe('utils', () => {
it('extracts branch from ref', () => {