Skip to content
Merged
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
4 changes: 2 additions & 2 deletions packages/sources/confluence/src/confluence.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ describe("Confluence E2E", () => {
const { llm } = createConfluenceClient(context);

it("llm.getUserActivity", async () => {
const items = await llm.getUserActivity({
const report = await llm.getUserActivity({
username,
fromDate: prettyDate("prev month"),
});
console.log(items.join("\n\n"));
console.log(report);
});

it("llm.getPage by pageUrl", async () => {
Expand Down
45 changes: 31 additions & 14 deletions packages/sources/confluence/src/llm/get-user-activity.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { formatDate } from "@analtools/zerocrat-source-utils";

import * as api from "../api";
import type { ConfluenceApiContext } from "../types";
import { getFileCategory } from "../utils";
Expand All @@ -9,12 +11,21 @@ export async function getUserActivity(
fromDate?: Date;
toDate?: Date;
},
): Promise<string[]> {
): Promise<string> {
const events = await api.getUserActivity(context, options);

const { username } = options;

return events.map((event) => {
const result: string[] = [];

result.push(
`# Confluence Activity - ${options.username} - ${options.fromDate ? `from ${formatDate(options.fromDate)} ` : ""}to ${formatDate(options.toDate ?? new Date())}`,
);
result.push(``);
result.push(`CONFLUENCE_HOST = ${context.confluenceHost!}`);
result.push(``);

for (const event of events) {
const spaceLink =
event.namespaceTitle && event.namespaceUrl
? `[${event.namespaceTitle}](${event.namespaceUrl})`
Expand All @@ -33,24 +44,30 @@ export async function getUserActivity(
const fileCategory = getFileCategory(event.title);
const categoryText =
fileCategory === "файл" ? "вложение" : `вложение (${fileCategory})`;
return `📎 @${username} добавил ${categoryText} "${event.title}" к документу "${documentTitle}" (${isoDate})`;
}

if (event.type === "comment") {
result.push(
`📎 @${username} добавил ${categoryText} "${event.title}" к документу "${documentTitle}" (${isoDate})`,
);
} else if (event.type === "comment") {
// Берём текст комментария из excerpt, чистим и обрезаем
let commentText = event.excerpt ? event.excerpt.trim() : "Без текста.";
if (!commentText) commentText = "Без текста.";

// Заменяем переносы на пробелы, убираем лишние пробелы
commentText = commentText.replace(/\s+/g, " ");

return `💬 @${username} оставил комментарий: "${commentText}" к документу "💬 ${documentTitle}" (${isoDate})`;
}

if (event.type === "page") {
return `📄 @${username} создал документ "${event.title}" (${isoDate})`;
result.push(
`💬 @${username} оставил комментарий: "${commentText}" к документу "💬 ${documentTitle}" (${isoDate})`,
);
} else if (event.type === "page") {
result.push(
`📄 @${username} создал документ "${event.title}" (${isoDate})`,
);
} else {
result.push(
`⚡ @${username} выполнил действие "${event.title}" к документу "${documentTitle}" (${isoDate})`,
);
}

return `⚡ @${username} выполнил действие "${event.title}" к документу "${documentTitle}" (${isoDate})`;
});
result.push(``);
}
return result.join("\n").trim();
}
4 changes: 2 additions & 2 deletions packages/sources/gitlab/src/llm/get-user-activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function getUserActivity(
const result: string[] = [];

result.push(
`# Gitlab Activity - ${options.username}${options.fromDate ? ` - from ${formatDate(options.fromDate)}` : ""} to ${formatDate(options.toDate ?? new Date())}`,
`# Gitlab Activity - ${options.username} - ${options.fromDate ? `from ${formatDate(options.fromDate)} ` : ""}to ${formatDate(options.toDate ?? new Date())}`,
);

result.push(``);
Expand All @@ -35,8 +35,8 @@ export async function getUserActivity(
result.push(`JIRA_HOST = ${context.jiraHost!}`);
result.push(``);
result.push(await jiraClient.llm.getReportByIssues({ issues }));
result.push(``);
}
result.push(``);

result.push(`## Events`);
for (const event of events) {
Expand Down
2 changes: 1 addition & 1 deletion packages/sources/jira/src/llm/get-user-activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export async function getUserActivity(
}

result.push(
`# Jira Activity - ${usernames.join(",")}${options.fromDate ? ` - from ${formatDate(options.fromDate)}` : ""}${options.toDate ? ` - to ${formatDate(options.toDate ?? new Date())}` : ""}`,
`# Jira Activity - ${usernames.join(",")} - ${options.fromDate ? `from ${formatDate(options.fromDate)} ` : ""}to ${formatDate(options.toDate ?? new Date())}`,
);
result.push(``);

Expand Down
Loading