quality-graph-cli 0.1.7__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.
@@ -1,4 +1,5 @@
1
1
  .venv/
2
+ .env
2
3
  __pycache__/
3
4
  *.py[cod]
4
5
  .pytest_cache/
@@ -1,12 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: quality-graph-cli
3
- Version: 0.1.7
3
+ Version: 0.1.9
4
4
  Summary: Provider-driven Quality Graph command-line application
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
- Requires-Dist: quality-graph-core==0.1.7
9
+ Requires-Dist: quality-graph-core==0.1.9
10
10
  Description-Content-Type: text/markdown
11
11
 
12
12
  # qg
@@ -15,7 +15,7 @@ Provider-driven command-line application for Quality Graph projects.
15
15
 
16
16
  The CLI discovers providers through the `qg.providers` entry-point group. Install it together
17
17
  with the GitHub provider using
18
- `uv tool install quality-graph-cli==0.1.2 --with quality-graph-github==0.1.2`.
18
+ `uv tool install quality-graph-cli==0.1.8 --with quality-graph-github==0.1.8`.
19
19
 
20
20
  Initialize a repository with its default branch, generate the provider-owned files, and list
21
21
  those paths for repository tooling:
@@ -4,7 +4,7 @@ Provider-driven command-line application for Quality Graph projects.
4
4
 
5
5
  The CLI discovers providers through the `qg.providers` entry-point group. Install it together
6
6
  with the GitHub provider using
7
- `uv tool install quality-graph-cli==0.1.2 --with quality-graph-github==0.1.2`.
7
+ `uv tool install quality-graph-cli==0.1.8 --with quality-graph-github==0.1.8`.
8
8
 
9
9
  Initialize a repository with its default branch, generate the provider-owned files, and list
10
10
  those paths for repository tooling:
@@ -4,16 +4,16 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "quality-graph-cli"
7
- version = "0.1.7"
7
+ version = "0.1.9"
8
8
  description = "Provider-driven Quality Graph command-line application"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
11
11
  license = "MIT"
12
- dependencies = ["quality-graph-core==0.1.7"]
12
+ dependencies = ["quality-graph-core==0.1.9"]
13
13
 
14
14
  [project.urls]
15
- Homepage = "https://alchemmist.github.io/quality-graph/"
16
- Documentation = "https://alchemmist.github.io/quality-graph/"
15
+ Homepage = "https://quality-graph.xyz/"
16
+ Documentation = "https://quality-graph.xyz/"
17
17
 
18
18
  [project.scripts]
19
19
  qg = "qg_cli.cli:main"
@@ -4,6 +4,7 @@ from __future__ import annotations
4
4
 
5
5
  import argparse
6
6
  import sys
7
+ from importlib import import_module
7
8
  from pathlib import Path
8
9
  from typing import TYPE_CHECKING
9
10
 
@@ -35,6 +36,16 @@ def parser() -> argparse.ArgumentParser:
35
36
  "generated-files", help="List compiler-owned artifact paths"
36
37
  )
37
38
  generated_files.add_argument("--root", default=".")
39
+ github = commands.add_parser("github", help="Synchronize GitHub repository settings")
40
+ github_commands = github.add_subparsers(dest="github_command")
41
+ required_checks = github_commands.add_parser(
42
+ "required-checks", help="Manage required status checks"
43
+ )
44
+ required_checks_commands = required_checks.add_subparsers(dest="required_checks_command")
45
+ synchronize = required_checks_commands.add_parser(
46
+ "sync", help="Synchronize required checks from qg.yaml"
47
+ )
48
+ synchronize.add_argument("--root", default=".")
38
49
  graph_schema = commands.add_parser("schema", help="Render the graph JSON Schema")
39
50
  graph_schema.add_argument("--output", default="-")
40
51
  result_command = commands.add_parser("result", help="Work with native result JSON")
@@ -52,6 +63,8 @@ def parser() -> argparse.ArgumentParser:
52
63
  emit.add_argument("--metric", action="append", default=[])
53
64
  emit.add_argument("--repository", required=True)
54
65
  emit.add_argument("--pull-request", type=int)
66
+ emit.add_argument("--flow-id")
67
+ emit.add_argument("--operation-id")
55
68
  emit.add_argument("--head-sha", required=True)
56
69
  emit.add_argument("--workflow-run-id", type=int, required=True)
57
70
  emit.add_argument("--run-attempt", type=int, required=True)
@@ -69,12 +82,31 @@ def main(arguments: Sequence[str] | None = None) -> int:
69
82
  return _project_command(args)
70
83
  if args.command == "result":
71
84
  return _result_command(command_parser, args)
72
- except (OSError, TypeError, ValueError) as error:
85
+ if args.command == "github":
86
+ return _github_command(command_parser, args)
87
+ except (ModuleNotFoundError, OSError, RuntimeError, TypeError, ValueError) as error:
73
88
  command_parser.error(str(error))
74
89
  command_parser.print_help()
75
90
  return 0
76
91
 
77
92
 
93
+ def _github_command(command_parser: argparse.ArgumentParser, args: argparse.Namespace) -> int:
94
+ if args.github_command != "required-checks" or args.required_checks_command != "sync":
95
+ command_parser.print_help()
96
+ return 0
97
+ project = Project.open(Path(args.root))
98
+ github = import_module("qg_github.github")
99
+ synchronization = import_module("qg_github.required_checks")
100
+ port = github.HttpGitHubPort.from_environment()
101
+ plan = synchronization.plan_required_checks(port, project.graph)
102
+ sys.stdout.write(plan.render())
103
+ sys.stdout.flush()
104
+ synchronization.apply_required_checks(port, plan)
105
+ result = "Applied required-check synchronization.\n" if plan.changed else "No changes.\n"
106
+ sys.stdout.write(result)
107
+ return 0
108
+
109
+
78
110
  def _project_command(args: argparse.Namespace) -> int:
