remove /commit, use github|gitlab.commit replace it
This commit is contained in:
parent
389ad70c2e
commit
bb0ed153c7
@ -1,30 +0,0 @@
|
||||
# Commit 命令
|
||||
|
||||
该命令用于为选中的代码更改编写格式良好的提交信息,并通过Git提交这些更改。
|
||||
|
||||
## 用法
|
||||
/commit [to close #issue_number]
|
||||
|
||||
|
||||
## 说明
|
||||
|
||||
- 该命令会引导你完成以下步骤:
|
||||
|
||||
1. 选择要包含在本次提交中的修改文件
|
||||
2. 查看并编辑AI生成的提交信息
|
||||
3. 确认并执行Git提交
|
||||
|
||||
- 你可以选择性地在命令中包含要关闭的issue编号,例如:
|
||||
|
||||
/commit to close #12
|
||||
|
||||
|
||||
- 如果不指定issue编号,命令仍会正常执行,只是不会在提交信息中包含关闭issue的引用。
|
||||
|
||||
- 该命令会调用Git来执行实际的提交操作,因此请确保你的系统中已正确安装并配置了Git。
|
||||
|
||||
## 提示
|
||||
|
||||
- 在执行该命令之前,请确保你已经对要提交的文件进行了必要的修改。
|
||||
- 仔细检查AI生成的提交信息,并根据需要进行编辑,以确保信息准确反映了你的更改。
|
||||
- 养成经常小批量提交的好习惯,这有助于更好地跟踪项目历史。
|
@ -1,6 +0,0 @@
|
||||
description: 'Writes a well-formatted commit message for selected code changes and commits them via Git. Include an issue number if desired (e.g., input "/commit to close #12").'
|
||||
hint: to close Issue #issue_number
|
||||
input: optional
|
||||
help: README.md
|
||||
steps:
|
||||
- run: $devchat_python $command_path/commit.py "$input"
|
@ -1,436 +0,0 @@
|
||||
# flake8: noqa: E402
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
# from llm_api import chat_completion_stream # noqa: E402
|
||||
from devchat.llm import chat_completion_stream
|
||||
|
||||
from lib.chatmark import Checkbox, Form, TextEditor
|
||||
from lib.ide_service import IDEService
|
||||
|
||||
diff_too_large_message_en = (
|
||||
"Commit failed. The modified content is too long "
|
||||
"and exceeds the model's length limit. "
|
||||
"You can try to make partial changes to the file and submit multiple times. "
|
||||
"Making small changes and submitting them multiple times is a better practice."
|
||||
)
|
||||
diff_too_large_message_zh = (
|
||||
"提交失败。修改内容太长,超出模型限制长度,"
|
||||
"可以尝试选择部分修改文件多次提交,小修改多提交是更好的做法。"
|
||||
)
|
||||
|
||||
COMMIT_PROMPT_LIMIT_SIZE = 20000
|
||||
|
||||
|
||||
def _T(en_text, zh_text):
|
||||
"""
|
||||
Returns a text in the current language.
|
||||
:param en_text: The English version of the text
|
||||
:param zh_text: The Chinese version of the text
|
||||
:return: The text in the current language
|
||||
"""
|
||||
if IDEService().ide_language() == "zh":
|
||||
return zh_text
|
||||
else:
|
||||
return en_text
|
||||
|
||||
|
||||
def extract_markdown_block(text):
|
||||
"""
|
||||
Extracts the first Markdown code block from the given text without the language specifier.
|
||||
|
||||
:param text: A string containing Markdown text
|
||||
:return: The content of the first Markdown code block, or None if not found
|
||||
"""
|
||||
# 正则表达式匹配Markdown代码块,忽略可选的语言类型标记
|
||||
pattern = r"```(?:\w+)?\s*\n(.*?)\n```"
|
||||
match = re.search(pattern, text, re.DOTALL)
|
||||
|
||||
if match:
|
||||
# 返回第一个匹配的代码块内容,去除首尾的反引号和语言类型标记
|
||||
# 去除块结束标记前的一个换行符,但保留其他内容
|
||||
block_content = match.group(1)
|
||||
return block_content
|
||||
else:
|
||||
return text
|
||||
|
||||
|
||||
# Read the prompt from the diffCommitMessagePrompt.txt file
|
||||
def read_prompt_from_file(filename):
|
||||
"""
|
||||
Reads the content of a file and returns it as a string.
|
||||
|
||||
This function is designed to read a prompt message from a text file.
|
||||
It expects the file to be encoded in UTF-8 and will strip any leading
|
||||
or trailing whitespace from the content of the file. If the file does
|
||||
not exist or an error occurs during reading, the function logs an error
|
||||
message and exits the script.
|
||||
|
||||
Parameters:
|
||||
- filename (str): The path to the file that contains the prompt message.
|
||||
|
||||
Returns:
|
||||
- str: The content of the file as a string.
|
||||
|
||||
Raises:
|
||||
- FileNotFoundError: If the file does not exist.
|
||||
- Exception: If any other error occurs during file reading.
|
||||
"""
|
||||
s = IDEService()
|
||||
try:
|
||||
with open(filename, "r", encoding="utf-8") as file:
|
||||
return file.read().strip()
|
||||
except FileNotFoundError:
|
||||
s.ide_logging(
|
||||
"info",
|
||||
f"File {filename} not found. "
|
||||
"Please make sure it exists in the same directory as the script.",
|
||||
)
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
s.ide_logging("info", f"An error occurred while reading the file {filename}: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
# Read the prompt content from the file
|
||||
script_path = os.path.dirname(__file__)
|
||||
PROMPT_FILENAME = os.path.join(script_path, "diffCommitMessagePrompt.txt")
|
||||
PROMPT_COMMIT_MESSAGE_BY_DIFF_USER_INPUT = read_prompt_from_file(PROMPT_FILENAME)
|
||||
prompt_commit_message_by_diff_user_input_llm_config = {
|
||||
"model": os.environ.get("LLM_MODEL", "gpt-3.5-turbo-1106")
|
||||
}
|
||||
|
||||
|
||||
language = ""
|
||||
|
||||
|
||||
def assert_value(value, message):
|
||||
"""
|
||||
判断给定的value是否为True,如果是,则输出指定的message并终止程序。
|
||||
|
||||
Args:
|
||||
value: 用于判断的值。
|
||||
message: 如果value为True时需要输出的信息。
|
||||
|
||||
Returns:
|
||||
无返回值。
|
||||
|
||||
"""
|
||||
if value:
|
||||
print(message, file=sys.stderr, flush=True)
|
||||
sys.exit(-1)
|
||||
|
||||
|
||||
def decode_path(encoded_path):
|
||||
octal_pattern = re.compile(r"\\[0-7]{3}")
|
||||
|
||||
if octal_pattern.search(encoded_path):
|
||||
bytes_path = encoded_path.encode("utf-8").decode("unicode_escape").encode("latin1")
|
||||
decoded_path = bytes_path.decode("utf-8")
|
||||
return decoded_path
|
||||
else:
|
||||
return encoded_path
|
||||
|
||||
|
||||
def get_modified_files():
|
||||
"""
|
||||
获取当前修改文件列表以及已经staged的文件列表
|
||||
|
||||
Args:
|
||||
无
|
||||
|
||||
Returns:
|
||||
tuple: 包含两个list的元组,第一个list包含当前修改过的文件,第二个list包含已经staged的文件
|
||||
"""
|
||||
""" 获取当前修改文件列表以及已经staged的文件列表"""
|
||||
output = subprocess.check_output(["git", "status", "-s", "-u"], text=True, encoding="utf-8")
|
||||
lines = output.split("\n")
|
||||
modified_files = []
|
||||
staged_files = []
|
||||
|
||||
def strip_file_name(file_name):
|
||||
file = file_name.strip()
|
||||
if file.startswith('"'):
|
||||
file = file[1:-1]
|
||||
return file
|
||||
|
||||
for line in lines:
|
||||
if len(line) > 2:
|
||||
status, filename = line[:2], decode_path(line[3:])
|
||||
# check wether filename is a directory
|
||||
if os.path.isdir(filename):
|
||||
continue
|
||||
modified_files.append((os.path.normpath(strip_file_name(filename)), status[1:2]))
|
||||
if status[0:1] == "M" or status[0:1] == "A" or status[0:1] == "D":
|
||||
staged_files.append((os.path.normpath(strip_file_name(filename)), status[0:1]))
|
||||
return modified_files, staged_files
|
||||
|
||||
|
||||
def get_marked_files(modified_files, staged_files):
|
||||
"""
|
||||
根据给定的参数获取用户选中以供提交的文件
|
||||
|
||||
Args:
|
||||
modified_files (List[str]): 用户已修改文件列表
|
||||
staged_files (List[str]): 用户已staged文件列表
|
||||
|
||||
Returns:
|
||||
List[str]: 用户选中的文件列表
|
||||
"""
|
||||
# Create two Checkbox instances for staged and unstaged files
|
||||
staged_files_show = [f'{file[1] if file[1]!="?" else "U"} {file[0]}' for file in staged_files]
|
||||
staged_checkbox = Checkbox(staged_files_show, [True] * len(staged_files_show))
|
||||
|
||||
unstaged_files = [file for file in modified_files if file[1].strip() != ""]
|
||||
unstaged_files_show = [
|
||||
f'{file[1] if file[1]!="?" else "U"} {file[0]}' for file in unstaged_files
|
||||
]
|
||||
unstaged_checkbox = Checkbox(unstaged_files_show, [False] * len(unstaged_files_show))
|
||||
|
||||
# Create a Form with both Checkbox instances
|
||||
form_list = []
|
||||
if len(staged_files) > 0:
|
||||
form_list.append("Staged:\n\n")
|
||||
form_list.append(staged_checkbox)
|
||||
|
||||
if len(unstaged_files) > 0:
|
||||
form_list.append("Unstaged:\n\n")
|
||||
form_list.append(unstaged_checkbox)
|
||||
|
||||
form = Form(form_list, submit_button_name="Continue")
|
||||
|
||||
# Render the Form and get user input
|
||||
form.render()
|
||||
|
||||
# Retrieve the selected files from both Checkbox instances
|
||||
staged_checkbox_selections = staged_checkbox.selections if staged_checkbox.selections else []
|
||||
unstaged_selections = unstaged_checkbox.selections if unstaged_checkbox.selections else []
|
||||
selected_staged_files = [staged_files[idx][0] for idx in staged_checkbox_selections]
|
||||
selected_unstaged_files = [unstaged_files[idx][0] for idx in unstaged_selections]
|
||||
|
||||
return selected_staged_files, selected_unstaged_files
|
||||
|
||||
|
||||
def rebuild_stage_list(staged_select_files, unstaged_select_files):
|
||||
"""
|
||||
根据用户选中文件,重新构建stage列表
|
||||
|
||||
Args:
|
||||
staged_select_files: 当前选中的已staged文件列表
|
||||
unstaged_select_files: 当前选中的未staged文件列表
|
||||
|
||||
Returns:
|
||||
None
|
||||
"""
|
||||
# 获取当前所有staged文件
|
||||
current_staged_files = subprocess.check_output(
|
||||
["git", "diff", "--name-only", "--cached"], text=True
|
||||
).splitlines()
|
||||
|
||||
# 添加unstaged_select_files中的文件到staged
|
||||
for file in unstaged_select_files:
|
||||
subprocess.check_output(["git", "add", file])
|
||||
|
||||
# 将不在staged_select_files中的文件从staged移除
|
||||
user_selected_files = staged_select_files + unstaged_select_files
|
||||
files_to_unstage = [file for file in current_staged_files if file not in user_selected_files]
|
||||
for file in files_to_unstage:
|
||||
subprocess.check_output(["git", "reset", file])
|
||||
|
||||
|
||||
def get_diff():
|
||||
"""
|
||||
获取暂存区文件的Diff信息
|
||||
|
||||
Args:
|
||||
无
|
||||
|
||||
Returns:
|
||||
bytes: 返回bytes类型,是git diff --cached命令的输出结果
|
||||
|
||||
"""
|
||||
return subprocess.check_output(["git", "diff", "--cached"])
|
||||
|
||||
|
||||
def get_current_branch():
|
||||
try:
|
||||
# 使用git命令获取当前分支名称
|
||||
result = subprocess.check_output(
|
||||
["git", "branch", "--show-current"], stderr=subprocess.STDOUT
|
||||
).strip()
|
||||
# 将结果从bytes转换为str
|
||||
current_branch = result.decode("utf-8")
|
||||
return current_branch
|
||||
except subprocess.CalledProcessError:
|
||||
# 如果发生错误,打印错误信息
|
||||
return None
|
||||
except FileNotFoundError:
|
||||
# 如果未找到git命令,可能是没有安装git或者不在PATH中
|
||||
return None
|
||||
|
||||
|
||||
def generate_commit_message_base_diff(user_input, diff):
|
||||
"""
|
||||
根据diff信息,通过AI生成一个commit消息
|
||||
|
||||
Args:
|
||||
user_input (str): 用户输入的commit信息
|
||||
diff (str): 提交的diff信息
|
||||
|
||||
Returns:
|
||||
str: 生成的commit消息
|
||||
|
||||
"""
|
||||
global language
|
||||
language_prompt = "You must response commit message in chinese。\n" if language == "zh" else ""
|
||||
prompt = PROMPT_COMMIT_MESSAGE_BY_DIFF_USER_INPUT.replace("{__DIFF__}", f"{diff}").replace(
|
||||
"{__USER_INPUT__}", f"{user_input + language_prompt}"
|
||||
)
|
||||
|
||||
model_token_limit_error = (
|
||||
diff_too_large_message_en if language == "en" else diff_too_large_message_zh
|
||||
)
|
||||
if len(str(prompt)) > COMMIT_PROMPT_LIMIT_SIZE:
|
||||
print(model_token_limit_error, flush=True)
|
||||
sys.exit(0)
|
||||
|
||||
messages = [{"role": "user", "content": prompt}]
|
||||
response = chat_completion_stream(messages, prompt_commit_message_by_diff_user_input_llm_config)
|
||||
|
||||
if (
|
||||
not response["content"]
|
||||
and response.get("error", None)
|
||||
and f'{response["error"]}'.find("This model's maximum context length is") > 0
|
||||
):
|
||||
print(model_token_limit_error)
|
||||
sys.exit(0)
|
||||
|
||||
assert_value(not response["content"], response.get("error", ""))
|
||||
response["content"] = extract_markdown_block(response["content"])
|
||||
return response
|
||||
|
||||
|
||||
def display_commit_message_and_commit(commit_message):
|
||||
"""
|
||||
展示提交信息并提交。
|
||||
|
||||
Args:
|
||||
commit_message: 提交信息。
|
||||
|
||||
Returns:
|
||||
None。
|
||||
|
||||
"""
|
||||
text_editor = TextEditor(commit_message, submit_button_name="Commit")
|
||||
text_editor.render()
|
||||
|
||||
new_commit_message = text_editor.new_text
|
||||
if not new_commit_message:
|
||||
return None
|
||||
return subprocess.check_output(["git", "commit", "-m", new_commit_message])
|
||||
|
||||
|
||||
def check_git_installed():
|
||||
try:
|
||||
subprocess.run(
|
||||
["git", "--version"],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True,
|
||||
check=True,
|
||||
)
|
||||
return True
|
||||
except subprocess.CalledProcessError:
|
||||
print("Git is not installed on your system.", file=sys.stderr, flush=True)
|
||||
except FileNotFoundError:
|
||||
print("Git is not installed on your system.", file=sys.stderr, flush=True)
|
||||
except Exception:
|
||||
print("Git is not installed on your system.", file=sys.stderr, flush=True)
|
||||
return False
|
||||
|
||||
|
||||
def main():
|
||||
global language
|
||||
try:
|
||||
start_msg = _T("Let's follow the steps below.\n\n", "开始按步骤操作。\n\n")
|
||||
print(start_msg)
|
||||
# Ensure enough command line arguments are provided
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: python script.py <user_input>", file=sys.stderr, flush=True)
|
||||
sys.exit(-1)
|
||||
|
||||
user_input = sys.argv[1]
|
||||
language = IDEService().ide_language()
|
||||
|
||||
if not check_git_installed():
|
||||
sys.exit(-1)
|
||||
|
||||
step1_msg = _T(
|
||||
"Step 1/2: Select the files you've changed that you wish to include in this commit, "
|
||||
"then click 'Submit'.",
|
||||
"第一步/2:选择您希望包含在这次提交中的文件,然后点击“提交”。",
|
||||
)
|
||||
print(step1_msg, end="\n\n", flush=True)
|
||||
modified_files, staged_files = get_modified_files()
|
||||
if len(modified_files) == 0:
|
||||
print("There are no files to commit.", flush=True)
|
||||
sys.exit(0)
|
||||
|
||||
staged_select_files, unstaged_select_files = get_marked_files(modified_files, staged_files)
|
||||
if not staged_select_files and not unstaged_select_files:
|
||||
no_files_msg = _T(
|
||||
"No files selected, the commit has been aborted.",
|
||||
"没有选择任何文件,提交已中止。",
|
||||
)
|
||||
print(no_files_msg)
|
||||
return
|
||||
|
||||
rebuild_stage_list(staged_select_files, unstaged_select_files)
|
||||
|
||||
step2_msg = _T(
|
||||
"Step 2/2: Review the commit message I've drafted for you. "
|
||||
"Edit it below if needed. Then click 'Commit' to proceed with "
|
||||
"the commit using this message.",
|
||||
"第二步/2:查看我为您起草的提交消息。如果需要,请在下面编辑它。然后单击“提交”以使用此消息进行提交。",
|
||||
)
|
||||
print(step2_msg, end="\n\n", flush=True)
|
||||
diff = get_diff()
|
||||
branch_name = get_current_branch()
|
||||
if branch_name:
|
||||
user_input += "\ncurrent repo branch name is:" + branch_name
|
||||
commit_message = generate_commit_message_base_diff(user_input, diff)
|
||||
if not commit_message:
|
||||
sys.exit(1)
|
||||
|
||||
# TODO
|
||||
# remove Closes #IssueNumber in commit message
|
||||
commit_message["content"] = (
|
||||
commit_message["content"]
|
||||
.replace("Closes #IssueNumber", "")
|
||||
.replace("No specific issue to close", "")
|
||||
.replace("No specific issue mentioned.", "")
|
||||
)
|
||||
|
||||
commit_result = display_commit_message_and_commit(commit_message["content"])
|
||||
if not commit_result:
|
||||
commit_abort_msg = _T(
|
||||
"Commit aborted.",
|
||||
"提交已中止。",
|
||||
)
|
||||
print(commit_abort_msg, flush=True)
|
||||
else:
|
||||
commit_completed_msg = _T(
|
||||
"Commit completed.",
|
||||
"提交已完成。",
|
||||
)
|
||||
print(commit_completed_msg, flush=True)
|
||||
sys.exit(0)
|
||||
except Exception as err:
|
||||
print("Exception:", err, file=sys.stderr, flush=True)
|
||||
sys.exit(-1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
@ -1,37 +0,0 @@
|
||||
Objective:** Generate a commit message that succinctly describes the codebase changes reflected in the provided diff, while incorporating any extra context or guidance from the user.
|
||||
|
||||
**Commit Message Structure:**
|
||||
1. **Title Line:** Choose a type such as `feat`, `fix`, `docs`, `style`, `refactor`, `perf`, `test`, `build`, `ci`, `chore`, and so on, and couple it with a succinct title. Use the format: `type: Title`. Only one title line is permissible.
|
||||
2. **Summary:** Summarize all adjustments concisely within a maximum of three detailed message lines. Prefix each line with a \"-\".
|
||||
3. **Closing Reference (Conditional):** Include the line `Closes #IssueNumber` only if a specific, relevant issue number has been mentioned in the user input.
|
||||
|
||||
**Response Format:**
|
||||
```
|
||||
type: Title
|
||||
|
||||
- Detail message line 1
|
||||
- Detail message line 2
|
||||
- Detail message line 3
|
||||
|
||||
Closes #IssueNumber
|
||||
```
|
||||
Only append the \"Closes #IssueNumber\" if the user input explicitly references an issue to close.
|
||||
|
||||
**Constraints:**
|
||||
- Exclude markdown code block indicators (```) and the placeholder \"commit_message\" from your response.
|
||||
- Follow commit message best practices:
|
||||
- Limit the title length to 50 characters.
|
||||
- Limit each summary line to 72 characters.
|
||||
- If the precise issue number is not known or not stated by the user, do not include the closing reference.
|
||||
|
||||
**User Input:** `{__USER_INPUT__}`
|
||||
|
||||
Determine if `{__USER_INPUT__}` contains a reference to closing an issue. If so, include the closing reference in the commit message. Otherwise, exclude it.
|
||||
|
||||
**Code Changes:**
|
||||
```
|
||||
{__DIFF__}
|
||||
```
|
||||
|
||||
Utilize the provided format to craft a commit message that adheres to the stipulated criteria.
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,9 +0,0 @@
|
||||
prompts:
|
||||
[
|
||||
'../../diffCommitMessagePrompt.txt'
|
||||
]
|
||||
providers:
|
||||
- id: "exec:python commit_message_run.py"
|
||||
tests:
|
||||
- commit_message_tests.yaml
|
||||
|
@ -1,86 +0,0 @@
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
import requests
|
||||
from devchat.llm import chat_completion_stream
|
||||
|
||||
|
||||
def get_script_path():
|
||||
"""Return the directory path of the current script."""
|
||||
return os.path.dirname(__file__)
|
||||
|
||||
|
||||
def load_commit_cache():
|
||||
"""Load or initialize the commit cache."""
|
||||
try:
|
||||
cache_filepath = os.path.join(get_script_path(), "commit_cache.json")
|
||||
if not os.path.exists(cache_filepath):
|
||||
return {}
|
||||
with open(cache_filepath, "r", encoding="utf-8") as cache_file:
|
||||
return json.load(cache_file)
|
||||
except (FileNotFoundError, json.JSONDecodeError):
|
||||
return None
|
||||
|
||||
|
||||
def save_commit_cache(commit_cache):
|
||||
"""Save the commit cache to a JSON file."""
|
||||
try:
|
||||
cache_filepath = os.path.join(get_script_path(), "commit_cache.json")
|
||||
with open(cache_filepath, "w", encoding="utf-8") as cache_file:
|
||||
json.dump(commit_cache, cache_file)
|
||||
except IOError as e:
|
||||
print(f"Error saving commit cache: {e}")
|
||||
|
||||
|
||||
def get_commit_diff(url, commit_cache):
|
||||
"""Extract commit diff from the given URL."""
|
||||
parts = url.split("/")
|
||||
user = parts[3]
|
||||
repo = parts[4]
|
||||
commit_hash = parts[6]
|
||||
|
||||
api_url = f"https://api.github.com/repos/{user}/{repo}/commits/{commit_hash}"
|
||||
|
||||
for _1 in range(5):
|
||||
try:
|
||||
if commit_hash in commit_cache and "diff" in commit_cache[commit_hash]:
|
||||
return commit_cache[commit_hash]["diff"]
|
||||
response = requests.get(
|
||||
api_url,
|
||||
headers={"Accept": "application/vnd.github.v3.diff"},
|
||||
timeout=20,
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
if commit_hash not in commit_cache:
|
||||
commit_cache[commit_hash] = {}
|
||||
commit_cache[commit_hash]["diff"] = response.text
|
||||
return response.text
|
||||
except Exception:
|
||||
continue
|
||||
raise Exception("Error: Unable to fetch the commit diff.")
|
||||
|
||||
|
||||
def get_commit_messages():
|
||||
"""Compose commit messages based on the provided commit URL."""
|
||||
commit_cache = load_commit_cache()
|
||||
if commit_cache is None:
|
||||
sys.exit(-1)
|
||||
prompt = sys.argv[1]
|
||||
context = json.loads(sys.argv[3])
|
||||
commit_url = context["vars"]["commit_url"]
|
||||
|
||||
diff = get_commit_diff(commit_url, commit_cache)
|
||||
save_commit_cache(commit_cache)
|
||||
|
||||
prompt = prompt.replace("{__USER_INPUT__}", "").replace("{__DIFF__}", diff)
|
||||
|
||||
messages = [{"role": "user", "content": prompt}]
|
||||
response = chat_completion_stream(messages, {"model": "gpt-4-1106-preview"})
|
||||
|
||||
print(response.get("content", "")) if response.get("content", "") else print(response)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
get_commit_messages()
|
@ -1,126 +0,0 @@
|
||||
- vars:
|
||||
commit_message: The commit fixes a use-after-free error in the AFS volume tree
|
||||
due to a race condition between volume lookup and removal. The patch prevents
|
||||
looking up volumes with zero reference count and ensures that once a volume's
|
||||
refcount reaches zero, it is flagged and not looked up again. This resolves
|
||||
crashes and warnings caused by the race.
|
||||
commit_url: https://github.com/torvalds/linux/commit/9a6b294ab496650e9f270123730df37030911b55
|
||||
- vars:
|
||||
commit_message: Fix implemented in IDA to prevent crashes during `ida_free` when
|
||||
the bitmap is empty, addressing overlooked double-free detection for NULL bitmaps.
|
||||
New tests added, albeit with noisy output, to avoid future regressions. Reported
|
||||
by Zhenghan Wang and signed by Matthew Wilcox and Linus Torvalds.
|
||||
commit_url: https://github.com/torvalds/linux/commit/af73483f4e8b6f5c68c9aa63257bdd929a9c194a
|
||||
- vars:
|
||||
commit_message: This update allows DNS-related keys to be immediately reclaimed
|
||||
upon expiry without delay, facilitating faster DNS lookups. Previously, expired
|
||||
keys had a default 5-minute buffer period. Now, DNS keys expire instantly and
|
||||
negative DNS results have a 1-second default expiry if not otherwise specified.
|
||||
commit_url: https://github.com/torvalds/linux/commit/39299bdd2546688d92ed9db4948f6219ca1b9542
|
||||
- vars:
|
||||
commit_message: The commit updates the names of constants for USB PIDs in the
|
||||
ftdi_sio driver to match the new products assigned to those IDs, ensuring accuracy
|
||||
in the identification of Actisense products.
|
||||
commit_url: https://github.com/torvalds/linux/commit/513d88a88e0203188a38f4647dd08170aebd85df
|
||||
- vars:
|
||||
commit_message: The IPv6 network code is reverting a previous change due to race
|
||||
conditions and use-after-free errors related to managing expired routes. The
|
||||
problematic commit aimed to handle expired routes with a separate list but introduced
|
||||
issues. It will be revisited in a future release. Fixes and reviews are noted.
|
||||
commit_url: https://github.com/torvalds/linux/commit/dade3f6a1e4e35a5ae916d5e78b3229ec34c78ec
|
||||
- vars:
|
||||
commit_message: Confirmed successful generation of events2table.c.
|
||||
commit_url: https://github.com/ruby/ruby/commit/7016ab873eaa68d1dfe1af50198c157e451c784b
|
||||
- vars:
|
||||
commit_message: Introduced a new `errno_ptr` property to the Universal Parser
|
||||
to facilitate error tracking, allowing the parser to communicate and store error
|
||||
codes more efficiently during parsing operations.
|
||||
commit_url: https://github.com/ruby/ruby/commit/4374236e959c1e585611acfc7a2e3d2142265ab0
|
||||
- vars:
|
||||
commit_message: The commit introduces an `ary_modify` property to the Universal
|
||||
Parser, enabling flexible array modifications during data parsing.
|
||||
commit_url: https://github.com/ruby/ruby/commit/73fa3224975c42e1c4e2231212a64ac325054130
|
||||
- vars:
|
||||
commit_message: 'Fixed the ARCH_FLAG issue to enable correct cross-compilation
|
||||
as mandated by bug report #20088.'
|
||||
commit_url: https://github.com/ruby/ruby/commit/2a4a84664a1972c48c4365c29e73be83f8004139
|
||||
- vars:
|
||||
commit_message: Added basic documentation for constants in the Ruby 'etc' library,
|
||||
enhancing code understandability and usability by providing information on their
|
||||
purpose and usage.
|
||||
commit_url: https://github.com/ruby/ruby/commit/c027dcfde2bf40c45dfb0fe1b79f97b8827d89f3
|
||||
- vars:
|
||||
commit_message: "Implemented automatic import feature for the `imports` field\
|
||||
\ in `package.json`, enhancing the module resolution process for projects, with\
|
||||
\ contributions from Mateusz Burzy\u0144ski and Andrew Branch."
|
||||
commit_url: https://github.com/microsoft/TypeScript/commit/fbcdb8cf4fbbbea0111a9adeb9d0d2983c088b7c
|
||||
- vars:
|
||||
commit_message: 'Implemented checks to ensure enums are consistent across different
|
||||
versions to maintain compatibility in project issue #55924.'
|
||||
commit_url: https://github.com/microsoft/TypeScript/commit/93e6b9da0c4cb164ca90a5a1b07415e81e97f2b1
|
||||
- vars:
|
||||
commit_message: This commit provides type suggestions for `@types/bun` when the
|
||||
`Bun` global is not detected, aiding in proper type hinting and code completion.
|
||||
(#56795)
|
||||
commit_url: https://github.com/microsoft/TypeScript/commit/0e5927d5d38399bac1818ad4160f2ff91c33c174
|
||||
- vars:
|
||||
commit_message: Added functionality to support the 'const' modifier on type parameters
|
||||
within JSDoc, enhancing TypeScript compatibility and type-checking features.
|
||||
(#56649)
|
||||
commit_url: https://github.com/microsoft/TypeScript/commit/a36d04fc63c83b6ec5a8099942b653a5caa29eb1
|
||||
- vars:
|
||||
commit_message: 'Corrected a formatting issue where a space was missing after
|
||||
the ''implements'' or ''extends'' keywords when followed by generics in typescript
|
||||
files, resolving issue #56699.'
|
||||
commit_url: https://github.com/microsoft/TypeScript/commit/2c134db31df48ba5f158f490168dea733a11ae44
|
||||
- vars:
|
||||
commit_message: The commit updates the configuration to ensure that functions
|
||||
major(), makedev(), and minor() are enabled on HP-UX systems, by enforcing the
|
||||
inclusion order of <sys/types.h> before <sys/sysmacros.h>. Co-authored by Serhiy
|
||||
Storchaka.
|
||||
commit_url: https://github.com/python/cpython/commit/f108468970bf4e70910862476900f924fb701399
|
||||
- vars:
|
||||
commit_message: Fixed the `--with-openssl-rpath` option for macOS to correctly
|
||||
use the platform-specific `-rpath` linker flag, resolving compatibility issues
|
||||
on that OS. (#113441)
|
||||
commit_url: https://github.com/python/cpython/commit/cc13eabc7ce08accf49656e258ba500f74a1dae8
|
||||
- vars:
|
||||
commit_message: The commit deprecates the `_enablelegacywindowsfsencoding` method
|
||||
(#107729) which is tracked in issue gh-73427.
|
||||
commit_url: https://github.com/python/cpython/commit/bfee2f77e16f01a718c1044564ee624f1f2bc328
|
||||
- vars:
|
||||
commit_message: 'Moved the `cpp.py` script to the `libclinic` directory for better
|
||||
organization as part of Pull Request #113526, which addresses issue gh-113299.'
|
||||
commit_url: https://github.com/python/cpython/commit/7ab9efdd6a2fb21cddca1ccd70175f1ac6bd9168
|
||||
- vars:
|
||||
commit_message: Refactored error handling in Argument Clinic's C preprocessor
|
||||
helper by creating a subclass of ClinicError for improved exception management,
|
||||
and relocated ClinicError into a separate errors module, streamlining preparations
|
||||
to integrate cpp.py into libclinic.
|
||||
commit_url: https://github.com/python/cpython/commit/87295b4068762f9cbdfcae5fed5ff54aadd3cb62
|
||||
- vars:
|
||||
commit_message: 'Updated the ''lib/time'' package to the 2023d version. This update
|
||||
was part of addressing issue #22487 and included a code review process with
|
||||
multiple reviewers before auto-submission.'
|
||||
commit_url: https://github.com/golang/go/commit/36a2463e7c01151b05fff9a1f1c6fb08d764c82e
|
||||
- vars:
|
||||
commit_message: 'This commit fixes issue #64826 by ensuring the Go compiler correctly
|
||||
handles the constant-folding of jump table indices that are out of range, even
|
||||
for statically unreachable code.'
|
||||
commit_url: https://github.com/golang/go/commit/f6509cf5cdbb5787061b784973782933c47f1782
|
||||
- vars:
|
||||
commit_message: 'The `go mod init` command no longer imports configurations from
|
||||
other vendoring tools as of Go 1.22, with the change documented and support
|
||||
removed. This addresses issues #61422 and fixes #53327.'
|
||||
commit_url: https://github.com/golang/go/commit/9dd1cde9ac0f1e935ed44d33f6b4668be538c1ed
|
||||
- vars:
|
||||
commit_message: 'The commit reverts a change in the ''go'' command that tried
|
||||
to improve flag parsing for ''go run'' and ''go install''. It reintroduces Go
|
||||
1.21 behavior and defers the decision for a fix to a later date due to new problems.
|
||||
It addresses issue #64738 and rolls back to a previous commit.'
|
||||
commit_url: https://github.com/golang/go/commit/52dbffeac86863e1e0c9455b5b216ec50c828946
|
||||
- vars:
|
||||
commit_message: Removed the 'interfacecycles' debug flag from Go compiler since
|
||||
no related issues have emerged since Go 1.20, eliminating checks for anonymous
|
||||
interface cycles. The relevant tests have been updated to reflect this change.
|
||||
commit_url: https://github.com/golang/go/commit/6fe0d3758b35afcc342832e376d8d985a5a29070
|
@ -1,89 +0,0 @@
|
||||
|
||||
## Overview
|
||||
|
||||
This README provides information about the workflow used for generating commit messages based on commit differences. The workflow involves recording prompts, defining test cases, and running scripts to process these cases.
|
||||
|
||||
## Dependency Installation
|
||||
|
||||
Before you can run the tests for commit message generation, you need to install the necessary dependencies. This involves setting up both Node.js and Python environments. Follow the steps below to install the dependencies.
|
||||
|
||||
### Node.js Dependency
|
||||
|
||||
To install the `promptfoo` tool using `npx`, run the following command:
|
||||
|
||||
```bash
|
||||
npx promptfoo@latest
|
||||
```
|
||||
|
||||
This command will ensure that you are using the latest version of `promptfoo`.
|
||||
|
||||
### Python Dependencies
|
||||
|
||||
The test script requires certain Python packages to be installed. To install these dependencies, navigate to the directory containing the `requirements-test.txt` file and run:
|
||||
|
||||
```bash
|
||||
pip install -r commit/test/prompt/requirements-test.txt
|
||||
```
|
||||
|
||||
This will install all the Python packages listed in the `requirements-test.txt` file, which are necessary for the test script to function correctly.
|
||||
|
||||
After completing these steps, you should have all the required dependencies installed and be ready to proceed with the test execution as described in the **Getting Started** section of this README.
|
||||
|
||||
|
||||
## Getting Started
|
||||
|
||||
To get started with the commit message generation workflow:
|
||||
|
||||
1. Ensure you have `npx` and `promptfoo` installed and configured on your system.
|
||||
2. Navigate to the directory containing the workflow files.
|
||||
3. Review and update the test cases in `commit_message_tests.yaml` as needed.
|
||||
4. Run the test execution command to generate commit messages.
|
||||
5. Use the test results viewing command to analyze the results.
|
||||
|
||||
|
||||
For a quick way to execute the current test cases, you can use the provided script file `./run.sh`. This script will automate the process of installation and test execution for you. Simply run the following command in your terminal:
|
||||
|
||||
```bash
|
||||
./run.sh
|
||||
```
|
||||
|
||||
This will ensure that all necessary dependencies are installed, and then it will proceed to run the tests as defined in your test cases file.
|
||||
|
||||
|
||||
For any additional help or to report issues, please refer to the project's issue tracker or contact the repository administrator.
|
||||
|
||||
|
||||
## File Structure
|
||||
|
||||
- **Prompt Record File**: `./commit/diffCommitMessagePrompt.txt`
|
||||
- This file contains the prompts that are used to generate commit messages.
|
||||
|
||||
- **Test Cases File**: `./commit/test/prompt/commit_message_tests.yaml`
|
||||
- This YAML file holds the test cases for the commit message generation tests. Each test case includes the `commit_url` which points to the specific commit differences to be used for generating the commit message.
|
||||
|
||||
- **Test Script**: `./commit/test/prompt/commit_message_run.py`
|
||||
- This is the Python script that processes the test cases. It fetches the commit differences from the provided `commit_url` and generates the commit messages accordingly.
|
||||
|
||||
- **Test Configuration File**: `./commit/test/prompt/commit_message_prompt_config.yaml`
|
||||
- This YAML file provides the overall description of the tests and configurations needed for the test execution.
|
||||
|
||||
## Test Execution
|
||||
|
||||
To execute the tests for commit message generation, use the following command:
|
||||
|
||||
```bash
|
||||
npx promptfoo eval -c commit/test/prompt/commit_message_prompt_config.yaml
|
||||
```
|
||||
|
||||
This command will run the tests as defined in the `commit_message_prompt_config.yaml` file.
|
||||
|
||||
## Viewing Test Results
|
||||
|
||||
After running the tests, you can display the results using the command below:
|
||||
|
||||
```bash
|
||||
npx promptfoo view
|
||||
```
|
||||
|
||||
This command will present the outcomes of the tests, allowing you to review the generated commit messages and their respective test cases.
|
||||
|
@ -1,3 +0,0 @@
|
||||
requests>=2.31.0
|
||||
openai>=1.6.1
|
||||
pyyaml>=6.0.1
|
@ -1,33 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 获取脚本所在目录
|
||||
SCRIPT_DIR=$(dirname "$0")
|
||||
TEST_DIR="${SCRIPT_DIR}"
|
||||
REQUIREMENTS_FILE="${TEST_DIR}/requirements-test.txt"
|
||||
CONFIG_FILE="${TEST_DIR}/commit_message_prompt_config.yaml"
|
||||
|
||||
# 安装Node.js依赖
|
||||
echo "Installing promptfoo using npx..."
|
||||
npx promptfoo@latest
|
||||
|
||||
# 检查Python是否安装
|
||||
if ! command -v python3 &> /dev/null
|
||||
then
|
||||
echo "Python could not be found, please install Python 3."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 安装Python依赖
|
||||
echo "Installing Python dependencies..."
|
||||
pip3 install -r ${REQUIREMENTS_FILE}
|
||||
|
||||
# 执行测试用例
|
||||
echo "Running test cases..."
|
||||
npx promptfoo eval -c ${CONFIG_FILE}
|
||||
|
||||
# 打开测试结果视图
|
||||
echo "Opening test results view..."
|
||||
npx promptfoo view
|
||||
|
||||
# 执行结束
|
||||
echo "Test execution and result viewing completed."
|
Loading…
x
Reference in New Issue
Block a user