Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ Below is a table outlining the various configuration parameters available for **
| `CORE_HOURS_START` | Start of core hours. Excludes non-working hours from the calculations of time-related metrics. By default, a full day is counted. Time should be entered in the format **HH:mm**. The timezone corresponds to that specified in the `TIMEZONE` input (default is UTC). For correct operation, `CORE_HOURS_END` must also be specified and must be later than `CORE_HOURS_START`. Example: `10:00` | - |
| `CORE_HOURS_END` | End of core hours. Excludes non-working hours from the calculations of time-related metrics. By default, a full day is counted. Time should be entered in the format **HH:mm**. The timezone corresponds to that specified in the `TIMEZONE` input (default is UTC). For correct operation, `CORE_HOURS_END` must also be specified and must be later than `CORE_HOURS_START`. Example: `19:00` | - |
| `HOLIDAYS` | Dates to be excluded from the calculations of time-related metrics. Saturday and Sunday are already excluded by default. Dates should be entered in the format **d/MM/yyyy**, separated by commas. Example: `01/01/2024, 08/03/2024` | - |
| `WEEKENDS` | Specifies the days of the week considered as weekends. Values are represented as numbers, where 0 corresponds to Sunday | `0,6` |
| `TIMEZONE` | Timezone that will be used in action. Examples: `Europe/Berlin` or `America/New_York`. See the full list of time zones [here](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) | `UTC` |
| `PERCENTILE` | Percentile value for timeline. This parameter is mandatory if `percentile` is specified in the `SHOW_STATS_TYPES` input. | `75` |
| `ISSUE_TITLE` | Title for the created/updated issue with report | `Pull requests report(d/MM/yyyy HH:mm)` |
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ inputs:
CORE_HOURS_END:
description: "End time of core hours(HH:mm)"
required: false
WEEKENDS:
description: "Specifies the days of the week considered as weekends. Values are represented as numbers, where 0 corresponds to Sunday"
required: false
default: "0,6"
HOLIDAYS:
description: "Holidays separated by comma(d/MM/yyyy)"
required: false
Expand Down
35 changes: 27 additions & 8 deletions build/index.js

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "pull-request-analytics-action",
"version": "4.5.0",
"version": "4.6.0",
"description": "Generates detailed PR analytics reports within GitHub, focusing on review efficiency and team performance.",
"main": "build/index.js",
"scripts": {
"start": "node ./build/index.js",
"build": "tsc && ncc build ./dist/index.js -o build",
"tsc": "tsc",
"lint": "eslint ./src/**/*.ts",
"test": "TZ=utc jest",
"test:watch": "TZ=utc jest --watch",
"test": "TZ=utc WEEKENDS=0,6 jest",
"test:watch": "TZ=utc WEEKENDS=0,6 jest --watch",
"prepare": "husky install"
},
"author": "Aleksei Simatov",
Expand Down
33 changes: 33 additions & 0 deletions src/converters/utils/calculations/calcAverageValue.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { calcAverageValue } from './calcAverageValue';

describe('calcAverageValue', () => {
it('should return 0 if no values are provided', () => {
expect(calcAverageValue()).toBe(0);
});

it('should return 0 if an empty array is provided', () => {
expect(calcAverageValue([])).toBe(0);
});

it('should return the average value of the provided numbers', () => {
expect(calcAverageValue([1, 2, 3, 4, 5])).toBe(3);
expect(calcAverageValue([10, 20, 30])).toBe(20);
expect(calcAverageValue([1, 1, 1, 1, 1])).toBe(1);
});

it('should return the ceiling of the average value', () => {
expect(calcAverageValue([1, 2, 3])).toBe(2);
expect(calcAverageValue([1, 2, 2])).toBe(2);
expect(calcAverageValue([1, 1, 2])).toBe(2);
});

it('should handle negative numbers correctly', () => {
expect(calcAverageValue([-1, -2, -3, -4, -5])).toBe(-3);
expect(calcAverageValue([-10, -20, -30])).toBe(-20);
});

it('should handle a mix of positive and negative numbers', () => {
expect(calcAverageValue([-1, 1, -1, 1])).toBe(0);
expect(calcAverageValue([-10, 10, -10, 10])).toBe(0);
});
});
101 changes: 101 additions & 0 deletions src/converters/utils/calculations/calcDraftTime.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { calcDraftTime } from "./calcDraftTime";
import {
convertToDraftTimelineEvent,
readyForReviewTimelineEvent,
} from "../../constants";

