Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/various fixes #22

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ engines:
token: Ex4mp1eEx4mp1eEx4mp1eEx4
# Atlassian user who owns the API token
user: [email protected]
# optional list of document types to be searched. defaults to [page]
documentTypes: [page, blogpost, comment]

# Dropbox files and folders
dropbox:
Expand Down Expand Up @@ -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
Expand Down
19 changes: 14 additions & 5 deletions src/engines/confluence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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}`,
}));
},
Expand Down
17 changes: 13 additions & 4 deletions src/engines/hound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}: {
organization: string;
name: string | undefined;
codeHost: string | undefined;
organization: string | undefined;
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");
}

Expand Down Expand Up @@ -53,7 +62,7 @@ const engine: Engine = {
? "(Line too long to display)"
: `<code>${he.encode(Line)}</code>`,
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}`,
})),
),
)
Expand Down
4 changes: 2 additions & 2 deletions src/engines/jira.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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}`,
}));
Expand Down
2 changes: 1 addition & 1 deletion src/ui/definitions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ interface Engine {
id: string;
init: (options: object) => void | Promise<void>;
isSnippetLarge?: boolean;
name: string;
name: string | (() => string);
search: (q: string) => Promise<Result[]>;
}

Expand Down