Skip to content

Commit

Permalink
Spike3: Retrieve and display code errors without using mongodb
Browse files Browse the repository at this point in the history
  • Loading branch information
dsellarsnr committed May 13, 2024
1 parent 317946f commit 0089f82
Show file tree
Hide file tree
Showing 62 changed files with 557 additions and 2,423 deletions.
9 changes: 2 additions & 7 deletions shared/agent/src/api/codestream/codestreamApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -776,12 +776,6 @@ export class CodeStreamApiProvider implements ApiProvider {
await this.fetchAndStoreUnknownAuthors(e.data as CSPost[]);

break;
case MessageType.CodeErrors: {
e.data = await SessionContainer.instance().codeErrors.resolve(e, { onlyIfNeeded: false });
if (e.data == null || e.data.length === 0) return;

break;
}
case MessageType.Streams:
e.data = await SessionContainer.instance().streams.resolve(e, { onlyIfNeeded: false });
if (e.data == null || e.data.length === 0) return;
Expand Down Expand Up @@ -1052,11 +1046,12 @@ export class CodeStreamApiProvider implements ApiProvider {
};
}

return this.post<CSCreatePostRequest, CSCreatePostResponse>(
const result = this.post<CSCreatePostRequest, CSCreatePostResponse>(
`/posts`,
{ ...request, teamId: this.teamId },
tokenHolder.accessToken
);
return result;
}

