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

feat: tests for modules #14

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3144662
chore: formatting evaluator tests
gentlementlegen Apr 20, 2024
77ba319
chore: content evaluator tests
gentlementlegen Apr 21, 2024
6d2ff7b
chore: fake wallet db
gentlementlegen Apr 21, 2024
4b2fb40
chore: tests for permit generation
gentlementlegen Apr 21, 2024
d24b998
chore: changed body type to an array of string
gentlementlegen Apr 21, 2024
e77d749
Merge branch 'refs/heads/feat/github-comment' into feat/testing
gentlementlegen Apr 22, 2024
193a160
chore: test for github comment
gentlementlegen Apr 22, 2024
27aa759
chore: fixed knip checks
gentlementlegen Apr 22, 2024
34ad6dc
chore: fetching all the comments from pull-requests
gentlementlegen Apr 23, 2024
391e96e
chore: sanitizing content to avoid accidentally rendering html
gentlementlegen Apr 23, 2024
aef3ff4
chore: added contribution detail to formatting
gentlementlegen Apr 23, 2024
f8842a3
chore: ignore mentioned pull request for result calculation
gentlementlegen Apr 24, 2024
bb3d121
chore: fixed data purge for commands
gentlementlegen Apr 24, 2024
5794c4b
chore: merged branch
gentlementlegen Apr 24, 2024
e483216
chore: added missing comments on collect
gentlementlegen Apr 24, 2024
99c3e09
chore: updated test results
gentlementlegen Apr 24, 2024
485fc5c
chore: fixed knip and cspell
gentlementlegen Apr 24, 2024
737f371
chore: fixed knip
gentlementlegen Apr 24, 2024
a4b0f21
chore: changed fs import
gentlementlegen Apr 24, 2024
f0346c4
chore: fixed jest testing file
gentlementlegen Apr 24, 2024
90e150f
chore: renamed task to specification
gentlementlegen Apr 24, 2024
424609b
chore: added specification to details
gentlementlegen Apr 24, 2024
f531882
Merge branch 'refs/heads/development' into feat/testing
gentlementlegen Apr 25, 2024
b0c3446
chore: fixed merged reverting changes
gentlementlegen Apr 25, 2024
4156b4d
chore: removed URL cleaning from comment body
gentlementlegen May 2, 2024
7f3297a
chore: properly match all closing issue patterns in body
gentlementlegen May 2, 2024
989e56f
chore: changed default configuration
gentlementlegen May 2, 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 .cspell.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json",
"version": "0.2",
"ignorePaths": ["**/*.json", "**/*.css", "node_modules", "**/*.log"],
"ignorePaths": ["**/*.json", "**/*.css", "node_modules", "**/*.log", "**/tests/__mocks__"],
"useGitignore": true,
"language": "en",
"words": ["dataurl", "devpool", "outdir", "servedir", "ubiquibot", "tiktoken", "typebox", "supabase", "wxdai", "noopener"],
"words": ["dataurl", "devpool", "outdir", "servedir", "ubiquibot", "tiktoken", "typebox", "supabase", "wxdai", "noopener", "knip", "hellip"],
"dictionaries": ["typescript", "node", "software-terms"],
"import": ["@cspell/dict-typescript/cspell-ext.json", "@cspell/dict-node/cspell-ext.json", "@cspell/dict-software-terms"],
"ignoreRegExpList": ["[0-9a-fA-F]{6}"]
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/jest-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ jobs:
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }}
X25519_PRIVATE_KEY: ${{ secrets.X25519_PRIVATE_KEY }}
NFT_MINTER_PRIVATE_KEY: ${{ secrets.NFT_MINTER_PRIVATE_KEY }}
NFT_CONTRACT_ADDRESS: ${{ secrets.NFT_CONTRACT_ADDRESS }}
EVM_PRIVATE_ENCRYPTED: ${{ secrets.EVM_PRIVATE_ENCRYPTED }}

