mirror of
https://github.com/documenso/documenso.git
synced 2025-11-10 04:22:32 +10:00
feat: added pr count workflow
Signed-off-by: Adithya Krishna <adi@documenso.com>
This commit is contained in:
69
.github/workflows/pr-count.yml
vendored
Normal file
69
.github/workflows/pr-count.yml
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
# Triggered with '/pr-count @username'
|
||||
name: "PR Count"
|
||||
|
||||
on:
|
||||
issue_comment:
|
||||
types: [created]
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
|
||||
jobs:
|
||||
countPRs:
|
||||
if: ${{ github.event.issue.pull_request }}
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
MY_ENV_VARIABLE: ${{ secrets.GITHUB_TOKEN }}
|
||||
steps:
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '18'
|
||||
|
||||
- name: Install Octokit
|
||||
run: npm install @octokit/rest@18
|
||||
|
||||
- name: Parse comment and count PRs
|
||||
id: parse-comment
|
||||
uses: actions/github-script@v5
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
const { Octokit } = require("@octokit/rest");
|
||||
const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });
|
||||
|
||||
const comment = context.payload.comment.body.trim();
|
||||
const regex = /^\/pr-count @(\S+)/;
|
||||
const match = comment.match(regex);
|
||||
|
||||
if (match) {
|
||||
const username = match[1];
|
||||
console.log(`Username extracted: ${username}`);
|
||||
|
||||
const { data: pullRequests } = await octokit.pulls.list({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
creator: username,
|
||||
state: 'open'
|
||||
});
|
||||
|
||||
const prCount = pullRequests.length;
|
||||
console.log(`PR count for ${username}: ${prCount}`);
|
||||
|
||||
const issueCommentId = context.payload.comment.id;
|
||||
console.log(`Issue comment ID: ${issueCommentId}`);
|
||||
|
||||
const prCountMessage = `@${username} has ${prCount} open pull requests created.`;
|
||||
|
||||
await octokit.request('POST /repos/{owner}/{repo}/issues/{issue_number}/comments', {
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: context.issue.number,
|
||||
body: prCountMessage,
|
||||
headers: {
|
||||
'Authorization': `token ${{ secrets.GITHUB_TOKEN }}`,
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.log('No valid username found in the comment');
|
||||
}
|
||||
Reference in New Issue
Block a user