Skip to content

Commit

Permalink
chore: added missing comments on collect
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed Apr 24, 2024
1 parent 5794c4b commit e483216
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 38 deletions.
20 changes: 10 additions & 10 deletions rewards-configuration.default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,34 @@ formattingEvaluator:
td: 1
hr: 0
multipliers:
- type: [ISSUE, ISSUER, TASK]:
- type: [ISSUE, ISSUER, TASK]
formattingMultiplier: 1
wordValue: 0.1
- type: [ISSUE, ISSUER, COMMENTED]:
- type: [ISSUE, ISSUER, COMMENTED]
formattingMultiplier: 1
wordValue: 0.2
- type: [ISSUE, ASSIGNEE, COMMENTED]:
- type: [ISSUE, ASSIGNEE, COMMENTED]
formattingMultiplier: 0
wordValue: 0
- type: [ISSUE, COLLABORATOR, COMMENTED]:
- type: [ISSUE, COLLABORATOR, COMMENTED]
formattingMultiplier: 1
wordValue: 0.1
- type: [ISSUE, CONTRIBUTOR, COMMENTED]:
- type: [ISSUE, CONTRIBUTOR, COMMENTED]
formattingMultiplier: 0.25
wordValue: 0.1
- type: [REVIEW, ISSUER, SPECIFICATION]:
- type: [REVIEW, ISSUER, SPECIFICATION]
formattingMultiplier: 0
wordValue: 0
- type: [REVIEW, ISSUER, COMMENTED]:
- type: [REVIEW, ISSUER, COMMENTED]
formattingMultiplier: 2
wordValue: 0.2
- type: [REVIEW, ASSIGNEE, COMMENTED]:
- type: [REVIEW, ASSIGNEE, COMMENTED]
formattingMultiplier: 1
wordValue: 0.1
- type: [REVIEW, COLLABORATOR, COMMENTED]:
- type: [REVIEW, COLLABORATOR, COMMENTED]
formattingMultiplier: 1
wordValue: 0.1
- type: [REVIEW, CONTRIBUTOR, COMMENTED]:
- type: [REVIEW, CONTRIBUTOR, COMMENTED]
formattingMultiplier: 0.25
wordValue: 0.1
permitGeneration:
Expand Down
28 changes: 21 additions & 7 deletions src/data-collection/collect-linked-pulls.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
import { GitHubLinkEvent, isGitHubLinkEvent } from "../github-types";
import { IssueParams, getAllTimelineEvents } from "../start";
import { IssueParams, getAllTimelineEvents, parseGitHubUrl } from "../start";

