-
Notifications
You must be signed in to change notification settings - Fork 4k
/
autoformat.js
39 lines (36 loc) · 1.05 KB
/
autoformat.js
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
const createCommitStatus = async (context, github, sha, state) => {
const { workflow, runId } = context;
const { owner, repo } = context.repo;
const target_url = `https://github.com/${owner}/${repo}/actions/runs/${runId}`;
await github.repos.createCommitStatus({
owner,
repo,
sha,
state,
target_url,
description: sha,
context: workflow,
});
};
const createStatus = async (context, github) => {
const { owner, repo } = context.repo;
const pull_number = context.issue.number;
const pr = await github.pulls.get({ owner, repo, pull_number });
const { sha, ref } = pr.data.head;
await createCommitStatus(context, github, sha, 'pending');
return {
repository: `${owner}/${repo}`,
pull_number,
sha,
ref,
};
};
const updateStatus = async (context, github, sha, needs) => {
const failed = Object.values(needs).some(({ result }) => result === 'failure');
const state = failed ? 'failure' : 'success';
await createCommitStatus(context, github, sha, state);
};
module.exports = {
createStatus,
updateStatus,
};