|
1 |
| -import * as fs from "fs"; |
2 |
| -import path from "path"; |
3 |
| - |
4 | 1 | export type projectInfo = {
|
5 | 2 | to: string; // email to send patches to
|
6 | 3 | branch: string; // upstream branch a PR must be based on
|
@@ -73,76 +70,3 @@ export interface IConfig {
|
73 | 70 | user: IUserConfig;
|
74 | 71 | syncUpstreamBranches: ISyncUpstreamBranchesConfig[]; // branches to sync from upstream to our repo
|
75 | 72 | }
|
76 |
| - |
77 |
| -let config: IConfig; // singleton |
78 |
| - |
79 |
| -/** |
80 |
| - * Query to get the current configuration. |
81 |
| - * |
82 |
| - * @returns IConfig interface |
83 |
| - */ |
84 |
| -export function getConfig(): IConfig { |
85 |
| - if (config === undefined) { |
86 |
| - throw new Error("project-config not set"); |
87 |
| - } |
88 |
| - |
89 |
| - return config; |
90 |
| -} |
91 |
| - |
92 |
| -export async function getExternalConfig(file: string): Promise<IConfig> { |
93 |
| - const filePath = path.resolve(file); |
94 |
| - const newConfig = await loadConfig(filePath); |
95 |
| - |
96 |
| - if (!Object.prototype.hasOwnProperty.call(newConfig, "project")) { |
97 |
| - throw new Error(`User configurations must have a 'project:'. Not found in ${filePath}`); |
98 |
| - } |
99 |
| - |
100 |
| - if (!newConfig.repo.owner.match(/^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$/i)) { |
101 |
| - throw new Error(`Invalid 'owner' ${newConfig.repo.owner} in ${filePath}`); |
102 |
| - } |
103 |
| - |
104 |
| - if (!newConfig.repo.upstreamOwner.match(/^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$/i)) { |
105 |
| - throw new Error(`Invalid 'baseOwner' ${newConfig.repo.upstreamOwner} in ${filePath}`); |
106 |
| - } |
107 |
| - |
108 |
| - return newConfig; |
109 |
| -} |
110 |
| - |
111 |
| -type importedConfig = { default: IConfig }; |
112 |
| - |
113 |
| -/** |
114 |
| - * Load a config. The config may be a javascript file (plain or generated |
115 |
| - * from typescript) or a json file (with a .json extension). |
116 |
| - * |
117 |
| - * @param file fully qualified filename and path |
118 |
| - * @returns IConfig interface |
119 |
| - */ |
120 |
| -export async function loadConfig(file: string): Promise<IConfig> { |
121 |
| - let loadedConfig: IConfig; |
122 |
| - |
123 |
| - if (path.extname(file) === ".js") { |
124 |
| - const { default: newConfig } = (await import(file)) as importedConfig; |
125 |
| - loadedConfig = newConfig; |
126 |
| - } else { |
127 |
| - // eslint-disable-next-line security/detect-non-literal-fs-filename |
128 |
| - const fileText = fs.readFileSync(file, { encoding: "utf-8" }); |
129 |
| - loadedConfig = JSON.parse(fileText) as IConfig; |
130 |
| - } |
131 |
| - |
132 |
| - if (loadedConfig === undefined) { |
133 |
| - throw new Error("project-config not set"); |
134 |
| - } |
135 |
| - |
136 |
| - return loadedConfig; |
137 |
| -} |
138 |
| - |
139 |
| -/** |
140 |
| - * Set/update the configuration. |
141 |
| - * |
142 |
| - * @param newConfig configuration to be set |
143 |
| - * @returns current IConfig interface |
144 |
| - */ |
145 |
| -export function setConfig(newConfig: IConfig): IConfig { |
146 |
| - config = newConfig; |
147 |
| - return config; |
148 |
| -} |
0 commit comments