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

feat(bezier-icons): update icons #68

Closed
wants to merge 2 commits into from
Closed
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
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"
}
}
1 change: 1 addition & 0 deletions packages/bezier-icons/icons.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
61 changes: 61 additions & 0 deletions packages/bezier-icons/scripts/make-pr-description.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const { exec } = require('child_process')

const { Octokit } = require('octokit')

const githubToken = process.argv[0]
const pullNumber = process.argv[1]
const octokit = new Octokit({
auth: githubToken,
})

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
Loading