@bbcsoftwarefactory/skills 0.0.0-stage → 0.1.1
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.
- package/dist/index.json +42 -0
- package/dist/skills/code-quality-gate/SKILL.md +59 -0
- package/dist/skills/code-quality-gate/references/gate-bigo.md +31 -0
- package/dist/skills/code-quality-gate/references/gate-earlyreturn.md +73 -0
- package/dist/skills/code-quality-gate/references/gate-typesafe.md +32 -0
- package/dist/skills/code-quality-gate/references/output-schema.yml +40 -0
- package/dist/skills/code-quality-gate/scripts/extract-diff-scope.py +225 -0
- package/dist/skills/code-quality-gate/tests/extract-diff-scope.test.sh +200 -0
- package/dist/skills/delivery-coordinator/SKILL.md +81 -0
- package/dist/skills/delivery-coordinator/references/hud-output.md +55 -0
- package/dist/skills/delivery-coordinator/references/intake.md +86 -0
- package/dist/skills/delivery-coordinator/references/issue-claim.md +143 -0
- package/dist/skills/delivery-coordinator/references/issue-dedup.md +38 -0
- package/dist/skills/delivery-coordinator/references/sleuth-regression-exercise.md +60 -0
- package/dist/skills/delivery-coordinator/references/visual-reference.md +45 -0
- package/dist/skills/delivery-coordinator/references/worktree-isolation.md +19 -0
- package/dist/skills/delivery-coordinator/scripts/check-issue-claim.py +363 -0
- package/dist/skills/delivery-coordinator/scripts/check-worktree-guard.py +220 -0
- package/dist/skills/delivery-coordinator/scripts/classify-change-lane.py +263 -0
- package/dist/skills/delivery-coordinator/tests/check-issue-claim.test.sh +221 -0
- package/dist/skills/delivery-coordinator/tests/check-worktree-guard.test.sh +123 -0
- package/dist/skills/delivery-coordinator/tests/classify-change-lane.test.sh +124 -0
- package/dist/skills/documentation-steward/SKILL.md +43 -0
- package/dist/skills/documentation-steward/references/discovery.md +17 -0
- package/dist/skills/documentation-steward/references/handoff.md +15 -0
- package/dist/skills/greptile-review-loop/SKILL.md +57 -0
- package/dist/skills/greptile-review-loop/references/review-protocol.md +37 -0
- package/dist/skills/greptile-review-loop/scripts/review-loop.py +435 -0
- package/dist/skills/greptile-review-loop/tests/review-loop.test.sh +331 -0
- package/dist/skills/issue-reviewer/SKILL.md +87 -0
- package/dist/skills/issue-reviewer/references/review-format.md +100 -0
- package/dist/skills/issue-reviewer/references/triage.md +105 -0
- package/dist/skills/issue-reviewer/scripts/fetch-issue-attachments.py +239 -0
- package/dist/skills/issue-reviewer/scripts/plan-issue-triage.py +311 -0
- package/dist/skills/issue-reviewer/tests/fetch-issue-attachments.test.sh +90 -0
- package/dist/skills/issue-reviewer/tests/plan-issue-triage.test.sh +168 -0
- package/dist/skills/question-gate/SKILL.md +66 -0
- package/dist/skills/question-gate/references/client-hooks.md +111 -0
- package/dist/skills/question-gate/references/diagram-routing.md +58 -0
- package/dist/skills/question-gate/scripts/triage-question.py +713 -0
- package/dist/skills/question-gate/tests/fixtures/question-corpus.json +481 -0
- package/dist/skills/question-gate/tests/question-corpus.test.sh +32 -0
- package/dist/skills/question-gate/tests/triage-question.test.sh +441 -0
- package/dist/skills/regression-testing/SKILL.md +49 -0
- package/dist/skills/regression-testing/references/evidence-record.md +35 -0
- package/dist/skills/requirements-spec/SKILL.md +59 -0
- package/dist/skills/risk-scout/SKILL.md +53 -0
- package/dist/skills/risk-scout/references/risk-matrix.md +49 -0
- package/dist/skills/skill-clean-architecture/SKILL.md +54 -0
- package/dist/skills/skill-clean-architecture/references/layer-rules.md +22 -0
- package/dist/skills/skill-clean-architecture/references/source-headers.md +31 -0
- package/dist/skills/skill-clean-architecture/scripts/measure-bigo.py +427 -0
- package/dist/skills/skill-clean-architecture/tests/fixtures/bigo/bad-utf8.js +1 -0
- package/dist/skills/skill-clean-architecture/tests/fixtures/bigo/edge-crlf.ts +6 -0
- package/dist/skills/skill-clean-architecture/tests/fixtures/bigo/edge-mixed.ts +15 -0
- package/dist/skills/skill-clean-architecture/tests/fixtures/bigo/empty.js +0 -0
- package/dist/skills/skill-clean-architecture/tests/fixtures/bigo/no-newline.js +1 -0
- package/dist/skills/skill-clean-architecture/tests/fixtures/bigo.expected.yml +95 -0
- package/dist/skills/skill-clean-architecture/tests/measure-bigo.test.sh +222 -0
- package/dist/skills/tool-depot/SKILL.md +47 -0
- package/dist/skills/tool-depot/references/checkout.md +29 -0
- package/dist/skills/tool-depot/references/loki-read.md +41 -0
- package/dist/skills/tool-depot/references/readonly-access.md +84 -0
- package/dist/skills/tool-depot/references/tool-catalog.json +47 -0
- package/dist/skills/tool-depot/scripts/loki-runtime-logs.py +305 -0
- package/dist/skills/tool-depot/tests/loki-runtime-logs.test.sh +101 -0
- package/dist/skills/watcher-observability/SKILL.md +73 -0
- package/dist/skills/watcher-observability/references/batch-protocol.md +44 -0
- package/dist/skills/watcher-observability/references/configuration.md +31 -0
- package/dist/skills/watcher-observability/references/error-scan.md +102 -0
- package/dist/skills/watcher-observability/references/live-protocol.md +49 -0
- package/dist/skills/watcher-observability/references/server-account.md +72 -0
- package/dist/skills/watcher-observability/scripts/error-scan.py +318 -0
- package/dist/skills/watcher-observability/scripts/resolve-containers.py +155 -0
- package/dist/skills/watcher-observability/scripts/save-counts.py +381 -0
- package/dist/skills/watcher-observability/scripts/summarize-logs.py +113 -0
- package/dist/skills/watcher-observability/scripts/watch-live.py +606 -0
- package/dist/skills/watcher-observability/server/watcher-gate.sh +51 -0
- package/dist/skills/watcher-observability/tests/error-scan.test.sh +257 -0
- package/dist/skills/watcher-observability/tests/live-windows.test.sh +177 -0
- package/dist/skills/watcher-observability/tests/resolve-containers.test.sh +87 -0
- package/dist/skills/watcher-observability/tests/save-counts.test.sh +338 -0
- package/dist/skills/watcher-observability/tests/sleuth.test.sh +176 -0
- package/dist/skills/watcher-observability/tests/summarize-logs.test.sh +105 -0
- package/dist/skills/watcher-observability/tests/watcher-config.test.sh +70 -0
- package/dist/skills/watcher-observability/tests/watcher-gate.test.sh +110 -0
- package/dist/skills/watcher-observability/watcher.json +1 -0
- package/dist/skills/workflow-auditor/SKILL.md +55 -0
- package/dist/skills/workflow-auditor/references/audit-protocol.md +49 -0
- package/dist/skills/workflow-auditor/references/ledger.md +122 -0
- package/dist/skills/workflow-auditor/scripts/audit-ledger.py +624 -0
- package/dist/skills/workflow-auditor/scripts/list-zed-commands.py +183 -0
- package/dist/skills/workflow-auditor/scripts/render-workflow.py +201 -0
- package/dist/skills/workflow-auditor/scripts/validate-skills.py +444 -0
- package/dist/skills/workflow-auditor/tests/audit-ledger.test.sh +660 -0
- package/dist/skills/workflow-auditor/tests/list-zed-commands.test.sh +93 -0
- package/dist/skills/workflow-auditor/tests/render-workflow.test.sh +135 -0
- package/dist/skills/workflow-auditor/tests/validate-skills.test.sh +190 -0
- package/package.json +27 -6
- package/README.md +0 -3
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Triage: assign the author, label, and prioritize
|
|
2
|
+
|
|
3
|
+
Every issue review ends with a triage plan: the issue author is assigned, the labels are reviewed against what the issue actually is, and the issue gets one priority. The reviewer (an LLM) judges type, area, and priority from the evidence; `scripts/plan-issue-triage.py` turns that judgment into the only GitHub writes allowed. The triage is applied only after the person approves the exact plan at the Boss Gate, and a comment on the issue always states what was done and why.
|
|
4
|
+
|
|
5
|
+
Every rule below has an ID. The script decides the `TR*` rules; `workflow-auditor` checks `I1`–`I2` in the ledger. When an LLM reading this file and the script disagree, the script's verdict stands and the difference is reported.
|
|
6
|
+
|
|
7
|
+
## Why the author is assigned
|
|
8
|
+
|
|
9
|
+
The author reported what they saw, so they own confirming it: answering questions, validating the fix, and closing the loop. The assignment is a **reporter assignment**, not a claim to build the fix. Without the claim label (`status:in-progress`), [`check-issue-claim.py`](../../delivery-coordinator/references/issue-claim.md#reporter-assignment) does not treat the author as holding the issue, so a developer can still claim it.
|
|
10
|
+
|
|
11
|
+
## 1. Read (Tool Depot `github-read` / `check-issue-triage`)
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
gh api repos/<owner>/<repo>/issues/<n> > issue.json
|
|
15
|
+
gh api --paginate --slurp "repos/<owner>/<repo>/labels?per_page=100" > labels.json
|
|
16
|
+
gh api -i repos/<owner>/<repo>/assignees/<author> # status 204: yes, 404: no
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Any other result of the assignability call (network error, 403) is `unknown`.
|
|
20
|
+
|
|
21
|
+
## 2. Judge (LLM)
|
|
22
|
+
|
|
23
|
+
Decide from the evidence already gathered in the review (text, attachments, code, PRs, sanitized logs), never from the title alone. Write the proposal to `proposal.json`:
|
|
24
|
+
|
|
25
|
+
```json
|
|
26
|
+
{"priority": "P1", "add": ["bug", "area:flows"], "remove": ["enhancement"],
|
|
27
|
+
"rationale": "Saving any flow fails for every bot in production (screenshot + 42 HTTP_5xx in Watcher); no workaround."}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
| Decision | How to judge |
|
|
31
|
+
|---|---|
|
|
32
|
+
| Type | `bug` when current behavior contradicts what the product promises; `enhancement` / `feature` for a new capability; `documentation` or `question` when nothing is broken. Remove a type label the review contradicts. |
|
|
33
|
+
| Area | The component or route the review identified (`area:*` or the repository's equivalent). Only areas with evidence; ambiguity stays a `🟡` note. |
|
|
34
|
+
| Verdict labels | `🔴 POSIBLE FALSA ALARMA` → `invalid` or `needs-info` if they exist; `🟠 YA RESUELTO` → `duplicate` if another issue covers it; `🟡 SIN CONFIRMAR` → `needs-info` when the author must supply proof. |
|
|
35
|
+
| Priority | The rubric below. Pick the lowest level the evidence supports; a hypothesis never raises the level. |
|
|
36
|
+
|
|
37
|
+
| Level | Meaning | Typical evidence |
|
|
38
|
+
|---|---|---|
|
|
39
|
+
| `P0` Crítica | Production down, data loss or corruption, security exposure, or payments blocked; no workaround. | Many customers or all bots affected; confirmed in logs or code. |
|
|
40
|
+
| `P1` Alta | A core feature is broken or wrong for many users, or the workaround is costly. | Confirmed, reproducible, recurring. |
|
|
41
|
+
| `P2` Media | A secondary feature fails, or a core one with a reasonable workaround. | Limited scope or intermittent. |
|
|
42
|
+
| `P3` Baja | Cosmetic, copy, minor UX, or a nice-to-have improvement. | No functional impact. |
|
|
43
|
+
|
|
44
|
+
The `rationale` names the facts behind the level (who is affected, how often, workaround, evidence) in the issue's language. It is pasted into the comment, so it must be sanitized.
|
|
45
|
+
|
|
46
|
+
## 3. Plan (`plan-issue-triage.py`)
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
python3 -I -B <issue-reviewer>/scripts/plan-issue-triage.py --repo <owner>/<repo> \
|
|
50
|
+
--issue-json issue.json --labels-json labels.json --proposal-json proposal.json \
|
|
51
|
+
--author-assignable yes|no|unknown [--claim-label status:in-progress]
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The script resolves label names to the repository's exact spelling, derives the priority label from the level when the proposal names none, replaces any other priority label on the issue, and prints the exact `commands`.
|
|
55
|
+
|
|
56
|
+
| Verdict | Exit | Next |
|
|
57
|
+
|---|---|---|
|
|
58
|
+
| `ready` | 0 | Show the plan at the Boss Gate. |
|
|
59
|
+
| `ready-with-gaps` | 0 | Show the plan and each gap; the comment states them. |
|
|
60
|
+
| `invalid-proposal` | 1 | Fix the proposal and rerun; no commands are printed. |
|
|
61
|
+
| `unusable` | 2 | Report what is missing; do not triage from memory. |
|
|
62
|
+
|
|
63
|
+
| Rule | Condition | Effect |
|
|
64
|
+
|---|---|---|
|
|
65
|
+
| `TR1` | An input is missing or malformed, the issue is not open, the priority is not `P0`–`P3`, the rationale is empty, or a label is both added and removed. | `unusable` |
|
|
66
|
+
| `TR2` | The author is a bot (`user.type` `Bot` or a `[bot]` login). | Gap: nobody is assigned. |
|
|
67
|
+
| `TR3` | The author cannot be assigned (`no`) or that was not verified (`unknown`). | Gap: nobody is assigned. |
|
|
68
|
+
| `TR4` | A proposed label does not exist in the repository. | Gap: the label is dropped; the workflow never creates labels. |
|
|
69
|
+
| `TR5` | The proposal adds or removes a `status:*` label or the claim label. | `invalid-proposal`: those belong to the delivery workflow. |
|
|
70
|
+
| `TR6` | More than one priority label would be added. | `invalid-proposal` |
|
|
71
|
+
| `TR7` | The priority label does not match the level, or several repository labels mean that level and none was named. | `invalid-proposal` |
|
|
72
|
+
| `TR8` | The repository has no label for the level. | Gap: the priority goes in the comment only; a maintainer may create the label. |
|
|
73
|
+
|
|
74
|
+
Priority labels are recognized by name: `priority:*`, `prioridad:*`, `prio:*`, or `P0`–`P3`, with level words `critical`/`crítica`/`urgent`, `high`/`alta`, `medium`/`media`, `low`/`baja`.
|
|
75
|
+
|
|
76
|
+
## 4. Boss Gate, apply, and say it (Tool Depot `github-write` / `triage-approved-issue`)
|
|
77
|
+
|
|
78
|
+
Show the plan (assignee, `+`/`−` labels, priority with rationale, gaps) at the issue-reviewer Boss Gate together with the refined draft. The person's approval of that exact plan covers the `commands` and the comment that states them; any change to the plan needs a new approval.
|
|
79
|
+
|
|
80
|
+
Run the `commands` exactly as printed: add the author (never remove or add anyone else), add labels, remove labels. Then post one comment (`comment-approved-issue`) in the issue's language, after the triage, with a visual reference ([rule](../../delivery-coordinator/references/visual-reference.md)); reusing the issue's own attachment is enough. When the body was also refined, this one comment covers both.
|
|
81
|
+
|
|
82
|
+
```markdown
|
|
83
|
+
## 🏷️ Triage
|
|
84
|
+
- **Asignado a:** @<author> — quien abrió el issue; queda como responsable de confirmar el comportamiento, responder dudas y validar la solución.
|
|
85
|
+
- **Etiquetas:** +`bug` +`area:flows` −`enhancement`
|
|
86
|
+
- **Prioridad:** P1 (Alta) — <rationale>
|
|
87
|
+
- 🟡 <one line per gap: bot or non-assignable author, dropped label, missing priority label>
|
|
88
|
+
|
|
89
|
+

|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Ledger record and rules checked by `workflow-auditor`
|
|
93
|
+
|
|
94
|
+
When a delivery ledger exists, record the read, the triage write, and the comment as Tool Depot requests and uses on the same target (`owner/repo#n`):
|
|
95
|
+
|
|
96
|
+
```json
|
|
97
|
+
{"id": "TD-4", "requester": "issue-reviewer", "tool": "github-write", "purpose": "triage-approved-issue",
|
|
98
|
+
"target": "example/repo#7", "operation": "assign carla; +bug +priority:high -priority:low",
|
|
99
|
+
"disposition": "eligible", "authorization": "AUTH-2"}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
| Rule | Violation |
|
|
103
|
+
|---|---|
|
|
104
|
+
| `I1` | A `triage-approved-issue` use with no earlier eligible `check-issue-triage` use on the same issue. |
|
|
105
|
+
| `I2` | A `triage-approved-issue` use with no later `comment-approved-issue` use on the same issue. |
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Fetch and download visual attachments from a GitHub issue and its comments.
|
|
3
|
+
|
|
4
|
+
Uses `gh api` with `Accept: application/vnd.github.full+json` so private-repo
|
|
5
|
+
`github.com/user-attachments/assets/...` embeds resolve to short-lived signed URLs
|
|
6
|
+
in `body_html`.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import argparse
|
|
10
|
+
import html
|
|
11
|
+
import json
|
|
12
|
+
import mimetypes
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
import re
|
|
15
|
+
import subprocess
|
|
16
|
+
import sys
|
|
17
|
+
import tempfile
|
|
18
|
+
import urllib.error
|
|
19
|
+
import urllib.parse
|
|
20
|
+
import urllib.request
|
|
21
|
+
|
|
22
|
+
IMG_SRC_RE = re.compile(r'<img\b[^>]*\bsrc=["\']([^"\']+)["\']', re.IGNORECASE)
|
|
23
|
+
LINK_HREF_RE = re.compile(r'<a\b[^>]*\bhref=["\']([^"\']+)["\']', re.IGNORECASE)
|
|
24
|
+
MD_IMAGE_RE = re.compile(r'!\[[^\]]*\]\((https?://[^)\s]+)\)')
|
|
25
|
+
|
|
26
|
+
IMAGE_EXTENSIONS = ('.png', '.jpg', '.jpeg', '.gif', '.webp', '.svg')
|
|
27
|
+
MAX_ATTACHMENT_BYTES = 20 * 1024 * 1024
|
|
28
|
+
ALLOWED_HOSTS = (
|
|
29
|
+
'github.com',
|
|
30
|
+
'raw.githubusercontent.com',
|
|
31
|
+
'user-images.githubusercontent.com',
|
|
32
|
+
'private-user-images.githubusercontent.com',
|
|
33
|
+
'objects.githubusercontent.com',
|
|
34
|
+
'avatars.githubusercontent.com',
|
|
35
|
+
)
|
|
36
|
+
REPO_RE = re.compile(r'^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$')
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def is_allowed_attachment_url(url):
|
|
40
|
+
parsed = urllib.parse.urlparse(url)
|
|
41
|
+
if parsed.scheme.lower() != 'https':
|
|
42
|
+
return False
|
|
43
|
+
host = (parsed.hostname or '').lower()
|
|
44
|
+
if not host:
|
|
45
|
+
return False
|
|
46
|
+
if host in ALLOWED_HOSTS or host.endswith('.githubusercontent.com'):
|
|
47
|
+
return True
|
|
48
|
+
return False
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def extract_urls_from_html(body_html, body_md=''):
|
|
52
|
+
urls = []
|
|
53
|
+
seen = set()
|
|
54
|
+
|
|
55
|
+
for raw in IMG_SRC_RE.findall(body_html or ''):
|
|
56
|
+
clean = html.unescape(raw).strip()
|
|
57
|
+
if clean and clean not in seen:
|
|
58
|
+
seen.add(clean)
|
|
59
|
+
urls.append({'kind': 'image', 'url': clean})
|
|
60
|
+
|
|
61
|
+
for raw in LINK_HREF_RE.findall(body_html or ''):
|
|
62
|
+
clean = html.unescape(raw).strip()
|
|
63
|
+
if not clean or clean in seen:
|
|
64
|
+
continue
|
|
65
|
+
parsed = urllib.parse.urlparse(clean)
|
|
66
|
+
path_lower = parsed.path.lower()
|
|
67
|
+
if (
|
|
68
|
+
'user-attachments' in parsed.path
|
|
69
|
+
or 'private-user-images.githubusercontent.com' in parsed.netloc
|
|
70
|
+
or 'objects.githubusercontent.com' in parsed.netloc
|
|
71
|
+
or path_lower.endswith(IMAGE_EXTENSIONS)
|
|
72
|
+
):
|
|
73
|
+
seen.add(clean)
|
|
74
|
+
urls.append({'kind': 'attachment', 'url': clean})
|
|
75
|
+
|
|
76
|
+
for raw in MD_IMAGE_RE.findall(body_md or ''):
|
|
77
|
+
clean = html.unescape(raw).strip()
|
|
78
|
+
if clean and clean not in seen and 'github.com/user-attachments/' not in clean:
|
|
79
|
+
seen.add(clean)
|
|
80
|
+
urls.append({'kind': 'image', 'url': clean})
|
|
81
|
+
|
|
82
|
+
return urls
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def extension_for_content_type(content_type, url):
|
|
86
|
+
ct = (content_type or '').split(';')[0].strip().lower()
|
|
87
|
+
if ct:
|
|
88
|
+
ext = mimetypes.guess_extension(ct)
|
|
89
|
+
if ext == '.jpe':
|
|
90
|
+
return '.jpg'
|
|
91
|
+
if ext:
|
|
92
|
+
return ext
|
|
93
|
+
path_ext = Path(urllib.parse.urlparse(url).path).suffix.lower()
|
|
94
|
+
if path_ext in IMAGE_EXTENSIONS:
|
|
95
|
+
return path_ext
|
|
96
|
+
return '.bin'
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
class _SafeRedirectHandler(urllib.request.HTTPRedirectHandler):
|
|
100
|
+
def redirect_request(self, req, fp, code, msg, headers, newurl):
|
|
101
|
+
if not is_allowed_attachment_url(newurl):
|
|
102
|
+
raise urllib.error.URLError(f'Refusing untrusted redirect host: {newurl}')
|
|
103
|
+
return super().redirect_request(req, fp, code, msg, headers, newurl)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def download_attachment(url, dest_dir, index):
|
|
107
|
+
if not is_allowed_attachment_url(url):
|
|
108
|
+
return {
|
|
109
|
+
'url': url,
|
|
110
|
+
'local_path': None,
|
|
111
|
+
'content_type': None,
|
|
112
|
+
'bytes': 0,
|
|
113
|
+
'status': 'error',
|
|
114
|
+
'error': 'Untrusted attachment URL scheme or host',
|
|
115
|
+
}
|
|
116
|
+
req = urllib.request.Request(url, headers={'User-Agent': 'bbc-issue-reviewer/1.0'})
|
|
117
|
+
opener = urllib.request.build_opener(_SafeRedirectHandler())
|
|
118
|
+
try:
|
|
119
|
+
with opener.open(req, timeout=20) as resp:
|
|
120
|
+
content_type = resp.headers.get('Content-Type', '')
|
|
121
|
+
chunks = []
|
|
122
|
+
total = 0
|
|
123
|
+
while True:
|
|
124
|
+
chunk = resp.read(65536)
|
|
125
|
+
if not chunk:
|
|
126
|
+
break
|
|
127
|
+
total += len(chunk)
|
|
128
|
+
if total > MAX_ATTACHMENT_BYTES:
|
|
129
|
+
raise ValueError(f'Attachment exceeds {MAX_ATTACHMENT_BYTES} byte limit')
|
|
130
|
+
chunks.append(chunk)
|
|
131
|
+
payload = b''.join(chunks)
|
|
132
|
+
except (urllib.error.URLError, TimeoutError, OSError, ValueError) as err:
|
|
133
|
+
return {
|
|
134
|
+
'url': url,
|
|
135
|
+
'local_path': None,
|
|
136
|
+
'content_type': None,
|
|
137
|
+
'bytes': 0,
|
|
138
|
+
'status': 'error',
|
|
139
|
+
'error': str(err),
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
ext = extension_for_content_type(content_type, url)
|
|
143
|
+
is_image = content_type.lower().startswith('image/') or ext in IMAGE_EXTENSIONS
|
|
144
|
+
out_path = Path(dest_dir) / f'attachment-{index}{ext}'
|
|
145
|
+
out_path.write_bytes(payload)
|
|
146
|
+
return {
|
|
147
|
+
'url': url,
|
|
148
|
+
'local_path': str(out_path),
|
|
149
|
+
'content_type': content_type or None,
|
|
150
|
+
'bytes': len(payload),
|
|
151
|
+
'status': 'downloaded' if is_image else 'downloaded_non_image',
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def fetch_github_json(endpoint):
|
|
156
|
+
proc = subprocess.run(
|
|
157
|
+
['gh', 'api', '-H', 'Accept: application/vnd.github.full+json', endpoint],
|
|
158
|
+
capture_output=True,
|
|
159
|
+
text=True,
|
|
160
|
+
check=False,
|
|
161
|
+
timeout=20,
|
|
162
|
+
)
|
|
163
|
+
if proc.returncode != 0:
|
|
164
|
+
raise RuntimeError(proc.stderr.strip() or f'gh api failed for {endpoint}')
|
|
165
|
+
return json.loads(proc.stdout)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def process_issue_payload(issue_data, comments_data, out_dir, downloader=download_attachment):
|
|
169
|
+
entries = []
|
|
170
|
+
seen_urls = set()
|
|
171
|
+
|
|
172
|
+
sources = [('body', issue_data)] + [
|
|
173
|
+
(f'comment:{c.get("id", idx)}', c) for idx, c in enumerate(comments_data or [], start=1)
|
|
174
|
+
]
|
|
175
|
+
|
|
176
|
+
counter = 0
|
|
177
|
+
for source_name, item in sources:
|
|
178
|
+
if not isinstance(item, dict):
|
|
179
|
+
continue
|
|
180
|
+
found = extract_urls_from_html(item.get('body_html', ''), item.get('body', ''))
|
|
181
|
+
for entry in found:
|
|
182
|
+
url = entry['url']
|
|
183
|
+
if url in seen_urls:
|
|
184
|
+
continue
|
|
185
|
+
seen_urls.add(url)
|
|
186
|
+
counter += 1
|
|
187
|
+
dl = downloader(url, out_dir, counter)
|
|
188
|
+
dl['source'] = source_name
|
|
189
|
+
dl['kind'] = entry['kind']
|
|
190
|
+
entries.append(dl)
|
|
191
|
+
|
|
192
|
+
return {
|
|
193
|
+
'issue': issue_data.get('number'),
|
|
194
|
+
'title': issue_data.get('title'),
|
|
195
|
+
'url': issue_data.get('html_url'),
|
|
196
|
+
'out_dir': str(out_dir),
|
|
197
|
+
'attachments': entries,
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def parse_args(argv):
|
|
202
|
+
parser = argparse.ArgumentParser(
|
|
203
|
+
description='Resolve and download attachments from a GitHub issue via gh api body_html.'
|
|
204
|
+
)
|
|
205
|
+
parser.add_argument('--repo', help='GitHub repository in owner/repo format.')
|
|
206
|
+
parser.add_argument('--issue', type=int, help='Issue number.')
|
|
207
|
+
parser.add_argument('--out', help='Output directory for downloaded attachments.')
|
|
208
|
+
parser.add_argument('--stdin', action='store_true', help='Read {"issue": ..., "comments": ...} JSON from stdin.')
|
|
209
|
+
return parser.parse_args(argv)
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def main(argv):
|
|
213
|
+
args = parse_args(argv)
|
|
214
|
+
out_dir = Path(args.out) if args.out else Path(tempfile.mkdtemp(prefix=f'bbc-issue-{args.issue or "stdin"}-'))
|
|
215
|
+
out_dir.mkdir(parents=True, exist_ok=True)
|
|
216
|
+
|
|
217
|
+
if args.stdin:
|
|
218
|
+
payload = json.load(sys.stdin)
|
|
219
|
+
issue_data = payload.get('issue', {})
|
|
220
|
+
comments_data = payload.get('comments', [])
|
|
221
|
+
report = process_issue_payload(issue_data, comments_data, out_dir)
|
|
222
|
+
else:
|
|
223
|
+
if not args.repo or not args.issue or not REPO_RE.fullmatch(args.repo) or args.issue <= 0:
|
|
224
|
+
print(json.dumps({'error': 'Pass --repo owner/repo and positive --issue N (or --stdin).'}))
|
|
225
|
+
return 2
|
|
226
|
+
try:
|
|
227
|
+
issue_data = fetch_github_json(f'repos/{args.repo}/issues/{args.issue}')
|
|
228
|
+
comments_data = fetch_github_json(f'repos/{args.repo}/issues/{args.issue}/comments')
|
|
229
|
+
except (RuntimeError, ValueError, OSError, subprocess.SubprocessError) as err:
|
|
230
|
+
print(json.dumps({'error': str(err)}))
|
|
231
|
+
return 1
|
|
232
|
+
report = process_issue_payload(issue_data, comments_data, out_dir)
|
|
233
|
+
|
|
234
|
+
print(json.dumps(report, indent=2, ensure_ascii=False))
|
|
235
|
+
return 0
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
if __name__ == '__main__':
|
|
239
|
+
sys.exit(main(sys.argv[1:]))
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""plan-issue-triage.py: turn an LLM triage proposal into the exact, safe GitHub writes for one issue.
|
|
3
|
+
|
|
4
|
+
Read-only and offline: it evaluates GitHub REST (or `gh --json`) output fetched through Tool Depot
|
|
5
|
+
and the reviewer's proposal, and never calls GitHub itself. Rules TR1-TR8 are defined in
|
|
6
|
+
references/triage.md.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import json
|
|
10
|
+
import re
|
|
11
|
+
import sys
|
|
12
|
+
from urllib.parse import quote
|
|
13
|
+
|
|
14
|
+
DEFAULT_CLAIM_LABEL = 'status:in-progress'
|
|
15
|
+
ASSIGNABLE = ('yes', 'no', 'unknown')
|
|
16
|
+
PRIORITIES = ('P0', 'P1', 'P2', 'P3')
|
|
17
|
+
PRIORITY_NAME = re.compile(r'(?:priority|prioridad|prio)\s*[:/_ -]\s*(.+)|(p[0-3])\b.*')
|
|
18
|
+
LEVEL_WORDS = {
|
|
19
|
+
'p0': 0, 'critical': 0, 'critica': 0, 'crítica': 0, 'urgent': 0, 'urgente': 0, 'blocker': 0,
|
|
20
|
+
'p1': 1, 'high': 1, 'alta': 1,
|
|
21
|
+
'p2': 2, 'medium': 2, 'media': 2, 'normal': 2,
|
|
22
|
+
'p3': 3, 'low': 3, 'baja': 3, 'minor': 3,
|
|
23
|
+
}
|
|
24
|
+
INVALID_RULES = ('TR5', 'TR6', 'TR7')
|
|
25
|
+
SHELL_SPECIAL = re.compile(r'(["$`\\])')
|
|
26
|
+
|
|
27
|
+
HELP = (
|
|
28
|
+
'Usage: python3 -I -B scripts/plan-issue-triage.py --repo <owner/repo>\n'
|
|
29
|
+
' --issue-json <file> gh api repos/<o>/<r>/issues/<n> (or gh issue view <n> --json ...)\n'
|
|
30
|
+
' --labels-json <file> gh api --paginate --slurp "repos/<o>/<r>/labels?per_page=100"\n'
|
|
31
|
+
' --proposal-json <file> {"priority": "P0-P3", "add": [...], "remove": [...], "rationale": "..."}\n'
|
|
32
|
+
' --author-assignable yes|no|unknown gh api repos/<o>/<r>/assignees/<author> (204 yes, 404 no)\n'
|
|
33
|
+
' [--claim-label status:in-progress]\n'
|
|
34
|
+
'Exit 0: ready or ready-with-gaps; 1: invalid-proposal; 2: unusable.'
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class Unusable(Exception):
|
|
39
|
+
"""The inputs cannot be evaluated (rule TR1)."""
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _write_out(text):
|
|
43
|
+
sys.stdout.buffer.write((text + '\n').encode('utf-8', 'surrogateescape'))
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _fold(value):
|
|
47
|
+
return value.strip().casefold() if isinstance(value, str) else ''
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _login(value):
|
|
51
|
+
if isinstance(value, dict):
|
|
52
|
+
value = value.get('login')
|
|
53
|
+
return value if isinstance(value, str) and value.strip() else None
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _flatten(value):
|
|
57
|
+
if isinstance(value, list) and all(isinstance(item, list) for item in value):
|
|
58
|
+
return [item for page in value for item in page]
|
|
59
|
+
return value
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _names(items):
|
|
63
|
+
names = []
|
|
64
|
+
for item in items or []:
|
|
65
|
+
name = item.get('name') if isinstance(item, dict) else item
|
|
66
|
+
if isinstance(name, str) and name.strip():
|
|
67
|
+
names.append(name)
|
|
68
|
+
return names
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _load_json(path, label):
|
|
72
|
+
try:
|
|
73
|
+
with open(path, encoding='utf-8') as handle:
|
|
74
|
+
return json.load(handle)
|
|
75
|
+
except OSError:
|
|
76
|
+
raise Unusable(label + ' cannot be read.')
|
|
77
|
+
except ValueError:
|
|
78
|
+
raise Unusable(label + ' is not valid JSON.')
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def load_issue(path):
|
|
82
|
+
raw = _load_json(path, 'Issue JSON')
|
|
83
|
+
if not isinstance(raw, dict) or not isinstance(raw.get('number'), int):
|
|
84
|
+
raise Unusable('Issue JSON needs a numeric number.')
|
|
85
|
+
if not isinstance(raw.get('state'), str) or raw['state'].lower() != 'open':
|
|
86
|
+
raise Unusable('Only an open issue is triaged; reopen it first.')
|
|
87
|
+
user = raw.get('user') if isinstance(raw.get('user'), dict) else raw.get('author')
|
|
88
|
+
author = _login(user)
|
|
89
|
+
if author is None:
|
|
90
|
+
raise Unusable('Issue JSON needs the author login (user.login).')
|
|
91
|
+
kind = user.get('type') if isinstance(user, dict) else None
|
|
92
|
+
return {
|
|
93
|
+
'number': raw['number'],
|
|
94
|
+
'author': author,
|
|
95
|
+
'bot': kind == 'Bot' or author.endswith('[bot]') or bool(isinstance(user, dict) and user.get('is_bot')),
|
|
96
|
+
'assignees': [login for login in map(_login, raw.get('assignees') or []) if login],
|
|
97
|
+
'labels': _names(raw.get('labels')),
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def load_labels(path):
|
|
102
|
+
raw = _flatten(_load_json(path, 'Repository labels JSON'))
|
|
103
|
+
if not isinstance(raw, list):
|
|
104
|
+
raise Unusable('Repository labels JSON must be an array.')
|
|
105
|
+
return _names(raw)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def load_proposal(path):
|
|
109
|
+
raw = _load_json(path, 'Proposal JSON')
|
|
110
|
+
if not isinstance(raw, dict):
|
|
111
|
+
raise Unusable('Proposal JSON must be an object.')
|
|
112
|
+
priority = raw.get('priority')
|
|
113
|
+
if not isinstance(priority, str) or priority.strip().upper() not in PRIORITIES:
|
|
114
|
+
raise Unusable('Proposal priority must be one of: ' + ', '.join(PRIORITIES) + '.')
|
|
115
|
+
if not isinstance(raw.get('rationale'), str) or not raw['rationale'].strip():
|
|
116
|
+
raise Unusable('Proposal needs a rationale grounded in the evidence.')
|
|
117
|
+
lists = {}
|
|
118
|
+
for key in ('add', 'remove'):
|
|
119
|
+
value = raw.get(key) or []
|
|
120
|
+
if not isinstance(value, list) or not all(isinstance(name, str) and name.strip() for name in value):
|
|
121
|
+
raise Unusable('Proposal "' + key + '" must be an array of label names.')
|
|
122
|
+
lists[key] = value
|
|
123
|
+
both = {_fold(name) for name in lists['add']} & {_fold(name) for name in lists['remove']}
|
|
124
|
+
if both:
|
|
125
|
+
raise Unusable('A label cannot be added and removed at once: ' + ', '.join(sorted(both)) + '.')
|
|
126
|
+
return {'priority': priority.strip().upper(), 'add': lists['add'], 'remove': lists['remove'],
|
|
127
|
+
'rationale': raw['rationale'].strip()}
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def priority_level(name):
|
|
131
|
+
"""(is a priority label, level 0-3 or None when the level word is unknown)."""
|
|
132
|
+
match = PRIORITY_NAME.fullmatch(_fold(name))
|
|
133
|
+
if match is None:
|
|
134
|
+
return False, None
|
|
135
|
+
word = match.group(2) or re.split(r'[\s:/_-]+', match.group(1).strip())[0]
|
|
136
|
+
return True, LEVEL_WORDS.get(word)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def _is_priority(name):
|
|
140
|
+
return priority_level(name)[0]
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
class Report:
|
|
144
|
+
def __init__(self):
|
|
145
|
+
self.findings = []
|
|
146
|
+
|
|
147
|
+
def add(self, rule, detail, labels=None):
|
|
148
|
+
finding = {'rule': rule, 'detail': detail}
|
|
149
|
+
if labels:
|
|
150
|
+
finding['labels'] = labels
|
|
151
|
+
self.findings.append(finding)
|
|
152
|
+
|
|
153
|
+
def verdict(self):
|
|
154
|
+
rules = {finding['rule'] for finding in self.findings}
|
|
155
|
+
if rules & set(INVALID_RULES):
|
|
156
|
+
return 'invalid-proposal'
|
|
157
|
+
return 'ready-with-gaps' if rules else 'ready'
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def plan_assignment(issue, assignable, report):
|
|
161
|
+
if issue['bot']:
|
|
162
|
+
report.add('TR2', 'The author is a bot; nobody is assigned. Say so in the triage comment.')
|
|
163
|
+
return None, False
|
|
164
|
+
if _fold(issue['author']) in {_fold(login) for login in issue['assignees']}:
|
|
165
|
+
return None, True
|
|
166
|
+
if assignable != 'yes':
|
|
167
|
+
reason = 'cannot be assigned in this repository' if assignable == 'no' else 'was not verified as assignable'
|
|
168
|
+
report.add('TR3', 'The author ' + reason + '; nobody is assigned. Say so in the triage comment.')
|
|
169
|
+
return None, False
|
|
170
|
+
return issue['author'], False
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def plan_priority(proposal, resolved_add, repo_labels, current, report):
|
|
174
|
+
level = int(proposal['priority'][1])
|
|
175
|
+
chosen = [name for name in resolved_add if _is_priority(name)]
|
|
176
|
+
if len(chosen) > 1:
|
|
177
|
+
report.add('TR6', 'Only one priority label may be set.', chosen)
|
|
178
|
+
return None
|
|
179
|
+
if chosen:
|
|
180
|
+
if priority_level(chosen[0])[1] != level:
|
|
181
|
+
report.add('TR7', 'The priority label does not match ' + proposal['priority'] + '.', chosen)
|
|
182
|
+
return chosen[0]
|
|
183
|
+
candidates = [name for name in repo_labels if priority_level(name) == (True, level)]
|
|
184
|
+
on_issue = [name for name in candidates if _fold(name) in current]
|
|
185
|
+
if len(candidates) == 1 or len(on_issue) == 1:
|
|
186
|
+
return (on_issue or candidates)[0]
|
|
187
|
+
if candidates:
|
|
188
|
+
report.add('TR7', 'Several repository labels mean ' + proposal['priority'] + '; name one in "add".', candidates)
|
|
189
|
+
return None
|
|
190
|
+
detail = ('The repository has no priority labels' if not any(map(_is_priority, repo_labels))
|
|
191
|
+
else 'The repository has no label for ' + proposal['priority'])
|
|
192
|
+
report.add('TR8', detail + '; state the priority in the triage comment only. A maintainer may create the label.')
|
|
193
|
+
return None
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def evaluate(issue, repo_labels, proposal, assignable, claim_label):
|
|
197
|
+
report = Report()
|
|
198
|
+
real = {}
|
|
199
|
+
for name in repo_labels:
|
|
200
|
+
real.setdefault(_fold(name), name)
|
|
201
|
+
current = {_fold(name): name for name in issue['labels']}
|
|
202
|
+
|
|
203
|
+
protected = [name for name in proposal['add'] + proposal['remove']
|
|
204
|
+
if _fold(name) == _fold(claim_label) or _fold(name).startswith('status:')]
|
|
205
|
+
if protected:
|
|
206
|
+
report.add('TR5', 'Status and claim labels belong to the delivery workflow; triage never changes them.',
|
|
207
|
+
protected)
|
|
208
|
+
|
|
209
|
+
resolved_add, missing, seen = [], [], set()
|
|
210
|
+
for name in proposal['add']:
|
|
211
|
+
if _fold(name) not in real:
|
|
212
|
+
missing.append(name)
|
|
213
|
+
elif _fold(name) not in seen:
|
|
214
|
+
seen.add(_fold(name))
|
|
215
|
+
resolved_add.append(real[_fold(name)])
|
|
216
|
+
if missing:
|
|
217
|
+
report.add('TR4', 'Labels missing in the repository were dropped; the workflow never creates labels.', missing)
|
|
218
|
+
|
|
219
|
+
priority_label = plan_priority(proposal, resolved_add, repo_labels, current, report)
|
|
220
|
+
if priority_label is not None and _fold(priority_label) not in seen:
|
|
221
|
+
resolved_add.append(priority_label)
|
|
222
|
+
labels_add = [name for name in resolved_add if _fold(name) not in current]
|
|
223
|
+
labels_remove = [current[_fold(name)] for name in proposal['remove'] if _fold(name) in current]
|
|
224
|
+
removed = {_fold(name) for name in labels_remove}
|
|
225
|
+
for name in issue['labels']:
|
|
226
|
+
if _is_priority(name) and _fold(name) != _fold(priority_label) and _fold(name) not in removed:
|
|
227
|
+
removed.add(_fold(name))
|
|
228
|
+
labels_remove.append(name)
|
|
229
|
+
|
|
230
|
+
assign, already = plan_assignment(issue, assignable, report)
|
|
231
|
+
final = [name for name in issue['labels'] if _fold(name) not in removed] + labels_add
|
|
232
|
+
return {
|
|
233
|
+
'verdict': report.verdict(),
|
|
234
|
+
'issue': issue['number'],
|
|
235
|
+
'author': issue['author'],
|
|
236
|
+
'assign': assign,
|
|
237
|
+
'already_assigned': already,
|
|
238
|
+
'labels_add': labels_add,
|
|
239
|
+
'labels_remove': labels_remove,
|
|
240
|
+
'labels_final': final,
|
|
241
|
+
'priority': proposal['priority'],
|
|
242
|
+
'priority_label': priority_label,
|
|
243
|
+
'missing_labels': missing,
|
|
244
|
+
'rationale': proposal['rationale'],
|
|
245
|
+
'findings': report.findings,
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def _arg(value):
|
|
250
|
+
return '"' + SHELL_SPECIAL.sub(r'\\\1', value) + '"'
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def commands(plan, repo):
|
|
254
|
+
base = 'repos/' + repo + '/issues/' + str(plan['issue'])
|
|
255
|
+
lines = []
|
|
256
|
+
if plan['assign']:
|
|
257
|
+
lines.append('gh api -X POST ' + base + '/assignees -f ' + _arg('assignees[]=' + plan['assign']))
|
|
258
|
+
if plan['labels_add']:
|
|
259
|
+
lines.append('gh api -X POST ' + base + '/labels ' + ' '.join('-f ' + _arg('labels[]=' + name)
|
|
260
|
+
for name in plan['labels_add']))
|
|
261
|
+
for name in plan['labels_remove']:
|
|
262
|
+
lines.append('gh api -X DELETE ' + base + '/labels/' + quote(name, safe=''))
|
|
263
|
+
return lines
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def parse_args(argv):
|
|
267
|
+
options = {'repo': None, 'issue': None, 'labels': None, 'proposal': None, 'assignable': None,
|
|
268
|
+
'claim_label': DEFAULT_CLAIM_LABEL}
|
|
269
|
+
keys = {'--repo': 'repo', '--issue-json': 'issue', '--labels-json': 'labels', '--proposal-json': 'proposal',
|
|
270
|
+
'--author-assignable': 'assignable', '--claim-label': 'claim_label'}
|
|
271
|
+
args = list(argv)
|
|
272
|
+
while args:
|
|
273
|
+
arg = args.pop(0)
|
|
274
|
+
if arg in ('-h', '--help'):
|
|
275
|
+
return None
|
|
276
|
+
if arg not in keys or not args:
|
|
277
|
+
raise Unusable('Unexpected argument ' + arg + '; see --help.')
|
|
278
|
+
options[keys[arg]] = args.pop(0)
|
|
279
|
+
missing = [flag for flag, key in keys.items() if key != 'claim_label' and not options[key]]
|
|
280
|
+
if missing:
|
|
281
|
+
raise Unusable('Required: ' + ', '.join(missing) + '.')
|
|
282
|
+
if not re.fullmatch(r'[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+', options['repo']):
|
|
283
|
+
raise Unusable('--repo must be <owner>/<repo>.')
|
|
284
|
+
if options['assignable'] not in ASSIGNABLE:
|
|
285
|
+
raise Unusable('--author-assignable must be one of: ' + ', '.join(ASSIGNABLE) + '.')
|
|
286
|
+
return options
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
def main(argv):
|
|
290
|
+
try:
|
|
291
|
+
options = parse_args(argv)
|
|
292
|
+
if options is None:
|
|
293
|
+
_write_out(HELP)
|
|
294
|
+
return 0
|
|
295
|
+
issue = load_issue(options['issue'])
|
|
296
|
+
repo_labels = load_labels(options['labels'])
|
|
297
|
+
proposal = load_proposal(options['proposal'])
|
|
298
|
+
plan = evaluate(issue, repo_labels, proposal, options['assignable'], options['claim_label'])
|
|
299
|
+
except Unusable as error:
|
|
300
|
+
_write_out(json.dumps({'verdict': 'unusable', 'proceed': False,
|
|
301
|
+
'findings': [{'rule': 'TR1', 'detail': str(error)}]}, indent=2, ensure_ascii=False))
|
|
302
|
+
return 2
|
|
303
|
+
proceed = plan['verdict'] != 'invalid-proposal'
|
|
304
|
+
plan['proceed'] = proceed
|
|
305
|
+
plan['commands'] = commands(plan, options['repo']) if proceed else []
|
|
306
|
+
_write_out(json.dumps(plan, indent=2, ensure_ascii=False))
|
|
307
|
+
return 0 if proceed else 1
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
if __name__ == '__main__':
|
|
311
|
+
sys.exit(main(sys.argv[1:]))
|