Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
94 changes: 94 additions & 0 deletions packages/action/__tests__/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!!!'
}),
});
});

});

});
8 changes: 6 additions & 2 deletions packages/action/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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}`);

Expand Down
24 changes: 24 additions & 0 deletions website/src/pages/docs/products/action.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down