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

85 lines
2.9 KiB
YAML
Raw Normal View History

2024-12-09 15:17:15 +01:00
name: Core Feature Alert
on:
pull_request:
2024-12-09 15:38:42 +01:00
types:
- opened
- synchronize
2024-12-09 15:17:15 +01:00
paths:
2024-12-09 15:28:43 +01:00
- src/lib/features/client-feature-toggles/*
- src/lib/features/frontend-api/*
2024-12-09 15:49:10 +01:00
2024-12-09 15:17:15 +01:00
jobs:
2024-12-09 15:38:42 +01:00
check-core-feature:
2024-12-09 15:17:15 +01:00
runs-on: ubuntu-latest
steps:
2024-12-09 15:38:42 +01:00
- name: Checkout the repository
uses: actions/checkout@v3
2024-12-09 15:17:15 +01:00
2024-12-09 15:38:42 +01:00
- name: Fetch PR details
id: pr-details
run: |
echo "PR_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_ENV
echo "PR_CREATOR=${{ github.event.pull_request.user.login }}" >> $GITHUB_ENV
- name: Check if reviewers or comment already exist
id: check-comment
2024-12-09 15:17:15 +01:00
uses: actions/github-script@v6
with:
script: |
2024-12-09 15:38:42 +01:00
const prNumber = context.payload.pull_request.number;
2024-12-09 15:44:44 +01:00
// Check if a comment already exists
2024-12-09 15:38:42 +01:00
const comments = await github.rest.issues.listComments({
2024-12-09 15:17:15 +01:00
owner: context.repo.owner,
repo: context.repo.repo,
2024-12-09 15:38:42 +01:00
issue_number: prNumber,
});
const hasComment = comments.data.some(comment =>
comment.body.includes("Core features have been modified")
);
// Check if reviewers are already assigned
const reviewers = await github.rest.pulls.listRequestedReviewers({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
});
const hasReviewers = reviewers.data.users.length > 0;
2024-12-09 15:44:44 +01:00
core.setOutput('hasComment', hasComment);
core.setOutput('hasReviewers', hasReviewers);
2024-12-09 15:38:42 +01:00
- name: Add reviewers and comment if necessary
2024-12-09 15:44:44 +01:00
if: steps.check-comment.outputs.hasComment == 'false' || steps.check-comment.outputs.hasReviewers == 'false'
2024-12-09 15:32:10 +01:00
uses: actions/github-script@v6
with:
script: |
2024-12-09 15:38:42 +01:00
const prNumber = context.payload.pull_request.number;
const prCreator = context.payload.pull_request.user.login;
2024-12-09 15:48:20 +01:00
// Add a comment if not already present
2024-12-09 15:44:44 +01:00
if (!${{ steps.check-comment.outputs.hasComment }}) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: `@${prCreator}, core features have been modified in this pull request. Reviewers have been added.`,
});
}
2024-12-09 15:38:42 +01:00
2024-12-09 15:48:20 +01:00
// Add reviewers if not already present
2024-12-09 15:44:44 +01:00
if (!${{ steps.check-comment.outputs.hasReviewers }}) {
2024-12-09 15:38:42 +01:00
await github.rest.pulls.requestReviewers({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
2024-12-09 15:44:44 +01:00
reviewers: ['FredrikOseberg'], // Do not include @ in reviewer names
2024-12-09 15:38:42 +01:00
});
2024-12-09 15:44:44 +01:00
}
2024-12-09 15:48:20 +01:00
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}