Skip to content

Commit

Permalink
Merge pull request #12 from gentlementlegen/feat/github-comment
Browse files Browse the repository at this point in the history
feat: github comment generation and posting
  • Loading branch information
gentlementlegen authored Apr 25, 2024
2 parents dd6b3ee + a12318e commit a466667
Show file tree
Hide file tree
Showing 32 changed files with 5,725 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"ignorePaths": ["**/*.json", "**/*.css", "node_modules", "**/*.log"],
"useGitignore": true,
"language": "en",
"words": ["dataurl", "devpool", "outdir", "servedir", "ubiquibot", "tiktoken", "typebox"],
"words": ["dataurl", "devpool", "outdir", "servedir", "ubiquibot", "tiktoken", "typebox", "supabase", "wxdai", "noopener"],
"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
1 change: 1 addition & 0 deletions .github/workflows/cspell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Spell Check

on:
push:
pull_request:

jobs:
spellcheck:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ node_modules
static/dist
.env
junit.xml
coverage
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"],
ignoreDependencies: ["ts-node", "msw"],
jest: {
config: ["jest.config.ts"],
entry: ["src/**/*.test.ts"],
Expand Down
5 changes: 3 additions & 2 deletions 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.0.3",
"@ubiquibot/permit-generation": "1.2.1",
"commander": "12.0.0",
"decimal.js": "10.4.3",
"dotenv": "16.4.5",
Expand All @@ -56,7 +56,7 @@
"@types/node": "20.11.28",
"@typescript-eslint/eslint-plugin": "6.21.0",
"@typescript-eslint/parser": "6.21.0",
"babel-jest": "^29.7.0",
"babel-jest": "29.7.0",
"cspell": "8.3.2",
"eslint": "8.56.0",
"eslint-plugin-sonarjs": "0.23.0",
Expand All @@ -65,6 +65,7 @@
"jest-junit": "16.0.0",
"knip": "5.7.0",
"lint-staged": "15.2.2",
"msw": "2.2.14",
"npm-run-all": "4.1.5",
"prettier": "3.2.5",
"ts-node": "10.9.2",
Expand Down
28 changes: 19 additions & 9 deletions rewards-configuration.default.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#disabled: true
enabled: true
contentEvaluator:
enabled: true
userExtractor:
Expand Down Expand Up @@ -27,29 +27,39 @@ formattingEvaluator:
td: 1
hr: 0
multipliers:
- type: [ISSUE, ISSUER]:
- type: [ISSUE, ISSUER, TASK]:
formattingMultiplier: 1
wordValue: 0.1
- type: [ISSUE, ISSUER, COMMENTED]:
formattingMultiplier: 1
wordValue: 0.2
- type: [ISSUE, ASSIGNEE]:
- type: [ISSUE, ASSIGNEE, COMMENTED]:
formattingMultiplier: 0
wordValue: 0
- type: [ISSUE, COLLABORATOR]:
- type: [ISSUE, COLLABORATOR, COMMENTED]:
formattingMultiplier: 1
wordValue: 0.1
- type: [ISSUE, CONTRIBUTOR]:
- type: [ISSUE, CONTRIBUTOR, COMMENTED]:
formattingMultiplier: 0.25
wordValue: 0.1
- type: [REVIEW, ISSUER]:
- type: [REVIEW, ISSUER, SPECIFICATION]:
formattingMultiplier: 0
wordValue: 0
- type: [REVIEW, ISSUER, COMMENTED]:
formattingMultiplier: 2
wordValue: 0.2
- type: [REVIEW, ASSIGNEE]:
- type: [REVIEW, ASSIGNEE, COMMENTED]:
formattingMultiplier: 1
wordValue: 0.1
- type: [REVIEW, COLLABORATOR]:
- type: [REVIEW, COLLABORATOR, COMMENTED]:
formattingMultiplier: 1
wordValue: 0.1
- type: [REVIEW, CONTRIBUTOR]:
- type: [REVIEW, CONTRIBUTOR, COMMENTED]:
formattingMultiplier: 0.25
wordValue: 0.1
permitGeneration:
enabled: true
githubComment:
enabled: true
post: false
debug: true
11 changes: 11 additions & 0 deletions src/configuration/github-comment-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Static, Type } from "@sinclair/typebox";

