/
pull_request_stats.ts
47 lines (42 loc) · 1.27 KB
/
pull_request_stats.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
import {AirbyteRecord} from 'faros-airbyte-cdk';
import {DestinationModel, DestinationRecord} from '../converter';
import {GitHubCommon, GitHubConverter} from './common';
export class PullRequestStats extends GitHubConverter {
readonly destinationModels: ReadonlyArray<DestinationModel> = [
'vcs_PullRequest',
];
async convert(
record: AirbyteRecord
): Promise<ReadonlyArray<DestinationRecord>> {
const source = this.streamName.source;
const prStats = record.record.data;
const repository = GitHubCommon.parseRepositoryKey(
prStats.repository,
source
);
if (!repository) return [];
return [
{
model: 'vcs_PullRequest__Update',
record: {
at: Date.now(),
where: {
number: prStats.number,
uid: prStats.number.toString(),
repository,
},
mask: ['commitCount', 'commentCount', 'diffStats'],
patch: {
commitCount: prStats.commits,
commentCount: prStats.comments + prStats.review_comments,
diffStats: {
linesAdded: prStats.additions,
linesDeleted: prStats.deletions,
filesChanged: prStats.changed_files,
},
},
},
},
];
}
}