Skip to content

Commit

Permalink
feat: ignore bot comments in top-level discussion (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
pvcnt authored Aug 27, 2024
1 parent 9c6ef36 commit 076e597
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 89 deletions.
2 changes: 1 addition & 1 deletion apps/webapp/tests/lib/db.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { mockConnection, mockSection, mockPull } from "@repo/testing";
test("should save a connection", async () => {
const connection = mockConnection({
viewer: {
user: { name: "pvcnt", avatarUrl: "" },
user: { name: "pvcnt", avatarUrl: "", bot: false },
teams: [{ name: "test" }],
},
orgs: ["apache", "kubernetes"],
Expand Down
4 changes: 2 additions & 2 deletions apps/webapp/tests/worker/instance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ describe("sync viewers", () => {

let connection = await db.connections.get("1");
expect(connection?.viewer).toBeDefined();
expect(connection?.viewer?.user).toEqual({ name: "test[1]", avatarUrl: "" });
expect(connection?.viewer?.user).toEqual({ name: "test[1]", avatarUrl: "", bot: false });

connection = await db.connections.get("2");
expect(connection?.viewer).toBeDefined();
expect(connection?.viewer?.user).toEqual({ name: "test[2]", avatarUrl: "" });
expect(connection?.viewer?.user).toEqual({ name: "test[2]", avatarUrl: "", bot: false });

activity = await db.activities.get("syncViewers");
expect(activity?.running).toBeFalsy();
Expand Down
7 changes: 6 additions & 1 deletion packages/github/src/attention.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ export function isInAttentionSet(connection: Connection, pull: PullProps): Atten
continue;
}
const lastViewerCommentPos = discussion.comments.findLastIndex(c => c.author?.name === viewerName);
const commentsAfterLastViewerComment = (lastViewerCommentPos === -1)
let commentsAfterLastViewerComment = (lastViewerCommentPos === -1)
? discussion.comments
: discussion.comments.slice(lastViewerCommentPos + 1);
if (discussion.file === undefined) {
// Ignore bot comments in top-level discussions, since this particular one tends
// to be catch-all, and not really a threaded discussion.
commentsAfterLastViewerComment = commentsAfterLastViewerComment.filter(c => c.author === undefined || !c.author.bot);
}
if (lastViewerCommentPos > -1 && commentsAfterLastViewerComment.length > 0) {
// The author and reviewers are always notified when somebody replied to them.
commentsAfterLastViewerComment
Expand Down
16 changes: 13 additions & 3 deletions packages/github/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type GHReview = {
}

type GHUser = {
__typename: "Bot"|"EnterpriseUserAccount"|"Mannequin"|"Organization"|"User"
login: string
avatarUrl: string
}
Expand All @@ -93,6 +94,7 @@ export class DefaultGitHubClient implements GitHubClient {
const user: User = {
name: userResponse.data.login,
avatarUrl: userResponse.data.avatar_url,
bot: false,
};
const teamsResponse = await octokit.paginate("GET /user/teams", { per_page: 100 });
const teams: Team[] = teamsResponse.map(obj => ({ name: `${obj.organization.login}/${obj.slug}` }));
Expand Down Expand Up @@ -152,8 +154,9 @@ export class DefaultGitHubClient implements GitHubClient {
additions
deletions
author {
__typename
login
avatarUrl
avatarUrl
}
statusCheckRollup {
state
Expand All @@ -163,6 +166,7 @@ export class DefaultGitHubClient implements GitHubClient {
nodes {
id
author {
__typename
login
avatarUrl
}
Expand Down Expand Up @@ -198,6 +202,7 @@ export class DefaultGitHubClient implements GitHubClient {
nodes {
id
author {
__typename
login
avatarUrl
}
Expand All @@ -217,6 +222,7 @@ export class DefaultGitHubClient implements GitHubClient {
nodes {
id
author {
__typename
login
avatarUrl
}
Expand Down Expand Up @@ -330,7 +336,11 @@ export class DefaultGitHubClient implements GitHubClient {
}

private makeUser(user: GHUser): User {
return { name: user.login, avatarUrl: user.avatarUrl };
return {
name: user.login,
avatarUrl: user.avatarUrl,
bot: user.__typename === "Bot",
};
}

private makeTeam(team: GHTeam): Team {
Expand Down Expand Up @@ -361,7 +371,7 @@ export class TestGitHubClient implements GitHubClient {

getViewer(connection: Connection): Promise<Profile> {
return Promise.resolve({
user: { name: `test[${connection.id}]`, avatarUrl: "" },
user: { name: `test[${connection.id}]`, avatarUrl: "", bot: false },
teams: [ { name: `test[${connection.id}]` } ],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
},
"entries": [
{
"_id": "cc0646ae14889a5d068e12034aa668ad",
"_id": "3227fef667e90b40698466a986053b05",
"_order": 0,
"cache": {},
"request": {
"bodySize": 2278,
"bodySize": 2372,
"cookies": [],
"headers": [
{
Expand All @@ -32,23 +32,23 @@
"value": "octokit.js/0.0.0-development octokit-core.js/6.1.2 Node.js/22"
}
],
"headersSize": 273,
"headersSize": 242,
"httpVersion": "HTTP/1.1",
"method": "POST",
"postData": {
"mimeType": "application/json; charset=utf-8",
"params": [],
"text": "{\"query\":\"query pull($id: ID!) {\\n node(id: $id) {\\n ... on PullRequest {\\n number\\n title\\n repository {\\n nameWithOwner\\n }\\n createdAt\\n updatedAt\\n state\\n url\\n isDraft\\n closed\\n merged\\n reviewDecision\\n additions\\n deletions\\n author {\\n login\\n avatarUrl \\n }\\n statusCheckRollup {\\n state\\n }\\n comments(first: 100) {\\n totalCount\\n nodes {\\n id\\n author {\\n login\\n avatarUrl\\n }\\n body\\n createdAt\\n }\\n }\\n reviewRequests(first: 100) {\\n totalCount\\n nodes {\\n requestedReviewer {\\n __typename\\n ... on Bot {\\n login\\n avatarUrl\\n }\\n ... on Mannequin {\\n login\\n avatarUrl\\n }\\n ... on User {\\n login\\n avatarUrl\\n }\\n ... on Team {\\n combinedSlug\\n }\\n }\\n }\\n }\\n reviews(first: 100) {\\n totalCount\\n nodes {\\n id\\n author {\\n login\\n avatarUrl\\n }\\n authorCanPushToRepository\\n state\\n body\\n createdAt\\n }\\n }\\n reviewThreads(first: 100) {\\n totalCount\\n nodes {\\n isResolved\\n path\\n comments(first: 100) {\\n totalCount\\n nodes {\\n id\\n author {\\n login\\n avatarUrl\\n }\\n createdAt\\n body\\n }\\n }\\n }\\n }\\n }\\n }\\n rateLimit {\\n cost\\n }\\n }\",\"variables\":{\"id\":\"PR_none\"}}"
"text": "{\"query\":\"query pull($id: ID!) {\\n node(id: $id) {\\n ... on PullRequest {\\n number\\n title\\n repository {\\n nameWithOwner\\n }\\n createdAt\\n updatedAt\\n state\\n url\\n isDraft\\n closed\\n merged\\n reviewDecision\\n additions\\n deletions\\n author {\\n __typename\\n login\\n avatarUrl\\n }\\n statusCheckRollup {\\n state\\n }\\n comments(first: 100) {\\n totalCount\\n nodes {\\n id\\n author {\\n __typename\\n login\\n avatarUrl\\n }\\n body\\n createdAt\\n }\\n }\\n reviewRequests(first: 100) {\\n totalCount\\n nodes {\\n requestedReviewer {\\n __typename\\n ... on Bot {\\n login\\n avatarUrl\\n }\\n ... on Mannequin {\\n login\\n avatarUrl\\n }\\n ... on User {\\n login\\n avatarUrl\\n }\\n ... on Team {\\n combinedSlug\\n }\\n }\\n }\\n }\\n reviews(first: 100) {\\n totalCount\\n nodes {\\n id\\n author {\\n __typename\\n login\\n avatarUrl\\n }\\n authorCanPushToRepository\\n state\\n body\\n createdAt\\n }\\n }\\n reviewThreads(first: 100) {\\n totalCount\\n nodes {\\n isResolved\\n path\\n comments(first: 100) {\\n totalCount\\n nodes {\\n id\\n author {\\n __typename\\n login\\n avatarUrl\\n }\\n createdAt\\n body\\n }\\n }\\n }\\n }\\n }\\n }\\n rateLimit {\\n cost\\n }\\n }\",\"variables\":{\"id\":\"PR_none\"}}"
},
"queryString": [],
"url": "https://api.github.com/graphql"
},
"response": {
"bodySize": 201,
"bodySize": 98,
"content": {
"mimeType": "application/json; charset=utf-8",
"size": 201,
"text": "{\"data\":{\"node\":null,\"rateLimit\":{\"cost\":1}},\"errors\":[{\"type\":\"NOT_FOUND\",\"path\":[\"node\"],\"locations\":[{\"line\":2,\"column\":7}],\"message\":\"Could not resolve to a node with the global id of 'PR_none'\"}]}"
"size": 98,
"text": "{\"message\":\"Bad credentials\",\"documentation_url\":\"https://docs.github.com/graphql\",\"status\":\"401\"}"
},
"cookies": [],
"headers": [
Expand All @@ -61,8 +61,8 @@
"value": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset"
},
{
"name": "content-encoding",
"value": "gzip"
"name": "content-length",
"value": "98"
},
{
"name": "content-security-policy",
Expand All @@ -74,7 +74,7 @@
},
{
"name": "date",
"value": "Tue, 27 Aug 2024 14:12:26 GMT"
"value": "Tue, 27 Aug 2024 14:48:35 GMT"
},
{
"name": "referrer-policy",
Expand All @@ -88,18 +88,10 @@
"name": "strict-transport-security",
"value": "max-age=31536000; includeSubdomains; preload"
},
{
"name": "transfer-encoding",
"value": "chunked"
},
{
"name": "vary",
"value": "Accept-Encoding, Accept, X-Requested-With"
},
{
"name": "x-accepted-oauth-scopes",
"value": "repo"
},
{
"name": "x-content-type-options",
"value": "nosniff"
Expand All @@ -114,53 +106,49 @@
},
{
"name": "x-github-request-id",
"value": "C5FC:2D68BC:38B277D:395A312:66CDDEC9"
},
{
"name": "x-oauth-scopes",
"value": "read:org, repo, user"
"value": "C805:B6DE5:3880FCB:392D728:66CDE743"
},
{
"name": "x-ratelimit-limit",
"value": "5000"
"value": "0"
},
{
"name": "x-ratelimit-remaining",
"value": "4874"
"value": "0"
},
{
"name": "x-ratelimit-reset",
"value": "1724768719"
"value": "1724773715"
},
{
"name": "x-ratelimit-resource",
"value": "graphql"
},
{
"name": "x-ratelimit-used",
"value": "126"
"value": "0"
},
{
"name": "x-xss-protection",
"value": "0"
}
],
"headersSize": 1138,
"headersSize": 1028,
"httpVersion": "HTTP/1.1",
"redirectURL": "",
"status": 200,
"statusText": "OK"
"status": 401,
"statusText": "Unauthorized"
},
"startedDateTime": "2024-08-27T14:12:25.809Z",
"time": 201,
"startedDateTime": "2024-08-27T14:48:35.690Z",
"time": 147,
"timings": {
"blocked": -1,
"connect": -1,
"dns": -1,
"receive": 0,
"send": 0,
"ssl": -1,
"wait": 201
"wait": 147
}
}
],
Expand Down
Loading

0 comments on commit 076e597

Please sign in to comment.