This practical uses Danger JS - a proven, reliable tool for automated code review on GitHub Actions. This version is tested and confirmed working.
Time: ~1 hour
Need: GitHub account (free)
Experience needed: None
Visit: https://github.com/bitrise-io/android-demo-app
- Click "Fork" (top-right)
- Click "Create fork"
- Wait for completion
- Click "Add file" → "Create new file"
- Filename:
.github/workflows/danger.yml - Copy and paste this EXACT content:
name: Danger Check
on:
pull_request:
types: [opened, edited, synchronize, reopened]
jobs:
danger:
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install Danger
run: npm install -D danger
- name: Run Danger
run: npx danger ci
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}- Commit message:
ci: add Danger GitHub Actions workflow - Click "Commit changes"
- Click "Add file" → "Create new file"
- Filename:
dangerfile.js - Copy and paste this EXACT content:
import { danger, warn, message } from "danger";
// Welcome message
message("👋 Thanks for your pull request!");
// Get PR details
const title = danger.github.pr.title;
const body = danger.github.pr.body || "";
const additions = danger.github.pr.additions;
const deletions = danger.github.pr.deletions;
const changedFiles = danger.git.modified_files.length + danger.git.created_files.length;
// Rule 1: Check title format
if (!title.includes("feat:") && !title.includes("fix:") && !title.includes("test:") && !title.includes("chore:")) {
warn("⚠️ PR title should start with: feat:, fix:, test:, or chore:");
message("Example: `feat: add new calculator button`");
}
// Rule 2: Check description
if (!body || body.length < 10) {
warn("⚠️ Please add a meaningful PR description (at least 10 characters)");
}
// Rule 3: Check PR size
const totalChanges = additions + deletions;
if (totalChanges > 300) {
warn("⚠️ Large PR (#{totalChanges} lines). Consider breaking into smaller PRs");
}
// Rule 4: Check for tests
const kotlinFiles = danger.git.modified_files.filter(f => f.endsWith('.kt') && !f.includes('test'));
const testFiles = danger.git.modified_files.filter(f => f.includes('test') || f.includes('Test'));
if (kotlinFiles.length > 0 && testFiles.length === 0) {
message("💡 Consider adding tests for your Kotlin changes");
}
// Summary message
message(`📊 **PR Summary:**`);
message(`- Files changed: ${changedFiles}`);
message(`- Lines added: ${additions} ➕`);
message(`- Lines deleted: ${deletions} ➖`);
message(`- Total changes: ${totalChanges}`);
message("✅ Review complete!");- Commit message:
chore: add Danger configuration file - Click "Commit changes"
- Click branch dropdown (says "main")
- Type:
test-danger - Click "Create branch: test-danger"
- Click "Add file" → "Create new file"
- Filename:
app/src/main/java/TestFile.kt - Content:
class TestFile {
fun hello() {
println("Hello!")
}
}- Commit to
test-dangerbranch - Commit message:
added test(intentionally simple/wrong)
- Click "Pull requests" tab
- Click "New pull request"
- Select
test-dangerbranch - Intentionally fill in poorly:
- Title:
added test file(no prefix) - Description: leave empty or write just "test"
- Title:
- Click "Create pull request"
- Go to "Actions" tab
- Wait for workflow to complete (1-2 minutes)
- Return to your PR
- Scroll down to find Danger comments
- You should see warnings about title format and description
Now fix the issues:
- Click the three dots (...) next to PR title
- Click "Edit"
- Change to:
feat: add test file - Click "Save"
- Click "Edit" next to description
- Write:
Added a simple test file to the project.
This demonstrates how Danger checks PR details.
- Click "Save"
- Workflow runs automatically again
- After 1-2 minutes, check your PR
- Danger comments should now show:
- ✅ Good title format
- ✅ Good description
- ✅ Summary table
if (!title.includes("feat:") && ...) {
warn("⚠️ PR title should start with...");
}What it does: Checks if title has a prefix
Why: Organizes PR history
if (!body || body.length < 10) {
warn("⚠️ Please add a meaningful PR description...");
}What it does: Requires at least 10 characters
Why: Good descriptions help reviewers
if (totalChanges > 300) {
warn("⚠️ Large PR...");
}What it does: Warns if over 300 lines changed
Why: Large PRs are harder to review
if (kotlinFiles.length > 0 && testFiles.length === 0) {
message("💡 Consider adding tests...");
}What it does: Reminds about tests
Why: Tests catch bugs early
Edit dangerfile.js and add before the final messages:
// Check for changelog
const hasChangelog = danger.git.modified_files.some(f => f.includes('CHANGELOG'));
const isTrivial = title.toLowerCase().includes('chore') || title.toLowerCase().includes('docs');
if (additions + deletions > 10 && !hasChangelog && !isTrivial) {
message("📝 Consider updating CHANGELOG.md");
}Change this line:
if (totalChanges > 500) { // Changed from 300 to 500Change title check to:
if (!title.includes("feat:") && !title.includes("fix:") && !title.includes("test:") &&
!title.includes("chore:") && !title.includes("docs:") && !title.includes("refactor:")) {Create new PRs with:
- Different titles
- Different file types
- Different numbers of changes
See how Danger reacts!
✅ Set up automated code review on GitHub Actions
✅ Created review rules with Danger JS
✅ Tested with intentional bad PRs
✅ Fixed PRs based on automated feedback
✅ Learned CI/CD fundamentals
| Term | Meaning |
|---|---|
| GitHub Actions | Automation tool that runs on GitHub |
| Workflow | Automated tasks that run on events |
| Danger | Tool for automated code review |
| dangerfile.js | File with review rules |
| PR | Pull request - proposed changes |
- ✅ Danger JS is built for GitHub Actions
- ✅ No complex setup needed
- ✅ Works with forked repositories
- ✅ Automatically posts comments
- ✅ Easy to customize rules
Solution:
- Go to Actions tab
- Check if workflow shows green ✅ (passed)
- If red ❌, click it to see the error
- Look for error in the "Run Danger" step
Common issues:
- Missing
dangerfile.jsfile - Wrong file location (must be root)
- YAML syntax error in workflow
Solution:
- Check file names exactly match
- Verify
dangerfile.jsis in root directory - Check workflow file has correct YAML
Check:
- Is your title exactly like:
added feature? - Does it have any of:
feat:,fix:,test:,chore:? - If no - Danger should warn!
If still not warning, edit dangerfile.js and add:
message(`DEBUG: Title is: "${title}"`);This will show what Danger sees.
- Create more test PRs with different scenarios
- Edit dangerfile.js to add more rules
- Share this setup with a friend
- Apply to your own projects using this as a template
- Danger JS Docs: https://danger.systems/js/
- GitHub Actions: https://docs.github.com/actions
- Android Development: https://developer.android.com/
You successfully set up professional automated code review for Android!
This is real technology used by:
- Microsoft
- Millions of developers worldwide
Congratulations! 🎉
You now understand and use CI/CD automation that keeps code quality high and catches issues before they become problems.
.github/workflows/danger.yml- Automation workflowdangerfile.js- Review rules
- Workflow: Runs Danger automatically on every PR
- Dangerfile: Defines what to check
- Make changes → Push branch
- Create PR
- GitHub Actions runs automatically
- Danger reviews and leaves comments
- Fix based on feedback
That's it! Simple but powerful. 🚀