forked from ubiquity/ubiquibot
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix config #45
Merged
0x4007
merged 3 commits into
0x4007:feat/contributor-incentives-total-scoring
from
ubiquity-whilefoo:fix-config
Nov 16, 2023
Merged
Fix config #45
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,44 @@ | ||
import { Value } from "@sinclair/typebox/value"; | ||
import { DefinedError } from "ajv"; | ||
import merge from "lodash/merge"; | ||
import mergeWith from "lodash/merge"; | ||
import { Context as ProbotContext } from "probot"; | ||
import YAML from "yaml"; | ||
import Runtime from "../bindings/bot-runtime"; | ||
import { BotConfig, Payload, stringDuration, validateBotConfig } from "../types"; | ||
import ubiquibotConfigDefault from "../ubiquibot-config-default"; | ||
|
||
const UBIQUIBOT_CONFIG_REPOSITORY = "ubiquibot-config"; | ||
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( | ||
Comment on lines
+15
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer that you do not shorten words. The reason why is to reduce cognitive overhead when reading through all of the code. |
||
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); | ||
const merged = mergeWith({}, orgConfig, repoConfig, (objValue: unknown, srcValue: unknown) => { | ||
if (Array.isArray(objValue) && Array.isArray(srcValue)) { | ||
// if it's string array, concat and remove duplicates | ||
if (objValue.every((value) => typeof value === "string")) { | ||
return [...new Set(objValue.concat(srcValue))]; | ||
} | ||
// otherwise just concat | ||
return objValue.concat(srcValue); | ||
} | ||
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) { | ||
let errMsg = getErrorMsg(validateBotConfig.errors as DefinedError[]); | ||
|
@@ -111,28 +80,28 @@ | |
let errorMsg = ""; | ||
try { | ||
config.timers.reviewDelayTolerance = Value.Decode(stringDuration(), config.timers.reviewDelayTolerance); | ||
} catch (err: any) { | ||
if (err.value) { | ||
errorMsg += `Invalid reviewDelayTolerance value: ${err.value}\n`; | ||
} | ||
} | ||
try { | ||
config.timers.taskStaleTimeoutDuration = Value.Decode(stringDuration(), config.timers.taskStaleTimeoutDuration); | ||
} catch (err: any) { | ||
if (err.value) { | ||
errorMsg += `Invalid taskStaleTimeoutDuration value: ${err.value}\n`; | ||
} | ||
} | ||
try { | ||
config.timers.taskFollowUpDuration = Value.Decode(stringDuration(), config.timers.taskFollowUpDuration); | ||
} catch (err: any) { | ||
if (err.value) { | ||
errorMsg += `Invalid taskFollowUpDuration value: ${err.value}\n`; | ||
} | ||
} | ||
try { | ||
config.timers.taskDisqualifyDuration = Value.Decode(stringDuration(), config.timers.taskDisqualifyDuration); | ||
} catch (err: any) { | ||
if (err.value) { | ||
errorMsg += `Invalid taskDisqualifyDuration value: ${err.value}\n`; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8797,7 +8797,7 @@ zod-validation-error@^1.5.0: | |
resolved "https://registry.yarnpkg.com/zod-validation-error/-/zod-validation-error-1.5.0.tgz#2b355007a1c3b7fb04fa476bfad4e7b3fd5491e3" | ||
integrity sha512-/7eFkAI4qV0tcxMBB/3+d2c1P6jzzZYdYSlBuAklzMuCrJu5bzJfHS0yVAS87dRHVlhftd6RFJDIvv03JgkSbw== | ||
|
||
[email protected], zod@^3.22.4: | ||
[email protected]: | ||
version "3.22.4" | ||
resolved "https://registry.yarnpkg.com/zod/-/zod-3.22.4.tgz#f31c3a9386f61b1f228af56faa9255e845cf3fff" | ||
integrity sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg== |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it makes sense to enable all commands by default? It seems that disabling by default has always caused more headaches when starting new repos for us? rfc @whilefoo