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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ Below is a table outlining the various configuration parameters available for **
| `INCLUDE_LABELS` | Only PRs with mentioned labels will be included in the report. Values should be separated by commas. Example: `bugfix, enhancement` | - |
| `INCLUDE_USERS` | Only data for the specified users or teams will be included in the report. Multiple values should be separated by commas. Example: `dev1, dev2, team1` | - |
| `EXCLUDE_USERS` | Data for the specified users or teams will be excluded from the report. Multiple values should be separated by commas. Example: `dev1, dev2, team1` | - |
| `FILTER_HEAD_BRANCHES` | Only PRs from head branches (source branches) matching the specified regular expression pattern will be included in the report. Example: `^feature` | - |
| `FILTER_BASE_BRANCHES` | Only PRs to base branches (target branches) matching the specified regular expression pattern will be included in the report. Example: `^develop$` | - |
| `EXECUTION_OUTCOME` | This parameter allows you to specify the format in which you wish to receive the report. Options include creating a new issue, updating an existing one, obtaining markdown, or JSON. Markdown and JSON will be available in outputs. Can take mulitple values separated by commas: `new-issue`, `markdown`, `collection`, `existing-issue`. This parameter is **required** Example: `existing-issue` | `new-issue` |
| `ISSUE_NUMBER` | Issue number to update. Add `existing-issue` to `EXECUTION_OUTCOME` for updating existing issue. The specified issue must already exist at the time the action is executed. This parameter is mandatory if the `EXECUTION_OUTCOME` input includes `existing-issue` value | - |
| `ALLOW_ANALYTICS` | Allows sending non-sensitive inputs to mixpanel for better understanding user's needs. Set the value to `false` to disable sending action parameter data | `true` |
Expand All @@ -305,6 +307,7 @@ Below is a table describing the possible outputs of **pull-request-analytics-act
- To hide individual metrics, specify users in the `HIDE_USERS` parameter or leave `total` and GitHub team names in the `SHOW_USERS` parameter.
- To avoid a long list of title changes when updating an existing issue, it is recommended to set the title yourself using the `ISSUE_TITLE` parameter.
- You can filter pull requests using labels with the `EXCLUDE_LABELS` and `INCLUDE_LABELS` parameters.
- You can filter pull requests by both source (head) and target (base) branches using the `EXCLUDE_HEAD_BRANCHES`, `INCLUDE_HEAD_BRANCHES`, `EXCLUDE_BASE_BRANCHES`, and `INCLUDE_BASE_BRANCHES` parameters. These parameters accept regular expression patterns for flexible filtering. Note that exclude filters always take priority over include filters.

## Troubleshooting

Expand Down
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ inputs:
EXCLUDE_LABELS:
description: "Excludes PRs with mentioned labels. Values should be separated by comma"
required: false
FILTER_HEAD_BRANCHES:
description: "Includes only PRs from head branches matching the specified regular expression pattern"
required: false
FILTER_BASE_BRANCHES:
description: "Includes only PRs to base branches matching the specified regular expression pattern"
required: false
INCLUDE_USERS:
description: "Only data for the specified users will be included in the report. Multiple values should be separated by commas"
required: false
Expand Down
64 changes: 50 additions & 14 deletions build/index.js

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

