-
Notifications
You must be signed in to change notification settings - Fork 6
[CSR-3565] feat: add full OpenAPI parity with Actions and Runs management APIs #33
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
Open
miguelangaranocurrents
wants to merge
1
commit into
main
Choose a base branch
from
ai/feat/openapi-actions-runs-parity
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| import { z } from "zod"; | ||
| import { postApi } from "../../lib/request.js"; | ||
| import { logger } from "../../lib/logger.js"; | ||
|
|
||
| // Define condition type and operator enums | ||
| const ConditionType = z.enum([ | ||
| "testId", | ||
| "project", | ||
| "title", | ||
| "file", | ||
| "git_branch", | ||
| "git_authorName", | ||
| "git_authorEmail", | ||
| "git_remoteOrigin", | ||
| "git_message", | ||
| "error_message", | ||
| "titlePath", | ||
| "annotation", | ||
| "tag", | ||
| ]); | ||
|
|
||
| const ConditionOperator = z.enum([ | ||
| "eq", | ||
| "neq", | ||
| "any", | ||
| "empty", | ||
| "in", | ||
| "notIn", | ||
| "inc", | ||
| "notInc", | ||
| "incAll", | ||
| "notIncAll", | ||
| ]); | ||
|
|
||
| // Define rule action schemas | ||
| const RuleActionSkip = z.object({ | ||
| op: z.literal("skip"), | ||
| }); | ||
|
|
||
| const RuleActionQuarantine = z.object({ | ||
| op: z.literal("quarantine"), | ||
| }); | ||
|
|
||
| const RuleActionTag = z.object({ | ||
| op: z.literal("tag"), | ||
| details: z.object({ | ||
| tags: z.array(z.string()).max(10).describe("Tags to add to matching tests"), | ||
| }), | ||
| }); | ||
|
|
||
| const RuleAction = z.union([RuleActionSkip, RuleActionQuarantine, RuleActionTag]); | ||
|
|
||
| // Define matcher condition schema | ||
| const RuleMatcherCondition = z.object({ | ||
| type: ConditionType, | ||
| op: ConditionOperator, | ||
| value: z.union([z.string(), z.array(z.string())]).optional().nullable(), | ||
| }); | ||
|
|
||
| // Define matcher schema | ||
| const RuleMatcher = z.object({ | ||
| op: z.enum(["AND", "OR"]).describe("How to combine multiple conditions"), | ||
| cond: z.array(RuleMatcherCondition).min(1).describe("List of conditions to match"), | ||
| }); | ||
|
|
||
| const zodSchema = z.object({ | ||
| projectId: z | ||
| .string() | ||
| .describe("The project ID to create the action for."), | ||
| name: z | ||
| .string() | ||
| .min(1) | ||
| .max(255) | ||
| .describe("Human-readable name for the action."), | ||
| description: z | ||
| .string() | ||
| .max(1000) | ||
| .optional() | ||
| .nullable() | ||
| .describe("Optional description for the action."), | ||
| action: z | ||
| .array(RuleAction) | ||
| .min(1) | ||
| .describe("Actions to perform when conditions match."), | ||
| matcher: RuleMatcher.describe("Matcher defining which tests this action applies to."), | ||
| expiresAfter: z | ||
| .string() | ||
| .optional() | ||
| .nullable() | ||
| .describe("Optional expiration date in ISO 8601 format."), | ||
| }); | ||
|
|
||
| interface CreateActionRequest { | ||
| name: string; | ||
| description?: string | null; | ||
| action: any[]; | ||
| matcher: any; | ||
| expiresAfter?: string | null; | ||
| } | ||
|
|
||
| interface ActionResponse { | ||
| status: string; | ||
| data: any; | ||
| } | ||
|
|
||
| const handler = async ({ | ||
| projectId, | ||
| name, | ||
| description, | ||
| action, | ||
| matcher, | ||
| expiresAfter, | ||
| }: z.infer<typeof zodSchema>) => { | ||
| logger.info(`Creating action for project ${projectId}: ${name}`); | ||
|
|
||
| const body: CreateActionRequest = { | ||
| name, | ||
| description, | ||
| action, | ||
| matcher, | ||
| expiresAfter, | ||
| }; | ||
|
|
||
| const queryParams = new URLSearchParams(); | ||
| queryParams.append("projectId", projectId); | ||
|
|
||
| const data = await postApi<ActionResponse, CreateActionRequest>( | ||
| `/actions?${queryParams.toString()}`, | ||
| body | ||
| ); | ||
|
|
||
| if (!data) { | ||
| return { | ||
| content: [ | ||
| { | ||
| type: "text" as const, | ||
| text: "Failed to create action", | ||
| }, | ||
| ], | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| content: [ | ||
| { | ||
| type: "text" as const, | ||
| text: JSON.stringify(data, null, 2), | ||
| }, | ||
| ], | ||
| }; | ||
| }; | ||
|
|
||
| export const createActionTool = { | ||
| schema: zodSchema.shape, | ||
| handler, | ||
| }; |
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.
P2:
deleteApiunconditionally callsresponse.json()which will throw an error if the API returns 204 No Content (a common response for DELETE operations). This would cause successful deletions to be incorrectly reported as failures. Consider checking if the response has content before parsing JSON.Prompt for AI agents