File tree 1 file changed +31
-1
lines changed
1 file changed +31
-1
lines changed Original file line number Diff line number Diff line change 1
- import { ConfigurationError } from "./util" ;
1
+ import { ConfigurationError , getRequiredEnvParam } from "./util" ;
2
2
3
3
// A repository name with owner, parsed into its two parts
4
4
export interface RepositoryNwo {
5
5
owner : string ;
6
6
repo : string ;
7
7
}
8
8
9
+ /**
10
+ * Get the repository name with owner from the environment variable
11
+ * `GITHUB_REPOSITORY`.
12
+ *
13
+ * @returns The repository name with owner.
14
+ */
15
+ export function getRepositoryNwo ( ) : RepositoryNwo {
16
+ return getRepositoryNwoFromEnv ( "GITHUB_REPOSITORY" ) ;
17
+ }
18
+
19
+ /**
20
+ * Get the repository name with owner from the first environment variable that
21
+ * is set and non-empty.
22
+ *
23
+ * @param envVarNames The names of the environment variables to check.
24
+ * @returns The repository name with owner.
25
+ * @throws ConfigurationError if none of the environment variables are set.
26
+ */
27
+ export function getRepositoryNwoFromEnv (
28
+ ...envVarNames : string [ ]
29
+ ) : RepositoryNwo {
30
+ const envVarName = envVarNames . find ( ( name ) => process . env [ name ] ) ;
31
+ if ( ! envVarName ) {
32
+ throw new ConfigurationError (
33
+ `None of the env vars ${ envVarNames . join ( ", " ) } are set` ,
34
+ ) ;
35
+ }
36
+ return parseRepositoryNwo ( getRequiredEnvParam ( envVarName ) ) ;
37
+ }
38
+
9
39
export function parseRepositoryNwo ( input : string ) : RepositoryNwo {
10
40
const parts = input . split ( "/" ) ;
11
41
if ( parts . length !== 2 ) {
You can’t perform that action at this time.
0 commit comments