ai-cr 2.0.0.dev2__py3-none-any.whl → 2.0.2__py3-none-any.whl

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.
gito/utils.py CHANGED
@@ -1,214 +1,226 @@
1
- import re
2
- import sys
3
- import os
4
- from pathlib import Path
5
-
6
- import typer
7
- import git
8
- from git import Repo
9
-
10
- _EXT_TO_HINT: dict[str, str] = {
11
- # scripting & languages
12
- ".py": "python",
13
- ".js": "javascript",
14
- ".ts": "typescript",
15
- ".java": "java",
16
- ".c": "c",
17
- ".cpp": "cpp",
18
- ".cc": "cpp",
19
- ".cxx": "cpp",
20
- ".h": "cpp",
21
- ".hpp": "cpp",
22
- ".cs": "csharp",
23
- ".rb": "ruby",
24
- ".go": "go",
25
- ".rs": "rust",
26
- ".swift": "swift",
27
- ".kt": "kotlin",
28
- ".scala": "scala",
29
- ".dart": "dart",
30
- ".php": "php",
31
- ".pl": "perl",
32
- ".pm": "perl",
33
- ".lua": "lua",
34
- # web & markup
35
- ".html": "html",
36
- ".htm": "html",
37
- ".css": "css",
38
- ".scss": "scss",
39
- ".less": "less",
40
- ".json": "json",
41
- ".xml": "xml",
42
- ".yaml": "yaml",
43
- ".yml": "yaml",
44
- ".toml": "toml",
45
- ".ini": "ini",
46
- ".csv": "csv",
47
- ".md": "markdown",
48
- ".rst": "rest",
49
- # shell & config
50
- ".sh": "bash",
51
- ".bash": "bash",
52
- ".zsh": "bash",
53
- ".fish": "bash",
54
- ".ps1": "powershell",
55
- ".dockerfile": "dockerfile",
56
- # build & CI
57
- ".makefile": "makefile",
58
- ".mk": "makefile",
59
- "CMakeLists.txt": "cmake",
60
- "Dockerfile": "dockerfile",
61
- ".gradle": "groovy",
62
- ".travis.yml": "yaml",
63
- # data & queries
64
- ".sql": "sql",
65
- ".graphql": "graphql",
66
- ".proto": "protobuf",
67
- ".yara": "yara",
68
- }
69
-
70
-
71
- def syntax_hint(file_path: str | Path) -> str:
72
- """
73
- Returns a syntax highlighting hint based on the file's extension or name.
74
-
75
- This can be used to annotate code blocks for rendering with syntax highlighting,
76
- e.g., using Markdown-style code blocks: ```<syntax_hint>\n<code>\n```.
77
-
78
- Args:
79
- file_path (str | Path): Path to the file.
80
-
81
- Returns:
82
- str: A syntax identifier suitable for code highlighting (e.g., 'python', 'json').
83
- """
84
- p = Path(file_path)
85
- ext = p.suffix.lower()
86
- if not ext:
87
- name = p.name.lower()
88
- if name == "dockerfile":
89
- return "dockerfile"
90
- return ""
91
- return _EXT_TO_HINT.get(ext, ext.lstrip("."))
92
-
93
-
94
- def is_running_in_github_action():
95
- return os.getenv("GITHUB_ACTIONS") == "true"
96
-
97
-
98
- def no_subcommand(app: typer.Typer) -> bool:
99
- """
100
- Checks if the current script is being invoked as a command in a target Typer application.
101
- """
102
- return not (
103
- (first_arg := next((a for a in sys.argv[1:] if not a.startswith('-')), None))
104
- and first_arg in (
105
- cmd.name or cmd.callback.__name__.replace('_', '-')
106
- for cmd in app.registered_commands
107
- )
108
- or '--help' in sys.argv
109
- )
110
-
111
-
112
- def parse_refs_pair(refs: str) -> tuple[str | None, str | None]:
113
- SEPARATOR = '..'
114
- if not refs:
115
- return None, None
116
- if SEPARATOR not in refs:
117
- return refs, None
118
- what, against = refs.split(SEPARATOR, 1)
119
- return what or None, against or None
120
-
121
-
122
- def max_line_len(text: str) -> int:
123
- return max((len(line) for line in text.splitlines()), default=0)
124
-
125
-
126
- def block_wrap_lr(text: str, left: str = "", right: str = "", max_rwrap: int = 60) -> str:
127
- ml = max_line_len(text)
128
- lines = text.splitlines()
129
- wrapped_lines = []
130
- for line in lines:
131
- ln = left+line
132
- if ml <= max_rwrap:
133
- ln += ' ' * (ml - len(line)) + right
134
- wrapped_lines.append(ln)
135
- return "\n".join(wrapped_lines)
136
-
137
-
138
- def extract_gh_owner_repo(repo: git.Repo) -> tuple[str, str]:
139
- """
140
- Extracts the GitHub owner and repository name.
141
-
142
- Returns:
143
- tuple[str, str]: A tuple containing the owner and repository name.
144
- """
145
- remote_url = repo.remotes.origin.url
146
- if remote_url.startswith('git@github.com:'):
147
- # SSH format: git@github.com:owner/repo.git
148
- repo_path = remote_url.split(':')[1].replace('.git', '')
149
- elif remote_url.startswith('https://github.com/'):
150
- # HTTPS format: https://github.com/owner/repo.git
151
- repo_path = remote_url.replace('https://github.com/', '').replace('.git', '')
152
- else:
153
- raise ValueError("Unsupported remote URL format")
154
- owner, repo_name = repo_path.split('/')
155
- return owner, repo_name
156
-
157
-
158
- def detect_github_env() -> dict:
159
- """
160
- Try to detect GitHub repository/PR info from environment variables (for GitHub Actions).
161
- Returns a dict with github_repo, github_pr_sha, github_pr_number, github_ref, etc.
162
- """
163
- repo = os.environ.get("GITHUB_REPOSITORY", "")
164
- pr_sha = os.environ.get("GITHUB_SHA", "")
165
- pr_number = os.environ.get("GITHUB_REF", "")
166
- branch = ""
167
- ref = os.environ.get("GITHUB_REF", "")
168
- # Try to resolve PR head SHA if available.
169
- # On PRs, GITHUB_HEAD_REF/BASE_REF contain branch names.
170
- if "GITHUB_HEAD_REF" in os.environ:
171
- branch = os.environ["GITHUB_HEAD_REF"]
172
- elif ref.startswith("refs/heads/"):
173
- branch = ref[len("refs/heads/"):]
174
- elif ref.startswith("refs/pull/"):
175
- # for pull_request events
176
- branch = ref
177
-
178
- d = {
179
- "github_repo": repo,
180
- "github_pr_sha": pr_sha,
181
- "github_pr_number": pr_number,
182
- "github_branch": branch,
183
- "github_ref": ref,
184
- }
185
- # Fallback for local usage: try to get from git
186
- if not repo:
187
- git_repo = None
188
- try:
189
- git_repo = Repo(".", search_parent_directories=True)
190
- origin = git_repo.remotes.origin.url
191
- # e.g. git@github.com:Nayjest/ai-code-review.git -> Nayjest/ai-code-review
192
- match = re.search(r"[:/]([\w\-]+)/([\w\-\.]+?)(\.git)?$", origin)
193
- if match:
194
- d["github_repo"] = f"{match.group(1)}/{match.group(2)}"
195
- d["github_pr_sha"] = git_repo.head.commit.hexsha
196
- d["github_branch"] = (
197
- git_repo.active_branch.name if hasattr(git_repo, "active_branch") else ""
198
- )
199
- except Exception:
200
- pass
201
- finally:
202
- if git_repo:
203
- try:
204
- git_repo.close()
205
- except Exception:
206
- pass
207
- # If branch is not a commit SHA, prefer branch for links
208
- if d["github_branch"]:
209
- d["github_pr_sha_or_branch"] = d["github_branch"]
210
- elif d["github_pr_sha"]:
211
- d["github_pr_sha_or_branch"] = d["github_pr_sha"]
212
- else:
213
- d["github_pr_sha_or_branch"] = "main"
214
- return d
1
+ import re
2
+ import sys
3
+ import os
4
+ from pathlib import Path
5
+
6
+ import typer
7
+ import git
8
+ from git import Repo
9
+ from microcore import ui
10
+
11
+
12
+ _EXT_TO_HINT: dict[str, str] = {
13
+ # scripting & languages
14
+ ".py": "python",
15
+ ".js": "javascript",
16
+ ".ts": "typescript",
17
+ ".java": "java",
18
+ ".c": "c",
19
+ ".cpp": "cpp",
20
+ ".cc": "cpp",
21
+ ".cxx": "cpp",
22
+ ".h": "cpp",
23
+ ".hpp": "cpp",
24
+ ".cs": "csharp",
25
+ ".rb": "ruby",
26
+ ".go": "go",
27
+ ".rs": "rust",
28
+ ".swift": "swift",
29
+ ".kt": "kotlin",
30
+ ".scala": "scala",
31
+ ".dart": "dart",
32
+ ".php": "php",
33
+ ".pl": "perl",
34
+ ".pm": "perl",
35
+ ".lua": "lua",
36
+ # web & markup
37
+ ".html": "html",
38
+ ".htm": "html",
39
+ ".css": "css",
40
+ ".scss": "scss",
41
+ ".less": "less",
42
+ ".json": "json",
43
+ ".xml": "xml",
44
+ ".yaml": "yaml",
45
+ ".yml": "yaml",
46
+ ".toml": "toml",
47
+ ".ini": "ini",
48
+ ".csv": "csv",
49
+ ".md": "markdown",
50
+ ".rst": "rest",
51
+ # shell & config
52
+ ".sh": "bash",
53
+ ".bash": "bash",
54
+ ".zsh": "bash",
55
+ ".fish": "bash",
56
+ ".ps1": "powershell",
57
+ ".dockerfile": "dockerfile",
58
+ # build & CI
59
+ ".makefile": "makefile",
60
+ ".mk": "makefile",
61
+ "CMakeLists.txt": "cmake",
62
+ "Dockerfile": "dockerfile",
63
+ ".gradle": "groovy",
64
+ ".travis.yml": "yaml",
65
+ # data & queries
66
+ ".sql": "sql",
67
+ ".graphql": "graphql",
68
+ ".proto": "protobuf",
69
+ ".yara": "yara",
70
+ }
71
+
72
+
73
+ def syntax_hint(file_path: str | Path) -> str:
74
+ """
75
+ Returns a syntax highlighting hint based on the file's extension or name.
76
+
77
+ This can be used to annotate code blocks for rendering with syntax highlighting,
78
+ e.g., using Markdown-style code blocks: ```<syntax_hint>\n<code>\n```.
79
+
80
+ Args:
81
+ file_path (str | Path): Path to the file.
82
+
83
+ Returns:
84
+ str: A syntax identifier suitable for code highlighting (e.g., 'python', 'json').
85
+ """
86
+ p = Path(file_path)
87
+ ext = p.suffix.lower()
88
+ if not ext:
89
+ name = p.name.lower()
90
+ if name == "dockerfile":
91
+ return "dockerfile"
92
+ return ""
93
+ return _EXT_TO_HINT.get(ext, ext.lstrip("."))
94
+
95
+
96
+ def is_running_in_github_action():
97
+ return os.getenv("GITHUB_ACTIONS") == "true"
98
+
99
+
100
+ def no_subcommand(app: typer.Typer) -> bool:
101
+ """
102
+ Checks if the current script is being invoked as a command in a target Typer application.
103
+ """
104
+ return not (
105
+ (first_arg := next((a for a in sys.argv[1:] if not a.startswith('-')), None))
106
+ and first_arg in (
107
+ cmd.name or cmd.callback.__name__.replace('_', '-')
108
+ for cmd in app.registered_commands
109
+ )
110
+ or '--help' in sys.argv
111
+ )
112
+
113
+
114
+ def parse_refs_pair(refs: str) -> tuple[str | None, str | None]:
115
+ SEPARATOR = '..'
116
+ if not refs:
117
+ return None, None
118
+ if SEPARATOR not in refs:
119
+ return refs, None
120
+ what, against = refs.split(SEPARATOR, 1)
121
+ return what or None, against or None
122
+
123
+
124
+ def max_line_len(text: str) -> int:
125
+ return max((len(line) for line in text.splitlines()), default=0)
126
+
127
+
128
+ def block_wrap_lr(
129
+ text: str,
130
+ left: str = "",
131
+ right: str = "",
132
+ max_rwrap: int = 60,
133
+ min_wrap: int = 0,
134
+ ) -> str:
135
+ ml = max(max_line_len(text), min_wrap)
136
+ lines = text.splitlines()
137
+ wrapped_lines = []
138
+ for line in lines:
139
+ ln = left+line
140
+ if ml <= max_rwrap:
141
+ ln += ' ' * (ml - len(line)) + right
142
+ wrapped_lines.append(ln)
143
+ return "\n".join(wrapped_lines)
144
+
145
+
146
+ def extract_gh_owner_repo(repo: git.Repo) -> tuple[str, str]:
147
+ """
148
+ Extracts the GitHub owner and repository name.
149
+
150
+ Returns:
151
+ tuple[str, str]: A tuple containing the owner and repository name.
152
+ """
153
+ remote_url = repo.remotes.origin.url
154
+ if remote_url.startswith('git@github.com:'):
155
+ # SSH format: git@github.com:owner/repo.git
156
+ repo_path = remote_url.split(':')[1].replace('.git', '')
157
+ elif remote_url.startswith('https://github.com/'):
158
+ # HTTPS format: https://github.com/owner/repo.git
159
+ repo_path = remote_url.replace('https://github.com/', '').replace('.git', '')
160
+ else:
161
+ raise ValueError("Unsupported remote URL format")
162
+ owner, repo_name = repo_path.split('/')
163
+ return owner, repo_name
164
+
165
+
166
+ def detect_github_env() -> dict:
167
+ """
168
+ Try to detect GitHub repository/PR info from environment variables (for GitHub Actions).
169
+ Returns a dict with github_repo, github_pr_sha, github_pr_number, github_ref, etc.
170
+ """
171
+ repo = os.environ.get("GITHUB_REPOSITORY", "")
172
+ pr_sha = os.environ.get("GITHUB_SHA", "")
173
+ pr_number = os.environ.get("GITHUB_REF", "")
174
+ branch = ""
175
+ ref = os.environ.get("GITHUB_REF", "")
176
+ # Try to resolve PR head SHA if available.
177
+ # On PRs, GITHUB_HEAD_REF/BASE_REF contain branch names.
178
+ if "GITHUB_HEAD_REF" in os.environ:
179
+ branch = os.environ["GITHUB_HEAD_REF"]
180
+ elif ref.startswith("refs/heads/"):
181
+ branch = ref[len("refs/heads/"):]
182
+ elif ref.startswith("refs/pull/"):
183
+ # for pull_request events
184
+ branch = ref
185
+
186
+ d = {
187
+ "github_repo": repo,
188
+ "github_pr_sha": pr_sha,
189
+ "github_pr_number": pr_number,
190
+ "github_branch": branch,
191
+ "github_ref": ref,
192
+ }
193
+ # Fallback for local usage: try to get from git
194
+ if not repo:
195
+ git_repo = None
196
+ try:
197
+ git_repo = Repo(".", search_parent_directories=True)
198
+ origin = git_repo.remotes.origin.url
199
+ # e.g. git@github.com:Nayjest/ai-code-review.git -> Nayjest/ai-code-review
200
+ match = re.search(r"[:/]([\w\-]+)/([\w\-\.]+?)(\.git)?$", origin)
201
+ if match:
202
+ d["github_repo"] = f"{match.group(1)}/{match.group(2)}"
203
+ d["github_pr_sha"] = git_repo.head.commit.hexsha
204
+ d["github_branch"] = (
205
+ git_repo.active_branch.name if hasattr(git_repo, "active_branch") else ""
206
+ )
207
+ except Exception:
208
+ pass
209
+ finally:
210
+ if git_repo:
211
+ try:
212
+ git_repo.close()
213
+ except Exception:
214
+ pass
215
+ # If branch is not a commit SHA, prefer branch for links
216
+ if d["github_branch"]:
217
+ d["github_pr_sha_or_branch"] = d["github_branch"]
218
+ elif d["github_pr_sha"]:
219
+ d["github_pr_sha_or_branch"] = d["github_pr_sha"]
220
+ else:
221
+ d["github_pr_sha_or_branch"] = "main"
222
+ return d
223
+
224
+
225
+ def stream_to_cli(text):
226
+ print(ui.blue(text), end='')
@@ -1,23 +0,0 @@
1
- gito/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- gito/__main__.py,sha256=EClCwCzb6h6YBpt0hrnG4h0mlNhNePyg_xBNNSVm1os,65
3
- gito/bootstrap.py,sha256=ETKioiDc2Npc7znd8HJxA5-twd7sZMPCufIGwXFQSbY,2403
4
- gito/cli.py,sha256=98Cym9Oil1y1X4SB8cb7xAcJENJPv9ZBPxBEcniB1q4,7994
5
- gito/commands/__init__.py,sha256=NKUUDskR6taZGbHk5qR9msDS22aHpdzAZlUDxzRdMYA,56
6
- gito/commands/fix.py,sha256=Nht_14as5txOBGgzrD_1p9pKDJ5J8ghvmaUEVJsJyqI,5462
7
- gito/commands/gh_comment.py,sha256=uU3CdqsduD_yRfm5eSBC-nE4naofppTkd5inSE0_O_Q,5188
8
- gito/commands/repl.py,sha256=waN7FJBl98gWmDwZWMa8x157iWbPHIDPJEKmTdzWQ70,396
9
- gito/config.toml,sha256=NU_nFJtDZVz6dLsz3y33FPiDtf7WP9ZEnzN3mSlxi0s,16002
10
- gito/constants.py,sha256=DNqh3hOxeLM_KscUH4uFdAc9295o1hiXtwoEw2KxLiU,392
11
- gito/core.py,sha256=XzrgkNu1GZsjQLkK_PRzV5x-qgdMbhTpSIVrYVadJxc,8300
12
- gito/issue_trackers.py,sha256=1S8yMuKM6Vq7l81nElNS6IOwXTjEcC5123cp2-6aHkc,453
13
- gito/pipeline.py,sha256=zI8iRsb8Y18EO6lrUnPFwxBhefJc_VUDVAfcgA9zCWo,2334
14
- gito/pipeline_steps/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
- gito/pipeline_steps/jira.py,sha256=hujeWGFAbIHPOidPWgvWPYlgB2hjdXHqU5-lo2Qcjvs,2672
16
- gito/project_config.py,sha256=LCYMcxXYbiijOMwsDwr4FY_E4pDHwUE7UkRzJkgX1Uk,2568
17
- gito/report_struct.py,sha256=xX93WJSAzVP5_w4fFXjeuDXEOGPvTsEEvLqcOPfWPXM,4234
18
- gito/utils.py,sha256=BXy7wT7S9CNymPyNlgFqH8WXNTfErKQ6WQlM-IfqYGg,6489
19
- ai_cr-2.0.0.dev2.dist-info/entry_points.txt,sha256=Ua1DxkhJJ8TZuLgnH-IlWCkrre_0S0dq_GtYRaYupWk,38
20
- ai_cr-2.0.0.dev2.dist-info/LICENSE,sha256=XATf3zv-CppUSJqI18KLhwnPEomUXEl5WbBzFyb9OSU,1096
21
- ai_cr-2.0.0.dev2.dist-info/METADATA,sha256=TRMBhhnhRBWsMGbHZsyfXG0-VFchXmmw_HwTjd8YnHk,7763
22
- ai_cr-2.0.0.dev2.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
23
- ai_cr-2.0.0.dev2.dist-info/RECORD,,