Skip to content

Commit

Permalink
Fix parameters of repos.getContent API
Browse files Browse the repository at this point in the history
  • Loading branch information
LitoMore committed Dec 22, 2024
1 parent 413d2e0 commit 3699e65
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/index.mjs

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions src/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ async function getPrFiles(core, client, context, prNumber) {
patch: fileInfo.patch,
path: fileInfo.filename,
status: fileInfo.status,
contentsUrl: fileInfo.contents_url,
});
} catch (err) {
core.warning(
Expand All @@ -180,6 +181,7 @@ async function getPrFiles(core, client, context, prNumber) {
patch: fileInfo.patch,
path: fileInfo.filename,
status: fileInfo.status,
contentsUrl: fileInfo.contents_url,
});
} catch (err) {
core.warning(
Expand All @@ -202,6 +204,7 @@ async function getPrFiles(core, client, context, prNumber) {
patch: dataFile.patch,
path: dataFile.filename,
status: dataFile.status,
contentsUrl: dataFile.contents_url,
});
}

Expand Down Expand Up @@ -322,13 +325,14 @@ async function getChangesFromFile(core, file, client, context, id) {
const contentResult = await client.rest.repos.getContent({
owner: context.repo.owner,
repo: context.repo.repo,
path: file.filename,
ref: file.sha,
path: file.path,
ref: new URL(file.contentsUrl).searchParams.get('ref'),
});

filePatch = Buffer.from(
contentResult.content,
contentResult.encoding,
// The content is base64 encoded but splited with newlines, so we need to remove them before decoding
contentResult.data.content.replaceAll('\n', ''),
contentResult.data.encoding,
).toString();
}

Expand Down
82 changes: 82 additions & 0 deletions src/generate-release-note.js
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 };
};

0 comments on commit 3699e65

Please sign in to comment.