Skip to content
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

chore(pro) #86

Merged
merged 5 commits into from
Aug 29, 2023
Merged
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
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,13 @@ Through the above introduction and Demo demonstration, you must be curious about
## Quick Start

1. Run with source code
```
1. Clone the latest code or select a released version, Python3.7 or later is ready.
1. Download the [released version](https://github.com/kuafuai/DevOpsGPT/releases), or clone the latest code(instability), Ensure SQLite and Python3.7 or later is ready.
2. Generate the configuration file: Copy `env.yaml.tpl` and rename it to `env.yaml`.
3. Modify the configuration file: Edit `env.yaml` and add the necessary information such as GPT Token (refer to [documentation link](docs/DOCUMENT.md) for detailed instructions).
4. Run the service: Execute `sh run.sh` on Linux or Mac, or double-click `run.bat` on Windows.
5. Access the service: Access the service through a browser (check the startup log for the access address, default is http://127.0.0.1:8080).
6. Complete requirement development: Follow the instructions on the page to complete requirement development, and view the generated code in the `./workspace` directory.
```

2. Run with Docker
```shell
1. Create a directory: mkdir -p workspace
Expand Down
43 changes: 32 additions & 11 deletions backend/app/controllers/requirement.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from app.models.task import getEmptyTaskInfo
from app.pkgs.tools.i18b import getI18n
from app.models.requirement import Requirement
from config import REQUIREMENT_STATUS_NotStarted
from app.models.requirement_memory_pro import RequirementMemory
from config import REQUIREMENT_STATUS_NotStarted, GRADE

bp = Blueprint('requirement', __name__, url_prefix='/requirement')

Expand Down Expand Up @@ -32,8 +33,9 @@ def setup_app():
sourceBranch = data['source_branch']
featureBranch = data['feature_branch']
username = session['username']
tenantID = session['tenant_id']

requirement = Requirement.create_requirement("", "New", appID, 1, REQUIREMENT_STATUS_NotStarted, 0, 0)
requirement = Requirement.create_requirement(tenantID, "", "New", appID, 1, sourceBranch, featureBranch, REQUIREMENT_STATUS_NotStarted, 0, 0)

session[username]['memory']['task_info'] = {
"app_id": appID,
Expand All @@ -44,20 +46,39 @@ def setup_app():
session.update()

if requirement.requirement_id:
return {"task_id": session[username]['memory']['task_info']['task_id']}
return Requirement.get_requirement_by_id(requirement.requirement_id)
else:
raise Exception(_("Failed to set up app."))

@bp.route('/get', methods=['GET'])
@json_response
def getAll():
def get_all():
_ = getI18n("controllers")
owner = session['username']
appID = request.args.get('app_id')
tenantID = session['tenant_id']

try:
requirements = Requirement.get_all_requirements(appID)
requirements = Requirement.get_all_requirements(tenantID)

return {'requirements': requirements}
except Exception as e:
raise Exception(_("Failed to get applications."))
return {'requirements': requirements}

@bp.route('/get_one', methods=['GET'])
@json_response
def get_one():
_ = getI18n("controllers")
requirementID = request.args.get('requirement_id')

requirement = Requirement.get_requirement_by_id(requirementID)

memory = {
"task_info" : {
"app_id": requirement["app_id"],
"task_id": requirement["requirement_id"],
"source_branch": requirement["default_source_branch"],
"feature_branch": requirement["default_target_branch"]
}
}
requirement["old_memory"] = memory

if GRADE != "base":
requirement["memory"] = RequirementMemory.get_all_requirement_memories(requirementID, 1)

return requirement
16 changes: 4 additions & 12 deletions backend/app/controllers/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
@json_response
def get_git_config_list():
_ = getI18n("controllers")
username = session['username']
tenantID = session['tenant_id']
appID = session[username]['memory']['task_info']['app_id']

gitList, success = getGitConfigList(tenantID, appID)
gitList, success = getGitConfigList(tenantID, 0)
if not success:
raise Exception(_("Failed to get git config list."))

Expand All @@ -24,11 +22,9 @@ def get_git_config_list():
@json_response
def get_ci_config_list():
_ = getI18n("controllers")
username = session['username']
tenantID = session['tenant_id']
appID = session[username]['memory']['task_info']['app_id']

gitList, success = getCIConfigList(tenantID, appID)
gitList, success = getCIConfigList(tenantID, 0)
if not success:
raise Exception(_("Failed to get git config list."))

Expand All @@ -38,11 +34,9 @@ def get_ci_config_list():
@json_response
def get_cd_config_list():
_ = getI18n("controllers")
username = session['username']
tenantID = session['tenant_id']
appID = session[username]['memory']['task_info']['app_id']

gitList, success = getCDConfigList(tenantID, appID)
gitList, success = getCDConfigList(tenantID, 0)
if not success:
raise Exception(_("Failed to get git config list."))

Expand All @@ -52,11 +46,9 @@ def get_cd_config_list():
@json_response
def get_llm_config_list():
_ = getI18n("controllers")
username = session['username']
tenantID = session['tenant_id']
appID = session[username]['memory']['task_info']['app_id']

gitList, success = getLLMConfigList(tenantID, appID)
gitList, success = getLLMConfigList(tenantID, 0)
if not success:
raise Exception(_("Failed to get git config list."))

Expand Down
8 changes: 5 additions & 3 deletions backend/app/controllers/step_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from app.pkgs.tools.i18b import getI18n
from app.pkgs.prompt.prompt import clarifyAPI
from app.pkgs.knowledge.app_info import getServiceSwagger
from app.models.requirement import Requirement

bp = Blueprint('step_api', __name__, url_prefix='/step_api')

Expand All @@ -13,12 +14,13 @@ def gen_interface_doc():
_ = getI18n("controllers")
userPrompt = request.json.get('user_prompt')
username = session["username"]
requirementID = request.json.get('task_id')

# todo Use llm to determine which interface documents to adjust
appID = session[username]['memory']['task_info']['app_id']
apiDoc, success = getServiceSwagger(appID, 0)
req = Requirement.get_requirement_by_id(requirementID)
apiDoc, success = getServiceSwagger(req["app_id"], 0)

msg, success = clarifyAPI(userPrompt, apiDoc)
msg, success = clarifyAPI(requirementID, userPrompt, apiDoc)

session[username]['memory']['originalPrompt'] = userPrompt
session.update()
Expand Down
26 changes: 19 additions & 7 deletions backend/app/controllers/step_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,25 @@ def edit_file_task():
newTask = request.json.get('new_task')
newCode = request.json.get('new_code')
fileTask = request.json.get('file_task')
filePath = request.json.get('file_path')
requirementID = request.json.get('task_id')

re, success = aiGenCode(fileTask, newTask, newCode)
re, success = aiGenCode(requirementID, fileTask, newTask, newCode, filePath)
if not success:
raise Exception(_("Failed to edit file with new task."))

return {'success': success, 'code': re["code"], 'reasoning': re["reasoning"]}

@bp.route('/check_file', methods=['POST'])
@bp.route('/check_code', methods=['POST'])
@json_response
def check_file():
_ = getI18n("controllers")
code = request.json.get('code')
fileTask = request.json.get('fileTask')
requirementID = request.json.get('task_id')
filePath = request.json.get('file_path')

re, success = aiCheckCode(fileTask, code)
re, success = aiCheckCode(requirementID, fileTask, code, filePath)
if not success:
raise Exception(_("Failed to check file."))

Expand All @@ -43,8 +47,10 @@ def merge_file():
fileTask = request.json.get('file_task')
userName = session["username"]
appName = session[userName]['memory']['task_info']['app_name']
requirementID = request.json.get('task_id')
filePath = request.json.get('file_path')

re, success = aiMergeCode(fileTask, appName, baseCode, newCode)
re, success = aiMergeCode(requirementID, fileTask, appName, baseCode, newCode, filePath)
if not success:
raise Exception(_("Failed to merge old and new code."))

Expand All @@ -61,12 +67,14 @@ def reference_repair():
userName = session["username"]
appName = session[userName]['memory']['task_info']['app_name']
branch = session[userName]['memory']['task_info']['source_branch']
requirementID = request.json.get('task_id')
filePath = request.json.get('file_path')

hasGitCode, referenceCode = getFileContent(referenceFile, branch, repo)
if not hasGitCode:
raise Exception(_("Failed to reference repair no reference file found."))

re, success = aiReferenceRepair(newCode, appName, referenceCode, fileTask)
re, success = aiReferenceRepair(requirementID, newCode, appName, referenceCode, fileTask, filePath)
if not success:
raise Exception(_("Reference repair failed for unknown reasons."))

Expand All @@ -78,8 +86,10 @@ def reference_repair():
def fix_compile():
code = request.json.get('code')
solution = request.json.get('solution')
requirementID = request.json.get('task_id')
filePath = request.json.get('file_path')

re, success = aiFixError(solution, code)
re, success = aiFixError(requirementID, solution, code, filePath, "compile")
reCode = re["code"]
reason = re["reasoning"]

Expand All @@ -91,8 +101,10 @@ def fix_compile():
def fix_lint():
code = request.json.get('code')
solution = request.json.get('solution')
requirementID = request.json.get('task_id')
filePath = request.json.get('file_path')

re, success = aiFixError(solution, code)
re, success = aiFixError(requirementID, solution, code, filePath, "lint")
reCode = re["code"]
reason = re["reasoning"]

Expand Down
59 changes: 28 additions & 31 deletions backend/app/controllers/step_devops.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from app.models.application_service import ApplicationService
from flask import Blueprint
from app.models.setting import getCIConfigList, getCDConfigList
from app.models.requirement import Requirement

bp = Blueprint('step_devops', __name__, url_prefix='/step_devops')

Expand All @@ -18,29 +19,29 @@
def trigger_ci():
serviceName = request.json.get('repo_path')
username = session['username']
appID = session[username]['memory']['task_info']['app_id']
serviceInfo = ApplicationService.get_service_by_name(appID, serviceName)
requirementID = request.json.get('task_id')
req = Requirement.get_requirement_by_id(requirementID)
serviceInfo = ApplicationService.get_service_by_name(req["app_id"], serviceName)
tenantID = session['tenant_id']
appID = session[username]['memory']['task_info']['app_id']
ciConfigList, success = getCIConfigList(tenantID, appID)
ciConfigList, success = getCIConfigList(tenantID, req["app_id"])
branch = session[username]['memory']['task_info']['feature_branch']

result, piplineID, piplineUrl, success = triggerPipeline(branch, serviceInfo, ciConfigList[0])
result, piplineID, piplineUrl, success = triggerPipeline(requirementID, branch, serviceInfo, ciConfigList[0])
if success:
return {"name": 'ci', "info": {"piplineID": piplineID, "repopath": serviceInfo["git_path"], "piplineUrl": piplineUrl}}
else:
raise Exception(result)


@bp.route('/plugin_ci', methods=['GET'])
@bp.route('/query_ci', methods=['GET'])
@json_response
def plugin_ci():
pipeline_id = request.args.get('piplineID')
repopath = request.args.get('repopath')
tenantID = session['tenant_id']
username = session['username']
appID = session[username]['memory']['task_info']['app_id']
ciConfigList, success = getCIConfigList(tenantID, appID)
requirementID = request.args.get('task_id')
req = Requirement.get_requirement_by_id(requirementID)
ciConfigList, success = getCIConfigList(tenantID, req["app_id"] )

piplineJobs, success = getPipelineStatus(pipeline_id, repopath, ciConfigList[0])
print("piplineJobs:", piplineJobs)
Expand All @@ -56,20 +57,19 @@ def plugin_ci():
@json_response
def check_compile():
_ = getI18n("controllers")
task_id = request.json.get('task_id')
requirementID = request.json.get('task_id')
serviceName = request.json.get('repo_path')
wsPath = get_ws_path(task_id)
username = session['username']
appID = session[username]['memory']['task_info']['app_id']
gitPath, success = getServiceGitPath(appID, serviceName)
wsPath = get_ws_path(requirementID)
req = Requirement.get_requirement_by_id(requirementID)
gitPath, success = getServiceGitPath(req["app_id"], serviceName)

success, message = compileCheck(wsPath, gitPath)
success, message = compileCheck(requirementID, wsPath, gitPath)

if success:
reasoning = _("Compile check pass.")
return {'pass': True, 'message': message, 'reasoning': reasoning}
else:
reasoning, success = aiAnalyzeError(message)
reasoning, success = aiAnalyzeError(requirementID, message, "")
if success:
return {'pass': False, 'message': message, 'reasoning': reasoning}
else:
Expand All @@ -80,21 +80,20 @@ def check_compile():
@json_response
def check_lint():
_ = getI18n("controllers")
task_id = request.json.get('task_id')
requirementID = request.json.get('task_id')
file_path = request.json.get('file_path')
serviceName = request.json.get('service_name')
username = session['username']
appID = session[username]['memory']['task_info']['app_id']
gitPath, success = getServiceGitPath(appID, serviceName)
ws_path = get_ws_path(task_id)
req = Requirement.get_requirement_by_id(requirementID)
gitPath, success = getServiceGitPath(req["app_id"], serviceName)
ws_path = get_ws_path(requirementID)

success, message = lintCheck(ws_path, gitPath, file_path)
success, message = lintCheck(requirementID, ws_path, gitPath, file_path)

if success:
reasoning = _("Static code scan passed.")
return {'pass': True, 'message': message, 'reasoning': reasoning}
else:
reasoning, success = aiAnalyzeError(message)
reasoning, success = aiAnalyzeError(requirementID, message, file_path)
if success:
return {'pass': False, 'message': message, 'reasoning': reasoning}
else:
Expand All @@ -103,17 +102,15 @@ def check_lint():
@bp.route('/trigger_cd', methods=['POST'])
@json_response
def trigger_cd():
username = session['username']
appID = session[username]['memory']['task_info']['app_id']
requirementID = request.json.get('task_id')
req = Requirement.get_requirement_by_id(requirementID)
serviceName = request.json.get('repo_path')
serviceInfo = ApplicationService.get_service_by_name(appID, serviceName)
image, success = getServiceDockerImage(appID, serviceName)
serviceInfo = ApplicationService.get_service_by_name(req["app_id"], serviceName)
image, success = getServiceDockerImage(req["app_id"], serviceName)
tenantID = session['tenant_id']
username = session['username']
appID = session[username]['memory']['task_info']['app_id']
cdConfigList, success = getCDConfigList(tenantID, appID)
cdConfigList, success = getCDConfigList(tenantID, req["app_id"])

result, success = triggerCD(image, serviceInfo, cdConfigList[0])
result, success = triggerCD(requirementID, image, serviceInfo, cdConfigList[0])
if success:
return {"internet_ip": result}
else:
Expand Down
Loading