generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 2
/
input.ts
52 lines (44 loc) · 1.15 KB
/
input.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
52
import {getInput} from '@actions/core'
export function getOauth2ClientOrError(): Oauth2Client {
return {
secret: getInputOrError('clientSecret'),
id: getInputOrError('clientId'),
redirectUri: getInputOrError('redirectUri')
}
}
export function getOauth2CredentialOrError(): Oauth2Credential {
const credential = getInputOrError('credential_json')
return JSON.parse(credential)
}
export function getQueryString(): string {
return getInputOrError('q')
}
export function getPath(): string {
return getInputOrDefault('path', process.cwd())
}
interface Oauth2Client {
secret: string
id: string
redirectUri: string
}
interface Oauth2Credential {
access_token: string
refresh_token: string
scope: string
token_type: string
expiry_date: number
}
function getInputOrError(name: string): string {
const input = getInput(name, {required: true})
if (!input || input.length === 0) {
throw Error(`${name} must be provided`)
}
return input
}
function getInputOrDefault(name: string, defaultValue: string): string {
const input = getInput(name)
if (!input || input.length === 0) {
return defaultValue
}
return input
}