Skip to content

Commit

Permalink
feat: configuration is fetched org wide
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed May 28, 2024
1 parent 632e738 commit 91eb0be
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
Binary file modified bun.lockb
100644 → 100755
Binary file not shown.
20 changes: 17 additions & 3 deletions src/github/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { configSchema, PluginConfiguration } from "../types/plugin-configuration
import { eventNames } from "../types/webhook-events";

const UBIQUIBOT_CONFIG_FULL_PATH = ".github/.ubiquibot-config.yml";
const UBIQUIBOT_CONFIG_ORG_REPO = "ubiquibot-config";

export async function getConfig(context: GitHubContext): Promise<PluginConfiguration> {
const payload = context.payload;
Expand All @@ -16,18 +17,31 @@ export async function getConfig(context: GitHubContext): Promise<PluginConfigura
return defaultConfiguration;
}

const _repoConfig = parseYaml(
let _innerConfig: PluginConfiguration;
// First, try to get the config in the target repo
_innerConfig = parseYaml(
await download({
context,
repository: payload.repository.name,
owner: payload.repository.owner.login,
})
);
if (!_repoConfig) return defaultConfiguration;
// If no config is found, check if there is an Org wide config
if (!_innerConfig) {
_innerConfig = parseYaml(
await download({
context,
repository: UBIQUIBOT_CONFIG_ORG_REPO,
owner: payload.repository.owner.login,
})
);
}
// Otherwise, use defaults
if (!_innerConfig) return defaultConfiguration;

let config: PluginConfiguration;
try {
config = Value.Decode(configSchema, Value.Default(configSchema, _repoConfig));
config = Value.Decode(configSchema, Value.Default(configSchema, _innerConfig));
} catch (error) {
console.error("Error decoding config, will use default.", error);
return defaultConfiguration;
Expand Down
8 changes: 6 additions & 2 deletions wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ compatibility_date = "2023-12-06"

[env]
[env.dev]

[[env.dev.kv_namespaces]]
binding = "PLUGIN_CHAIN_STATE"
id = "4f7aadc56bef41a7ae2cc8c0582320b3"
[env.production]

[[env.production.kv_namespaces]]
binding = "PLUGIN_CHAIN_STATE"
id = "TO_BE_DEFINED"
[[kv_namespaces]]
binding = "PLUGIN_CHAIN_STATE"
id = "TO_BE_DEFINED"
Expand Down

0 comments on commit 91eb0be

Please sign in to comment.