-
Notifications
You must be signed in to change notification settings - Fork 5.6k
[spec-gen-sdk-runner] Move SpecGenSdkArtifactInfo to .github/shared #38816
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
Changes from 1 commit
7de1b35
ee44798
8e1749e
0524f9a
5a197a6
08bdafd
7ee3337
3a44525
5a78988
505cd59
4190c80
36d8fb1
9269d89
6b174fa
82ff3ec
a79e05a
b553ef0
8e1d539
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,38 @@ | ||
| /* v8 ignore start */ | ||
| import * as z from "zod"; | ||
|
|
||
| const SdkNameSchema = z.enum([ | ||
| "azure-sdk-for-go", | ||
| "azure-sdk-for-java", | ||
| "azure-sdk-for-js", | ||
| "azure-sdk-for-net", | ||
| "azure-sdk-for-python", | ||
| ]); | ||
| /** | ||
| * @typedef {'azure-sdk-for-go' | 'azure-sdk-for-java' | 'azure-sdk-for-js' | 'azure-sdk-for-net' | 'azure-sdk-for-python'} SdkName | ||
| * @typedef {import("zod").infer<typeof SdkNameSchema>} SdkName | ||
|
||
| */ | ||
|
|
||
| /* | ||
| * Data for the API view request. | ||
| */ | ||
| const APIViewRequestDataSchema = z.object({ packageName: z.string(), filePath: z.string() }); | ||
| /** | ||
| * @typedef {import("zod").infer<typeof APIViewRequestDataSchema>} APIViewRequestData | ||
|
Member
Author
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. type |
||
| */ | ||
|
|
||
| /** | ||
| * Represents the result of the spec-gen-sdk generation process. | ||
| */ | ||
| export const SpecGenSdkArtifactInfoSchema = z.object({ | ||
| language: SdkNameSchema, | ||
| result: z.string(), | ||
| headSha: z.string(), | ||
| prNumber: z.string().optional(), | ||
| labelAction: z.boolean().optional(), | ||
| isSpecGenSdkCheckRequired: z.boolean(), | ||
| apiViewRequestData: z.array(APIViewRequestDataSchema), | ||
| }); | ||
| /** | ||
| * @typedef {import("zod").infer<typeof SpecGenSdkArtifactInfoSchema>} SpecGenSdkArtifactInfo | ||
|
Member
Author
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. type |
||
| */ | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /** | ||
| * @typedef {import("../src/sdk-types.js").SpecGenSdkArtifactInfo} SpecGenSdkArtifactInfo | ||
| */ | ||
|
|
||
| /** | ||
| * Create a mock SpecGenSdkArtifactInfo, filling unspecified properties with defaults. | ||
mikeharder marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * @param {Partial<import("../src/sdk-types.js").SpecGenSdkArtifactInfo>} [overrides] | ||
| * @returns {SpecGenSdkArtifactInfo} | ||
| */ | ||
| export function createMockSpecGenSdkArtifactInfo(overrides = {}) { | ||
| /** @type {SpecGenSdkArtifactInfo} */ | ||
| const defaults = { | ||
| apiViewRequestData: [], | ||
| headSha: "abc123", | ||
| isSpecGenSdkCheckRequired: true, | ||
| language: "azure-sdk-for-go", | ||
| result: "test result", | ||
| }; | ||
|
|
||
| return { ...defaults, ...overrides }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { sdkLabels, SpecGenSdkArtifactInfoSchema } from "../src/sdk-types.js"; | ||
| import { createMockSpecGenSdkArtifactInfo } from "./sdk-types.js"; | ||
|
|
||
| describe("sdk-types", () => { | ||
| it("defines sdkLabels", () => { | ||
| // Ensures constant "sdkLabels" is considered "covered" by codecov | ||
| expect(sdkLabels).toBeDefined(); | ||
| }); | ||
|
|
||
| it("parses SpecGetSdkArtifactInfo", () => { | ||
| const artifactInfo = createMockSpecGenSdkArtifactInfo(); | ||
|
|
||
| const json = JSON.stringify(artifactInfo); | ||
| expect(json).toMatchInlineSnapshot( | ||
| `"{"apiViewRequestData":[],"headSha":"abc123","isSpecGenSdkCheckRequired":true,"language":"azure-sdk-for-go","result":"test result"}"`, | ||
| ); | ||
|
|
||
| const parsed = SpecGenSdkArtifactInfoSchema.parse(JSON.parse(json)); | ||
| expect(parsed).toEqual(artifactInfo); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import { sdkLabels } from "../../shared/src/sdk-types.js"; | ||
| import { SpecGenSdkArtifactInfoSchema, sdkLabels } from "../../shared/src/sdk-types.js"; | ||
| import { getAdoBuildInfoFromUrl, getAzurePipelineArtifact } from "./artifacts.js"; | ||
| import { extractInputs } from "./context.js"; | ||
| import { LabelAction } from "./label.js"; | ||
|
|
@@ -72,12 +72,14 @@ | |
| } else { | ||
| core.info(`Artifact content: ${result.artifactData}`); | ||
| // Parse the JSON data | ||
| const specGenSdkArtifactInfo = JSON.parse(result.artifactData); | ||
| const specGenSdkArtifactInfo = SpecGenSdkArtifactInfoSchema.parse( | ||
| JSON.parse(result.artifactData), | ||
| ); | ||
| const labelActionText = specGenSdkArtifactInfo.labelAction; | ||
|
|
||
| head_sha = specGenSdkArtifactInfo.headSha; | ||
|
|
||
| issue_number = parseInt(specGenSdkArtifactInfo.prNumber, 10); | ||
| issue_number = parseInt(specGenSdkArtifactInfo.prNumber ?? "", 10); | ||
|
Member
Author
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.
|
||
| if (!issue_number) { | ||
| core.warning( | ||
| `No PR number found in the artifact '${artifactName}' with details_url:${details_url}.`, | ||
|
|
||
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.
added test coverage, so we can remove ignore