-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
ci: Add sloppy /test command #33558
ci: Add sloppy /test command #33558
Conversation
WalkthroughWalkthroughThe overall change to the pull request automation workflow includes implementing a new script for tag parsing from PR descriptions using Changes
Recent Review DetailsConfiguration used: CodeRabbit UI Files selected for processing (1)
Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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.
Actionable comments posted: 3
function parseTags({core, context}) { | ||
const body = context.payload.pull_request.body; | ||
|
||
// "/ok-to-test" matcher. Takes precedence over the "/test" matcher. | ||
const strictMatch = body.match(/\/ok-to-test tags="(.+?)"/)?.[1]; | ||
if (strictMatch) { | ||
return strictMatch; | ||
return; | ||
} | ||
|
||
// "/test" matcher. | ||
const allTags = require(process.env.GITHUB_WORKSPACE + "/app/client/cypress/tags.js").Tag; | ||
const config = body.match(/^\/test\s+(.*)$/m)?.[1] ?? ""; | ||
const concreteTags = []; | ||
|
||
for (const [rawTag] of config.matchAll(/\w+/g)) { | ||
console.log("Given: '" + rawTag + "'"); | ||
|
||
// See if there is exact case-insensitive match. | ||
const exactTagMatch = allTags.find(t => t.toLowerCase() === "@tag." + rawTag); | ||
if (exactTagMatch) { | ||
console.log("\tMatch found:", exactTagMatch); | ||
concreteTags.push(exactTagMatch); | ||
continue; | ||
} | ||
|
||
// See if there is a singular/plural match (very rudimentary language skills). | ||
const countedMatch = allTags.find(t => t.toLowerCase().replace(/s$/, "") === "@tag." + rawTag.replace(/s$/, "")); | ||
if (countedMatch) { | ||
console.log("\tMatch found:", countedMatch); | ||
concreteTags.push(countedMatch); | ||
continue; | ||
} | ||
|
||
// More smart matchers? | ||
|
||
// No match, fail. | ||
core.setFailed("\tNo match found for tag:", rawTag); | ||
|
||
// We still process the rest, so we report all invalid tags in the input in a single run. | ||
} | ||
|
||
return concreteTags.join(", "); | ||
} |
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.
Consider adding unit tests for parseTags
to ensure its robustness.
Would you like me to help by setting up some initial unit tests for this function?
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Adds support for a
/test
command, without breaking the existing/ok-to-test
habits.This is a sloppy version of
/ok-to-test
. Turns out humans are sloppy. So let's embrace the human. 🤯Example incantation:
The sloppy parser at work:
Of course, if a PR body contains
/ok-to-test
, that takes precedence, and any/test
is ignored.We're also moving the logic of parsing the tags to a separate Javascript file. It's still not in a form that's easily testable, perhaps, but I hope this is a start for us to get to a "unit-tested CI". ❤️