-
Notifications
You must be signed in to change notification settings - Fork 4
feat: add new issue command #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
narrowizard
wants to merge
1
commit into
devchat-ai:main
Choose a base branch
from
narrowizard:devlake/issue
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,4 @@ | ||
| # new issue | ||
| Help you to create github issue, with a certain format. | ||
|
|
||
| ## Usage |
This file contains hidden or 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,5 @@ | ||
| description: 创建一个bug类型的issue | ||
| hint: question | ||
| input: required | ||
| steps: | ||
| - run: $devchat_python $command_path/../command.py ".devchat/information/issue/bug.txt$input" |
This file contains hidden or 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,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(' ') | ||
| 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() | ||
This file contains hidden or 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,5 @@ | ||
| description: 创建一个issue | ||
| hint: question | ||
| input: required | ||
| steps: | ||
| - run: $devchat_python $command_path/command.py "$input" |
This file contains hidden or 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,5 @@ | ||
| description: 创建一个feature-request类型的issue | ||
| hint: question | ||
| input: required | ||
| steps: | ||
| - run: $devchat_python $command_path/../command.py ".devchat/information/issue/feature-request.txt$input" |
This file contains hidden or 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,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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.