open-quality-cli 0.2.0__tar.gz → 0.3.0__tar.gz

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.
Files changed (46) hide show
  1. {open_quality_cli-0.2.0/open_quality_cli.egg-info → open_quality_cli-0.3.0}/PKG-INFO +5 -13
  2. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/README.md +4 -12
  3. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/cli/cli.py +147 -19
  4. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/cli/core.py +140 -54
  5. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/cli/model.py +7 -1
  6. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/cli/providers/github_projects/__init__.py +1 -0
  7. open_quality_cli-0.3.0/cli/providers/gitlab/__init__.py +246 -0
  8. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/cli/providers/jira_cloud/__init__.py +7 -3
  9. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/cli/providers/openproject/__init__.py +9 -4
  10. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/cli/renderer.py +2 -2
  11. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/cli/scaffold.py +68 -62
  12. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0/open_quality_cli.egg-info}/PKG-INFO +5 -13
  13. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/open_quality_cli.egg-info/SOURCES.txt +1 -1
  14. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/pyproject.toml +1 -1
  15. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/schema/v0.1/approval-policy.schema.json +1 -5
  16. open_quality_cli-0.2.0/schema/v0.1/artifact.schema.json → open_quality_cli-0.3.0/schema/v0.1/documentation.schema.json +4 -9
  17. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/schema/v0.1/metric.schema.json +1 -2
  18. open_quality_cli-0.3.0/schema/v0.1/quality-contract.schema.json +199 -0
  19. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/schema/v0.1/quality-measure-element.schema.json +1 -3
  20. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/schema/v0.1/quality.schema.json +1 -1
  21. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/schema/v0.1/requirement.schema.json +1 -2
  22. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/schema/v0.1/role.schema.json +1 -2
  23. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/schema/v0.1/stage.schema.json +2 -3
  24. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/schema/v0.1/workflow.schema.json +1 -2
  25. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/tests/test_cli.py +10 -16
  26. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/tests/test_core.py +26 -27
  27. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/tests/test_scaffold.py +4 -4
  28. open_quality_cli-0.2.0/cli/providers/gitlab/__init__.py +0 -136
  29. open_quality_cli-0.2.0/schema/v0.1/quality-contract.schema.json +0 -93
  30. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/LICENSE +0 -0
  31. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/NOTICE +0 -0
  32. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/cli/__init__.py +0 -0
  33. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/cli/providers/__init__.py +0 -0
  34. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/cli/providers/github/__init__.py +0 -0
  35. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/cli/providers/interfaces.py +0 -0
  36. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/open_quality_cli.egg-info/dependency_links.txt +0 -0
  37. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/open_quality_cli.egg-info/entry_points.txt +0 -0
  38. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/open_quality_cli.egg-info/requires.txt +0 -0
  39. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/open_quality_cli.egg-info/top_level.txt +0 -0
  40. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/schema/__init__.py +0 -0
  41. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/schema/v0.1/common.schema.json +0 -0
  42. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/setup.cfg +0 -0
  43. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/tests/test_github_projects_provider.py +0 -0
  44. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/tests/test_github_provider.py +0 -0
  45. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/tests/test_gitlab_provider.py +0 -0
  46. {open_quality_cli-0.2.0 → open_quality_cli-0.3.0}/tests/test_provider.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: open-quality-cli
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: Command-line interface for the Open Quality 0.1 specification
5
5
  License-Expression: GPL-3.0-only
6
6
  Project-URL: Homepage, https://github.com/duanribeiro/open-quality
@@ -74,7 +74,6 @@ site automatically.
74
74
  The example in [`examples/minimal`](examples/minimal/README.md) describes a small release process for a payment API. Each YAML document declares one resource using a common envelope:
75
75
 
76
76
  ```yaml
77
- specVersion: "0.1"
78
77
  kind: QualityRequirement
79
78
  metadata:
80
79
  id: api-availability
@@ -171,17 +170,10 @@ format follow the lightweight decision process in [GOVERNANCE.md](GOVERNANCE.md)
171
170
 
172
171
  ## Compatibility and releases
173
172
 
174
- Open Quality is currently at specification version `0.1.0` and is experimental.
175
- The CLI supports Python 3.10 and later. Versioned schemas live under
176
- [`schema/v0.1`](schema/v0.1); tools should select schemas by the contract's
177
- `specVersion` rather than assuming future compatibility.
178
-
179
- Until `1.0.0`, the project may make breaking changes. Each release will be
180
- tagged, documented in [`CHANGELOG.md`](CHANGELOG.md), and identify its schema
181
- compatibility and migration notes where needed. After `1.0.0`, releases will
182
- follow semantic versioning: patch releases are backward-compatible fixes,
183
- minor releases add backward-compatible functionality, and major releases may
184
- contain breaking changes.
173
+ Open Quality is currently experimental at version `0.1.0`. The CLI supports
174
+ Python 3.10 and later. Schemas ship with the CLI under [`schema/v0.1`](schema/v0.1);
175
+ resource documents do not include a separate version field. Breaking format
176
+ changes may require updating existing contracts.
185
177
 
186
178
  ## License
187
179
 
@@ -45,7 +45,6 @@ site automatically.
45
45
  The example in [`examples/minimal`](examples/minimal/README.md) describes a small release process for a payment API. Each YAML document declares one resource using a common envelope:
46
46
 
47
47
  ```yaml
