-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.js
37 lines (30 loc) · 1015 Bytes
/
generate.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
const github = require('@actions/github');
const {commitDatetime, commitMessage} = require('./git');
const ONE_WEEK = 60 * 60 * 24 * 7;
function generateTTL() {
return Math.floor(Date.now() / 1000) + ONE_WEEK;
}
function normalizeSlices(rawSlices) {
if (typeof rawSlices !== 'string' || rawSlices.trim() === '') {
return [];
}
return rawSlices
.split(",")
.map(x => x.trim())
.filter(x => x !== '');
}
async function generatePayload(rawSlices, customSha = null, customBranch = null) {
const {owner, repo} = github.context.repo;
const branch = (customBranch || github.context.ref).trim().replace('refs/heads/', '');
const commitSha = customSha || github.context.sha;
return {
repository: `${owner}/${repo}`,
commit_sha: commitSha,
commit_branch: branch,
commit_datetime: await commitDatetime(commitSha),
commit_message: await commitMessage(commitSha),
slices: normalizeSlices(rawSlices),
ttl: generateTTL(),
};
}
module.exports = generatePayload;