From 9323ecaf396ef065b9973292b88a372a02644571 Mon Sep 17 00:00:00 2001 From: Dirk Wilden Date: Tue, 25 Jan 2022 09:33:12 +0100 Subject: [PATCH 1/5] make confluence engine more configurable --- src/engines/confluence.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/engines/confluence.ts b/src/engines/confluence.ts index d7d5d68..d08a17a 100644 --- a/src/engines/confluence.ts +++ b/src/engines/confluence.ts @@ -11,13 +11,18 @@ const normalize = (wikiMarkup: string) => .replace(/@@@(end)?hl@@@/g, "") .replace(/\s+/g, " "); +type DocumentType = "blogpost" | "page" | "comment" | "attachment"; + +let documentTypes: DocumentType[]; + const engine: Engine = { id: "confluence", - init: (options: { origin: string; token: string; user: string }) => { + init: (options: { origin: string; token: string; user: string, documentTypes: DocumentType[]|undefined}) => { client = axios.create({ auth: { password: options.token, username: options.user }, baseURL: `${options.origin}/wiki/rest/api`, }); + documentTypes = options.documentTypes ? options.documentTypes : ["page"]; }, name: "Confluence", search: async q => { @@ -31,32 +36,36 @@ const engine: Engine = { results: { content?: { status: "current" | "draft" | "historical" | "trashed"; - type: "blogpost" | "page"; + type: DocumentType; }; excerpt: string; /** e.g. "2020-06-30T19:04:37.644Z" */ lastModified: string; title: string; + resultGlobalContainer: { + title: string; + }; url: string; }[]; } = ( await client.get("/search", { params: { - cql: `(type = page) AND (text ~ "${escapeQuotes( + cql: `(type in (${documentTypes.join(',')})) AND (text ~ "${escapeQuotes( q, )}") OR (title ~ "${escapeQuotes(q)}")`, limit: 1000, }, }) ).data; + return data.results .filter( - r => r.content?.status === "current" && r.content?.type === "page", + r => r.content?.status === "current", ) .map(r => ({ modified: getUnixTime(r.lastModified), snippet: normalize(r.excerpt), - title: normalize(r.title), + title: `${r.resultGlobalContainer ? '[' + r.resultGlobalContainer.title + '] ' : ''}${normalize(r.title)}`, url: `${data._links.base}${r.url}`, })); }, From d3c0fd20b8ebdb77a269e23384384799b324650b Mon Sep 17 00:00:00 2001 From: Dirk Wilden Date: Tue, 25 Jan 2022 09:33:34 +0100 Subject: [PATCH 2/5] trim jira results --- src/engines/jira.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/engines/jira.ts b/src/engines/jira.ts index 46f96a6..f395def 100644 --- a/src/engines/jira.ts +++ b/src/engines/jira.ts @@ -1,6 +1,6 @@ import axios, { AxiosInstance } from "axios"; -import { escapeQuotes, getUnixTime } from "../util"; +import { escapeQuotes, getUnixTime, trimLines } from "../util"; let client: AxiosInstance | undefined; let origin: string | undefined; @@ -46,7 +46,7 @@ const engine: Engine = { ).data; return data.issues.map(issue => ({ modified: getUnixTime(issue.fields.updated), - snippet: issue.renderedFields.description, + snippet: trimLines(issue.renderedFields.description, q), title: `${issue.key}: ${issue.fields.summary}`, url: `${origin}/browse/${issue.key}`, })); From 836faca67675147dedeea22e50c0194bdfe73094 Mon Sep 17 00:00:00 2001 From: Dirk Wilden Date: Tue, 25 Jan 2022 09:33:52 +0100 Subject: [PATCH 3/5] improve hound engine --- src/engines/hound.ts | 15 ++++++++++++--- src/ui/definitions.d.ts | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/engines/hound.ts b/src/engines/hound.ts index 262e216..dccfd31 100644 --- a/src/engines/hound.ts +++ b/src/engines/hound.ts @@ -3,22 +3,31 @@ import * as he from "he"; let client: AxiosInstance | undefined; let org: string | undefined; +let host: string; + +let displayName: string; const engine: Engine = { id: "hound", init: ({ + name, + codeHost, organization, origin, }: { + name: string | undefined; + codeHost: string | undefined; organization: string; origin: string; }) => { client = axios.create({ baseURL: `${origin}/api/v1` }); org = organization; + displayName = name ? name : "hound"; + host = codeHost ? codeHost : "https://github.com" }, - name: "Hound", + name: () => displayName, search: async q => { - if (!(client && org)) { + if (!(client && host)) { throw Error("Engine not initialized"); } @@ -53,7 +62,7 @@ const engine: Engine = { ? "(Line too long to display)" : `${he.encode(Line)}`, title: `${repo}/${Filename}#L${LineNumber}`, - url: `https://github.com/${org}/${repo}/blob/master/${Filename}#L${LineNumber}`, + url: `${host}/${org}/${repo}/blob/master/${Filename}#L${LineNumber}`, })), ), ) diff --git a/src/ui/definitions.d.ts b/src/ui/definitions.d.ts index 3022613..e3c07e8 100644 --- a/src/ui/definitions.d.ts +++ b/src/ui/definitions.d.ts @@ -5,7 +5,7 @@ interface Engine { id: string; init: (options: object) => void | Promise; isSnippetLarge?: boolean; - name: string; + name: string | (() => string); search: (q: string) => Promise; } From ee38552caa2f0b1c42d3ee660b3f8921d6990545 Mon Sep 17 00:00:00 2001 From: Dirk Wilden Date: Tue, 25 Jan 2022 09:39:44 +0100 Subject: [PATCH 4/5] add changes to sample config --- config.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/config.yaml b/config.yaml index 861eed2..1763b18 100644 --- a/config.yaml +++ b/config.yaml @@ -37,6 +37,8 @@ engines: token: Ex4mp1eEx4mp1eEx4mp1eEx4 # Atlassian user who owns the API token user: admin@example.com + # optional list of document types to be searched. defaults to [page] + documentTypes: [page, blogpost, comment] # Dropbox files and folders dropbox: @@ -123,7 +125,9 @@ engines: # Hound-indexed code: https://github.com/hound-search/hound hound: - # GitHub organization + # base url of code hoster. defaults to https://github.com + codeHost: https://github.com + # optional: GitHub organization organization: example # Hound server URL origin origin: https://hound.example.com From b0ece59e010f6752f82a0da5f15d6caa26f46b22 Mon Sep 17 00:00:00 2001 From: Dirk Wilden Date: Tue, 25 Jan 2022 09:39:54 +0100 Subject: [PATCH 5/5] make organization optional --- src/engines/hound.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engines/hound.ts b/src/engines/hound.ts index dccfd31..6d99df3 100644 --- a/src/engines/hound.ts +++ b/src/engines/hound.ts @@ -17,7 +17,7 @@ const engine: Engine = { }: { name: string | undefined; codeHost: string | undefined; - organization: string; + organization: string | undefined; origin: string; }) => { client = axios.create({ baseURL: `${origin}/api/v1` });