const githubCommentConfigurationType = Type.Object({
enabled: Type.Boolean({ default: true }),
post: Type.Boolean({ default: true }),
debug: Type.Boolean({ default: false }),
});

export type GithubCommentConfiguration = Static<typeof githubCommentConfigurationType>;

export default githubCommentConfigurationType;
41 changes: 38 additions & 3 deletions src/issue-activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,42 @@ import {
} from "./start";

export enum CommentType {
/**
* Review related item
*/
REVIEW = 0b1,
/**
* Issue related item
*/
ISSUE = 0b10,
/**
* User assigned to the {@link CommentType.ISSUE} or {@link CommentType.REVIEW}
*/
ASSIGNEE = 0b100,
/**
* The author of the {@link CommentType.ISSUE} or {@link CommentType.REVIEW}
*/
ISSUER = 0b1000,
/**
* A user that is part of the organization or owner of the repo
*/
COLLABORATOR = 0b10000,
/**
* A user that is NOT part of the organization nor owner of the repo
*/
CONTRIBUTOR = 0b100000,
/**
* A user comment action on a {@link CommentType.ISSUE} or {@link CommentType.REVIEW}
*/
COMMENTED = 0b1000000,
/**
* Pull request opening item
*/
TASK = 0b10000000,
/**
* Issue opening item
*/
SPECIFICATION = 0b100000000,
}

export class IssueActivity {
Expand Down Expand Up @@ -73,14 +103,19 @@ export class IssueActivity {
self: GitHubPullRequest | GitHubIssue | null
) {
let ret = 0;
ret |= "pull_request_review_id" in comment ? CommentType.REVIEW : CommentType.ISSUE;
ret |= "pull_request_review_id" in comment || "draft" in comment ? CommentType.REVIEW : CommentType.ISSUE;
if (comment.id === self?.id) {
ret |= ret & CommentType.ISSUE ? CommentType.TASK : CommentType.SPECIFICATION;
} else {
ret |= CommentType.COMMENTED;
}
if (comment.user?.id === self?.user?.id) {
ret |= CommentType.ISSUER;
} else if (comment.user?.id === self?.assignee?.id) {
ret |= CommentType.ASSIGNEE;
} else if (comment.author_association === "MEMBER") {
} else if (comment.author_association === "MEMBER" || comment.author_association === "COLLABORATOR") {
ret |= CommentType.COLLABORATOR;
} else if (comment.author_association === "CONTRIBUTOR") {
} else {
ret |= CommentType.CONTRIBUTOR;
}
return ret;
Expand Down
4 changes: 2 additions & 2 deletions src/parser/data-purge-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class DataPurgeModule implements Module {
return this.configuration.enabled;
}

transform(data: Readonly<IssueActivity>, result: Result) {
async transform(data: Readonly<IssueActivity>, result: Result) {
for (const comment of data.allComments) {
if (comment.body && comment.user?.login && result[comment.user.login]) {
const newContent = comment.body
Expand All @@ -33,6 +33,6 @@ export class DataPurgeModule implements Module {
}
}
}
return Promise.resolve(result);
return result;
}
}
4 changes: 2 additions & 2 deletions src/parser/formatting-evaluator-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class FormattingEvaluatorModule implements Module {
}
}

transform(data: Readonly<IssueActivity>, result: Result) {
async transform(data: Readonly<IssueActivity>, result: Result) {
for (const key of Object.keys(result)) {
const currentElement = result[key];
const comments = currentElement.comments || [];
Expand Down Expand Up @@ -64,7 +64,7 @@ export class FormattingEvaluatorModule implements Module {
};
}
}
return Promise.resolve(result);
return result;
}

get enabled(): boolean {
Expand Down
Loading

0 comments on commit a466667

Please sign in to comment.