Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions new-issue/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# new issue
Help you to create github issue, with a certain format.

## Usage
5 changes: 5 additions & 0 deletions new-issue/bug/command.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
description: 创建一个bug类型的issue
hint: question
input: required
steps:
- run: $devchat_python $command_path/../command.py ".devchat/information/issue/bug.txt$input"
132 changes: 132 additions & 0 deletions new-issue/command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import sys
import os
import json

from devchat.llm.chat import chat_json
from github import Github
from github import Auth
# from common_util import editor

def read_config():
config_path = os.path.join(os.getcwd(), '.devchat', 'information', 'config', 'config.json')
if not os.path.exists(config_path):
print('Config file does not exist')
return None
with open(config_path, 'r') as f:
return json.load(f)

def write_config(repo_path, github_token):
config_path = os.path.join(os.getcwd(), '.devchat', 'information', 'config', 'config.json')
with open(config_path, 'w') as f:
json.dump({'repo_path': repo_path, 'github_token': github_token}, f)

PROMPT= prompt = """
pls return a JSON object without line break(the response must be parsed as json, not contain any redundant chars), including a string field Title and a markdown string field called Body.
{information}
{request}
{context}
"""
@chat_json(prompt=PROMPT)
def get_issue_content(information, request, context):
pass

PROMPT= prompt = """
I will request you to write an issue. The request is consists of two parts, Firstly, I will give a context list(organized by concept name). You may choose most related ones and return it as a json object(with key files) according to the requst content. Then I will ask you for issue content with the context you chosen. Now is the first request, pls only return an json object with context files you chosen. context files: {context_list}, issue content:
`{request_content}`
"""
@chat_json(prompt=PROMPT)
def get_related_context_file(context_list, request_content):
pass

# @editor("Please specify the issue's repository, "
# "If the issue is within this repository, no need to specify. "
# "Otherwise, format as: username/repository-name")
# @editor("Input your github TOKEN to access github api:")
# def set_config(repo_path, github_token):
# pass

def get_request(path):
if not os.path.exists(path):
return
with open(path, 'r') as f:
request = f.read()
return request

def read_api_config():
config = read_config()
# set config by devlake ui
# repo_path = ''
# github_token = ''
# if config != None:
# repo_path = config['repo_path']
# github_token = config['github_token']
# else:
# # request user config
# repo_path, github_token = set_config(repo_path, github_token)

# write_config(repo_path, github_token)
repo_path = config['repo_path']
github_token = config['github_token']
return repo_path, github_token
def create_github_issue(github_token, repo_path, issue_content, issue_title):
auth = Auth.Token(github_token)
g = Github(auth=auth)
repo = g.get_repo(repo_path)
issue = repo.create_issue(title=issue_title, body=issue_content)
print(issue, flush=True)

def main():
# get user input
user_input = sys.argv[1]
params = user_input.strip().split(' ')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: if your provide parameter with english, the request context will be seperated by space.

user_content = params[1]
print(f'reading request...\n', flush=True)
request_path = os.path.join(os.getcwd(), params[0])
request = get_request(request_path)
if request == '':
print('Request file does not exist', flush=True)
return
# get repository context
information = ''
# get request context
print(f'reading context list\n', flush=True)
# get context list
context_list = os.listdir(os.path.join(os.getcwd(), '.devchat', 'information', 'context'))
# print(context_list, flush=True)
print(f'[ai]choosing context files...\n', flush=True)
response = get_related_context_file(context_list=context_list, request_content=request + user_content)
print(response)
chosen_context_files = response['files']
print(f'chosen context files: {chosen_context_files}\n', flush=True)
print(f'reading context...\n', flush=True)
for context_file in chosen_context_files:
context_file_path = os.path.join(os.getcwd(), '.devchat', 'information', 'context', context_file)
if not os.path.exists(context_file_path):
print(f'context file {context_file} does not exist\n', flush=True)
return
with open(context_file_path, 'r') as f:
information += f.read()
print(f'context read\n', flush=True)

print(f'reading config...\n', flush=True)
# check if github token is configured
repo_path, github_token = read_api_config()
print(f'[ai] generating issue content...\n', flush=True)
# # debug
# print(information)
# print(request)
# print(user_content)
# get issue_content from ai
issue_content=get_issue_content(information=information, request=request, context=user_content)
# print issue content and wait for user confirmation
print(issue_content, flush=True)
# TODO:: add user confirmation
print(f'creating issue...\n', flush=True)
create_github_issue(github_token, repo_path, issue_content['Body'], issue_content['Title'])

# request github api to create issue
print(f'issue created\n', flush=True)


if __name__ == "__main__":
main()
5 changes: 5 additions & 0 deletions new-issue/command.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
description: 创建一个issue
hint: question
input: required
steps:
- run: $devchat_python $command_path/command.py "$input"
5 changes: 5 additions & 0 deletions new-issue/feature-request/command.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
description: 创建一个feature-request类型的issue
hint: question
input: required
steps:
- run: $devchat_python $command_path/../command.py ".devchat/information/issue/feature-request.txt$input"
14 changes: 14 additions & 0 deletions new-issue/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
certifi==2024.2.2
cffi==1.16.0
charset-normalizer==3.3.2
cryptography==42.0.5
Deprecated==1.2.14
idna==3.6
pycparser==2.21
PyGithub==2.2.0
PyJWT==2.8.0
PyNaCl==1.5.0
requests==2.31.0
typing_extensions==4.10.0
urllib3==2.2.1
wrapt==1.16.0