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

Chore/testing #15

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
2200b47
chore: prep
Keyrxng Jul 31, 2024
b84f543
chore: test prep
Keyrxng Aug 5, 2024
254919c
chore: comment metadata parsing
Keyrxng Jul 31, 2024
8ef8cd0
chore: no multi org
Keyrxng Aug 5, 2024
a9d7179
chore: test
Keyrxng Aug 5, 2024
b8597db
fix: cast created_at as date first
Keyrxng Aug 5, 2024
4f3a726
feat: tests
Keyrxng Aug 5, 2024
bed3f95
fix: new date casting
Keyrxng Aug 5, 2024
8174cb7
Merge branch 'refactor/remove-supabase' into chore/testing
Keyrxng Aug 5, 2024
50d680e
chore: fix test env
Keyrxng Aug 5, 2024
0f28006
chore: remove unused
Keyrxng Aug 5, 2024
fcf4a7d
chore: tests
Keyrxng Aug 6, 2024
c1963b7
ci: knip - jest/globals unlisted
Keyrxng Aug 6, 2024
bf670a9
chore: .gitignore
Keyrxng Aug 8, 2024
f88a819
chore: use search API
Keyrxng Aug 12, 2024
60b2c59
chore: search api tests
Keyrxng Aug 12, 2024
c14c338
chore: add v1 support
Keyrxng Aug 16, 2024
55f86c4
chore: fix search query and v1 support
Keyrxng Aug 16, 2024
cfcdfed
chore: duration can be equal to 0
Keyrxng Aug 16, 2024
eebf328
chore: update tests
Keyrxng Aug 16, 2024
7dd82e5
chore: index fix
Keyrxng Aug 16, 2024
c6dfebc
chore: remove packageManager field from package.json
Keyrxng Aug 16, 2024
8902bba
chore: code clean up and verbose logging
Keyrxng Aug 19, 2024
5a295dc
chore: add linked:issue to pr search query
Keyrxng Aug 19, 2024
4901365
chore: move to graphql
Keyrxng Aug 19, 2024
7bfe815
chore: correct prop access
Keyrxng Aug 19, 2024
9215562
chore: omit return false until live
Keyrxng Aug 19, 2024
c8c4039
chore: update tests
Keyrxng Aug 19, 2024
06912a2
chore: knip fix
Keyrxng Aug 19, 2024
2c542cb
chore: graph config and comment
Keyrxng Aug 24, 2024
6bcf0f4
Merge remote-tracking branch 'upstream/development' into chore/testing
Keyrxng Aug 24, 2024
f622182
chore: sync SupportedEvents with manifest
Keyrxng Aug 24, 2024
d908e06
chore: remove unused
Keyrxng Aug 24, 2024
0dcc361
chore: if and throw for null types
Keyrxng Aug 24, 2024
7625c17
chore: refactor test event payload
Keyrxng Aug 24, 2024
53e6838
chore: fix indentation
Keyrxng Aug 24, 2024
bc40396
chore: use filter()
Keyrxng Aug 27, 2024
81afb6a
chore: better fn names
Keyrxng Aug 27, 2024
4a77619
chore: update followup with comment metadata
Keyrxng Aug 27, 2024
b704d0f
chore: track followup with metadata header
Keyrxng Aug 27, 2024
9f1af45
chore: fix test
Keyrxng Aug 27, 2024
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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@octokit/rest": "20.1.1",
"@octokit/webhooks": "13.2.7",
"@sinclair/typebox": "0.32.31",
"@ubiquity-dao/ubiquibot-logger": "^1.3.0",
"@ubiquity-dao/ubiquibot-logger": "^1.3.1",
"dotenv": "16.4.5",
"luxon": "3.4.4",
"ms": "2.1.3",
Expand Down Expand Up @@ -89,4 +89,4 @@
]
},
"packageManager": "[email protected]"
Keyrxng marked this conversation as resolved.
Show resolved Hide resolved
}
}
8 changes: 1 addition & 7 deletions src/helpers/get-assignee-activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ export async function getAssigneesActivityForIssue(context: Context, issue: List
issueEvents.push(...events);
}

