Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: summary support #21

Merged
merged 2 commits into from
Sep 28, 2024
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
8 changes: 5 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137841,7 +137841,7 @@ async function deleteOldComments(octokit, owner, repo, pull_number) {
});
}
}
async function commentOnPullRequest(analysis, artifactId) {
async function commentOnPullRequest(commentBody) {
if (!github.context.payload.pull_request) {
throw new Error("No pull request found in the context!");
}
Expand All @@ -137857,7 +137857,6 @@ async function commentOnPullRequest(analysis, artifactId) {
if (deleteComments) {
await deleteOldComments(octokit, owner, repo, pull_number);
}
const commentBody = getCommentTemplate(analysis, artifactId);
await octokit.rest.issues.createComment({
owner,
repo,
Expand All @@ -137878,6 +137877,7 @@ async function commentOnPullRequest(analysis, artifactId) {




const coveragePath = "vmd-analysis.json";
async function installVMD(skipInstall, pkgManager, version) {
if (skipInstall) {
Expand All @@ -137903,8 +137903,10 @@ async function runVueMessDetector(input) {
core.debug(runOutput);
const analysisOutput = parseAnalysisOutput(coveragePath);
const artifact = await uploadOutputArtifact(coveragePath);
const commentBody = getCommentTemplate(analysisOutput, artifact);
await core.summary.addRaw(commentBody).write();
if (isPullRequest() && input.commentsEnabled) {
await commentOnPullRequest(analysisOutput, artifact);
await commentOnPullRequest(commentBody);
}
}
catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions src/analyser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import fs from "node:fs";
import { uploadOutputArtifact } from "./github/artifact.js";
import { commentOnPullRequest } from "./github/comments.js";
import { tagsRemover } from "./utils/constants.js";
import { getCommentTemplate } from "./templates/commentTemplate.js";

const coveragePath: string = "vmd-analysis.json";

Expand Down Expand Up @@ -49,12 +50,12 @@ export async function runVueMessDetector(input: ActionInputs): Promise<void> {
core.debug(runOutput);

const analysisOutput: VMDAnalysis = parseAnalysisOutput(coveragePath);

const artifact: number | undefined =
await uploadOutputArtifact(coveragePath);

const commentBody: string = getCommentTemplate(analysisOutput, artifact);
await core.summary.addRaw(commentBody).write();
if (isPullRequest() && input.commentsEnabled) {
await commentOnPullRequest(analysisOutput, artifact);
await commentOnPullRequest(commentBody);
}
} catch (error: unknown) {
core.setFailed(error instanceof Error ? error.message : "Unknown error");
Expand Down
9 changes: 2 additions & 7 deletions src/github/comments.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as github from "@actions/github";
import * as core from "@actions/core";
import { VMDAnalysis } from "../types.js";
import { GitHub } from "@actions/github/lib/utils.js";
import { getCommentTemplate, watermark } from "../templates/commentTemplate.js";
import { watermark } from "../templates/commentTemplate.js";

async function deleteOldComments(
octokit: InstanceType<typeof GitHub>,
Expand All @@ -29,10 +28,7 @@ async function deleteOldComments(
}
}

export async function commentOnPullRequest(
analysis: VMDAnalysis,
artifactId: number | undefined
): Promise<void> {
export async function commentOnPullRequest(commentBody: string): Promise<void> {
if (!github.context.payload.pull_request) {
throw new Error("No pull request found in the context!");
}
Expand All @@ -53,7 +49,6 @@ export async function commentOnPullRequest(
if (deleteComments) {
await deleteOldComments(octokit, owner, repo, pull_number);
}
const commentBody: string = getCommentTemplate(analysis, artifactId);
await octokit.rest.issues.createComment({
owner,
repo,
Expand Down
Loading