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
123 changes: 95 additions & 28 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.7.5",
"version": "1.8.0",
"description": "github action to show prs report",
"main": "build/index.js",
"scripts": {
Expand Down
33 changes: 4 additions & 29 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
import "dotenv/config";
import * as core from "@actions/core";

import { createMarkdown } from "./view";
import {
createIssue,
getOwnersRepositories,
makeComplexRequest,
} from "./requests";
import { createOutput } from "./view";
import { getOwnersRepositories, makeComplexRequest } from "./requests";
import { collectData } from "./converters";
import { octokit } from "./octokit/octokit";
import {
checkCommentSkip,
getMultipleValuesInput,
setTimezone,
validate,
} from "./common/utils";
import { checkCommentSkip, setTimezone, validate } from "./common/utils";

async function main() {
setTimezone();
Expand Down Expand Up @@ -71,23 +62,7 @@ async function main() {
);
const preparedData = collectData(mergedData);
console.log("Calculation complete. Generating markdown.");
const markdown = createMarkdown(preparedData);
console.log("Markdown successfully generated.");
getMultipleValuesInput("EXECUTION_OUTCOME")
.filter((outcome) =>
["new-issue", "output", "collection", "markdown"].includes(outcome)
)
.forEach((outcome) => {
if (outcome === "new-issue") {
createIssue(markdown);
}
if (outcome === "markdown" || outcome === "output") {
core.setOutput("MARKDOWN", markdown);
}
if (outcome === "collection") {
core.setOutput("JSON_COLLECTION", JSON.stringify(preparedData));
}
});
await createOutput(preparedData);

const rateLimitAtEnd = await octokit.rest.rateLimit.get();
console.log(
Expand Down
5 changes: 3 additions & 2 deletions src/requests/createIssue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { octokit } from "../octokit/octokit";
import { format } from "date-fns";
import { getMultipleValuesInput } from "../common/utils";

export const createIssue = (markdown: string) => {
export const createIssue = async (markdown: string) => {
const issueTitle =
core.getInput("ISSUE_TITLE") ||
process.env.ISSUE_TITLE ||
Expand All @@ -17,7 +17,7 @@ export const createIssue = (markdown: string) => {
(assignee) => assignee && typeof assignee === "string"
) || [];

octokit.rest.issues.create({
const result = await octokit.rest.issues.create({
repo:
core.getInput("GITHUB_REPO_FOR_ISSUE") ||
process.env.GITHUB_REPO_FOR_ISSUE!,
Expand All @@ -29,4 +29,5 @@ export const createIssue = (markdown: string) => {
labels,
assignees,
});
return result;
};
28 changes: 7 additions & 21 deletions src/view/createMarkdown.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
import { Collection } from "../converters/types";
import {
StatsType,
createConfigParamsCode,
createPullRequestQualityTable,
createReviewTable,
createTimelineContent,
createTimelineMonthsGanttBar,
createTotalTable,
getDisplayUserList,
sortCollectionsByDate,
} from "./utils";
import { getMultipleValuesInput } from "../common/utils";

export const createMarkdown = (
data: Record<string, Record<string, Collection>>
data: Record<string, Record<string, Collection>>,
users: string[],
dates: string[],
title: string = "Pull Request report"
) => {
const users = getDisplayUserList(data);

const dates = sortCollectionsByDate(data.total);

const contentTypes = getMultipleValuesInput("SHOW_STATS_TYPES");

const content = dates.map((date) => {
Expand All @@ -39,23 +34,14 @@ export const createMarkdown = (
`;
});

if (content.join("").trim() === "") return "";

return `
## Pull Request report
## ${title}
This report based on ${
data.total?.total?.closed || 0
} last updated PRs. To learn more about the project and its configuration, please visit [Pull request analytics action](https://github.com/AlexSim93/pull-request-analytics-action).
${createConfigParamsCode()}
${content.join("\n")}
${getMultipleValuesInput("AGGREGATE_VALUE_METHODS")
.filter((method) => ["average", "median", "percentile"].includes(method))
.map((type) =>
createTimelineMonthsGanttBar(
data,
type as StatsType,
dates.filter((date) => date !== "total"),
"total"
)
)
.join("\n")}
`;
};
Loading