Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workflow to Automatically Title Case PRs #468

Merged
merged 3 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/prtitlecase.yml
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
2 changes: 2 additions & 0 deletions Tools/changelogs/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"name": "changelogs",
"author": "DEATHB4DEFEAT",
"license": "MIT",
"dependencies": {
"axios": "^1.3.4",
"js-yaml": "^4.1.0"
Expand Down
19 changes: 19 additions & 0 deletions Tools/prtitlecase/index.js
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 });
12 changes: 12 additions & 0 deletions Tools/prtitlecase/package.json
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"
}
}
Loading