79
111
  if args.command == "init":
80
112
  Project.initialize(
@@ -130,6 +162,8 @@ def _emitted_result(args: argparse.Namespace) -> Result:
130
162
  args.run_attempt,
131
163
  args.graph_digest,
132
164
  args.pull_request,
165
+ args.flow_id,
166
+ args.operation_id,
133
167
  ),
134
168
  failure,
135
169
  args.summary,
@@ -13,7 +13,8 @@ from quality_graph_core.graph import Graph
13
13
  if TYPE_CHECKING:
14
14
  from quality_graph_core.provider import GeneratedProject, Provider
15
15
 
16
- CONFIGURATION_PATH = Path("quality-graph.yml")
16
+ CONFIGURATION_PATH = Path("qg.yaml")
17
+ LEGACY_CONFIGURATION_PATH = Path("quality-graph.yml")
17
18
  PRETTIER_IGNORE_PATH = Path(".prettierignore")
18
19
  PRETTIER_BLOCK_START = "# Quality Graph generated files (managed by qg)"
19
20
  PRETTIER_BLOCK_END = "# End Quality Graph generated files"
@@ -42,7 +43,7 @@ class Project:
42
43
  @classmethod
43
44
  def open(cls, root: Path) -> Self:
44
45
  """Load a project from its committed declaration."""
45
- configuration = root / CONFIGURATION_PATH
46
+ configuration = _configuration_path(root)
46
47
  if not configuration.is_file():
47
48
  message = f"Quality Graph declaration does not exist: {configuration}"
48
49
  raise FileNotFoundError(message)
@@ -57,6 +58,19 @@ class Project:
57
58
  """Write every deterministic generated file."""
58
59
  generated = self.render()
59
60
  prettier_ignore = self._prettier_ignore(generated)
61
+ retired = self._retired_paths(generated)
62
+ for path in retired:
63
+ if (path.exists() or path.is_symlink()) and (
64
+ path.is_symlink()
65
+ or not path.read_text().startswith(
66
+ "# Generated by Quality Graph. DO NOT EDIT MANUALLY."
67
+ )
68
+ ):
69
+ message = f"Refusing to remove an unmanaged retired workflow: {path}"
70
+ raise ValueError(message)
71
+ for path in retired:
72
+ if path.exists():
73
+ path.unlink()
60
74
  for item in generated.files:
61
75
  path = self.root / item.path
62
76
  path.parent.mkdir(parents=True, exist_ok=True)
@@ -66,6 +80,15 @@ class Project:
66
80
  ignore_path.write_text(prettier_ignore)
67
81
  return generated
68
82
 
83
+ def _retired_paths(self, generated: GeneratedProject) -> tuple[Path, ...]:
84
+ root = self.root.resolve()
85
+ paths = tuple(self.root / path for path in generated.retired_files)
86
+ for path in paths:
87
+ if root not in path.resolve().parents:
88
+ message = f"Retired workflow is outside the project root: {path}"
89
+ raise ValueError(message)
90
+ return paths
91
+
69
92
  def generated_files(self) -> tuple[PurePosixPath, ...]:
70
93
  """Return stable repository-relative compiler-owned paths."""
71
94
  return tuple(item.path for item in self.render().files)
@@ -73,7 +96,13 @@ class Project:
73
96
  def validate(self) -> ValidationReport:
74
97
  """Compare generated output without mutating files."""
75
98
  problems: list[str] = []
76
- for item in self.render().files:
99
+ generated = self.render()
100
+ problems.extend(
101
+ f"retired generated file: {path.relative_to(self.root)}"
102
+ for path in self._retired_paths(generated)
103
+ if path.exists() or path.is_symlink()
104
+ )
105
+ for item in generated.files:
77
106
  path = self.root / item.path
78
107
  if not path.is_file():
79
108
  problems.append(f"missing generated file: {item.path}")
@@ -123,7 +152,7 @@ class Project:
123
152
  force: bool = False,
124
153
  ) -> Self:
125
154
  """Create one understandable starter declaration."""
126
- configuration = root / CONFIGURATION_PATH
155
+ configuration = _configuration_path(root)
127
156
  if configuration.exists() and not force:
128
157
  message = f"Refusing to replace existing declaration: {configuration}"
129
158
  raise FileExistsError(message)
@@ -136,6 +165,24 @@ class Project:
136
165
  return cls(root, graph, provider)
137
166
 
138
167
 
168
+ def _configuration_path(root: Path) -> Path:
169
+ configuration = root / CONFIGURATION_PATH
170
+ legacy = root / LEGACY_CONFIGURATION_PATH
171
+ if legacy.exists() or legacy.is_symlink():
172
+ if configuration.exists():
173
+ message = (
174
+ f"Both {CONFIGURATION_PATH} and {LEGACY_CONFIGURATION_PATH} exist; "
175
+ f"remove {LEGACY_CONFIGURATION_PATH}"
176
+ )
177
+ raise FileExistsError(message)
178
+ message = (
179
+ f"{LEGACY_CONFIGURATION_PATH} is no longer supported; "
180
+ f"rename it with `git mv {LEGACY_CONFIGURATION_PATH} {CONFIGURATION_PATH}`"
181
+ )
182
+ raise FileNotFoundError(message)
183
+ return configuration
184
+
185
+
139
186
  def _starter_configuration(
140
187
  runtime_action: str,
141
188
  default_branch: str,