Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
add backstage rule for catalog-info schema validation
Browse files Browse the repository at this point in the history
  • Loading branch information
raphapr committed May 12, 2023
1 parent 33343bf commit 775dbbd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
28 changes: 28 additions & 0 deletions rules/common/backstage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { danger, fail } from "danger"
import { validate } from "@roadiehq/roadie-backstage-entity-validator"

const backstage = async () => {
const pr = danger.github.pr
const utils = danger.github.utils

const isOpen = pr.state === "open"

if (!isOpen) {
return
}

const filePath = "catalog-info.yaml"
const fileContent = await utils.fileContents(filePath, `${pr.head.user.login}/${pr.head.repo.name}`, pr.head.sha)

if (fileContent) {
try {
await validate(fileContent, true, "./schemas/backstage.annotations.json")
} catch (e) {
fail(`The 'catalog-info.yaml' file is not valid for Backstage. Error details:\n\n\`\`\`\n${e}\n\`\`\``)
}
} else {
fail(`The '${filePath}' file doesn't exist in the pull request.`)
}
}

export default backstage
2 changes: 2 additions & 0 deletions rules/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import mergeCommits from "./mergeCommits"
import changelog from "./changelog"
import testsUpdated from "./testsUpdated"
import notificationHubTemplate from "./notificationHubTemplate"
import backstage from "./backstage"

// Default run
export default async () => {
Expand All @@ -13,4 +14,5 @@ export default async () => {
await changelog()
testsUpdated()
await notificationHubTemplate()
await backstage()
}
2 changes: 1 addition & 1 deletion settings-peril.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,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",
Expand Down

0 comments on commit 775dbbd

Please sign in to comment.