From 312ed2b6964ffcb5fffa3c8bdb807c8579392af6 Mon Sep 17 00:00:00 2001 From: Andrii Oriekhov Date: Wed, 10 Apr 2024 01:21:55 +0300 Subject: [PATCH] change action --- .github/scripts/main.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/.github/scripts/main.js b/.github/scripts/main.js index 2305e4b..ebbd55d 100644 --- a/.github/scripts/main.js +++ b/.github/scripts/main.js @@ -3,19 +3,22 @@ const { execSync } = require('child_process') const tsGraph = require('@andriyorehov/ts-graph'); -const { commits } = context.payload.pull_request -const rawFiles = execSync(`git diff --name-only HEAD HEAD~${commits}`).toString() -const changedFiles = rawFiles.split('\n').filter(Boolean) +module.exports = async ({ github, context }) => { + const { commits } = context.payload.pull_request -const owners = fs.readFileSync('owners.json', 'utf8'); -const ownersObj = JSON.parse(owners); + const rawFiles = execSync(`git diff --name-only HEAD HEAD~${commits}`).toString() + const changedFiles = rawFiles.split('\n').filter(Boolean) -for (const owner of ownersObj) { - for (const entries of owner.owns) { - const paths = Object.keys(tsGraph.getTreeByFile(entries).flatTree); - if (changedFiles.some(file => paths.includes(file))) { - execSync(`gh pr edit ${process.env.PR_NUMBER} --add-reviewer ${owner.team}`) + const owners = fs.readFileSync('owners.json', 'utf8'); + const ownersObj = JSON.parse(owners); + + for (const owner of ownersObj) { + for (const entries of owner.owns) { + const paths = Object.keys(tsGraph.getTreeByFile(entries).flatTree); + if (changedFiles.some(file => paths.includes(file))) { + execSync(`gh pr edit ${process.env.PR_NUMBER} --add-reviewer ${owner.team}`) + } } } -} +};