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 11, 2023
1 parent d84a248 commit 4b1abb1
Show file tree
Hide file tree
Showing 6 changed files with 415 additions and 118 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"type-check": "tsc --noEmit"
},
"devDependencies": {
"@roadiehq/roadie-backstage-entity-validator": "^2.3.0",
"@slack/client": "^4.2.2",
"@types/jest": "^22.2.3",
"@types/node": "^8.0.25",
Expand Down
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: 1 addition & 1 deletion rules/common/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const changelog = async () => {
Object.prototype.hasOwnProperty.call(packageJson, "release")

if (isOpen && hasChangelog && !hasSemanticRelease) {
const files = [...danger.git.modified_files, ...danger.git.created_files]
const files = [...(danger.git.modified_files || []), ...(danger.git.created_files || [])]

const hasCodeChanges = files.find(file => !file.match(/(test|spec)/i))
const hasChangelogChanges = files.find(file => changelogs_re.test(file))
Expand Down
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
Loading

0 comments on commit 4b1abb1

Please sign in to comment.