-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
97 lines (85 loc) · 3.21 KB
/
index.ts
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import * as core from '@actions/core'
import { dedent } from 'ts-dedent'
import { getSlackClient } from './clients'
import { parseInputs } from './inputs'
import {
createDirectMessageToActor,
createThreadMainMessageSurface
} from './messages'
export async function main(): Promise<void> {
try {
const inputs = parseInputs()
const slackClient = getSlackClient()
if (inputs.phase === 'start') {
const messageResponse = await slackClient.chat.postMessage(
await createThreadMainMessageSurface(inputs)
)
core.setOutput('thread_ts', messageResponse.ts)
core.info(
dedent`Start message sent Successfully: ${JSON.stringify(messageResponse, null, 2)}`
)
if (messageResponse.ts) {
const permaLink = await slackClient.chat.getPermalink({
channel: inputs.channel_id,
message_ts: messageResponse.ts
})
const directMessageResponse = await slackClient.chat.postMessage(
createDirectMessageToActor(permaLink.permalink)
)
core.info(
dedent`Direct message sent Successfully: ${JSON.stringify(directMessageResponse, null, 2)}`
)
}
} else if (inputs.phase === 'finish') {
const updatedMessageResponse = await slackClient.chat.update(
await createThreadMainMessageSurface(inputs)
)
const replyMessageResponse = await slackClient.chat.postMessage({
channel: inputs.channel_id,
thread_ts: inputs.thread_ts,
text: dedent`배포 완료되었습니다.`
})
core.info(
dedent`
Finish message sent Successfully: ${JSON.stringify(replyMessageResponse, null, 2)}
Message updated Successfully: ${JSON.stringify(updatedMessageResponse, null, 2)}
`
)
} else if (inputs.phase === 'failure') {
const updatedMessageResponse = await slackClient.chat.update(
await createThreadMainMessageSurface(inputs)
)
const replyMessageResponse = await slackClient.chat.postMessage({
channel: inputs.channel_id,
thread_ts: inputs.thread_ts,
text: dedent`배포가 실패했습니다. Run ID를 확인해 주세요.`
})
core.info(
dedent`
Failure message sent Successfully: ${JSON.stringify(replyMessageResponse, null, 2)}
Message updated Successfully: ${JSON.stringify(updatedMessageResponse, null, 2)}
`
)
} else if (inputs.phase === 'cancelled') {
const updatedMessageResponse = await slackClient.chat.update(
await createThreadMainMessageSurface(inputs)
)
const replyMessageResponse = await slackClient.chat.postMessage({
channel: inputs.channel_id,
thread_ts: inputs.thread_ts,
text: dedent`배포가 취소되었습니다. Run ID를 확인해 주세요.`
})
core.info(
dedent`
Cancellation message sent Successfully: ${JSON.stringify(replyMessageResponse, null, 2)}
Message updated Successfully: ${JSON.stringify(updatedMessageResponse, null, 2)}
`
)
}
} catch (error) {
// Fail the workflow run if an error occurs
console.log(error)
if (error instanceof Error) core.setFailed(error.message)
}
}
main()