-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
44 lines (36 loc) · 1.27 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 * as core from '@actions/core';
import { context, getOctokit } from '@actions/github/lib/github';
import PraceAction from './Prace';
import { PullRequestData } from './PullRequestData';
import { GithubApi } from './Github/GithubApi';
import CoreReporter from './Github/CoreReporter';
/**
* Execute the github action
*/
async function action() {
const githubToken = process.env.GITHUB_TOKEN!;
const octokit = getOctokit(githubToken);
core.info('Starting Prace!');
// Have to cast to unknown to then cast to the correct type
const pullRequest: PullRequestData = context.payload
.pull_request as unknown as PullRequestData;
if (!pullRequest) {
throw new Error(
"Payload doesn't contain `pull_request`. " +
'Make sure you followed the instructions to configure your repository ' +
'(https://github.com/innerspacetrainings/Prace.js/blob/master/README.md).'
);
}
const githubApi = new GithubApi(octokit, new CoreReporter());
const prace = new PraceAction(githubApi, pullRequest);
const result = await prace.execute();
core.info(`Finished evaluating and found${result ? ' no ' : ' '}problems`);
}
action().catch((error) => {
if (process.env.NODE_ENV === 'test') {
core.setFailed(error);
throw error;
}
core.error(error);
core.setFailed(error.message);
});