48
- specVersion: "0.1"
49
48
  kind: QualityRequirement
50
49
  metadata:
51
50
  id: api-availability
@@ -142,17 +141,10 @@ format follow the lightweight decision process in [GOVERNANCE.md](GOVERNANCE.md)
142
141
 
143
142
  ## Compatibility and releases
144
143
 
145
- Open Quality is currently at specification version `0.1.0` and is experimental.
146
- The CLI supports Python 3.10 and later. Versioned schemas live under
147
- [`schema/v0.1`](schema/v0.1); tools should select schemas by the contract's
148
- `specVersion` rather than assuming future compatibility.
149
-
150
- Until `1.0.0`, the project may make breaking changes. Each release will be
151
- tagged, documented in [`CHANGELOG.md`](CHANGELOG.md), and identify its schema
152
- compatibility and migration notes where needed. After `1.0.0`, releases will
153
- follow semantic versioning: patch releases are backward-compatible fixes,
154
- minor releases add backward-compatible functionality, and major releases may
155
- contain breaking changes.
144
+ Open Quality is currently experimental at version `0.1.0`. The CLI supports
145
+ Python 3.10 and later. Schemas ship with the CLI under [`schema/v0.1`](schema/v0.1);
146
+ resource documents do not include a separate version field. Breaking format
147
+ changes may require updating existing contracts.
156
148
 
157
149
  ## License
158
150
 
@@ -8,11 +8,13 @@ or Jira Cloud, under `cli.providers`).
8
8
  from __future__ import annotations
9
9
 
10
10
  import argparse
11
+ from datetime import datetime, timezone
12
+ import math
11
13
  import sys
12
14
  from pathlib import Path
13
15
 
14
16
  from . import renderer
15
- from .core import evaluate, load_contract, load_state, validate
17
+ from .core import calculated_metrics, evaluate, load_contract, load_state, validate
16
18
  from .providers import github, github_projects, gitlab, jira_cloud
17
19
  from .providers.openproject import (
18
20
  ExternalResource,
@@ -70,20 +72,30 @@ def _select_provider_roles(
70
72
  target_document: dict, provider_role: str | None
71
73
  ) -> list[tuple[str, dict]]:
72
74
  """Resolve either the selected provider role or every configured role."""
73
- if "providers" not in target_document:
75
+ if target_document.get("kind") != "QualityContract":
74
76
  if provider_role:
75
- raise ValueError(
76
- "--provider-role is only valid for a project file with providers"
77
- )
77
+ raise ValueError("--provider-role is only valid for a QualityContract file")
78
78
  return [("", target_document)]
79
79
 
80
- providers = target_document["providers"]
81
- if not isinstance(providers, dict):
82
- raise ValueError("providers must be a mapping")
80
+ reserved = {
81
+ "kind",
82
+ "metadata",
83
+ "team",
84
+ "description",
85
+ "quality",
86
+ "docs",
87
+ "roles",
88
+ "approvalPolicies",
89
+ }
90
+ providers = {
91
+ role: value
92
+ for role, value in target_document.items()
93
+ if role not in reserved and isinstance(value, dict)
94
+ }
83
95
 
84
96
  roles = [provider_role] if provider_role else list(providers)
85
97
  if not roles:
86
- raise ValueError("providers must contain at least one provider role")
98
+ raise ValueError("QualityContract must contain at least one provider role")
87
99
 
88
100
  selected = []
89
101
  for role in roles:
@@ -150,6 +162,11 @@ def _print_plan_summary(operations) -> None:
150
162
  )
151
163
 
152
164
 
