diff --git a/plugins/gogs/index.html b/plugins/gogs/index.html index e4e4a05f2..86eed2374 100755 --- a/plugins/gogs/index.html +++ b/plugins/gogs/index.html @@ -8,6 +8,7 @@

配置文件

配置修改

用户列表

+

项目列表

运行日志

提交日志

使用说明

@@ -18,6 +19,8 @@ \ No newline at end of file diff --git a/plugins/gogs/index.py b/plugins/gogs/index.py index 578d23357..88a27683a 100755 --- a/plugins/gogs/index.py +++ b/plugins/gogs/index.py @@ -498,6 +498,65 @@ def userList(): return mw.returnJson(True, 'OK', data) +def checkRepoListIsHasScript(data): + path = getRootPath() + for x in range(len(data)): + name = data[x]['name'] + '/' + data[x]['repo'] + '.git' + path_tmp = path + '/' + name + '/custom_hooks/post-receive' + if os.path.exists(path_tmp): + data[x]['has_hook'] = True + else: + data[x]['has_hook'] = False + return data + + +def repoList(): + + conf = getConf() + if not os.path.exists(conf): + return mw.returnJson(False, "请先安装初始化!
默认地址:http://" + mw.getLocalIp() + ":3000") + + conf = getDbConfValue() + gtype = getGogsDbType(conf) + if gtype != 'mysql': + return mw.returnJson(False, "仅支持mysql数据操作!") + + import math + args = getArgs() + + data = checkArgs(args, ['page', 'page_size']) + if not data[0]: + return data[1] + + page = int(args['page']) + page_size = int(args['page_size']) + search = '' + if 'search' in args: + search = args['search'] + + data = {} + + data['root_url'] = getRootUrl() + + start = (page - 1) * page_size + list_count = pQuery('select count(id) as num from repository') + count = list_count[0]["num"] + sql = 'select r.id,r.owner_id,r.name as repo, u.name from repository r left join user u on r.owner_id=u.id order by r.id desc limit ' + \ + str(start) + ',' + str(page_size) + # print(sql) + list_data = pQuery(sql) + # print(list_data) + list_data = checkRepoListIsHasScript(list_data) + + data['list'] = mw.getPage({'count': count, 'p': page, + 'row': page_size, 'tojs': 'gogsUserList'}) + data['page'] = page + data['page_size'] = page_size + data['page_count'] = int(math.ceil(count / page_size)) + data['data'] = list_data + return mw.returnJson(True, 'OK', data) + + def getAllUserProject(user, search=''): path = getRootPath() + '/' + user dlist = [] @@ -734,6 +793,8 @@ if __name__ == "__main__": print(submitGogsConf()) elif func == 'user_list': print(userList()) + elif func == 'repo_list': + print(repoList()) elif func == 'user_project_list': print(userProjectList()) elif func == 'project_script_edit': diff --git a/plugins/gogs/js/gogs.js b/plugins/gogs/js/gogs.js index 522415299..44bd9db9d 100755 --- a/plugins/gogs/js/gogs.js +++ b/plugins/gogs/js/gogs.js @@ -248,6 +248,70 @@ function userProjectListPage(user, search){ } +function gogsRepoListPage(page, search){ + var _data = {}; + if (typeof(page) =='undefined'){ + var page = 1; + } + + _data['page'] = page; + _data['page_size'] = 10; + if(typeof(search) != 'undefined'){ + _data['search'] = search; + } + + gogsPost('repo_list', _data, function(data){ + + var rdata = $.parseJSON(data.data); + if (!rdata.status){ + layer.msg(rdata.msg,{icon:0,time:2000,shade: [0.3, '#000']}); + return; + } + + var ulist = rdata['data']['data']; + var body = '' + for (i in ulist){ + console.log(ulist[i]); + body += ''+ulist[i]["id"]+''+ + '' + ulist[i]["name"]+''+ + '' + ulist[i]["repo"]+''+ + '' + + '源码' + ' | ' + + '脚本' + ' | ' + + '源码' + + '' + + ''; + } + + $('#repo_list tbody').html(body); + $('#repo_list_page').html(rdata['data']['list']); + }); +} +function gogsRepoList() { + content = '
'; + content += '
'; + + content += '
'; + content += ''; + content += ''; + content += ''; + content += ''; + content += ''; + content += ''; + + content += ''; + content += '
序号用户/组织项目名操作
'; + + var page = ''; + + content += page; + + $(".soft-man-con").html(content); + + gogsRepoListPage(1); +} + + function projectScript(user, name,has_hook){ // console.log(user,name,has_hook); @@ -345,7 +409,7 @@ function gogsRead(){ var readme = '';