quality-graph-github 0.1.8__tar.gz → 0.1.9__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 (22) hide show
  1. {quality_graph_github-0.1.8 → quality_graph_github-0.1.9}/.gitignore +1 -0
  2. {quality_graph_github-0.1.8 → quality_graph_github-0.1.9}/PKG-INFO +4 -4
  3. {quality_graph_github-0.1.8 → quality_graph_github-0.1.9}/pyproject.toml +4 -4
  4. {quality_graph_github-0.1.8 → quality_graph_github-0.1.9}/src/qg_github/artifacts.py +8 -2
  5. {quality_graph_github-0.1.8 → quality_graph_github-0.1.9}/src/qg_github/commands.py +23 -2
  6. {quality_graph_github-0.1.8 → quality_graph_github-0.1.9}/src/qg_github/compiler.py +193 -22
  7. quality_graph_github-0.1.9/src/qg_github/presentation.py +17 -0
  8. {quality_graph_github-0.1.8 → quality_graph_github-0.1.9}/src/qg_github/publication.py +16 -6
  9. {quality_graph_github-0.1.8 → quality_graph_github-0.1.9}/src/qg_github/runtime.py +13 -2
  10. {quality_graph_github-0.1.8 → quality_graph_github-0.1.9}/README.md +0 -0
  11. {quality_graph_github-0.1.8 → quality_graph_github-0.1.9}/src/qg_github/__init__.py +0 -0
  12. {quality_graph_github-0.1.8 → quality_graph_github-0.1.9}/src/qg_github/annotations.py +0 -0
  13. {quality_graph_github-0.1.8 → quality_graph_github-0.1.9}/src/qg_github/approvals.py +0 -0
  14. {quality_graph_github-0.1.8 → quality_graph_github-0.1.9}/src/qg_github/comments.py +0 -0
  15. {quality_graph_github-0.1.8 → quality_graph_github-0.1.9}/src/qg_github/controls.py +0 -0
  16. {quality_graph_github-0.1.8 → quality_graph_github-0.1.9}/src/qg_github/dashboard.py +0 -0
  17. {quality_graph_github-0.1.8 → quality_graph_github-0.1.9}/src/qg_github/github.py +0 -0
  18. {quality_graph_github-0.1.8 → quality_graph_github-0.1.9}/src/qg_github/labels.py +0 -0
  19. {quality_graph_github-0.1.8 → quality_graph_github-0.1.9}/src/qg_github/provider.py +0 -0
  20. {quality_graph_github-0.1.8 → quality_graph_github-0.1.9}/src/qg_github/py.typed +0 -0
  21. {quality_graph_github-0.1.8 → quality_graph_github-0.1.9}/src/qg_github/reporting.py +0 -0
  22. {quality_graph_github-0.1.8 → quality_graph_github-0.1.9}/src/qg_github/required_checks.py +0 -0
@@ -1,4 +1,5 @@
1
1
  .venv/
2
+ .env
2
3
  __pycache__/
3
4
  *.py[cod]
4
5
  .pytest_cache/
@@ -1,15 +1,15 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: quality-graph-github
3
- Version: 0.1.8
3
+ Version: 0.1.9
4
4
  Summary: GitHub provider and Action runtime for Quality Graph
5
- Project-URL: Homepage, https://alchemmist.github.io/quality-graph/
6
- Project-URL: Documentation, https://alchemmist.github.io/quality-graph/
5
+ Project-URL: Homepage, https://quality-graph.xyz/
6
+ Project-URL: Documentation, https://quality-graph.xyz/
7
7
  License-Expression: MIT
8
8
  Requires-Python: >=3.12
9
9
  Requires-Dist: httpx>=0.28.1
10
10
  Requires-Dist: jinja2>=3.1.6
11
11
  Requires-Dist: pyyaml>=6.0.2
12
- Requires-Dist: quality-graph-core==0.1.8
12
+ Requires-Dist: quality-graph-core==0.1.9
13
13
  Description-Content-Type: text/markdown
