File tree Expand file tree Collapse file tree 1 file changed +31
-1
lines changed
Expand file tree Collapse file tree 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" ;
22
33// A repository name with owner, parsed into its two parts
44export interface RepositoryNwo {
55 owner : string ;
66 repo : string ;
77}
88
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+
939export function parseRepositoryNwo ( input : string ) : RepositoryNwo {
1040 const parts = input . split ( "/" ) ;
1141 if ( parts . length !== 2 ) {
You can’t perform that action at this time.
0 commit comments