From a9dda6263805248c91a4ccb935f090c2bd3ce97f Mon Sep 17 00:00:00 2001 From: "nicolo.castro" Date: Thu, 8 May 2025 12:34:57 +0200 Subject: [PATCH 01/10] Add optional inputs for messages --- action.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/action.yml b/action.yml index 813284f209..2f843715a0 100644 --- a/action.yml +++ b/action.yml @@ -40,6 +40,16 @@ inputs: Helps to get the correct state of schema when Pull Request is behind the target branch (enabled by default) + success-title: + default: 'Everything looks good' + required: false + description: | + Title to display when the action is successful. If not provided, the default 'Everything looks good' will be used. + failure-title: + default: 'Something is wrong with your schema' + required: false + description: | + Title to display when the action failes. If not provided, the default 'Something is wrong with your schema' will be used. rules: description: | Apply rules that change certain checks from Breaking to Dangerous. From c2f574f805941eff6b396606c09ee6613a3dd31d Mon Sep 17 00:00:00 2001 From: "nicolo.castro" Date: Thu, 8 May 2025 12:35:07 +0200 Subject: [PATCH 02/10] use input for title message --- packages/action/src/run.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/action/src/run.ts b/packages/action/src/run.ts index 6ec0a9db07..88249c2d00 100644 --- a/packages/action/src/run.ts +++ b/packages/action/src/run.ts @@ -41,6 +41,8 @@ export async function run() { const approveLabel: string = core.getInput('approve-label') || 'approved-breaking-change'; const rulesList = getInputAsArray('rules') || []; const onUsage = core.getInput('onUsage'); + const successMessage: string = core.getInput('success-title') + const failureMessage: string = core.getInput('failure-title') const octokit = github.getOctokit(token); @@ -213,8 +215,8 @@ export async function run() { const title = conclusion === CheckConclusion.Failure - ? 'Something is wrong with your schema' - : 'Everything looks good'; + ? failureMessage + : successMessage; core.info(`Conclusion: ${conclusion}`); From f722fa804bf1ea9b69367405f37dc7e27640bb3c Mon Sep 17 00:00:00 2001 From: "nicolo.castro" Date: Thu, 8 May 2025 12:35:22 +0200 Subject: [PATCH 03/10] add test for success and failure message --- packages/action/__tests__/run.test.ts | 95 +++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/packages/action/__tests__/run.test.ts b/packages/action/__tests__/run.test.ts index 9a0b152066..995dfa3195 100644 --- a/packages/action/__tests__/run.test.ts +++ b/packages/action/__tests__/run.test.ts @@ -258,4 +258,99 @@ describe('Inspector Action', () => { }); }); }); + + describe('messages', () => { + it('should accept a success message', async () => { + vi.spyOn(core, 'getInput').mockImplementation((name: string, _options) => { + switch (name) { + case 'github-token': + return 'MOCK_GITHUB_TOKEN'; + case 'schema': + return 'master:schema.graphql'; + case 'rules': + return ` + suppressRemovalOfDeprecatedField + `; + case 'success-title': + return 'Your schema is good to go!!!'; + default: + return ''; + } + }); + + mockLoadFile + .mockResolvedValueOnce(/* GraphQL */ ` + type Query { + oldQuery: OldType @deprecated(reason: "use newQuery") + newQuery: Int! + } + + type OldType { + field: String! + } + `) + .mockResolvedValueOnce(/* GraphQL */ ` + type Query { + newQuery: Int! + } + `); + + await run(); + + expect(mockUpdateCheckRun).toBeCalledWith(expect.anything(), '2', { + conclusion: CheckConclusion.Success, + output: { + title: 'Your schema is good to go!!!', + + }, + }); + }); + + it('should accept a failure message', async () => { + vi.spyOn(core, 'getInput').mockImplementation((name: string, _options) => { + switch (name) { + case 'github-token': + return 'MOCK_GITHUB_TOKEN'; + case 'schema': + return 'master:schema.graphql'; + case 'rules': + return ` + suppressRemovalOfDeprecatedField + `; + case 'failure-title': + return 'Your schema is broken!!!'; + default: + return ''; + } + }); + + mockLoadFile + .mockResolvedValueOnce(/* GraphQL */ ` + type Query { + oldQuery: OldType + newQuery: Int! + } + + type OldType { + field: String! + } + `) + .mockResolvedValueOnce(/* GraphQL */ ` + type Query { + newQuery: Int! + } + `); + + await run(); + + expect(mockUpdateCheckRun).toBeCalledWith(expect.anything(), '2', { + conclusion: CheckConclusion.Failure, + output: { + title: 'Your schema is broken!!!', + }, + }); + }); + + }); + }); From dc8a6b908f189d97818b4030dd8732b9b7575026 Mon Sep 17 00:00:00 2001 From: "nicolo.castro" Date: Thu, 8 May 2025 13:57:42 +0200 Subject: [PATCH 04/10] force run From c1e12312f773b6237411536b8281c5f12c111a9b Mon Sep 17 00:00:00 2001 From: "nicolo.castro" Date: Thu, 8 May 2025 14:53:42 +0200 Subject: [PATCH 05/10] ensure default message --- packages/action/src/run.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/action/src/run.ts b/packages/action/src/run.ts index 88249c2d00..439df7cfe2 100644 --- a/packages/action/src/run.ts +++ b/packages/action/src/run.ts @@ -41,8 +41,8 @@ export async function run() { const approveLabel: string = core.getInput('approve-label') || 'approved-breaking-change'; const rulesList = getInputAsArray('rules') || []; const onUsage = core.getInput('onUsage'); - const successMessage: string = core.getInput('success-title') - const failureMessage: string = core.getInput('failure-title') + const successMessage: string = core.getInput('success-title') || 'Everything looks good'; + const failureMessage: string = core.getInput('failure-title') || 'Something is wrong with your schema'; const octokit = github.getOctokit(token); @@ -213,10 +213,12 @@ export async function run() { const summary = createSummary(changes, 100, false); + // const successMessage: string = 'Everything looks good'; + // const failureMessage: string = 'Something is wrong with your schema'; const title = conclusion === CheckConclusion.Failure - ? failureMessage - : successMessage; + ? failureMessage + : successMessage; core.info(`Conclusion: ${conclusion}`); From 1c15fe4391ae80e1848e519a7de6f3bf51aec134 Mon Sep 17 00:00:00 2001 From: "nicolo.castro" Date: Thu, 8 May 2025 15:15:36 +0200 Subject: [PATCH 06/10] validate title --- packages/action/__tests__/run.test.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/action/__tests__/run.test.ts b/packages/action/__tests__/run.test.ts index 995dfa3195..9cf9a2bf0b 100644 --- a/packages/action/__tests__/run.test.ts +++ b/packages/action/__tests__/run.test.ts @@ -299,10 +299,9 @@ describe('Inspector Action', () => { expect(mockUpdateCheckRun).toBeCalledWith(expect.anything(), '2', { conclusion: CheckConclusion.Success, - output: { - title: 'Your schema is good to go!!!', - - }, + output: expect.objectContaining({ + title: 'Your schema is good to go!!!' + }), }); }); @@ -345,9 +344,9 @@ describe('Inspector Action', () => { expect(mockUpdateCheckRun).toBeCalledWith(expect.anything(), '2', { conclusion: CheckConclusion.Failure, - output: { - title: 'Your schema is broken!!!', - }, + output: expect.objectContaining({ + title: 'Your schema is broken!!!' + }), }); }); From b37a9504690867b1cff8dadc2434cd489b1eada6 Mon Sep 17 00:00:00 2001 From: "nicolo.castro" Date: Thu, 8 May 2025 15:47:01 +0200 Subject: [PATCH 07/10] put new inputs at teh bottom --- action.yml | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/action.yml b/action.yml index 2f843715a0..fc33e9c6b6 100644 --- a/action.yml +++ b/action.yml @@ -40,16 +40,6 @@ inputs: Helps to get the correct state of schema when Pull Request is behind the target branch (enabled by default) - success-title: - default: 'Everything looks good' - required: false - description: | - Title to display when the action is successful. If not provided, the default 'Everything looks good' will be used. - failure-title: - default: 'Something is wrong with your schema' - required: false - description: | - Title to display when the action failes. If not provided, the default 'Something is wrong with your schema' will be used. rules: description: | Apply rules that change certain checks from Breaking to Dangerous. @@ -62,7 +52,16 @@ inputs: Should be a path to a JS file as described in https://the-guild.dev/graphql/inspector/docs/essentials/diff#considerusage required: false - + success-title: + default: 'Everything looks good' + required: false + description: | + Title to display when the action is successful. If not provided, the default 'Everything looks good' will be used. + failure-title: + default: 'Something is wrong with your schema' + required: false + description: | + Title to display when the action failes. If not provided, the default 'Something is wrong with your schema' will be used. outputs: changes: description: Total number of changes From 6acc55a3c696b861cf379c098de89c2982f35db4 Mon Sep 17 00:00:00 2001 From: "nicolo.castro" Date: Thu, 8 May 2025 15:47:10 +0200 Subject: [PATCH 08/10] update documentation --- website/src/pages/docs/products/action.mdx | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/website/src/pages/docs/products/action.mdx b/website/src/pages/docs/products/action.mdx index 3b1a98068b..cee0cba876 100644 --- a/website/src/pages/docs/products/action.mdx +++ b/website/src/pages/docs/products/action.mdx @@ -151,6 +151,30 @@ Must be used with the `rules` input. Required to apply the custom logic for the onUsage: check-usage.js ``` +### `success-title` + +Title to add to the check run in case of a successful run (`Everything looks good` by +default). + +```yaml +- uses: graphql-hive/graphql-inspector@master + with: + schema: 'master:schema.graphql' + success-title: 'Your schema contains no breaking change!!' +``` + +### `failure-title` + +Title to add to the check run in case of a failed run (`Something is wrong with your schema` by +default). + +```yaml +- uses: graphql-hive/graphql-inspector@master + with: + schema: 'master:schema.graphql' + success-title: 'A breaking change was found in the schema. If this is expected you can ignore it by adding `approved-breaking-change` to the PR labels' +``` + ## Outputs Read From e44768e2f0b0a106cdb28aa42689827d6b1f9680 Mon Sep 17 00:00:00 2001 From: "nicolo.castro" Date: Fri, 9 May 2025 08:31:28 +0200 Subject: [PATCH 09/10] aligning default values to the lable approach --- action.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/action.yml b/action.yml index fc33e9c6b6..f1832b0cbc 100644 --- a/action.yml +++ b/action.yml @@ -53,13 +53,9 @@ inputs: Should be a path to a JS file as described in https://the-guild.dev/graphql/inspector/docs/essentials/diff#considerusage required: false success-title: - default: 'Everything looks good' - required: false description: | Title to display when the action is successful. If not provided, the default 'Everything looks good' will be used. failure-title: - default: 'Something is wrong with your schema' - required: false description: | Title to display when the action failes. If not provided, the default 'Something is wrong with your schema' will be used. outputs: From b0824bc17d73a75e7dfcddfc1719b0fe1e333f9c Mon Sep 17 00:00:00 2001 From: nicolocastro89 <80069314+nicolocastro89@users.noreply.github.com> Date: Thu, 29 May 2025 16:28:18 +0200 Subject: [PATCH 10/10] Update website/src/pages/docs/products/action.mdx Co-authored-by: maxmelamed <50888194+maxmelamed@users.noreply.github.com> --- website/src/pages/docs/products/action.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/src/pages/docs/products/action.mdx b/website/src/pages/docs/products/action.mdx index cee0cba876..df243cd80b 100644 --- a/website/src/pages/docs/products/action.mdx +++ b/website/src/pages/docs/products/action.mdx @@ -172,7 +172,7 @@ default). - uses: graphql-hive/graphql-inspector@master with: schema: 'master:schema.graphql' - success-title: 'A breaking change was found in the schema. If this is expected you can ignore it by adding `approved-breaking-change` to the PR labels' + failure-title: 'A breaking change was found in the schema. If this is expected you can ignore it by adding `approved-breaking-change` to the PR labels' ``` ## Outputs