1
- import * as core from '@actions/core'
2
- import * as github from '@actions/github'
1
+ import { context } from '@actions/github'
3
2
import { Octokit } from '@octokit/core'
4
3
import sodium from 'tweetsodium'
5
4
6
5
export namespace Util {
7
- export function getOctokit ( ) {
8
- const token = core . getInput ( 'GITHUB_TOKEN' , { required : true } )
9
- return github . getOctokit ( token )
10
- }
11
-
12
6
async function createSecret ( octokit : Octokit , value : string ) {
13
- const repo = github . context . repo
7
+ const repo = context . repo
14
8
const res = await octokit . request (
15
9
'GET /repos/:owner/:repo/actions/secrets/public-key' ,
16
10
repo ,
@@ -37,23 +31,26 @@ export namespace Util {
37
31
name : string ,
38
32
value : string ,
39
33
) {
40
- try {
41
- const octokit = new Octokit ( { auth : token } )
42
- const secret = await createSecret ( octokit , value )
43
- core . info ( `created secret: ${ JSON . stringify ( secret , null , 2 ) } ` )
34
+ const octokit = new Octokit ( { auth : token } )
35
+ const secret = await createSecret ( octokit , value )
36
+ await octokit . request (
37
+ 'PUT /repos/:owner/:repo/actions/secrets/:secret_name' ,
38
+ {
39
+ ...context . repo ,
40
+ secret_name : name ,
41
+ data : secret ,
42
+ } ,
43
+ )
44
+ }
44
45
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
- )
53
- } catch ( e ) {
54
- core . error ( e )
55
- core . error ( JSON . stringify ( e , null , 2 ) )
56
- core . setFailed ( e . message )
57
- }
46
+ export async function deleteSecret ( token : string , name : string ) {
47
+ const octokit = new Octokit ( { auth : token } )
48
+ await octokit . request (
49
+ 'DELETE /repos/:owner/:repo/actions/secrets/:secret_name' ,
50
+ {
51
+ ...context . repo ,
52
+ secret_name : name ,
53
+ } ,
54
+ )
58
55
}
59
56
}
0 commit comments