From e880e9d38d5c81ad446a59f42c13269cbb2eddfc Mon Sep 17 00:00:00 2001 From: Tianhao Zhou Date: Wed, 26 May 2021 00:05:05 -0700 Subject: [PATCH] feat: add custom config capability (#11) --- README.md | 6 +- package-lock.json | 124 ++++++-------------- package.json | 2 +- src/builtin_fetchers/github_fetcher.test.ts | 20 +++- src/builtin_fetchers/github_fetcher.ts | 5 +- 5 files changed, 67 insertions(+), 90 deletions(-) diff --git a/README.md b/README.md index 319b5e6..4e50b69 100644 --- a/README.md +++ b/README.md @@ -1 +1,5 @@ -# wow-lookup-fetcher \ No newline at end of file +# WOW Lookup Fetcher + +```bash +npm login --scope=@wowlink --registry=https://npm.pkg.github.com +``` diff --git a/package-lock.json b/package-lock.json index 1890f89..e99b3e3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "MIT", "dependencies": { "@octokit/rest": "^18.5.3", - "@wowlink/wow-interface": "^1.3.2", + "@wowlink/wow-interface": "^1.4.0", "js-yaml": "^4.1.0" }, "devDependencies": { @@ -2749,9 +2749,9 @@ "dev": true }, "node_modules/@wowlink/wow-interface": { - "version": "1.3.2", - "resolved": "https://npm.pkg.github.com/download/@wowlink/wow-interface/1.3.2/fd4923a051193c727ee69a388bac16d6e3d5dc4214647c67545824c9112bdcc2", - "integrity": "sha512-DuV0AlenOtG9O1teIqqkKAa3HRJHAC3JmkXCX5m7ZP9Z8YbSlpB36HfS3TdNJ7XXHAo0N9KWbQFu6llvyagoVw==", + "version": "1.4.0", + "resolved": "https://npm.pkg.github.com/download/@wowlink/wow-interface/1.4.0/9472d2d7979d2fdb911876944bbe0cca9e24a8df5ecf58c1d678007582175e4a", + "integrity": "sha512-gcta+yI63wel/AhPguLZ/SU7VFpVuJO7gSvdxg4Lx9NvbIP2wOpDaabv/slbH/MVhTADK227r9yb4sqsfGAO8g==", "license": "MIT" }, "node_modules/abab": { @@ -3350,14 +3350,14 @@ "dev": true }, "node_modules/browserslist": { - "version": "4.16.4", - "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.16.4.tgz", - "integrity": "sha512-d7rCxYV8I9kj41RH8UKYnvDYCRENUlHRgyXy/Rhr/1BaeLGfiCptEdFE8MIrvGfWbBFNjVYx76SQWvNX1j+/cQ==", + "version": "4.16.6", + "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.16.6.tgz", + "integrity": "sha512-Wspk/PqO+4W9qp5iUTJsa1B/QrYn1keNCcEP5OvP7WBwT4KaDly0uONYmC6Xa3Z5IqnUgS0KcgLYu1l74x0ZXQ==", "dev": true, "dependencies": { - "caniuse-lite": "^1.0.30001208", + "caniuse-lite": "^1.0.30001219", "colorette": "^1.2.2", - "electron-to-chromium": "^1.3.712", + "electron-to-chromium": "^1.3.723", "escalade": "^3.1.1", "node-releases": "^1.1.71" }, @@ -3366,6 +3366,10 @@ }, "engines": { "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/browserslist" } }, "node_modules/bser": { @@ -3446,10 +3450,14 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001209", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001209.tgz", - "integrity": "sha512-2Ktt4OeRM7EM/JaOZjuLzPYAIqmbwQMNnYbgooT+icoRGrKOyAxA1xhlnotBD1KArRSPsuJp3TdYcZYrL7qNxA==", - "dev": true + "version": "1.0.30001230", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001230.tgz", + "integrity": "sha512-5yBd5nWCBS+jWKTcHOzXwo5xzcj4ePE/yjtkZyUV1BTUmrBaA9MRGC+e7mxnqXSA90CmCA8L3eKLaSUkt099IQ==", + "dev": true, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/browserslist" + } }, "node_modules/capture-exit": { "version": "2.0.0", @@ -3768,37 +3776,6 @@ "semver": "7.0.0" } }, - "node_modules/core-js-compat/node_modules/browserslist": { - "version": "4.16.6", - "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.16.6.tgz", - "integrity": "sha512-Wspk/PqO+4W9qp5iUTJsa1B/QrYn1keNCcEP5OvP7WBwT4KaDly0uONYmC6Xa3Z5IqnUgS0KcgLYu1l74x0ZXQ==", - "dev": true, - "dependencies": { - "caniuse-lite": "^1.0.30001219", - "colorette": "^1.2.2", - "electron-to-chromium": "^1.3.723", - "escalade": "^3.1.1", - "node-releases": "^1.1.71" - }, - "bin": { - "browserslist": "cli.js" - }, - "engines": { - "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" - } - }, - "node_modules/core-js-compat/node_modules/caniuse-lite": { - "version": "1.0.30001219", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001219.tgz", - "integrity": "sha512-c0yixVG4v9KBc/tQ2rlbB3A/bgBFRvl8h8M4IeUbqCca4gsiCfvtaheUssbnux/Mb66Vjz7x8yYjDgYcNQOhyQ==", - "dev": true - }, - "node_modules/core-js-compat/node_modules/electron-to-chromium": { - "version": "1.3.725", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.725.tgz", - "integrity": "sha512-2BbeAESz7kc6KBzs7WVrMc1BY5waUphk4D4DX5dSQXJhsc3tP5ZFaiyuL0AB7vUKzDYpIeYwTYlEfxyjsGUrhw==", - "dev": true - }, "node_modules/core-js-compat/node_modules/semver": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/semver/-/semver-7.0.0.tgz", @@ -4220,9 +4197,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.3.717", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.717.tgz", - "integrity": "sha512-OfzVPIqD1MkJ7fX+yTl2nKyOE4FReeVfMCzzxQS+Kp43hZYwHwThlGP+EGIZRXJsxCM7dqo8Y65NOX/HP12iXQ==", + "version": "1.3.739", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.739.tgz", + "integrity": "sha512-+LPJVRsN7hGZ9EIUUiWCpO7l4E3qBYHNadazlucBfsXBbccDFNKUBAgzE68FnkWGJPwD/AfKhSzL+G+Iqb8A4A==", "dev": true }, "node_modules/emittery": { @@ -16884,9 +16861,9 @@ "dev": true }, "@wowlink/wow-interface": { - "version": "1.3.2", - "resolved": "https://npm.pkg.github.com/download/@wowlink/wow-interface/1.3.2/fd4923a051193c727ee69a388bac16d6e3d5dc4214647c67545824c9112bdcc2", - "integrity": "sha512-DuV0AlenOtG9O1teIqqkKAa3HRJHAC3JmkXCX5m7ZP9Z8YbSlpB36HfS3TdNJ7XXHAo0N9KWbQFu6llvyagoVw==" + "version": "1.4.0", + "resolved": "https://npm.pkg.github.com/download/@wowlink/wow-interface/1.4.0/9472d2d7979d2fdb911876944bbe0cca9e24a8df5ecf58c1d678007582175e4a", + "integrity": "sha512-gcta+yI63wel/AhPguLZ/SU7VFpVuJO7gSvdxg4Lx9NvbIP2wOpDaabv/slbH/MVhTADK227r9yb4sqsfGAO8g==" }, "abab": { "version": "2.0.5", @@ -17375,14 +17352,14 @@ "dev": true }, "browserslist": { - "version": "4.16.4", - "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.16.4.tgz", - "integrity": "sha512-d7rCxYV8I9kj41RH8UKYnvDYCRENUlHRgyXy/Rhr/1BaeLGfiCptEdFE8MIrvGfWbBFNjVYx76SQWvNX1j+/cQ==", + "version": "4.16.6", + "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.16.6.tgz", + "integrity": "sha512-Wspk/PqO+4W9qp5iUTJsa1B/QrYn1keNCcEP5OvP7WBwT4KaDly0uONYmC6Xa3Z5IqnUgS0KcgLYu1l74x0ZXQ==", "dev": true, "requires": { - "caniuse-lite": "^1.0.30001208", + "caniuse-lite": "^1.0.30001219", "colorette": "^1.2.2", - "electron-to-chromium": "^1.3.712", + "electron-to-chromium": "^1.3.723", "escalade": "^3.1.1", "node-releases": "^1.1.71" } @@ -17453,9 +17430,9 @@ } }, "caniuse-lite": { - "version": "1.0.30001209", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001209.tgz", - "integrity": "sha512-2Ktt4OeRM7EM/JaOZjuLzPYAIqmbwQMNnYbgooT+icoRGrKOyAxA1xhlnotBD1KArRSPsuJp3TdYcZYrL7qNxA==", + "version": "1.0.30001230", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001230.tgz", + "integrity": "sha512-5yBd5nWCBS+jWKTcHOzXwo5xzcj4ePE/yjtkZyUV1BTUmrBaA9MRGC+e7mxnqXSA90CmCA8L3eKLaSUkt099IQ==", "dev": true }, "capture-exit": { @@ -17719,31 +17696,6 @@ "semver": "7.0.0" }, "dependencies": { - "browserslist": { - "version": "4.16.6", - "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.16.6.tgz", - "integrity": "sha512-Wspk/PqO+4W9qp5iUTJsa1B/QrYn1keNCcEP5OvP7WBwT4KaDly0uONYmC6Xa3Z5IqnUgS0KcgLYu1l74x0ZXQ==", - "dev": true, - "requires": { - "caniuse-lite": "^1.0.30001219", - "colorette": "^1.2.2", - "electron-to-chromium": "^1.3.723", - "escalade": "^3.1.1", - "node-releases": "^1.1.71" - } - }, - "caniuse-lite": { - "version": "1.0.30001219", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001219.tgz", - "integrity": "sha512-c0yixVG4v9KBc/tQ2rlbB3A/bgBFRvl8h8M4IeUbqCca4gsiCfvtaheUssbnux/Mb66Vjz7x8yYjDgYcNQOhyQ==", - "dev": true - }, - "electron-to-chromium": { - "version": "1.3.725", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.725.tgz", - "integrity": "sha512-2BbeAESz7kc6KBzs7WVrMc1BY5waUphk4D4DX5dSQXJhsc3tP5ZFaiyuL0AB7vUKzDYpIeYwTYlEfxyjsGUrhw==", - "dev": true - }, "semver": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/semver/-/semver-7.0.0.tgz", @@ -18091,9 +18043,9 @@ } }, "electron-to-chromium": { - "version": "1.3.717", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.717.tgz", - "integrity": "sha512-OfzVPIqD1MkJ7fX+yTl2nKyOE4FReeVfMCzzxQS+Kp43hZYwHwThlGP+EGIZRXJsxCM7dqo8Y65NOX/HP12iXQ==", + "version": "1.3.739", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.739.tgz", + "integrity": "sha512-+LPJVRsN7hGZ9EIUUiWCpO7l4E3qBYHNadazlucBfsXBbccDFNKUBAgzE68FnkWGJPwD/AfKhSzL+G+Iqb8A4A==", "dev": true }, "emittery": { diff --git a/package.json b/package.json index 911e0e3..0ac7ec5 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ }, "dependencies": { "@octokit/rest": "^18.5.3", - "@wowlink/wow-interface": "^1.3.2", + "@wowlink/wow-interface": "^1.4.0", "js-yaml": "^4.1.0" } } diff --git a/src/builtin_fetchers/github_fetcher.test.ts b/src/builtin_fetchers/github_fetcher.test.ts index 852f0cd..5b70dcf 100644 --- a/src/builtin_fetchers/github_fetcher.test.ts +++ b/src/builtin_fetchers/github_fetcher.test.ts @@ -1,6 +1,10 @@ import { WowLookupFetcherConfig, WowLookupFetchRequest, WowLookupFetchResponse } from "@wowlink/wow-interface"; import { GitHubWowLookupFetcher } from "./github_fetcher"; +/** + * Note that some of the tests use https://github.com/wowlink/dev-config + * as the example configuration to fetch. + */ describe("GitHub fetcher tests", () => { test("Initialize GitHub fetcher", () => { const config: WowLookupFetcherConfig = { @@ -14,7 +18,7 @@ describe("GitHub fetcher tests", () => { test("Fetch repository config", async () => { const config: WowLookupFetcherConfig = { githubUser: "wowlink", - githubRepository: "default-profile", + githubRepository: "dev-config", }; const fetcher: GitHubWowLookupFetcher = new GitHubWowLookupFetcher(config); const request: WowLookupFetchRequest = {}; @@ -23,4 +27,18 @@ describe("GitHub fetcher tests", () => { const mapping: Record = response.wowMapping; expect(mapping["gh"]).toMatch("https://github.com"); }); + + test("Custom configuration filename", async () => { + const config: WowLookupFetcherConfig = { + githubUser: "wowlink", + githubRepository: "dev-config", + githubConfigFilename: "alternative-config.yaml" + }; + const fetcher: GitHubWowLookupFetcher = new GitHubWowLookupFetcher(config); + const request: WowLookupFetchRequest = {}; + const response: WowLookupFetchResponse = await fetcher.fetch(request); + expect(response.wowMapping).toBeDefined(); + const mapping: Record = response.wowMapping; + expect(mapping["gh/me"]).toMatch("https://github.com/tianhaoz95"); + }); }); \ No newline at end of file diff --git a/src/builtin_fetchers/github_fetcher.ts b/src/builtin_fetchers/github_fetcher.ts index dab3e32..7957626 100644 --- a/src/builtin_fetchers/github_fetcher.ts +++ b/src/builtin_fetchers/github_fetcher.ts @@ -17,10 +17,13 @@ class GitHubWowLookupFetcher implements WowLookupFetcher { async fetch(req: WowLookupFetchRequest): Promise { if (this.config_.githubUser && this.config_.githubRepository) { const octokit = new Octokit(); + const configFilename: string = + this.config_.githubConfigFilename + ? this.config_.githubConfigFilename : "config.yaml"; const configResponse = await octokit.rest.repos.getContent({ owner: this.config_.githubUser, repo: this.config_.githubRepository, - path: "config.yaml", + path: configFilename, }); const configStr = Buffer.from( configResponse.data["content"], "base64").toString();