Skip to content

Commit

Permalink
feat(auto_assign): Add GitHub Actions workflow for auto-assigning PR …
Browse files Browse the repository at this point in the history
…creators (#102)

* feat(auto_assign): add GitHub Actions workflow for auto-assigning PR creators

* fix(auto_assign): improve error handling in auto-assign workflow for PR creators

- Removed unnecessary permissions for issues.
- Added try-catch block to handle errors when assigning PR creators, with logging for success and failure cases.

* refactor(auto_assign):  implement auto-assign

* refactor(auto_assign): streamline token retrieval and context handling

* chore(auto_assign) : update guthub actions workflow to use latest actions

* chore(auto_assign) : use pnpm and fix indent

* chore(vscode): add GitHub Actions extension to recommendations
  • Loading branch information
developerjhp authored Feb 10, 2025
1 parent 8771724 commit 28aa922
Show file tree
Hide file tree
Showing 5 changed files with 324 additions and 1 deletion.
32 changes: 32 additions & 0 deletions .github/workflows/auto-assign/auto_assign.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/no-require-imports */
const github = require('@actions/github');

async function getOctokitAndContext() {
const token = process.env.GITHUB_TOKEN;
if (!token) throw new Error('GITHUB_TOKEN is not provided');
return { octokit: github.getOctokit(token), context: github.context };
}

async function run() {
try {
const { octokit, context } = await getOctokitAndContext();
const { pull_request: pr, repository } = context.payload;

if (!pr) throw new Error('This action only runs on pull request events.');

await octokit.rest.issues.addAssignees({
owner: repository.owner.login,
repo: repository.name,
issue_number: pr.number,
assignees: [pr.user.login],
});

console.log(`Successfully assigned ${pr.user.login} to PR #${pr.number}`);
} catch (error) {
console.error('Failed to assign PR creator:', error.message);
process.exit(1);
}
}

run();
235 changes: 235 additions & 0 deletions .github/workflows/auto-assign/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .github/workflows/auto-assign/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "auto-assign",
"version": "1.0.0",
"description": "",
"main": "auto_assign.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@actions/github": "^6.0.0"
}
}
37 changes: 37 additions & 0 deletions .github/workflows/auto_assign.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Auto Assign PR Creator

on:
pull_request:
types: [opened]

permissions:
pull-requests: write
contents: read

jobs:
auto-assign:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v4
with:
cache: pnpm
node-version-file: .nvmrc

- name: Install dependencies for auto-assign
run: |
cd .github/workflows/auto-assign
pnpm install --frozen-lockfile
- name: Run Auto Assign Script
run: node auto_assign.js
working-directory: .github/workflows/auto-assign
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 5 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"recommendations": ["biomejs.biome", "dbaeumer.vscode-eslint"]
"recommendations": [
"biomejs.biome",
"dbaeumer.vscode-eslint",
"github.vscode-github-actions"
]
}

0 comments on commit 28aa922

Please sign in to comment.