Compare commits

...

17 Commits

Author SHA1 Message Date
刘德华 45c5ffd18f 回滚 2024-07-13 02:52:27 +08:00
刘德华 b85c7ce9f6 1 2024-07-13 02:47:07 +08:00
刘德华 eb1ce45c4d 1 2024-07-13 02:37:22 +08:00
刘德华 4080689fcf 1 2024-07-13 02:31:32 +08:00
刘德华 6b5ae8e652 最终版本 2024-07-13 01:49:31 +08:00
刘德华 50df735f21 解决报错 2024-07-13 01:43:52 +08:00
刘德华 64a7fe5075 1 2024-07-13 00:57:57 +08:00
刘德华 5dcf8a78f7 1 2024-07-13 00:31:17 +08:00
刘德华 6c4e811183 1 2024-07-13 00:20:58 +08:00
刘德华 dd32140696 1 2024-07-13 00:13:54 +08:00
刘德华 4e5d5672ce 更新dockerfile 2024-07-13 00:06:34 +08:00
吴舒先 33a3763410 合并远程 2024-07-10 00:33:52 +08:00
吴舒先 eb61024190 添加issue相关配置 2024-07-10 00:30:39 +08:00
SheYuWu03 b35babf90b refactor: .devops/test.yml 2024-06-25 04:15:49 +00:00
SheYuWu03 0b14ed7a0f feat: .devops/test.yml 2024-06-25 04:15:46 +00:00
qinxiaonan_branch c8abeb9520 补充查看日志失败的效果 2024-06-24 15:54:48 +08:00
qinxiaonan_branch 86285f352d test 2024-06-06 20:11:42 +08:00
9 changed files with 410 additions and 16 deletions

61
.devops/test.yml Normal file
View File

@ -0,0 +1,61 @@
version: 2
name: test
description: ""
global:
concurrent: 1
trigger:
webhook: gitlink@1.0.0
event:
- ref: pr
ruleset:
- param-ref: target_branch
operator: EQ
value: '"master"'
ruleset-operator: AND
workflow:
- ref: start
name: 开始
task: start
- ref: git_clone_0
name: git clone
task: git_clone@1.2.9
input:
remote_url: '"https://gitlink.org.cn/SheYuWu03/reposync.git"'
ref: '"refs/heads/master"'
commit_id: '""'
depth: 1
needs:
- start
- ref: docker_image_build_0
name: docker镜像构建
task: docker_image_build@1.6.0
input:
image_name: '"registry.cn-guangzhou.aliyuncs.com/nudt_devops/gitlink_help_center"'
image_tag: '"latest"'
registry_address: '"registry.cn-guangzhou.aliyuncs.com"'
docker_file: '"Dockerfile"'
docker_build_path: '"."'
workspace: git_clone_0.git_path
image_push: true
build_args: '""'
needs:
- git_clone_0
- ref: ssh_cmd_0
name: ssh执行命令
task: ssh_cmd@1.1.1
input:
ssh_ip: '"116.62.120.115"'
ssh_port: '"22"'
ssh_user: '"root"'
ssh_cmd: '"docker stop ghc_group6 && docker rm ghc_group6 && docker pull
registry.cn-guangzhou.aliyuncs.com/nudt_devops/gitlink_help_center_group6:latest
&& docker run -d -p 3000:3000 --name ghc_group6
registry.cn-guangzhou.aliyuncs.com/nudt_devops/gitlink_help_center_group6:latest"'
needs:
- docker_image_build_0
- ref: end
name: 结束
task: end
needs:
- ssh_cmd_0

View File

