forked from MBilalShafi/no-response-add-label
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
51 lines (45 loc) · 1.66 KB
/
main.ts
File metadata and controls
51 lines (45 loc) · 1.66 KB
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
// src/main.ts
import * as core from '@actions/core'
import * as github from '@actions/github'
import Config from './config'
import NoResponse from './no-response'
async function run(): Promise<void> {
try {
const eventName = github.context.eventName
const eventType =
'string' === typeof github.context.payload.action ? github.context.payload.action : undefined
core.info(`Running action for: name=${eventName} type=${eventType ?? ''}`)
const config = new Config()
const noResponse = new NoResponse(config)
if ('schedule' === eventName || 'workflow_dispatch' === eventName) {
await noResponse.sweep()
} else if ('issue_comment' === eventName) {
// React to comments on issues
// When it was the author, we must update the issue
if ('created' === eventType) {
await noResponse.handleAuthorCommented()
} else {
core.info(`Unrecognized issue_comment type: ${eventType}`)
}
} else if ('issues' === eventName) {
// React to issue events
// Specifically removing the optional label,
// after the issue was closed and removing the
// author from the assigned users
if ('labeled' === eventType) {
await noResponse.handleLabeled()
} else if ('closed' === eventType) {
await noResponse.handleClosedIssue()
} else {
core.info(`Unrecognized issues type: ${eventType}`)
}
} else {
core.info(`This action was skipped. Unrecognized event: ${eventName}`)
}
} catch (error: any) {
// Graceful failure reporting for the GitHub UI
core.setFailed(error.message)
}
}
// Entry point with top-level await support
await run()