@bbcsoftwarefactory/commands 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.
@@ -0,0 +1,275 @@
1
+ #!/usr/bin/env bash
2
+ set -eu
3
+ cd -- "${BASH_SOURCE[0]%/*}/.."
4
+ PYTHON_BIN=$(command -v python3 || command -v python)
5
+ "$PYTHON_BIN" -I -X utf8 -B - <<'PY'
6
+ import importlib.util
7
+ import json
8
+ from pathlib import Path
9
+ import subprocess
10
+ import sys
11
+ import tempfile
12
+
13
+ script_path = Path('scripts/recap.py')
14
+ assert script_path.is_file(), f'Missing {script_path}'
15
+
16
+ spec = importlib.util.spec_from_file_location('recap', script_path)
17
+ mod = importlib.util.module_from_spec(spec)
18
+ spec.loader.exec_module(mod)
19
+
20
+ checks = 0
21
+
22
+ # 1. CLI help and invalid flag handling
23
+ assert mod.main(['--help']) == 0
24
+ assert mod.main(['--repo', 'invalid/repo/extra']) == 2
25
+ assert mod.main(['--since', 'not-a-date']) == 2
26
+ assert mod.main(['--project', 'not-a-project']) == 2
27
+ assert mod.main(['--sync-board']) == 2
28
+ checks += 1
29
+
30
+ # 2. --since and --project parsing
31
+ dt_day = mod.parse_since('2026-11-30')
32
+ assert dt_day.year == 2026 and dt_day.month == 11 and dt_day.day == 30
33
+ dt_rel = mod.parse_since('12h')
34
+ assert dt_rel.tzinfo is not None
35
+ pref_url = mod.parse_project_ref('https://github.com/orgs/example-org/projects/1/views/7')
36
+ assert pref_url == {'owner_type': 'organization', 'owner': 'example-org', 'number': 1, 'view': 7}, pref_url
37
+ pref_short = mod.parse_project_ref('example-org/1')
38
+ assert pref_short == {'owner_type': 'organization', 'owner': 'example-org', 'number': 1, 'view': None}, pref_short
39
+ checks += 1
40
+
41
+ # 3. Synthetic payload with all 7 metrics + date filtering
42
+ payload = {
43
+ 'user': 'dev-alice',
44
+ 'repo': 'example-org/example-app',
45
+ 'since': '2026-11-30T00:00:00+00:00',
46
+ 'github_available': True,
47
+ 'issues_created': [
48
+ {'number': 101, 'title': 'Add recap', 'state': 'open', 'created_at': '2026-11-30T09:00:00Z', 'url': 'https://github.com/example-org/example-app/issues/101'},
49
+ {'number': 102, 'title': 'Fix parser', 'state': 'closed', 'created_at': '2026-11-30T10:00:00Z', 'url': 'https://github.com/example-org/example-app/issues/102'},
50
+ {'number': 90, 'title': 'Old issue', 'state': 'open', 'created_at': '2026-11-29T22:00:00Z', 'url': 'https://github.com/example-org/example-app/issues/90'},
51
+ ],
52
+ 'issues_closed': [
53
+ {'number': 95, 'title': 'Older bug fixed', 'closed_at': '2026-11-30T08:30:00Z', 'url': 'https://github.com/example-org/example-app/issues/95'},
54
+ {'number': 98, 'title': 'Docs gap', 'closed_at': '2026-11-30T11:00:00Z', 'url': 'https://github.com/example-org/example-app/issues/98'},
55
+ {'number': 102, 'title': 'Fix parser', 'closed_at': '2026-11-30T12:00:00Z', 'url': 'https://github.com/example-org/example-app/issues/102'},
56
+ {'number': 80, 'title': 'Closed yesterday', 'closed_at': '2026-11-29T18:00:00Z', 'url': 'https://github.com/example-org/example-app/issues/80'},
57
+ ],
58
+ 'prs_opened': [
59
+ {'number': 201, 'title': 'feat: recap', 'state': 'closed', 'draft': False, 'created_at': '2026-11-30T09:30:00Z', 'merged_at': '2026-11-30T13:00:00Z', 'ci_status': 'success', 'url': 'https://github.com/example-org/example-app/pull/201'},
60
+ {'number': 202, 'title': 'fix: edge case', 'state': 'open', 'draft': False, 'created_at': '2026-11-30T14:00:00Z', 'merged_at': None, 'ci_status': 'success', 'url': 'https://github.com/example-org/example-app/pull/202'},
61
+ ],
62
+ 'prs_merged': [
63
+ {'number': 201, 'title': 'feat: recap', 'merged_at': '2026-11-30T13:00:00Z', 'url': 'https://github.com/example-org/example-app/pull/201'},
64
+ {'number': 199, 'title': 'chore: cleanup', 'merged_at': '2026-11-30T07:45:00Z', 'url': 'https://github.com/example-org/example-app/pull/199'},
65
+ ],
66
+ 'prs_in_progress': [
67
+ {'number': 202, 'title': 'fix: edge case', 'draft': False, 'updated_at': '2026-11-30T14:15:00Z', 'ci_status': 'success'},
68
+ {'number': 203, 'title': 'wip: refactor', 'draft': True, 'updated_at': '2026-11-30T15:00:00Z', 'ci_status': 'pending'},
69
+ ],
70
+ 'reviews_and_comments': 2,
71
+ 'local_git': {
72
+ 'available': True,
73
+ 'branch': 'feat/recap-command',
74
+ 'commits': 4,
75
+ 'files_changed': 5,
76
+ 'insertions': 120,
77
+ 'deletions': 35,
78
+ 'ahead_commits': 1,
79
+ 'working_changes': 2,
80
+ },
81
+ }
82
+
83
+ report = mod.compute_recap(payload)
84
+ assert report['issues_created']['count'] == 2, report['issues_created']
85
+ assert report['issues_closed']['count'] == 3, report['issues_closed']
86
+ assert report['prs_opened']['count'] == 2, report['prs_opened']
87
+ assert report['contribution']['commits'] == 4, report['contribution']
88
+ assert report['contribution']['files_changed'] == 5
89
+ assert report['contribution']['insertions'] == 120
90
+ assert report['contribution']['deletions'] == 35
91
+ assert report['contribution']['reviews_and_comments'] == 2
92
+ assert report['solved']['issues_closed'] == 3
93
+ assert report['solved']['prs_merged'] == 2
94
+ assert report['solved']['total'] == 5
95
+ assert report['progress']['prs_open_updated'] == 2
96
+ assert report['progress']['prs_ready'] == 1
97
+ assert report['progress']['prs_draft'] == 1
98
+ assert report['progress']['ahead_commits'] == 1
99
+ assert report['progress']['working_changes'] == 2
100
+ assert report['effectiveness']['pr_merge_ratio']['display'] == '2/2 (100%)'
101
+ assert report['effectiveness']['ci_pass_rate']['display'] == '2/2 (100%)'
102
+ assert report['effectiveness']['issue_close_ratio']['display'] == '3/2 (150%)'
103
+ checks += 1
104
+
105
+ # 4. Zero-denominator and unavailable GitHub gap never invent data
106
+ gap_report = mod.compute_recap({
107
+ 'user': None,
108
+ 'repo': 'example-org/example-app',
109
+ 'since': '2026-11-30T00:00:00+00:00',
110
+ 'github_available': False,
111
+ 'github_gap': 'gh CLI not authenticated',
112
+ 'local_git': {
113
+ 'available': True,
114
+ 'branch': 'main',
115
+ 'commits': 0,
116
+ 'files_changed': 0,
117
+ 'insertions': 0,
118
+ 'deletions': 0,
119
+ 'ahead_commits': 0,
120
+ 'working_changes': 0,
121
+ },
122
+ })
123
+ assert gap_report['issues_created']['count'] is None
124
+ assert gap_report['issues_closed']['count'] is None
125
+ assert gap_report['prs_opened']['count'] is None
126
+ assert gap_report['effectiveness']['pr_merge_ratio']['display'] == 'N/A'
127
+ assert gap_report['effectiveness']['ci_pass_rate']['display'] == 'N/A'
128
+ assert gap_report['effectiveness']['issue_close_ratio']['display'] == 'N/A'
129
+ assert any('gh CLI' in g for g in gap_report['gaps']), gap_report['gaps']
130
+ checks += 1
131
+
132
+ # 5. HUD rendering in Spanish and English
133
+ hud_es = mod.format_hud(report, lang='es')
134
+ for token in ('RECAP', 'Issues creados', 'Issues cerrados', 'PRs enviados', 'Aporte', 'Solucionado', 'Avance', 'Efectividad'):
135
+ assert token in hud_es, f'Missing {token!r} in HUD:\n{hud_es}'
136
+ hud_en = mod.format_hud(gap_report, lang='en')
137
+ assert 'GAP' in hud_en and 'N/A' in hud_en, hud_en
138
+ checks += 1
139
+
140
+ # 6. Real temporary Git repo integration (--no-github --json)
141
+ with tempfile.TemporaryDirectory() as tmp:
142
+ repo = Path(tmp)
143
+ subprocess.run(['git', 'init'], cwd=repo, check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
144
+ subprocess.run(['git', 'config', 'user.name', 'Alice Dev'], cwd=repo, check=True)
145
+ subprocess.run(['git', 'config', 'user.email', 'alice@example.test'], cwd=repo, check=True)
146
+ (repo / 'a.txt').write_text('one\ntwo\n', encoding='utf-8')
147
+ subprocess.run(['git', 'add', 'a.txt'], cwd=repo, check=True)
148
+ subprocess.run(['git', 'commit', '-m', 'feat: first'], cwd=repo, check=True, stdout=subprocess.DEVNULL)
149
+ (repo / 'b.txt').write_text('three\n', encoding='utf-8')
150
+ subprocess.run(['git', 'add', 'b.txt'], cwd=repo, check=True)
151
+ subprocess.run(['git', 'commit', '-m', 'feat: second'], cwd=repo, check=True, stdout=subprocess.DEVNULL)
152
+ (repo / 'dirty.txt').write_text('wip\n', encoding='utf-8')
153
+
154
+ proc = subprocess.run(
155
+ [sys.executable, '-I', '-X', 'utf8', '-B', str(script_path.resolve()), '--cwd', str(repo), '--no-github', '--json'],
156
+ capture_output=True,
157
+ text=True,
158
+ check=False,
159
+ )
160
+ assert proc.returncode == 0, proc.stderr + proc.stdout
161
+ data = json.loads(proc.stdout)
162
+ assert data['contribution']['commits'] == 2, data
163
+ assert data['contribution']['files_changed'] == 2, data
164
+ assert data['contribution']['insertions'] == 3, data
165
+ assert data['progress']['working_changes'] == 1, data
166
+ assert data['issues_created']['count'] is None, data
167
+ assert '@' not in (data.get('user') or ''), data
168
+ checks += 1
169
+
170
+ # 7. Project board summary, sync planner (dry-run, colors, labels), and team HUD
171
+ project_meta = {
172
+ 'available': True,
173
+ 'project_id': 'PVT_1',
174
+ 'title': 'Platform Board',
175
+ 'url': 'https://github.com/orgs/example-org/projects/1/views/7',
176
+ 'view': 7,
177
+ 'view_name': 'Tablero',
178
+ 'target_view': {'id': 'PVTV_7', 'number': 7, 'name': 'Tablero', 'layout': 'BOARD_LAYOUT'},
179
+ 'fields': [
180
+ {'id': 'F_TITLE', 'name': 'Title', 'dataType': 'TITLE'},
181
+ {'id': 'F_ASSIGNEES', 'name': 'Assignees', 'dataType': 'ASSIGNEES'},
182
+ {'id': 'F_LABELS', 'name': 'Labels', 'dataType': 'LABELS'},
183
+ {'id': 'F_PRIO', 'name': 'Priority', 'dataType': 'SINGLE_SELECT', 'options': []},
184
+ {
185
+ 'id': 'F_STATUS',
186
+ 'name': 'Status',
187
+ 'dataType': 'SINGLE_SELECT',
188
+ 'options': [
189
+ {'id': 'opt_backlog', 'name': 'Backlog', 'color': 'GREEN', 'description': ''},
190
+ {'id': 'opt_ready', 'name': 'Ready', 'color': 'BLUE', 'description': ''},
191
+ {'id': 'opt_review', 'name': 'In review', 'color': 'PURPLE', 'description': ''},
192
+ {'id': 'opt_done', 'name': 'Done', 'color': 'ORANGE', 'description': ''},
193
+ ],
194
+ },
195
+ {
196
+ 'id': 'F_AREA',
197
+ 'name': 'Area',
198
+ 'dataType': 'SINGLE_SELECT',
199
+ 'options': [
200
+ {'id': 'opt_core', 'name': 'Core', 'color': 'GRAY', 'description': ''},
201
+ {'id': 'opt_ai', 'name': 'AI', 'color': 'GRAY', 'description': ''},
202
+ ],
203
+ },
204
+ ],
205
+ 'items': [
206
+ {
207
+ 'id': 'ITEM_102',
208
+ 'repo': 'example-org/example-app',
209
+ 'number': 102,
210
+ 'type': 'Issue',
211
+ 'title': 'Fix parser',
212
+ 'state': 'CLOSED',
213
+ 'merged': False,
214
+ 'url': 'https://github.com/example-org/example-app/issues/102',
215
+ 'status': 'In review',
216
+ 'assignees': ['dev-alice'],
217
+ },
218
+ {
219
+ 'id': 'ITEM_95',
220
+ 'repo': 'example-org/example-app',
221
+ 'number': 95,
222
+ 'type': 'Issue',
223
+ 'title': 'Older bug fixed',
224
+ 'state': 'CLOSED',
225
+ 'merged': False,
226
+ 'url': 'https://github.com/example-org/example-app/issues/95',
227
+ 'status': 'Done',
228
+ 'assignees': ['dev-bob'],
229
+ },
230
+ ],
231
+ }
232
+
233
+ board_payload = dict(payload)
234
+ board_payload['team'] = [
235
+ {'user': 'dev-alice', 'available': True, 'issues_created': 2, 'issues_closed': 3, 'prs_opened': 2, 'prs_merged': 2},
236
+ {'user': 'dev-bob', 'available': True, 'issues_created': 1, 'issues_closed': 1, 'prs_opened': 1, 'prs_merged': 1},
237
+ ]
238
+ board_payload['project'] = project_meta
239
+ board_report = mod.compute_recap(board_payload)
240
+ proj_rep = board_report['project']
241
+ assert proj_rep['total_items'] == 2
242
+ assert proj_rep['status_counts'] == {'In review': 1, 'Done': 1}, proj_rep['status_counts']
243
+ assert any(m['number'] == 101 for m in proj_rep['missing_from_board']), proj_rep['missing_from_board']
244
+ assert any(mm['number'] == 102 for mm in proj_rep['status_mismatches']), proj_rep['status_mismatches']
245
+
246
+ plan = mod.plan_board_sync(proj_rep, project_meta, fix_colors=True)
247
+ add_101 = next((a for a in plan['adds'] if a['number'] == 101), None)
248
+ assert add_101 and add_101['target_status'] == 'Ready', plan['adds']
249
+ add_202 = next((a for a in plan['adds'] if a['number'] == 202), None)
250
+ assert add_202 and add_202['target_status'] == 'In review', plan['adds']
251
+ assert len(plan['moves']) == 1 and plan['moves'][0]['target_status'] == 'Done', plan['moves']
252
+ assert len(plan['color_updates']) == 2, plan['color_updates']
253
+ status_cu = next(c for c in plan['color_updates'] if c['field_name'] == 'Status')
254
+ assert {o['name']: (o['id'], o['color']) for o in status_cu['options']}['Done'] == ('opt_done', 'GREEN')
255
+ assert plan['view_update'] and 'F_LABELS' in plan['view_update']['visible_field_ids'], plan['view_update']
256
+
257
+ assert mod.infer_repo_label('fix(api): handle timeout', ['bug', 'enhancement']) == 'bug'
258
+ assert mod.infer_repo_label('feat(ui): add board', ['bug', 'enhancement']) == 'enhancement'
259
+ assert mod.infer_repo_label('docs(readme): update', ['documentation']) == 'documentation'
260
+
261
+ dry_res = mod.apply_board_sync(plan, dry_run=True)
262
+ assert dry_res['dry_run'] is True and dry_res['planned_moves'] == 1
263
+ board_report['board_sync'] = dry_res
264
+
265
+ board_hud_es = mod.format_hud(board_report, lang='es')
266
+ assert 'Tablero ─ Platform Board · Tablero' in board_hud_es, board_hud_es
267
+ assert 'Equipo' in board_hud_es and '@dev-bob' in board_hud_es, board_hud_es
268
+ assert 'Plan tablero (dry-run)' in board_hud_es, board_hud_es
269
+ board_hud_en = mod.format_hud(board_report, lang='en')
270
+ assert 'Board ─ Platform Board · Tablero' in board_hud_en, board_hud_en
271
+ assert 'Board plan (dry-run)' in board_hud_en, board_hud_en
272
+ checks += 1
273
+
274
+ print(f'PASS {checks} checks')
275
+ PY
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@bbcsoftwarefactory/commands",
3
+ "version": "0.1.1",
4
+ "description": "Public BuilderBot slash commands (daily, recap, issue-clean-and-close), packaged for installation by the CLI.",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "engines": {
8
+ "node": ">=22.18.0"
9
+ },
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "scripts": {
14
+ "build": "node build.ts",
15
+ "prepack": "node build.ts",
16
+ "test": "node --test \"*.test.ts\""
17
+ },
18
+ "dependencies": {
19
+ "@bbcsoftwarefactory/cli-core": "^0.1.0"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/builberbot/bbc-skill-internals.git",
24
+ "directory": "packages/commands"
25
+ },
26
+ "publishConfig": {
27
+ "access": "public",
28
+ "provenance": true
29
+ },
30
+ "commands": [
31
+ "daily",
32
+ "issue-clean-and-close",
33
+ "recap"
34
+ ],
35
+ "entries": {
36
+ "commands/daily": [
37
+ "SKILL.md",
38
+ "adapters"
39
+ ],
40
+ "commands/issue-clean-and-close": [
41
+ "SKILL.md",
42
+ "adapters",
43
+ "references",
44
+ "scripts",
45
+ "tests"
46
+ ],
47
+ "commands/recap": [
48
+ "SKILL.md",
49
+ "adapters",
50
+ "scripts",
51
+ "tests"
52
+ ]
53
+ }
54
+ }
package/package.json CHANGED
@@ -1,6 +1,30 @@
1
- {
2
- "name": "@bbcsoftwarefactory/commands",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
1
+ {
2
+ "name": "@bbcsoftwarefactory/commands",
3
+ "version": "0.1.1",
4
+ "description": "Public BuilderBot slash commands (daily, recap, issue-clean-and-close), packaged for installation by the CLI.",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "engines": {
8
+ "node": ">=22.18.0"
9
+ },
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "scripts": {
14
+ "build": "node build.ts",
15
+ "prepack": "node build.ts",
16
+ "test": "node --test \"*.test.ts\""
17
+ },
18
+ "dependencies": {
19
+ "@bbcsoftwarefactory/cli-core": "^0.1.0"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/builberbot/bbc-skill-internals.git",
24
+ "directory": "packages/commands"
25
+ },
26
+ "publishConfig": {
27
+ "access": "public",
28
+ "provenance": true
29
+ }
30
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.