Added support for external repository file links

This commit is contained in:
Michael Chen 2022-12-13 15:48:29 +01:00
parent ca6fee127c
commit b4f5e3ebd4
Signed by: cnml
GPG Key ID: 5845BF3F82D5F629
2 changed files with 5 additions and 1 deletions

View File

@ -218,6 +218,7 @@ from typing import TypedDict
class Artifact(TypedDict): class Artifact(TypedDict):
file: str file: str
lines: NotRequired[list[int]] lines: NotRequired[list[int]]
repository: NotRequired[str]
class SecurityRule(TypedDict): class SecurityRule(TypedDict):
status: str status: str
@ -253,6 +254,8 @@ properties:
properties: properties:
file: file:
type: string type: string
repository:
type: string
lines: lines:
type: array type: array
items: items:
@ -306,7 +309,7 @@ rule_names = {
def artifact_to_string(info: ModelInformation, artifact: Artifact): def artifact_to_string(info: ModelInformation, artifact: Artifact):
file = Path(artifact['file']) file = Path(artifact['file'])
filename = file.name filename = file.name
file_url = f"https://github.com/{info['slug']}/blob/{info.get('branch', 'master')}/{artifact['file']}" file_url = f"https://github.com/{artifact.get('repository', info['slug'])}/blob/{info.get('branch', 'master')}/{artifact['file']}"
lines = artifact.get("lines") lines = artifact.get("lines")
if lines is None: if lines is None:
return f"- {filename}: [File]({file_url})" return f"- {filename}: [File]({file_url})"

View File

@ -27,6 +27,7 @@
"type": "object", "type": "object",
"additionalProperties": false, "additionalProperties": false,
"properties": { "properties": {
"repository": { "type": "string" },
"file": { "type": "string" }, "file": { "type": "string" },
"lines": { "type": "array", "items": { "type": "integer" } } "lines": { "type": "array", "items": { "type": "integer" } }
}, },