From a0ab7d049e18144fc34f322875a404f97a0ac783 Mon Sep 17 00:00:00 2001 From: Michael St Clair Date: Mon, 19 Jun 2023 15:20:06 -0600 Subject: [PATCH] add subdirectory input --- action.yaml | 3 +++ index.js | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/action.yaml b/action.yaml index 4f6ed67..3517086 100644 --- a/action.yaml +++ b/action.yaml @@ -15,6 +15,9 @@ inputs: github_token: description: GitHub Token required: true + subdirectory: + description: If your app is in a subdirectory, specify it here + required: false outputs: covered: description: Number of lines covered diff --git a/index.js b/index.js index 6aa1fc5..539f73b 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,9 @@ import { HttpClient } from "@actions/http-client" import Decimal from "decimal.js-light" import fs from "fs" +import path from "path" + +const subdirectory = core.getInput("subdirectory") || "" const parse = (data, changedFiles) => { const { covered, coveredForPatch, relevant, relevantForPatch, annotations } = data.source_files.reduce( @@ -14,7 +17,10 @@ const parse = (data, changedFiles) => { const relevant = sourceLines.filter(l => l.coverage !== null) const relevantForPatch = relevant.filter( - line => file.name in changedFiles && changedFiles[file.name].includes(`+${line.code}`) + line => { + const fileName = path.join(subdirectory, file.name) + return fileName in changedFiles && changedFiles[fileName].includes(`+${line.code}`) + } ) const covered = relevant.filter(l => l.coverage > 0) @@ -24,7 +30,7 @@ const parse = (data, changedFiles) => { .filter(l => l.coverage === 0) .map(line => { return { - path: file.name, + path: path.join(subdirectory, file.name), start_line: line.lineNumber, end_line: line.lineNumber, annotation_level: "warning",