Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes entry 1 #4

Merged
merged 28 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -5,11 +5,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 @@ -19,14 +23,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"]
}
]
Loading