-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix parameters of
repos.getContent
API
- Loading branch information
Showing
3 changed files
with
91 additions
and
5 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,82 @@ | ||
/** | ||
* @file | ||
* Script for generating release note. | ||
*/ | ||
import { execSync } from 'node:child_process'; | ||
import path from 'node:path'; | ||
import process from 'node:process'; | ||
import { getDirnameFromImportMeta, titleToSlug } from '../../sdk.mjs'; | ||
|
||
const loadRevision = (revision) => { | ||
const projectRoot = path.join( | ||
getDirnameFromImportMeta(import.meta.url), | ||
'..', | ||
'..', | ||
); | ||
const json = JSON.parse( | ||
execSync(`git show ${revision}:_data/simple-icons.json`).toString(), | ||
); | ||
|
||
const hashes = new Map( | ||
execSync( | ||
`git ls-tree --format="%(objectname) %(path)" ${revision} icons/*`, | ||
{ cwd: projectRoot, shell: true }, | ||
) | ||
.toString() | ||
.trim() | ||
.replaceAll(/(icons\/|\.svg)/g, '') | ||
.split('\n') | ||
.map((line) => { | ||
const [hash, slug] = line.split(' '); | ||
return [slug, hash]; | ||
}), | ||
); | ||
const icons = new Map( | ||
json.icons | ||
? json.icons.map((icon) => [icon.slug ?? titleToSlug(icon.title), icon]) | ||
: json.map((icon) => [icon.slug ?? titleToSlug(icon.title), icon]), | ||
); | ||
return { hashes, icons }; | ||
}; | ||
|
||
const iconDiff = (beforeRevision, afterRevision) => { | ||
const before = loadRevision(beforeRevision); | ||
const after = loadRevision(afterRevision); | ||
const beforeSlugs = new Set(before.icons.keys()); | ||
const afterSlugs = new Set(after.icons.keys()); | ||
|
||
const newSlugs = afterSlugs.difference(beforeSlugs); | ||
const removedSlugs = beforeSlugs.difference(afterSlugs); | ||
const restSlugs = beforeSlugs.intersection(afterSlugs); | ||
|
||
const updatedSlugs = new Set(); | ||
for (const slug of restSlugs) { | ||
const beforeIconString = JSON.stringify(before.icons.get(slug)); | ||
const afterIconString = JSON.stringify(after.icons.get(slug)); | ||
if (beforeIconString !== afterIconString) updatedSlugs.add(slug); | ||
|
||
const beforeIconHash = before.hashes.get(slug); | ||
const afterIconHash = after.hashes.get(slug); | ||
if (beforeIconHash !== afterIconHash) updatedSlugs.add(slug); | ||
} | ||
|
||
return { | ||
newIcons: [...newSlugs].map((x) => after.icons.get(x)), | ||
removeIcons: [...removedSlugs].map((x) => before.icons.get(x)), | ||
updatedIcons: [...updatedSlugs].map((x) => after.icons.get(x)), | ||
}; | ||
}; | ||
|
||
export const generateReleaseNote = () => { | ||
const diff = iconDiff('master', 'develop'); | ||
const releaseNote = Object.entries(diff) | ||
.map(([key, icons]) => { | ||
const title = key.replace(/Icons$/, ' icons'); | ||
return icons.length > 0 | ||
? `## ${icons.length} ${title}\n\n${icons.map((icon) => `- ${icon.title}`).join('\n')}` | ||
: ''; | ||
}) | ||
.filter(Boolean) | ||
.join('\n\n'); | ||
return { diff, releaseNote }; | ||
}; |