-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
43 lines (38 loc) · 1 KB
/
main.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
40
41
42
43
const core = require('@actions/core');
const { Octokit } = require('@octokit/rest');
const repository = core.getInput('repository');
const token = core.getInput('token');
const branch = core.getInput('branch');
var owner = core.getInput('owner');
var repo = core.getInput('repo');
const octokit = (() => {
if (token) {
return new Octokit({ auth: token });
} else {
return new Octokit();
}
})();
async function run() {
try {
if (repository) {
[owner, repo] = repository.split('/');
}
var commits = await octokit.repos.listCommits({
owner: owner,
repo: repo,
sha: branch,
});
commits = commits.data;
if (commits.length) {
console.log(commits);
core.setOutput('shorthash', commits[0].sha.slice(0, 7));
core.setOutput('hash', String(commits[0].sha));
core.setOutput('description', String(commits[0].commit.message));
} else {
core.setFailed('Error');
}
} catch (error) {
core.setFailed(error.message);
}
}
run();