12 Commits

Author SHA1 Message Date
Conventional Changelog Action
e5ba2cf34b chore(release): v1.0.45 2022-01-17 08:44:24 +00:00
Simone Corsi
f68439999d Merge pull request #13 from simonecorsi/dependabot/npm_and_yarn/shelljs-0.8.5
build(deps): bump shelljs from 0.8.4 to 0.8.5
2022-01-17 09:43:14 +01:00
dependabot[bot]
1da350a3d0 build(deps): bump shelljs from 0.8.4 to 0.8.5
Bumps [shelljs](https://github.com/shelljs/shelljs) from 0.8.4 to 0.8.5.
- [Release notes](https://github.com/shelljs/shelljs/releases)
- [Changelog](https://github.com/shelljs/shelljs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/shelljs/shelljs/compare/v0.8.4...v0.8.5)

---
updated-dependencies:
- dependency-name: shelljs
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-01-15 07:04:53 +00:00
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
7 changed files with 115 additions and 47 deletions

View File

@@ -1,36 +1,35 @@
## <small>1.0.40 (2021-10-13)</small>
## <small>1.0.45 (2022-01-17)</small>
* 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))
* build(deps): bump shelljs from 0.8.4 to 0.8.5 ([1da350a](https://github.com/simonecorsi/mawesome/commit/1da350a))
## <small>1.0.39 (2021-08-31)</small>
## <small>1.0.44 (2021-10-26)</small>
* chore(release): v1.0.39 ([f7a8341](https://github.com/simonecorsi/mawesome/commit/f7a8341))
* build(deps): bump path-parse from 1.0.6 to 1.0.7 ([ef137b5](https://github.com/simonecorsi/mawesome/commit/ef137b5))
* chore(release): v1.0.44 ([6ffe17f](https://github.com/simonecorsi/mawesome/commit/6ffe17f))
* feat: git add multiple files at once ([4aef61f](https://github.com/simonecorsi/mawesome/commit/4aef61f))
## <small>1.0.38 (2021-06-23)</small>
## <small>1.0.43 (2021-10-15)</small>
* chore(release): v1.0.38 ([3e66d85](https://github.com/simonecorsi/mawesome/commit/3e66d85))
* 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.37 (2021-06-23)</small>
## <small>1.0.42 (2021-10-14)</small>
* chore(release): v1.0.37 ([1643092](https://github.com/simonecorsi/mawesome/commit/1643092))
* build(deps): bump glob-parent from 5.1.1 to 5.1.2 ([e558e07](https://github.com/simonecorsi/mawesome/commit/e558e07))
* build(deps): bump hosted-git-info from 2.8.8 to 2.8.9 ([110a667](https://github.com/simonecorsi/mawesome/commit/110a667))
* build(deps): bump normalize-url from 4.5.0 to 4.5.1 ([202d6fe](https://github.com/simonecorsi/mawesome/commit/202d6fe))
* 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.36 (2021-06-23)</small>
## <small>1.0.41 (2021-10-14)</small>
* chore(release): v1.0.36 ([9c0b622](https://github.com/simonecorsi/mawesome/commit/9c0b622))
* feat: saving json data for future use ([7ceb9cb](https://github.com/simonecorsi/mawesome/commit/7ceb9cb))
* 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))

View File

@@ -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'];
@@ -21415,7 +21424,7 @@ function getNextPage(links) {
if (!next || !last)
return null;
const matchNext = next.uri.match(/page=([0-9]*)/);
const matchLast = next.uri.match(/page=([0-9]*)/);
const matchLast = last.uri.match(/page=([0-9]*)/);
if (!matchNext || !matchLast)
return null;
if (matchNext[1] === matchLast[1])
@@ -21446,18 +21455,47 @@ function paginateStars(url) {
}
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* () {
let data = [];
const data = [];
try {
for (var _b = __asyncValues(paginateStars(url)), _c; _c = yield _b.next(), !_c.done;) {
const stars = _c.value;
data = data.concat(stars);
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 (_c && !_c.done && (_a = _b.return)) yield _a.call(_b);
if (_h && !_h.done && (_a = _g.return)) yield _a.call(_g);
}
finally { if (e_1) throw e_1.error; }
}
@@ -21486,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();
});
}

8
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{
"name": "mawesome",
"version": "1.0.38",
"version": "1.0.44",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@@ -7414,9 +7414,9 @@
"dev": true
},
"shelljs": {
"version": "0.8.4",
"resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.4.tgz",
"integrity": "sha512-7gk3UZ9kOfPLIAbslLzyWeGiEqx9e3rxwZM0KE6EL8GlGwjym9Mrlx5/p33bWTu9YG6vcS4MBxYZDHYr5lr8BQ==",
"version": "0.8.5",
"resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.5.tgz",
"integrity": "sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow==",
"dev": true,
"requires": {
"glob": "^7.0.0",

View File

@@ -1,6 +1,6 @@
{
"name": "mawesome",
"version": "1.0.40",
"version": "1.0.45",
"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

@@ -9,7 +9,7 @@ import GithubApi from './api';
import link from './link';
import git from './git';
import type { PaginationLink, ApiGetStarResponse, Stars } from './types';
import type { PaginationLink, ApiGetStarResponse, Stars, Star } from './types';
export const REPO_USERNAME = process.env.GITHUB_REPOSITORY?.split('/')[0];
export const API_STARRED_URL = `${process.env.GITHUB_API_URL}/users/${REPO_USERNAME}/starred`;
@@ -37,8 +37,7 @@ export function getNextPage(links: PaginationLink[]): string | null {
const last = links.find((l) => l.rel === 'last');
if (!next || !last) return null;
const matchNext = next.uri.match(/page=([0-9]*)/);
const matchLast = 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];
@@ -66,9 +65,37 @@ async function* paginateStars(url: string): AsyncGenerator<Stars> {
export async function apiGetStar(
url: string = API_STARRED_URL
): Promise<ApiGetStarResponse> {
let data: Stars[] = [];
const data: Partial<Star>[] = [];
for await (const stars of paginateStars(url)) {
data = data.concat(stars);
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;
}
@@ -102,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

@@ -71,9 +71,9 @@ 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'));
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);
});