Skip to content

Commit

Permalink
add subdirectory input
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelst committed Jun 19, 2023
1 parent 2487adc commit a0ab7d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
Expand All @@ -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",
Expand Down

0 comments on commit a0ab7d0

Please sign in to comment.