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

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
backstage rule
Browse files Browse the repository at this point in the history
raphapr committed May 10, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 969692a commit 08b3fcb
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
@@ -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()
}
2 changes: 1 addition & 1 deletion settings-peril.json
Original file line number Diff line number Diff line change
@@ -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",

0 comments on commit 08b3fcb

Please sign in to comment.