| 165 | @click.argument("style") |
| 166 | @click.argument("mode") |
| 167 | def comment_body(baseline: Path, target: Path, style: str, mode: str) -> None: |
| 168 | cmd = ( |
| 169 | f"{sys.executable} -m diff_shades --no-color " |
| 170 | f"compare {baseline} {target} --quiet --check" |
| 171 | ).split(" ") |
| 172 | proc = subprocess.run(cmd, stdout=subprocess.PIPE, encoding="utf-8") |
| 173 | if proc.returncode: |
| 174 | run_id = os.getenv("GITHUB_RUN_ID") |
| 175 | jobs = http_get( |
| 176 | f"https://api.github.com/repos/{REPO}/actions/runs/{run_id}/jobs", |
| 177 | )["jobs"] |
| 178 | job = next(j for j in jobs if j["name"] == f"compare / {mode}") |
| 179 | diff_step = next(s for s in job["steps"] if s["name"] == DIFF_STEP_NAME) |
| 180 | diff_url = f"{job['html_url']}#step:{diff_step['number']}:1" |
| 181 | |
| 182 | body = ( |
| 183 | "<details>" |
| 184 | f"<summary><b><code>--{style}</code> style</b> " |
| 185 | f'(<a href="{diff_url}">View full diff</a>):</summary>' |
| 186 | f"<pre>{proc.stdout.strip()}</pre>" |
| 187 | "</details>" |
| 188 | ) |
| 189 | else: |
| 190 | body = f"<b><code>--{style}</code> style</b>: no changes" |
| 191 | |
| 192 | filename = f".{style}{COMMENT_FILE}" |
| 193 | print(f"[INFO]: writing comment details to {filename}") |
| 194 | with open(filename, "w", encoding="utf-8") as f: |
| 195 | f.write(body) |
| 196 | |
| 197 | |
| 198 | @main.command("comment-details", help="Get PR comment resources from a workflow run.") |