-
-
Notifications
You must be signed in to change notification settings - Fork 52
/
dockerhub-helper.ts
51 lines (49 loc) · 1.2 KB
/
dockerhub-helper.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
import * as core from '@actions/core'
import * as fetch from 'node-fetch'
export async function getToken(
username: string,
password: string
): Promise<string> {
const body = {
username: username,
password: password
}
const response = await fetch('https://hub.docker.com/v2/users/login', {
method: 'post',
body: JSON.stringify(body),
headers: {'Content-Type': 'application/json'}
})
if (!response.ok) {
throw new Error(
`Unexpected response: ${response.status} ${response.statusText}`
)
}
const json = await response.json()
core.setSecret(json['token'])
return json['token']
}
export async function updateRepositoryDescription(
token: string,
repository: string,
description: string,
fullDescription: string
): Promise<void> {
const body = {
full_description: fullDescription
}
if (description) {
body['description'] = description
}
await fetch(`https://hub.docker.com/v2/repositories/${repository}`, {
method: 'patch',
body: JSON.stringify(body),
headers: {
'Content-Type': 'application/json',
Authorization: `JWT ${token}`
}
}).then(res => {
if (!res.ok) {
throw new Error(res.statusText)
}
})
}