return issueEvents
.reduce((acc, event) => {
if (event.actor && event.actor.id) {
if (assigneeIds.includes(event.actor.id)) acc.push(event);
}
return acc;
}, [] as GitHubListEvents[])
return issueEvents.filter((o) => o.actor && o.actor.id && assigneeIds.includes(o.actor.id))
.sort((a, b) => DateTime.fromISO(b.created_at).toMillis() - DateTime.fromISO(a.created_at).toMillis());
}
9 changes: 8 additions & 1 deletion src/helpers/remind-and-remove.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Context } from "../types/context";
import { parseIssueUrl } from "./github-url";
import { ListIssueForRepo } from "../types/github-types";
import { createStructuredMetadata } from "./structured-metadata";

export async function unassignUserFromIssue(context: Context, issue: ListIssueForRepo) {
const { logger, config } = context;
Expand Down Expand Up @@ -36,11 +37,17 @@ async function remindAssignees(context: Context, issue: ListIssueForRepo) {
.filter((o) => !!o)
.join(", @");

const logMessage = logger.info(`@${logins}, this task has been idle for a while. Please provide an update.\n\n`, {
taskAssignees: issue.assignees.map((o) => o?.id),
});

const metadata = createStructuredMetadata("Followup", logMessage);

await octokit.rest.issues.createComment({
owner,
repo,
issue_number,
body: `@${logins}, this task has been idle for a while. Please provide an update.`,
body: [logMessage.logMessage.raw, metadata].join("\n"),
});
return true;
}
Expand Down
28 changes: 28 additions & 0 deletions src/helpers/structured-metadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { LogReturn } from "@ubiquity-dao/ubiquibot-logger";

export function createStructuredMetadata(className: string, logReturn: LogReturn | null) {
let logMessage, metadata;
if (logReturn) {
logMessage = logReturn.logMessage;
metadata = logReturn.metadata;
}

const jsonPretty = JSON.stringify(metadata, null, 2);
const stackLine = new Error().stack?.split("\n")[2] ?? "";
const caller = stackLine.match(/at (\S+)/)?.[1] ?? "";
const ubiquityMetadataHeader = `<!-- Ubiquity - ${className} - ${caller} - ${metadata?.revision}`;

let metadataSerialized: string;
const metadataSerializedVisible = ["```json", jsonPretty, "```"].join("\n");
const metadataSerializedHidden = [ubiquityMetadataHeader, jsonPretty, "-->"].join("\n");

if (logMessage?.type === "fatal") {
// if the log message is fatal, then we want to show the metadata
metadataSerialized = [metadataSerializedVisible, metadataSerializedHidden].join("\n");
} else {
// otherwise we want to hide it
metadataSerialized = metadataSerializedHidden;
}

return metadataSerialized;
}
2 changes: 1 addition & 1 deletion src/helpers/task-deadline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Context } from "../types/context";
import { ListIssueForRepo } from "../types/github-types";
import { getAssigneesActivityForIssue } from "./get-assignee-activity";