@ -0,0 +1,138 @@
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<!-- CentOS customization -->
<link rel="stylesheet" href="/centos-design/css/centos.css">
<link rel="stylesheet" href="/centos-design/css/centos-listindex.css">
<!-- Favicon -->
<link href="/centos-design/images/favicon.ico" rel="icon" type="image/ico" />
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Exo+2&display=swap" rel="stylesheet">
<title>CentOS Mirrors List</title>
</head>
<body class="d-flex flex-column h-100">
<header>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
<a class="navbar-brand" href="https://www.centos.org/">
<img src="/centos-design/images/centos-logo-white.png" height="32" alt="CentOS">
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="https://www.centos.org/download">Download</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
About
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="https://www.centos.org/about/">About CentOS</a>
<a class="dropdown-item" href="https://wiki.centos.org/FAQ">Frequently Asked Questions (FAQs)</a>
<a class="dropdown-item" href="https://wiki.centos.org/SpecialInterestGroup">Special Interest Groups (SIGs)</a>
<a class="dropdown-item" href="https://www.centos.org/variants/">CentOS Variants</a>
<a class="dropdown-item" href="https://www.centos.org/about/governance/">Governance</a>
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Community
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="https://wiki.centos.org/Contribute">Contribute</a>
<a class="dropdown-item" href="https://www.centos.org/forums/">Forums</a>
<a class="dropdown-item" href="https://wiki.centos.org/GettingHelp/ListInfo">Mailing Lists</a>
<a class="dropdown-item" href="https://wiki.centos.org/irc">IRC</a>
<a class="dropdown-item" href="https://www.centos.org/community/calendar/">Calendar &amp; IRC Meeting List</a>
<a class="dropdown-item" href="http://planet.centos.org/">Planet</a>
<a class="dropdown-item" href="https://bugs.centos.org/">Submit a Bug</a>
<a class="dropdown-item" href="https://www.centos.org/community/stories/">Stories</a>
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Documentation
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="https://wiki.centos.org/">Wiki</a>
<a class="dropdown-item" href="https://docs.centos.org/">Manuals</a>
<a class="dropdown-item" href="https://www.centos.org/keys">GPG Key Info</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="https://wiki.centos.org/Documentation?action=show&redirect=GettingHelp">Help</a>
</li>
</ul>
</div>
</nav>
</header>
<main>
<div class="container mt-4 mb-4">
<b>In order to conserve the limited bandwidth available, ISO images are not downloadable from mirror.centos.org<br><br>
<div class="alert alert-success" role="alert">The following mirrors in your region should have the ISO images available:</b><br></div>
<a href='http://ftp.sjtu.edu.cn/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso'>http://ftp.sjtu.edu.cn/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso</a><br>
<a href='http://mirrors.ustc.edu.cn/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso'>http://mirrors.ustc.edu.cn/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso</a><br>
<a href='http://mirrors.nju.edu.cn/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso'>http://mirrors.nju.edu.cn/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso</a><br>
<a href='http://mirrors.jlu.edu.cn/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso'>http://mirrors.jlu.edu.cn/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso</a><br>
<a href='http://mirrors.cqu.edu.cn/CentOS/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso'>http://mirrors.cqu.edu.cn/CentOS/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso</a><br>
<a href='http://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso'>http://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso</a><br>
<a href='http://mirrors.aliyun.com/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso'>http://mirrors.aliyun.com/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso</a><br>
<a href='http://mirrors.bupt.edu.cn/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso'>http://mirrors.bupt.edu.cn/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso</a><br>
<br><div class="alert alert-info" role="alert"><b>Other mirrors further away:</b></div>
<a href='http://ftp.ksu.edu.tw/pub/CentOS/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso'>http://ftp.ksu.edu.tw/pub/CentOS/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso</a><br>
<a href='http://ftp.twaren.net/Linux/CentOS/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso'>http://ftp.twaren.net/Linux/CentOS/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso</a><br>
<a href='http://mirror.xtom.com.hk/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso'>http://mirror.xtom.com.hk/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso</a><br>
<a href='http://mirror-hk.koddos.net/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso'>http://mirror-hk.koddos.net/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso</a><br>
<a href='http://ftp.kaist.ac.kr/CentOS/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso'>http://ftp.kaist.ac.kr/CentOS/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso</a><br>
<a href='http://mirror.anigil.com/CentOS/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso'>http://mirror.anigil.com/CentOS/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso</a><br>
<a href='http://mirror.navercorp.com/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso'>http://mirror.navercorp.com/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso</a><br>
<a href='http://mirror.kakao.com/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso'>http://mirror.kakao.com/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso</a><br>
<a href='http://mirror.elice.io/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso'>http://mirror.elice.io/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso</a><br>
<a href='http://download.nus.edu.sg/mirror/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso'>http://download.nus.edu.sg/mirror/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso</a><br>
<a href='http://mirror.aktkn.sg/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso'>http://mirror.aktkn.sg/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso</a><br>
<a href='http://ftp.iij.ad.jp/pub/linux/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso'>http://ftp.iij.ad.jp/pub/linux/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso</a><br>
<a href='http://ftp.nara.wide.ad.jp/pub/Linux/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso'>http://ftp.nara.wide.ad.jp/pub/Linux/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso</a><br>
<a href='http://mirrors.cat.net/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso'>http://mirrors.cat.net/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso</a><br>
<a href='http://ftp.yz.yamagata-u.ac.jp/pub/linux/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso'>http://ftp.yz.yamagata-u.ac.jp/pub/linux/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso</a><br>
<a href='http://ftp.jaist.ac.jp/pub/Linux/CentOS/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso'>http://ftp.jaist.ac.jp/pub/Linux/CentOS/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso</a><br>
<a href='http://ftp-srv2.kddilabs.jp/Linux/packages/CentOS/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso'>http://ftp-srv2.kddilabs.jp/Linux/packages/CentOS/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso</a><br>
<a href='http://ftp.tsukuba.wide.ad.jp/Linux/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso'>http://ftp.tsukuba.wide.ad.jp/Linux/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso</a><br>
<a href='http://ftp.riken.jp/Linux/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso'>http://ftp.riken.jp/Linux/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso</a><br>
<a href='http://mirror.datacenter.mn/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso'>http://mirror.datacenter.mn/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso</a><br>
<a href='http://mirror.docker.ru/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso'>http://mirror.docker.ru/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso</a><br>
<a href='http://mirror.truenetwork.ru/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso'>http://mirror.truenetwork.ru/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso</a><br>
+ others, see the full list of mirrors: <a href='https://www.centos.org/download/mirrors/'>https://www.centos.org/download/mirrors/</a><br><br>Mirrors verified Thu Jun 27 12:08:02 2024 UTC<br><br>You can also download the ISO images using <a href='https://en.wikipedia.org/wiki/BitTorrent'>bittorrent</a>, a peer-to-peer file sharing protocol. The .torrent files can be found from CentOS mirrors. Various bittorrent clients are available, including (in no particular order of preference): utorrent, vuze (Azureus), BitTorrent, Deluge, ctorrent, ktorrent, rtorrent and transmission. Packaged copies of various torrent clients for CentOS can be found in the repositories listed in the following wiki article: <a href='https://wiki.centos.org/AdditionalResources/Repositories'>https://wiki.centos.org/AdditionalResources/Repositories</a>
</div>
</main>
<footer class="footer pt-2 bg-light sticky-bottom">
<div class="container mt-4">
<p class="text-muted credit text-center">&copy; 2019 The CentOS Project | <a href="https://www.centos.org/legal/">Legal</a> | <a href="https://www.centos.org/legal/privacy/">Privacy</a></p>
</div>
</footer>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>

