whycode-cli 0.2.4__py3-none-any.whl → 0.2.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
whycode/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  """WhyCode — tells you what to be afraid of before touching a file."""
2
2
 
3
- __version__ = "0.2.4"
3
+ __version__ = "0.2.5"
whycode/cli.py CHANGED
@@ -238,6 +238,14 @@ def diff(
238
238
  json_out: bool = typer.Option(
239
239
  False, "--json", help="Emit machine-readable JSON instead of a table."
240
240
  ),
241
+ markdown: bool = typer.Option(
242
+ False,
243
+ "--markdown",
244
+ help=(
245
+ "Emit GitHub-flavoured markdown suitable for posting as a PR comment. "
246
+ "Pipe into a workflow step that calls `gh pr comment`."
247
+ ),
248
+ ),
241
249
  fail_on: str | None = typer.Option(
242
250
  None,
243
251
  "--fail-on",
@@ -305,6 +313,37 @@ def diff(
305
313
 
306
314
  flagged = [c for c in cards if _is_actionable(c)]
307
315
  quiet_n = len(cards) - len(flagged)
316
+ scope_md = "files staged for commit" if staged else f"files changed vs `{actual_base}`"
317
+ if markdown:
318
+ # Stable marker so a follow-up workflow step can find-and-update the
319
+ # same comment on subsequent pushes instead of stacking new ones.
320
+ print("<!-- whycode-comment -->")
321
+ print("## WhyCode risk briefing")
322
+ print()
323
+ print(f"**{len(files)} {scope_md}**")
324
+ print()
325
+ if not flagged:
326
+ print("Nothing flagged. Read the diff anyway.")
327
+ else:
328
+ print("| Score | Band | File | Top signal |")
329
+ print("| ----: | ---- | ---- | ---------- |")
330
+ for c in flagged:
331
+ top_signal = c.signals[0].headline.replace("|", "\\|")
332
+ print(
333
+ f"| {c.score.value} | {c.score.band.value} | "
334
+ f"`{c.path}` | {top_signal} |"
335
+ )
336
+ if quiet_n:
337
+ print()
338
+ print(f"_+ {quiet_n} file(s) changed with no flags._")
339
+ print()
340
+ print(
341
+ "_Run `whycode why <path>` for the full Risk Card on any of the above._"
342
+ )
343
+ if threshold is not None and any(c.score.value >= threshold for c in cards):
344
+ raise typer.Exit(1)
345
+ return
346
+
308
347
  scope = "staged for commit" if staged else f"changed vs {actual_base}"
309
348
  console.print(f"[bold]{len(files)} file(s) {scope}[/bold]")
310
349
  if not flagged:
@@ -1,11 +1,12 @@
1
1
  # Risk-rank pull requests with WhyCode.
2
2
  #
3
- # On every PR this workflow computes the Risk Card for each changed file
4
- # (vs the PR base) and prints a risk-ranked table to the job log.
5
- # Advisory by default humans decide.
3
+ # On every PR this workflow:
4
+ # 1. Computes the Risk Card for each changed file (vs the PR base)
5
+ # 2. Prints a risk-ranked table to the job log
6
+ # 3. Posts (or updates) a single PR comment with the same table
6
7
  #
7
- # To turn it into a hard gate that blocks merging, append `--fail-on <band>`
8
- # to the `whycode diff` line below:
8
+ # Advisory by default — humans decide. To turn it into a hard gate that
9
+ # blocks merging, append `--fail-on <band>` to the diff line:
9
10
  # handle block at HANDLE WITH CARE (score >= 75)
10
11
  # history block at READ HISTORY FIRST (score >= 50)
11
12
  # look stricter — block at >= 25
@@ -17,7 +18,7 @@ on:
17
18
 
18
19
  permissions:
19
20
  contents: read
20
- pull-requests: read
21
+ pull-requests: write # required to post / update the PR comment
21
22
 
22
23
  jobs:
23
24
  whycode:
@@ -36,5 +37,28 @@ jobs:
36
37
  - name: Install WhyCode
37
38
  run: pip install whycode-cli
38
39
 
39
- - name: Risk-rank files in this PR
40
+ - name: Risk-rank files in this PR (job log)
40
41
  run: whycode diff --base origin/${{ github.base_ref }}
42
+
43
+ - name: Build PR comment body
44
+ run: whycode diff --base origin/${{ github.base_ref }} --markdown > whycode-comment.md
45
+
46
+ - name: Post or update the PR comment
47
+ env:
48
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49
+ PR_NUMBER: ${{ github.event.pull_request.number }}
50
+ REPO: ${{ github.repository }}
51
+ run: |
52
+ set -euo pipefail
53
+ BODY=$(cat whycode-comment.md)
54
+ # Find any existing comment we previously posted (identified by the
55
+ # hidden HTML marker WhyCode emits at the top of the message).
56
+ EXISTING=$(gh api "repos/${REPO}/issues/${PR_NUMBER}/comments" \
57
+ --jq 'map(select(.body | contains("<!-- whycode-comment -->"))) | .[0].id // empty')
58
+ if [ -n "$EXISTING" ]; then
59
+ gh api -X PATCH "repos/${REPO}/issues/comments/${EXISTING}" \
60
+ -f body="$BODY" > /dev/null
61
+ else
62
+ gh api -X POST "repos/${REPO}/issues/${PR_NUMBER}/comments" \
63
+ -f body="$BODY" > /dev/null
64
+ fi
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: whycode-cli
3
- Version: 0.2.4
3
+ Version: 0.2.5
4
4
  Summary: Tells you what to be afraid of before you touch a file.
5
5
  Author: Kevin
6
6
  License-Expression: MIT
@@ -1,6 +1,6 @@
1
- whycode/__init__.py,sha256=vahOy3X-a02yX10f7cBtuylMKDlCKJQyvZVggnCiQqw,96
1
+ whycode/__init__.py,sha256=xXDqsMrsG7I_1V_VGQJ-kv6ORri4-rfyuFN-BlildIk,96
2
2
  whycode/__main__.py,sha256=dqAk6746YpuM-FTIH4TBOULegGc5WweojiZjce0VYgQ,105
3
- whycode/cli.py,sha256=jrX3GaMmZbNjnXzQtCViXMB6C3F-zwKKoMPtsISwgT4,30917
3
+ whycode/cli.py,sha256=QB33UGjSTF6DXcxM2r8TZcODIjOw0QqOBb9Kh7TsCbs,32464
4
4
  whycode/git_facts.py,sha256=VozSt59dWhUcDQ2qyDA2Bfa6AWvfBmIaQKP1DAYUpPM,17820
5
5
  whycode/ignore.py,sha256=sdRO_0HSedm8aO69CSGl-zQrUVX5MEg9QGcAJWwAvP4,3021
6
6
  whycode/mcp_server.py,sha256=56csOHSP90Zk59-_Puvk4WTSlCJ6xQAm-K10b_qmyAQ,7105
@@ -9,11 +9,11 @@ whycode/scorer.py,sha256=4pBejunfxzYhGUzMeL8uGEMQzC6DWiqwcTeMdo3eras,1444
9
9
  whycode/signals.py,sha256=14KziRolXvhmOnMnluXpPPInoBRO5uDu0tm024EYik0,13066
10
10
  whycode/suppressions.py,sha256=1lKSs-kCgpnJbcxozcgiSP8ZAfjEDMHXuM3sw4FaY78,3836
11
11
  whycode/templates/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
- whycode/templates/github-workflow.yml,sha256=yy87tbYKCexNYFso4e4OxGAdIIYOLn2cVxEt-FzP2oo,1095
12
+ whycode/templates/github-workflow.yml,sha256=LAfHMDG2TkAwi4vCNinHk-4zOt-mCWErBpmpaqlW5oA,2251
13
13
  whycode/templates/pre-commit,sha256=IhU11CvoDwqRAAsvHwUo-BwaNbdgy1cpXc54Z_phrmQ,316
14
- whycode_cli-0.2.4.dist-info/licenses/LICENSE,sha256=U6LN5qg5kJXSJf7KFPm9KJhmiGn3qK_GsTVWXdt1DFA,1062
15
- whycode_cli-0.2.4.dist-info/METADATA,sha256=ESACr8PI_DsPCZl0_LQ4fD0EhpsK1FEKgUrdwv3HDV4,9260
16
- whycode_cli-0.2.4.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
17
- whycode_cli-0.2.4.dist-info/entry_points.txt,sha256=xrNWc4CQn3ZhQFJxsGIPiTqpN19K4pRpgaj6qGaEzSQ,44
18
- whycode_cli-0.2.4.dist-info/top_level.txt,sha256=6yIL5rxW-4DbARHQYrPlGQVqKddZ88sjvmNosDh1w3A,8
19
- whycode_cli-0.2.4.dist-info/RECORD,,
14
+ whycode_cli-0.2.5.dist-info/licenses/LICENSE,sha256=U6LN5qg5kJXSJf7KFPm9KJhmiGn3qK_GsTVWXdt1DFA,1062
15
+ whycode_cli-0.2.5.dist-info/METADATA,sha256=IhRYXPiCmhDwmP2H_FiViZGeR4kw4o_tzwYVS60piV0,9260
16
+ whycode_cli-0.2.5.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
17
+ whycode_cli-0.2.5.dist-info/entry_points.txt,sha256=xrNWc4CQn3ZhQFJxsGIPiTqpN19K4pRpgaj6qGaEzSQ,44
18
+ whycode_cli-0.2.5.dist-info/top_level.txt,sha256=6yIL5rxW-4DbARHQYrPlGQVqKddZ88sjvmNosDh1w3A,8
19
+ whycode_cli-0.2.5.dist-info/RECORD,,