Skip to content

Commit

Permalink
diff script
Browse files Browse the repository at this point in the history
  • Loading branch information
fraxy-v committed Sep 1, 2024
1 parent ca612ba commit 7edc3a1
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions scripts/diff.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const { execSync } = require('child_process');
const { parse } = require('path');
const output = execSync(`git diff origin/master`).toString().split('\n')

let count = 0;
let start = 0;
let current = 0;
let sources = [];
for (let i = 0; i < output.length; i++) {
if (output[i].startsWith('diff --git')) {
// skip 'diff --git a/' prefix
const file = output[i].split(' ')[2].substring(2);
sources.push({'file': file, 'lines': []});
// go to header line, e.g. '@@ -1,2 +1,3 @@'
do {
++i;
}
while (!output[i].startsWith('@@'));
output[i].split(' ').forEach((c) => {
if (c.startsWith('+')) {
[start, count] = c.split(',');
start = parseInt(start);
count = parseInt(count);
current = 0;
}
});
}
else if (current < count && !output[i].startsWith('-')) {
if (output[i].startsWith('+')) {
sources[sources.length - 1].lines.push(start + current);
}
++current;
}
}

module.exports = ({github, context}) => {
return context.payload.client_payload.value
}

0 comments on commit 7edc3a1

Please sign in to comment.