14
14
 
15
15
  # Quality Graph GitHub Provider
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "quality-graph-github"
7
- version = "0.1.8"
7
+ version = "0.1.9"
8
8
  description = "GitHub provider and Action runtime for Quality Graph"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
@@ -13,12 +13,12 @@ dependencies = [
13
13
  "httpx>=0.28.1",
14
14
  "jinja2>=3.1.6",
15
15
  "pyyaml>=6.0.2",
16
- "quality-graph-core==0.1.8",
16
+ "quality-graph-core==0.1.9",
17
17
  ]
18
18
 
19
19
  [project.urls]
20
- Homepage = "https://alchemmist.github.io/quality-graph/"
21
- Documentation = "https://alchemmist.github.io/quality-graph/"
20
+ Homepage = "https://quality-graph.xyz/"
21
+ Documentation = "https://quality-graph.xyz/"
22
22
 
23
23
  [project.entry-points."qg.providers"]
24
24
  github = "qg_github:provider"
@@ -7,7 +7,7 @@ import io
7
7
  import re
8
8
  import stat
9
9
  import zipfile
10
- from dataclasses import dataclass
10
+ from dataclasses import dataclass, field
11
11
  from pathlib import PurePosixPath
12
12
  from typing import TYPE_CHECKING
13
13
 
@@ -15,7 +15,7 @@ from qg_github.github import GITHUB_PAGE_SIZE, GitHubPort
15
15
  from quality_graph_core.result import JsonValue, Result
16
16
 
17
17
  if TYPE_CHECKING:
18
- from collections.abc import Iterable
18
+ from collections.abc import Iterable, Mapping
19
19
 
