add files
This commit is contained in:
parent
37afebf1d0
commit
1b46b0dc9a
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,36 @@
|
||||||
|
# -*- coding:utf-8 -*-
|
||||||
|
'''
|
||||||
|
@Author:Robin
|
||||||
|
@Email: 329080237@qq.com
|
||||||
|
@Wechat: 15618110227
|
||||||
|
@File: admin.py
|
||||||
|
@Date: 2021/9/25 14:59
|
||||||
|
@Description:
|
||||||
|
'''
|
||||||
|
|
||||||
|
from web.git.base import RequestGit
|
||||||
|
from web.git.users import updateToken
|
||||||
|
|
||||||
|
def createUser(request, email, username, password):
|
||||||
|
api = "/admin/users"
|
||||||
|
formData = {
|
||||||
|
"email": email,
|
||||||
|
"full_name": username,
|
||||||
|
"login_name": username,
|
||||||
|
"must_change_password": False,
|
||||||
|
"password": password,
|
||||||
|
"send_notify": True,
|
||||||
|
"source_id": 0,
|
||||||
|
"username": username
|
||||||
|
}
|
||||||
|
res = RequestGit(request, api).post(formData, token=True)
|
||||||
|
if res.status_code == 201: #创建帐号成功
|
||||||
|
pass
|
||||||
|
# 更新 用户Token
|
||||||
|
#updateToken(request, username, password)
|
||||||
|
else:
|
||||||
|
# 创建失败(token已存在,其它原因失败!)
|
||||||
|
raise Exception("Gitea授权失败,请重新登录!")
|
||||||
|
|
||||||
|
#print(res.status_code)
|
||||||
|
return res.text
|
|
@ -0,0 +1,80 @@
|
||||||
|
# -*- coding:utf-8 -*-
|
||||||
|
'''
|
||||||
|
@Author:Robin
|
||||||
|
@Email: 329080237@qq.com
|
||||||
|
@Wechat: 15618110227
|
||||||
|
@File: api.py
|
||||||
|
@Date: 2021/9/24 17:20
|
||||||
|
@Description:
|
||||||
|
'''
|
||||||
|
|
||||||
|
import base64
|
||||||
|
import requests, json
|
||||||
|
|
||||||
|
class RequestGit:
|
||||||
|
|
||||||
|
def __init__(self, request, api):
|
||||||
|
self.url = "http://39.103.231.107:3000/api/v1" + api
|
||||||
|
self.username = request.session.get("username", "")
|
||||||
|
self.password = request.session.get("password", "")
|
||||||
|
self.access_token = request.session.get("access_token")
|
||||||
|
self.headers = {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
"Authorization": "Basic {}".format(self.getAuth()),
|
||||||
|
'Cookie': 'i_like_gitea=702577be6fb66a16; _csrf=0OFOibEHGY18vp0TNZhlblNuz6M6MTYzMjczMTg2NTk0MTc1MDI5NA',
|
||||||
|
}
|
||||||
|
|
||||||
|
#self.access_token = "7043f5103e78a74cd936d06da33dd47b33b2b05a"
|
||||||
|
|
||||||
|
|
||||||
|
def getAuth(self):
|
||||||
|
serect = self.username + ":" + self.password
|
||||||
|
auth = str(base64.b64encode(serect.encode("utf-8")), "utf-8")
|
||||||
|
return auth
|
||||||
|
|
||||||
|
|
||||||
|
def get(self, query=None, token=False):
|
||||||
|
if token:
|
||||||
|
request_url = self.url + "?access_token=" + self.access_token
|
||||||
|
else:
|
||||||
|
request_url = self.url
|
||||||
|
|
||||||
|
return requests.request("GET", request_url, headers=self.headers, params=query)
|
||||||
|
|
||||||
|
|
||||||
|
def post(self, payload=None, token=False):
|
||||||
|
# token = True 需要携带token访问,拼接成API URL
|
||||||
|
if token:
|
||||||
|
request_url = self.url + "?access_token=" + self.access_token
|
||||||
|
else:
|
||||||
|
request_url = self.url
|
||||||
|
|
||||||
|
return requests.request("POST", request_url, headers=self.headers, data=json.dumps(payload))
|
||||||
|
|
||||||
|
|
||||||
|
def put(self, payload=None, token=False):
|
||||||
|
# token = True 需要携带token访问,拼接成API URL
|
||||||
|
if token:
|
||||||
|
request_url = self.url + "?access_token=" + self.access_token
|
||||||
|
else:
|
||||||
|
request_url = self.url
|
||||||
|
|
||||||
|
return requests.request("PUT", request_url, headers=self.headers, data=json.dumps(payload))
|
||||||
|
|
||||||
|
|
||||||
|
def delete(self, payload=None, token=False):
|
||||||
|
if token:
|
||||||
|
request_url = self.url + "?access_token=" + self.access_token
|
||||||
|
else:
|
||||||
|
request_url = self.url
|
||||||
|
|
||||||
|
return requests.request("DELETE", request_url, headers=self.headers, data=json.dumps(payload))
|
||||||
|
|
||||||
|
def patch(self, payload=None, token=False):
|
||||||
|
# token = True 需要携带token访问,拼接成API URL
|
||||||
|
if token:
|
||||||
|
request_url = self.url + "?access_token=" + self.access_token
|
||||||
|
else:
|
||||||
|
request_url = self.url
|
||||||
|
|
||||||
|
return requests.request("PATCH", request_url, headers=self.headers, data=json.dumps(payload))
|
|
@ -0,0 +1,179 @@
|
||||||
|
# -*- coding:utf-8 -*-
|
||||||
|
'''
|
||||||
|
@Author:Robin
|
||||||
|
@Email: 329080237@qq.com
|
||||||
|
@Wechat: 15618110227
|
||||||
|
@File: issues.py
|
||||||
|
@Date: 2021/9/28 20:33
|
||||||
|
@Description:
|
||||||
|
'''
|
||||||
|
from utils.public import *
|
||||||
|
from .base import RequestGit
|
||||||
|
import json
|
||||||
|
|
||||||
|
def getIssues(request, owner, repo):
|
||||||
|
data = json.loads(request.GET.get("data"))
|
||||||
|
query = data.get("query")
|
||||||
|
payload = {}
|
||||||
|
if query:
|
||||||
|
payload = {
|
||||||
|
"page": query.get("pageNo", 1),
|
||||||
|
"limit": query.get("pageSize", 10),
|
||||||
|
"q": query.get("q"),
|
||||||
|
"state": query.get("state"),
|
||||||
|
"labels": query.get("labels")
|
||||||
|
}
|
||||||
|
console(payload)
|
||||||
|
api = "/repos/{}/{}/issues".format(owner, repo)
|
||||||
|
res = RequestGit(request, api).get(query=payload)
|
||||||
|
if res.status_code == 200:
|
||||||
|
items = json.loads(res.text)
|
||||||
|
total = res.headers['x-total-count']
|
||||||
|
else:
|
||||||
|
print(res.text)
|
||||||
|
raise Exception("获取issues列表信息失败!")
|
||||||
|
|
||||||
|
resData = {
|
||||||
|
"items": items,
|
||||||
|
"total": int(total)
|
||||||
|
}
|
||||||
|
#console(resData)
|
||||||
|
return jsonData(data=resData)
|
||||||
|
|
||||||
|
def issueDetail(request, owner, repo, id):
|
||||||
|
api = '/repos/{}/{}/issues/{}'.format(owner, repo, id)
|
||||||
|
res = RequestGit(request, api).get()
|
||||||
|
if res.status_code == 200:
|
||||||
|
items = json.loads(res.text)
|
||||||
|
else:
|
||||||
|
print(res.text)
|
||||||
|
raise Exception("获取issues详情失败!")
|
||||||
|
|
||||||
|
# console(resData)
|
||||||
|
return jsonData(data=items)
|
||||||
|
|
||||||
|
def createIssue(request, owner, repo):
|
||||||
|
data = json.loads(request.body)
|
||||||
|
payload = {
|
||||||
|
"title": data.get("title"),
|
||||||
|
"body": data.get("body")
|
||||||
|
}
|
||||||
|
print(payload)
|
||||||
|
api = "/repos/{}/{}/issues".format(owner, repo)
|
||||||
|
res = RequestGit(request, api).post(payload=payload)
|
||||||
|
if res.status_code == 201:
|
||||||
|
print('创建issue成功!')
|
||||||
|
else:
|
||||||
|
print(res.text)
|
||||||
|
raise Exception("创建issues失败!")
|
||||||
|
|
||||||
|
# console(resData)
|
||||||
|
return jsonData()
|
||||||
|
|
||||||
|
def updateIssue(request, owner, repo, id):
|
||||||
|
data = json.loads(request.body)
|
||||||
|
payload = {
|
||||||
|
"assignees": data.get("assignees")
|
||||||
|
}
|
||||||
|
|
||||||
|
print(payload)
|
||||||
|
api = "/repos/{}/{}/issues/{}".format(owner, repo, id)
|
||||||
|
res = RequestGit(request, api).patch(payload=payload)
|
||||||
|
if res.status_code == 201:
|
||||||
|
print('指派成员成功!')
|
||||||
|
else:
|
||||||
|
print(res.text)
|
||||||
|
raise Exception("指派成员失败!")
|
||||||
|
|
||||||
|
# console(resData)
|
||||||
|
return jsonData()
|
||||||
|
|
||||||
|
def getIssuesClosedTotal(request, owner, repo):
|
||||||
|
payload = {
|
||||||
|
"state": "closed"
|
||||||
|
}
|
||||||
|
api = "/repos/{}/{}/issues".format(owner, repo)
|
||||||
|
res = RequestGit(request, api).get(query=payload)
|
||||||
|
if res.status_code == 200:
|
||||||
|
total = res.headers['x-total-count']
|
||||||
|
else:
|
||||||
|
print(res.text)
|
||||||
|
raise Exception("获取issues 关闭数失败!")
|
||||||
|
|
||||||
|
resData = {
|
||||||
|
"total": int(total)
|
||||||
|
}
|
||||||
|
# console(resData)
|
||||||
|
return jsonData(data=resData)
|
||||||
|
|
||||||
|
|
||||||
|
def getRepoLabels(request, owner, repo):
|
||||||
|
api = "/repos/{}/{}/labels".format(owner, repo)
|
||||||
|
res = RequestGit(request, api).get()
|
||||||
|
if res.status_code == 200:
|
||||||
|
items = json.loads(res.text)
|
||||||
|
else:
|
||||||
|
print(res.text)
|
||||||
|
raise Exception("获取issues 关闭数失败!")
|
||||||
|
|
||||||
|
resData = {
|
||||||
|
"items": items,
|
||||||
|
"total": len(items)
|
||||||
|
}
|
||||||
|
# console(resData)
|
||||||
|
return jsonData(data=resData)
|
||||||
|
|
||||||
|
|
||||||
|
def getCollaborators(request, owner, repo):
|
||||||
|
api = "/repos/{}/{}/collaborators".format(owner, repo)
|
||||||
|
res = RequestGit(request, api).get(token=True)
|
||||||
|
if res.status_code == 200:
|
||||||
|
items = json.loads(res.text)
|
||||||
|
else:
|
||||||
|
print(res.text)
|
||||||
|
raise Exception("获取issues 关闭数失败!")
|
||||||
|
|
||||||
|
resData = {
|
||||||
|
"items": items,
|
||||||
|
"total": len(items)
|
||||||
|
}
|
||||||
|
# console(resData)
|
||||||
|
return jsonData(data=resData)
|
||||||
|
|
||||||
|
def createRepoLabel(request, owner, repo):
|
||||||
|
data = json.loads(request.body)
|
||||||
|
api = "/repos/{}/{}/labels".format(owner, repo)
|
||||||
|
res = RequestGit(request, api).post(token=True, payload=data)
|
||||||
|
|
||||||
|
if res.status_code == 201:
|
||||||
|
items = json.loads(res.text)
|
||||||
|
else:
|
||||||
|
print(res.text)
|
||||||
|
raise Exception("创建标签失败!")
|
||||||
|
|
||||||
|
return jsonData()
|
||||||
|
|
||||||
|
|
||||||
|
def delRepoLabel(request, owner, repo, id):
|
||||||
|
api = "/repos/{}/{}/labels/{}".format(owner, repo, id)
|
||||||
|
res = RequestGit(request, api).delete(token=True)
|
||||||
|
print(res)
|
||||||
|
if res.status_code == 204:
|
||||||
|
print('删除成功!')
|
||||||
|
else:
|
||||||
|
print(res.text)
|
||||||
|
raise Exception("删除标签失败!")
|
||||||
|
|
||||||
|
return jsonData()
|
||||||
|
|
||||||
|
def updateRepoLabel(request, owner, repo, id):
|
||||||
|
api = "/repos/{}/{}/labels/{}".format(owner, repo, id)
|
||||||
|
payload = json.loads(request.body)
|
||||||
|
res = RequestGit(request, api).patch(token=True, payload=payload)
|
||||||
|
if res.status_code == 200:
|
||||||
|
print('更新成功!')
|
||||||
|
else:
|
||||||
|
print(res.text)
|
||||||
|
raise Exception("修改标签失败!")
|
||||||
|
|
||||||
|
return jsonData()
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,244 @@
|
||||||
|
# -*- coding:utf-8 -*-
|
||||||
|
'''
|
||||||
|
@Author:Robin
|
||||||
|
@Email: 329080237@qq.com
|
||||||
|
@Wechat: 15618110227
|
||||||
|
@File: api.py
|
||||||
|
@Date: 2021/9/25 9:08
|
||||||
|
@Description:
|
||||||
|
'''
|
||||||
|
from utils.public import *
|
||||||
|
from .base import RequestGit
|
||||||
|
from django.db import transaction
|
||||||
|
import json, base64
|
||||||
|
|
||||||
|
@try_except
|
||||||
|
def getReposTags(request, full_name):
|
||||||
|
api = "/repos/"+ full_name +"/tags"
|
||||||
|
res = RequestGit(request, api).get()
|
||||||
|
data = json.loads(res.content)
|
||||||
|
tagList = [ i['name'] for i in data ]
|
||||||
|
return tagList
|
||||||
|
|
||||||
|
def getLanguages(request, owner, repo):
|
||||||
|
api = "/repos/{}/{}/languages".format(owner, repo)
|
||||||
|
res = RequestGit(request, api).get()
|
||||||
|
data = json.loads(res.text)
|
||||||
|
tagList = [i for i in data]
|
||||||
|
return tagList
|
||||||
|
|
||||||
|
@try_except
|
||||||
|
def search(request):
|
||||||
|
args = ("id", "name", "repo_name", "userKey__username", "content", "userKey__avatar", "score", "level")
|
||||||
|
items = Project.objects.exclude(private=1).values(*args).order_by("?")[:6]
|
||||||
|
|
||||||
|
#console(items)
|
||||||
|
|
||||||
|
# api = "/repos/search?page=1&limit=6"
|
||||||
|
# res = RequestGit(request, api).get()
|
||||||
|
# print(res.status_code)
|
||||||
|
# data = json.loads(res.content)
|
||||||
|
# items = data['data']
|
||||||
|
|
||||||
|
for i in items:
|
||||||
|
i['tagList'] = getLanguages(request, i["userKey__username"], i["repo_name"])
|
||||||
|
i['stars_count'] = ProjectTriple.objects.filter(projectKey=i['id'], type=2).count()
|
||||||
|
|
||||||
|
resData = {
|
||||||
|
"items": list(items),
|
||||||
|
"total": len(items)
|
||||||
|
}
|
||||||
|
#console(resData)
|
||||||
|
return jsonData(data=resData)
|
||||||
|
|
||||||
|
class CreateRepo:
|
||||||
|
|
||||||
|
def __init__(self, request, data, owner=None, repo=None):
|
||||||
|
self.userKey = request.session.get("user_id")
|
||||||
|
self.data = data
|
||||||
|
self.owner = owner
|
||||||
|
self.repo = repo
|
||||||
|
self.request = request
|
||||||
|
|
||||||
|
|
||||||
|
def project(self):
|
||||||
|
'''本地数据库创建项目'''
|
||||||
|
groupKey = self.data.get("groupKey")
|
||||||
|
if type(self.data.get("groupKey")) == list:
|
||||||
|
groupKey = [x for x in groupKey if x is not None].pop()
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
"name": self.data.get("name"),
|
||||||
|
"repo_name": self.data.get("repo_name"),
|
||||||
|
"content": self.data.get("content"),
|
||||||
|
"userKey_id": self.userKey,
|
||||||
|
"groupKey_id": groupKey,
|
||||||
|
"private": self.data.get("private")
|
||||||
|
}
|
||||||
|
Project.objects.create(**payload)
|
||||||
|
|
||||||
|
|
||||||
|
def repo_create(self):
|
||||||
|
api = "/user/repos"
|
||||||
|
payload = {
|
||||||
|
"name": self.data.get("repo_name"),
|
||||||
|
"description": self.data.get("content"),
|
||||||
|
"private": self.data.get("private"),
|
||||||
|
"license": self.data.get("license")
|
||||||
|
}
|
||||||
|
#console(data, payload)
|
||||||
|
res = RequestGit(self.request, api).post(payload=payload)
|
||||||
|
if res.status_code == 201:
|
||||||
|
print('创建仓库成功')
|
||||||
|
data = json.loads(res.text)
|
||||||
|
else:
|
||||||
|
print(res.text)
|
||||||
|
raise Exception("创建项目失败!")
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
|
def team(self):
|
||||||
|
'''将圈子中所有成员拉到项目群组中'''
|
||||||
|
username = self.request.session.get("username") # 拉取协助时排除自己
|
||||||
|
groupKey = self.data.get("groupKey")
|
||||||
|
# 前端返回的是数组,所以要进行过滤处理
|
||||||
|
if type(self.data.get("groupKey")) == list:
|
||||||
|
groupKey = [x for x in groupKey if x is not None].pop()
|
||||||
|
|
||||||
|
usernameList = GroupUsers.objects.exclude(userKey__username=username).filter(groupKey=groupKey).values_list('userKey__username', flat=True)
|
||||||
|
# console(usernameList)
|
||||||
|
for i in usernameList:
|
||||||
|
api = "/repos/{}/{}/collaborators/{}".format(self.owner, self.repo, i)
|
||||||
|
RequestGit(self.request, api).put()
|
||||||
|
|
||||||
|
@transaction.atomic
|
||||||
|
def create(request):
|
||||||
|
# 记录回滚点
|
||||||
|
sp = transaction.savepoint()
|
||||||
|
try:
|
||||||
|
data = json.loads(request.body)
|
||||||
|
CreateRepo(request, data).project() # 创建本地数据
|
||||||
|
res = CreateRepo(request, data).repo_create() # 创建Gitea仓库
|
||||||
|
CreateRepo(request, data, res['owner']['login'], res['name']).team() # 创建协作团队
|
||||||
|
resData = {"owner": res['owner']['login'], "repo": res['name']}
|
||||||
|
except:
|
||||||
|
# 如以上三步操作发生异常时,回滚事务
|
||||||
|
transaction.savepoint_rollback(sp)
|
||||||
|
raise Exception("创建项目失败!")
|
||||||
|
|
||||||
|
return jsonData(data=resData)
|
||||||
|
|
||||||
|
|
||||||
|
@try_except
|
||||||
|
def getRepo(request, owner, repo):
|
||||||
|
api = "/repos/"+owner+"/"+repo
|
||||||
|
res = RequestGit(request, api).get()
|
||||||
|
if res.status_code == 200:
|
||||||
|
data = json.loads(res.text)
|
||||||
|
else:
|
||||||
|
print(res.text)
|
||||||
|
raise Exception("获取项目信息失败!")
|
||||||
|
|
||||||
|
return jsonData(data=data)
|
||||||
|
|
||||||
|
@try_except
|
||||||
|
def getBranches(request, owner, repo):
|
||||||
|
'''获取项目分支列表'''
|
||||||
|
api = "/repos/"+ owner +"/"+ repo +"/branches"
|
||||||
|
res = RequestGit(request, api).get()
|
||||||
|
if res.status_code == 200:
|
||||||
|
data = json.loads(res.text)
|
||||||
|
else:
|
||||||
|
print(res.text)
|
||||||
|
raise Exception("获取项目分支信息失败!")
|
||||||
|
|
||||||
|
resData = {
|
||||||
|
"items": data
|
||||||
|
}
|
||||||
|
return jsonData(data=resData)
|
||||||
|
|
||||||
|
@try_except
|
||||||
|
def getCommits(request, owner, repo):
|
||||||
|
data = json.loads(request.GET.get("data"))
|
||||||
|
api = "/repos/{}/{}/commits?sha={}".format(owner, repo, data['sha'])
|
||||||
|
res = RequestGit(request, api).get()
|
||||||
|
if res.status_code == 200:
|
||||||
|
total = res.headers['X-Total']
|
||||||
|
else:
|
||||||
|
print(res.text)
|
||||||
|
raise Exception("获取提交数信息失败!")
|
||||||
|
|
||||||
|
resData = {
|
||||||
|
"total": total
|
||||||
|
}
|
||||||
|
#console(resData)
|
||||||
|
return jsonData(data=resData)
|
||||||
|
|
||||||
|
|
||||||
|
@try_except
|
||||||
|
def readme(request, owner, repo, filepath):
|
||||||
|
data = json.loads(request.GET.get("data"))
|
||||||
|
api = "/repos/{}/{}/contents/{}?ref={}".format(owner, repo, filepath, data['ref'])
|
||||||
|
res = RequestGit(request, api).get()
|
||||||
|
if res.status_code == 200:
|
||||||
|
data = json.loads(res.text)
|
||||||
|
content = str(base64.b64decode(data['content']), encoding="utf-8")
|
||||||
|
else:
|
||||||
|
content = ""
|
||||||
|
#print(res.text)
|
||||||
|
#raise Exception("获取readme.md失败!")
|
||||||
|
|
||||||
|
resData = {
|
||||||
|
"content": content
|
||||||
|
}
|
||||||
|
return jsonData(data=resData)
|
||||||
|
|
||||||
|
def getRepoTree(request, owner, repo):
|
||||||
|
data = json.loads(request.GET.get("data"))
|
||||||
|
ref = data.get("ref")
|
||||||
|
filepath = data.get("filepath")
|
||||||
|
if filepath:
|
||||||
|
api = "/repos/{}/{}/contents/{}?ref={}".format(owner, repo, filepath, ref)
|
||||||
|
else:
|
||||||
|
api = "/repos/{}/{}/contents?ref={}".format(owner, repo, ref)
|
||||||
|
|
||||||
|
res = RequestGit(request, api).get()
|
||||||
|
items = []
|
||||||
|
if res.status_code == 200:
|
||||||
|
data = json.loads(res.text)
|
||||||
|
items = sorted(data, key=lambda x: x["type"])
|
||||||
|
|
||||||
|
resData = {
|
||||||
|
"items": items
|
||||||
|
}
|
||||||
|
return jsonData(data=resData)
|
||||||
|
|
||||||
|
def downloadZIP(request, owner, repo):
|
||||||
|
data = json.loads(request.GET.get("data"))
|
||||||
|
ref = data.get("ref")
|
||||||
|
api = "/repos/{}/{}/archive/{}.zip".format(owner, repo, ref)
|
||||||
|
res = RequestGit(request, api).get()
|
||||||
|
if res.status_code == 200:
|
||||||
|
print("下载")
|
||||||
|
else:
|
||||||
|
print(res.text)
|
||||||
|
raise Exception("下载失败!")
|
||||||
|
|
||||||
|
return jsonData()
|
||||||
|
|
||||||
|
def lastCommit(request, owner, repo):
|
||||||
|
data = json.loads(request.GET.get("data"))
|
||||||
|
ref = data.get("ref")
|
||||||
|
api = "/repos/{}/{}/commits?sha={}&page=1&limit=1".format(owner, repo, ref)
|
||||||
|
res = RequestGit(request, api).get()
|
||||||
|
if res.status_code == 200:
|
||||||
|
data = json.loads(res.text)
|
||||||
|
committer = data[0]['commit']['author']
|
||||||
|
userInfo = User.objects.filter(username=committer["name"])
|
||||||
|
committer["avatar_url"] = userInfo[0].avatar if userInfo else None
|
||||||
|
committer["total"] = res.headers['X-Total-Count']
|
||||||
|
else:
|
||||||
|
print(res.text)
|
||||||
|
raise Exception("获取提交信息失败!")
|
||||||
|
|
||||||
|
return jsonData(data=committer)
|
|
@ -0,0 +1,45 @@
|
||||||
|
# -*- coding:utf-8 -*-
|
||||||
|
'''
|
||||||
|
@Author:Robin.lau
|
||||||
|
@Email: 329080237@qq.com
|
||||||
|
@Wechat: 15618110227
|
||||||
|
@File: urls.py
|
||||||
|
@Date: 2021/2/27 13:45
|
||||||
|
@Description: Api地址配置文件
|
||||||
|
'''
|
||||||
|
from django.urls import path
|
||||||
|
from web.git import repository, kernel, users, issues
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
|
||||||
|
# repos APIs 仓库/代码项目查询
|
||||||
|
path('repos/create/', repository.create), # 创建仓库
|
||||||
|
path('repos/search/', repository.search), # 查询公开项目列表
|
||||||
|
path('repos/<str:owner>/<str:repo>/', repository.getRepo), # 查询仓库详情信息
|
||||||
|
path('repos/<str:owner>/<str:repo>/branches/', repository.getBranches), # 获取项目分支列表
|
||||||
|
path('repos/<str:owner>/<str:repo>/commits', repository.getCommits), # 获取当前分支提交数
|
||||||
|
path('repos/<str:owner>/<str:repo>/contents/<str:filepath>', repository.readme), # 读取README.md
|
||||||
|
path('repos/<str:owner>/<str:repo>/contents/', repository.getRepoTree), # 获取分支目录树
|
||||||
|
# path('repos/<str:owner>/<str:repo>/downloadZIP/', repository.downloadZIP), # 下载分支
|
||||||
|
path('repos/<str:owner>/<str:repo>/lastCommit/', repository.lastCommit), # 获取分支最后一次提交者信息
|
||||||
|
|
||||||
|
# Issues APIs /repos/Write-Bug/write-bug/issues
|
||||||
|
path('repos/<str:owner>/<str:repo>/issues/', issues.getIssues), # 查询issues列表
|
||||||
|
path('repos/<str:owner>/<str:repo>/issues/<int:id>', issues.issueDetail), # 查询issues列表
|
||||||
|
path('repos/<str:owner>/<str:repo>/issues/create/', issues.createIssue), # 创建issue
|
||||||
|
path('repos/<str:owner>/<str:repo>/issues/update/<int:id>', issues.updateIssue), # 更新issue
|
||||||
|
path('repos/<str:owner>/<str:repo>/issuesClosedTotal/', issues.getIssuesClosedTotal), # 查询issues已关闭数
|
||||||
|
path('repos/<str:owner>/<str:repo>/getRepoLabels/', issues.getRepoLabels), # 查询issues中标签列表
|
||||||
|
path('repos/<str:owner>/<str:repo>/getCollaborators/', issues.getCollaborators), # 查询项目协作者列表
|
||||||
|
path('repos/<str:owner>/<str:repo>/createRepoLabel/', issues.createRepoLabel), # 创建标签
|
||||||
|
path('repos/<str:owner>/<str:repo>/updateRepoLabel/<int:id>', issues.updateRepoLabel), # 修改标签
|
||||||
|
path('repos/<str:owner>/<str:repo>/delRepoLabel/<int:id>', issues.delRepoLabel), # 删除标签
|
||||||
|
|
||||||
|
# 项目评估
|
||||||
|
path('kernel/code_analysis_result_call_back/', kernel.code_analysis_result_call_back), # 生成项目评估报告 回调
|
||||||
|
path('code_analysis_test/', kernel.code_analysis_test), # 发送评估请求
|
||||||
|
path('kernel/reportView/', kernel.reportView) # 评估报告总览
|
||||||
|
|
||||||
|
|
||||||
|
# users APIs
|
||||||
|
]
|
|
@ -0,0 +1,39 @@
|
||||||
|
# -*- coding:utf-8 -*-
|
||||||
|
'''
|
||||||
|
@Author:Robin
|
||||||
|
@Email: 329080237@qq.com
|
||||||
|
@Wechat: 15618110227
|
||||||
|
@File: admin.py
|
||||||
|
@Date: 2021/9/25 14:59
|
||||||
|
@Description:
|
||||||
|
'''
|
||||||
|
|
||||||
|
from web.git.base import RequestGit
|
||||||
|
from web.models import User
|
||||||
|
from utils.public import try_except, jsonData, console
|
||||||
|
import json
|
||||||
|
|
||||||
|
@try_except
|
||||||
|
def updateToken(request, username):
|
||||||
|
console(username)
|
||||||
|
item = User.objects.filter(username=username)
|
||||||
|
access_token = item[0].access_token if item else None
|
||||||
|
console(access_token)
|
||||||
|
if access_token is None:
|
||||||
|
api = "/users/"+username+"/tokens"
|
||||||
|
payload = {"name": username}
|
||||||
|
res = RequestGit(request, api).post(payload)
|
||||||
|
if res.status_code == 201: #创建Token成功
|
||||||
|
data = json.loads(res.text)
|
||||||
|
token = data.get("sha1")
|
||||||
|
User.objects.filter(username=username).update(access_token=token)
|
||||||
|
request.session['access_token'] = token
|
||||||
|
else:
|
||||||
|
# 创建失败(token已存在,其它原因失败!)
|
||||||
|
print(res.text)
|
||||||
|
raise Exception("Gitea授权失败,请重新登录!")
|
||||||
|
else:
|
||||||
|
request.session['access_token'] = access_token
|
||||||
|
|
||||||
|
|
||||||
|
return jsonData()
|
Loading…
Reference in New Issue