Skip to content

feat: AI-Powered PDF Chatbot #191

feat: AI-Powered PDF Chatbot

feat: AI-Powered PDF Chatbot #191

Workflow file for this run

name: PR Auto Comment & Label
on:
pull_request_target:
types: [opened, closed]
jobs:
pr_feedback:
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
pull-requests: write
steps:
- name: Add comment and labels when PR is opened
if: github.event.action == 'opened'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const prNumber = context.payload.pull_request.number;
const prBody = context.payload.pull_request.body || '';
const prAuthor = context.payload.pull_request.user.login;
// Extract issue numbers from PR body (supports #123, fixes #123, closes #123, resolves #123, etc.)
const issuePattern = /(close[sd]?|fix(e[sd])?|resolve[sd]?)\s*#(\d+)|#(\d+)/gi;
const matches = [...prBody.matchAll(issuePattern)];
const issueNumbers = [...new Set(matches.map(m => m[3] || m[4]).filter(Boolean))];
let allLabels = new Set(['awaiting review', 'nsoc26']);
let linkedIssuesInfo = [];
// Fetch labels from each linked issue
for (const issueNumber of issueNumbers) {
try {
const issue = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: parseInt(issueNumber)
});
const issueLabels = issue.data.labels.map(label =>
typeof label === 'string' ? label : label.name
);
linkedIssuesInfo.push({
number: issueNumber,
title: issue.data.title
});
// Add issue labels to PR
issueLabels.forEach(label => allLabels.add(label));
} catch (error) {
console.log(`Could not fetch issue #${issueNumber}: ${error.message}`);
}
}
// Apply all collected labels to PR
if (allLabels.size > 0) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
labels: Array.from(allLabels)
});
}
// Assign mugenkyou as reviewer (only if they're not the PR author)
if (prAuthor !== 'mugenkyou') {
try {
await github.rest.pulls.requestReviewers({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
reviewers: ['mugenkyou']
});
} catch (error) {
console.log(`Could not assign reviewer mugenkyou: ${error.message}`);
}
}
// Create professional comment
let commentBody = `## 📥 Pull Request Received\n\n`;
commentBody += `Thank you for your contribution to **College Daddy**. Your pull request has been received and is currently under review.\n\n`;
if (linkedIssuesInfo.length > 0) {
commentBody += `### 🔗 Linked Issues\n\n`;
for (const issue of linkedIssuesInfo) {
commentBody += `- **#${issue.number}**: ${issue.title}\n`;
}
commentBody += `\n`;
}
commentBody += `### ✅ Pre-Merge Checklist\n\n`;
commentBody += `Please ensure the following requirements are met:\n\n`;
commentBody += `- [ ] Changes adhere to contribution guidelines\n`;
commentBody += `- [ ] Related issues are referenced in description\n`;
commentBody += `- [ ] All changes tested and verified locally\n`;
commentBody += `- [ ] Code follows project standards\n\n`;
if (prAuthor !== 'mugenkyou') {
commentBody += `### 👤 Reviewer Assigned\n\n`;
commentBody += `@mugenkyou has been assigned to review this pull request.\n\n`;
}
commentBody += `---\n\n`;
commentBody += `Our team will review your submission shortly. We appreciate your effort in improving the platform for students.`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: commentBody
});
- name: Add thank-you comment when merged
if: github.event.action == 'closed' && github.event.pull_request.merged == true
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const prNumber = context.payload.pull_request.number;
const contributor = context.payload.pull_request.user.login;
const commentBody = `## 🎉 Pull Request Merged Successfully\n\n` +
`**Contributor**: @${contributor}\n\n` +
`Your pull request has been successfully merged into the main codebase. ` +
`Thank you for your valuable contribution to **College Daddy**.\n\n` +
`### 🚀 Next Steps\n\n` +
`We encourage you to:\n\n` +
`- ⭐ Star the repository to support the project\n` +
`- 👀 Watch for updates and participate in discussions\n` +
`- 🔄 Continue contributing to enhance the platform\n\n` +
`---\n\n` +
`We value your commitment to improving educational technology and look forward to your continued involvement.`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: commentBody
});
- name: Update labels when merged
if: github.event.action == 'closed' && github.event.pull_request.merged == true
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const prNumber = context.payload.pull_request.number;
// Remove 'awaiting review' label
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
name: 'awaiting review'
});
} catch (error) {
console.log(`Label 'awaiting review' not found or already removed`);
}