Skip to content

Commit

Permalink
Feature: Added discussion types
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSim93 committed Dec 10, 2023
1 parent 2789246 commit 493c612
Show file tree
Hide file tree
Showing 13 changed files with 287 additions and 28 deletions.
146 changes: 137 additions & 9 deletions build/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pull-request-analytics-action",
"version": "1.2.2",
"version": "1.3.0",
"description": "github action to show prs report",
"main": "build/index.js",
"scripts": {
Expand Down
13 changes: 8 additions & 5 deletions src/controllers/data/preparations/collectData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ export const collectData = (
const collection: Record<string, Record<string, Collection>> = { total: {} };

data.pullRequestInfo.forEach((pullRequest, index) => {
const closedDate = pullRequest?.closed_at
? parseISO(pullRequest?.closed_at)
if (pullRequest === undefined || pullRequest === null) {
return;
}
const closedDate = pullRequest.closed_at
? parseISO(pullRequest.closed_at)
: null;

const dateKey = closedDate ? format(closedDate, "M/y") : "invalidDate";

const userKey = pullRequest?.user.login || "invalidUser";
const userKey = pullRequest.user.login || "invalidUser";
if (!collection[userKey]) {
collection[userKey] = {};
}
Expand All @@ -40,13 +43,13 @@ export const collectData = (
});
});

prepareReviews(data, collection, index, dateKey, pullRequest?.user.login);
prepareReviews(data, collection, index, dateKey, pullRequest.user.login);
prepareDiscussions(
data.comments,
collection,
index,
dateKey,
pullRequest?.user.login
pullRequest.user.login
);
});

Expand Down
10 changes: 5 additions & 5 deletions src/controllers/data/preparations/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ type TimelinePoints = {

type DiscussionResult = {
total: number;
agreed: number;
disagreed: number;
unresolved: number;
agreed?: number;
disagreed?: number;
unresolved?: number;
};

type DiscussionType = {
[key: string]: {
received: DiscussionResult;
conducted: DiscussionResult;
received?: DiscussionResult;
conducted?: DiscussionResult;
};
};

Expand Down
21 changes: 21 additions & 0 deletions src/controllers/data/preparations/utils/getDiscussionType.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { getDiscussionType } from "./getDiscussionType";

describe("check getDiscussionType", () => {
it("check text without value ", () => {
expect(getDiscussionType("text text")).toEqual([]);
});
it("check value in text", () => {
expect(getDiscussionType("text [[value1]] text")).toEqual(["value1"]);
});
it("check multiple values in text", () => {
expect(getDiscussionType("text [[value1]] [[value2]] text")).toEqual([
"value1",
"value2",
]);
});
it("check value with different symbols", () => {
expect(
getDiscussionType("text [[value-1]] [[value:2]] [[value.3]]text")
).toEqual(["value-1", "value:2", "value.3"]);
});
});
9 changes: 9 additions & 0 deletions src/controllers/data/preparations/utils/getDiscussionType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const getDiscussionType = (text: string) => {
const regex = /\[\[(.*?)\]\]/g;
return (
text
.match(regex)
?.map((el) => el.replace(/[\[\]]/g, ""))
.filter((el) => el) || []
);
};
Loading

0 comments on commit 493c612

Please sign in to comment.