/
main.ts
45 lines (39 loc) · 1.18 KB
/
main.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
import * as core from '@actions/core'
import * as inputHelper from './input-helper'
import * as dockerhubHelper from './dockerhub-helper'
import * as fs from 'fs'
import {inspect} from 'util'
function getErrorMessage(error: unknown) {
if (error instanceof Error) return error.message
return String(error)
}
async function run(): Promise<void> {
try {
const inputs = inputHelper.getInputs()
core.debug(`Inputs: ${inspect(inputs)}`)
inputHelper.validateInputs(inputs)
// Fetch the readme content
const readmeContent = await fs.promises.readFile(inputs.readmeFilepath, {
encoding: 'utf8'
})
// Acquire a token for the Docker Hub API
core.info('Acquiring token')
const token = await dockerhubHelper.getToken(
inputs.username,
inputs.password
)
// Send a PATCH request to update the description of the repository
core.info('Sending PATCH request')
await dockerhubHelper.updateRepositoryDescription(
token,
inputs.repository,
inputs.shortDescription,
readmeContent
)
core.info('Request successful')
} catch (error) {
core.debug(inspect(error))
core.setFailed(getErrorMessage(error))
}
}
run()