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

Issue PR reminder workflow created #1

Merged
merged 1 commit into from
Feb 17, 2025
Merged
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
101 changes: 101 additions & 0 deletions .github/workflows/issue-pr-reminder.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Issue PR Reminder

on:
schedule:
- cron: '0 * * * *' # Runs every hour, at the start of each hour
workflow_dispatch:

jobs:
issue-reminder:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
env:
INTERVAL_HOURS: ${{ vars.CREATE_REMINDER_AFTER_HOURS }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const owner = "keyshade-xyz";
const repo = "keyshade";
const createReminderAfterHours = process.env.CREATE_REMINDER_AFTER_HOURS || 48;
const now = Date.now();

async function listOpenIssuesWithoutPR() {
const allIssues = [];
let page = 1;
let hasNextPage = true;

while (hasNextPage) {
const issuesResponse = await github.rest.issues.listForRepo({
owner,
repo,
state: "open",
per_page: 100,
page
});

const issuesWithoutPR = issuesResponse.data.filter(issue => !issue.pull_request);

allIssues.push(...issuesWithoutPR);

hasNextPage = issues.headers.link && issues.headers.link.includes('rel="next"');
page++;
}

return allIssues;
}

async function listIssueComments(issue) {
const allComments = [];
let page = 1;
let hasNextPage = true;

while (hasNextPage) {
const issuesResponse = await github.rest.issues.listComments({
owner,
repo,
issue_number: issue.number,
per_page: 100,
page
});

allComments.push(...issuesResponse.data);

hasNextPage = issues.headers.link && issues.headers.link.includes('rel="next"');
page++;
}

return allIssues;
}

const issues = await listOpenIssuesWithoutPR();

issues.forEach(issue => {
const issueCreatedAt = new Date(issue.created_at);
const createReminderAfter = issueCreatedAt.setHours(issueCreatedAt.getHours() + createReminderAfterHours);

// Check if it's time to create the reminder
if(now < createReminderAfter) {
return;
}

// Create reminder for each assignee
const comments = await listIssueComments(issue);

issue.assignees.forEach(assignee => {
const reminder = `@${assignee.login}, please open a draft PR linking this issue!`;

// Check if the issue already has the reminder
if(comments.some(comment => comment.body === reminder)) {
return;
}

// Create the reminder
await github.rest.issues.createComment({
owner,
repo,
issue_number: issue.number,
body: reminder
});
});
});
Loading