describe("calcDraftTime", () => {
it("should return an empty array if statuses is empty", () => {
const result = calcDraftTime(
"2021-01-01T00:00:00Z",
"2021-01-02T00:00:00Z",
[]
);
expect(result).toEqual([]);
});

it("should calculate draft time correctly when there is only one readyForReviewTimelineEvent", () => {
const statuses = [
{
event: readyForReviewTimelineEvent,
created_at: "2021-01-01T12:00:00Z",
},
];
const result = calcDraftTime(
"2021-01-01T00:00:00Z",
"2021-01-02T00:00:00Z",
statuses
);
expect(result).toEqual([["2021-01-01T00:00:00Z", "2021-01-01T12:00:00Z"]]);
});

it("should calculate draft time correctly when there are multiple events", () => {
const statuses = [
{
event: convertToDraftTimelineEvent,
created_at: "2021-01-01T12:00:00Z",
},
{
event: readyForReviewTimelineEvent,
created_at: "2021-01-01T14:00:00Z",
},
{
event: convertToDraftTimelineEvent,
created_at: "2021-01-01T16:00:00Z",
},
{
event: readyForReviewTimelineEvent,
created_at: "2021-01-01T18:00:00Z",
},
];
const result = calcDraftTime(
"2021-01-01T00:00:00Z",
"2021-01-02T00:00:00Z",
statuses
);
expect(result).toEqual([
["2021-01-01T12:00:00Z", "2021-01-01T14:00:00Z"],
["2021-01-01T16:00:00Z", "2021-01-01T18:00:00Z"],
]);
});

it("should include the closedAt time if the last event is convertToDraftTimelineEvent", () => {
const statuses = [
{
event: readyForReviewTimelineEvent,
created_at: "2021-01-01T12:00:00Z",
},
{
event: convertToDraftTimelineEvent,
created_at: "2021-01-01T14:00:00Z",
},
];
const result = calcDraftTime(
"2021-01-01T00:00:00Z",
"2021-01-02T00:00:00Z",
statuses
);
expect(result).toEqual([
["2021-01-01T00:00:00Z", "2021-01-01T12:00:00Z"],
["2021-01-01T14:00:00Z", "2021-01-02T00:00:00Z"],
]);
});

it("should handle undefined createdAt and closedAt correctly", () => {
const statuses = [
{
event: readyForReviewTimelineEvent,
created_at: "2021-01-01T12:00:00Z",
},
{
event: convertToDraftTimelineEvent,
created_at: "2021-01-01T14:00:00Z",
},
];
const result = calcDraftTime(undefined, undefined, statuses);
expect(result).toEqual([
[undefined, "2021-01-01T12:00:00Z"],
["2021-01-01T14:00:00Z", undefined],
]);
});
});
4 changes: 2 additions & 2 deletions src/converters/utils/calculations/calcNonWorkingHours.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import {
differenceInMinutes,
eachDayOfInterval,
isBefore,
isWeekend,
setHours,
setMinutes,
} from "date-fns";
import { isHoliday } from "./isHoliday";
import { checkWeekend } from "./checkWeekend";