steps:
- name: Checkout code
Expand Down
2 changes: 1 addition & 1 deletion knip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const config: KnipConfig = {
project: ["src/**/*.ts"],
ignore: ["src/data-collection/examples/*.ts", "src/configuration/common-config-type.ts"],
ignoreExportsUsedInFile: true,
ignoreDependencies: ["ts-node", "msw"],
ignoreDependencies: ["ts-node", "msw", "@mswjs/data"],
jest: {
config: ["jest.config.ts"],
entry: ["src/**/*.test.ts"],
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@octokit/rest": "20.1.0",
"@sinclair/typebox": "0.32.20",
"@supabase/supabase-js": "2.42.0",
"@ubiquibot/permit-generation": "1.2.1",
"@ubiquibot/permit-generation": "1.2.2",
"commander": "12.0.0",
"decimal.js": "10.4.3",
"dotenv": "16.4.5",
Expand All @@ -50,6 +50,7 @@
"@cspell/dict-node": "4.0.3",
"@cspell/dict-software-terms": "3.3.18",
"@cspell/dict-typescript": "3.1.2",
"@mswjs/data": "0.16.1",
"@types/jest": "29.5.12",
"@types/jsdom": "21.1.6",
"@types/markdown-it": "13.0.7",
Expand Down
22 changes: 11 additions & 11 deletions rewards-configuration.default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,39 @@ formattingEvaluator:
td: 1
hr: 0
multipliers:
- type: [ISSUE, ISSUER, TASK]:
- type: [ISSUE, ISSUER, SPECIFICATION]
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, TASK]
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:
enabled: true
githubComment:
enabled: true
post: false
post: true
debug: true
35 changes: 33 additions & 2 deletions src/data-collection/collect-linked-pulls.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,41 @@
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);
return onlyPullRequests.filter((event) => {
if (!event.source.issue.body) {
return false;
}
// Matches all keywords according to the docs:
// https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword
// Works on multiple linked issues, and matches #<number> or URL patterns
const linkedIssueRegex =
/\b(?:Close(?:s|d)?|Fix(?:es|ed)?|Resolve(?:s|d)?):?\s+(?:#(\d+)|https?:\/\/(?:www\.)?github\.com\/(?:[^/\s]+\/[^/\s]+\/(?:issues|pull)\/(\d+)))\b/gi;
const linkedPrUrls = event.source.issue.body.match(linkedIssueRegex);
if (!linkedPrUrls) {
return false;
}
let isClosingPr = false;
for (const linkedPrUrl of linkedPrUrls) {
const idx = linkedPrUrl.indexOf("#");
if (idx !== -1) {
isClosingPr = Number(linkedPrUrl.slice(idx + 1)) === issue.issue_number;
} else {
const url = linkedPrUrl.match(/https.+/)?.[0];
if (url) {
const linkedRepo = parseGitHubUrl(url);
isClosingPr =
linkedRepo.issue_number === issue.issue_number &&
linkedRepo.repo === issue.repo &&
linkedRepo.owner === issue.owner;
gentlementlegen marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
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
64 changes: 42 additions & 22 deletions src/issue-activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,19 @@ export class IssueActivity {
}

_getTypeFromComment(
comment: GitHubIssueComment | GitHubPullRequestReviewComment | GitHubIssue | GitHubPullRequest,
issueType: CommentType.ISSUE | CommentType.REVIEW,
comment:
| GitHubIssueComment
| GitHubPullRequestReviewComment
| GitHubPullRequestReviewState
| GitHubIssue
| GitHubPullRequest,
self: GitHubPullRequest | GitHubIssue | null
) {
let ret = 0;
ret |= "pull_request_review_id" in comment || "draft" in comment ? CommentType.REVIEW : CommentType.ISSUE;
ret |= issueType;
if (comment.id === self?.id) {
ret |= ret & CommentType.ISSUE ? CommentType.TASK : CommentType.SPECIFICATION;
ret |= ret & CommentType.ISSUE ? CommentType.SPECIFICATION : CommentType.TASK;
} else {
ret |= CommentType.COMMENTED;
}
Expand All @@ -121,36 +127,43 @@ export class IssueActivity {
return ret;
}

_getLinkedReviewComments() {
const comments = [];
for (const linkedReview of this.linkedReviews) {
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({
...value,
type: this._getTypeFromComment(CommentType.REVIEW, value, value),
});
}
}
}
return comments;
}

get allComments() {
const comments: Array<
(GitHubIssueComment | GitHubPullRequestReviewComment | GitHubIssue | GitHubPullRequest) & { type: CommentType }
> = this.comments.map((comment) => ({
...comment,
type: this._getTypeFromComment(comment, this.self),
type: this._getTypeFromComment(CommentType.ISSUE, comment, this.self),
}));
if (this.self) {
comments.push({
...this.self,
type: this._getTypeFromComment(this.self, this.self),
type: this._getTypeFromComment(CommentType.ISSUE, this.self, this.self),
});
}
if (this.linkedReviews) {
for (const linkedReview of this.linkedReviews) {
if (linkedReview.self) {
comments.push({
...linkedReview.self,
type: this._getTypeFromComment(linkedReview.self, linkedReview.self),
});
}
if (linkedReview.reviewComments) {
for (const reviewComment of linkedReview.reviewComments) {
comments.push({
...reviewComment,
type: this._getTypeFromComment(reviewComment, linkedReview.self),
});
}
}
}
comments.push(...this._getLinkedReviewComments());
}
return comments;
}
Expand All @@ -160,14 +173,21 @@ export class Review {
self: GitHubPullRequest | null = null;
reviews: GitHubPullRequestReviewState[] | null = null; // this includes every comment on the files view.
reviewComments: GitHubPullRequestReviewComment[] | null = null;
comments: GitHubIssueComment[] | null = null;

constructor(private _pullParams: PullParams) {}

async init() {
[this.self, this.reviews, this.reviewComments] = await Promise.all([
[this.self, this.reviews, this.reviewComments, this.comments] = await Promise.all([
getPullRequest(this._pullParams),
getPullRequestReviews(this._pullParams),
getPullRequestReviewComments(this._pullParams),
// This fetches all the comments inside the Pull Request that were not created in a reviewing context
getIssueComments({
owner: this._pullParams.owner,
repo: this._pullParams.repo,
issue_number: this._pullParams.pull_number,
}),
]);
}
}
2 changes: 1 addition & 1 deletion src/parser/command-line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if (process.env.NODE_ENV === "test") {
process.argv.push("-n");
process.argv.push("100");
process.argv.push("-e");
process.argv.push("privateKey");
process.argv.push(`${process.env.EVM_PRIVATE_ENCRYPTED}`);
}

const program = new Command()
Expand Down
6 changes: 4 additions & 2 deletions src/parser/data-purge-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ export class DataPurgeModule implements Module {
for (const comment of data.allComments) {
if (comment.body && comment.user?.login && result[comment.user.login]) {
const newContent = comment.body
// Remove quoted text
.replace(/^>.*$/gm, "")
// Remove commands such as /start
.replace(/^\/.+/g, "")
gentlementlegen marked this conversation as resolved.
Show resolved Hide resolved
// makes the content single lined
.replace(/[\r\n]+/g, " ")
.replace(/\[.*?\]\(.*?\)/g, "")
.replace(/^\/\S+/g, "")
.trim();
if (newContent.length) {
result[comment.user.login].comments = [
Expand Down
Loading
Loading