Revert line number implementation

This commit is contained in:
Justin Hutchings
2024-03-11 22:05:19 +00:00
parent 5bc19761c5
commit 70801db78f
4 changed files with 10 additions and 1109 deletions
Generated Vendored
+4 -1028
View File
File diff suppressed because it is too large Load Diff
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
Generated Vendored
-19
View File
@@ -1069,25 +1069,6 @@ Apache License
limitations under the License.
graceful-fs
ISC
The ISC License
Copyright (c) 2011-2022 Isaac Z. Schlueter, Ben Noordhuis, and Contributors
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
indent-string
MIT
MIT License
+5 -61
View File
@@ -367,70 +367,14 @@ async function createScorecardWarnings(
dependency.scorecard?.score &&
dependency.scorecard?.score < config.warn_on_openssf_scorecard_level
) {
const lineColNumbers: {
lineNumber: number
startCol: number
endCol: number
} = await findLineColNumbers(
dependency.change.manifest,
dependency.change.name
core.warning(
`${dependency.change.ecosystem}/${dependency.change.name} has an OpenSSF Scorecard of ${dependency.scorecard?.score}, which is less than this repository's threshold of ${config.warn_on_openssf_scorecard_level}.`,
{
title: 'OpenSSF Scorecard Warning'
}
)
core.debug(
`LineColNumbers: ${JSON.stringify(lineColNumbers)}; Manifest: ${dependency.change.manifest}; Name: ${dependency.change.name}`
)
if (lineColNumbers.lineNumber > 0 && lineColNumbers.startCol > 0) {
core.warning(
`${dependency.change.ecosystem}/${dependency.change.name} has an OpenSSF Scorecard of ${dependency.scorecard?.score}, which is less than this repository's threshold of ${config.warn_on_openssf_scorecard_level}.`,
{
title: 'OpenSSF Scorecard Warning',
file: dependency.change.manifest,
startLine: lineColNumbers.lineNumber,
endLine: lineColNumbers.lineNumber,
startColumn: lineColNumbers.startCol,
endColumn: lineColNumbers.endCol
}
)
} else {
core.warning(
`${dependency.change.ecosystem}/${dependency.change.name} has an OpenSSF Scorecard of ${dependency.scorecard?.score}, which is less than this repository's threshold of ${config.warn_on_openssf_scorecard_level}.`,
{
title: 'OpenSSF Scorecard Warning'
}
)
}
}
}
}
// Finds the line number of the package in the manifest file
async function findLineColNumbers(
manifest: string,
packageName: string
): Promise<{lineNumber: number; startCol: number; endCol: number}> {
// Concatenate the GITHUB_WORKSPACE to the manifest file
const fileName = path.join(process.env.GITHUB_WORKSPACE || '', manifest)
// Open the file
fs.readFile(fileName, 'utf8', function (err, data) {
if (err) {
core.error(`Error reading file: ${fileName}`)
throw err
}
core.debug(`File: ${fileName}, contents: ${data}`)
// split the file into lines
const lines = data.split('\n')
// search for the package name in the file
for (let lineNumber = 0; lineNumber < lines.length; lineNumber++) {
if (lines[lineNumber].includes(packageName)) {
const startCol = lines[lineNumber].indexOf(packageName)
const endCol = startCol + packageName.length
return {lineNumber, startCol, endCol}
}
}
return {lineNumber: -1, startCol: -1, endCol: -1}
})
return {lineNumber: -1, startCol: -1, endCol: -1}
}
run()