4 changes: 2 additions & 2 deletions package-lock.json

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": "4.8.1",
"version": "4.9.0",
"description": "Generates detailed PR analytics reports within GitHub, focusing on review efficiency and team performance.",
"main": "build/index.js",
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions src/analytics/sendActionError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export const sendActionError = (error: Error) => {
USE_CHARTS: getValueAsIs("USE_CHARTS"),
SHOW_CORRELATION_GRAPHS: getValueAsIs("SHOW_CORRELATION_GRAPHS"),
SHOW_ACTIVITY_TIME_GRAPHS: getValueAsIs("SHOW_ACTIVITY_TIME_GRAPHS"),
FILTER_HEAD_BRANCHES: !!getValueAsIs("FILTER_HEAD_BRANCHES"),
FILTER_BASE_BRANCHES: !!getValueAsIs("FILTER_BASE_BRANCHES"),
});
} else {
mixpanel.track("Anonymous action error", { distinct_id: "anonymous" });
Expand Down
2 changes: 2 additions & 0 deletions src/analytics/sendActionRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export const sendActionRun = () => {
USE_CHARTS: getValueAsIs("USE_CHARTS"),
SHOW_CORRELATION_GRAPHS: getValueAsIs("SHOW_CORRELATION_GRAPHS"),
SHOW_ACTIVITY_TIME_GRAPHS: getValueAsIs("SHOW_ACTIVITY_TIME_GRAPHS"),
FILTER_HEAD_BRANCHES: !!getValueAsIs("FILTER_HEAD_BRANCHES"),
FILTER_BASE_BRANCHES: !!getValueAsIs("FILTER_BASE_BRANCHES"),
});
} else {
mixpanel.track("Anomymous action run", { distinct_id: "anonymous" });
Expand Down
24 changes: 8 additions & 16 deletions src/requests/makeComplexRequest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { getMultipleValuesInput } from "../common/utils";
import { getMultipleValuesInput, getValueAsIs } from "../common/utils";
import { getDataWithThrottle } from "./getDataWithThrottle";
import { getPullRequests } from "./getPullRequests";
import { Options, Repository } from "./types";
import { filterPRs } from "./utils";

export const makeComplexRequest = async (
amount: number = 100,
Expand All @@ -12,21 +13,12 @@ export const makeComplexRequest = async (
) => {
const pullRequests = await getPullRequests(amount, repository);

const pullRequestNumbers = pullRequests
.filter((pr) => {
const excludeLabels = getMultipleValuesInput("EXCLUDE_LABELS");
const includeLabels = getMultipleValuesInput("INCLUDE_LABELS");
const isIncludeLabelsCorrect =
includeLabels.length > 0
? pr.labels.some((label) => includeLabels.includes(label.name))
: true;
const isExcludeLabelsCorrect =
excludeLabels.length > 0
? !pr.labels.some((label) => excludeLabels.includes(label.name))
: true;
return isIncludeLabelsCorrect && isExcludeLabelsCorrect;
})
.map((item) => item.number);
const pullRequestNumbers = filterPRs(pullRequests, {
excludeLabels: getMultipleValuesInput("EXCLUDE_LABELS"),
includeLabels: getMultipleValuesInput("INCLUDE_LABELS"),
filterHeadBranchesPattern: getValueAsIs("FILTER_HEAD_BRANCHES"),
filterBaseBranchesPattern: getValueAsIs("FILTER_BASE_BRANCHES"),
});

const { PRs, PREvents, PRComments } = await getDataWithThrottle(
pullRequestNumbers,
Expand Down
70 changes: 70 additions & 0 deletions src/requests/utils/filterPRs.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Mock data: 10 PRs with different branches and labels
export const mockPullRequests = [
// PRs with fix/ branch
{
number: 1,
head: { ref: "fix/authentication-bug" },
base: { ref: "main" },
labels: [{ name: "bug" }, { name: "enhancement" }],
},
{
number: 2,
head: { ref: "fix/ui-glitch" },
base: { ref: "develop" },
labels: [{ name: "ui-kit" }, { name: "bug" }],
},
{
number: 3,
head: { ref: "fix/validation-error" },
base: { ref: "main" },
labels: [],
},

// PRs with feature/ branch
{
number: 4,
head: { ref: "feature/user-dashboard" },
base: { ref: "develop" },
labels: [{ name: "enhancement" }, { name: "ui-kit" }],
},
{
number: 5,
head: { ref: "feature/export-functionality" },
base: { ref: "develop" },
labels: [{ name: "enhancement" }],
},
{
number: 6,
head: { ref: "feature/user-profile-page" },
base: { ref: "main" },
labels: [{ name: "enhancement" }, { name: "docs" }],
},

// PRs with refactor/ branch
{
number: 7,
head: { ref: "refactor/authentication-module" },
base: { ref: "develop" },
labels: [{ name: "enhancement" }],
},
{
number: 8,
head: { ref: "refactor/api-endpoints" },
base: { ref: "main" },
labels: [],
},

// PRs with cursor/ branch
{
number: 9,
head: { ref: "cursor/code-improvements" },
base: { ref: "main" },
labels: [{ name: "enhancement" }],
},
{
number: 10,
head: { ref: "cursor/ui-fixes" },
base: { ref: "develop" },
labels: [{ name: "ui-kit" }, { name: "bug" }],
},
];
Loading