Skip to content

Commit

Permalink
feat: add custom config capability (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
tianhaoz95 authored May 26, 2021
1 parent 9a81261 commit e880e9d
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 90 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# wow-lookup-fetcher
# WOW Lookup Fetcher

```bash
npm login --scope=@wowlink --registry=https://npm.pkg.github.com
```
124 changes: 38 additions & 86 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 @@ -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"
}
}
20 changes: 19 additions & 1 deletion src/builtin_fetchers/github_fetcher.test.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -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 = {};
Expand All @@ -23,4 +27,18 @@ describe("GitHub fetcher tests", () => {
const mapping: Record<string, string> = 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<string, string> = response.wowMapping;
expect(mapping["gh/me"]).toMatch("https://github.com/tianhaoz95");
});
});
5 changes: 4 additions & 1 deletion src/builtin_fetchers/github_fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ class GitHubWowLookupFetcher implements WowLookupFetcher {
async fetch(req: WowLookupFetchRequest): Promise<WowLookupFetchResponse> {
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();
Expand Down

0 comments on commit e880e9d

Please sign in to comment.