diff --git a/action.yml b/action.yml index 813284f209..f1832b0cbc 100644 --- a/action.yml +++ b/action.yml @@ -52,7 +52,12 @@ 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: + description: | + Title to display when the action is successful. If not provided, the default 'Everything looks good' will be used. + failure-title: + 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 diff --git a/packages/action/__tests__/run.test.ts b/packages/action/__tests__/run.test.ts index 9a0b152066..9cf9a2bf0b 100644 --- a/packages/action/__tests__/run.test.ts +++ b/packages/action/__tests__/run.test.ts @@ -258,4 +258,98 @@ 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: expect.objectContaining({ + 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: expect.objectContaining({ + title: 'Your schema is broken!!!' + }), + }); + }); + + }); + }); diff --git a/packages/action/src/run.ts b/packages/action/src/run.ts index 6ec0a9db07..439df7cfe2 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') || 'Everything looks good'; + const failureMessage: string = core.getInput('failure-title') || 'Something is wrong with your schema'; const octokit = github.getOctokit(token); @@ -211,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 - ? 'Something is wrong with your schema' - : 'Everything looks good'; + ? failureMessage + : successMessage; core.info(`Conclusion: ${conclusion}`); 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