Skip to content

Commit

Permalink
Merge pull request #4 from github-tooling/changes-entry-1
Browse files Browse the repository at this point in the history
Changes entry 1
  • Loading branch information
andriyor authored Apr 9, 2024
2 parents a5ac7e1 + 312ed2b commit ad48ffa
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 12 deletions.
24 changes: 24 additions & 0 deletions .github/scripts/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const fs = require('fs');
const { execSync } = require('child_process')

const tsGraph = require('@andriyorehov/ts-graph');


module.exports = async ({ github, context }) => {
const { commits } = context.payload.pull_request

const rawFiles = execSync(`git diff --name-only HEAD HEAD~${commits}`).toString()
const changedFiles = rawFiles.split('\n').filter(Boolean)

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}`)
}
}
}
};
17 changes: 11 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ on:
branches:
- main


jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- uses: pnpm/action-setup@v2
with:
version: 8
Expand All @@ -20,14 +24,15 @@ jobs:
cache: 'pnpm'
- name: Install modules
run: pnpm install
- name: Check for automated commit
run: echo $(git diff-tree --no-commit-id --name-only -r HEAD)
- name: Check changed files
uses: actions/github-script@v6
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
PR_NUMBER: ${{ github.event.number }}
with:
script: |
const { execSync } = require('child_process')
const { commits } = context.payload.pull_request
console.log(commits)
const rawFiles = execSync(`git diff --name-only HEAD HEAD~${commits}`).toString()
const files = rawFiles.split('\n').filter(Boolean)
const script = require('.github/scripts/main.js')
script({github, context})
console.log(files)
6 changes: 3 additions & 3 deletions main.ts → main.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import fs from 'fs';
const fs = require('fs');

import { getTreeByFile } from '@andriyorehov/ts-graph';
const tsGraph = require('@andriyorehov/ts-graph');

const owners = fs.readFileSync('owners.json', 'utf8');
const ownersObj = JSON.parse(owners);

for (const owner of ownersObj) {
for (const entries of owner.owns) {
console.log(entries);
console.log(Object.keys(getTreeByFile(entries).flatTree));
console.log(Object.keys(tsGraph.getTreeByFile(entries).flatTree));
}
}
2 changes: 1 addition & 1 deletion main/entry1/nested.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const nested = 'nested';
export const nested = 'nested-new-';
4 changes: 2 additions & 2 deletions owners.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[
{
"team": "entry1",
"team": "github-tooling/entry1",
"owns": ["main/entry1/main.ts"]
},
{
"team": "entry2",
"team": "github-tooling/entry2",
"owns": ["main/entry2/main.ts"]
}
]

0 comments on commit ad48ffa

Please sign in to comment.