Skip to content

Commit

Permalink
added commentting on pull requests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexvuka1 committed Feb 12, 2024
1 parent 8c0b065 commit a3d88c3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ inputs:
required: true
doc-path:
required: true
token:
required: true

runs:
using: node20
Expand Down
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
},
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/github": "^6.0.0",
"@apidevtools/swagger-parser": "^10.1.0",
"@readme/openapi-parser": "^2.5.0",
"ajv": "^8.12.0",
Expand Down
24 changes: 21 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { read } from 'to-vfile';
import { visit } from 'unist-util-visit';
import { objectEntries } from './utils';
import { difference } from 'lodash-es';
import github from '@actions/github';

type Methods = OpenAPIV2.HttpMethods &
OpenAPIV3.HttpMethods &
Expand All @@ -25,6 +26,9 @@ export const run = async () => {
try {
const oasPath = core.getInput('openapi-path', { required: true });
const docPath = core.getInput('doc-path', { required: true });
const token = core.getInput('token', { required: true });
const octokit = github.getOctokit(token);
const { context } = github;

const oas = await SwaggerParser.validate(oasPath);
const endpoints = oas.paths
Expand Down Expand Up @@ -59,11 +63,25 @@ export const run = async () => {
if (outdated.length > 0) {
errors.push(`Outdated: ${outdated.join(', ')}`);
}
if (errors.length > 0) {
throw new Error(errors.join('\n'));

const body =
errors.length > 0
? errors.join('\n')
: 'Success - No inconsistencies found!';

if (context.eventName === 'pull_request') {
await octokit.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body,
});
}

core.debug('Success - No inconsistencies found!');
if (errors.length > 0) {
throw new Error(body);
}
core.debug(body);
} catch (error) {
// Fail the workflow run if an error occurs
if (error instanceof Error) core.setFailed(error.message);
Expand Down

0 comments on commit a3d88c3

Please sign in to comment.