Skip to content

fix: update repository URLs to correct GitHub username #4

fix: update repository URLs to correct GitHub username

fix: update repository URLs to correct GitHub username #4

name: Complexity Analysis
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
workflow_dispatch:
inputs:
max_complexity:
description: 'Maximum allowed complexity'
required: false
default: '10'
jobs:
complexity-check:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: Install dependencies
run: bun install
- name: Run tests
run: bun test
- name: Analyze complexity
id: complexity
run: |
MAX_COMPLEXITY=${{ github.event.inputs.max_complexity || '15' }}
echo "MAX_COMPLEXITY=$MAX_COMPLEXITY" >> $GITHUB_ENV
# Run analysis and capture output
bun run src/cli.ts analyze src --max-complexity $MAX_COMPLEXITY --format json > complexity-report.json || true
# Also generate human-readable output
bun run src/cli.ts analyze src --max-complexity $MAX_COMPLEXITY > complexity-report.txt || FAILED=true
# Set output for PR comment
if [ "$FAILED" = "true" ]; then
echo "status=failed" >> $GITHUB_OUTPUT
else
echo "status=passed" >> $GITHUB_OUTPUT
fi
- name: Upload complexity report
if: always()
uses: actions/upload-artifact@v4
with:
name: complexity-reports
path: |
complexity-report.json
complexity-report.txt
- name: Comment PR with results
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const report = fs.readFileSync('complexity-report.txt', 'utf8');
// Extract summary information
const lines = report.split('\n');
const summaryStart = lines.findIndex(line => line.includes('Summary'));
const summary = lines.slice(summaryStart).join('\n');
// Find high complexity functions
const highComplexity = lines
.filter(line => line.includes('⚠️'))
.slice(0, 5)
.join('\n');
const status = '${{ steps.complexity.outputs.status }}';
const emoji = status === 'passed' ? '✅' : '⚠️';
const body = `## ${emoji} Complexity Analysis Results
<details>
<summary>View detailed report</summary>
### High Complexity Functions
\`\`\`
${highComplexity || 'None found! 🎉'}
\`\`\`
### Summary
\`\`\`
${summary}
\`\`\`
</details>
**Max allowed complexity:** ${{ env.MAX_COMPLEXITY }}
> 💡 **Tip:** Functions with high cognitive complexity are harder to understand than those with high cyclomatic complexity.
`;
// Find and update or create comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('Complexity Analysis Results')
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});
}
- name: Check complexity results
if: steps.complexity.outputs.status == 'failed'
run: |
echo "⚠️ Some functions exceed maximum complexity of $MAX_COMPLEXITY"
echo "See the artifact for detailed report"
echo "Consider refactoring complex functions in future updates"
# Don't fail the workflow for now - just warn
# exit 1