-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Workflow to Automatically Title Case PRs (#468)
# Description Hooray, more JavaScript! I tested this on a personal repo with a new PAT, but it *should* work here first try. --------- Signed-off-by: DEATHB4DEFEAT <[email protected]>
- Loading branch information
1 parent
2bf744d
commit 5a379f2
Showing
4 changed files
with
67 additions
and
0 deletions.
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,34 @@ | ||
name: PR Title Case | ||
on: | ||
pull_request_target: | ||
types: [opened, edited, synchronize] | ||
|
||
env: | ||
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }} | ||
PR_NUMBER: ${{ github.event.pull_request.number }} | ||
|
||
jobs: | ||
prtitlecase: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Master | ||
uses: actions/checkout@v3 | ||
with: | ||
token: ${{ secrets.BOT_TOKEN }} | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.x | ||
|
||
- name: Install Dependencies | ||
run: | | ||
cd "Tools/prtitlecase" | ||
npm install | ||
shell: bash | ||
|
||
- name: Change Title | ||
run: | | ||
cd "Tools/prtitlecase" | ||
node src/index.js | ||
shell: bash |
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
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,19 @@ | ||
import axios from 'axios'; | ||
import { titleCase } from 'title-case'; | ||
|
||
if (process.env.GITHUB_TOKEN) axios.defaults.headers.common['Authorization'] = `token ${process.env.GITHUB_TOKEN}`; | ||
else throw new Error('BOT_TOKEN was not provided in repository secrets or GITHUB_TOKEN was not set correctly.'); | ||
|
||
|
||
// Get PR title | ||
let prTitle = await axios.get(`https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pulls/${process.env.PR_NUMBER}`) | ||
.then(res => res.data.title); | ||
|
||
// Title case PR title | ||
console.log(`Old PR title: ${prTitle}`); | ||
prTitle = titleCase(prTitle); | ||
console.log(`New PR title: ${prTitle}`); | ||
|
||
// Update PR title | ||
await axios.patch(`https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pulls/${process.env.PR_NUMBER}`, | ||
{ title: prTitle }); |
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,12 @@ | ||
{ | ||
"name": "prtitlecase", | ||
"description": "Converts PR titles to Title Case using title-case package", | ||
"type": "module", | ||
"exports": "./index.js", | ||
"author": "DEATHB4DEFEAT", | ||
"license": "MIT", | ||
"dependencies": { | ||
"axios": "^1.7.2", | ||
"title-case": "^4.3.1" | ||
} | ||
} |