From 7edc3a171abcb3dd0a044eb0cfa2742def6c03cf Mon Sep 17 00:00:00 2001 From: Fraxy V Date: Sun, 1 Sep 2024 10:53:38 +0300 Subject: [PATCH] diff script --- scripts/diff.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 scripts/diff.js diff --git a/scripts/diff.js b/scripts/diff.js new file mode 100644 index 0000000..dc8eeff --- /dev/null +++ b/scripts/diff.js @@ -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 +}