-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(auto_assign): Add GitHub Actions workflow for auto-assigning PR …
…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
1 parent
8771724
commit 28aa922
Showing
5 changed files
with
324 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |