-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (46 loc) · 1.54 KB
/
index.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
44
45
46
47
48
49
50
51
52
53
54
55
const core = require('@actions/core');
const github = require('@actions/github');
async function run() {
try {
const token = core.getInput('GITHUB_TOKEN');
const title = core.getInput('title');
const label = core.getInput('label');
const body = core.getInput('body');
const octokit = github.getOctokit(token);
const { context } = github;
const repo = context.repo.repo;
const owner = context.repo.owner;
const runId = context.runId;
const failedActionRun = `https://github.com/${owner}/${repo}/actions/runs/${runId}`;
const { data: issues } = await octokit.issues.listForRepo({
owner,
repo,
state: 'open',
labels: label,
orderBy: 'created',
direction: 'desc',
});
const issueNumber = issues.length > 0 ? issues[0].number : null;
const bodyWithDetails = `${body} [Action Run link](${failedActionRun})`;
if (issueNumber) {
await octokit.issues.createComment({
owner,
repo,
issue_number: issueNumber,
body: bodyWithDetails,
});
} else {
await octokit.issues.create({
owner,
repo,
title,
body: bodyWithDetails,
labels: [label],
});
}
core.setOutput('issue-number', issueNumber);
} catch (error) {
core.setFailed(error.message);
}
}
run();