Skip to content

Commit fa33bd1

Browse files
authored
Apply lint rules (#10)
1 parent 6cd1f34 commit fa33bd1

File tree

4 files changed

+62
-39
lines changed

4 files changed

+62
-39
lines changed

dist/main/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"eslint": "^7.5.0",
2929
"eslint-plugin-github": "^4.1.1",
3030
"eslint-plugin-jest": "^23.18.0",
31+
"eslint-plugin-prettier": "^3.1.4",
3132
"jest": "^24.9.0",
3233
"jest-circus": "^26.1.0",
3334
"js-yaml": "^3.14.0",

src/main.ts

Lines changed: 59 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
import * as core from "@actions/core";
2-
import * as github from "@actions/github";
3-
import * as axios from "axios"
1+
import * as core from '@actions/core'
2+
import * as github from '@actions/github'
3+
import * as axios from 'axios'
44

5-
function sleep(ms: number) {
6-
return new Promise((resolve) => {
7-
setTimeout(resolve, ms);
8-
});
9-
}
5+
async function sleep(ms: number): Promise<unknown> {
6+
return new Promise(resolve => {
7+
setTimeout(resolve, ms)
8+
})
9+
}
1010

11-
async function run() {
11+
async function run(): Promise<unknown> {
1212
try {
13-
const token = core.getInput("github-token");
13+
const token = core.getInput('github-token')
1414
if (!token) {
1515
core.setFailed("'github-token' input can't be empty")
1616
return
1717
}
1818

19-
const webhookUri = core.getInput("webhook-uri")
19+
const webhookUri = core.getInput('webhook-uri')
2020
if (!webhookUri) {
2121
core.setFailed("'webhook-uri' input can't be empty")
2222
return
2323
}
24-
const ctx = github.context;
25-
const o = github.getOctokit(token);
24+
const ctx = github.context
25+
const o = github.getOctokit(token)
2626

2727
core.debug(JSON.stringify(ctx))
2828

@@ -31,16 +31,24 @@ async function run() {
3131
const jobList = await o.actions.listJobsForWorkflowRun({
3232
repo: ctx.repo.repo,
3333
owner: ctx.repo.owner,
34-
run_id: ctx.runId,
35-
});
34+
run_id: ctx.runId
35+
})
3636

3737
const jobs = jobList.data.jobs
3838
core.debug(JSON.stringify(jobs))
39-
40-
const job = jobs.find(job => job.name === ctx.job);
4139

42-
const stoppedStep = job?.steps.find(s => s.conclusion === "failure" || s.conclusion === "timed_out" || s.conclusion === "cancelled" || s.conclusion === "action_required")
43-
const lastStep = stoppedStep ? stoppedStep : job?.steps.reverse().find(s => s.status === "completed")
40+
const job = jobs.find(j => j.name === ctx.job)
41+
42+
const stoppedStep = job?.steps.find(
43+
s =>
44+
s.conclusion === 'failure' ||
45+
s.conclusion === 'timed_out' ||
46+
s.conclusion === 'cancelled' ||
47+
s.conclusion === 'action_required'
48+
)
49+
const lastStep = stoppedStep
50+
? stoppedStep
51+
: job?.steps.reverse().find(s => s.status === 'completed')
4452

4553
const wr = await o.actions.getWorkflowRun({
4654
owner: ctx.repo.owner,
@@ -53,42 +61,56 @@ async function run() {
5361
const repository_url = ctx.payload.repository?.html_url
5462
const commit_author = ctx.actor
5563

56-
var themeColor = lastStep?.conclusion === "success" ? "90C978": lastStep?.conclusion === "cancelled" ? "FFF175" : "C23B23"
57-
const conclusion = lastStep?.conclusion === "success" ? "SUCCEEDED" : lastStep?.conclusion === "cancelled" ? "CANCELLED" : "FAILED"
58-
64+
const themeColor =
65+
lastStep?.conclusion === 'success'
66+
? '90C978'
67+
: lastStep?.conclusion === 'cancelled'
68+
? 'FFF175'
69+
: 'C23B23'
70+
const conclusion =
71+
lastStep?.conclusion === 'success'
72+
? 'SUCCEEDED'
73+
: lastStep?.conclusion === 'cancelled'
74+
? 'CANCELLED'
75+
: 'FAILED'
76+
5977
const webhookBody = {
60-
"@type": "MessageCard",
61-
"@context": "http://schema.org/extensions",
62-
"themeColor": `${themeColor}`,
63-
"summary": `${commit_author} commited new changes`,
64-
"sections": [
78+
'@type': 'MessageCard',
79+
'@context': 'http://schema.org/extensions',
80+
themeColor: `${themeColor}`,
81+
summary: `${commit_author} commited new changes`,
82+
sections: [
6583
{
66-
"activityTitle": `Workflow '${ctx.workflow}' #${ctx.runNumber} ${conclusion}`,
67-
"activitySubtitle": `on [${ctx.payload.repository?.full_name}](${repository_url})`,
68-
"facts": [
84+
activityTitle: `Workflow '${ctx.workflow}' #${ctx.runNumber} ${conclusion}`,
85+
activitySubtitle: `on [${ctx.payload.repository?.full_name}](${repository_url})`,
86+
facts: [
6987
{
70-
name: "Commit",
88+
name: 'Commit',
7189
value: `[${wr.data.head_commit.message}](${wr.data.repository.html_url}/commit/${wr.data.head_sha}) by [${ctx.payload.sender?.login}](${ctx.payload.sender?.html_url})`
7290
},
7391
{
74-
name: ctx.eventName === "pull_request" ? "Pull request" : "Branch",
75-
value: ctx.eventName === "pull_request" ? `[${ctx.payload.pull_request?.html_url}](${ctx.payload.pull_request?.html_url})` : `[${ctx.payload.repository?.html_url}/tree/${ctx.ref}](${ctx.payload.repository?.html_url}/tree/${ctx.ref})`
92+
name:
93+
ctx.eventName === 'pull_request' ? 'Pull request' : 'Branch',
94+
value:
95+
ctx.eventName === 'pull_request'
96+
? `[${ctx.payload.pull_request?.html_url}](${ctx.payload.pull_request?.html_url})`
97+
: `[${ctx.payload.repository?.html_url}/tree/${ctx.ref}](${ctx.payload.repository?.html_url}/tree/${ctx.ref})`
7698
},
7799
{
78-
name: "Workflow run details",
100+
name: 'Workflow run details',
79101
value: `[${wr.data.html_url}](${wr.data.html_url})`
80102
}
81103
],
82-
"markdown": true
104+
markdown: true
83105
}
84106
]
85107
}
86108
const response = await axios.default.post(webhookUri, webhookBody)
87109
core.debug(JSON.stringify(response.data))
88110
// TODO: check response status, if not succesful, mark workflow as failed
89111
} catch (error) {
90-
core.setFailed(error.message);
112+
core.setFailed(error.message)
91113
}
92114
}
93115

94-
run();
116+
run()

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1865,7 +1865,7 @@ eslint-plugin-jest@^23.18.0:
18651865
dependencies:
18661866
"@typescript-eslint/experimental-utils" "^2.5.0"
18671867

1868-
eslint-plugin-prettier@>=3.1.2:
1868+
eslint-plugin-prettier@>=3.1.2, eslint-plugin-prettier@^3.1.4:
18691869
version "3.1.4"
18701870
resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-3.1.4.tgz#168ab43154e2ea57db992a2cd097c828171f75c2"
18711871
integrity sha512-jZDa8z76klRqo+TdGDTFJSavwbnWK2ZpqGKNZ+VvweMW516pDUMmQ2koXvxEE4JhzNvTv+radye/bWGBmA6jmg==

0 commit comments

Comments
 (0)