20
20
  ARTIFACT_NAME_RE = re.compile(
21
21
  r"^quality-result-(?P<node>[a-z][a-z0-9-]{0,62})-"
@@ -40,6 +40,8 @@ class ArtifactExpectation:
40
40
  workflow_run_id: int
41
41
  graph_digest: str
42
42
  node_ids: frozenset[str]
43
+ flow_id: str | None = None
44
+ operation_ids: Mapping[str, str] = field(default_factory=dict)
43
45
 
44
46
 
45
47
  @dataclass(frozen=True)
@@ -174,6 +176,8 @@ def _validate_result(
174
176
  expectation.workflow_run_id,
175
177
  descriptor.attempt,
176
178
  expectation.graph_digest,
179
+ expectation.flow_id,
180
+ expectation.operation_ids.get(result.node_id),
177
181
  )
178
182
  observed = (
179
183
  provenance.repository,
@@ -182,6 +186,8 @@ def _validate_result(
182
186
  provenance.workflow_run_id,
183
187
  provenance.run_attempt,
184
188
  provenance.graph_digest,
189
+ provenance.flow_id,
190
+ provenance.operation_id,
185
191
  )
186
192
  if result.node_id != descriptor.node_id or observed != expected:
187
193
  message = f"artifact provenance does not match workflow metadata: {descriptor.id}"
@@ -10,9 +10,10 @@ from enum import StrEnum
10
10
 
11
11
  from qg_github.approvals import ApprovalRecord, append_approval_record
12
12
  from qg_github.artifacts import ArtifactExpectation, download_results
13
- from qg_github.compiler import compile_graph, project_graph
13
+ from qg_github.compiler import compile_graph
14
14
  from qg_github.controls import control_states, decode_control_marker
15
15
  from qg_github.github import GITHUB_PAGE_SIZE, GitHubPort
16
+ from qg_github.presentation import pr_presentation_graph
16
17
  from quality_graph_core.graph import Graph
17
18
  from quality_graph_core.policy import ApprovalTarget, effective_graph
18
19
  from quality_graph_core.result import ControlKind, JsonValue
@@ -178,6 +179,20 @@ def handle_command(port: GitHubPort, event_value: JsonValue) -> CommandOutcome:
178
179
  return CommandOutcome(handled=True, authorized=True, changed=True)
179
180
 
180
181
 
182
+ def dispatch_pr_command(port: GitHubPort, event_value: JsonValue) -> CommandOutcome:
183
+ """Dispatch comment events only when the trusted declaration enables PR presentation."""
184
+ request = command_request(event_value)
185
+ if request is None or request.pull_request is None:
186
+ return CommandOutcome(handled=False)
187
+ pull = _object(port.request("GET", f"/pulls/{request.pull_request}"), "pull request")
188
+ base = _object(pull.get("base"), "pull request base")
189
+ base_sha = _string(base.get("sha"), "pull request base SHA")
190
+ graph = Graph.from_yaml(_repository_file(port, "qg.yaml", base_sha))
191
+ if pr_presentation_graph(graph) is None:
192
+ return CommandOutcome(handled=False)
193
+ return handle_command(port, event_value)
194
+
195
+
181
196
  # pragma: no mutate start
182
197
  def _command_context(port: GitHubPort, number: int) -> CommandContext:
183
198
  pull = _object(port.request("GET", f"/pulls/{number}"), "pull request")
@@ -187,7 +202,11 @@ def _command_context(port: GitHubPort, number: int) -> CommandContext:
187
202
  base_sha = _string(base.get("sha"), "pull request base SHA")
188
203
  graph = Graph.from_yaml(_repository_file(port, "qg.yaml", base_sha))
189
204
  compiled = compile_graph(graph)
190
- graph = project_graph(graph, "pull-request")
205
+ projected = pr_presentation_graph(graph)
206
+ if projected is None:
207
+ message = "GitHub PR presentation is disabled"
208
+ raise ValueError(message)
209
+ graph = projected
191
210
  run = _latest_run(port, number)
192
211
  run_id = _integer(run.get("id"), "workflow run id")
193
212
  attempt = _integer(run.get("run_attempt", 1), "workflow run attempt")
@@ -198,6 +217,8 @@ def _command_context(port: GitHubPort, number: int) -> CommandContext:
198
217
  run_id,
199
218
  compiled.graph_digest,
200
219
  frozenset(node.id for node in graph.nodes),
220
+ graph.flow_id,
221
+ {node.id: node.operation_id for node in graph.nodes if node.operation_id is not None},
201
222
  )
202
223
  results = download_results(port, expectation)
203
224
  if any(result.provenance.run_attempt > attempt for result in results.values()):
@@ -11,7 +11,16 @@ from typing import TYPE_CHECKING, cast, override
11
11
 
12
12
  import yaml
13
13
 
14
- from quality_graph_core.graph import DependencyPolicy, Graph, LabelSpec, Node, Profile, Step
14
+ from quality_graph_core.graph import (
15
+ DependencyPolicy,
16
+ Flow,
17
+ FlowNode,
18
+ Graph,
19
+ LabelSpec,
20
+ Node,
21
+ Profile,
22
+ Step,
23
+ )
15
24
  from quality_graph_core.provider import GeneratedFile, GeneratedProject
16
25
 
17
26
  if TYPE_CHECKING:
@@ -105,24 +114,43 @@ def _validate_github_graph(graph: Graph) -> _GitHubConfiguration:
105
114
  if publisher_action.partition("@")[0] != action.partition("@")[0]:
106
115
  message = "GitHub publisher action must use the runtime action repository"
107
116
  raise ValueError(message)
117
+ _validate_execution_contracts(graph)
118
+ if graph.flows:
119
+ _validate_explicit_flows(graph)
120
+ _validate_merge_presentation(graph, merge_required=merge_required)
121
+ else:
122
+ _event_projections(graph)
123
+ return _GitHubConfiguration(
124
+ action,
125
+ publisher_action,
126
+ upload_artifact_action,
127
+ default_branch,
128
+ merge_required,
129
+ )
130
+
131
+
132
+ def _validate_execution_contracts(graph: Graph) -> None:
133
+ if graph.flow_id is not None:
134
+ message = "compile the original declaration, not a resolved flow"
135
+ raise ValueError(message)
108
136
  for profile in graph.profiles:
109
137
  _validate_permissions(profile)
110
138
  for step in profile.setup:
111
139
  _validate_step(step)
112
140
  for node in graph.nodes:
113
141
  _validate_step(node.step)
142
+ for operation in graph.operations:
143
+ _validate_step(operation.step)
114
144
  titles = [node.title for node in graph.nodes]
115
145
  if len(set(titles)) != len(titles):
116
146
  message = "GitHub dashboard requires unique node titles"
117
147
  raise ValueError(message)
118
- _event_projections(graph)
119
- return _GitHubConfiguration(
120
- action,
121
- publisher_action,
122
- upload_artifact_action,
123
- default_branch,
124
- merge_required,
125
- )
148
+
149
+
150
+ def _validate_merge_presentation(graph: Graph, *, merge_required: bool) -> None:
151
+ if merge_required and not any(flow.presentation == "github-pr" for flow in graph.flows):
152
+ message = "merge.required needs an enabled GitHub PR presentation adapter"
153
+ raise ValueError(message)
126
154
 
127
155
 
128
156
  def _merge_required(merge: JsonValue) -> bool:
@@ -140,6 +168,16 @@ def _merge_required(merge: JsonValue) -> bool:
140
168
 
141
169
 
142
170
  def _event_projections(graph: Graph) -> tuple[EventProjection, ...]:
171
+ if graph.flows:
172
+ return tuple(
173
+ EventProjection(
174
+ "push" if flow.trigger == "push" else "pull-request",
175
+ graph.for_flow(flow.id).nodes,
176
+ flow.dependencies,
177
+ )
178
+ for flow in graph.flows
179
+ if flow.trigger != "workflow-dispatch"
180
+ )
143
181
  supported = set(SUPPORTED_EVENTS)
144
182
  unknown = set(graph.execution) - supported
145
183
  for node in graph.nodes:
@@ -182,9 +220,31 @@ def event_projection(graph: Graph, event: str) -> EventProjection:
182
220
 
183
221
  def project_graph(graph: Graph, event: str) -> Graph:
184
222
  """Return one dependency-normalized GitHub event graph."""
223
+ if graph.flows:
224
+ for flow in graph.flows:
225
+ if flow.trigger == event:
226
+ return graph.for_flow(flow.id)
227
+ message = f"no flow declares the {event} trigger"
228
+ raise ValueError(message)
185
229
  return replace(graph, nodes=event_projection(graph, event).nodes)
186
230
 
187
231
 
232
+ def _validate_explicit_flows(graph: Graph) -> None:
233
+ for trigger in SUPPORTED_EVENTS:
234
+ selected = [flow for flow in graph.flows if flow.trigger == trigger]
235
+ if len(selected) > 1:
236
+ message = f"GitHub supports one {trigger} flow per declaration"
237
+ raise ValueError(message)
238
+ for flow in graph.flows:
239
+ for branch in flow.branches:
240
+ _default_branch(branch)
241
+ if flow.presentation == "github-pr":
242
+ titles = [node.title for node in graph.for_flow(flow.id).nodes]
243
+ if len(set(titles)) != len(titles):
244
+ message = "GitHub PR presentation requires unique placement titles"
245
+ raise ValueError(message)
246
+
247
+
188
248
  def _default_branch(value: JsonValue) -> str:
189
249
  branch = "main" if value is None else value
190
250
  if not isinstance(branch, str) or not 1 <= len(branch) <= MAX_BRANCH_NAME_LENGTH:
@@ -242,6 +302,8 @@ def _validate_step(step: Step) -> None:
242
302
  def compile_graph(graph: Graph) -> GeneratedProject:
243
303
  """Compile one graph through the public declaration seam."""
244
304
  configuration = _validate_github_graph(graph)
305
+ if graph.flows:
306
+ return _compile_flows(graph, configuration)
245
307
  projections = {item.event: item for item in _event_projections(graph)}
246
308
  manifest = _manifest_value(graph, configuration)
247
309
  digest = hashlib.sha256(_canonical_json(manifest).encode()).hexdigest()
@@ -279,6 +341,84 @@ def compile_graph(graph: Graph) -> GeneratedProject:
279
341
  return GeneratedProject(digest, files)
280
342
 
281
343
 
344
+ def _compile_flows(graph: Graph, configuration: _GitHubConfiguration) -> GeneratedProject:
345
+ manifest = _manifest_value(graph, configuration)
346
+ profiles = graph.expanded_profiles()
347
+ manifest.pop("nodes")
348
+ manifest["manifestVersion"] = 1
349
+ manifest["operations"] = {
350
+ operation.id: {
351
+ **_node_value(
352
+ operation.place(
353
+ FlowNode(operation.id, operation.id),
354
+ DependencyPolicy.GRAPH,
355
+ ),
356
+ profiles[operation.profile],
357
+ ),
358
+ "diffOnly": operation.diff_only,
359
+ }
360
+ for operation in graph.operations
361
+ }
362
+ manifest["flows"] = {flow.id: _flow_value(flow) for flow in graph.flows}
363
+ for contract in cast("dict[str, dict[str, JsonValue]]", manifest["operations"]).values():
364
+ contract.pop("needs")
365
+ digest = hashlib.sha256(_canonical_json(manifest).encode()).hexdigest()
366
+ manifest.update({"graphDigest": digest, "_generated": GENERATED_NOTICE})
367
+ files: list[GeneratedFile] = []
368
+ for flow in graph.flows:
369
+ if flow.trigger == "workflow-dispatch":
370
+ continue
371
+ projection = EventProjection(flow.trigger, graph.for_flow(flow.id).nodes, flow.dependencies)
372
+ workflow = _execution_workflow(graph, projection, configuration, digest, flow=flow)
373
+ if flow.concurrency is not None:
374
+ workflow["concurrency"] = {
375
+ "group": f"quality-graph-{flow.concurrency}",
376
+ "cancel-in-progress": False,
377
+ }
378
+ if flow.trigger == "push":
379
+ workflow["on"] = {"push": {"branches": list(flow.branches)}}
380
+ else:
381
+ workflow["on"] = {"pull_request": {"branches": [configuration.default_branch]}}
382
+ path = EXECUTION_WORKFLOW if flow.trigger == "pull-request" else PUSH_WORKFLOW
383
+ files.append(GeneratedFile(path, _yaml_file(workflow)))
384
+ if any(flow.presentation == "github-pr" for flow in graph.flows):
385
+ files.append(
386
+ GeneratedFile(
387
+ PUBLICATION_WORKFLOW,
388
+ _yaml_file(_publication_workflow(configuration.publisher_action)),
389
+ )
390
+ )
391
+ files.append(GeneratedFile(GRAPH_MANIFEST, _canonical_json(manifest)))
392
+ paths = {item.path for item in files}
393
+ retired = tuple(
394
+ path
395
+ for path in (EXECUTION_WORKFLOW, PUSH_WORKFLOW, PUBLICATION_WORKFLOW)
396
+ if path not in paths
397
+ )
398
+ return GeneratedProject(digest, tuple(files), retired)
399
+
400
+
401
+ def _flow_value(flow: Flow) -> dict[str, JsonValue]:
402
+ return {
403
+ "trigger": flow.trigger,
404
+ "branches": list(flow.branches),
405
+ "inputs": dict(flow.inputs),
406
+ "dependencies": flow.dependencies.value,
407
+ "presentation": flow.presentation,
408
+ "concurrency": flow.concurrency,
409
+ "execution": "design-only" if flow.trigger == "workflow-dispatch" else "github-actions",
410
+ "nodes": [
411
+ {
412
+ "id": node.id,
413
+ "operation": node.operation,
414
+ "needs": list(node.needs),
415
+ "checkpoint": dict(node.checkpoint),
416
+ }
417
+ for node in flow.nodes
418
+ ],
419
+ }
420
+
421
+
282
422
  def _manifest_value(
283
423
  graph: Graph,
284
424
  configuration: _GitHubConfiguration,
@@ -395,6 +535,8 @@ def _execution_workflow(
395
535
  projection: EventProjection,
396
536
  configuration: _GitHubConfiguration,
397
537
  digest: str,
538
+ *,
539
+ flow: Flow | None = None,
398
540
  ) -> dict[str, JsonValue]:
399
541
  profiles = graph.expanded_profiles()
400
542
  jobs: dict[str, JsonValue] = {
@@ -403,6 +545,7 @@ def _execution_workflow(
403
545
  profiles[node.profile],
404
546
  configuration,
405
547
  digest,
548
+ flow=flow,
406
549
  )
407
550
  for node in projection.nodes
408
551
  }
@@ -434,6 +577,8 @@ def _execution_job(
434
577
  profile: Profile,
435
578
  configuration: _GitHubConfiguration,
436
579
  graph_digest: str,
580
+ *,
581
+ flow: Flow | None = None,
437
582
  ) -> dict[str, JsonValue]:
438
583
  runner = cast("str", profile.runner)
439
584
  command = _workflow_step(node.step)
@@ -444,25 +589,13 @@ def _execution_job(
444
589
  "continue-on-error": True,
445
590
  }
446
591
  )
447
- report_path = node.result.path or ""
448
592
  result_path = f"${{{{ runner.temp }}}}/quality-graph/{node.id}.json"
449
593
  collect: dict[str, JsonValue] = {
450
594
  "name": f"Collect {node.title} result",
451
595
  "id": "quality-result",
452
596
  "if": "always()",
453
597
  "uses": configuration.runtime_action,
454
- "with": {
455
- "operation": "collect",
456
- "node-id": node.id,
457
- "title": node.title,
458
- "adapter": node.result.kind.value,
459
- "report-path": report_path,
460
- "command-outcome": "${{ steps.quality-command.outcome }}",
461
- "graph-digest": graph_digest,
462
- "approval-findings": str(node.policy.approvals.findings).lower(),
463
- "approval-files": str(node.policy.approvals.files).lower(),
464
- "approval-node": str(node.policy.approvals.node).lower(),
465
- },
598
+ "with": _collection_inputs(node, graph_digest, flow),
466
599
  }
467
600
  upload: dict[str, JsonValue] = {
468
601
  "name": f"Upload {node.title} result",
@@ -498,6 +631,16 @@ def _execution_job(
498
631
  value["needs"] = list(node.needs)
499
632
  environment = _json_string_mapping(profile.environment)
500
633
  environment.update(_json_string_mapping(node.environment))
634
+ if flow is not None:
635
+ environment.update(
636
+ {
637
+ "QG_FLOW_ID": flow.id,
638
+ "QG_OPERATION_ID": node.operation_id,
639
+ "QG_NODE_ID": node.id,
640
+ "QG_NODE_TITLE": node.title,
641
+ "QG_GRAPH_DIGEST": graph_digest,
642
+ }
643
+ )
501
644
  if environment:
502
645
  value["env"] = environment
503
646
  timeout = node.timeout_minutes or profile.timeout_minutes
@@ -508,6 +651,34 @@ def _execution_job(
508
651
  return value
509
652
 
510
653
 
654
+ def _collection_inputs(node: Node, graph_digest: str, flow: Flow | None) -> dict[str, JsonValue]:
655
+ inputs: dict[str, JsonValue] = {
656
+ "operation": "collect",
657
+ "node-id": node.id,
658
+ "title": node.title,
659
+ "adapter": node.result.kind.value,
660
+ "report-path": node.result.path or "",
661
+ "command-outcome": "${{ steps.quality-command.outcome }}",
662
+ "graph-digest": graph_digest,
663
+ "approval-findings": str(node.policy.approvals.findings).lower(),
664
+ "approval-files": str(node.policy.approvals.files).lower(),
665
+ "approval-node": str(node.policy.approvals.node).lower(),
666
+ }
667
+ if flow is not None:
668
+ inputs.update(
669
+ {
670
+ "flow-id": flow.id,
671
+ "operation-id": node.operation_id,
672
+ "presentation": flow.presentation,
673
+ }
674
+ )
675
+ if flow.presentation != "github-pr":
676
+ inputs.update(
677
+ {"approval-findings": "false", "approval-files": "false", "approval-node": "false"}
678
+ )
679
+ return inputs
680
+
681
+
511
682
  def _workflow_step(step: Step) -> dict[str, JsonValue]:
512
683
  return _step_value(step)
513
684
 
@@ -0,0 +1,17 @@
1
+ """Select the GitHub PR presentation adapter from trusted flow configuration."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import TYPE_CHECKING
6
+
7
+ from qg_github.compiler import project_graph
8
+
9
+ if TYPE_CHECKING:
10
+ from quality_graph_core.graph import Graph
11
+
12
+
13
+ def pr_presentation_graph(graph: Graph) -> Graph | None:
14
+ """Return PR adapter input, or disable every PR write for this declaration."""
15
+ if graph.flows and not any(flow.presentation == "github-pr" for flow in graph.flows):
16
+ return None
17
+ return project_graph(graph, "pull-request")
@@ -12,7 +12,7 @@ from typing import TYPE_CHECKING, cast
12
12
  from qg_github.approvals import approval_ledger
13
13
  from qg_github.artifacts import ArtifactError, ArtifactExpectation, download_results
14
14
  from qg_github.comments import find_managed_comment, upsert_managed_comment
15
- from qg_github.compiler import compile_graph, project_graph
15
+ from qg_github.compiler import compile_graph
16
16
  from qg_github.dashboard import (
17
17
  DASHBOARD_MARKER,
18
18
  DashboardModel,
@@ -25,6 +25,7 @@ from qg_github.dashboard import (
25
25
  )
26
26
  from qg_github.github import GITHUB_PAGE_SIZE, GitHubPort
27
27
  from qg_github.labels import parse_label_state, reconcile_labels
28
+ from qg_github.presentation import pr_presentation_graph
28
29
  from quality_graph_core.graph import Graph
29
30
  from quality_graph_core.policy import effective_graph
30
31
  from quality_graph_core.result import JsonValue, ResultStatus
@@ -122,7 +123,10 @@ def _publish_completed_workflow_run(
122
123
  graph: Graph,
123
124
  ) -> PublicationOutcome:
124
125
  compiled = compile_graph(graph)
125
- graph = project_graph(graph, "pull-request")
126
+ projected = pr_presentation_graph(graph)
127
+ if projected is None:
128
+ return PublicationOutcome(published=False)
129
+ graph = projected
126
130
  run = DashboardRun(event.id, event.attempt, pull.head_sha, event.url)
127
131
  model, effective_results = _completed_dashboard(
128
132
  port,
@@ -168,7 +172,9 @@ def watch_workflow_run(
168
172
  if not _is_latest_run(port, event, number):
169
173
  return PublicationOutcome(published=False)
170
174
  graph = Graph.from_yaml(_repository_file(port, "qg.yaml", pull.base_sha))
171
- projected = project_graph(graph, "pull-request")
175
+ projected = pr_presentation_graph(graph)
176
+ if projected is None:
177
+ return PublicationOutcome(published=False)
172
178
  nodes = tuple(DashboardNode(node.id, node.title) for node in projected.nodes)
173
179
  run = DashboardRun(event.id, event.attempt, pull.head_sha, event.url)
174
180
  _publish_check(port, pending_dashboard(projected, run))
@@ -178,9 +184,11 @@ def watch_workflow_run(
178
184
 
179
185
  while not publish_workflow_jobs(port, number, nodes, run, is_current=is_current):
180
186
  sleep(poll_interval)
181
- if not is_current():
182
- return PublicationOutcome(published=False)
183
- return _publish_completed_workflow_run(port, event, number, pull, graph)
187
+ return (
188
+ _publish_completed_workflow_run(port, event, number, pull, graph)
189
+ if is_current()
190
+ else PublicationOutcome(published=False)
191
+ )
184
192
 
185
193
 
186
194
  def publish_workflow_jobs(
@@ -282,6 +290,8 @@ def _completed_dashboard(
282
290
  run.id,
283
291
  graph_digest,
284
292
  frozenset(node.id for node in graph.nodes),
293
+ graph.flow_id,
294
+ {node.id: node.operation_id for node in graph.nodes if node.operation_id is not None},
285
295
  )
286
296
  try:
287
297
  results = download_results(port, expectation)
@@ -10,7 +10,7 @@ from pathlib import Path
10
10
  from typing import TYPE_CHECKING, cast
11
11
 
12
12
  from qg_github.annotations import escape_data, publish_annotations
13
- from qg_github.commands import handle_command
13
+ from qg_github.commands import dispatch_pr_command as handle_command
14
14
  from qg_github.github import HttpGitHubPort
15
15
  from qg_github.publication import (
16
16
  publish_workflow_run,
@@ -48,6 +48,7 @@ class CollectionRequest:
48
48
  summary_path: Path | None
49
49
  output_path: Path
50
50
  approval_policy: ApprovalPolicy
51
+ presentation: str = "github-pr"
51
52
 
52
53
  @classmethod
53
54
  def from_environment(
@@ -65,6 +66,10 @@ class CollectionRequest:
65
66
  )
66
67
  summary = environment.get("GITHUB_STEP_SUMMARY")
67
68
  provenance = _provenance(environment, event)
69
+ presentation = environment.get("QG_PRESENTATION") or "github-pr"
70
+ if presentation not in {"github-pr", "none", "release"}:
71
+ message = f"unsupported collection presentation: {presentation}"
72
+ raise ValueError(message)
68
73
  context = AdapterContext(
69
74
  node_id,
70
75
  _required(environment, "QG_TITLE"),
@@ -84,6 +89,7 @@ class CollectionRequest:
84
89
  _boolean(environment, "QG_APPROVAL_FILES"),
85
90
  _boolean(environment, "QG_APPROVAL_NODE"),
86
91
  ),
92
+ presentation,
87
93
  )
88
94
 
89
95
 
@@ -116,6 +122,8 @@ def collect(request: CollectionRequest) -> Result:
116
122
 
117
123
 
118
124
  def _with_policy_controls(request: CollectionRequest, result: Result) -> Result:
125
+ if request.presentation != "github-pr":
126
+ return replace(result, controls=())
119
127
  controls = policy_controls(result.node_id, result.findings, request.approval_policy)
120
128
  return replace(result, controls=controls)
121
129
 
@@ -133,7 +141,8 @@ def publish_collection(request: CollectionRequest, result: Result) -> int:
133
141
  request.result_path.write_text(result.to_json())
134
142
  if request.summary_path is not None:
135
143
  append_job_summary(request.summary_path, result)
136
- publish_annotations(result.annotations)
144
+ if request.presentation == "github-pr":
145
+ publish_annotations(result.annotations)
137
146
  exit_code = _result_exit_code(result)
138
147
  request.output_path.parent.mkdir(parents=True, exist_ok=True)
139
148
  with request.output_path.open("a") as output:
@@ -198,6 +207,8 @@ def _provenance(
198
207
  int(_required(environment, "GITHUB_RUN_ATTEMPT")),
199
208
  _required(environment, "QG_GRAPH_DIGEST"),
200
209
  pull_number,
210
+ environment.get("QG_FLOW_ID") or None,
211
+ environment.get("QG_OPERATION_ID") or None,
201
212
  )
202
213
 
203
214