Skip to content

Commit 655ebe5

Browse files
committed
fix: 🐛 set secret
1 parent e6cf021 commit 655ebe5

File tree

1 file changed

+12
-31
lines changed

1 file changed

+12
-31
lines changed

src/util.ts

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,15 @@ export namespace Util {
99
return github.getOctokit(token)
1010
}
1111

12-
export async function createSecret(
13-
octokit: ReturnType<typeof getOctokit>,
14-
value: string,
15-
) {
12+
async function createSecret(octokit: Octokit, value: string) {
1613
const repo = github.context.repo
17-
18-
core.info(`Repo: ${JSON.stringify(repo, null, 2)}`)
19-
20-
const oct = new Octokit({ auth: value })
21-
22-
// const oct = getOctokit()
23-
// const rr = await oct.actions.getRepoPublicKey({
24-
// ...github.context.repo,
25-
// })
26-
27-
// core.info(`RR: ${JSON.stringify(rr, null, 2)}`)
28-
29-
// Get publick key
30-
const ret = await oct.request(
14+
const res = await octokit.request(
3115
'GET /repos/:owner/:repo/actions/secrets/public-key',
3216
repo,
3317
)
3418

35-
core.info(`Ret: ${JSON.stringify(ret, null, 2)}`)
36-
37-
const res = await octokit.actions.getRepoPublicKey({
38-
...github.context.repo,
39-
})
4019
const key = res.data.key
4120

42-
core.info(`Key: ${JSON.stringify(res.data, null, 2)}`)
43-
4421
// Convert the message and key to Uint8Array's
4522
const messageBytes = Buffer.from(value)
4623
const keyBytes = Buffer.from(key, 'base64')
@@ -56,19 +33,23 @@ export namespace Util {
5633
}
5734

5835
export async function createOrUpdateRepoSecret(
59-
octokit: ReturnType<typeof github.getOctokit>,
36+
token: string,
6037
name: string,
6138
value: string,
6239
) {
6340
try {
41+
const octokit = new Octokit({ auth: token })
6442
const secret = await createSecret(octokit, value)
6543
core.info(`created secret: ${JSON.stringify(secret, null, 2)}`)
6644

67-
await octokit.actions.createOrUpdateRepoSecret({
68-
...github.context.repo,
69-
...secret,
70-
secret_name: name,
71-
})
45+
await octokit.request(
46+
'PUT /repos/:owner/:repo/actions/secrets/:secret_name',
47+
{
48+
...github.context.repo,
49+
secret_name: name,
50+
data: secret,
51+
},
52+
)
7253
} catch (e) {
7354
core.error(e)
7455
core.error(JSON.stringify(e, null, 2))

0 commit comments

Comments
 (0)