From 12772a096fad3aea74196d4b1fd4e014aa00e4a3 Mon Sep 17 00:00:00 2001 From: Robert Halter Date: Tue, 19 Sep 2023 23:13:40 +0000 Subject: [PATCH 1/8] declare module --- githubApi.d.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/githubApi.d.ts b/githubApi.d.ts index cf7cfe0..bd24c1b 100644 --- a/githubApi.d.ts +++ b/githubApi.d.ts @@ -1 +1,4 @@ -declare module "githubApi"; +// declare here a module with name github-api-get +declare module "github-api-get"; + +// TODO declare function type From 26d96ad2ae99a4a4cd1a30f315a24f60cf9de473 Mon Sep 17 00:00:00 2001 From: Robert Halter Date: Tue, 19 Sep 2023 23:17:00 +0000 Subject: [PATCH 2/8] rename impl --- githubApi.d.ts => githubApiGet.d.ts | 0 githubApi.js => githubApiGet.js | 0 githubApi.ts => githubApiGet.ts | 0 test.ts | 2 +- 4 files changed, 1 insertion(+), 1 deletion(-) rename githubApi.d.ts => githubApiGet.d.ts (100%) rename githubApi.js => githubApiGet.js (100%) rename githubApi.ts => githubApiGet.ts (100%) diff --git a/githubApi.d.ts b/githubApiGet.d.ts similarity index 100% rename from githubApi.d.ts rename to githubApiGet.d.ts diff --git a/githubApi.js b/githubApiGet.js similarity index 100% rename from githubApi.js rename to githubApiGet.js diff --git a/githubApi.ts b/githubApiGet.ts similarity index 100% rename from githubApi.ts rename to githubApiGet.ts diff --git a/test.ts b/test.ts index 23bea6f..e7caec9 100644 --- a/test.ts +++ b/test.ts @@ -1,5 +1,5 @@ import test from "ava"; -import { getGithubTopics } from "./githubApi.js"; +import { getGithubTopics } from "./githubApiGet.js"; test("foo", (t) => { t.pass(); From 5dc5fa5b4fd5bf62f6ff7ec5a8a9fd8c9a13eece Mon Sep 17 00:00:00 2001 From: Robert Halter Date: Tue, 19 Sep 2023 23:19:56 +0000 Subject: [PATCH 3/8] align package.json filenames --- package.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 1847fec..20fa0ad 100644 --- a/package.json +++ b/package.json @@ -1,24 +1,24 @@ { "name": "github-api-get", - "version": "0.3.5", + "version": "0.3.6", "description": "use github api", "type": "module", "exports": { ".": { - "types": "./githubApi.d.ts", - "module": "./githubApi.js", - "import": "./githubApi.js", - "default": "./githubApi.js" + "types": "./githubApiGet.d.ts", + "module": "./githubApiGet.js", + "import": "./githubApiGet.js", + "default": "./githubApiGet.js" }, "./package.json": "./package.json" }, - "types": "./githubApi.d.ts", + "types": "./githubApiGet.d.ts", "files": [ - "./githubApi.d.ts", - "./githubApi.ts", + "./githubApiGet.d.ts", + "./githubApiGet.ts", "./decs.d.ts", "./consts.ts", - "./githubApi.js", + "./githubApiGet.js", "./consts.js", "LICENSE", "README.md" From 86b2e026916078e62b3b9e45ecb0e5cf64c07eda Mon Sep 17 00:00:00 2001 From: Robert Halter Date: Tue, 19 Sep 2023 23:29:53 +0000 Subject: [PATCH 4/8] update README.md code example --- README.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4a088b1..e01f2f9 100644 --- a/README.md +++ b/README.md @@ -16,13 +16,19 @@ npm install github-api-get ```javascript --- -import { getGithubTopics } from "./githubApi.js"; +// in a module +export {} -// async ... getGithubTopics from github: +// import the function from the library +import { getGithubTopics } from "github-api-get"; + +// define a example usage function +export async function getGithubTopicsFromGithub() { const loginName = "roebi"; const projectName = "01-01-vanilla-HTML5-starter-page"; const infoLog = true; const isProd = true; + const githubTopics = getGithubTopics(loginName, projectName, infoLog, isProd) as Promise; const realGithubTopics = await githubTopics; @@ -30,7 +36,11 @@ import { getGithubTopics } from "./githubApi.js"; console.info("realGithubTopics"); console.info(realGithubTopics); console.groupEnd(); +} + +await getGithubTopicsFromGithub(); +// TODO ... // if you need a part of the project information // github-api.project.topics From 6f2d6fa72a0cf21cacde93369f13ddad173385ea Mon Sep 17 00:00:00 2001 From: Robert Halter Date: Tue, 19 Sep 2023 23:30:53 +0000 Subject: [PATCH 5/8] update code example --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e01f2f9..f016f6d 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ export async function getGithubTopicsFromGithub() { console.groupEnd(); } +// run the example await getGithubTopicsFromGithub(); // TODO ... From 1ed451d680d9be47be9fc553d3dfa6ea04cc8b15 Mon Sep 17 00:00:00 2001 From: Robert Halter Date: Tue, 19 Sep 2023 23:33:40 +0000 Subject: [PATCH 6/8] update code example --- README.md | 2 +- test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f016f6d..b60f23e 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ npm install github-api-get ```javascript --- // in a module -export {} +export {}; // import the function from the library import { getGithubTopics } from "github-api-get"; diff --git a/test.js b/test.js index f200a97..4bd6a0d 100644 --- a/test.js +++ b/test.js @@ -1,5 +1,5 @@ import test from "ava"; -import { getGithubTopics } from "./githubApi.js"; +import { getGithubTopics } from "./githubApiGet.js"; test("foo", (t) => { t.pass(); }); From 905e03b03d5ff87da4b4450f0256521b93462045 Mon Sep 17 00:00:00 2001 From: Robert Halter Date: Tue, 19 Sep 2023 23:36:30 +0000 Subject: [PATCH 7/8] npm install , npm run compile --- githubApiGet.js | 92 +++++++++++++++++++++++------------------------ package-lock.json | 4 +-- test.js | 54 ++++++++++++++-------------- 3 files changed, 75 insertions(+), 75 deletions(-) diff --git a/githubApiGet.js b/githubApiGet.js index 613b6bb..9c4bdb7 100644 --- a/githubApiGet.js +++ b/githubApiGet.js @@ -16,25 +16,26 @@ import { GITHUB_API_BASE_URL } from "./consts.js"; * @returns {Promise} The github topics of a project */ export async function getGithubTopics(loginName, projectName, infoLog, isProd) { - if (infoLog) { - console.group("getGithubTopics"); - } - if (loginName && projectName) { if (infoLog) { - console.info("githubApi.ts: loginName: " + loginName); - console.info("githubApi.ts: projectName: " + projectName); + console.group("getGithubTopics"); } - if (infoLog) { - console.groupEnd(); + if (loginName && projectName) { + if (infoLog) { + console.info("githubApi.ts: loginName: " + loginName); + console.info("githubApi.ts: projectName: " + projectName); + } + if (infoLog) { + console.groupEnd(); + } + // https://www.npmjs.com/package/jsonpath MIT License + return Promise.resolve(jp.query(await returnData(loginName, projectName, infoLog, isProd), "$.topics[*]")); } - // https://www.npmjs.com/package/jsonpath MIT License - return Promise.resolve(jp.query(await returnData(loginName, projectName, infoLog, isProd), "$.topics[*]")); - } else { - if (infoLog) { - console.groupEnd(); + else { + if (infoLog) { + console.groupEnd(); + } + return Promise.resolve([]); } - return Promise.resolve([]); - } } /** * Returns the github the project object / json of a project. @@ -49,36 +50,35 @@ export async function getGithubTopics(loginName, projectName, infoLog, isProd) { * @returns {Promise} The github the project object / json of a project */ async function returnData(loginName, projectName, infoLog, isProd) { - if (isProd) { - // get from github project api - const GITHUB_API_PROJECT_URL = GITHUB_API_BASE_URL + "repos/" + loginName + "/"; - const response = await fetch(GITHUB_API_PROJECT_URL + projectName); - if (!response.ok) { - if (infoLog) { - console.info( - "API rate limit exceeded for nnn.nnn.nnn.nnn. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)", - ); - console.info("https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting"); - } - // Github has a Rate Limit - // in this case Status is 403 Forbidden - // and return this Message Object / Json: - // { - // message: "API rate limit exceeded for nnn.nnn.nnn.nnn. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)", - // documentation_url: 'https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting' - // } + if (isProd) { + // get from github project api + const GITHUB_API_PROJECT_URL = GITHUB_API_BASE_URL + "repos/" + loginName + "/"; + const response = await fetch(GITHUB_API_PROJECT_URL + projectName); + if (!response.ok) { + if (infoLog) { + console.info("API rate limit exceeded for nnn.nnn.nnn.nnn. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)"); + console.info("https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting"); + } + // Github has a Rate Limit + // in this case Status is 403 Forbidden + // and return this Message Object / Json: + // { + // message: "API rate limit exceeded for nnn.nnn.nnn.nnn. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)", + // documentation_url: 'https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting' + // } + } + return await response.json(); + } + else { + // return mock data + // based on + // github-api/01-01-vanilla-HTML5-starter-page.json + return Promise.resolve({ + name: "01-01-vanilla-HTML5-starter-page", + html_url: "https://github.com/roebi/01-01-vanilla-HTML5-starter-page", + description: "vanilla HTML 5 starter page - Have you ever heard of this HTML 5 tags ?", + homepage: "https://roebi.github.io/01-01-vanilla-HTML5-starter-page/", + topics: [" mockdata!", "html5", "html5-template", "roebi", "starter"], + }); } - return await response.json(); - } else { - // return mock data - // based on - // github-api/01-01-vanilla-HTML5-starter-page.json - return Promise.resolve({ - name: "01-01-vanilla-HTML5-starter-page", - html_url: "https://github.com/roebi/01-01-vanilla-HTML5-starter-page", - description: "vanilla HTML 5 starter page - Have you ever heard of this HTML 5 tags ?", - homepage: "https://roebi.github.io/01-01-vanilla-HTML5-starter-page/", - topics: [" mockdata!", "html5", "html5-template", "roebi", "starter"], - }); - } } diff --git a/package-lock.json b/package-lock.json index ee5fcc5..47c151c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "github-api-get", - "version": "0.3.5", + "version": "0.3.6", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "github-api-get", - "version": "0.3.5", + "version": "0.3.6", "license": "MIT", "dependencies": { "jsonpath": "^1.1.1", diff --git a/test.js b/test.js index 4bd6a0d..7f84cc6 100644 --- a/test.js +++ b/test.js @@ -1,41 +1,41 @@ import test from "ava"; import { getGithubTopics } from "./githubApiGet.js"; test("foo", (t) => { - t.pass(); + t.pass(); }); test("bar", async (t) => { - const bar = Promise.resolve("bar"); - t.is(await bar, "bar"); + const bar = Promise.resolve("bar"); + t.is(await bar, "bar"); }); test("mockdataTopics", async (t) => { - const loginName = "roebi"; - const projectName = "01-01-vanilla-HTML5-starter-page"; - const infoLog = true; - const isProd = false; - const githubTopics = getGithubTopics(loginName, projectName, infoLog, isProd); - t.deepEqual(await githubTopics, [" mockdata!", "html5", "html5-template", "roebi", "starter"]); + const loginName = "roebi"; + const projectName = "01-01-vanilla-HTML5-starter-page"; + const infoLog = true; + const isProd = false; + const githubTopics = getGithubTopics(loginName, projectName, infoLog, isProd); + t.deepEqual(await githubTopics, [" mockdata!", "html5", "html5-template", "roebi", "starter"]); }); test("noTopics", async (t) => { - const loginName = ""; - const projectName = ""; - const infoLog = true; - const isProd = false; - const githubTopics = getGithubTopics(loginName, projectName, infoLog, isProd); - t.deepEqual(await githubTopics, []); + const loginName = ""; + const projectName = ""; + const infoLog = true; + const isProd = false; + const githubTopics = getGithubTopics(loginName, projectName, infoLog, isProd); + t.deepEqual(await githubTopics, []); }); test("prodDataTopics", async (t) => { - const loginName = "roebi"; - const projectName = "01-01-vanilla-HTML5-starter-page"; - const infoLog = true; - const isProd = true; - const githubTopics = getGithubTopics(loginName, projectName, infoLog, isProd); - t.deepEqual(await githubTopics, ["css3", "html5", "html5-template", "roebi", "starter"]); + const loginName = "roebi"; + const projectName = "01-01-vanilla-HTML5-starter-page"; + const infoLog = true; + const isProd = true; + const githubTopics = getGithubTopics(loginName, projectName, infoLog, isProd); + t.deepEqual(await githubTopics, ["css3", "html5", "html5-template", "roebi", "starter"]); }); test("prodDataNoTopicsInvalidProjectName", async (t) => { - const loginName = "roebi"; - const projectName = "project-not-exist"; - const infoLog = true; - const isProd = true; - const githubTopics = getGithubTopics(loginName, projectName, infoLog, isProd); - t.deepEqual(await githubTopics, []); + const loginName = "roebi"; + const projectName = "project-not-exist"; + const infoLog = true; + const isProd = true; + const githubTopics = getGithubTopics(loginName, projectName, infoLog, isProd); + t.deepEqual(await githubTopics, []); }); From 7feb841d0d151b9d584759df1c228bb395abc121 Mon Sep 17 00:00:00 2001 From: Robert Halter Date: Tue, 19 Sep 2023 23:41:27 +0000 Subject: [PATCH 8/8] test and prettier --- coverage/consts.js.html | 2 +- coverage/githubApiGet.js.html | 331 ++++++++ coverage/index.html | 4 +- ...on => coverage-13023-1695166635381-1.json} | 746 +++++++++--------- ...on => coverage-13023-1695166635454-0.json} | 559 +++++++------ githubApiGet.js | 92 +-- test.js | 54 +- 7 files changed, 1059 insertions(+), 729 deletions(-) create mode 100644 coverage/githubApiGet.js.html rename coverage/tmp/{coverage-9368-1695117625248-1.json => coverage-13023-1695166635381-1.json} (99%) rename coverage/tmp/{coverage-9368-1695117625319-0.json => coverage-13023-1695166635454-0.json} (99%) diff --git a/coverage/consts.js.html b/coverage/consts.js.html index cf4cf81..dd1b058 100644 --- a/coverage/consts.js.html +++ b/coverage/consts.js.html @@ -86,7 +86,7 @@

All files consts.js

+ + + + + diff --git a/coverage/index.html b/coverage/index.html index 70d482a..29cf4dc 100644 --- a/coverage/index.html +++ b/coverage/index.html @@ -91,7 +91,7 @@

All files

- githubApi.js + githubApiGet.js
@@ -117,7 +117,7 @@

All files