165
+ def _work_management_workflow_id(bundle, target_document: dict) -> str:
166
+ """Resolve the workflow override for a work-management provider target."""
167
+ return target_document.get("workflow") or bundle.workflow_id
168
+
169
+
153
170
  def _github_provider(
154
171
  target_document: dict,
155
172
  provider_role: str,
@@ -194,6 +211,35 @@ def _gitlab_provider(
194
211
  return 0
195
212
 
196
213
 
214
+ def _gitlab_work_management_provider(
215
+ target_document: dict,
216
+ provider_role: str,
217
+ values: argparse.Namespace,
218
+ is_apply: bool,
219
+ ) -> int:
220
+ """Plan or apply a GitLab Issue Board for a quality contract."""
221
+ config = gitlab.load_config(target_document, provider_role)
222
+ bundle = _valid(values.directory)
223
+ workflow_id = _work_management_workflow_id(bundle, target_document)
224
+ workflow = bundle.workflows[workflow_id]
225
+ stage_ids = list(workflow.spec["stages"])
226
+ _print_plan_header("gitlab-issue-board", config.name)
227
+ print(f" ENSURE GitLabGroup {config.group}")
228
+ if stage_ids:
229
+ print(
230
+ f" ENSURE IssueBoard {config.board_name} ({', '.join(stage_ids)})"
231
+ )
232
+ if is_apply:
233
+ lists_in_workflow_order = gitlab.apply_work_management(config, stage_ids)
234
+ print("\nApplied GitLab Issue Board changes.")
235
+ if not lists_in_workflow_order:
236
+ print(
237
+ "Warning: GitLab kept the existing list order; adjust the columns "
238
+ "in the Issue Board if they differ from the workflow."
239
+ )
240
+ return 0
241
+
242
+
197
243
  def _openproject_provider(
198
244
  target_document: dict,
199
245
  provider_role: str,
@@ -216,10 +262,11 @@ def _openproject_provider(
216
262
  client = provider.client
217
263
  if bundle.project and bundle.project.id not in state.resources:
218
264
  existing_project = client.find_project(bundle.project.id)
265
+ workflow_id = _work_management_workflow_id(bundle, target_document)
219
266
  operations = (
220
- provider.plan(bundle, state, members)
267
+ provider.plan(bundle, state, members, workflow_id)
221
268
  if provider
222
- else plan(bundle, state, config, members)
269
+ else plan(bundle, state, config, members, workflow_id)
223
270
  )
224
271
  if existing_project and bundle.project:
225
272
  project = next(
@@ -278,7 +325,8 @@ def _jira_provider(
278
325
  state_path = _state_path(values, provider_role)
279
326
  state = jira_cloud.load_state(state_path, config.name)
280
327
  bundle = _valid(values.directory)
281
- operations = jira_cloud.plan(bundle, state, config, members)
328
+ workflow_id = _work_management_workflow_id(bundle, target_document)
329
+ operations = jira_cloud.plan(bundle, state, config, members, workflow_id)
282
330
  _print_plan_header("jira-cloud", config.name)
283
331
  for operation in operations:
284
332
  _print_operation(operation)
@@ -309,7 +357,8 @@ def _github_projects_provider(
309
357
  state_path = _state_path(values, provider_role)
310
358
  state = github_projects.load_state(state_path, config.name)
311
359
  bundle = _valid(values.directory)
312
- workflow = bundle.workflows[bundle.project.spec["workflow"]]
360
+ workflow_id = _work_management_workflow_id(bundle, target_document)
361
+ workflow = bundle.workflows[workflow_id]
313
362
  stage_ids = list(workflow.spec["stages"])
314
363
  _print_plan_header("github-projects", config.name)
315
364
  print(f" ENSURE GitHubProject {config.owner}/{config.project}")
@@ -342,6 +391,14 @@ def _provider(args: list[str], is_apply: bool) -> int:
342
391
  provider_targets = _select_provider_roles(target_document, values.provider_role)
343
392
  values.provider_role_count = len(provider_targets)
344
393
  for provider_role, provider_target in provider_targets:
394
+ if (
395
+ provider_role == "workManagement"
396
+ and provider_target.get("provider") == "gitlab"
397
+ ):
398
+ _gitlab_work_management_provider(
399
+ provider_target, provider_role, values, is_apply
400
+ )
401
+ continue
345
402
  if provider_target.get("provider") == "github" and "project" in (
346
403
  provider_target.get("config") or {}
347
404
  ):
@@ -354,11 +411,77 @@ def _provider(args: list[str], is_apply: bool) -> int:
354
411
  return 0
355
412
 
356
413
 
414
+ def _record_measurements(directory: str) -> int:
415
+ """Prompt for each QualityMeasureElement and append any entered value."""
416
+ bundle = _valid(directory)
417
+ for element_id, element in bundle.quality_measure_elements.items():
418
+ unit = element.spec.get("unit", "")
419
+ answer = input(f"{element.name} [{unit}] (blank to skip): ").strip()
420
+ if not answer:
421
+ continue
422
+ try:
423
+ value = float(answer)
424
+ except ValueError as error:
425
+ raise ValueError(
426
+ f"{element_id}: enter a numeric value or leave blank"
427
+ ) from error
428
+ if not math.isfinite(value):
429
+ raise ValueError(f"{element_id}: measurement must be a finite number")
430
+ path = Path(bundle.files[element_id])
431
+ document = yaml.safe_load(path.read_text())
432
+ measurements = document["spec"].setdefault("measurements", [])
433
+ measurements.append(
434
+ {
435
+ "value": int(value) if value.is_integer() else value,
436
+ "measuredAt": (
437
+ datetime.now(timezone.utc)
438
+ .isoformat(timespec="seconds")
439
+ .replace("+00:00", "Z")
440
+ ),
441
+ }
442
+ )
443
+ path.write_text(yaml.safe_dump(document, sort_keys=False, allow_unicode=True))
444
+ print(f"Saved {element_id}: {value:g} {unit}".rstrip())
445
+ return 0
446
+
447
+
448
+ def _check_requirements(directory: str) -> int:
449
+ """Calculate quality measures and report each quality requirement result."""
450
+ bundle = _valid(directory)
451
+ metrics, calculation_errors = calculated_metrics(bundle)
452
+ state = {
453
+ "metrics": metrics,
454
+ "stages": {},
455
+ "approvals": {},
456
+ "documentation": {},
457
+ }
458
+ report = evaluate(bundle, state)
459
+ print(f"Quality requirement check: {bundle.project.name}\n")
460
+ print("Quality measures")
461
+ for measure_id, measure in bundle.metrics.items():
462
+ unit = measure.spec.get("unit", "")
463
+ if measure_id in metrics:
464
+ print(f" {measure.name}: {metrics[measure_id]:g} {unit}".rstrip())
465
+ else:
466
+ error = calculation_errors.get(measure_id, "measurement is unavailable")
467
+ print(f" ! {measure.name}: {error}")
468
+ print("\nRequirements")
469
+ for check in report.requirements:
470
+ icon = "PASS" if check.passed else "FAIL"
471
+ print(
472
+ f"{icon} {check.name}"
473
+ + (f" — {check.reason}" if check.reason else "")
474
+ )
475
+ passed = all(item.passed for item in report.requirements)
476
+ print("\nRequirements: " + ("PASS" if passed else "FAIL"))
477
+ return 0 if passed else 2
478
+
479
+
357
480
  def run(args: list[str]) -> int:
358
481
  """Execute one `oq` subcommand and return its process exit code."""
359
482
  if not args:
360
483
  raise ValueError(
361
- "usage: oq <init|add|validate|graph|evaluate|status|plan|apply> ..."
484
+ "usage: oq <init|add|measure|check|validate|graph|evaluate|status|plan|apply> ..."
362
485
  )
363
486
  command, rest = args[0], args[1:]
364
487
  if command == "init":
@@ -390,16 +513,21 @@ def run(args: list[str]) -> int:
390
513
  "team": add_team,
391
514
  }
392
515
  return adders[values.resource](values.quality_directory)
516
+ if command == "measure":
517
+ if len(rest) > 1:
518
+ raise ValueError("usage: oq measure [quality-directory]")
519
+ return _record_measurements(rest[0] if rest else ".quality")
520
+ if command == "check":
521
+ if len(rest) > 1:
522
+ raise ValueError("usage: oq check [quality-directory]")
523
+ return _check_requirements(rest[0] if rest else ".quality")
393
524
  if command in {"plan", "apply"}:
394
525
  return _provider(rest, command == "apply")
395
526
  if command == "validate":
396
527
  if len(rest) > 1:
397
528
  raise ValueError("usage: oq validate [quality-directory]")
398
529
  bundle = _valid(rest[0] if rest else ".quality")
399
- documentation_count = sum(
400
- item.spec.get("category") == "documentation"
401
- for item in bundle.artifacts.values()
402
- )
530
+ documentation_count = len(bundle.artifacts)
403
531
  print(
404
532
  f"PASS {bundle.project.name}\n\n1 QualityContract\n{len(bundle.workflows)} Workflow(s)\n{len(bundle.requirements)} Requirement(s)\n{len(bundle.stages)} Stage(s)\n{len(bundle.metrics)} QualityMeasure(s)\n{documentation_count} Documentation definition(s)\n{len(bundle.roles)} Role(s)\n{len(bundle.approval_policies)} Approval policy(s)"
405
533
  )
@@ -445,7 +573,7 @@ def run(args: list[str]) -> int:
445
573
  )
446
574
  return 0 if command == "status" or report.ready else 2
447
575
  raise ValueError(
448
- "usage: oq <init|add|validate|graph|evaluate|status|plan|apply> ..."
576
+ "usage: oq <init|add|measure|check|validate|graph|evaluate|status|plan|apply> ..."
449
577
  )
450
578
 
451
579