Skip to content

feat: git diff extraction and code refactor #20

feat: git diff extraction and code refactor

feat: git diff extraction and code refactor #20

Workflow file for this run

name: Impactifier CI
on:
push:
branches: [main]
pull_request:
branches: [main]
permissions:
contents: read
issues: write
pull-requests: write
jobs:
impactifier:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cache Cargo Registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- name: Cache Cargo Build
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-build-
- name: Build Impactifier
run: |
cargo build --release --manifest-path Cargo.toml
- name: Run Impactifier
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
./target/release/impactifier --tracing-level=0 --from-branch=main --to-branch=refactor
- name: Post Comment on Pull Request
if: github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const path = 'diff.json'; // Path to the diff JSON file
// Check if the diff file exists
if (!fs.existsSync(path)) {
console.log('No diff.json file found.');
return;
}
// Read and parse the diff JSON
const rawData = fs.readFileSync(path, 'utf8');
let diffData;
try {
diffData = JSON.parse(rawData);
} catch (error) {
console.error('Failed to parse diff.json:', error);
return;
}
// Format the diff for the comment
let formattedDiff = '';
if (diffData.deltas && Array.isArray(diffData.deltas)) {
diffData.deltas.forEach(delta => {
if (delta.value) {
formattedDiff += `${delta.value}\n`;
}
});
} else {
formattedDiff = 'No differences found.';
}
// Create the comment body with the diff in a Markdown code block
const commentBody = `## Impactifier Report
```diff ${formattedDiff} ````;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});