mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-05 21:30:40 +08:00
stable
This commit is contained in:
@ -2,7 +2,7 @@
|
|||||||
model="gpt-4"
|
model="gpt-4"
|
||||||
fallback-models=["gpt-3.5-turbo-16k"]
|
fallback-models=["gpt-3.5-turbo-16k"]
|
||||||
git_provider="github"
|
git_provider="github"
|
||||||
publish_output=false
|
publish_output=true
|
||||||
publish_output_progress=true
|
publish_output_progress=true
|
||||||
verbosity_level=2 # 0,1,2
|
verbosity_level=2 # 0,1,2
|
||||||
use_extra_bad_extensions=false
|
use_extra_bad_extensions=false
|
||||||
@ -25,7 +25,7 @@ publish_description_as_comment=false
|
|||||||
num_code_suggestions=4
|
num_code_suggestions=4
|
||||||
|
|
||||||
[pr_update_changelog]
|
[pr_update_changelog]
|
||||||
push_changelog_changes=false
|
push_changelog_changes=true
|
||||||
|
|
||||||
[github]
|
[github]
|
||||||
# The type of deployment to create. Valid values are 'app' or 'user'.
|
# The type of deployment to create. Valid values are 'app' or 'user'.
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
[pr_update_changelog_prompt]
|
[pr_update_changelog_prompt]
|
||||||
system="""You are a language model called CodiumAI-PR-Code-Reviewer.
|
system="""You are a language model called CodiumAI-PR-Code-Reviewer.
|
||||||
Your task is to update the CHANGELOG.md file of the project, based on the PR diff.
|
Your task is to update the CHANGELOG.md file of the project, to reflect the changes in this PR.
|
||||||
The update should be short and concise. It should match the existing CHANGELOG.md format.
|
The updated content should be short and concise as possible.
|
||||||
|
It should match the existing CHANGELOG.md format, style and conventions, so it will look like a natural part of the file.
|
||||||
|
For example, if previous changes were summarized in a single line, you should do the same.
|
||||||
|
|
||||||
Note that the output should be only the added lines to the CHANGELOG.md file, and nothing else.
|
Don't repeat previous changes. Generate content that is not already in the CHANGELOG.md file.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -21,6 +23,11 @@ The PR Diff:
|
|||||||
{{diff}}
|
{{diff}}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Current date:
|
||||||
|
```
|
||||||
|
{{today}}
|
||||||
|
```
|
||||||
|
|
||||||
The current CHANGELOG.md:
|
The current CHANGELOG.md:
|
||||||
```
|
```
|
||||||
{{changelog_file}}
|
{{changelog_file}}
|
||||||
|
@ -2,6 +2,7 @@ import copy
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import textwrap
|
import textwrap
|
||||||
|
from datetime import date
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
|
|
||||||
from jinja2 import Environment, StrictUndefined
|
from jinja2 import Environment, StrictUndefined
|
||||||
@ -13,6 +14,8 @@ from pr_agent.config_loader import settings
|
|||||||
from pr_agent.git_providers import get_git_provider, GithubProvider
|
from pr_agent.git_providers import get_git_provider, GithubProvider
|
||||||
from pr_agent.git_providers.git_provider import get_main_pr_language
|
from pr_agent.git_providers.git_provider import get_main_pr_language
|
||||||
|
|
||||||
|
CHANGELOG_LINES = 50
|
||||||
|
|
||||||
|
|
||||||
class PRUpdateChangelog:
|
class PRUpdateChangelog:
|
||||||
def __init__(self, pr_url: str, cli_mode=False):
|
def __init__(self, pr_url: str, cli_mode=False):
|
||||||
@ -21,15 +24,18 @@ class PRUpdateChangelog:
|
|||||||
self.main_language = get_main_pr_language(
|
self.main_language = get_main_pr_language(
|
||||||
self.git_provider.get_languages(), self.git_provider.get_files()
|
self.git_provider.get_languages(), self.git_provider.get_files()
|
||||||
)
|
)
|
||||||
max_lines=50
|
|
||||||
try:
|
try:
|
||||||
self.changelog_file = self.git_provider.repo_obj.get_contents("CHANGELOG.md", ref=self.git_provider.get_pr_branch())
|
self.changelog_file = self.git_provider.repo_obj.get_contents("CHANGELOG.md",
|
||||||
|
ref=self.git_provider.get_pr_branch())
|
||||||
changelog_file_lines = self.changelog_file.decoded_content.decode().splitlines()
|
changelog_file_lines = self.changelog_file.decoded_content.decode().splitlines()
|
||||||
changelog_file_lines = changelog_file_lines[:max_lines]
|
changelog_file_lines = changelog_file_lines[:CHANGELOG_LINES]
|
||||||
self.changelog_file_str = "\n".join(changelog_file_lines)
|
self.changelog_file_str = "\n".join(changelog_file_lines)
|
||||||
except:
|
except:
|
||||||
raise Exception("No CHANGELOG.md file found in the repository")
|
raise Exception("No CHANGELOG.md file found in the repository")
|
||||||
|
|
||||||
|
today = date.today()
|
||||||
|
print("Today's date:", today)
|
||||||
|
|
||||||
self.ai_handler = AiHandler()
|
self.ai_handler = AiHandler()
|
||||||
self.patches_diff = None
|
self.patches_diff = None
|
||||||
self.prediction = None
|
self.prediction = None
|
||||||
@ -41,6 +47,7 @@ class PRUpdateChangelog:
|
|||||||
"language": self.main_language,
|
"language": self.main_language,
|
||||||
"diff": "", # empty diff for initial calculation
|
"diff": "", # empty diff for initial calculation
|
||||||
"changelog_file": self.changelog_file_str,
|
"changelog_file": self.changelog_file_str,
|
||||||
|
"today": today,
|
||||||
}
|
}
|
||||||
self.token_handler = TokenHandler(self.git_provider.pr,
|
self.token_handler = TokenHandler(self.git_provider.pr,
|
||||||
self.vars,
|
self.vars,
|
||||||
@ -56,11 +63,11 @@ class PRUpdateChangelog:
|
|||||||
await retry_with_fallback_models(self._prepare_prediction)
|
await retry_with_fallback_models(self._prepare_prediction)
|
||||||
logging.info('Preparing PR changelog updates...')
|
logging.info('Preparing PR changelog updates...')
|
||||||
new_file_content, answer = self._prepare_changelog_update()
|
new_file_content, answer = self._prepare_changelog_update()
|
||||||
if settings.config.publish_output or True:
|
if settings.config.publish_output:
|
||||||
self.git_provider.remove_initial_comment()
|
self.git_provider.remove_initial_comment()
|
||||||
logging.info('publishing changelog updates...')
|
logging.info('publishing changelog updates...')
|
||||||
self.git_provider.publish_comment(f"**Changelog updates:**\n\n{answer}")
|
self.git_provider.publish_comment(f"**Changelog updates:**\n\n{answer}")
|
||||||
if settings.pr_update_changelog_prompt.push_changelog_changes:
|
if settings.pr_update_changelog.push_changelog_changes:
|
||||||
logging.info('Pushing PR changelog updates...')
|
logging.info('Pushing PR changelog updates...')
|
||||||
self.push_changelog_update(new_file_content)
|
self.push_changelog_update(new_file_content)
|
||||||
|
|
||||||
@ -89,10 +96,11 @@ class PRUpdateChangelog:
|
|||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def _prepare_changelog_update(self) -> Tuple[str,str]:
|
def _prepare_changelog_update(self) -> Tuple[str, str]:
|
||||||
answer = self.prediction.strip().strip("```").strip()
|
answer = self.prediction.strip().strip("```").strip()
|
||||||
new_file_content = answer.strip().strip("```").strip() + "\n\n" + self.changelog_file.decoded_content.decode()
|
new_file_content = answer + "\n\n" + self.changelog_file.decoded_content.decode()
|
||||||
|
if settings.config.verbosity_level >= 2:
|
||||||
|
logging.info(f"answer:\n{answer}")
|
||||||
return new_file_content, answer
|
return new_file_content, answer
|
||||||
|
|
||||||
def push_changelog_update(self, new_file_content):
|
def push_changelog_update(self, new_file_content):
|
||||||
|
Reference in New Issue
Block a user