View File

@ -1,18 +1,32 @@
FROM centos:7
FROM quay.io/centos/centos:7
RUN yum update -y && \
RUN curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo && \
yum makecache && \
yum update -y && \
yum install -y wget gcc make openssl-devel bzip2-devel libffi-devel zlib-devel
RUN wget -P /data/ob-tool https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tgz
RUN cd /data/ob-tool && tar xzf Python-3.9.6.tgz
RUN cd /data/ob-tool/Python-3.9.6 && ./configure --enable-optimizations && make altinstall
# 下载并安装Python 3.9.6
RUN wget -P /data/ob-tool https://mirrors.huaweicloud.com/python/3.9.6/Python-3.9.6.tgz && \
cd /data/ob-tool && \
tar xzf Python-3.9.6.tgz && \
cd Python-3.9.6 && \
./configure --enable-optimizations && \
make altinstall
# 将项目文件复制到容器中
ADD ./ /data/ob-robot/
RUN cd /data/ob-robot/ && \
pip3.9 install -r /data/ob-robot/requirement.txt
RUN yum install -y git openssh-server
RUN pip3.9 install -r /data/ob-robot/requirement.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/
# 安装Git和OpenSSH服务器
RUN yum install -y git openssh-server
# 设置Git SSH连接配置
ENV GIT_SSH_COMMAND='ssh -o StrictHostKeyChecking=no -i /root/.ssh/id_rsa'
# 安装autoconf和gettext并编译安装Git 2.32.0
RUN yum install -y autoconf gettext && \
wget http://github.com/git/git/archive/v2.32.0.tar.gz && \
tar -xvf v2.32.0.tar.gz && \
@ -23,5 +37,8 @@ RUN yum install -y autoconf gettext && \
make -j16 && \
make install
# 设置工作目录
WORKDIR /data/ob-robot
CMD if [ "$BOOT_MODE" = "app" ] ; then python3.9 main.py; fi
# 定义启动命令
CMD if [ "$BOOT_MODE" = "app" ]; then python3.9 main.py; fi

View File

