Skip to content

Commit

Permalink
feat: adds compacted by topics
Browse files Browse the repository at this point in the history
  • Loading branch information
simonecorsi committed Jul 6, 2022
1 parent bf78ae9 commit 9dfa1f3
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 21 deletions.
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ branding:
icon: align-justify
color: yellow
inputs:
compact-by-topic:
description: 'Generate another page with output compacted by github topics'
default: 'false'
required: false
api-token:
description: 'Personal API Token'
required: true
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"@actions/core": "^1.8.2",
"@actions/exec": "^1.1.1",
"ejs": "^3.1.8",
"gh-star-fetch": "^1.3.0",
"gh-star-fetch": "^1.5.0",
"got": "^11.8.1",
"remark": "^14.0.2",
"remark-toc": "^8.0.1"
Expand Down
54 changes: 41 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import path from 'path';
import * as core from '@actions/core';
import { readFile } from 'fs/promises';
import ghStarFetch from 'gh-star-fetch';
import ghStarFetch, {
Options,
compactByLanguage,
compactByTopic,
} from 'gh-star-fetch';

import {
renderer,
Expand All @@ -27,32 +31,56 @@ export async function main() {
core.info("Couldn't find template file, using default");
}

const sortedByLanguages = await ghStarFetch({
const opts: Partial<Options> = {
accessToken: core.getInput('api-token', { required: true }),
compactByLanguage: true,
});
};

const rendered = await renderer(
const results = await ghStarFetch(opts);

const files = [];

const compactedByLanguage = compactByLanguage(results);
const byLanguage = await renderer(
{
username: REPO_USERNAME,
stars: Object.entries(sortedByLanguages),
stars: Object.entries(compactedByLanguage),
updatedAt: Date.now(),
},
template
);

const markdown: string = await generateMd(rendered);

await git.pushNewFiles([
files.push(
{
filename: MARKDOWN_FILENAME,
data: markdown,
data: await generateMd(byLanguage),
},
{
filename: 'data.json',
data: JSON.stringify(sortedByLanguages, null, 2),
},
]);
data: JSON.stringify(compactedByLanguage, null, 2),
}
);

const shouldCompactByTopic =
!!core.getInput('compact-by-topic') ||
core.getInput('compact-by-topic') === 'true';

if (shouldCompactByTopic) {
const compactedByTopic = compactByTopic(results);
const byTopic = await renderer(
{
username: REPO_USERNAME,
stars: Object.entries(compactedByTopic),
updatedAt: Date.now(),
},
template
);
files.push({
filename: 'TOPICS.md',
data: await generateMd(byTopic),
});
}

await git.pushNewFiles(files);
}

export async function run(): Promise<void> {
Expand Down

0 comments on commit 9dfa1f3

Please sign in to comment.