generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
semaphore.ts
47 lines (43 loc) · 1.11 KB
/
semaphore.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
const axios = require('axios')
import * as core from '@actions/core'
import _ from 'lodash'
// TEMP: Will be implemented via action inputs
const semaphoreAPI = core.getInput('semaphoreAPI')
const semaphoreAPIKey = core.getInput('semaphoreAPIKey')
export async function getLocks(component: string): Promise<any> {
return axios.get(
semaphoreAPI +
`/api/products/5f7427d977b4b64aeabad92d/components/${component}/locks`,
{
headers: {
Authorization: semaphoreAPIKey
}
}
)
}
export async function setLock(component: string, url: string): Promise<any> {
return axios.post(
semaphoreAPI +
`/api/products/5f7427d977b4b64aeabad92d/components/${component}/locks`,
{
lock: {
created_by: 'github_action',
purpose: url,
expires_at: null
}
},
{
headers: {
Authorization: semaphoreAPIKey
}
}
)
}
export async function getLock(component: string) {
// Manual deployment, check locks
const locks = (await getLocks(component)).data.data
return _.find(locks, {
component: component,
unlocked_by: null
})
}