export async function handleDeadline(
export async function getDeadlineWithThreshold(
context: Context,
metadata: {
taskDeadline: string;
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/task-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Context } from "../types/context";
import { ListCommentsForIssue, ListForOrg, ListIssueForRepo } from "../types/github-types";
import ms from "ms";

export async function handleCommentsAndMetadata(
export async function getTaskMetadata(
context: Context,
repo: ListForOrg["data"][0],
issue: ListIssueForRepo
Expand All @@ -27,7 +27,7 @@ export async function handleCommentsAndMetadata(
DateTime.fromISO(a.created_at).toMillis() - DateTime.fromISO(b.created_at).toMillis()
)

const botFollowup = /this task has been idle for a while. Please provide an update./gi;
const botFollowup = /<!-- Ubiquity - Followup - remindAssignees/gi;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps you can use the real metadata parser, the original one I wrote.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you link to it I don't think I've seen it before

const botFollowupComments = botComments.filter((o) => botFollowup.test(o?.body || ""));

if (!botAssignmentComments.length && !botFollowupComments.length) {
Expand Down
8 changes: 4 additions & 4 deletions src/helpers/task-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ import { DateTime } from "luxon";
import { Context } from "../types/context";
import { ListForOrg, ListIssueForRepo } from "../types/github-types";
import { remindAssigneesForIssue, unassignUserFromIssue } from "./remind-and-remove";
import { handleDeadline } from "./task-deadline";
import { handleCommentsAndMetadata } from "./task-metadata";
import { getDeadlineWithThreshold } from "./task-deadline";
import { getTaskMetadata } from "./task-metadata";

export async function updateTaskReminder(context: Context, repo: ListForOrg["data"][0], issue: ListIssueForRepo) {
const { logger } = context;

let metadata, lastCheck, deadlineWithThreshold, reminderWithThreshold, now;

const handledMetadata = await handleCommentsAndMetadata(context, repo, issue);
const handledMetadata = await getTaskMetadata(context, repo, issue);

if (handledMetadata) {
metadata = handledMetadata.metadata;
lastCheck = handledMetadata.lastCheck;

const handledDeadline = await handleDeadline(context, metadata, issue, lastCheck);
const handledDeadline = await getDeadlineWithThreshold(context, metadata, issue, lastCheck);
if (handledDeadline) {
deadlineWithThreshold = handledDeadline.deadlineWithThreshold;
reminderWithThreshold = handledDeadline.reminderWithThreshold;
Expand Down
5 changes: 4 additions & 1 deletion tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import mockUsers from "./__mocks__/mock-users";
import { botAssignmentComment, getIssueHtmlUrl, getIssueUrl, noAssignmentCommentFor, STRINGS, updatingRemindersFor } from "./__mocks__/strings";
import { createComment, createIssue, createRepo, ONE_DAY } from "./__mocks__/helpers";
import { collectLinkedPullRequests } from "../src/handlers/collect-linked-pulls";
import { createStructuredMetadata } from "../src/helpers/structured-metadata";

dotenv.config();
const octokit = jest.requireActual("@octokit/rest");
Expand Down Expand Up @@ -119,7 +120,9 @@ describe("User start/stop", () => {
expect(updatedIssue?.assignees).toEqual([{ login: STRINGS.USER, id: 2 }]);

const comments = db.issueComments.getAll();
expect(comments[comments.length - 1].body).toEqual(JSON.stringify({ body: `@${STRINGS.USER}, this task has been idle for a while. Please provide an update.` }));
const latestComment = comments[comments.length - 1];
const partialComment = "@user2, this task has been idle for a while. Please provide an update.\\n\\n\\n<!-- Ubiquity - Followup -"
expect(latestComment.body).toContain(partialComment);
});

it("Should have nothing do within the warning period", async () => {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1810,10 +1810,10 @@
dependencies:
"@types/yargs-parser" "*"

"@ubiquity-dao/ubiquibot-logger@^1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@ubiquity-dao/ubiquibot-logger/-/ubiquibot-logger-1.3.0.tgz#b07364658be95b3be3876305c66b2adc906e9590"
integrity sha512-ifkd7fB2OMTSt3OL9L14bCIvCMXV+IHFdJYU5S8FUzE2U88b4xKxuEAYDFX+DX3wwDEswFAVUwx5aP3QcMIRWA==
"@ubiquity-dao/ubiquibot-logger@^1.3.1":
version "1.3.1"
resolved "https://registry.yarnpkg.com/@ubiquity-dao/ubiquibot-logger/-/ubiquibot-logger-1.3.1.tgz#c3f45d70014dcc2551442c28101046e1c8ea6886"
integrity sha512-kDLnVP87Y3yZV6NnqIEDAOz+92IW0nIcccML2lUn93uZ5ada78vfdTPtwPJo8tkXl1Z9qMKAqqHkwBMp1Ksnag==

JSONStream@^1.3.5:
version "1.3.5"
Expand Down