Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into deprecate-multi-rule
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Schwarz committed Aug 6, 2022
2 parents 25c2502 + 6061f29 commit fc16cb4
Show file tree
Hide file tree
Showing 126 changed files with 15,463 additions and 920 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/danger.yaml
@@ -0,0 +1,41 @@
name: "Danger"

on:
issue_comment:
pull_request_target:
types: [assigned, opened, synchronize, reopened]
branches:
- "**"

permissions:
actions: write
checks: write
contents: write
issues: write
pull-requests: write
statuses: write

jobs:
danger:
name: Danger JS
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@2fddd8803e2f5c9604345a0b591c3020ee971a93 # tag=v3
with:
node-version: "16"
cache: "yarn"
cache-dependency-path: "website/yarn.lock"

- name: Install Yarn Dependencies
working-directory: bots/
run: yarn install

- name: Run Danger
working-directory: bots/
run: yarn danger ci
env:
DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/detekt-with-type-resolution.yaml
Expand Up @@ -39,7 +39,7 @@ jobs:
arguments: :detekt-cli:runWithArgsFile

- name: Upload SARIF to Github using the upload-sarif action
uses: github/codeql-action/upload-sarif@0c670bbf0414f39666df6ce8e718ec5662c21e03 # tag=v2
uses: github/codeql-action/upload-sarif@2ca79b6fa8d3ec278944088b4aa5f46912db5d63 # tag=v2
if: ${{ always() }}
with:
sarif_file: build/detekt-report.sarif
Expand Down
9 changes: 9 additions & 0 deletions bots/.gitignore
@@ -0,0 +1,9 @@
# Dependencies
/node_modules

# Misc
.DS_Store

npm-debug.log*
yarn-debug.log*
yarn-error.log*
62 changes: 62 additions & 0 deletions bots/dangerfile.js
@@ -0,0 +1,62 @@
import { danger, fail, markdown, warn, message } from "danger";

// API reference: https://danger.systems/js/reference.html
const pr = danger.github.pr;

const functionalChanges = danger.git.fileMatch("**/src/main/kotlin/**/*.kt");
const testChanges = danger.git.fileMatch("**/src/test/kotlin/**/*.kt");
const docsChanges = danger.git.fileMatch("**/*.md");
const rulesChanges = danger.git.fileMatch(
"detekt-rules-*/src/main/kotlin/**/*.kt"
);
const ruleTestChanges = danger.git.fileMatch(
"detekt-rules-*/src/test/kotlin/**/*.kt"
);
const detektConfigFileChanges = danger.git.fileMatch(
"**/default-detekt-config.yml"
);
const milestone = danger.github.pr.milestone;
const prReviews = danger.github.reviews;

// Warn if the PR contains a functional change without a test
if (functionalChanges.length > 0 && testChanges.length === 0) {
warn(
"It looks like this PR contains functional changes without a corresponding test."
);
}

// Handle PRs for new Detekt rules.
if (rulesChanges.created) {
message("Thanks for adding a new rule to Detekt :heart:");
if (ruleTestChanges.length === 0) {
warn(
"It looks like your new rule doesn't comes with tests. Make sure you include them."
);
}
if (detektConfigFileChanges.length === 0) {
warn(
"It looks like you haven't updated the `default-detekt-config.yml` file in your PR. Make sure you run `./gradlew generateDocumentation`"
);
}
}

// If `default-detekt-config.yml` changes without a rule change, warn the user
if (detektConfigFileChanges.length > 0 && rulesChanges.length === 0) {
warn(
"It looks like you're touching the `default-detekt-config.yml` file without updating the rules code. This file is automatically generated with the `gradlew generateDocumentation` task, so your changes will be overridden."
);
}

// Say thank you to Website edits.
if (docsChanges.edited) {
message(
"Thank you very much for making [our website](https://detekt.dev/) better :heart:!"
);
}

// Warn if the PR has been accepted but has no milestone set.
if (!milestone && prReviews.some((review) => review.state === "APPROVED")) {
warn(
"This PR is approved with no milestone set. If merged, it won't appear in the Detekt release notes."
);
}
12 changes: 12 additions & 0 deletions bots/package.json
@@ -0,0 +1,12 @@
{
"name": "@detekt/bots",
"version": "1.0.0",
"private": true,
"description": "Bots and automation for Detekt",
"type": "module",
"main": "index.js",
"license": "MIT",
"devDependencies": {
"danger": "^11.1.1"
}
}

0 comments on commit fc16cb4

Please sign in to comment.