1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

feat: add core feature alert gh action (#8948)

Adds a GH action that notifies us that core features were changed. The
action listens on paths in the source code where our client api and
frontend api are located. If there is a change to these files, we add a
comment to the PR to review carefully and add principals and CTO as
reviewers.
This commit is contained in:
Fredrik Strand Oseberg 2024-12-10 10:09:52 +01:00 committed by GitHub
parent 9de96c8004
commit dfcb196b20
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -0,0 +1,65 @@
name: Core Feature Alert
on:
pull_request:
types:
- opened
- synchronize
paths:
- src/lib/features/client-feature-toggles/*
- src/lib/features/frontend-api/*
jobs:
notify-core-changes:
runs-on: ubuntu-latest
steps:
- name: Fetch PR Creator's Username
id: pr-creator
run: echo "PR_CREATOR=${{ github.event.pull_request.user.login }}" >> $GITHUB_ENV
- name: Post a notification about core feature changes if not already commented
uses: actions/github-script@v6
with:
script: |
const prCreator = process.env.PR_CREATOR;
const commentBody = `@${prCreator}, core features have been modified in this pull request. Please review carefully!`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
});
const alreadyCommented = comments.some(comment => comment.body === commentBody);
if (!alreadyCommented) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: commentBody,
});
console.log('Posted a new comment.');
} else {
console.log('Comment already exists, skipping.');
}
- name: Add reviewers to the PR if they are not the creator
uses: actions/github-script@v6
with:
script: |
const prCreator = process.env.PR_CREATOR;
const allReviewers = ['FredrikOseberg', 'gastonfournier', 'chriswk', 'ivarconr'];
const reviewersToAdd = allReviewers.filter(reviewer => reviewer !== prCreator);
if (reviewersToAdd.length > 0) {
github.rest.pulls.requestReviewers({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
reviewers: reviewersToAdd,
});
console.log(`Added reviewers: ${reviewersToAdd.join(', ')}`);
} else {
console.log(`No reviewers to add as all match the PR creator.`);
}