@ -10,7 +10,7 @@ import src.api.Log
import src.api.Auth
import src.api.Sync_config
from extras.obfastapi.frame import OBFastAPI
from src.router import CE_ROBOT, PROJECT, JOB, ACCOUNT, PULL_REQUEST, USER, LOG, AUTH, SYNC_CONFIG
from src.router import CE_ROBOT, PROJECT, JOB, ACCOUNT, PULL_REQUEST, USER, LOG, AUTH, SYNC_CONFIG, ISSUES
from fastapi.staticfiles import StaticFiles
app = OBFastAPI()
@ -24,6 +24,7 @@ app.include_router(USER)
app.include_router(LOG)
app.include_router(AUTH)
app.include_router(SYNC_CONFIG)
app.include_router(ISSUES)
app.mount("/", StaticFiles(directory="web/dist"), name="static")

View File

@ -1,5 +1,5 @@
uvicorn==0.14.0
SQLAlchemy==1.4.21
uvicorn>=0.14.0
SQLAlchemy>=1.4.21
fastapi==0.66.0
aiohttp==3.7.4.post0
pydantic==1.8.2

View File

@ -5,9 +5,11 @@ from fastapi import (
Query,
Depends,
Security,
Body
Body,
requests
)
from typing import Optional
import requests
from starlette.exceptions import HTTPException
@ -17,11 +19,13 @@ from extras.obfastapi.frame import OBResponse as Response
from src.base.code import Code
from src.base.error_code import ErrorTemplate, Errors
from src.router import PULL_REQUEST as pull_request
from src.router import ISSUES as issues
from src.api.Controller import APIController as Controller
from src.dto.pull_request import PullRequest as PullRequestData
from src.service.pull_request import PullRequestService
from src.service.sync import ProjectService
from src.utils import github
from src.utils import gitee
class PullRequest(Controller):
@ -36,10 +40,11 @@ class PullRequest(Controller):
search: Optional[str] = Query(None, description='搜索内容'),
orderby: Optional[str] = Query(None, description='排序选项')
):
# 项目是否存在
await self._check_project(name)
pull_request_service = PullRequestService()
count = await pull_request_service.count_pull_request(name)
answer = await pull_request_service.fetch_pull_request(name)
answer = await pull_request_service.fetch_pull_request(name) # 获取所有PR信息从哪里
if not answer:
logger.info(f"The project {name} has no pull request")
answer = []
@ -48,20 +53,25 @@ class PullRequest(Controller):
data=DataList(total=count, list=answer)
)
@pull_request.get("/projects/{name}/pullrequests/sync", response_model=Response, description='列出pull request')
@pull_request.get("/projects/{name}/pullrequests/sync", response_model=Response, description='同步pull request')
async def sync_pull_request(
self,
name: str = Query(..., description='工程名字')
):
# 项目是否存在查sync_project表,同时获取数据库中的一条完整记录
resp = await self._check_project(name)
# 解析 resp 获取需要的信息(仓库地址、名字等)
organization, repo = github.transfer_github_to_name(
resp[0].github_address)
# 如果仓库存在,执行同步操作
if organization and repo:
pull_request_service = PullRequestService()
await pull_request_service.sync_pull_request(name, organization, repo)
else:
# 否则抛出异常
logger.error(f"The pull rquest of project {name} sync failed")
raise Errors.QUERY_FAILD
# 返回响应信息
return Response(
code=Code.SUCCESS,
msg="发送同意请求成功"
@ -173,9 +183,61 @@ class PullRequest(Controller):
async def _check_project(self, name: str):
project_service = ProjectService()
resp = await project_service.search_project(name=name)
resp = await project_service.search_project(name=name) # 从sync_project中查询项目是否存在
if len(resp) == 0:
logger.error(
f"The project {name} is not exist")
raise Errors.QUERY_FAILD
return resp
@pull_request.get("/projects/{name}/pullrequests/", description='获取指定仓库的PR')
async def fetch_pull_request(
self,
domain: str = Query(..., description='平台'),
owner: str = Query(..., description='仓库所有者'),
repo: str = Query(..., description='仓库名称'),
token: str = Query(..., description='用户token'),
state: str = Query(None, description='可选PR的状态'),
):
try:
if 'gitee' in domain:
if state:
url = f'https://gitee.com/api/v5/repos/{owner}/{repo}/pulls?state={state}'
else:
url = f'https://gitee.com/api/v5/repos/{owner}/{repo}/pulls'
elif 'gitlink' in domain:
url = f'https://www.gitlink.org.cn/api/v1/{owner}/{repo}/pulls.json'
headers = {
'Authorization': f'token {token}'
}
response = requests.get(url, headers=headers)
response.raise_for_status() # 如果请求返回了不成功的状态码,就会产生一个 HTTPError 异常。
return response.json()
except requests.HTTPError as errh:
raise HTTPException(status_code=400, detail=str(errh))
except requests.RequestException as err:
raise HTTPException(status_code=500, detail=str(err))
@pull_request.get("/projects/{name}/pullrequests/test", description='测试接口')
async def testInterface(
self,
token: str = Query(..., description='用户授权码'),
owner: str = Query(..., description='仓库所有者'),
repo: str = Query(..., description='仓库名称'),
state: str = Query(None, description='可选PR的状态'),
):
return gitee.fetch_gitee_pull_request(token, owner, repo, state)
class Issues(Controller):
def get_user(self, cookie_key=Security(Controller.API_KEY_BUC_COOKIE), token: str = None):
return super().get_user(cookie_key=cookie_key, token=token)
@issues.get("/fetch/issues", description='获取issues列表')
async def get_issues(
self,
owner: str = Query(..., description= '仓库所有者'),
repo: str = Query(..., description='仓库名称')
):
issue_list = gitee.fetch_gitee_issues(owner, repo)
return issue_list

View File

@ -1,6 +1,9 @@
import re
import requests
from typing import Optional
from fastapi import HTTPException
from src.base import config
from src.utils.logger import logger
@ -37,3 +40,75 @@ def get_gitee_address_with_token(http_address: str, token: str) -> str:
return http_address[:8] + owner_name + ":" + token + '@' + http_address[8:]
except Exception as e:
print(e)
def fetch_gitee_pull_request(token: str, owner: str, repo: str, state: str = None):
"""
获取指定仓库的PR数据
Attributes
token 用户授权码
owner 仓库拥有者
repo 仓库名称
state 可选PR的状态
"""
# 根据state决定request的地址
if state:
url = f'https://gitee.com/api/v5/repos/{owner}/{repo}/pulls?state={state}'
else:
url = f'https://gitee.com/api/v5/repos/{owner}/{repo}/pulls'
# 请求头的内容
headers = {
'Authorization': f'token {token}'
}
response = requests.get(url, headers=headers)
pull_requests = response.json()
data = []
for pull_request in pull_requests:
data_item = {
'pull_request_id': pull_request['id'],
'project': repo,
'title': pull_request['title'],
'type': 'Gitee',
'address': pull_request['html_url'],
'author': pull_request['user']['login'],
'email': None,
'target_branch': pull_request['base']['ref'],
'latest_commit': pull_request['head']['sha'],
'inline': pull_request['base']['repo']['internal'],
}
data.append(data_item)
return data
def create_pull_request(owner: str, repo: str, title: str, head: str, base: str):
"""
创建一个合并请求
Attributes:
owner 仓库拥有者
repo 仓库名称
title PR的标题
head PR提交的源分支
base PR的目标分支
"""
pass
def fetch_gitee_issues(owner: str, repo: str):
url = f'https://gitee.com/api/v5/repos/{owner}/{repo}/issues'
response = requests.get(url)
issues = response.json()
issue_list = []
for issue in issues:
state = 1
if issue['state'] == 'progressing':
state = 2
elif issue['state'] == 'closed':
state = 5
elif issue['state'] == 'rejected':
state = 6
issue_item = {
'status_id': state,
'priority_id': 1,
'subject': issue['title'],
'description': issue['body']
}
issue_list.append(issue_item)
return issue_list

1
test.txt Normal file
View File

@ -0,0 +1 @@
test

View File

@ -41,3 +41,42 @@ export default (props: Props) => {
</Modal>
);
};
export default (props) => {
// ...解构 props 和定义其他状态...
const [error, setError] = useState(null); // 添加错误状态
useEffect(() => {
fetchJobLog({ name, id })
.then(response => {
// 处理成功的情况,例如设置数据状态等
})
.catch(error => {
setError(error); // 捕获错误并设置错误状态
message.error('获取日志失败,请稍后重试或联系管理员。'); // 显示错误提示信息
});
}, [name, id]); // 依赖数组中添加 name 和 id
// ...其他代码保持不变...
return (
<Modal
// ...其他属性保持不变...
>
<Spin spinning={loading}>
{error ? (
// 如果存在错误,展示错误信息
<div style={{ padding: '20px', textAlign: 'center' }}>
<b></b> {error.message || '未知错误'}
</div>
) : (
// 正常渲染日志列表
logsData?.data?.list?.map((item, index) => (
// ...渲染日志项...
))
)}
</Spin>
</Modal>
);
};