diff --git a/rules/common/backstage.ts b/rules/common/backstage.ts new file mode 100644 index 0000000..4a60903 --- /dev/null +++ b/rules/common/backstage.ts @@ -0,0 +1,40 @@ +import { danger, warn } from "danger" +import { validate } from "@roadiehq/roadie-backstage-entity-validator" + +const backstage = async () => { + const pr = danger.github.pr + const isOpen = pr.state === "open" + + if (!isOpen) { + return + } + + const filePath = "catalog-info.yaml" + let ghFileContent + try { + ghFileContent = await danger.github.api.repos.getContent({ + owner: pr.head.user.login, + repo: pr.head.repo.name, + path: filePath, + ref: danger.github.pr.head.sha, + }) + } catch (e) { + if (e.status === 404) { + fail(`'${filePath}' not found.`) + return + } else { + fail(`fail to retrieve '${filePath}.'`) + return + } + } + + const fileContent = Buffer.from(ghFileContent.data.content, "base64").toString() + + try { + await validate(fileContent, true) + } catch (e) { + fail(`Oh no! 'catalog-info.yaml' file is not valid for Backstage:\n\n\`\`\`sh ${e} \`\`\``) + } +} + +export default backstage diff --git a/rules/common/index.ts b/rules/common/index.ts index 96e20a6..d31804d 100644 --- a/rules/common/index.ts +++ b/rules/common/index.ts @@ -3,6 +3,7 @@ import workInProgress from "./workInProgress" import mergeCommits from "./mergeCommits" import changelog from "./changelog" import testsUpdated from "./testsUpdated" +import backstage from "./backstage" // Default run export default async () => { @@ -11,4 +12,5 @@ export default async () => { mergeCommits() await changelog() testsUpdated() + await backstage() } diff --git a/settings-peril.json b/settings-peril.json index 9603dc5..7c0cf0d 100644 --- a/settings-peril.json +++ b/settings-peril.json @@ -4,7 +4,7 @@ }, "rules": { "pull_request.opened": ["rules/common/approveReleasePR.ts", "rules/common/changelog.ts"], - "pull_request.synchronize": "rules/common/changelog.ts", + "pull_request.synchronize": ["rules/common/changelog.ts", "rules/common/backstage.ts"], "pull_request.closed": "rules/common/deleteMergedPRBranch.ts", "issue_comment.created": [ "rules/common/markAsMergeOnGreen.ts",