-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathindex.ts
44 lines (40 loc) · 1.47 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { logger } from '../../../../../logger';
import * as allVersioning from '../../../../../modules/versioning';
import type { BranchUpgradeConfig } from '../../../../types';
import { getInRangeReleases } from './releases';
import * as sourceGithub from './source-github';
import * as sourceGitlab from './source-gitlab';
import type { ChangeLogResult } from './types';
export * from './types';
export async function getChangeLogJSON(
args: BranchUpgradeConfig
): Promise<ChangeLogResult | null> {
const { sourceUrl, versioning, currentVersion, newVersion } = args;
try {
if (!(sourceUrl && currentVersion && newVersion)) {
return null;
}
const version = allVersioning.get(versioning);
if (version.equals(currentVersion, newVersion)) {
return null;
}
logger.debug(
`Fetching changelog: ${sourceUrl} (${currentVersion} -> ${newVersion})`
);
const releases = args.releases || (await getInRangeReleases(args));
let res: ChangeLogResult | null = null;
if (
args.sourceUrl?.includes('gitlab') ||
(args.platform === 'gitlab' &&
new URL(args.sourceUrl).hostname === new URL(args.endpoint).hostname)
) {
res = await sourceGitlab.getChangeLogJSON({ ...args, releases });
} else {
res = await sourceGithub.getChangeLogJSON({ ...args, releases });
}
return res;
} catch (err) /* istanbul ignore next */ {
logger.error({ config: args, err }, 'getChangeLogJSON error');
return null;
}
}