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

Commit

Permalink
backstage rule
Browse files Browse the repository at this point in the history
  • Loading branch information
raphapr committed May 10, 2023
1 parent 969692a commit 08b3fcb
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
40 changes: 40 additions & 0 deletions rules/common/backstage.ts
Original file line number Diff line number Diff line change
@@ -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. Please, add a proper catalog-info.yaml file.`)
return
} else {
fail(`fail to retrieve '${filePath}'. ${e.status}.`)
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
2 changes: 2 additions & 0 deletions rules/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -11,4 +12,5 @@ export default async () => {
mergeCommits()
await changelog()
testsUpdated()
await backstage()
}
2 changes: 1 addition & 1 deletion settings-peril.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 08b3fcb

Please sign in to comment.