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

feat: add core feature alert gh action #8948

Merged
merged 4 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
65 changes: 65 additions & 0 deletions .github/workflows/core-feature-alert.yml
Original file line number Diff line number Diff line change
@@ -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.`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class ClientFeatureToggleService {
query || {},
);

console.log('ALTERING CLIENT FEATURES');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be removed before merge. Used to trigger the action.

return result.map(
({
name,
Expand Down
Loading