Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
纵之格
Mogui
提交
6d15ede0
M
Mogui
项目概览
纵之格
/
Mogui
通知
3
Star
0
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
Mogui
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
6d15ede0
编写于
8月 17, 2017
作者:
G
gongfuxiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
项目操作地址与上线地址分开
上级
6786d91d
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
96 addition
and
36 deletion
+96
-36
.gitignore
.gitignore
+1
-0
mogui/common/function.py
mogui/common/function.py
+12
-0
mogui/controller/project.py
mogui/controller/project.py
+16
-4
mogui/controller/release.py
mogui/controller/release.py
+62
-28
mogui/controller/welcome.py
mogui/controller/welcome.py
+2
-1
mogui/view/v1/project/index.html
mogui/view/v1/project/index.html
+1
-1
mogui/view/v1/release/index.html
mogui/view/v1/release/index.html
+1
-1
mogui/view/v1/welcome/index.html
mogui/view/v1/welcome/index.html
+1
-1
未找到文件。
.gitignore
浏览文件 @
6d15ede0
...
@@ -9,3 +9,4 @@ Logs
...
@@ -9,3 +9,4 @@ Logs
logs
logs
*.lock
*.lock
*.pyc
*.pyc
temp_project
\ No newline at end of file
mogui/common/function.py
浏览文件 @
6d15ede0
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
# ============================================================
# ============================================================
from
django.http
import
HttpResponse
from
django.http
import
HttpResponse
from
django.conf
import
settings
import
json
import
json
# 特殊字符处理(超出ascii处理的范围)
# 特殊字符处理(超出ascii处理的范围)
...
@@ -16,6 +17,17 @@ import sys
...
@@ -16,6 +17,17 @@ import sys
reload
(
sys
)
reload
(
sys
)
sys
.
setdefaultencoding
(
'utf8'
)
sys
.
setdefaultencoding
(
'utf8'
)
# 获取项目临时操作地址
# @author Devil
# @version 0.0.1
# @blog http://gong.gg/
# @date 2017-08-04
# @return [string] [项目临时操作地址]
def
get_project_handle_temp_dir
()
:
return
settings
.
BASE_DIR
+
'/temp_project'
# 获取项目名称
# 获取项目名称
# @author Devil
# @author Devil
# @version 0.0.1
# @version 0.0.1
...
...
mogui/controller/project.py
浏览文件 @
6d15ede0
...
@@ -94,17 +94,29 @@ def save(request) :
...
@@ -94,17 +94,29 @@ def save(request) :
if
os
.
path
.
exists
(
git_dir_address
)
==
True
:
if
os
.
path
.
exists
(
git_dir_address
)
==
True
:
shutil
.
rmtree
(
git_dir_address
)
shutil
.
rmtree
(
git_dir_address
)
# 目录不存在则创建
#
项目实际地址-
目录不存在则创建
if
os
.
path
.
exists
(
request
.
POST
[
'dir_address'
])
==
False
:
if
os
.
path
.
exists
(
request
.
POST
[
'dir_address'
])
==
False
:
os
.
mkdir
(
request
.
POST
[
'dir_address'
])
os
.
mkdir
(
request
.
POST
[
'dir_address'
])
#
创建分支
#
项目实际地址-克隆代码
if
os
.
path
.
exists
(
git_dir_address
)
==
False
:
if
os
.
path
.
exists
(
git_dir_address
)
==
False
:
(
status
,
output
)
=
commands
.
getstatusoutput
(
'cd '
+
request
.
POST
[
'dir_address'
]
+
';git clone '
+
request
.
POST
[
'git_ssh_address'
])
(
status
,
output
)
=
commands
.
getstatusoutput
(
'cd '
+
request
.
POST
[
'dir_address'
]
+
';git clone '
+
request
.
POST
[
'git_ssh_address'
])
if
status
!=
0
:
return
function
.
ajax_return_exit
(
'git克隆失败'
,
-
10
,
[],
output
)
# 临时操作地址
project_temp_dir
=
function
.
get_project_handle_temp_dir
()
project_git_name
=
function
.
get_git_ssh_name
(
request
.
POST
[
'git_ssh_address'
])
# 临时操作地址-目录不存在则创建
if
os
.
path
.
exists
(
project_temp_dir
)
==
False
:
os
.
mkdir
(
project_temp_dir
)
# 项目是否拉取成功
# 临时操作地址-克隆代码
if
os
.
path
.
exists
(
project_temp_dir
+
'/'
+
project_git_name
)
==
False
:
(
status
,
output
)
=
commands
.
getstatusoutput
(
'cd '
+
project_temp_dir
+
';git clone '
+
request
.
POST
[
'git_ssh_address'
])
if
status
!=
0
:
if
status
!=
0
:
return
function
.
ajax_return_exit
(
'git克隆失败'
,
-
1
,
[],
output
)
return
function
.
ajax_return_exit
(
'git克隆失败'
,
-
1
0
,
[],
output
)
# 等于0则添加
# 等于0则添加
if
project_id
==
'0'
:
if
project_id
==
'0'
:
...
...
mogui/controller/release.py
浏览文件 @
6d15ede0
...
@@ -90,7 +90,8 @@ def get_branch_list(request) :
...
@@ -90,7 +90,8 @@ def get_branch_list(request) :
data
=
Project
.
objects
.
filter
(
project_id
=
project_id
).
first
()
data
=
Project
.
objects
.
filter
(
project_id
=
project_id
).
first
()
if
data
!=
None
:
if
data
!=
None
:
# 获取项目名称
# 获取项目名称
git_dir_address
=
function
.
get_git_address
(
data
.
dir_address
,
data
.
git_ssh_address
)
git_dir_address
=
function
.
get_git_address
(
function
.
get_project_handle_temp_dir
(),
data
.
git_ssh_address
)
if
os
.
path
.
exists
(
git_dir_address
)
==
False
:
if
os
.
path
.
exists
(
git_dir_address
)
==
False
:
return
function
.
ajax_return_exit
(
'项目路径地址不存在'
,
-
2
)
return
function
.
ajax_return_exit
(
'项目路径地址不存在'
,
-
2
)
...
@@ -126,7 +127,7 @@ def get_version_list(request) :
...
@@ -126,7 +127,7 @@ def get_version_list(request) :
data
=
Project
.
objects
.
filter
(
project_id
=
project_id
).
first
()
data
=
Project
.
objects
.
filter
(
project_id
=
project_id
).
first
()
if
data
!=
None
:
if
data
!=
None
:
# 获取项目名称
# 获取项目名称
git_dir_address
=
function
.
get_git_address
(
data
.
dir_address
,
data
.
git_ssh_address
)
git_dir_address
=
function
.
get_git_address
(
function
.
get_project_handle_temp_dir
()
,
data
.
git_ssh_address
)
if
os
.
path
.
exists
(
git_dir_address
)
==
False
:
if
os
.
path
.
exists
(
git_dir_address
)
==
False
:
return
function
.
ajax_return_exit
(
'项目路径地址不存在'
,
-
1
)
return
function
.
ajax_return_exit
(
'项目路径地址不存在'
,
-
1
)
...
@@ -145,6 +146,11 @@ def get_version_list(request) :
...
@@ -145,6 +146,11 @@ def get_version_list(request) :
if
status
!=
0
:
if
status
!=
0
:
return
function
.
ajax_return_exit
(
'git分支切换失败'
,
-
12
,
[],
output
)
return
function
.
ajax_return_exit
(
'git分支切换失败'
,
-
12
,
[],
output
)
# 拉取分支最新代码到本地分支
(
status
,
output
)
=
commands
.
getstatusoutput
(
'cd '
+
git_dir_address
+
';git pull origin '
+
branch
)
if
status
!=
0
:
return
function
.
ajax_return_exit
(
'git拉取分支代码失败'
,
-
13
,
[],
output
)
# 获取版本列表
# 获取版本列表
(
status
,
output
)
=
commands
.
getstatusoutput
(
'cd '
+
git_dir_address
+
';git log --pretty=format:"%h{|}%s{|}[%cd]{|}<%an>" --date=format:"%Y-%m-%d %H:%M:%S" -30'
)
(
status
,
output
)
=
commands
.
getstatusoutput
(
'cd '
+
git_dir_address
+
';git log --pretty=format:"%h{|}%s{|}[%cd]{|}<%an>" --date=format:"%Y-%m-%d %H:%M:%S" -30'
)
if
status
==
0
:
if
status
==
0
:
...
@@ -232,42 +238,70 @@ def handle_release(request) :
...
@@ -232,42 +238,70 @@ def handle_release(request) :
if
status
!=
0
:
if
status
!=
0
:
return
function
.
ajax_return_exit
(
'git清除本地改动项失败'
,
-
10
,
[],
output
)
return
function
.
ajax_return_exit
(
'git清除本地改动项失败'
,
-
10
,
[],
output
)
# 备份当前代码
# 上线操作
backup_name
=
'backup_'
+
time
.
strftime
(
'%Y%m%d%H%M%S'
,
time
.
localtime
())
if
handle_type
==
1
:
(
status
,
output
)
=
commands
.
getstatusoutput
(
'cd '
+
git_dir_address
+
';git branch '
+
backup_name
+
';git push origin '
+
backup_name
)
# 备份当前代码
if
status
!=
0
:
backup_name
=
'backup_'
+
time
.
strftime
(
'%Y%m%d%H%M%S'
,
time
.
localtime
())
return
function
.
ajax_return_exit
(
'备份失败'
,
-
11
,
[],
output
)
(
status
,
output
)
=
commands
.
getstatusoutput
(
'cd '
+
git_dir_address
+
';git branch '
+
backup_name
)
if
status
!=
0
:
return
function
.
ajax_return_exit
(
'git创建备份失败'
,
-
11
,
[],
output
)
# 拉取远程分支最新代码
# 备份分支推送到远程仓库
(
status
,
output
)
=
commands
.
getstatusoutput
(
'cd '
+
git_dir_address
+
';git fetch origin '
+
release
.
branch
)
(
status
,
output
)
=
commands
.
getstatusoutput
(
'cd '
+
git_dir_address
+
';git push origin '
+
backup_name
)
if
status
!=
0
:
if
status
!=
0
:
return
function
.
ajax_return_exit
(
'git拉取远程分支
失败'
,
-
12
,
[],
output
)
return
function
.
ajax_return_exit
(
'git备份到远程仓库
失败'
,
-
12
,
[],
output
)
# 分支切换
# 拉取远程分支最新代码
(
status
,
output
)
=
commands
.
getstatusoutput
(
'cd '
+
git_dir_address
+
';git checkout '
+
release
.
branch
)
(
status
,
output
)
=
commands
.
getstatusoutput
(
'cd '
+
git_dir_address
+
';git fetch origin '
+
release
.
branch
)
if
status
!=
0
:
if
status
!=
0
:
return
function
.
ajax_return_exit
(
'git分支切换失败'
,
-
13
,
[],
output
)
return
function
.
ajax_return_exit
(
'git拉取远程分支失败'
,
-
13
,
[],
output
)
# 分支切换
(
status
,
output
)
=
commands
.
getstatusoutput
(
'cd '
+
git_dir_address
+
';git checkout '
+
release
.
branch
)
if
status
!=
0
:
return
function
.
ajax_return_exit
(
'git分支切换失败'
,
-
14
,
[],
output
)
# 拉取分支最新代码到本地分支
(
status
,
output
)
=
commands
.
getstatusoutput
(
'cd '
+
git_dir_address
+
';git pull origin '
+
release
.
branch
)
if
status
!=
0
:
return
function
.
ajax_return_exit
(
'git拉取分支代码失败'
,
-
15
,
[],
output
)
if
handle_type
==
1
:
# git更新到工单指定分支与版本
# git更新到工单指定分支与版本
(
status
,
output
)
=
commands
.
getstatusoutput
(
'cd '
+
git_dir_address
+
';git reset --hard '
+
release
.
version
)
(
status
,
output
)
=
commands
.
getstatusoutput
(
'cd '
+
git_dir_address
+
';git reset --hard '
+
release
.
version
)
if
status
!=
0
:
if
status
!=
0
:
return
function
.
ajax_return_exit
(
'上线失败'
,
-
100
,
[],
output
)
return
function
.
ajax_return_exit
(
'上线失败'
,
-
100
,
[],
output
)
# 更新工单数据
Release
.
objects
.
filter
(
release_id
=
release_id
).
update
(
status
=
1
,
backup_name
=
backup_name
)
return
function
.
ajax_return_exit
(
'上线成功'
)
# 回滚操作
elif
handle_type
==
2
:
elif
handle_type
==
2
:
# 拉取远程分支最新代码
(
status
,
output
)
=
commands
.
getstatusoutput
(
'cd '
+
git_dir_address
+
';git fetch origin '
+
release
.
backup_name
)
if
status
!=
0
:
return
function
.
ajax_return_exit
(
'git远程备份分支拉取失败'
,
-
13
,
[],
output
)
# 分支切换
(
status
,
output
)
=
commands
.
getstatusoutput
(
'cd '
+
git_dir_address
+
';git checkout '
+
release
.
backup_name
)
(
status
,
output
)
=
commands
.
getstatusoutput
(
'cd '
+
git_dir_address
+
';git checkout '
+
release
.
backup_name
)
if
status
!=
0
:
if
status
!=
0
:
return
function
.
ajax_return_exit
(
'上线失败'
,
-
100
,
[],
output
)
return
function
.
ajax_return_exit
(
'git分支切换失败'
,
-
14
,
[],
output
)
# 拉取分支最新代码到本地分支
(
status
,
output
)
=
commands
.
getstatusoutput
(
'cd '
+
git_dir_address
+
';git pull origin '
+
release
.
backup_name
)
if
status
!=
0
:
return
function
.
ajax_return_exit
(
'回滚失败'
,
-
100
,
[],
output
)
# 更新工单数据
Release
.
objects
.
filter
(
release_id
=
release_id
).
update
(
status
=
2
)
return
function
.
ajax_return_exit
(
'回滚成功'
)
# 操作类型有误
else
:
else
:
return
function
.
ajax_return_exit
(
'上线工单类型错误'
,
-
99
)
return
function
.
ajax_return_exit
(
'上线工单类型错误'
,
-
99
)
# 更新工单数据
# 默认失败返回
if
handle_type
==
1
:
return
function
.
ajax_return_exit
(
'操作失败'
,
-
1000
)
Release
.
objects
.
filter
(
release_id
=
release_id
).
update
(
status
=
1
,
backup_name
=
backup_name
)
msg
=
'上线成功'
else
:
Release
.
objects
.
filter
(
release_id
=
release_id
).
update
(
status
=
2
)
msg
=
'回滚成功'
return
function
.
ajax_return_exit
(
msg
)
mogui/controller/welcome.py
浏览文件 @
6d15ede0
...
@@ -2,8 +2,9 @@
...
@@ -2,8 +2,9 @@
# 引入模板视图类库
# 引入模板视图类库
from
django.shortcuts
import
render
from
django.shortcuts
import
render
from
django.conf
import
settings
def
index
(
request
)
:
def
index
(
request
)
:
context
=
{}
context
=
{}
context
[
'hello'
]
=
'Hello World!'
context
[
'hello'
]
=
'Hello World!'
+
settings
.
BASE_DIR
return
render
(
request
,
'welcome/index.html'
,
context
)
return
render
(
request
,
'welcome/index.html'
,
context
)
\ No newline at end of file
mogui/view/v1/project/index.html
浏览文件 @
6d15ede0
{% include "../base/header.html" %}
{% include "../base/header.html" %}
<div
id=
"app"
v-loading=
"loading"
element-loading-text=
"
加载
中..."
>
<div
id=
"app"
v-loading=
"loading"
element-loading-text=
"
处理
中..."
>
<form
class=
"search-form"
action=
""
method=
"post"
>
<form
class=
"search-form"
action=
""
method=
"post"
>
<el-input
placeholder=
"请输入搜索内容"
v-model=
"search.keywords"
class=
"keywords"
>
<el-input
placeholder=
"请输入搜索内容"
v-model=
"search.keywords"
class=
"keywords"
>
<el-button
slot=
"append"
icon=
"search"
@
click=
"get_project_list"
></el-button>
<el-button
slot=
"append"
icon=
"search"
@
click=
"get_project_list"
></el-button>
...
...
mogui/view/v1/release/index.html
浏览文件 @
6d15ede0
{% include "../base/header.html" %}
{% include "../base/header.html" %}
<div
id=
"app"
v-loading=
"loading"
element-loading-text=
"
加载
中..."
>
<div
id=
"app"
v-loading=
"loading"
element-loading-text=
"
处理
中..."
>
<form
class=
"search-form"
action=
""
method=
"post"
>
<form
class=
"search-form"
action=
""
method=
"post"
>
<el-input
placeholder=
"请输入搜索内容"
v-model=
"search.keywords"
class=
"keywords"
>
<el-input
placeholder=
"请输入搜索内容"
v-model=
"search.keywords"
class=
"keywords"
>
<el-button
slot=
"append"
icon=
"search"
@
click=
"get_release_list"
></el-button>
<el-button
slot=
"append"
icon=
"search"
@
click=
"get_release_list"
></el-button>
...
...
mogui/view/v1/welcome/index.html
浏览文件 @
6d15ede0
welcome
{{ hello }}
\ No newline at end of file
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录