Skip to content

Commit

Permalink
update permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
stenjo committed Aug 27, 2024
1 parent a2a59fb commit 46b4b42
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/stryker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ on:
branches:
- main

permissions:
contents: read
pull-requests: write
repository-projects: write
# permissions:
# contents: read
# pull-requests: write
# repository-projects: write

jobs:
stryker-js:
Expand Down
29 changes: 14 additions & 15 deletions script/generate_md_report.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
"""Generate MD report based on a json report"""
import json
import os
import sys
from collections import defaultdict
from urllib.parse import quote


def load_json_file(file_path: str) -> dict:
"""Load JSON data from a file."""
with open(file_path, "r", encoding="utf-8") as file:
return json.load(file)


def count_mutation_statuses(report: dict) -> dict:
"""Count the mutation statuses"""
status_counts = {}
total_counts: int = defaultdict(int)

Expand Down Expand Up @@ -43,18 +44,16 @@ def count_mutation_statuses(report: dict) -> dict:
}

# Calculate overall totals
total_killed = total_counts["Killed"]
total_survived = total_counts["Survived"]
total_timeout = total_counts["Timeout"]
total_relevant = total_killed + total_survived + total_timeout
total_counts["Timeout"] = total_counts["Timeout"]
total_relevant = total_counts["Killed"] + total_counts["Survived"] + total_counts["Timeout"]

total_score = (total_killed / total_relevant * 100) if total_relevant > 0 else 0
total_score = (total_counts["Killed"] / total_relevant * 100) if total_relevant > 0 else 0

status_counts["All"] = {
"score": total_score,
"killed": total_killed,
"timeout": total_timeout,
"survived": total_survived,
"killed": total_counts["Killed"],
"timeout": total_counts["Timeout"],
"survived": total_counts["Survived"],
"no_cov": total_counts["NoCoverage"],
"errors": total_counts["CompileError"],
"file_name": None, # No link for the total row
Expand All @@ -63,7 +62,7 @@ def count_mutation_statuses(report: dict) -> dict:
return status_counts


def generate_markdown_report(status_counts: dict, base_url: str) -> str:
def generate_markdown_report(status_counts: dict, url: str) -> str:
"""Generate a Markdown report summarizing
mutation status counts per file."""
markdown = "# Stryker report for changed files\n\n"
Expand All @@ -77,7 +76,7 @@ def generate_markdown_report(status_counts: dict, base_url: str) -> str:
# Remove 'src/' from the file path and create
# a URL link to the mutation report
relative_path = counts["file_name"].replace("src/", "")
link = f"{base_url}#mutant/{quote(relative_path)}"
link = f"{url}#mutant/{quote(relative_path)}"
file_link = f"[{file_name}]({link})"
else:
file_link = file_name
Expand All @@ -97,19 +96,19 @@ def save_markdown_file(markdown: str, output_path: str) -> None:
print(f"Markdown report generated at {output_path}")


def main(input_file: str, output_file: str, base_url: str):
def main(file: str, out_file: str, url: str):
"""Main function to process the mutation report and generate a summary."""
# Load the JSON data
mutation_report = load_json_file(input_file)
mutation_report = load_json_file(file)

# Count the mutation statuses per file and calculate scores
status_counts = count_mutation_statuses(mutation_report)

# Generate the Markdown report
markdown_report = generate_markdown_report(status_counts, base_url)
markdown_report = generate_markdown_report(status_counts, url)

# Save the Markdown report to a file
save_markdown_file(markdown_report, output_file)
save_markdown_file(markdown_report, out_file)


if __name__ == "__main__":
Expand Down

0 comments on commit 46b4b42

Please sign in to comment.