Skip to content

Commit

Permalink
feat(pr-description-test)
Browse files Browse the repository at this point in the history
  • Loading branch information
yangwooseong committed Sep 23, 2023
1 parent 5b83d10 commit 632cd00
Show file tree
Hide file tree
Showing 4 changed files with 384 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .github/workflows/generate-icon-files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ jobs:
git add .
git commit -m "feat(bezier-icons): generate icon files from icons.json" || echo "skipped commit due to no update"
- name: Add pr description
run: |
node packages/bezier-icons/scripts/make-pr-description.js ${{ secrets.GITHUB_TOKEN }} ${{ github.event.number }}
- name: Delete icons.json files
run: |
git rm packages/bezier-icons/icons.json
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,8 @@
"path": "./node_modules/cz-conventional-changelog"
}
},
"packageManager": "[email protected]"
"packageManager": "[email protected]",
"dependencies": {
"octokit": "^3.1.0"
}
}
56 changes: 56 additions & 0 deletions packages/bezier-icons/scripts/make-pr-description.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const { exec } = require('child_process')

const githubToken = process.argv[0]
const pullNumber = process.argv[1]

const keyToHeader = {
M: 'Modified 🖊️\n',
A: 'Added 🎨\n',
D: 'Deleted 🗑️\n',
}

const getIconName = path => path.split('/').at(-1)

const getDescription = gitLog => {
let description = 'Update Icons 😃\n\n'

const updatedAndIconPath = gitLog
.trim()
.split('\n')
.map(line => line.split('\t'))
.filter(line => line[1].endsWith('.svg'))
.reduce((acc, cur) => {
const [key, file] = cur
const header = keyToHeader[key]
const icon = `- ${getIconName(file)}`

if (!acc[header]) {
acc[header] = [icon]
} else {
acc[header].push(icon)
}
return acc
}, {})

for (const [key, icons] of Object.entries(updatedAndIconPath)) {
description += key
description += icons.join('\n')
}

return description
}

exec('git log -1 --name-status --pretty="format:"', async (_undefined, stdout) => {
const description = getDescription(stdout)

await fetch(`https://api.github.com/repos/yangwooseong/bezier-react/${pullNumber}`, {
method: 'PATCH',
headers: {
'X-GitHub-Api-Version': '2022-11-28',
Authorization: `Bearer ${githubToken}`,
Accept: 'application/vnd.github+json',
},
body: description,
})
})

Loading

0 comments on commit 632cd00

Please sign in to comment.