Skip to content

Commit

Permalink
ci: add dangerjs wd-149
Browse files Browse the repository at this point in the history
  • Loading branch information
what1s1ove committed Nov 18, 2023
1 parent 20b7a9a commit 6896d7a
Show file tree
Hide file tree
Showing 4 changed files with 1,183 additions and 50 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/ci-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@ jobs:

- name: Install Dependencies
run: |
npm install
npm ci
- name: Lint Commits
run: |
npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose
- name: Lint Pull Request
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npx danger ci --failOnErrors --text-only
38 changes: 38 additions & 0 deletions dangerfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { danger, fail } from 'danger'

import { ProjectPrefix } from './project.config.js'

let appsPattern = ProjectPrefix.APPS.join(`|`)
let environmentsPattern = ProjectPrefix.ENVIRONMENTS.join(`|`)

let Config = /** @type {const} */ ({
BRANCH_PATTERN: new RegExp(
`^((${appsPattern})-[0-9]{1,6})-[a-zA-Z0-9-]+$|(${environmentsPattern})$`,
),
IS_ASSIGNEE_REQUIRED: true,
TITLE_PATTERN: new RegExp(
`^((${appsPattern})-[0-9]{1,6}): (.*\\S)$|(${environmentsPattern}) to (${environmentsPattern})$`,
),
})

let isTitleValid = Config.TITLE_PATTERN.test(danger.github.pr.title)

if (!isTitleValid) {
fail(
`Pull Request title should match the following pattern – ${Config.TITLE_PATTERN}.`,
)
}

let isBranchValid = Config.BRANCH_PATTERN.test(danger.github.pr.head.ref)

if (!isBranchValid) {
fail(
`Pull Request branch should match the following pattern – ${Config.BRANCH_PATTERN}.`,
)
}

let hasAssignee = Boolean(danger.github.pr.assignee)

if (Config.IS_ASSIGNEE_REQUIRED && !hasAssignee) {
fail(`Pull Request should have at least one assignee.`)
}
Loading

0 comments on commit 6896d7a

Please sign in to comment.