export async function collectLinkedMergedPulls(issue: IssueParams) {
// normally we should only use this one to calculate incentives, because this specifies that the pull requests are merged (accepted)
// and that are also related to the current issue, no just mentioned by
const onlyPullRequests = await collectLinkedPulls(issue);
return onlyPullRequests.filter(
(event) =>
isGitHubLinkEvent(event) &&
event.source.issue.pull_request?.merged_at &&
event.source.issue.number === issue.issue_number
);
return onlyPullRequests.filter((event) => {
if (!event.source.issue.body) {
return false;
}
const linkedPrUrl = /Resolves[\s:]*(https:\/\/\S+|#\d+)/gim.exec(event.source.issue.body)?.[1];
if (!linkedPrUrl) {
return false;
}
let isClosingPr: boolean;
if (linkedPrUrl[0] === "#") {
isClosingPr = Number(linkedPrUrl.slice(1)) === issue.issue_number;
} else {
const linkedRepo = parseGitHubUrl(linkedPrUrl);
isClosingPr =
linkedRepo.issue_number === issue.issue_number &&
linkedRepo.repo === issue.repo &&
linkedRepo.owner === issue.owner;
}
return isGitHubLinkEvent(event) && event.source.issue.pull_request?.merged_at && isClosingPr;
});
}
export async function collectLinkedPulls(issue: IssueParams) {
// this one was created to help with tests, but probably should not be used in the main code
Expand Down
36 changes: 17 additions & 19 deletions src/issue-activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,12 @@ export class IssueActivity {

_getTypeFromComment(
issueType: CommentType.ISSUE | CommentType.REVIEW,
comment: GitHubIssueComment | GitHubPullRequestReviewComment | GitHubIssue | GitHubPullRequest,
comment:
| GitHubIssueComment
| GitHubPullRequestReviewComment
| GitHubPullRequestReviewState
| GitHubIssue
| GitHubPullRequest,
self: GitHubPullRequest | GitHubIssue | null
) {
let ret = 0;
Expand All @@ -125,25 +130,18 @@ export class IssueActivity {
_getLinkedReviewComments() {
const comments = [];
for (const linkedReview of this.linkedReviews) {
if (linkedReview.self) {
comments.push({
...linkedReview.self,
type: this._getTypeFromComment(CommentType.REVIEW, linkedReview.self, linkedReview.self),
});
}
if (linkedReview.reviewComments) {
for (const reviewComment of linkedReview.reviewComments) {
comments.push({
...reviewComment,
type: this._getTypeFromComment(CommentType.REVIEW, reviewComment, linkedReview.self),
});
}
}
if (linkedReview.comments) {
for (const comment of linkedReview.comments) {
for (const value of Object.values(linkedReview)) {
if (Array.isArray(value)) {
for (const review of value) {
comments.push({
...review,
type: this._getTypeFromComment(CommentType.REVIEW, review, linkedReview.self),
});
}
} else if (value) {
comments.push({
...comment,
type: this._getTypeFromComment(CommentType.REVIEW, comment, linkedReview.self),
...value,
type: this._getTypeFromComment(CommentType.REVIEW, value, value),
});
}
}
Expand Down
5 changes: 3 additions & 2 deletions tests/__mocks__/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { http, HttpResponse } from "msw";
import issueGet from "./routes/issue-get.json";
import issueEventsGet from "./routes/issue-events-get.json";
import issueEvents2Get from "./routes/issue-events-2-get.json";
import issueCommentsGet from "./routes/issue-comments-get.json";
import issueTimelineGet from "./routes/issue-timeline-get.json";
import pullsGet from "./routes/pulls-get.json";
Expand All @@ -15,8 +16,8 @@ export const handlers = [
http.get("https://api.github.com/repos/ubiquibot/comment-incentives/issues/22", () => {
return HttpResponse.json(issueGet);
}),
http.get("https://api.github.com/repos/ubiquibot/comment-incentives/issues/22/events", () => {
return HttpResponse.json(issueEventsGet);
http.get("https://api.github.com/repos/ubiquibot/comment-incentives/issues/22/events", ({ params: { page } }) => {
return HttpResponse.json(!page ? issueEventsGet : issueEvents2Get);
}),
http.get("https://api.github.com/repos/ubiquibot/comment-incentives/issues/22/comments", () => {
return HttpResponse.json(issueCommentsGet);
Expand Down
32 changes: 32 additions & 0 deletions tests/__mocks__/routes/issue-events-2-get.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"id": 11835426216,
"node_id": "SE_lADOK87YcM5_fo85zwAAAALBckWo",
"url": "https://api.github.com/repos/ubiquibot/comment-incentives/issues/events/11835426216",
"actor": {
"login": "0x4007",
"id": 4975670,
"node_id": "MDQ6VXNlcjQ5NzU2NzA=",
"avatar_url": "https://avatars.githubusercontent.com/u/4975670?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/0x4007",
"html_url": "https://github.com/0x4007",
"followers_url": "https://api.github.com/users/0x4007/followers",
"following_url": "https://api.github.com/users/0x4007/following{/other_user}",
"gists_url": "https://api.github.com/users/0x4007/gists{/gist_id}",
"starred_url": "https://api.github.com/users/0x4007/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/0x4007/subscriptions",
"organizations_url": "https://api.github.com/users/0x4007/orgs",
"repos_url": "https://api.github.com/users/0x4007/repos",
"events_url": "https://api.github.com/users/0x4007/events{/privacy}",
"received_events_url": "https://api.github.com/users/0x4007/received_events",
"type": "User",
"site_admin": false
},
"event": "subscribed",
"commit_id": null,
"commit_url": null,
"created_at": "2024-02-17T03:55:29Z",
"performed_via_github_app": null
}
]
6 changes: 6 additions & 0 deletions tests/process.issue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ describe("Modules tests", () => {
await processor.run(activity);
processor.dump();
expect(logSpy).toHaveBeenCalledWith(JSON.stringify(userCommentResults, undefined, 2));
logSpy.mockReset();
});

it("Should purge data", async () => {
Expand All @@ -89,6 +90,7 @@ describe("Modules tests", () => {
await processor.run(activity);
processor.dump();
expect(logSpy).toHaveBeenCalledWith(JSON.stringify(dataPurgeResults, undefined, 2));
logSpy.mockReset();
});

it("Should evaluate formatting", async () => {
Expand All @@ -98,6 +100,7 @@ describe("Modules tests", () => {
await processor.run(activity);
processor.dump();
expect(logSpy).toHaveBeenCalledWith(JSON.stringify(formattingEvaluatorResults, undefined, 2));
logSpy.mockReset();
});

it("Should evaluate content", async () => {
Expand All @@ -112,6 +115,7 @@ describe("Modules tests", () => {
await processor.run(activity);
processor.dump();
expect(logSpy).toHaveBeenCalledWith(JSON.stringify(contentEvaluatorResults, undefined, 2));
logSpy.mockReset();
});

it("Should generate permits", async () => {
Expand All @@ -127,6 +131,7 @@ describe("Modules tests", () => {
await processor.run(activity);
processor.dump();
expect(logSpy).toHaveBeenCalledWith(JSON.stringify(permitGenerationResults, undefined, 2));
logSpy.mockReset();
});

it("Should generate GitHub comment", async () => {
Expand All @@ -144,5 +149,6 @@ describe("Modules tests", () => {
processor.dump();
expect(logSpy).toHaveBeenCalledWith(JSON.stringify(githubCommentResults, undefined, 2));
expect(fs.readFileSync("./output.html")).toEqual(fs.readFileSync("./tests/__mocks__/results/output.html"));
logSpy.mockReset();
});
});

0 comments on commit e483216

Please sign in to comment.