From 1eb7ce7d6851a55b7032d9bc73a0e2e4969b2f15 Mon Sep 17 00:00:00 2001 From: DEATHB4DEFEAT Date: Sun, 16 Jun 2024 13:49:46 -0700 Subject: [PATCH 1/2] title case workflow --- .github/workflows/prtitlecase.yml | 34 +++++++++++++++++++++++++++++++ Tools/changelog/package.json | 2 ++ Tools/prtitlecase/index.js | 19 +++++++++++++++++ Tools/prtitlecase/package.json | 12 +++++++++++ 4 files changed, 67 insertions(+) create mode 100644 .github/workflows/prtitlecase.yml create mode 100644 Tools/prtitlecase/index.js create mode 100644 Tools/prtitlecase/package.json diff --git a/.github/workflows/prtitlecase.yml b/.github/workflows/prtitlecase.yml new file mode 100644 index 00000000000..0c5a38a4e8a --- /dev/null +++ b/.github/workflows/prtitlecase.yml @@ -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 diff --git a/Tools/changelog/package.json b/Tools/changelog/package.json index 512a3624c87..1f0899df96c 100644 --- a/Tools/changelog/package.json +++ b/Tools/changelog/package.json @@ -1,5 +1,7 @@ { "name": "changelogs", + "author": "DEATHB4DEFEAT", + "license": "MIT", "dependencies": { "axios": "^1.3.4", "js-yaml": "^4.1.0" diff --git a/Tools/prtitlecase/index.js b/Tools/prtitlecase/index.js new file mode 100644 index 00000000000..0d72b711312 --- /dev/null +++ b/Tools/prtitlecase/index.js @@ -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 }); diff --git a/Tools/prtitlecase/package.json b/Tools/prtitlecase/package.json new file mode 100644 index 00000000000..0b14e5cc3d0 --- /dev/null +++ b/Tools/prtitlecase/package.json @@ -0,0 +1,12 @@ +{ + "name": "prtitlecase", + "description": "Converts PR titles to Title Case using title-case package", + "type": "module", + "exports": "./src/index.js", + "author": "DEATHB4DEFEAT", + "license": "MIT", + "dependencies": { + "axios": "^1.7.2", + "title-case": "^4.3.1" + } +} From 3824c9b39a7fc4b9a25b1ad4993eb03306c9c40f Mon Sep 17 00:00:00 2001 From: DEATHB4DEFEAT <77995199+DEATHB4DEFEAT@users.noreply.github.com> Date: Mon, 17 Jun 2024 01:09:47 -0700 Subject: [PATCH 2/2] Update Tools/prtitlecase/package.json Signed-off-by: DEATHB4DEFEAT <77995199+DEATHB4DEFEAT@users.noreply.github.com> --- Tools/prtitlecase/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tools/prtitlecase/package.json b/Tools/prtitlecase/package.json index 0b14e5cc3d0..ecba01099fe 100644 --- a/Tools/prtitlecase/package.json +++ b/Tools/prtitlecase/package.json @@ -2,7 +2,7 @@ "name": "prtitlecase", "description": "Converts PR titles to Title Case using title-case package", "type": "module", - "exports": "./src/index.js", + "exports": "./index.js", "author": "DEATHB4DEFEAT", "license": "MIT", "dependencies": {