25 Commits

Author SHA1 Message Date
Conventional Changelog Action
6ffe17f8b4 chore(release): v1.0.44 2021-10-26 07:51:36 +00:00
GitHub Actions
4aef61f232 feat: git add multiple files at once 2021-10-26 09:50:38 +02:00
Conventional Changelog Action
5e0ef822fd chore(release): v1.0.43 2021-10-15 07:18:53 +00:00
GitHub Actions
94635fe447 feat: reduce json output size 2021-10-15 09:17:49 +02:00
Conventional Changelog Action
5b36813618 chore(release): v1.0.42 2021-10-14 07:47:28 +00:00
GitHub Actions
dcf9898d67 fix(paginator): last page now correctly matches rex 2021-10-14 09:46:33 +02:00
Conventional Changelog Action
884fc90171 chore(release): v1.0.41 2021-10-14 07:13:40 +00:00
GitHub Actions
b97833f7c5 test: fixs suite 2021-10-14 09:12:48 +02:00
Simone Corsi
1d6848cd17 fix: should avoid index lock 2021-10-14 08:57:35 +02:00
Conventional Changelog Action
0e016f41d3 chore(release): v1.0.40 2021-10-13 22:22:11 +00:00
GitHub Actions
8f9b4ccf8d fix: fixes while exit condition 2021-10-14 00:20:38 +02:00
GitHub Actions
51da6c20db feat: paginates using async generator 2021-10-13 23:44:05 +02:00
Conventional Changelog Action
f7a8341bb1 chore(release): v1.0.39 2021-08-31 09:17:17 +00:00
Simone Corsi
c361d6e2b6 Merge pull request #12 from simonecorsi/dependabot/npm_and_yarn/path-parse-1.0.7
build(deps): bump path-parse from 1.0.6 to 1.0.7
2021-08-31 11:16:32 +02:00
dependabot[bot]
ef137b518e build(deps): bump path-parse from 1.0.6 to 1.0.7
Bumps [path-parse](https://github.com/jbgutierrez/path-parse) from 1.0.6 to 1.0.7.
- [Release notes](https://github.com/jbgutierrez/path-parse/releases)
- [Commits](https://github.com/jbgutierrez/path-parse/commits/v1.0.7)

---
updated-dependencies:
- dependency-name: path-parse
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-12 23:57:13 +00:00
Conventional Changelog Action
3e66d85077 chore(release): v1.0.38 2021-06-23 22:10:04 +00:00
Conventional Changelog Action
16430922c4 chore(release): v1.0.37 2021-06-23 22:09:38 +00:00
Simone Corsi
20b7de127d Merge pull request #7 from simonecorsi/dependabot/npm_and_yarn/hosted-git-info-2.8.9
build(deps): bump hosted-git-info from 2.8.8 to 2.8.9
2021-06-24 00:09:33 +02:00
Simone Corsi
9def6961a9 Merge pull request #9 from simonecorsi/dependabot/npm_and_yarn/normalize-url-4.5.1
build(deps): bump normalize-url from 4.5.0 to 4.5.1
2021-06-24 00:09:23 +02:00
Simone Corsi
f846c5ee47 Merge pull request #10 from simonecorsi/dependabot/npm_and_yarn/glob-parent-5.1.2
build(deps): bump glob-parent from 5.1.1 to 5.1.2
2021-06-24 00:09:00 +02:00
Simone Corsi
8133f1f32e Merge branch 'main' into dependabot/npm_and_yarn/normalize-url-4.5.1 2021-06-24 00:08:00 +02:00
Simone Corsi
19e564c928 Merge branch 'main' into dependabot/npm_and_yarn/glob-parent-5.1.2 2021-06-24 00:07:19 +02:00
dependabot[bot]
e558e07817 build(deps): bump glob-parent from 5.1.1 to 5.1.2
Bumps [glob-parent](https://github.com/gulpjs/glob-parent) from 5.1.1 to 5.1.2.
- [Release notes](https://github.com/gulpjs/glob-parent/releases)
- [Changelog](https://github.com/gulpjs/glob-parent/blob/main/CHANGELOG.md)
- [Commits](https://github.com/gulpjs/glob-parent/compare/v5.1.1...v5.1.2)

---
updated-dependencies:
- dependency-name: glob-parent
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-06-12 15:27:03 +00:00
dependabot[bot]
202d6fe6c3 build(deps): bump normalize-url from 4.5.0 to 4.5.1
Bumps [normalize-url](https://github.com/sindresorhus/normalize-url) from 4.5.0 to 4.5.1.
- [Release notes](https://github.com/sindresorhus/normalize-url/releases)
- [Commits](https://github.com/sindresorhus/normalize-url/commits)

---
updated-dependencies:
- dependency-name: normalize-url
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-06-12 03:41:41 +00:00
dependabot[bot]
110a667b31 build(deps): bump hosted-git-info from 2.8.8 to 2.8.9
Bumps [hosted-git-info](https://github.com/npm/hosted-git-info) from 2.8.8 to 2.8.9.
- [Release notes](https://github.com/npm/hosted-git-info/releases)
- [Changelog](https://github.com/npm/hosted-git-info/blob/v2.8.9/CHANGELOG.md)
- [Commits](https://github.com/npm/hosted-git-info/compare/v2.8.8...v2.8.9)

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-19 09:24:36 +00:00
9 changed files with 255 additions and 172 deletions

View File

@@ -1,35 +1,36 @@
## <small>1.0.36 (2021-06-23)</small>
## <small>1.0.44 (2021-10-26)</small>
* feat: saving json data for future use ([7ceb9cb](https://github.com/simonecorsi/mawesome/commit/7ceb9cb))
* feat: git add multiple files at once ([4aef61f](https://github.com/simonecorsi/mawesome/commit/4aef61f))
## <small>1.0.35 (2021-06-22)</small>
## <small>1.0.43 (2021-10-15)</small>
* chore(release): v1.0.35 ([cee1906](https://github.com/simonecorsi/mawesome/commit/cee1906))
* build(deps): bump set-getter from 0.1.0 to 0.1.1 ([970d603](https://github.com/simonecorsi/mawesome/commit/970d603))
* chore(release): v1.0.43 ([5e0ef82](https://github.com/simonecorsi/mawesome/commit/5e0ef82))
* feat: reduce json output size ([94635fe](https://github.com/simonecorsi/mawesome/commit/94635fe))
## <small>1.0.34 (2021-05-19)</small>
## <small>1.0.42 (2021-10-14)</small>
* chore(release): v1.0.34 ([ab02c0d](https://github.com/simonecorsi/mawesome/commit/ab02c0d))
* chore(release): v1.0.42 ([5b36813](https://github.com/simonecorsi/mawesome/commit/5b36813))
* fix(paginator): last page now correctly matches rex ([dcf9898](https://github.com/simonecorsi/mawesome/commit/dcf9898))
## <small>1.0.33 (2021-05-19)</small>
## <small>1.0.41 (2021-10-14)</small>
* chore(release): v1.0.33 ([fc187df](https://github.com/simonecorsi/mawesome/commit/fc187df))
* build(deps): bump handlebars from 4.7.6 to 4.7.7 ([012928b](https://github.com/simonecorsi/mawesome/commit/012928b))
* build(deps): bump lodash from 4.17.20 to 4.17.21 ([1015179](https://github.com/simonecorsi/mawesome/commit/1015179))
* chore(release): v1.0.41 ([884fc90](https://github.com/simonecorsi/mawesome/commit/884fc90))
* test: fixs suite ([b97833f](https://github.com/simonecorsi/mawesome/commit/b97833f))
* fix: should avoid index lock ([1d6848c](https://github.com/simonecorsi/mawesome/commit/1d6848c))
## <small>1.0.32 (2021-01-22)</small>
## <small>1.0.40 (2021-10-13)</small>
* chore: removed unused npm packages ([3ad1555](https://github.com/simonecorsi/mawesome/commit/3ad1555))
* chore(release): v1.0.32 ([fe15d93](https://github.com/simonecorsi/mawesome/commit/fe15d93))
* docs: added documentation ([5753aef](https://github.com/simonecorsi/mawesome/commit/5753aef))
* chore(release): v1.0.40 ([0e016f4](https://github.com/simonecorsi/mawesome/commit/0e016f4))
* fix: fixes while exit condition ([8f9b4cc](https://github.com/simonecorsi/mawesome/commit/8f9b4cc))
* feat: paginates using async generator ([51da6c2](https://github.com/simonecorsi/mawesome/commit/51da6c2))

162
index.js
View File

@@ -18482,7 +18482,7 @@ const testParameter = (name, filters) => {
};
const normalizeDataURL = (urlString, {stripHash}) => {
const parts = urlString.match(/^data:(.*?),(.*?)(?:#(.*))?$/);
const parts = urlString.match(/^data:([^,]*?),([^#]*?)(?:#(.*))?$/);
if (!parts) {
throw new Error(`Invalid URL: ${urlString}`);
@@ -21291,7 +21291,16 @@ class Git {
}));
};
this.config = (prop, value) => this.exec(`config ${prop} "${value}"`);
this.add = (file) => this.exec(`add ${file}`);
this.add = (file) => {
let str = '';
if (Array.isArray(file)) {
file.map((f) => (str += ` ${f}`));
}
else {
str = file;
}
return this.exec(`add ${str}`);
};
this.commit = (message) => this.exec(`commit -m "${message}"`);
this.pull = () => __awaiter(this, void 0, void 0, function* () {
const args = ['pull'];
@@ -21356,12 +21365,32 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
};
var __asyncValues = (this && this.__asyncValues) || function (o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _a;
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.pushNewFiles = exports.MARKDOWN_FILENAME = exports.generateMd = exports.paginate = exports.API_STARRED_URL = exports.REPO_USERNAME = exports.apiGetStar = exports.renderer = exports.isLastPage = exports.wait = void 0;
exports.pushNewFiles = exports.MARKDOWN_FILENAME = exports.generateMd = exports.apiGetStar = exports.getNextPage = exports.renderer = exports.wait = exports.API_STARRED_URL = exports.REPO_USERNAME = void 0;
const fs_1 = __importDefault(__nccwpck_require__(5747));
const ejs_1 = __importDefault(__nccwpck_require__(8431));
const core = __importStar(__nccwpck_require__(2186));
const remark_1 = __importDefault(__nccwpck_require__(2081));
@@ -21370,16 +21399,13 @@ const template_1 = __importDefault(__nccwpck_require__(3932));
const api_1 = __importDefault(__nccwpck_require__(8229));
const link_1 = __importDefault(__nccwpck_require__(9338));
const git_1 = __importDefault(__nccwpck_require__(6350));
const fs_1 = __importDefault(__nccwpck_require__(5747));
exports.REPO_USERNAME = (_a = process.env.GITHUB_REPOSITORY) === null || _a === void 0 ? void 0 : _a.split('/')[0];
exports.API_STARRED_URL = `${process.env.GITHUB_API_URL}/users/${exports.REPO_USERNAME}/starred`;
const fsp = fs_1.default.promises;
function wait(time = 200) {
return new Promise((resolve) => setTimeout(resolve, time));
}
exports.wait = wait;
function isLastPage(links) {
return links.next === links.last;
}
exports.isLastPage = isLastPage;
function renderer(data, templateString = template_1.default) {
return __awaiter(this, void 0, void 0, function* () {
try {
@@ -21392,32 +21418,91 @@ function renderer(data, templateString = template_1.default) {
});
}
exports.renderer = renderer;
function apiGetStar(url) {
function getNextPage(links) {
const next = links.find((l) => l.rel === 'next');
const last = links.find((l) => l.rel === 'last');
if (!next || !last)
return null;
const matchNext = next.uri.match(/page=([0-9]*)/);
const matchLast = last.uri.match(/page=([0-9]*)/);
if (!matchNext || !matchLast)
return null;
if (matchNext[1] === matchLast[1])
return null;
return matchNext[1];
}
exports.getNextPage = getNextPage;
function paginateStars(url) {
return __asyncGenerator(this, arguments, function* paginateStars_1() {
let nextPage = '1';
while (nextPage) {
try {
const { headers, body } = yield __await(api_1.default.get(url, {
searchParams: {
page: nextPage,
},
}));
yield yield __await(body);
nextPage = getNextPage(link_1.default.parse(headers.link).refs);
yield __await(wait(1000)); // avoid limits
}
catch (e) {
console.error(e);
break;
}
}
});
}
function apiGetStar(url = exports.API_STARRED_URL) {
var e_1, _a;
var _b, _c, _d, _e, _f;
return __awaiter(this, void 0, void 0, function* () {
const { headers, body } = yield api_1.default.get(url);
return {
data: body,
links: link_1.default.parse(headers.link).refs.reduce((acc, val) => (Object.assign(Object.assign({}, acc), { [val.rel]: val.uri })), {}),
};
const data = [];
try {
for (var _g = __asyncValues(paginateStars(url)), _h; _h = yield _g.next(), !_h.done;) {
const stars = _h.value;
for (const star of stars) {
data.push({
id: star.id,
node_id: star.node_id,
name: star.name,
full_name: star.full_name,
owner: {
login: (_b = star === null || star === void 0 ? void 0 : star.owner) === null || _b === void 0 ? void 0 : _b.login,
id: (_c = star === null || star === void 0 ? void 0 : star.owner) === null || _c === void 0 ? void 0 : _c.id,
avatar_url: (_d = star === null || star === void 0 ? void 0 : star.owner) === null || _d === void 0 ? void 0 : _d.avatar_url,
url: (_e = star === null || star === void 0 ? void 0 : star.owner) === null || _e === void 0 ? void 0 : _e.url,
html_url: (_f = star === null || star === void 0 ? void 0 : star.owner) === null || _f === void 0 ? void 0 : _f.html_url,
},
html_url: star.html_url,
description: star.description,
url: star.url,
languages_url: star.languages_url,
created_at: star.created_at,
updated_at: star.updated_at,
git_url: star.git_url,
ssh_url: star.ssh_url,
clone_url: star.clone_url,
homepage: star.homepage,
stargazers_count: star.stargazers_count,
watchers_count: star.watchers_count,
language: star.language,
topics: star.topics,
});
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_h && !_h.done && (_a = _g.return)) yield _a.call(_g);
}
finally { if (e_1) throw e_1.error; }
}
return data;
});
}
exports.apiGetStar = apiGetStar;
exports.REPO_USERNAME = (_a = process.env.GITHUB_REPOSITORY) === null || _a === void 0 ? void 0 : _a.split('/')[0];
exports.API_STARRED_URL = `${process.env.GITHUB_API_URL}/users/${exports.REPO_USERNAME}/starred`;
let links = {
next: exports.API_STARRED_URL,
last: undefined,
};
function paginate() {
return __awaiter(this, void 0, void 0, function* () {
if (isLastPage(links))
return null;
const r = yield apiGetStar(links.next);
links = r.links;
return r;
});
}
exports.paginate = paginate;
function generateMd(data) {
return new Promise((resolve) => {
remark_1.default()
@@ -21439,11 +21524,9 @@ function pushNewFiles(files = []) {
if (!files.length)
return;
yield git_1.default.pull();
yield Promise.all(files.map(({ filename, data }) => __awaiter(this, void 0, void 0, function* () {
yield fsp.writeFile(filename, data);
yield git_1.default.add(filename);
yield git_1.default.commit(`chore(${filename}): updated ${filename}`);
})));
yield Promise.all(files.map(({ filename, data }) => fsp.writeFile(filename, data)));
yield git_1.default.add(files.map(({ filename }) => filename));
yield git_1.default.commit(`chore(updates): updated entries in files`);
yield git_1.default.push();
});
}
@@ -21491,14 +21574,7 @@ const core = __importStar(__nccwpck_require__(2186));
const helpers_1 = __nccwpck_require__(3015);
function main() {
return __awaiter(this, void 0, void 0, function* () {
let results = [];
while (true) {
// sorry.
const r = yield helpers_1.paginate();
if (!r || r === null)
break;
results = results.concat(r.data);
}
const results = yield helpers_1.apiGetStar();
const sortedByLanguages = results.reduce((acc, val) => {
const language = val.language || 'generic';
if (!acc[language]) {

56
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{
"name": "mawesome",
"version": "1.0.35",
"version": "1.0.38",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@@ -2339,9 +2339,9 @@
}
},
"hosted-git-info": {
"version": "2.8.8",
"resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.8.tgz",
"integrity": "sha512-f/wzC2QaWBs7t9IYqB4T3sR1xviIViXJRJTWBlx2Gf3g0Xi5vI7Yy4koXQ1c9OYDGHN9sBy1DQ2AB8fqZBWhUg==",
"version": "2.8.9",
"resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz",
"integrity": "sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==",
"dev": true
},
"indent-string": {
@@ -3980,9 +3980,9 @@
"dev": true
},
"hosted-git-info": {
"version": "2.8.8",
"resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.8.tgz",
"integrity": "sha512-f/wzC2QaWBs7t9IYqB4T3sR1xviIViXJRJTWBlx2Gf3g0Xi5vI7Yy4koXQ1c9OYDGHN9sBy1DQ2AB8fqZBWhUg==",
"version": "2.8.9",
"resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz",
"integrity": "sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==",
"dev": true
},
"indent-string": {
@@ -4263,9 +4263,9 @@
}
},
"glob-parent": {
"version": "5.1.1",
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.1.tgz",
"integrity": "sha512-FnI+VGOpnlGHWZxthPGR+QhR78fuiK0sNLkHQv+bL9fQi57lNNdquIbna/WrfROrolq8GK5Ek6BiMwqL/voRYQ==",
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz",
"integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==",
"dev": true,
"requires": {
"is-glob": "^4.0.1"
@@ -4532,9 +4532,9 @@
}
},
"hosted-git-info": {
"version": "3.0.7",
"resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-3.0.7.tgz",
"integrity": "sha512-fWqc0IcuXs+BmE9orLDyVykAG9GJtGLGuZAAqgcckPgv5xad4AcXGIv8galtQvlwutxSlaMcdw7BUtq2EIvqCQ==",
"version": "3.0.8",
"resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-3.0.8.tgz",
"integrity": "sha512-aXpmwoOhRBrw6X3j0h5RloK4x1OzsxMPyxqIHyNfSe2pypkVTZFpEiRoSipPEPlMrh0HW/XsjkJ5WgnCirpNUw==",
"dev": true,
"requires": {
"lru-cache": "^6.0.0"
@@ -6180,9 +6180,9 @@
"dev": true
},
"normalize-url": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.0.tgz",
"integrity": "sha512-2s47yzUxdexf1OhyRi4Em83iQk0aPvwTddtFz4hnSSw9dCEsLEGf6SwIO8ss/19S9iBb5sJaOuTvTGDeZI00BQ=="
"version": "4.5.1",
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.1.tgz",
"integrity": "sha512-9UZCFRHQdNrfTpGg8+1INIg93B6zE0aXMVFkw1WFwvO4SlZywU6aLg5Of0Ap/PgcbSw4LNxvMWXMeugwMCX0AA=="
},
"npm-run-path": {
"version": "4.0.1",
@@ -6668,9 +6668,9 @@
"dev": true
},
"path-parse": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz",
"integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==",
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz",
"integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==",
"dev": true
},
"path-to-regexp": {
@@ -6944,9 +6944,9 @@
},
"dependencies": {
"hosted-git-info": {
"version": "2.8.8",
"resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.8.tgz",
"integrity": "sha512-f/wzC2QaWBs7t9IYqB4T3sR1xviIViXJRJTWBlx2Gf3g0Xi5vI7Yy4koXQ1c9OYDGHN9sBy1DQ2AB8fqZBWhUg==",
"version": "2.8.9",
"resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz",
"integrity": "sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==",
"dev": true
},
"normalize-package-data": {
@@ -7922,9 +7922,9 @@
"dev": true
},
"hosted-git-info": {
"version": "2.8.8",
"resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.8.tgz",
"integrity": "sha512-f/wzC2QaWBs7t9IYqB4T3sR1xviIViXJRJTWBlx2Gf3g0Xi5vI7Yy4koXQ1c9OYDGHN9sBy1DQ2AB8fqZBWhUg==",
"version": "2.8.9",
"resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz",
"integrity": "sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==",
"dev": true
},
"load-json-file": {
@@ -8490,9 +8490,9 @@
"dev": true
},
"hosted-git-info": {
"version": "2.8.8",
"resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.8.tgz",
"integrity": "sha512-f/wzC2QaWBs7t9IYqB4T3sR1xviIViXJRJTWBlx2Gf3g0Xi5vI7Yy4koXQ1c9OYDGHN9sBy1DQ2AB8fqZBWhUg==",
"version": "2.8.9",
"resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz",
"integrity": "sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==",
"dev": true
},
"indent-string": {

View File

@@ -1,6 +1,6 @@
{
"name": "mawesome",
"version": "1.0.36",
"version": "1.0.44",
"description": "Generate awesome list from user starred repositories",
"main": "index.js",
"author": "Simone Corsi<simonecorsi.dev@gmail.com>",

View File

@@ -60,7 +60,15 @@ class Git {
config = (prop: string, value: string) =>
this.exec(`config ${prop} "${value}"`);
add = (file: string) => this.exec(`add ${file}`);
add = (file: string | string[]) => {
let str = '';
if (Array.isArray(file)) {
file.map((f) => (str += ` ${f}`));
} else {
str = file;
}
return this.exec(`add ${str}`);
};
commit = (message: string) => this.exec(`commit -m "${message}"`);

View File

@@ -1,3 +1,4 @@
import fs from 'fs';
import ejs from 'ejs';
import * as core from '@actions/core';
import remark from 'remark';
@@ -8,9 +9,10 @@ import GithubApi from './api';
import link from './link';
import git from './git';
import type { PaginationLink, ApiGetStarResponse } from './types';
import type { PaginationLink, ApiGetStarResponse, Stars, Star } from './types';
import fs from 'fs';
export const REPO_USERNAME = process.env.GITHUB_REPOSITORY?.split('/')[0];
export const API_STARRED_URL = `${process.env.GITHUB_API_URL}/users/${REPO_USERNAME}/starred`;
const fsp = fs.promises;
@@ -18,10 +20,6 @@ export function wait(time = 200): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, time));
}
export function isLastPage(links: PaginationLink): boolean {
return links.next === links.last;
}
export async function renderer(
data: { [key: string]: any },
templateString = MD_TEMPLATE
@@ -34,32 +32,72 @@ export async function renderer(
}
}
export async function apiGetStar(url: string): Promise<ApiGetStarResponse> {
const { headers, body }: any = await GithubApi.get(url);
return {
data: body,
links: link.parse(headers.link).refs.reduce(
(acc, val) => ({
...acc,
[val.rel]: val.uri,
}),
{}
),
};
export function getNextPage(links: PaginationLink[]): string | null {
const next = links.find((l) => l.rel === 'next');
const last = links.find((l) => l.rel === 'last');
if (!next || !last) return null;
const matchNext = next.uri.match(/page=([0-9]*)/);
const matchLast = last.uri.match(/page=([0-9]*)/);
if (!matchNext || !matchLast) return null;
if (matchNext[1] === matchLast[1]) return null;
return matchNext[1];
}
export const REPO_USERNAME = process.env.GITHUB_REPOSITORY?.split('/')[0];
export const API_STARRED_URL = `${process.env.GITHUB_API_URL}/users/${REPO_USERNAME}/starred`;
async function* paginateStars(url: string): AsyncGenerator<Stars> {
let nextPage: string | null = '1';
while (nextPage) {
try {
const { headers, body } = await GithubApi.get(url, {
searchParams: {
page: nextPage,
},
});
yield (body as unknown) as Stars;
nextPage = getNextPage(link.parse(headers.link).refs);
await wait(1000); // avoid limits
} catch (e) {
console.error(e);
break;
}
}
}
let links: PaginationLink = {
next: API_STARRED_URL,
last: undefined,
};
export async function paginate(): Promise<ApiGetStarResponse | null> {
if (isLastPage(links)) return null;
const r = await apiGetStar(links.next);
links = r.links;
return r;
export async function apiGetStar(
url: string = API_STARRED_URL
): Promise<ApiGetStarResponse> {
const data: Partial<Star>[] = [];
for await (const stars of paginateStars(url)) {
for (const star of stars) {
data.push({
id: star.id,
node_id: star.node_id,
name: star.name,
full_name: star.full_name,
owner: {
login: star?.owner?.login,
id: star?.owner?.id,
avatar_url: star?.owner?.avatar_url,
url: star?.owner?.url,
html_url: star?.owner?.html_url,
},
html_url: star.html_url,
description: star.description,
url: star.url,
languages_url: star.languages_url,
created_at: star.created_at,
updated_at: star.updated_at,
git_url: star.git_url,
ssh_url: star.ssh_url,
clone_url: star.clone_url,
homepage: star.homepage,
stargazers_count: star.stargazers_count,
watchers_count: star.watchers_count,
language: star.language,
topics: star.topics,
} as Partial<Star>);
}
}
return (data as unknown) as Stars;
}
export function generateMd(data: string): Promise<string> {
@@ -91,12 +129,10 @@ export async function pushNewFiles(files: File[] = []): Promise<any> {
await git.pull();
await Promise.all(
files.map(async ({ filename, data }) => {
await fsp.writeFile(filename, data);
await git.add(filename);
await git.commit(`chore(${filename}): updated ${filename}`);
})
files.map(({ filename, data }) => fsp.writeFile(filename, data))
);
await git.add(files.map(({ filename }) => filename));
await git.commit(`chore(updates): updated entries in files`);
await git.push();
}

View File

@@ -1,26 +1,18 @@
import * as core from '@actions/core';
import { data } from 'remark';
import {
renderer,
paginate,
REPO_USERNAME,
generateMd,
pushNewFiles,
MARKDOWN_FILENAME,
apiGetStar,
} from './helpers';
import type { SortedLanguageList, Stars, Star } from './types';
export async function main(): Promise<any> {
let results: Stars = [];
while (true) {
// sorry.
const r = await paginate();
if (!r || r === null) break;
results = results.concat(r.data);
}
const results: Stars = await apiGetStar();
const sortedByLanguages = results.reduce(
(acc: SortedLanguageList, val: Star) => {

View File

@@ -5,14 +5,11 @@ export type SortedLanguageList = {
};
export type PaginationLink = {
next: string;
last: string | undefined | null;
uri: string;
rel: 'next' | 'last' | 'prev' | 'first';
};
export type Stars = Endpoints['GET /user/starred']['response']['data'];
export type Star = Stars[number] | { language: string };
export type ApiGetStarResponse = {
links: PaginationLink;
data: Stars;
};
export type ApiGetStarResponse = Stars;

View File

@@ -7,7 +7,7 @@ sinon.replace(core, 'getInput', sinon.fake());
import GithubApi from '../src/api';
const GithubApiFake = sinon.fake((rul) => ({
body: 'data',
body: [],
headers: {
link:
'<https://api.github.com/user/5617452/starred?page=2>; rel="next", <https://api.github.com/user/5617452/starred?page=2>; rel="last"',
@@ -32,11 +32,9 @@ const writeFile = sinon.fake();
sinon.replace(fsp, 'writeFile', writeFile);
import {
isLastPage,
wait,
renderer,
apiGetStar,
paginate,
generateMd,
pushNewFiles,
} from '../src/helpers';
@@ -46,40 +44,15 @@ test('wait should wait', async (t) => {
t.pass();
});
test('isLastPage', (t) => {
t.true(
isLastPage({
next: 'last',
last: 'last',
})
);
t.false(
isLastPage({
next: 'last',
last: undefined,
})
);
});
test('renderer should render', async (t) => {
const output = await renderer({ variable: 123 }, 'Test: <%= variable %>');
t.is(output, 'Test: 123');
});
test('apiGetStar', async (t) => {
let { data, links } = await apiGetStar('url');
let stars = await apiGetStar('url');
t.true(GithubApiFake.called);
t.is(data, 'data');
t.deepEqual(links, {
last: 'https://api.github.com/user/5617452/starred?page=2',
next: 'https://api.github.com/user/5617452/starred?page=2',
});
});
test('paginate', async (t) => {
await paginate();
const res = await paginate();
t.is(res, null);
t.true(Array.isArray(stars));
});
test('generateMd should create TOC', async (t) => {
@@ -97,10 +70,10 @@ test('generateMd should create TOC', async (t) => {
});
test('should push', async (t) => {
await pushNewFiles([{filename: "README.md", data: '# title'}]);
t.true(writeFile.calledWith('README.md', '# title'));
await pushNewFiles([{ filename: 'README.md', data: '# title' }]);
t.true(writeFile.called);
t.true(pull.called);
t.true(add.calledWith('README.md'));
t.true(commit.calledWith('chore(README.md): updated README.md'));
t.true(add.called);
t.true(commit.called);
t.true(push.called);
});