-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #131 from devchat-ai/feature/switch-submodule-dire…
…ctories refactor: Replace subprocess calls with subprocess_check_output
- Loading branch information
Showing
38 changed files
with
2,348 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
### code_task_summary | ||
|
||
根据当前分支或指定的Issue,生成代码任务摘要。 | ||
|
||
#### 用途 | ||
- 自动生成简洁的代码任务描述 | ||
- 帮助开发者快速理解任务要点 | ||
- 用于更新项目配置或文档 | ||
|
||
#### 使用方法 | ||
执行命令: `/github.code_task_summary [issue_url]` | ||
|
||
- 如不提供issue_url,将基于当前分支名称提取Issue信息 | ||
- 如提供issue_url,将直接使用该Issue的内容 | ||
|
||
#### 操作流程 | ||
1. 获取Issue信息 | ||
2. 生成代码任务摘要 | ||
3. 允许用户编辑摘要 | ||
4. 更新项目配置文件 | ||
|
||
#### 注意事项 | ||
- 确保Git仓库配置正确 | ||
- 需要有效的GitHub Token以访问API |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import json | ||
import os | ||
import sys | ||
|
||
from devchat.llm import chat_json | ||
|
||
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")) | ||
|
||
from common_util import assert_exit, ui_edit # noqa: E402 | ||
from git_api import ( # noqa: E402 | ||
check_git_installed, | ||
get_current_branch, | ||
get_gitlab_issue_repo, | ||
get_issue_info, | ||
is_issue_url, | ||
read_issue_by_url, | ||
) | ||
|
||
|
||
def extract_issue_id(branch_name): | ||
if "#" in branch_name: | ||
return branch_name.split("#")[-1] | ||
return None | ||
|
||
|
||
# Function to generate a random branch name | ||
PROMPT = ( | ||
"You are a coding engineer, required to summarize the ISSUE description into a coding task description of no more than 50 words. \n" # noqa: E501 | ||
"The ISSUE description is as follows: {issue_body}, please summarize the corresponding coding task description.\n" # noqa: E501 | ||
'The coding task description should be output in JSON format, in the form of: {{"summary": "code task summary"}}\n' # noqa: E501 | ||
) | ||
|
||
|
||
@chat_json(prompt=PROMPT) | ||
def generate_code_task_summary(issue_body): | ||
pass | ||
|
||
|
||
@ui_edit(ui_type="editor", description="Edit code task summary:") | ||
def edit_code_task_summary(task_summary): | ||
pass | ||
|
||
|
||
def get_issue_or_task(task): | ||
if is_issue_url(task): | ||
issue = read_issue_by_url(task.strip()) | ||
assert_exit(not issue, "Failed to read issue.", exit_code=-1) | ||
|
||
return json.dumps( | ||
{"id": issue["iid"], "title": issue["title"], "description": issue["description"]} | ||
) | ||
else: | ||
return task | ||
|
||
|
||
def get_issue_json(issue_id, task): | ||
issue = {"id": "no issue id", "title": "", "description": task} | ||
if issue_id: | ||
issue = get_issue_info(issue_id) | ||
assert_exit(not issue, f"Failed to retrieve issue with ID: {issue_id}", exit_code=-1) | ||
issue = { | ||
"id": issue_id, | ||
"web_url": issue["web_url"], | ||
"title": issue["title"], | ||
"description": issue["description"], | ||
} | ||
return issue | ||
|
||
|
||
# Main function | ||
def main(): | ||
print("Start update code task summary ...", end="\n\n", flush=True) | ||
|
||
is_git_installed = check_git_installed() | ||
assert_exit(not is_git_installed, "Git is not installed.", exit_code=-1) | ||
|
||
task = sys.argv[1] | ||
|
||
repo_name = get_gitlab_issue_repo() | ||
branch_name = get_current_branch() | ||
issue_id = extract_issue_id(branch_name) | ||
|
||
# print basic info, repo_name, branch_name, issue_id | ||
print("repo name:", repo_name, end="\n\n") | ||
print("branch name:", branch_name, end="\n\n") | ||
print("issue id:", issue_id, end="\n\n") | ||
|
||
issue = get_issue_json(issue_id, task) | ||
assert_exit( | ||
not issue["description"], f"Failed to retrieve issue with ID: {issue_id}", exit_code=-1 | ||
) | ||
|
||
# Generate 5 branch names | ||
print("Generating code task summary ...", end="\n\n", flush=True) | ||
code_task_summary = generate_code_task_summary(issue_body=issue["description"]) | ||
assert_exit(not code_task_summary, "Failed to generate code task summary.", exit_code=-1) | ||
assert_exit( | ||
not code_task_summary.get("summary", None), | ||
"Failed to generate code task summary, missing summary field in result.", | ||
exit_code=-1, | ||
) | ||
code_task_summary = code_task_summary["summary"] | ||
|
||
# Select branch name | ||
code_task_summary = edit_code_task_summary(code_task_summary) | ||
assert_exit(not code_task_summary, "Failed to edit code task summary.", exit_code=-1) | ||
code_task_summary = code_task_summary[0] | ||
|
||
# create and checkout branch | ||
print("Updating code task summary to config:") | ||
config_file = os.path.join(".chat", "complete.config") | ||
if os.path.exists(config_file): | ||
with open(config_file, "r") as f: | ||
config = json.load(f) | ||
config["taskDescription"] = code_task_summary | ||
else: | ||
config = {"taskDescription": code_task_summary} | ||
with open(config_file, "w") as f: | ||
json.dump(config, f, indent=4) | ||
print("Code task summary has updated") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.