-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
source.ts
82 lines (76 loc) · 2.54 KB
/
source.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import URL from 'node:url';
import { GlobalConfig } from '../../../../../../config/global';
import { logger } from '../../../../../../logger';
import * as hostRules from '../../../../../../util/host-rules';
import type { BranchUpgradeConfig } from '../../../../../types';
import { ChangeLogSource } from '../source';
import type { ChangeLogError } from '../types';
export class GitHubChangeLogSource extends ChangeLogSource {
constructor() {
super('github', 'github-tags');
}
getAPIBaseUrl(config: BranchUpgradeConfig): string {
const baseUrl = this.getBaseUrl(config);
return baseUrl.startsWith('https://github.com/')
? 'https://api.github.com/'
: baseUrl + 'api/v3/';
}
getCompareURL(
baseUrl: string,
repository: string,
prevHead: string,
nextHead: string,
): string {
return `${baseUrl}${repository}/compare/${prevHead}...${nextHead}`;
}
protected override shouldSkipPackage(config: BranchUpgradeConfig): boolean {
if (
config.sourceUrl === 'https://github.com/DefinitelyTyped/DefinitelyTyped'
) {
logger.trace('No release notes for @types');
return true;
}
return false;
}
protected override hasValidToken(config: BranchUpgradeConfig): {
isValid: boolean;
error?: ChangeLogError;
} {
const sourceUrl = config.sourceUrl!;
const parsedUrl = URL.parse(sourceUrl);
const host = parsedUrl.host;
const manager = config.manager;
const packageName = config.packageName;
const url = sourceUrl.startsWith('https://github.com/')
? 'https://api.github.com/'
: sourceUrl;
const { token } = hostRules.find({
hostType: 'github',
url,
readOnly: true,
});
// istanbul ignore if
if (host && !token) {
if (host.endsWith('.git.luolix.top') || host === 'github.com') {
if (!GlobalConfig.get('githubTokenWarn')) {
logger.debug(
{ manager, packageName, sourceUrl },
'GitHub token warning has been suppressed. Skipping release notes retrieval',
);
return { isValid: false };
}
logger.warn(
{ manager, packageName, sourceUrl },
'No github.com token has been configured. Skipping release notes retrieval',
);
return { isValid: false, error: 'MissingGithubToken' };
}
logger.debug(
{ manager, packageName, sourceUrl },
'Repository URL does not match any known github hosts - skipping changelog retrieval',
);
return { isValid: false };
}
return { isValid: true };
}
}