@log()
Expand Down
22 changes: 0 additions & 22 deletions shared/agent/src/api/codestream/unreads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,34 +154,12 @@ export class CodeStreamUnreads {
if (!repoSettings || !repoSettings.length) return posts;

try {
const codeErrors = (
await SessionContainer.instance().codeErrors.get({
streamIds: streamIds,
})
).codeErrors;

posts = posts
.filter(_ => {
if (_.mentionedUserIds && _.mentionedUserIds.includes(this._api.userId)) {
return _;
}

if (_.codeErrorId) {
const codeError = codeErrors.find(c => c.id === _.codeErrorId);
if (codeError) {
let found: any = undefined;
for (const repoSetting of repoSettings) {
const match = codeError.stackTraces?.find(m => {
return repoSetting.id === m.repoId;
});
found = match ? _ : undefined;
if (found) {
return found;
}
}
return found;
}
}
return undefined;
})
.filter(Boolean);
Expand Down
30 changes: 0 additions & 30 deletions shared/agent/src/api/extensions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use strict";
import {
CSCodeError,
CSCodemark,
CSLocationArray,
CSMarker,
Expand Down Expand Up @@ -423,20 +422,6 @@ export function toActionId(
return JSON.stringify(actionId);
}

export function toCodeErrorActionId(
id: number,
linkType: "web" | "ide" | "code-error-reply",
codeError: CSCodeError
): string {
const actionId: CodeErrorActionId = {
id: id,
codeErrorId: codeError.id,
linkType: linkType,
};

return JSON.stringify(actionId);
}

export function toExternalActionId(
id: number,
providerType: "issue" | "code",
Expand All @@ -457,21 +442,6 @@ export function toExternalActionId(
return JSON.stringify(actionId);
}

export function toCodeErrorReplyActionId(
id: number,
codeError: CSCodeError,
providerCreatorUserId?: string
): string {
const actionId: CodeErrorReplyActionId = {
id: id,
linkType: "code-error-reply",
ceId: codeError.id,
pcuId: providerCreatorUserId,
};

return JSON.stringify(actionId);
}

export function toReviewReplyActionId(
id: number,
review: CSReview,
Expand Down
102 changes: 2 additions & 100 deletions shared/agent/src/api/slack/slackSharingApi.adapters.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use strict";
import { CodeErrorPlus, CodemarkPlus, ReviewPlus } from "@codestream/protocols/agent";
import { CodemarkPlus, ReviewPlus } from "@codestream/protocols/agent";
import {
CodemarkType,
CSChannelStream,
Expand All @@ -15,13 +15,7 @@ import { ActionsBlock, KnownBlock, MessageAttachment } from "@slack/web-api";

import { Logger } from "../../logger";
import { providerDisplayNamesByNameKey } from "../../providers/provider";
import {
Marker,
toActionId,
toCodeErrorActionId,
toExternalActionId,
toReviewActionId,
} from "../extensions";
import { Marker, toActionId, toExternalActionId, toReviewActionId } from "../extensions";

import getProviderDisplayName = Marker.getProviderDisplayName;

Expand Down Expand Up @@ -1047,98 +1041,6 @@ export function toSlackReviewPostBlocks(
return blocks;
}

export function toSlackCodeErrorPostBlocks(
codeError: CodeErrorPlus,
userMaps: UserMaps,
repos?: { [key: string]: CSRepository } | undefined,
slackUserId?: string
): Blocks {
const blocks: Blocks = [];
const creator = userMaps.codeStreamUsersByUserId.get(codeError.creatorId);
let creatorName = "Someone ";
if (creator && creator.username) {
creatorName = `${creator.username} `;
}
blocks.push({
type: "context",
elements: [
{
type: "mrkdwn",
text: `${creatorName}is diagnosing an issue`,
},
],
});

if (codeError.title) {
blocks.push({
type: "section",
text: {
type: "mrkdwn",
text: toSlackText(codeError.title, userMaps),
},
});
}

if (codeError.stackTraces && codeError.stackTraces[0]) {
// 9 = ```*2 + ...
const stackTrace = codeError.stackTraces[0].text || (codeError as any).stackTrace || "";
const contentLength = stackTrace.length + 9;
const isTruncated = contentLength > slackBlockTextCodeMax;
blocks.push({
type: "section",
text: {
type: "mrkdwn",
text: `\`\`\`${stackTrace.substring(0, slackBlockTextCodeMax - 9)}${
isTruncated ? "..." : ""
}\`\`\``,
},
});

if (isTruncated) {
blocks.push(blockTruncated());
}
}

const permalink = codeError.permalink;
if (permalink) {
const counter = 0;
const actionId = toCodeErrorActionId(counter, "ide", codeError);
const actions: ActionsBlock = {
type: "actions",
block_id: "codeerror_actions",
elements: [
{
type: "button",
action_id: actionId,
text: {
type: "plain_text",
text: "Open in IDE",
},
url: `${permalink}?ide=default&src=${encodeURIComponent(
providerDisplayNamesByNameKey.get("slack") || ""
)}`,
},
],
};

blocks.push(actions);
}

blocks.push({
type: "context",
// MUST keep this data in sync with codemarkAttachmentRegex above
block_id: `codestream://review/${codeError.id}?teamId=${codeError.teamId}`,
elements: [
{
type: "plain_text",
text: "Replies in thread will be shared to CodeStream",
},
],
});

return blocks;
}

export function toSlackTextPostBlocks(
text: string,
parentText?: string,
Expand Down
6 changes: 0 additions & 6 deletions shared/agent/src/api/slack/slackSharingApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import {
fromSlackPost,
fromSlackPostId,
fromSlackUser,
toSlackCodeErrorPostBlocks,
toSlackPostBlocks,
toSlackPostText,
toSlackReviewPostBlocks,
Expand Down Expand Up @@ -428,11 +427,6 @@ export class SlackSharingApiProvider {
text = `${review.title || ""}${review.title && review.text ? `\n\n` : ""}${
review.text || ""
}`;
} else if (request.codeError != null) {
const codeError = request.codeError;
blocks = toSlackCodeErrorPostBlocks(codeError, userMaps, repoHash, this._slackUserId);
// Set the fallback (notification) content for the message
text = `${codeError.title}`;
} else if (text) {
blocks = toSlackTextPostBlocks(text, request.parentText, request.files);
}
Expand Down
8 changes: 0 additions & 8 deletions shared/agent/src/container.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
"use strict";
import { CodeStreamAgent } from "agent";
import { DocumentManager } from "./documentManager";
import { ErrorReporter } from "./errorReporter";
import { GitService } from "./git/gitService";
import { GitServiceLite } from "./git/gitServiceLite";
import { RepositoryLocator } from "./git/repositoryLocator";
import { Logger } from "./logger";
import { CodeErrorsManager } from "./managers/codeErrorsManager";
import { CompaniesManager } from "./managers/companiesManager";
import { FilesManager } from "./managers/filesManager";
import { IgnoreFilesManager } from "./managers/ignoreFilesManager";
Expand Down Expand Up @@ -96,11 +94,6 @@ export class SessionServiceContainer {
return this._textFiles;
}

private readonly _codeErrors: CodeErrorsManager;
get codeErrors() {
return this._codeErrors;
}

private readonly _nr: NRManager;
get nr() {
return this._nr;
Expand All @@ -126,7 +119,6 @@ export class SessionServiceContainer {
this._companies = new CompaniesManager(session);
this._ignoreFiles = new IgnoreFilesManager(session);
this._textFiles = new TextFilesManager(session);
this._codeErrors = new CodeErrorsManager(session);
this._nr = new NRManager(session);
this._repoIdentifier = new RepoIdentificationManager(session);
}
Expand Down
1 change: 0 additions & 1 deletion shared/agent/src/managers/baseManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ export abstract class ManagerBase<T> {

cacheResponse(response: any) {
const container = SessionContainer.instance();
this.cacheResponseEntities(container.codeErrors, response.codeErrors);
this.cacheResponseEntities(container.companies, response.companies);
this.cacheResponseEntities(container.posts, response.posts);
this.cacheResponseEntities(container.streams, response.streams);
Expand Down
96 changes: 0 additions & 96 deletions shared/agent/src/managers/codeErrorsManager.ts

This file was deleted.

Loading

0 comments on commit 0089f82

Please sign in to comment.