mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-05 21:30:40 +08:00
Merge pull request #1384 from MarkRx/feature/version-metadata
Add --version command and version metadata
This commit is contained in:
@ -7,6 +7,7 @@ from litellm import acompletion
|
|||||||
from tenacity import retry, retry_if_exception_type, stop_after_attempt
|
from tenacity import retry, retry_if_exception_type, stop_after_attempt
|
||||||
|
|
||||||
from pr_agent.algo.ai_handlers.base_ai_handler import BaseAiHandler
|
from pr_agent.algo.ai_handlers.base_ai_handler import BaseAiHandler
|
||||||
|
from pr_agent.algo.utils import get_version
|
||||||
from pr_agent.config_loader import get_settings
|
from pr_agent.config_loader import get_settings
|
||||||
from pr_agent.log import get_logger
|
from pr_agent.log import get_logger
|
||||||
|
|
||||||
@ -132,7 +133,7 @@ class LiteLLMAIHandler(BaseAiHandler):
|
|||||||
if "langfuse" in callbacks:
|
if "langfuse" in callbacks:
|
||||||
metadata.update({
|
metadata.update({
|
||||||
"trace_name": command,
|
"trace_name": command,
|
||||||
"tags": [git_provider, command],
|
"tags": [git_provider, command, f'version:{get_version()}'],
|
||||||
"trace_metadata": {
|
"trace_metadata": {
|
||||||
"command": command,
|
"command": command,
|
||||||
"pr_url": pr_url,
|
"pr_url": pr_url,
|
||||||
@ -141,7 +142,7 @@ class LiteLLMAIHandler(BaseAiHandler):
|
|||||||
if "langsmith" in callbacks:
|
if "langsmith" in callbacks:
|
||||||
metadata.update({
|
metadata.update({
|
||||||
"run_name": command,
|
"run_name": command,
|
||||||
"tags": [git_provider, command],
|
"tags": [git_provider, command, f'version:{get_version()}'],
|
||||||
"extra": {
|
"extra": {
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"command": command,
|
"command": command,
|
||||||
|
@ -7,11 +7,13 @@ import html
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
import textwrap
|
import textwrap
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
from importlib.metadata import PackageNotFoundError, version
|
||||||
from typing import Any, List, Tuple
|
from typing import Any, List, Tuple
|
||||||
|
|
||||||
import html2text
|
import html2text
|
||||||
@ -1111,3 +1113,24 @@ def process_description(description_full: str) -> Tuple[str, List]:
|
|||||||
get_logger().exception(f"Failed to process description: {e}")
|
get_logger().exception(f"Failed to process description: {e}")
|
||||||
|
|
||||||
return base_description_str, files
|
return base_description_str, files
|
||||||
|
|
||||||
|
def get_version() -> str:
|
||||||
|
# First check pyproject.toml if running directly out of repository
|
||||||
|
if os.path.exists("pyproject.toml"):
|
||||||
|
if sys.version_info >= (3, 11):
|
||||||
|
import tomllib
|
||||||
|
with open("pyproject.toml", "rb") as f:
|
||||||
|
data = tomllib.load(f)
|
||||||
|
if "project" in data and "version" in data["project"]:
|
||||||
|
return data["project"]["version"]
|
||||||
|
else:
|
||||||
|
get_logger().warning("Version not found in pyproject.toml")
|
||||||
|
else:
|
||||||
|
get_logger().warning("Unable to determine local version from pyproject.toml")
|
||||||
|
|
||||||
|
# Otherwise get the installed pip package version
|
||||||
|
try:
|
||||||
|
return version('pr-agent')
|
||||||
|
except PackageNotFoundError:
|
||||||
|
get_logger().warning("Unable to find package named 'pr-agent'")
|
||||||
|
return "unknown"
|
||||||
|
@ -3,6 +3,7 @@ import asyncio
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from pr_agent.agent.pr_agent import PRAgent, commands
|
from pr_agent.agent.pr_agent import PRAgent, commands
|
||||||
|
from pr_agent.algo.utils import get_version
|
||||||
from pr_agent.config_loader import get_settings
|
from pr_agent.config_loader import get_settings
|
||||||
from pr_agent.log import get_logger, setup_logger
|
from pr_agent.log import get_logger, setup_logger
|
||||||
|
|
||||||
@ -45,6 +46,7 @@ def set_parser():
|
|||||||
To edit any configuration parameter from 'configuration.toml', just add -config_path=<value>.
|
To edit any configuration parameter from 'configuration.toml', just add -config_path=<value>.
|
||||||
For example: 'python cli.py --pr_url=... review --pr_reviewer.extra_instructions="focus on the file: ..."'
|
For example: 'python cli.py --pr_url=... review --pr_reviewer.extra_instructions="focus on the file: ..."'
|
||||||
""")
|
""")
|
||||||
|
parser.add_argument('--version', action='version', version=f'pr-agent {get_version()}')
|
||||||
parser.add_argument('--pr_url', type=str, help='The URL of the PR to review', default=None)
|
parser.add_argument('--pr_url', type=str, help='The URL of the PR to review', default=None)
|
||||||
parser.add_argument('--issue_url', type=str, help='The URL of the Issue to review', default=None)
|
parser.add_argument('--issue_url', type=str, help='The URL of the Issue to review', default=None)
|
||||||
parser.add_argument('command', type=str, help='The', choices=commands, default='review')
|
parser.add_argument('command', type=str, help='The', choices=commands, default='review')
|
||||||
|
@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "pr-agent"
|
name = "pr-agent"
|
||||||
version = "0.2.4"
|
version = "0.2.5"
|
||||||
|
|
||||||
authors = [{ name = "CodiumAI", email = "tal.r@codium.ai" }]
|
authors = [{ name = "CodiumAI", email = "tal.r@codium.ai" }]
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user