ai-cr 2.0.3__tar.gz → 3.0.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.
- {ai_cr-2.0.3 → ai_cr-3.0.0}/PKG-INFO +4 -4
- {ai_cr-2.0.3 → ai_cr-3.0.0}/README.md +1 -1
- {ai_cr-2.0.3 → ai_cr-3.0.0}/gito/bootstrap.py +28 -12
- ai_cr-3.0.0/gito/cli.py +210 -0
- ai_cr-3.0.0/gito/cli_base.py +90 -0
- {ai_cr-2.0.3 → ai_cr-3.0.0}/gito/commands/deploy.py +3 -3
- {ai_cr-2.0.3 → ai_cr-3.0.0}/gito/commands/fix.py +1 -1
- {ai_cr-2.0.3 → ai_cr-3.0.0}/gito/commands/gh_post_review_comment.py +23 -20
- {ai_cr-2.0.3 → ai_cr-3.0.0}/gito/commands/gh_react_to_comment.py +1 -1
- ai_cr-3.0.0/gito/commands/linear_comment.py +53 -0
- {ai_cr-2.0.3 → ai_cr-3.0.0}/gito/commands/repl.py +1 -1
- {ai_cr-2.0.3 → ai_cr-3.0.0}/gito/config.toml +18 -4
- ai_cr-3.0.0/gito/context.py +19 -0
- {ai_cr-2.0.3 → ai_cr-3.0.0}/gito/core.py +62 -19
- ai_cr-3.0.0/gito/env.py +3 -0
- {ai_cr-2.0.3 → ai_cr-3.0.0}/gito/gh_api.py +1 -1
- {ai_cr-2.0.3 → ai_cr-3.0.0}/gito/pipeline.py +8 -7
- {ai_cr-2.0.3 → ai_cr-3.0.0}/gito/pipeline_steps/jira.py +6 -1
- {ai_cr-2.0.3 → ai_cr-3.0.0}/gito/report_struct.py +2 -1
- ai_cr-2.0.3/gito/tpl/github_workflows/components/env-vars.jinja2 → ai_cr-3.0.0/gito/tpl/github_workflows/components/env-vars.j2 +1 -1
- ai_cr-3.0.0/gito/tpl/github_workflows/components/installs.j2 +23 -0
- ai_cr-2.0.3/gito/tpl/github_workflows/gito-code-review.yml.jinja2 → ai_cr-3.0.0/gito/tpl/github_workflows/gito-code-review.yml.j2 +5 -5
- ai_cr-2.0.3/gito/tpl/github_workflows/gito-react-to-comments.yml.jinja2 → ai_cr-3.0.0/gito/tpl/github_workflows/gito-react-to-comments.yml.j2 +2 -2
- ai_cr-3.0.0/gito/tpl/release_notes.j2 +24 -0
- {ai_cr-2.0.3 → ai_cr-3.0.0}/gito/utils.py +14 -3
- {ai_cr-2.0.3 → ai_cr-3.0.0}/pyproject.toml +3 -3
- ai_cr-2.0.3/gito/cli.py +0 -217
- ai_cr-2.0.3/gito/tpl/github_workflows/components/installs.jinja2 +0 -8
- {ai_cr-2.0.3 → ai_cr-3.0.0}/LICENSE +0 -0
- {ai_cr-2.0.3 → ai_cr-3.0.0}/gito/__init__.py +0 -0
- {ai_cr-2.0.3 → ai_cr-3.0.0}/gito/__main__.py +0 -0
- {ai_cr-2.0.3 → ai_cr-3.0.0}/gito/commands/__init__.py +0 -0
- {ai_cr-2.0.3 → ai_cr-3.0.0}/gito/constants.py +0 -0
- {ai_cr-2.0.3 → ai_cr-3.0.0}/gito/issue_trackers.py +0 -0
- {ai_cr-2.0.3 → ai_cr-3.0.0}/gito/pipeline_steps/__init__.py +0 -0
- {ai_cr-2.0.3 → ai_cr-3.0.0}/gito/pipeline_steps/linear.py +0 -0
- {ai_cr-2.0.3 → ai_cr-3.0.0}/gito/project_config.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: ai-cr
|
3
|
-
Version:
|
3
|
+
Version: 3.0.0
|
4
4
|
Summary: AI code review tool that works with any language model provider. It detects issues in GitHub pull requests or local changes—instantly, reliably, and without vendor lock-in.
|
5
5
|
License: MIT
|
6
6
|
Keywords: static code analysis,code review,code quality,ai,coding,assistant,llm,github,automation,devops,developer tools,github actions,workflows,git
|
@@ -16,8 +16,8 @@ Classifier: Programming Language :: Python :: 3.12
|
|
16
16
|
Classifier: Programming Language :: Python :: 3.13
|
17
17
|
Classifier: Topic :: Software Development
|
18
18
|
Requires-Dist: GitPython (>=3.1.44,<4.0.0)
|
19
|
-
Requires-Dist: ai-microcore (==4.
|
20
|
-
Requires-Dist: anthropic (>=0.
|
19
|
+
Requires-Dist: ai-microcore (==4.2.1)
|
20
|
+
Requires-Dist: anthropic (>=0.57.1,<0.58.0)
|
21
21
|
Requires-Dist: ghapi (>=1.0.6,<1.1.0)
|
22
22
|
Requires-Dist: google-generativeai (>=0.8.5,<0.9.0)
|
23
23
|
Requires-Dist: jira (>=3.8.0,<4.0.0)
|
@@ -87,7 +87,7 @@ jobs:
|
|
87
87
|
uses: actions/setup-python@v5
|
88
88
|
with: { python-version: "3.13" }
|
89
89
|
- name: Install AI Code Review tool
|
90
|
-
run: pip install gito.bot~=
|
90
|
+
run: pip install gito.bot~=3.0
|
91
91
|
- name: Run AI code analysis
|
92
92
|
env:
|
93
93
|
LLM_API_KEY: ${{ secrets.LLM_API_KEY }}
|
@@ -58,7 +58,7 @@ jobs:
|
|
58
58
|
uses: actions/setup-python@v5
|
59
59
|
with: { python-version: "3.13" }
|
60
60
|
- name: Install AI Code Review tool
|
61
|
-
run: pip install gito.bot~=
|
61
|
+
run: pip install gito.bot~=3.0
|
62
62
|
- name: Run AI code analysis
|
63
63
|
env:
|
64
64
|
LLM_API_KEY: ${{ secrets.LLM_API_KEY }}
|
@@ -1,16 +1,18 @@
|
|
1
|
-
import logging
|
2
1
|
import os
|
2
|
+
import sys
|
3
|
+
import io
|
4
|
+
import logging
|
3
5
|
from datetime import datetime
|
4
6
|
from pathlib import Path
|
5
7
|
|
6
8
|
import microcore as mc
|
7
|
-
import typer
|
8
9
|
|
9
10
|
from .utils import is_running_in_github_action
|
10
11
|
from .constants import HOME_ENV_PATH, EXECUTABLE, PROJECT_GITO_FOLDER
|
12
|
+
from .env import Env
|
11
13
|
|
12
14
|
|
13
|
-
def setup_logging():
|
15
|
+
def setup_logging(log_level: int = logging.INFO):
|
14
16
|
class CustomFormatter(logging.Formatter):
|
15
17
|
def format(self, record):
|
16
18
|
dt = datetime.fromtimestamp(record.created).strftime("%Y-%m-%d %H:%M:%S")
|
@@ -25,23 +27,41 @@ def setup_logging():
|
|
25
27
|
|
26
28
|
handler = logging.StreamHandler()
|
27
29
|
handler.setFormatter(CustomFormatter())
|
28
|
-
logging.basicConfig(level=
|
30
|
+
logging.basicConfig(level=log_level, handlers=[handler])
|
29
31
|
|
30
32
|
|
31
|
-
def bootstrap():
|
33
|
+
def bootstrap(verbosity: int = 1):
|
32
34
|
"""Bootstrap the application with the environment configuration."""
|
33
|
-
|
34
|
-
|
35
|
+
log_levels_by_verbosity = {
|
36
|
+
0: logging.CRITICAL,
|
37
|
+
1: logging.INFO,
|
38
|
+
2: logging.DEBUG,
|
39
|
+
3: logging.DEBUG,
|
40
|
+
}
|
41
|
+
Env.verbosity = verbosity
|
42
|
+
Env.logging_level = log_levels_by_verbosity.get(verbosity, logging.INFO)
|
43
|
+
setup_logging(Env.logging_level)
|
44
|
+
logging.info("Bootstrapping... "+mc.ui.gray(f"[verbosity={verbosity}]"))
|
45
|
+
|
46
|
+
# cp1251 is used on Windows when redirecting output
|
47
|
+
if sys.stdout.encoding and sys.stdout.encoding.lower() != "utf-8":
|
48
|
+
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
49
|
+
|
35
50
|
try:
|
36
51
|
mc.configure(
|
37
52
|
DOT_ENV_FILE=HOME_ENV_PATH,
|
38
|
-
USE_LOGGING=
|
53
|
+
USE_LOGGING=verbosity >= 1,
|
39
54
|
EMBEDDING_DB_TYPE=mc.EmbeddingDbType.NONE,
|
40
55
|
PROMPT_TEMPLATES_PATH=[
|
41
56
|
PROJECT_GITO_FOLDER,
|
42
57
|
Path(__file__).parent / "tpl"
|
43
58
|
],
|
44
59
|
)
|
60
|
+
if verbosity > 1:
|
61
|
+
mc.logging.LoggingConfig.STRIP_REQUEST_LINES = None
|
62
|
+
else:
|
63
|
+
mc.logging.LoggingConfig.STRIP_REQUEST_LINES = [300, 15]
|
64
|
+
|
45
65
|
except mc.LLMConfigError as e:
|
46
66
|
msg = str(e)
|
47
67
|
if is_running_in_github_action():
|
@@ -65,7 +85,3 @@ def bootstrap():
|
|
65
85
|
except Exception as e:
|
66
86
|
logging.error(f"Unexpected configuration error: {e}")
|
67
87
|
raise SystemExit(3)
|
68
|
-
mc.logging.LoggingConfig.STRIP_REQUEST_LINES = [300, 15]
|
69
|
-
|
70
|
-
|
71
|
-
app = typer.Typer(pretty_exceptions_show_locals=False)
|
ai_cr-3.0.0/gito/cli.py
ADDED
@@ -0,0 +1,210 @@
|
|
1
|
+
import os
|
2
|
+
import asyncio
|
3
|
+
import logging
|
4
|
+
import sys
|
5
|
+
import textwrap
|
6
|
+
|
7
|
+
import microcore as mc
|
8
|
+
import typer
|
9
|
+
from git import Repo
|
10
|
+
|
11
|
+
from .core import review, get_diff, filter_diff, answer
|
12
|
+
from .cli_base import (
|
13
|
+
app,
|
14
|
+
args_to_target,
|
15
|
+
arg_refs,
|
16
|
+
arg_what,
|
17
|
+
arg_filters,
|
18
|
+
arg_out,
|
19
|
+
arg_against,
|
20
|
+
get_repo_context,
|
21
|
+
)
|
22
|
+
from .report_struct import Report
|
23
|
+
from .constants import HOME_ENV_PATH, GITHUB_MD_REPORT_FILE_NAME
|
24
|
+
from .bootstrap import bootstrap
|
25
|
+
from .utils import no_subcommand, extract_gh_owner_repo, remove_html_comments
|
26
|
+
from .gh_api import resolve_gh_token
|
27
|
+
|
28
|
+
# Import fix command to register it
|
29
|
+
from .commands import fix, gh_react_to_comment, repl, deploy # noqa
|
30
|
+
from .commands.gh_post_review_comment import post_github_cr_comment
|
31
|
+
from .commands.linear_comment import linear_comment
|
32
|
+
|
33
|
+
app_no_subcommand = typer.Typer(pretty_exceptions_show_locals=False)
|
34
|
+
|
35
|
+
|
36
|
+
def main():
|
37
|
+
if sys.platform == "win32":
|
38
|
+
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
39
|
+
# Help subcommand alias: if 'help' appears as first non-option arg, replace it with '--help'
|
40
|
+
if len(sys.argv) > 1 and sys.argv[1] == "help":
|
41
|
+
sys.argv = [sys.argv[0]] + sys.argv[2:] + ["--help"]
|
42
|
+
|
43
|
+
if no_subcommand(app):
|
44
|
+
bootstrap()
|
45
|
+
app_no_subcommand()
|
46
|
+
else:
|
47
|
+
app()
|
48
|
+
|
49
|
+
|
50
|
+
@app.callback(invoke_without_command=True)
|
51
|
+
def cli(
|
52
|
+
ctx: typer.Context,
|
53
|
+
verbose: bool = typer.Option(default=None),
|
54
|
+
verbosity: int = typer.Option(
|
55
|
+
None,
|
56
|
+
'--verbosity', '-v',
|
57
|
+
help="Set verbosity level (0-3, default 1)"
|
58
|
+
),
|
59
|
+
):
|
60
|
+
if verbose is not None and verbosity is not None:
|
61
|
+
raise typer.BadParameter(
|
62
|
+
"Please specify either --verbose or --verbosity, not both."
|
63
|
+
)
|
64
|
+
if verbose is not None:
|
65
|
+
verbosity = 2 if verbose else 0
|
66
|
+
if verbosity is None:
|
67
|
+
verbosity = 1
|
68
|
+
|
69
|
+
if ctx.invoked_subcommand != "setup":
|
70
|
+
bootstrap(verbosity)
|
71
|
+
|
72
|
+
|
73
|
+
@app_no_subcommand.command(name="review", help="Perform code review")
|
74
|
+
@app.command(name="review", help="Perform code review")
|
75
|
+
@app.command(name="run", hidden=True)
|
76
|
+
def cmd_review(
|
77
|
+
refs: str = arg_refs(),
|
78
|
+
what: str = arg_what(),
|
79
|
+
against: str = arg_against(),
|
80
|
+
filters: str = arg_filters(),
|
81
|
+
merge_base: bool = typer.Option(default=True, help="Use merge base for comparison"),
|
82
|
+
url: str = typer.Option("", "--url", help="Git repository URL"),
|
83
|
+
post_comment: bool = typer.Option(default=False, help="Post review comment to GitHub"),
|
84
|
+
pr: int = typer.Option(
|
85
|
+
default=None,
|
86
|
+
help=textwrap.dedent("""\n
|
87
|
+
GitHub Pull Request number to post the comment to
|
88
|
+
(for local usage together with --post-comment,
|
89
|
+
in the github actions PR is resolved from the environment)
|
90
|
+
""")
|
91
|
+
),
|
92
|
+
out: str = arg_out()
|
93
|
+
):
|
94
|
+
_what, _against = args_to_target(refs, what, against)
|
95
|
+
with get_repo_context(url, _what) as (repo, out_folder):
|
96
|
+
asyncio.run(review(
|
97
|
+
repo=repo,
|
98
|
+
what=_what,
|
99
|
+
against=_against,
|
100
|
+
filters=filters,
|
101
|
+
use_merge_base=merge_base,
|
102
|
+
out_folder=out or out_folder,
|
103
|
+
))
|
104
|
+
if post_comment:
|
105
|
+
try:
|
106
|
+
owner, repo_name = extract_gh_owner_repo(repo)
|
107
|
+
except ValueError as e:
|
108
|
+
logging.error(
|
109
|
+
"Error posting comment:\n"
|
110
|
+
"Could not extract GitHub owner and repository name from the local repository."
|
111
|
+
)
|
112
|
+
raise typer.Exit(code=1) from e
|
113
|
+
post_github_cr_comment(
|
114
|
+
md_report_file=os.path.join(out or out_folder, GITHUB_MD_REPORT_FILE_NAME),
|
115
|
+
pr=pr,
|
116
|
+
gh_repo=f"{owner}/{repo_name}",
|
117
|
+
token=resolve_gh_token()
|
118
|
+
)
|
119
|
+
|
120
|
+
|
121
|
+
@app.command(name="ask", help="Answer questions about codebase changes")
|
122
|
+
@app.command(name="answer", hidden=True)
|
123
|
+
@app.command(name="talk", hidden=True)
|
124
|
+
def cmd_answer(
|
125
|
+
question: str = typer.Argument(help="Question to ask about the codebase changes"),
|
126
|
+
refs: str = arg_refs(),
|
127
|
+
what: str = arg_what(),
|
128
|
+
against: str = arg_against(),
|
129
|
+
filters: str = arg_filters(),
|
130
|
+
merge_base: bool = typer.Option(default=True, help="Use merge base for comparison"),
|
131
|
+
use_pipeline: bool = typer.Option(default=True),
|
132
|
+
post_to: str = typer.Option(
|
133
|
+
help="Post answer to ... Supported values: linear",
|
134
|
+
default=None,
|
135
|
+
show_default=False
|
136
|
+
),
|
137
|
+
):
|
138
|
+
_what, _against = args_to_target(refs, what, against)
|
139
|
+
if str(question).startswith("tpl:"):
|
140
|
+
prompt_file = str(question)[4:]
|
141
|
+
question = ""
|
142
|
+
else:
|
143
|
+
prompt_file = None
|
144
|
+
out = answer(
|
145
|
+
question=question,
|
146
|
+
what=_what,
|
147
|
+
against=_against,
|
148
|
+
filters=filters,
|
149
|
+
use_merge_base=merge_base,
|
150
|
+
prompt_file=prompt_file,
|
151
|
+
use_pipeline=use_pipeline,
|
152
|
+
)
|
153
|
+
if post_to == 'linear':
|
154
|
+
logging.info("Posting answer to Linear...")
|
155
|
+
linear_comment(remove_html_comments(out))
|
156
|
+
return out
|
157
|
+
|
158
|
+
|
159
|
+
@app.command(help="Configure LLM for local usage interactively")
|
160
|
+
def setup():
|
161
|
+
mc.interactive_setup(HOME_ENV_PATH)
|
162
|
+
|
163
|
+
|
164
|
+
@app.command(name="render")
|
165
|
+
@app.command(name="report", hidden=True)
|
166
|
+
def render(
|
167
|
+
format: str = typer.Argument(default=Report.Format.CLI),
|
168
|
+
source: str = typer.Option(
|
169
|
+
"",
|
170
|
+
"--src",
|
171
|
+
"--source",
|
172
|
+
help="Source file (json) to load the report from"
|
173
|
+
)
|
174
|
+
):
|
175
|
+
Report.load(file_name=source).to_cli(report_format=format)
|
176
|
+
|
177
|
+
|
178
|
+
@app.command(help="List files in the diff. Might be useful to check what will be reviewed.")
|
179
|
+
def files(
|
180
|
+
refs: str = arg_refs(),
|
181
|
+
what: str = arg_what(),
|
182
|
+
against: str = arg_against(),
|
183
|
+
filters: str = arg_filters(),
|
184
|
+
merge_base: bool = typer.Option(default=True, help="Use merge base for comparison"),
|
185
|
+
diff: bool = typer.Option(default=False, help="Show diff content")
|
186
|
+
):
|
187
|
+
_what, _against = args_to_target(refs, what, against)
|
188
|
+
repo = Repo(".")
|
189
|
+
try:
|
190
|
+
patch_set = get_diff(repo=repo, what=_what, against=_against, use_merge_base=merge_base)
|
191
|
+
patch_set = filter_diff(patch_set, filters)
|
192
|
+
print(
|
193
|
+
f"Changed files: "
|
194
|
+
f"{mc.ui.green(_what or 'INDEX')} vs "
|
195
|
+
f"{mc.ui.yellow(_against or repo.remotes.origin.refs.HEAD.reference.name)}"
|
196
|
+
f"{' filtered by ' + mc.ui.cyan(filters) if filters else ''}"
|
197
|
+
)
|
198
|
+
|
199
|
+
for patch in patch_set:
|
200
|
+
if patch.is_added_file:
|
201
|
+
color = mc.ui.green
|
202
|
+
elif patch.is_removed_file:
|
203
|
+
color = mc.ui.red
|
204
|
+
else:
|
205
|
+
color = mc.ui.blue
|
206
|
+
print(f"- {color(patch.path)}")
|
207
|
+
if diff:
|
208
|
+
print(mc.ui.gray(textwrap.indent(str(patch), " ")))
|
209
|
+
finally:
|
210
|
+
repo.close()
|
@@ -0,0 +1,90 @@
|
|
1
|
+
import contextlib
|
2
|
+
import logging
|
3
|
+
import tempfile
|
4
|
+
|
5
|
+
import microcore as mc
|
6
|
+
import typer
|
7
|
+
from git import Repo
|
8
|
+
from gito.utils import parse_refs_pair
|
9
|
+
|
10
|
+
|
11
|
+
def args_to_target(refs, what, against) -> tuple[str | None, str | None]:
|
12
|
+
_what, _against = parse_refs_pair(refs)
|
13
|
+
if _what:
|
14
|
+
if what:
|
15
|
+
raise typer.BadParameter(
|
16
|
+
"You cannot specify both 'refs' <WHAT>..<AGAINST> and '--what'. Use one of them."
|
17
|
+
)
|
18
|
+
else:
|
19
|
+
_what = what
|
20
|
+
if _against:
|
21
|
+
if against:
|
22
|
+
raise typer.BadParameter(
|
23
|
+
"You cannot specify both 'refs' <WHAT>..<AGAINST> and '--against'. Use one of them."
|
24
|
+
)
|
25
|
+
else:
|
26
|
+
_against = against
|
27
|
+
return _what, _against
|
28
|
+
|
29
|
+
|
30
|
+
def arg_refs() -> typer.Argument:
|
31
|
+
return typer.Argument(
|
32
|
+
default=None,
|
33
|
+
help="Git refs to review, [what]..[against] e.g. 'HEAD..HEAD~1'"
|
34
|
+
)
|
35
|
+
|
36
|
+
|
37
|
+
def arg_what() -> typer.Option:
|
38
|
+
return typer.Option(None, "--what", "-w", help="Git ref to review")
|
39
|
+
|
40
|
+
|
41
|
+
def arg_filters() -> typer.Option:
|
42
|
+
return typer.Option(
|
43
|
+
"", "--filter", "-f", "--filters",
|
44
|
+
help="""
|
45
|
+
filter reviewed files by glob / fnmatch pattern(s),
|
46
|
+
e.g. 'src/**/*.py', may be comma-separated
|
47
|
+
""",
|
48
|
+
)
|
49
|
+
|
50
|
+
|
51
|
+
def arg_out() -> typer.Option:
|
52
|
+
return typer.Option(
|
53
|
+
None,
|
54
|
+
"--out", "-o", "--output",
|
55
|
+
help="Output folder for the code review report"
|
56
|
+
)
|
57
|
+
|
58
|
+
|
59
|
+
def arg_against() -> typer.Option:
|
60
|
+
return typer.Option(
|
61
|
+
None,
|
62
|
+
"--against", "-vs", "--vs",
|
63
|
+
help="Git ref to compare against"
|
64
|
+
)
|
65
|
+
|
66
|
+
|
67
|
+
app = typer.Typer(pretty_exceptions_show_locals=False)
|
68
|
+
|
69
|
+
|
70
|
+
@contextlib.contextmanager
|
71
|
+
def get_repo_context(url: str, branch: str):
|
72
|
+
"""Context manager for handling both local and remote repositories."""
|
73
|
+
if url:
|
74
|
+
with tempfile.TemporaryDirectory() as temp_dir:
|
75
|
+
logging.info(
|
76
|
+
f"get_repo_context: "
|
77
|
+
f"Cloning [{mc.ui.green(url)}] to {mc.utils.file_link(temp_dir)} ..."
|
78
|
+
)
|
79
|
+
repo = Repo.clone_from(url, branch=branch, to_path=temp_dir)
|
80
|
+
try:
|
81
|
+
yield repo, temp_dir
|
82
|
+
finally:
|
83
|
+
repo.close()
|
84
|
+
else:
|
85
|
+
logging.info("get_repo_context: Using local repo...")
|
86
|
+
repo = Repo(".")
|
87
|
+
try:
|
88
|
+
yield repo, "."
|
89
|
+
finally:
|
90
|
+
repo.close()
|
@@ -5,7 +5,7 @@ from microcore import ApiType, ui, utils
|
|
5
5
|
from git import Repo
|
6
6
|
|
7
7
|
from ..utils import version, extract_gh_owner_repo
|
8
|
-
from ..
|
8
|
+
from ..cli_base import app
|
9
9
|
|
10
10
|
|
11
11
|
@app.command(name="deploy", help="Deploy Gito workflows to GitHub Actions")
|
@@ -56,11 +56,11 @@ def deploy(api_type: ApiType = None, commit: bool = None, rewrite: bool = False)
|
|
56
56
|
remove_indent=True,
|
57
57
|
)
|
58
58
|
gito_code_review_yml = mc.tpl(
|
59
|
-
"github_workflows/gito-code-review.yml.
|
59
|
+
"github_workflows/gito-code-review.yml.j2",
|
60
60
|
**template_vars
|
61
61
|
)
|
62
62
|
gito_react_to_comments_yml = mc.tpl(
|
63
|
-
"github_workflows/gito-react-to-comments.yml.
|
63
|
+
"github_workflows/gito-react-to-comments.yml.j2",
|
64
64
|
**template_vars
|
65
65
|
)
|
66
66
|
|
@@ -5,7 +5,7 @@ from time import sleep
|
|
5
5
|
import typer
|
6
6
|
from ghapi.core import GhApi
|
7
7
|
|
8
|
-
from ..
|
8
|
+
from ..cli_base import app
|
9
9
|
from ..constants import GITHUB_MD_REPORT_FILE_NAME, HTML_CR_COMMENT_MARKER
|
10
10
|
from ..gh_api import (
|
11
11
|
post_gh_comment,
|
@@ -15,8 +15,11 @@ from ..gh_api import (
|
|
15
15
|
from ..project_config import ProjectConfig
|
16
16
|
|
17
17
|
|
18
|
-
@app.command(help="Leave a GitHub PR comment with the review.")
|
19
|
-
def
|
18
|
+
@app.command(name="github-comment", help="Leave a GitHub PR comment with the review.")
|
19
|
+
def post_github_cr_comment(
|
20
|
+
md_report_file: str = typer.Option(default=None),
|
21
|
+
pr: int = typer.Option(default=None),
|
22
|
+
gh_repo: str = typer.Option(default=None, help="owner/repo"),
|
20
23
|
token: str = typer.Option(
|
21
24
|
"", help="GitHub token (or set GITHUB_TOKEN env var)"
|
22
25
|
),
|
@@ -24,7 +27,7 @@ def github_comment(
|
|
24
27
|
"""
|
25
28
|
Leaves a comment with the review on the current GitHub pull request.
|
26
29
|
"""
|
27
|
-
file = GITHUB_MD_REPORT_FILE_NAME
|
30
|
+
file = md_report_file or GITHUB_MD_REPORT_FILE_NAME
|
28
31
|
if not os.path.exists(file):
|
29
32
|
logging.error(f"Review file not found: {file}, comment will not be posted.")
|
30
33
|
raise typer.Exit(4)
|
@@ -38,25 +41,25 @@ def github_comment(
|
|
38
41
|
raise typer.Exit(1)
|
39
42
|
config = ProjectConfig.load()
|
40
43
|
gh_env = config.prompt_vars["github_env"]
|
41
|
-
gh_repo = gh_env.get("github_repo", "")
|
44
|
+
gh_repo = gh_repo or gh_env.get("github_repo", "")
|
42
45
|
pr_env_val = gh_env.get("github_pr_number", "")
|
43
46
|
logging.info(f"github_pr_number = {pr_env_val}")
|
44
47
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
48
|
+
if not pr:
|
49
|
+
# e.g. could be "refs/pull/123/merge" or a direct number
|
50
|
+
if "/" in pr_env_val and "pull" in pr_env_val:
|
51
|
+
# refs/pull/123/merge
|
52
|
+
try:
|
53
|
+
pr_num_candidate = pr_env_val.strip("/").split("/")
|
54
|
+
idx = pr_num_candidate.index("pull")
|
55
|
+
pr = int(pr_num_candidate[idx + 1])
|
56
|
+
except Exception:
|
57
|
+
pass
|
58
|
+
else:
|
59
|
+
try:
|
60
|
+
pr = int(pr_env_val)
|
61
|
+
except ValueError:
|
62
|
+
pass
|
60
63
|
if not pr:
|
61
64
|
if pr_str := os.getenv("PR_NUMBER_FROM_WORKFLOW_DISPATCH"):
|
62
65
|
try:
|
@@ -16,7 +16,7 @@ from microcore import ui
|
|
16
16
|
from ghapi.all import GhApi
|
17
17
|
import git
|
18
18
|
|
19
|
-
from ..
|
19
|
+
from ..cli_base import app
|
20
20
|
from ..constants import JSON_REPORT_FILE_NAME, HTML_TEXT_ICON
|
21
21
|
from ..core import answer
|
22
22
|
from ..gh_api import post_gh_comment, resolve_gh_token
|
@@ -0,0 +1,53 @@
|
|
1
|
+
import os
|
2
|
+
import sys
|
3
|
+
import logging
|
4
|
+
|
5
|
+
import typer
|
6
|
+
from git import Repo
|
7
|
+
|
8
|
+
from ..cli_base import app, arg_refs
|
9
|
+
from ..issue_trackers import resolve_issue_key
|
10
|
+
|
11
|
+
import requests
|
12
|
+
|
13
|
+
|
14
|
+
def post_linear_comment(issue_key, text, api_key):
|
15
|
+
response = requests.post(
|
16
|
+
'https://api.linear.app/graphql',
|
17
|
+
headers={'Authorization': api_key, 'Content-Type': 'application/json'},
|
18
|
+
json={
|
19
|
+
'query': '''
|
20
|
+
mutation($issueId: String!, $body: String!) {
|
21
|
+
commentCreate(input: {issueId: $issueId, body: $body}) {
|
22
|
+
comment { id }
|
23
|
+
}
|
24
|
+
}
|
25
|
+
''',
|
26
|
+
'variables': {'issueId': issue_key, 'body': text}
|
27
|
+
}
|
28
|
+
)
|
29
|
+
return response.json()
|
30
|
+
|
31
|
+
|
32
|
+
@app.command()
|
33
|
+
def linear_comment(
|
34
|
+
text: str = typer.Argument(None),
|
35
|
+
refs: str = arg_refs(),
|
36
|
+
):
|
37
|
+
if text is None or text == "-":
|
38
|
+
# Read from stdin if no text provided
|
39
|
+
text = sys.stdin.read()
|
40
|
+
|
41
|
+
if not text or not text.strip():
|
42
|
+
typer.echo("Error: No comment text provided.", err=True)
|
43
|
+
raise typer.Exit(code=1)
|
44
|
+
|
45
|
+
api_key = os.getenv("LINEAR_API_KEY")
|
46
|
+
if not api_key:
|
47
|
+
logging.error("LINEAR_API_KEY environment variable is not set")
|
48
|
+
return
|
49
|
+
|
50
|
+
repo = Repo(".")
|
51
|
+
key = resolve_issue_key(repo)
|
52
|
+
post_linear_comment(key, text, api_key)
|
53
|
+
logging.info("Comment posted to Linear issue %s", key)
|
@@ -50,7 +50,7 @@ report_template_cli = """
|
|
50
50
|
{%- if report.summary -%}
|
51
51
|
{{- "\n" }}
|
52
52
|
{{- "\n" }}{{- Style.BRIGHT }}✨ SUMMARY {{ Style.RESET_ALL -}}
|
53
|
-
{{- "\n" }}{{- report.summary -}}
|
53
|
+
{{- "\n" }}{{- remove_html_comments(report.summary) -}}
|
54
54
|
{%- endif %}
|
55
55
|
{% for issue in report.plain_issues -%}
|
56
56
|
{{"\n"}}{{ Style.BRIGHT }}{{Back.RED}}[ {{ issue.id}} ]{{Back.RESET}} {{ issue.title -}}{{ Style.RESET_ALL -}}
|
@@ -205,14 +205,16 @@ Summarize the code review in one sentence.
|
|
205
205
|
{{ issues | tojson(indent=2) }}
|
206
206
|
---
|
207
207
|
If the code changes include exceptional achievements, you may also present an award to the author in the summary text.
|
208
|
-
|
208
|
+
- (!) Only give awards to initial codebase authors, NOT to reviewers.
|
209
|
+
- (!) If you give an award, place the hidden <!-- award --> HTML comment on its own line immediately before the award text.
|
209
210
|
--Available Awards--
|
210
211
|
{{ awards }}
|
211
212
|
---
|
212
213
|
{% if pipeline_out.associated_issue and pipeline_out.associated_issue.title %}
|
213
214
|
----SUBTASK----
|
214
215
|
Include one sentence about how the code changes address the requirements of the associated issue listed below.
|
215
|
-
|
216
|
+
- (!) Place the hidden <!-- issue_alignment --> comment on its own line immediately before the related text.
|
217
|
+
- Use ✅ or ⚠️ to indicate whether the implementation fully satisfies the issue requirements.
|
216
218
|
--Associated Issue--
|
217
219
|
# {{ pipeline_out.associated_issue.title }}
|
218
220
|
{{ pipeline_out.associated_issue.description }}
|
@@ -223,10 +225,12 @@ Examples:
|
|
223
225
|
|
224
226
|
If the implementation fully delivers the requested functionality:
|
225
227
|
```
|
228
|
+
<!-- issue_alignment -->
|
226
229
|
✅ Implementation Satisfies [<ISSUE_KEY>](<ISSUE_URL>).
|
227
230
|
```
|
228
231
|
If there are concerns about how thoroughly the code covers the requirements and technical description from the associated issue:
|
229
232
|
```
|
233
|
+
<!-- issue_alignment -->
|
230
234
|
⚠️ <Describe specific gap or concern>.
|
231
235
|
⚠️ <Describe additional limitation or missing feature>.
|
232
236
|
```
|
@@ -253,6 +257,14 @@ Answer the following user question:
|
|
253
257
|
--FILE: {{ file }}--
|
254
258
|
{{ file_lines }}
|
255
259
|
{% endfor %}
|
260
|
+
|
261
|
+
{%- if pipeline_out.associated_issue and pipeline_out.associated_issue.title %}
|
262
|
+
----ASSOCIATED ISSUE----
|
263
|
+
# {{ pipeline_out.associated_issue.title }}
|
264
|
+
{{ pipeline_out.associated_issue.description }}
|
265
|
+
URL: {{ pipeline_out.associated_issue.url }}
|
266
|
+
{%- endif -%}{{ '\n' }}
|
267
|
+
|
256
268
|
----ANSWERING INSTRUCTIONS----
|
257
269
|
{{ answering_instructions }}
|
258
270
|
"""
|
@@ -438,7 +450,9 @@ decorators add depth and texture, and observer masterfully completes the composi
|
|
438
450
|
The Gang of Four gives a standing ovation from the stalls."
|
439
451
|
```
|
440
452
|
"""
|
441
|
-
requirements = ""
|
453
|
+
requirements = """
|
454
|
+
- (!) Never report issues related to software versions, model names, or similar details that you believe have not yet been released—you cannot reliably determine this.
|
455
|
+
"""
|
442
456
|
summary_requirements = ""
|
443
457
|
answering_instructions = """
|
444
458
|
- (!) Provide a concise, direct answer in engaging speech.
|
@@ -0,0 +1,19 @@
|
|
1
|
+
from dataclasses import dataclass, field
|
2
|
+
from typing import Iterable, TYPE_CHECKING
|
3
|
+
|
4
|
+
from unidiff.patch import PatchSet, PatchedFile
|
5
|
+
from git import Repo
|
6
|
+
|
7
|
+
|
8
|
+
if TYPE_CHECKING:
|
9
|
+
from .project_config import ProjectConfig
|
10
|
+
from .report_struct import Report
|
11
|
+
|
12
|
+
|
13
|
+
@dataclass
|
14
|
+
class Context:
|
15
|
+
report: "Report"
|
16
|
+
config: "ProjectConfig"
|
17
|
+
diff: PatchSet | Iterable[PatchedFile]
|
18
|
+
repo: Repo
|
19
|
+
pipeline_out: dict = field(default_factory=dict)
|