export type CoreHours = {
startOfWorkingTime: string;
Expand Down Expand Up @@ -36,7 +36,7 @@ export const calcNonWorkingHours = (
const endOfWorkingHours = setMinutes(setHours(day, endHours), endMinutes);
const endOfDay = setMinutes(setHours(day, 23), 59);

if (isWeekend(day) || isHoliday(day, holidays)) return acc;
if (checkWeekend(day) || isHoliday(day, holidays)) return acc;
if (arr.length === 1) {
if (
isBefore(secondDate, startOfWorkingHours) ||
Expand Down
17 changes: 7 additions & 10 deletions src/converters/utils/calculations/calcWeekendMinutes.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,36 @@
import {
differenceInMinutes,
eachDayOfInterval,
eachWeekendOfInterval,
isWeekend,
setHours,
setMinutes,
} from "date-fns";
import { isHoliday } from "./isHoliday";
import { checkWeekend } from "./checkWeekend";

export const calcWeekendMinutes = (
firstDate: Date,
secondDate: Date,
holidays?: string[]
) => {
const weekendsOfInterval = eachWeekendOfInterval({
start: firstDate,
end: secondDate,
});

const days = eachDayOfInterval({
start: firstDate,
end: secondDate,
});

const weekendsOfInterval = days.filter((day) => checkWeekend(day));

const minutesOnHolidays = days.reduce((acc, day) => {
if (isHoliday(day, holidays) && !isWeekend(day)) return acc + 24 * 60;
if (isHoliday(day, holidays) && !checkWeekend(day)) return acc + 24 * 60;
return acc;
}, 0);
let minutesInWeekend =
24 * 60 * weekendsOfInterval.length + (minutesOnHolidays || 0);

const isStartedAtWeekend = isWeekend(firstDate);
const isStartedAtWeekend = checkWeekend(firstDate);

const isStartedOnHoliday = isHoliday(firstDate, holidays);

const isEndedAtWeekend = isWeekend(secondDate);
const isEndedAtWeekend = checkWeekend(secondDate);

const isEndedOnHoliday = isHoliday(secondDate, holidays);

Expand Down
4 changes: 4 additions & 0 deletions src/converters/utils/calculations/checkUserInclusive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { getMultipleValuesInput } from "../../../common/utils";
export const checkUserInclusive = (name: string) => {
return !getMultipleValuesInput('EXCLUDE_USERS').includes(name) ;
};
52 changes: 52 additions & 0 deletions src/converters/utils/calculations/checkWeekend.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { checkWeekend } from "./checkWeekend";
import { getMultipleValuesInput } from "../../../common/utils";

jest.mock("../../../common/utils", () => ({
getMultipleValuesInput: jest.fn(),
}));

describe("checkWeekend", () => {
beforeEach(() => {
jest.resetAllMocks();
});

it("should return true if the date is a weekend", () => {
(getMultipleValuesInput as jest.Mock).mockReturnValue(["0", "6"]); // Sunday and Saturday

const date = new Date("2021-01-02T00:00:00Z"); // Saturday
const result = checkWeekend(date);
expect(result).toBe(true);
});

it("should return false if the date is not a weekend", () => {
(getMultipleValuesInput as jest.Mock).mockReturnValue(["0", "6"]); // Sunday and Saturday

const date = new Date("2021-01-01T00:00:00Z"); // Friday
const result = checkWeekend(date);
expect(result).toBe(false);
});

it("should handle numeric input for date", () => {
(getMultipleValuesInput as jest.Mock).mockReturnValue(["0", "6"]); // Sunday and Saturday

const date = new Date("2021-01-02T00:00:00Z").getTime(); // Saturday
const result = checkWeekend(date);
expect(result).toBe(true);
});

it("should return false if WEEKENDS environment variable is not set", () => {
(getMultipleValuesInput as jest.Mock).mockReturnValue([]);

const date = new Date("2021-01-02T00:00:00Z"); // Saturday
const result = checkWeekend(date);
expect(result).toBe(false);
});

it("should return true for custom weekend days", () => {
(getMultipleValuesInput as jest.Mock).mockReturnValue(["1", "2"]); // Monday and Tuesday

const date = new Date("2021-01-04T00:00:00Z"); // Monday
const result = checkWeekend(date);
expect(result).toBe(true);
});
});
8 changes: 8 additions & 0 deletions src/converters/utils/calculations/checkWeekend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { getDay } from "date-fns";
import { getMultipleValuesInput } from "../../../common/utils";

export const checkWeekend = (date: Date | number) => {
const currentDay = getDay(date);
const weekends = getMultipleValuesInput('WEEKENDS').map((el) => parseInt(el));
return weekends.includes(currentDay);
};
Loading