Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 133 additions & 0 deletions .github/workflows/code-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
name: AI Code Review
on:
pull_request:
types: [opened, synchronize, ready_for_review]
push:
branches: [main]

concurrency:
group: review-${{ github.ref }}
cancel-in-progress: true

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

env:
ZAI_BASE_URL: "https://api.z.ai/api/coding/paas/v4/"

jobs:
secret-scan:
name: "🔒 Secret Scan"
runs-on: ubuntu-latest
outputs:
secrets_found: ${{ steps.scan.outputs.found }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Scan diff for secrets
id: scan
uses: sulthonzh/code-reviewer@main
with:
command: secret-scan
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Block if secrets found
if: steps.scan.outputs.found == 'true'
run: |
echo "::error::Found potential secret(s) in the diff. Remove before merging."
exit 1

ai-review:
name: "🤖 AI Review"
runs-on: ubuntu-latest
needs: secret-scan
outputs:
approved: ${{ steps.review.outputs.approved }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Detect project context
id: context
uses: sulthonzh/code-reviewer@main
with:
command: detect-context
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Route model
id: model
run: |
DIFF_LINES=$(git diff origin/main...HEAD 2>/dev/null | wc -l || echo 0)
if [ "$DIFF_LINES" -gt 500 ]; then
echo "model=glm-5.1" >> "$GITHUB_OUTPUT"
else
echo "model=glm-4.5" >> "$GITHUB_OUTPUT"
fi
- name: Run AI review
id: review
uses: sulthonzh/code-reviewer@main
with:
command: ai-review
model: ${{ steps.model.outputs.model }}
project-type: ${{ steps.context.outputs.project_type }}
zai-api-key: ${{ secrets.ZAI_API_KEY }}
zai-base-url: ${{ env.ZAI_BASE_URL }}
github-token: ${{ secrets.GITHUB_TOKEN }}

quality-gate:
name: "✅ Quality Gate"
runs-on: ubuntu-latest
needs: [secret-scan, ai-review]
outputs:
passed: ${{ steps.gate.outputs.passed }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run quality checks
id: gate
uses: sulthonzh/code-reviewer@main
with:
command: quality-gate
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Post status
if: always()
uses: sulthonzh/code-reviewer@main
with:
command: post-status
passed: ${{ steps.gate.outputs.passed }}
github-token: ${{ secrets.GITHUB_TOKEN }}

auto-merge:
name: "🔀 Auto-Merge"
runs-on: ubuntu-latest
needs: [ai-review, quality-gate]
if: >-
needs.ai-review.outputs.approved == 'true' &&
needs.quality-gate.outputs.passed == 'true' &&
github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v4
- name: Approve and merge
uses: sulthonzh/code-reviewer@main
with:
command: auto-merge
github-token: ${{ secrets.GITHUB_TOKEN }}

auto-release:
name: "📦 Auto-Release"
runs-on: ubuntu-latest
if: >-
github.event_name == 'push' &&
github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Detect and release
uses: sulthonzh/code-reviewer@main
with:
command: auto-release
github-token: ${{ secrets.GITHUB_TOKEN }}
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ When `git merge` fails, developers face pain points:
- ✅ Open each file in your preferred `$EDITOR`
- ✅ Validate conflict markers are resolved before continuing
- ✅ Cross-platform (macOS, Linux, Windows)
- ✅ Continue/abort functionality
- ✅ Abort merge functionality
- ✅ Auto-stage resolved files (`--stage`)
- ✅ JSON output for scripting/CI (`--json`)
- ✅ Zero configuration required

## Installation
Expand Down Expand Up @@ -79,6 +81,22 @@ Run "git commit" to complete the merge.
git-conflicts --abort
```

### Auto-stage resolved files

```bash
git-conflicts --stage
```

With `--stage`, each file is automatically `git add`ed after conflict markers are resolved.

### JSON output (for scripting/CI)

```bash
git-conflicts --status --json
```

Returns structured JSON with conflict info, useful for CI pipelines or scripting.

## Configuration

`git-conflicts` respects your environment variables:
Expand All @@ -94,7 +112,7 @@ If neither is set, it defaults to:

1. Detects merge conflicts using `git diff --name-only --diff-filter=U`
2. Opens each conflicted file in your configured editor
3. Validates that conflict markers (`<<<<<<<`) are removed
3. Validates that all conflict markers (`<<<<<<<`, `=======`, `>>>>>>>`, `|||||||`) are removed
4. Tracks progress and shows summary
5. Prompts you to run `git commit` when done

Expand Down
5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ module.exports = {
coverageReporters: ['text', 'lcov'],
moduleFileExtensions: ['ts', 'js', 'json'],
verbose: true,
transform: {
'^.+\\.ts$': ['ts-jest', {
tsconfig: 'tsconfig.test.json',
}],
},
};
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ program
.option('-s, --status', 'Show conflict status only')
.option('--stage', 'Auto-stage resolved files with git add')
.option('-j, --json', 'Output in JSON format (for scripting/CI)')
.option('--cwd <path>', 'Path to git repository (defaults to current directory)')
.action(async (options) => {
const gitOps = new GitOperations();
const resolver = new ConflictResolver();
const gitOps = new GitOperations(options.cwd);
const resolver = new ConflictResolver(gitOps);

try {
// Handle abort
Expand Down
29 changes: 29 additions & 0 deletions src/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@ describe('GitOperations', () => {
expect(gitOps.hasConflictMarkers(cleanContent)).toBe(false);
});

it('should not false-positive on marker text inside strings', () => {
// A string literal or comment containing <<<<<<< should not be flagged
const contentWithString = 'const msg = "use <<<<<<< to mark conflicts";';
expect(gitOps.hasConflictMarkers(contentWithString)).toBe(false);
});

it('should detect diff3 conflict markers (|||||||)', () => {
const diff3Content = '||||||| merged common ancestors\nbase\n=======\nours\n>>>>>>> feature';
expect(gitOps.hasConflictMarkers(diff3Content)).toBe(true);
});

it('should detect remaining ======= and >>>>>>> markers', () => {
// User deleted <<<<<<< but left other markers
const partialMarkers = 'some code\n=======\ntheir code\n>>>>>>> feature\nend';
expect(gitOps.hasConflictMarkers(partialMarkers)).toBe(true);
});

it('should count conflict markers correctly', () => {
const singleConflict = 'some code\n<<<<<<< HEAD\nmy code\n=======\ntheir code\n>>>>>>> feature\nend';
expect(gitOps.countConflicts(singleConflict)).toBe(1);
Expand All @@ -85,6 +102,11 @@ describe('GitOperations', () => {
const cleanContent = 'no conflicts here';
expect(gitOps.countConflicts(cleanContent)).toBe(0);
});

it('should count bare <<<<<<< lines without branch name', () => {
const bareMarker = 'some code\n<<<<<<<\nmy code\n=======\ntheir code\n>>>>>>> feature';
expect(gitOps.countConflicts(bareMarker)).toBe(1);
});
});

describe('ConflictResolver', () => {
Expand All @@ -94,6 +116,13 @@ describe('ConflictResolver', () => {
resolver = new ConflictResolver();
});

it('should accept a GitOperations instance', () => {
const customGitOps = new GitOperations('/some/path');
const customResolver = new ConflictResolver(customGitOps);
// Should not throw
expect(customResolver).toBeInstanceOf(ConflictResolver);
});

it('should validate clean file content', async () => {
const cleanContent = 'const x = 1;';
(fs.readFile as jest.Mock).mockResolvedValue(cleanContent);
Expand Down
Loading
Loading