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

chore: create pr reminder action #993

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Changes from 1 commit
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
51 changes: 51 additions & 0 deletions .github/workflows/pr-reminder.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: PR Review Reminder

on:
schedule:
- cron: '0 9 * * 1-5' # Every weekday at 9:00 AM UTC
pull_request:

Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider removing the pull request trigger.

The workflow is designed as a daily reminder, but it's also triggered on pull request events. This may cause unnecessary runs of the workflow every time a PR is opened, closed, or updated.

Consider removing the pull request trigger:

 on:
   schedule:
     - cron: '0 9 * * 1-5'  # Every weekday at 9:00 AM UTC
-  pull_request:
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
name: PR Review Reminder
on:
schedule:
- cron: '0 9 * * 1-5' # Every weekday at 9:00 AM UTC
pull_request:
name: PR Review Reminder
on:
schedule:
- cron: '0 9 * * 1-5' # Every weekday at 9:00 AM UTC

permissions:
pull-requests: read

jobs:
pr-review:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: List open pull requests using GitHub Script
uses: actions/github-script@v7
id: pr-list
with:
script: |
const { data: pullRequests } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
});
let table = '';
pullRequests.forEach(pr => {
const assignees = pr.assignees.length > 0 ? `Assignees: ${pr.assignees.map(assignee => assignee.login).join(', ')}` : 'No assignees';
table += pr.draft ? '' : `
Title: ${pr.title}
Link: <${pr.html_url}>
Assigness: ${assignees}
`;
});
return table;
Comment on lines +17 to +36
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve assignee formatting for conciseness.

The current implementation for displaying assignees is verbose and may not scale well for PRs with many assignees.

Consider simplifying the assignee display:

-              const assignees = pr.assignees.length > 0 ? `Assignees: ${pr.assignees.map(assignee => assignee.login).join(', ')}` : 'No assignees';
+              const assignees = pr.assignees.length > 0 ? pr.assignees.map(assignee => `@${assignee.login}`).join(', ') : 'Unassigned';
               table += pr.draft ? '' : `
                       Title: ${pr.title}
                       Link: <${pr.html_url}>
-                      Assigness: ${assignees}
+                      Assignees: ${assignees}
                       `;

This change will make the output more concise and easier to read, especially for PRs with multiple assignees.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: List open pull requests using GitHub Script
uses: actions/github-script@v7
id: pr-list
with:
script: |
const { data: pullRequests } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
});
let table = '';
pullRequests.forEach(pr => {
const assignees = pr.assignees.length > 0 ? `Assignees: ${pr.assignees.map(assignee => assignee.login).join(', ')}` : 'No assignees';
table += pr.draft ? '' : `
Title: ${pr.title}
Link: <${pr.html_url}>
Assigness: ${assignees}
`;
});
return table;
- name: List open pull requests using GitHub Script
uses: actions/github-script@v7
id: pr-list
with:
script: |
const { data: pullRequests } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
});
let table = '';
pullRequests.forEach(pr => {
const assignees = pr.assignees.length > 0 ? pr.assignees.map(assignee => `@${assignee.login}`).join(', ') : 'Unassigned';
table += pr.draft ? '' : `
Title: ${pr.title}
Link: <${pr.html_url}>
Assignees: ${assignees}
`;
});
return table;

- name: Send Slack Reminder
if: steps.pr-list.outputs.result != ''
uses: rtCamp/[email protected]
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_CHANNEL: pr-github
SLACK_USERNAME: PR-Reminder
MSG_MINIMAL: true
SLACK_ICON_EMOJI: ":think:"
SLACK_COLOR: good
SLACKIFY_MARKDOWN: true
SLACK_TITLE: Daily Pull Request Review Reminder
SLACK_MESSAGE: |
${{ steps.pr-list.outputs.result }}
Comment on lines +37 to +50
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider using an environment variable for the Slack channel name.

While the Slack notification setup is generally good, the channel name is hardcoded. This might limit flexibility if you need to change the channel in different environments or contexts.

Consider using an environment variable for the Slack channel name:

 env:
   SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
-  SLACK_CHANNEL: pr-github
+  SLACK_CHANNEL: ${{ secrets.SLACK_CHANNEL }}
   SLACK_USERNAME: PR-Reminder

Then, set the SLACK_CHANNEL secret in your repository settings. This change will make it easier to modify the target channel without changing the workflow file.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Send Slack Reminder
if: steps.pr-list.outputs.result != ''
uses: rtCamp/[email protected]
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_CHANNEL: pr-github
SLACK_USERNAME: PR-Reminder
MSG_MINIMAL: true
SLACK_ICON_EMOJI: ":think:"
SLACK_COLOR: good
SLACKIFY_MARKDOWN: true
SLACK_TITLE: Daily Pull Request Review Reminder
SLACK_MESSAGE: |
${{ steps.pr-list.outputs.result }}
- name: Send Slack Reminder
if: steps.pr-list.outputs.result != ''
uses: rtCamp/[email protected]
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_CHANNEL: ${{ secrets.SLACK_CHANNEL }}
SLACK_USERNAME: PR-Reminder
MSG_MINIMAL: true
SLACK_ICON_EMOJI: ":think:"
SLACK_COLOR: good
SLACKIFY_MARKDOWN: true
SLACK_TITLE: Daily Pull Request Review Reminder
SLACK_MESSAGE: |
${{ steps.pr-list.outputs.result }}

Loading