kcreate-scaffolding-gcp-script 0.0.0-stage → 0.2.0

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,196 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """CLI de github-proyect-tracking; un JSON por comando, stdlib únicamente."""
4
+
5
+ from __future__ import annotations
6
+
7
+ import argparse
8
+ import shutil
9
+ import sys
10
+
11
+ from tracking_core import github as _github
12
+ from tracking_core.common import * # noqa: F401,F403
13
+ from tracking_core.events import * # noqa: F401,F403
14
+ from tracking_core.state import * # noqa: F401,F403
15
+ from tracking_core.commands import * # noqa: F401,F403
16
+
17
+ _raw_api = _github._raw_api
18
+
19
+
20
+ def _sync_runtime():
21
+ _github._raw_api = _raw_api
22
+ _github.shutil = shutil
23
+ _github.MAX_COMMENT_PAGES = MAX_COMMENT_PAGES
24
+ StateLock.STALE_SECONDS = LOCK_STALE_SECONDS
25
+ StateLock.WAIT_SECONDS = LOCK_WAIT_SECONDS
26
+
27
+
28
+ def api(method, path, token, body=None, retries=3):
29
+ _sync_runtime()
30
+ return _github.api(method, path, token, body, retries)
31
+
32
+
33
+ def check_issues_write(owner, repo, token):
34
+ _sync_runtime()
35
+ return _github.check_issues_write(owner, repo, token)
36
+
37
+
38
+ def resolve_token(cli_token=None, state=None):
39
+ _sync_runtime()
40
+ return _github.resolve_token(cli_token, state)
41
+
42
+
43
+ def post_comment(owner, repo, number, body, token,
44
+ baseline_ids=None, execution_id=None, sequence=None):
45
+ _sync_runtime()
46
+ return _github.post_comment(owner, repo, number, body, token,
47
+ baseline_ids, execution_id, sequence)
48
+
49
+
50
+ def fetch_issue(owner, repo, number, token):
51
+ _sync_runtime()
52
+ return _github.fetch_issue(owner, repo, number, token)
53
+
54
+
55
+ def fetch_all_comments(owner, repo, number, token):
56
+ _sync_runtime()
57
+ return _github.fetch_all_comments(owner, repo, number, token)
58
+
59
+
60
+ def close_issue(owner, repo, number, token):
61
+ _sync_runtime()
62
+ return _github.close_issue(owner, repo, number, token)
63
+
64
+
65
+ def find_issue_by_title(owner, repo, title, token):
66
+ _sync_runtime()
67
+ return _github.find_issue_by_title(owner, repo, title, token)
68
+
69
+
70
+ class JsonArgumentParser(argparse.ArgumentParser):
71
+ def error(self, message):
72
+ raise SkillError(EXIT_VALIDATION, "VALIDATION_ERROR",
73
+ f"argumentos inválidos: {message}")
74
+
75
+
76
+ def build_parser():
77
+ parser = JsonArgumentParser(
78
+ prog="tracking.py",
79
+ description="github-proyect-tracking: persiste y reanuda el estado de un "
80
+ "proceso en GitHub Issues. Cada comando imprime un único JSON.")
81
+ parser.add_argument("--version", action="version", version=USER_AGENT)
82
+ subparsers = parser.add_subparsers(dest="command", required=True)
83
+
84
+ def common(subparser, with_url=True, url_required=False):
85
+ if with_url:
86
+ subparser.add_argument(
87
+ "--url", required=url_required, metavar="URL",
88
+ help="github_project_url (https://github.com/{owner}/{repo}); "
89
+ "obligatorio si hay varios procesos activos")
90
+ subparser.add_argument("--token", default=None, metavar="T",
91
+ help="GitHub PAT con issues:write (si se omite: "
92
+ "env/gh/estado)")
93
+
94
+ subparser = subparsers.add_parser(
95
+ "init", help="nueva ejecución: valida, crea el Issue y guarda memoria")
96
+ common(subparser, url_required=True)
97
+ subparser.add_argument("--plan", default=None, metavar="JSON",
98
+ help='plan de pasos con nombres ÚNICOS, ej. \'["Paso 1","Paso 2"]\'')
99
+ subparser.add_argument("--plan-file", default=None, metavar="F",
100
+ help="archivo JSON con la lista de pasos")
101
+ subparser.add_argument("--prompt-token", action="store_true",
102
+ help="pedir el token interactivamente (TTY)")
103
+ subparser.add_argument("--store-token", action="store_true",
104
+ help="persistir el token provisto (opt-in; por defecto NO se guarda)")
105
+ subparser.add_argument("--no-store-token", action="store_true",
106
+ help="obsoleto (compatibilidad): ahora NO guardar es el default")
107
+ subparser.set_defaults(func=cmd_init)
108
+
109
+ subparser = subparsers.add_parser(
110
+ "resume", help="lee el último comentario del Issue y planea la reanudación")
111
+ common(subparser)
112
+ subparser.set_defaults(func=cmd_resume)
113
+
114
+ subparser = subparsers.add_parser(
115
+ "step-start", help="comenta [STATUS: INICIANDO] - Paso: N")
116
+ common(subparser)
117
+ subparser.add_argument("--name", required=True, metavar="N", help="nombre del paso")
118
+ subparser.set_defaults(func=cmd_step_start)
119
+
120
+ subparser = subparsers.add_parser(
121
+ "step-done", help="comenta [STATUS: COMPLETADO] - Paso: N")
122
+ common(subparser)
123
+ subparser.add_argument("--name", required=True, metavar="N", help="nombre del paso")
124
+ subparser.set_defaults(func=cmd_step_done)
125
+
126
+ subparser = subparsers.add_parser(
127
+ "step-error", help="comenta [STATUS: ERROR] y detiene el proceso")
128
+ common(subparser)
129
+ subparser.add_argument("--name", required=True, metavar="N", help="nombre del paso")
130
+ subparser.add_argument("--details", default=None, metavar="D",
131
+ help="mensaje de error o stacktrace (se sanitiza antes de publicar)")
132
+ subparser.add_argument("--details-file", default=None, metavar="F",
133
+ help="archivo con el error/stacktrace")
134
+ subparser.set_defaults(func=cmd_step_error)
135
+
136
+ subparser = subparsers.add_parser(
137
+ "finalize", help="cierra el Issue con resultado FINALIZADO o CANCELADO")
138
+ common(subparser)
139
+ subparser.add_argument("--force", action="store_true",
140
+ help="cancelar aunque queden pasos pendientes o no haya trabajo "
141
+ "(no aplica si el Issue fue cerrado externamente)")
142
+ subparser.set_defaults(func=cmd_finalize)
143
+
144
+ subparser = subparsers.add_parser(
145
+ "status", help="muestra el estado local (y remoto con --remote)")
146
+ common(subparser)
147
+ subparser.add_argument("--remote", action="store_true",
148
+ help="consultar también el Issue en GitHub")
149
+ subparser.set_defaults(func=cmd_status)
150
+
151
+ subparser = subparsers.add_parser(
152
+ "adopt", help="recupera el estado local desde un Issue remoto")
153
+ common(subparser, url_required=True)
154
+ subparser.add_argument("--execution-id", required=True, metavar="ID",
155
+ help="Execution ID EXACTO del título del Issue")
156
+ subparser.add_argument("--force", action="store_true",
157
+ help="reemplazar un proceso activo existente (conserva token "
158
+ "e historial)")
159
+ subparser.set_defaults(func=cmd_adopt)
160
+
161
+ subparser = subparsers.add_parser(
162
+ "clear", help="limpia la memoria interna (soft por defecto)")
163
+ common(subparser)
164
+ subparser.add_argument("--hard", action="store_true",
165
+ help="eliminar el archivo de estado por completo")
166
+ subparser.set_defaults(func=cmd_clear)
167
+
168
+ subparser = subparsers.add_parser(
169
+ "doctor", help="diagnóstico del entorno (siempre exit 0)")
170
+ common(subparser)
171
+ subparser.set_defaults(func=cmd_doctor)
172
+ return parser
173
+
174
+
175
+ def main(argv=None):
176
+ try:
177
+ args = build_parser().parse_args(argv)
178
+ _sync_runtime()
179
+ return args.func(args)
180
+ except SkillError as error:
181
+ emit(error.to_json())
182
+ return error.exit_code
183
+ except KeyboardInterrupt:
184
+ return 130
185
+ except SystemExit:
186
+ raise
187
+ except Exception as error:
188
+ emit({"ok": False, "error": {
189
+ "code": "UNEXPECTED",
190
+ "message": f"{type(error).__name__}: {error}",
191
+ "hint": "error no previsto; reporta el comando exacto y este JSON"}})
192
+ return EXIT_RUNTIME
193
+
194
+
195
+ if __name__ == "__main__":
196
+ sys.exit(main())
@@ -0,0 +1 @@
1
+ """Componentes internos de github-proyect-tracking."""