Skip to content

Commit

Permalink
fix: merge before validation/defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
whilefoo committed Nov 14, 2023
1 parent 232cecd commit 4cc7866
Showing 1 changed file with 2 additions and 42 deletions.
44 changes: 2 additions & 42 deletions src/utils/generate-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,62 +13,22 @@ const UBIQUIBOT_CONFIG_FULL_PATH = ".github/ubiquibot-config.yml";
export async function generateConfiguration(context: ProbotContext): Promise<BotConfig> {
const payload = context.payload as Payload;

const organizationConfiguration = parseYaml(
const orgConfig = parseYaml(
await download({
context,
repository: UBIQUIBOT_CONFIG_REPOSITORY,
owner: payload.organization?.login || payload.repository.owner.login,
})
);

const repositoryConfiguration = parseYaml(
const repoConfig = parseYaml(
await download({
context,
repository: payload.repository.name,
owner: payload.repository.owner.login,
})
);

let orgConfig: BotConfig | undefined;
if (organizationConfiguration) {
const valid = validateBotConfig(organizationConfiguration);
if (!valid) {
let errMsg = getErrorMsg(validateBotConfig.errors as DefinedError[]);
if (errMsg) {
errMsg = `Invalid org configuration! \n${errMsg}`;
if (payload.issue?.number)
await context.octokit.issues.createComment({
owner: payload.repository.owner.login,
repo: payload.repository.name,
issue_number: payload.issue?.number,
body: errMsg,
});
throw new Error(errMsg);
}
}
orgConfig = organizationConfiguration as BotConfig;
}

let repoConfig: BotConfig | undefined;
if (repositoryConfiguration) {
const valid = validateBotConfig(repositoryConfiguration);
if (!valid) {
let errMsg = getErrorMsg(validateBotConfig.errors as DefinedError[]);
if (errMsg) {
errMsg = `Invalid repo configuration! \n${errMsg}`;
if (payload.issue?.number)
await context.octokit.issues.createComment({
owner: payload.repository.owner.login,
repo: payload.repository.name,
issue_number: payload.issue?.number,
body: errMsg,
});
throw new Error(errMsg);
}
}
repoConfig = repositoryConfiguration as BotConfig;
}

const merged = merge(ubiquibotConfigDefault, orgConfig, repoConfig);
const valid = validateBotConfig(merged);
if (!valid) {
Expand Down

0 comments on commit 4cc7866

Please sign in to comment.