初步完成gitlink平台两个仓库疑修迁移工作,还有问题待解决
This commit is contained in:
parent
fbea8f35cb
commit
2773a17142
|
@ -0,0 +1,8 @@
|
|||
venv
|
||||
.idea
|
||||
*.pyc
|
||||
__pycache__
|
||||
pics/*
|
||||
cache/*
|
||||
*.pyc
|
||||
*.db
|
|
@ -0,0 +1,15 @@
|
|||
[[source]]
|
||||
url = "http://173.15.15.82:8081/repository/group-pypi/simple"
|
||||
verify_ssl = false
|
||||
name = "pip_conf_index_global"
|
||||
|
||||
[packages]
|
||||
requests = "*"
|
||||
loguru = "*"
|
||||
requests-toolbelt = "*"
|
||||
|
||||
[dev-packages]
|
||||
|
||||
[requires]
|
||||
python_version = "3.9"
|
||||
python_full_version = "3.9.5"
|
|
@ -0,0 +1,167 @@
|
|||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "7c1d05fb59ca92a8215dd57f68dad3e55dd7bcc96d87a048297c995b7ac8d2c4"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
"python_full_version": "3.9.5",
|
||||
"python_version": "3.9"
|
||||
},
|
||||
"sources": [
|
||||
{
|
||||
"name": "pip_conf_index_global",
|
||||
"url": "http://173.15.15.82:8081/repository/group-pypi/simple",
|
||||
"verify_ssl": false
|
||||
}
|
||||
]
|
||||
},
|
||||
"default": {
|
||||
"certifi": {
|
||||
"hashes": [
|
||||
"sha256:35824b4c3a97115964b408844d64aa14db1cc518f6562e8d7261699d1350a9e3",
|
||||
"sha256:4ad3232f5e926d6718ec31cfc1fcadfde020920e278684144551c91769c7bc18"
|
||||
],
|
||||
"markers": "python_version >= '3.6'",
|
||||
"version": "==2022.12.7"
|
||||
},
|
||||
"charset-normalizer": {
|
||||
"hashes": [
|
||||
"sha256:04afa6387e2b282cf78ff3dbce20f0cc071c12dc8f685bd40960cc68644cfea6",
|
||||
"sha256:04eefcee095f58eaabe6dc3cc2262f3bcd776d2c67005880894f447b3f2cb9c1",
|
||||
"sha256:0be65ccf618c1e7ac9b849c315cc2e8a8751d9cfdaa43027d4f6624bd587ab7e",
|
||||
"sha256:0c95f12b74681e9ae127728f7e5409cbbef9cd914d5896ef238cc779b8152373",
|
||||
"sha256:0ca564606d2caafb0abe6d1b5311c2649e8071eb241b2d64e75a0d0065107e62",
|
||||
"sha256:10c93628d7497c81686e8e5e557aafa78f230cd9e77dd0c40032ef90c18f2230",
|
||||
"sha256:11d117e6c63e8f495412d37e7dc2e2fff09c34b2d09dbe2bee3c6229577818be",
|
||||
"sha256:11d3bcb7be35e7b1bba2c23beedac81ee893ac9871d0ba79effc7fc01167db6c",
|
||||
"sha256:12a2b561af122e3d94cdb97fe6fb2bb2b82cef0cdca131646fdb940a1eda04f0",
|
||||
"sha256:12d1a39aa6b8c6f6248bb54550efcc1c38ce0d8096a146638fd4738e42284448",
|
||||
"sha256:1435ae15108b1cb6fffbcea2af3d468683b7afed0169ad718451f8db5d1aff6f",
|
||||
"sha256:1c60b9c202d00052183c9be85e5eaf18a4ada0a47d188a83c8f5c5b23252f649",
|
||||
"sha256:1e8fcdd8f672a1c4fc8d0bd3a2b576b152d2a349782d1eb0f6b8e52e9954731d",
|
||||
"sha256:20064ead0717cf9a73a6d1e779b23d149b53daf971169289ed2ed43a71e8d3b0",
|
||||
"sha256:21fa558996782fc226b529fdd2ed7866c2c6ec91cee82735c98a197fae39f706",
|
||||
"sha256:22908891a380d50738e1f978667536f6c6b526a2064156203d418f4856d6e86a",
|
||||
"sha256:3160a0fd9754aab7d47f95a6b63ab355388d890163eb03b2d2b87ab0a30cfa59",
|
||||
"sha256:322102cdf1ab682ecc7d9b1c5eed4ec59657a65e1c146a0da342b78f4112db23",
|
||||
"sha256:34e0a2f9c370eb95597aae63bf85eb5e96826d81e3dcf88b8886012906f509b5",
|
||||
"sha256:3573d376454d956553c356df45bb824262c397c6e26ce43e8203c4c540ee0acb",
|
||||
"sha256:3747443b6a904001473370d7810aa19c3a180ccd52a7157aacc264a5ac79265e",
|
||||
"sha256:38e812a197bf8e71a59fe55b757a84c1f946d0ac114acafaafaf21667a7e169e",
|
||||
"sha256:3a06f32c9634a8705f4ca9946d667609f52cf130d5548881401f1eb2c39b1e2c",
|
||||
"sha256:3a5fc78f9e3f501a1614a98f7c54d3969f3ad9bba8ba3d9b438c3bc5d047dd28",
|
||||
"sha256:3d9098b479e78c85080c98e1e35ff40b4a31d8953102bb0fd7d1b6f8a2111a3d",
|
||||
"sha256:3dc5b6a8ecfdc5748a7e429782598e4f17ef378e3e272eeb1340ea57c9109f41",
|
||||
"sha256:4155b51ae05ed47199dc5b2a4e62abccb274cee6b01da5b895099b61b1982974",
|
||||
"sha256:49919f8400b5e49e961f320c735388ee686a62327e773fa5b3ce6721f7e785ce",
|
||||
"sha256:53d0a3fa5f8af98a1e261de6a3943ca631c526635eb5817a87a59d9a57ebf48f",
|
||||
"sha256:5f008525e02908b20e04707a4f704cd286d94718f48bb33edddc7d7b584dddc1",
|
||||
"sha256:628c985afb2c7d27a4800bfb609e03985aaecb42f955049957814e0491d4006d",
|
||||
"sha256:65ed923f84a6844de5fd29726b888e58c62820e0769b76565480e1fdc3d062f8",
|
||||
"sha256:6734e606355834f13445b6adc38b53c0fd45f1a56a9ba06c2058f86893ae8017",
|
||||
"sha256:6baf0baf0d5d265fa7944feb9f7451cc316bfe30e8df1a61b1bb08577c554f31",
|
||||
"sha256:6f4f4668e1831850ebcc2fd0b1cd11721947b6dc7c00bf1c6bd3c929ae14f2c7",
|
||||
"sha256:6f5c2e7bc8a4bf7c426599765b1bd33217ec84023033672c1e9a8b35eaeaaaf8",
|
||||
"sha256:6f6c7a8a57e9405cad7485f4c9d3172ae486cfef1344b5ddd8e5239582d7355e",
|
||||
"sha256:7381c66e0561c5757ffe616af869b916c8b4e42b367ab29fedc98481d1e74e14",
|
||||
"sha256:73dc03a6a7e30b7edc5b01b601e53e7fc924b04e1835e8e407c12c037e81adbd",
|
||||
"sha256:74db0052d985cf37fa111828d0dd230776ac99c740e1a758ad99094be4f1803d",
|
||||
"sha256:75f2568b4189dda1c567339b48cba4ac7384accb9c2a7ed655cd86b04055c795",
|
||||
"sha256:78cacd03e79d009d95635e7d6ff12c21eb89b894c354bd2b2ed0b4763373693b",
|
||||
"sha256:80d1543d58bd3d6c271b66abf454d437a438dff01c3e62fdbcd68f2a11310d4b",
|
||||
"sha256:830d2948a5ec37c386d3170c483063798d7879037492540f10a475e3fd6f244b",
|
||||
"sha256:891cf9b48776b5c61c700b55a598621fdb7b1e301a550365571e9624f270c203",
|
||||
"sha256:8f25e17ab3039b05f762b0a55ae0b3632b2e073d9c8fc88e89aca31a6198e88f",
|
||||
"sha256:9a3267620866c9d17b959a84dd0bd2d45719b817245e49371ead79ed4f710d19",
|
||||
"sha256:a04f86f41a8916fe45ac5024ec477f41f886b3c435da2d4e3d2709b22ab02af1",
|
||||
"sha256:aaf53a6cebad0eae578f062c7d462155eada9c172bd8c4d250b8c1d8eb7f916a",
|
||||
"sha256:abc1185d79f47c0a7aaf7e2412a0eb2c03b724581139193d2d82b3ad8cbb00ac",
|
||||
"sha256:ac0aa6cd53ab9a31d397f8303f92c42f534693528fafbdb997c82bae6e477ad9",
|
||||
"sha256:ac3775e3311661d4adace3697a52ac0bab17edd166087d493b52d4f4f553f9f0",
|
||||
"sha256:b06f0d3bf045158d2fb8837c5785fe9ff9b8c93358be64461a1089f5da983137",
|
||||
"sha256:b116502087ce8a6b7a5f1814568ccbd0e9f6cfd99948aa59b0e241dc57cf739f",
|
||||
"sha256:b82fab78e0b1329e183a65260581de4375f619167478dddab510c6c6fb04d9b6",
|
||||
"sha256:bd7163182133c0c7701b25e604cf1611c0d87712e56e88e7ee5d72deab3e76b5",
|
||||
"sha256:c36bcbc0d5174a80d6cccf43a0ecaca44e81d25be4b7f90f0ed7bcfbb5a00909",
|
||||
"sha256:c3af8e0f07399d3176b179f2e2634c3ce9c1301379a6b8c9c9aeecd481da494f",
|
||||
"sha256:c84132a54c750fda57729d1e2599bb598f5fa0344085dbde5003ba429a4798c0",
|
||||
"sha256:cb7b2ab0188829593b9de646545175547a70d9a6e2b63bf2cd87a0a391599324",
|
||||
"sha256:cca4def576f47a09a943666b8f829606bcb17e2bc2d5911a46c8f8da45f56755",
|
||||
"sha256:cf6511efa4801b9b38dc5546d7547d5b5c6ef4b081c60b23e4d941d0eba9cbeb",
|
||||
"sha256:d16fd5252f883eb074ca55cb622bc0bee49b979ae4e8639fff6ca3ff44f9f854",
|
||||
"sha256:d2686f91611f9e17f4548dbf050e75b079bbc2a82be565832bc8ea9047b61c8c",
|
||||
"sha256:d7fc3fca01da18fbabe4625d64bb612b533533ed10045a2ac3dd194bfa656b60",
|
||||
"sha256:dd5653e67b149503c68c4018bf07e42eeed6b4e956b24c00ccdf93ac79cdff84",
|
||||
"sha256:de5695a6f1d8340b12a5d6d4484290ee74d61e467c39ff03b39e30df62cf83a0",
|
||||
"sha256:e0ac8959c929593fee38da1c2b64ee9778733cdf03c482c9ff1d508b6b593b2b",
|
||||
"sha256:e1b25e3ad6c909f398df8921780d6a3d120d8c09466720226fc621605b6f92b1",
|
||||
"sha256:e633940f28c1e913615fd624fcdd72fdba807bf53ea6925d6a588e84e1151531",
|
||||
"sha256:e89df2958e5159b811af9ff0f92614dabf4ff617c03a4c1c6ff53bf1c399e0e1",
|
||||
"sha256:ea9f9c6034ea2d93d9147818f17c2a0860d41b71c38b9ce4d55f21b6f9165a11",
|
||||
"sha256:f645caaf0008bacf349875a974220f1f1da349c5dbe7c4ec93048cdc785a3326",
|
||||
"sha256:f8303414c7b03f794347ad062c0516cee0e15f7a612abd0ce1e25caf6ceb47df",
|
||||
"sha256:fca62a8301b605b954ad2e9c3666f9d97f63872aa4efcae5492baca2056b74ab"
|
||||
],
|
||||
"markers": "python_full_version >= '3.7.0'",
|
||||
"version": "==3.1.0"
|
||||
},
|
||||
"colorama": {
|
||||
"hashes": [
|
||||
"sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44",
|
||||
"sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"
|
||||
],
|
||||
"markers": "sys_platform == 'win32'",
|
||||
"version": "==0.4.6"
|
||||
},
|
||||
"idna": {
|
||||
"hashes": [
|
||||
"sha256:814f528e8dead7d329833b91c5faa87d60bf71824cd12a7530b5526063d02cb4",
|
||||
"sha256:90b77e79eaa3eba6de819a0c442c0b4ceefc341a7a2ab77d7562bf49f425c5c2"
|
||||
],
|
||||
"markers": "python_version >= '3.5'",
|
||||
"version": "==3.4"
|
||||
},
|
||||
"loguru": {
|
||||
"hashes": [
|
||||
"sha256:1612053ced6ae84d7959dd7d5e431a0532642237ec21f7fd83ac73fe539e03e1",
|
||||
"sha256:b93aa30099fa6860d4727f1b81f8718e965bb96253fa190fab2077aaad6d15d3"
|
||||
],
|
||||
"index": "pip_conf_index_global",
|
||||
"version": "==0.7.0"
|
||||
},
|
||||
"requests": {
|
||||
"hashes": [
|
||||
"sha256:64299f4909223da747622c030b781c0d7811e359c37124b4bd368fb8c6518baa",
|
||||
"sha256:98b1b2782e3c6c4904938b84c0eb932721069dfdb9134313beff7c83c2df24bf"
|
||||
],
|
||||
"index": "pip_conf_index_global",
|
||||
"version": "==2.28.2"
|
||||
},
|
||||
"requests-toolbelt": {
|
||||
"hashes": [
|
||||
"sha256:18565aa58116d9951ac39baa288d3adb5b3ff975c4f25eee78555d89e8f247f7",
|
||||
"sha256:62e09f7ff5ccbda92772a29f394a49c3ad6cb181d568b1337626b2abb628a63d"
|
||||
],
|
||||
"index": "pip_conf_index_global",
|
||||
"version": "==0.10.1"
|
||||
},
|
||||
"urllib3": {
|
||||
"hashes": [
|
||||
"sha256:8a388717b9476f934a21484e8c8e61875ab60644d29b9b39e11e4b9dc1c6b305",
|
||||
"sha256:aa751d169e23c7479ce47a0cb0da579e3ede798f994f5816a74e4f4500dcea42"
|
||||
],
|
||||
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'",
|
||||
"version": "==1.26.15"
|
||||
},
|
||||
"win32-setctime": {
|
||||
"hashes": [
|
||||
"sha256:15cf5750465118d6929ae4de4eb46e8edae9a5634350c01ba582df868e932cb2",
|
||||
"sha256:231db239e959c2fe7eb1d7dc129f11172354f98361c4fa2d6d2d7e278baa8aad"
|
||||
],
|
||||
"markers": "sys_platform == 'win32'",
|
||||
"version": "==1.1.0"
|
||||
}
|
||||
},
|
||||
"develop": {}
|
||||
}
|
|
@ -0,0 +1,234 @@
|
|||
import os.path
|
||||
|
||||
from gitlink_api.project_api import ProjectApi
|
||||
from gitlink_api.get_issue_journal import get_issues_and_journals
|
||||
from gitlink_api.login_api import Login
|
||||
from config.config import target_host, target_project, user, pwd, source_host, source_project
|
||||
from config.project_path import ATTACHMENT_DIR
|
||||
from loguru import logger
|
||||
from business.insert_milestone import insert_milestone
|
||||
from business.insert_issue_tags import insert_issue_tags
|
||||
from gitlink_api.get_milestone import get_milestone
|
||||
from gitlink_api.get_issue_tags import get_issue_tags
|
||||
import re
|
||||
from common.helper import download_attachment
|
||||
|
||||
|
||||
def insert_issue_journal():
|
||||
"""
|
||||
往目标仓库新增issue和评论
|
||||
:return:
|
||||
"""
|
||||
logger.info("---------------------------开始进行疑修导入--------------------------------")
|
||||
# 获取源仓库所有的疑修和评论
|
||||
source_issues_and_journals = get_issues_and_journals(source_host, source_project)
|
||||
# 登录目标仓库
|
||||
login_cookies = Login(target_host).login_api(user, pwd).cookies
|
||||
project_api = ProjectApi(target_host, target_project, login_cookies)
|
||||
|
||||
# ===================处理里程碑==================================================================================================================
|
||||
# 保证目标仓库具备跟源仓库相同的里程碑
|
||||
insert_milestone()
|
||||
|
||||
# ===================处理标记=====================================================================================================================
|
||||
# 保证目标仓库具备跟源仓库相同的项目标记
|
||||
insert_issue_tags()
|
||||
|
||||
for source_issues_and_journal in source_issues_and_journals:
|
||||
source_issue_id = source_issues_and_journal.get("issue_id")
|
||||
source_issue_detail = source_issues_and_journal.get("issue_detail")
|
||||
source_issue_journal = source_issues_and_journal.get("issue_journals")
|
||||
# ===================处理里程碑===================
|
||||
# 获取该疑修对应的里程碑名称
|
||||
source_issue_milesone_name = source_issue_detail["milestone"]["name"] if source_issue_detail.get(
|
||||
"milestone") else None
|
||||
# 获取目标仓库所有的里程碑
|
||||
target_project_milestones = get_milestone(target_host, target_project)
|
||||
milestone_id = ""
|
||||
for target_project_milestone in target_project_milestones:
|
||||
if target_project_milestone.get("name") == source_issue_milesone_name:
|
||||
milestone_id = target_project_milestone.get("id")
|
||||
# ===================处理项目标记===================
|
||||
# 获取该疑修对应的项目标记
|
||||
source_issue_tags = source_issue_detail.get("tags", None)
|
||||
# 获取目标仓库所有的项目标记
|
||||
target_project_tags = get_issue_tags(target_host, target_project, login_cookies)
|
||||
issue_tag_ids = []
|
||||
if source_issue_tags:
|
||||
for i in source_issue_tags:
|
||||
for j in target_project_tags:
|
||||
if i["name"] == j["name"]:
|
||||
issue_tag_ids.append(j["id"])
|
||||
else:
|
||||
issue_tag_ids = None
|
||||
|
||||
# ===================处理描述===================
|
||||
# 描述中存在@的,移除掉
|
||||
source_issue_desc = source_issue_detail.get('description')
|
||||
pattern = r"\[@\w+\]\(.*?\)"
|
||||
new_description = re.sub(pattern, "", source_issue_desc)
|
||||
# TODO 还要处理疑修引用的问题,暂时还没想清楚怎么处理
|
||||
|
||||
# 处理疑修内容中的图片,将附件下载下来
|
||||
pattern = r"!\[\]\(/api/attachments/\d+\)"
|
||||
match = re.search(pattern, new_description)
|
||||
if match:
|
||||
attachment = match.group()
|
||||
attachment = attachment.replace(".replace(")", "")
|
||||
attachment_url = source_host + attachment
|
||||
attachment_path = os.path.join(ATTACHMENT_DIR, str(source_issue_id) + ".png")
|
||||
download_attachment(attachment_url, attachment_path)
|
||||
# 上传文件获取attachmentid
|
||||
new_attachment_id = project_api.upload_attachment(file=attachment_path,
|
||||
filename=str(source_issue_id) + ".png").get("id", None)
|
||||
issue_desc = new_description.replace(attachment, f"/api/attachments/{new_attachment_id}")
|
||||
else:
|
||||
issue_desc = new_description
|
||||
# ===================处理疑修附件===================
|
||||
attachment_ids = []
|
||||
source_issue_attachments = source_issue_detail.get("attachments", None)
|
||||
if source_issue_attachments:
|
||||
for source_attachment in source_issue_attachments:
|
||||
attachment_url = source_host + source_attachment["url"]
|
||||
attachment_path = os.path.join(ATTACHMENT_DIR, source_attachment["title"])
|
||||
download_attachment(attachment_url, attachment_path)
|
||||
|
||||
# 上传文件获取attachmentid
|
||||
new_attachment_id = project_api.upload_attachment(file=attachment_path,
|
||||
filename=source_attachment["title"]).get("id", None)
|
||||
attachment_ids.append(new_attachment_id)
|
||||
|
||||
else:
|
||||
attachment_ids = None
|
||||
|
||||
# ===================处理负责人===================
|
||||
# TODO 目标仓库没有对应的负责人,暂时先不处理,还没想清楚
|
||||
assigner_ids = []
|
||||
# ===================新建疑修=====================================================================================================================
|
||||
issue_payload = {
|
||||
"subject": source_issue_detail.get('subject'),
|
||||
"description": issue_desc,
|
||||
"branch_name": "", # TODO 需要判断目标分支是否存在该分支,存在插值
|
||||
"status_id": source_issue_detail.get('status').get("id"),
|
||||
"priority_id": source_issue_detail.get('priority').get("id"),
|
||||
"milestone_id": milestone_id,
|
||||
"issue_tag_ids": issue_tag_ids,
|
||||
"assigner_ids": assigner_ids,
|
||||
"attachment_ids": attachment_ids,
|
||||
"start_date": source_issue_detail.get('start_date'),
|
||||
"due_date": source_issue_detail.get('due_date'),
|
||||
"receivers_login": []
|
||||
}
|
||||
logger.info(f"新建疑修的参数:{issue_payload}")
|
||||
result = project_api.new_issue(payload=issue_payload)
|
||||
issue_id = result.get("project_issues_index", None)
|
||||
# ===================新建疑修一级评论=====================================================================================================================
|
||||
for journal in source_issue_journal:
|
||||
# ===================处理评论描述===================
|
||||
# 疑修评论中存在@的,移除掉
|
||||
source_journal_desc = journal.get('notes')
|
||||
pattern = r"\[@\w+\]\(.*?\)"
|
||||
new_notes = re.sub(pattern, "", source_journal_desc)
|
||||
# TODO 还要处理疑修引用的问题,暂时还没想清楚怎么处理
|
||||
# 处理疑修评论中的图片,将附件下载下来
|
||||
pattern = r"!\[\]\(/api/attachments/\d+\)"
|
||||
match = re.search(pattern, new_notes)
|
||||
if match:
|
||||
attachment = match.group()
|
||||
attachment = attachment.replace(".replace(")", "")
|
||||
attachment_url = source_host + attachment
|
||||
attachment_path = os.path.join(ATTACHMENT_DIR, str(source_issue_id) + "_journal_" + ".png")
|
||||
download_attachment(attachment_url, attachment_path)
|
||||
# 上传文件获取attachmentid
|
||||
new_attachment_id = project_api.upload_attachment(file=attachment_path,
|
||||
filename=str(
|
||||
source_issue_id) + "_journal_" + ".png").get("id",
|
||||
None)
|
||||
journal_desc = new_notes.replace(attachment, f"/api/attachments/{new_attachment_id}")
|
||||
else:
|
||||
journal_desc = new_notes
|
||||
# ===================处理疑修评论附件===================
|
||||
journal_attachment_ids = []
|
||||
source_journal_attachments = journal.get("attachments", None)
|
||||
if source_journal_attachments:
|
||||
for source_journal_attachment in source_journal_attachments:
|
||||
attachment_url = source_host + source_journal_attachment["url"]
|
||||
attachment_path = os.path.join(ATTACHMENT_DIR, source_journal_attachment["title"])
|
||||
download_attachment(attachment_url, attachment_path)
|
||||
|
||||
# 上传文件获取attachmentid
|
||||
new_attachment_id = project_api.upload_attachment(file=attachment_path,
|
||||
filename=source_journal_attachment["title"]).get(
|
||||
"id", None)
|
||||
journal_attachment_ids.append(new_attachment_id)
|
||||
|
||||
else:
|
||||
journal_attachment_ids = None
|
||||
journal_payload = {
|
||||
"notes": journal_desc,
|
||||
"attachment_ids": journal_attachment_ids,
|
||||
"receivers_login": "",
|
||||
}
|
||||
result = project_api.new_issue_journals(issue_id=issue_id, payload=journal_payload)
|
||||
first_journal_id = result.get("id")
|
||||
# ===================新建疑修二级评论=====================================================================================================================
|
||||
if journal.get("children_journals") and len(journal.get("children_journals")) > 0:
|
||||
children_journals = journal.get("children_journals")
|
||||
for children_journal in children_journals:
|
||||
# ===================处理评论描述===================
|
||||
# 疑修评论中存在@的,移除掉
|
||||
source_children_journal_desc = children_journal.get('notes')
|
||||
pattern = r"\[@\w+\]\(.*?\)"
|
||||
new_notes = re.sub(pattern, "", source_children_journal_desc)
|
||||
# TODO 还要处理疑修引用的问题,暂时还没想清楚怎么处理
|
||||
# 处理疑修评论中的图片,将附件下载下来
|
||||
pattern = r"!\[\]\(/api/attachments/\d+\)"
|
||||
match = re.search(pattern, new_notes)
|
||||
if match:
|
||||
attachment = match.group()
|
||||
attachment = attachment.replace(".replace(")", "")
|
||||
attachment_url = source_host + attachment
|
||||
attachment_path = os.path.join(ATTACHMENT_DIR,
|
||||
str(source_issue_id) + "_children_journal_" + ".png")
|
||||
download_attachment(attachment_url, attachment_path)
|
||||
# 上传文件获取attachmentid
|
||||
new_attachment_id = project_api.upload_attachment(file=attachment_path,
|
||||
filename=str(
|
||||
source_issue_id) + "_children_journal_" + ".png").get(
|
||||
"id",
|
||||
None)
|
||||
children_journal_desc = new_notes.replace(attachment, f"/api/attachments/{new_attachment_id}")
|
||||
else:
|
||||
children_journal_desc = new_notes
|
||||
# ===================处理疑修评论附件===================
|
||||
journal_children_attachment_ids = []
|
||||
source_children_journal_attachments = children_journal.get("attachments", None)
|
||||
if source_children_journal_attachments:
|
||||
for source_children_journal_attachment in source_children_journal_attachments:
|
||||
attachment_url = source_host + source_children_journal_attachment["url"]
|
||||
attachment_path = os.path.join(ATTACHMENT_DIR, source_children_journal_attachment["title"])
|
||||
download_attachment(attachment_url, attachment_path)
|
||||
|
||||
# 上传文件获取attachmentid
|
||||
new_attachment_id = project_api.upload_attachment(file=attachment_path,
|
||||
filename=
|
||||
source_children_journal_attachment[
|
||||
"title"]).get(
|
||||
"id", None)
|
||||
journal_children_attachment_ids.append(new_attachment_id)
|
||||
|
||||
else:
|
||||
journal_children_attachment_ids = None
|
||||
journal_payload = {
|
||||
"notes": children_journal_desc,
|
||||
"attachment_ids": journal_children_attachment_ids,
|
||||
"receivers_login": "",
|
||||
"parent_id": first_journal_id,
|
||||
"reply_id": first_journal_id,
|
||||
|
||||
}
|
||||
project_api.new_issue_journals(issue_id=issue_id, payload=journal_payload)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
insert_issue_journal()
|
|
@ -0,0 +1,53 @@
|
|||
from gitlink_api.get_issue_tags import get_issue_tags
|
||||
from config.config import source_host, source_project, target_host, target_project, user, pwd
|
||||
from gitlink_api.login_api import Login
|
||||
from gitlink_api.project_api import ProjectApi
|
||||
from loguru import logger
|
||||
|
||||
|
||||
def insert_issue_tags():
|
||||
login_cookies = Login(target_host).login_api(user, pwd).cookies
|
||||
|
||||
# 获取源仓库的项目标记
|
||||
source_project_tags = get_issue_tags(source_host, source_project, login_cookies)
|
||||
|
||||
# 获取目标仓库的项目标记
|
||||
target_project_tags = get_issue_tags(target_host, target_project, login_cookies)
|
||||
|
||||
# 源仓库在目标仓库中,找不到相同名称的项目标记
|
||||
tags_need_add = []
|
||||
|
||||
project_api = ProjectApi(target_host, target_project, login_cookies)
|
||||
|
||||
# 如果目标仓库里程碑列表不为空,则检查源仓库哪些里程碑在目标仓库不存在,不存在的追加到milestone_need_add方便后续创建
|
||||
if target_project_tags:
|
||||
for source_tag in source_project_tags:
|
||||
found = False
|
||||
for target_tag in target_project_tags:
|
||||
if source_tag['name'] == target_tag['name']:
|
||||
found = True
|
||||
break
|
||||
if not found:
|
||||
tags_need_add.append(source_tag)
|
||||
# 将源仓库里程碑不存在与目标仓库的里程碑,进行创建
|
||||
if tags_need_add:
|
||||
for tag in tags_need_add:
|
||||
payload = {
|
||||
"name": tag.get("name"),
|
||||
"description": tag.get("description"),
|
||||
"color": tag.get("color")}
|
||||
project_api.new_issue_tags(payload=payload)
|
||||
|
||||
# 如果目标仓库里程碑为空,则直接在目标仓库新建与源仓库相同的里程碑
|
||||
else:
|
||||
for source_project_tag in source_project_tags:
|
||||
payload = {
|
||||
"name": source_project_tag.get("name"),
|
||||
"description": source_project_tag.get("description"),
|
||||
"color": source_project_tag.get("color")}
|
||||
project_api.new_issue_tags(payload=payload)
|
||||
logger.debug(f"需要新建的项目标记:{tags_need_add}")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
insert_issue_tags()
|
|
@ -0,0 +1,53 @@
|
|||
from gitlink_api.get_milestone import get_milestone
|
||||
from config.config import source_host, source_project, target_host, target_project, user, pwd
|
||||
from gitlink_api.login_api import Login
|
||||
from gitlink_api.project_api import ProjectApi
|
||||
from loguru import logger
|
||||
|
||||
|
||||
def insert_milestone():
|
||||
# 获取源仓库的里程碑
|
||||
source_project_milestones = get_milestone(source_host, source_project)
|
||||
|
||||
# 获取目标仓库的里程碑
|
||||
target_project_milestones = get_milestone(target_host, target_project)
|
||||
|
||||
# 源仓库在目标仓库中,找不到相同名称的里程碑
|
||||
milestone_need_add = []
|
||||
|
||||
login_cookies = Login(target_host).login_api(user, pwd).cookies
|
||||
project_api = ProjectApi(target_host, target_project, login_cookies)
|
||||
|
||||
# 如果目标仓库里程碑列表不为空,则检查源仓库哪些里程碑在目标仓库不存在,不存在的追加到milestone_need_add方便后续创建
|
||||
if target_project_milestones:
|
||||
for source_milestone in source_project_milestones:
|
||||
found = False
|
||||
for target_milestone in target_project_milestones:
|
||||
if source_milestone['name'] == target_milestone['name']:
|
||||
found = True
|
||||
break
|
||||
if not found:
|
||||
milestone_need_add.append(source_milestone)
|
||||
# 将源仓库里程碑不存在与目标仓库的里程碑,进行创建
|
||||
if milestone_need_add:
|
||||
for milestone in milestone_need_add:
|
||||
payload = {
|
||||
"name": milestone.get("name"),
|
||||
"description": milestone.get("description"),
|
||||
"effective_date": milestone.get("effective_date"),
|
||||
"status": milestone.get("status")}
|
||||
project_api.new_milestone(payload=payload)
|
||||
# 如果目标仓库里程碑为空,则直接在目标仓库新建与源仓库相同的里程碑
|
||||
else:
|
||||
for source_project_milestone in source_project_milestones:
|
||||
payload = {
|
||||
"name": source_project_milestone.get("name"),
|
||||
"description": source_project_milestone.get("description"),
|
||||
"effective_date": source_project_milestone.get("effective_date"),
|
||||
"status": source_project_milestone.get("status")}
|
||||
project_api.new_milestone(payload=payload)
|
||||
logger.debug(f"需要新建的里程碑:{milestone_need_add}")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
insert_milestone()
|
|
@ -0,0 +1,87 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# @Version: Python 3.9
|
||||
# @Time : 2023/1/31 14:31
|
||||
# @Author : chenyinhua
|
||||
# @File : requests_handle.py
|
||||
# @Software: PyCharm
|
||||
# @Desc: 处理request请求
|
||||
import os.path
|
||||
|
||||
import requests
|
||||
from requests import Response
|
||||
from loguru import logger
|
||||
|
||||
|
||||
# ---------------------------------------- 进行请求----------------------------------------#
|
||||
class BaseRequest:
|
||||
"""
|
||||
进行请求
|
||||
"""
|
||||
session = None
|
||||
|
||||
@classmethod
|
||||
def get_session(cls):
|
||||
"""
|
||||
单例模式保证测试过程中使用的都是一个session对象;
|
||||
requests.session可以自动处理cookies,做状态保持。
|
||||
"""
|
||||
if cls.session is None:
|
||||
cls.session = requests.Session()
|
||||
return cls.session
|
||||
|
||||
@classmethod
|
||||
def send_request(cls, req_data: dict) -> Response:
|
||||
"""
|
||||
处理case数据,转换成可用数据发送请求
|
||||
:param case: 读取出来的每一行用例内容
|
||||
return: 响应对象
|
||||
"""
|
||||
logger.info(f"-----Start-----进行接口请求,并获取接口响应数据,请求数据:{type(req_data)} || {req_data}-----")
|
||||
# 进行接口请求,并获取接口响应数据
|
||||
res = cls.send_api(
|
||||
url=req_data["url"],
|
||||
method=req_data["method"],
|
||||
pk=req_data["pk"],
|
||||
header=req_data.get("header", None),
|
||||
data=req_data.get("data", None),
|
||||
file=req_data.get("file", None)
|
||||
)
|
||||
logger.info(f"-----End-----接口请求结束,请求响应数据:{res.text}-----")
|
||||
|
||||
return res
|
||||
|
||||
@classmethod
|
||||
def send_api(cls, url, method, pk, header=None, data=None, file=None) -> Response:
|
||||
"""
|
||||
根据pk参数的不同,决定请求参数是使用params,data还是json
|
||||
:param method: 请求方法
|
||||
:param url: 请求url
|
||||
:param pk: 入参关键字, params(查询参数类型,明文传输,一般在url?参数名=参数值), data(一般用于form表单类型参数)
|
||||
json(一般用于json类型请求参数)
|
||||
:param data: 参数数据,默认等于None
|
||||
:param file: 文件对象
|
||||
:param header: 请求头
|
||||
:return: 返回res对象
|
||||
"""
|
||||
session = cls.get_session()
|
||||
pk = pk.lower()
|
||||
if pk == 'params':
|
||||
res = session.request(method=method, url=url, params=data, headers=header, timeout=5)
|
||||
elif pk == 'data':
|
||||
res = session.request(method=method, url=url, data=data, files=file, headers=header, timeout=5)
|
||||
elif pk == 'json':
|
||||
res = session.request(method=method, url=url, json=data, files=file, headers=header, timeout=5)
|
||||
else:
|
||||
raise ValueError('pk可选关键字为params, json, data')
|
||||
return res
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from requests_toolbelt import MultipartEncoder
|
||||
from requests import request
|
||||
url = "https://testforgeplus.trustie.net/api/attachments.json"
|
||||
method = "POST"
|
||||
data = MultipartEncoder(fields={"file": ("upload_filename", open(os.path.abspath(__file__), "rb"))})
|
||||
file = "test.zip"
|
||||
headers = {"Content-Type": data.content_type}
|
||||
api = request(url=url, method=method, files=data)
|
|
@ -0,0 +1,39 @@
|
|||
from loguru import logger
|
||||
import os
|
||||
import urllib.request
|
||||
|
||||
|
||||
def create_dir(path):
|
||||
"""创建目录"""
|
||||
if not os.path.exists(path):
|
||||
os.mkdir(path)
|
||||
logger.debug(f"成功创建目录: {path}")
|
||||
logger.debug(f"目录地址已存在: {path}")
|
||||
|
||||
|
||||
def download_attachment(url, path):
|
||||
"""
|
||||
通过Python自带的库urllib下载图片
|
||||
需要导入:import urllib.request
|
||||
:param url: url地址
|
||||
:param path: 附件保存的绝对路径,需要带文件后缀
|
||||
"""
|
||||
try:
|
||||
request = urllib.request.Request(url)
|
||||
response = urllib.request.urlopen(request)
|
||||
if response.getcode() == 200:
|
||||
logger.debug("请求状态码200, 开始下载......")
|
||||
with open(path, "wb") as fb:
|
||||
fb.write(response.read())
|
||||
return path
|
||||
except Exception as e:
|
||||
logger.debug("捕获到异常,下载失败")
|
||||
return f"{e}"
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import os
|
||||
|
||||
url = "https://www.gitlink.org.cn/api/attachments/416249"
|
||||
path = os.path.join(r"C:\Users\chenyinhua\PycharmProjects\pythonProject7", "aaa.zip")
|
||||
download_attachment(url, path)
|
|
@ -0,0 +1,10 @@
|
|||
source_host = "https://xxx"
|
||||
|
||||
source_project = "xxxx/xxxx"
|
||||
|
||||
target_host = "https://xxx"
|
||||
|
||||
target_project = "xxxx/xxx"
|
||||
|
||||
user = "xxxxx"
|
||||
pwd = "12345678"
|
|
@ -0,0 +1,9 @@
|
|||
# 保存疑修下载附件的目录
|
||||
import os
|
||||
|
||||
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
ATTACHMENT_DIR = os.path.join(ROOT_DIR, "issue_attachments")
|
||||
if not os.path.exists(ATTACHMENT_DIR):
|
||||
os.mkdir(ATTACHMENT_DIR)
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
from gitlink_api.project_api import ProjectApi
|
||||
import math
|
||||
from loguru import logger
|
||||
from common.baseapi import BaseRequest
|
||||
|
||||
|
||||
def get_issue_ids(host, project):
|
||||
"""
|
||||
获取源仓库所有的issue_ids
|
||||
:return:
|
||||
"""
|
||||
issue_ids = []
|
||||
page = 1
|
||||
limit = 15
|
||||
project_api = ProjectApi(host, project)
|
||||
# 获取仓库所有issue数量
|
||||
issue_count = project_api.get_issue_list(limit=limit, page=page).get("total_issues_count", 0)
|
||||
logger.debug(f"总共有{issue_count}个issue")
|
||||
# 判断当前共有多少页
|
||||
total_page = math.ceil(int(issue_count) / limit)
|
||||
# 循环请求获取所有的issue_id
|
||||
while page <= total_page:
|
||||
issues = project_api.get_issue_list(page=page, limit=limit).get("issues", "")
|
||||
if issues and len(issues) > 0:
|
||||
for issue in issues:
|
||||
issue_ids.append(issue.get("project_issues_index"))
|
||||
page += 1
|
||||
logger.info(f"获取到所有issue_ids: {sorted(issue_ids)}")
|
||||
|
||||
return sorted(issue_ids)[:100]
|
||||
|
||||
|
||||
def get_issues_and_journals(host, project):
|
||||
project_api = ProjectApi(host, project)
|
||||
issue_ids = get_issue_ids(host, project)
|
||||
issues_and_journals = []
|
||||
for issue_id in issue_ids:
|
||||
# 获取源仓库的某一个issue详情及评论
|
||||
issue_detail = project_api.get_issue_detail(issue_id=issue_id)
|
||||
# 获取源仓库的某一个issue评论数量
|
||||
issue_journals = []
|
||||
page = 1
|
||||
limit = 50
|
||||
comment_journals_count = project_api.get_issue_journals_detail(issue_id=issue_id, page=page, limit=limit).get(
|
||||
"total_comment_journals_count", 0)
|
||||
# 当issue评论数量大于0时,去获取评论
|
||||
if comment_journals_count > 0:
|
||||
# 判断当前共有多少页
|
||||
total_page = math.ceil(int(comment_journals_count) / limit)
|
||||
# 循环请求获取所有的issue评论
|
||||
while page <= total_page:
|
||||
journals = project_api.get_issue_journals_detail(issue_id=issue_id, page=page,
|
||||
limit=limit).get("journals", "")
|
||||
if journals and len(journals) > 0:
|
||||
for journal in journals:
|
||||
issue_journals.append(journal)
|
||||
page += 1
|
||||
|
||||
issues_and_journals.append(
|
||||
{
|
||||
"issue_id": issue_id,
|
||||
"issue_detail": issue_detail,
|
||||
"issue_journals": issue_journals
|
||||
}
|
||||
)
|
||||
# logger.info(f"获取所有的疑修和评论如下:{issues_and_journals}")
|
||||
# # 根据疑修ID进行排序, 按照从小到大排序返回
|
||||
# sorted_issues_and_journals = sorted(issues_and_journals, key=lambda k: k['issue_id'])
|
||||
# return sorted_issues_and_journals
|
||||
return issues_and_journals
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from config import source_host, source_project
|
||||
|
||||
get_issues_and_journals(source_host, source_project)
|
|
@ -0,0 +1,35 @@
|
|||
import math
|
||||
from gitlink_api.project_api import ProjectApi
|
||||
from loguru import logger
|
||||
|
||||
|
||||
def get_issue_tags(host, project, cookies):
|
||||
project_api = ProjectApi(host, project, cookies)
|
||||
# 获取目标仓库的项目标记
|
||||
page = 1
|
||||
limit = 15
|
||||
issue_tags = []
|
||||
issue_tags_count = project_api.get_issue_tags_list(page=page, limit=limit).get("total_count", 0)
|
||||
# 判断当前共有多少页
|
||||
total_page = math.ceil(int(issue_tags_count) / limit)
|
||||
# 循环获取所有的项目标记
|
||||
while page <= total_page:
|
||||
issue_tags_list = project_api.get_issue_tags_list(page=page, limit=limit).get("issue_tags", "")
|
||||
if issue_tags_list and len(issue_tags_list) > 0:
|
||||
for issue_tag in issue_tags_list:
|
||||
issue_tags.append({
|
||||
"id": issue_tag.get("id"),
|
||||
"name": issue_tag.get("name"),
|
||||
"color": issue_tag.get("color"),
|
||||
"description": issue_tag.get("description")
|
||||
})
|
||||
page += 1
|
||||
# logger.info(f"获取仓库项目标记信息如下:{issue_tags}")
|
||||
return issue_tags
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from config import source_host, source_project
|
||||
from gitlink_api.login_api import Login
|
||||
cookies = Login(source_host).login_api("floraachy", "flora@123").cookies
|
||||
get_issue_tags(source_host, source_project, cookies)
|
|
@ -0,0 +1,43 @@
|
|||
import math
|
||||
from gitlink_api.project_api import ProjectApi
|
||||
from loguru import logger
|
||||
|
||||
|
||||
def get_milestone(host, project):
|
||||
project_api = ProjectApi(host, project)
|
||||
# 获取仓库的里程碑列表
|
||||
page = 1
|
||||
limit = 15
|
||||
milestones = []
|
||||
target_milestone_count = project_api.get_milestone_list(page=page, limit=limit, category="open").get(
|
||||
"opening_milestone_count", 0)
|
||||
# 判断当前共有多少页
|
||||
total_page = math.ceil(int(target_milestone_count) / limit)
|
||||
# 循环请求获取所有开启状态的里程碑
|
||||
while page <= total_page:
|
||||
milestones_open = project_api.get_milestone_list(page=page, limit=limit, category="open").get("milestones", "")
|
||||
if milestones_open and len(milestones_open) > 0:
|
||||
for milestone in milestones_open:
|
||||
milestones.append(milestone)
|
||||
page += 1
|
||||
target_milestone_count = project_api.get_milestone_list(page=page, limit=limit, category="open").get(
|
||||
"closed_milestone_count", 0)
|
||||
# 判断当前共有多少页
|
||||
total_page = math.ceil(int(target_milestone_count) / limit)
|
||||
# 循环请求获取所有关闭状态的里程碑
|
||||
while page <= total_page:
|
||||
milestones_closed = project_api.get_milestone_list(page=page, limit=limit, category="closed").get(
|
||||
"milestones",
|
||||
"")
|
||||
if milestones_closed and len(milestones_closed) > 0:
|
||||
for milestone in milestones_closed:
|
||||
milestones.append(milestone)
|
||||
page += 1
|
||||
# logger.info(f"获取仓库里程碑信息如下:{milestones}")
|
||||
return milestones
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from config import source_host, source_project
|
||||
|
||||
get_milestone(source_host, source_project)
|
|
@ -0,0 +1,36 @@
|
|||
from requests import request
|
||||
from loguru import logger
|
||||
|
||||
|
||||
class Login:
|
||||
"""登录"""
|
||||
|
||||
def __init__(self, host):
|
||||
self.host = host
|
||||
|
||||
def login_api(self, user, pwd):
|
||||
"""
|
||||
登录接口
|
||||
请求地址:{host}/api/accounts/login.json
|
||||
请求方法:POST
|
||||
请求头:{"Content-Type": "application/json;charset=UTF-8"}
|
||||
请求参数:
|
||||
{
|
||||
"login": {user}, # 用户名
|
||||
"password": {pwd}, # 密码
|
||||
"autologin": 1 # 前端是否勾选自动登录
|
||||
}
|
||||
"""
|
||||
|
||||
try:
|
||||
headers = {"Content-Type": "application/json;charset=UTF-8"}
|
||||
|
||||
payload = {"login": user, "password": pwd,
|
||||
"autologin": 1}
|
||||
response = request(url=self.host + "/api/accounts/login.json", method="POST", headers=headers, json=payload)
|
||||
json_data = response.json()
|
||||
if json_data["login"] == user:
|
||||
logger.debug(f'登录接口请求成功!user_id={json_data["user_id"]} - login={json_data["login"]}')
|
||||
return response
|
||||
except Exception as e:
|
||||
logger.error(f"登录接口请求错误:{e}")
|
|
@ -0,0 +1,218 @@
|
|||
import os.path
|
||||
|
||||
from requests_toolbelt import MultipartEncoder
|
||||
from requests import request
|
||||
from loguru import logger
|
||||
|
||||
|
||||
class ProjectApi:
|
||||
def __init__(self, host, project=None, cookies=None):
|
||||
self.host = host
|
||||
self.project = project
|
||||
self.cookies = cookies
|
||||
|
||||
def get_issue_list(self, **kwargs):
|
||||
"""
|
||||
获取疑修列表信息
|
||||
"""
|
||||
try:
|
||||
url = self.host + f"/api/v1/{self.project}/issues?participant_category=all&category=all&limit={kwargs.get('limit')}&page={kwargs.get('page')}"
|
||||
method = "GET"
|
||||
response = request(url=url, method=method, timeout=5)
|
||||
# logger.debug(f"获取issue列表接口的响应数据是:{response.json()}")
|
||||
return response.json()
|
||||
except Exception as e:
|
||||
logger.error(f"获取疑修列表信息:{e}")
|
||||
return {"error": f"{e}"}
|
||||
|
||||
def get_issue_detail(self, **kwargs):
|
||||
"""
|
||||
获取易修详情页数据
|
||||
"""
|
||||
try:
|
||||
url = self.host + f"/api/v1/{self.project}/issues/{kwargs.get('issue_id')}"
|
||||
method = "GET"
|
||||
response = request(url=url, method=method, timeout=5)
|
||||
# logger.debug(f"获取issue详情接口的响应数据是:{response.json()}")
|
||||
return response.json()
|
||||
except Exception as e:
|
||||
logger.error(f"获取易修详情页数据:{e}")
|
||||
return {"error": f"{e}"}
|
||||
|
||||
def get_issue_journals_detail(self, **kwargs):
|
||||
"""
|
||||
获取易修评论详情
|
||||
"""
|
||||
try:
|
||||
url = self.host + f"/api/v1/{self.project}/issues/{kwargs.get('issue_id')}/journals?category=comment&page={kwargs.get('page')}&limit={kwargs.get('limit')}"
|
||||
method = "GET"
|
||||
response = request(url=url, method=method, timeout=5)
|
||||
# logger.debug(f"获取易修评论详情接口的响应数据是:{response.json()}")
|
||||
return response.json()
|
||||
except Exception as e:
|
||||
logger.error(f"获取易修评论详情:{e}")
|
||||
return {"error": f"{e}"}
|
||||
|
||||
def new_issue(self, **kwargs):
|
||||
"""
|
||||
新建疑修
|
||||
payload = {
|
||||
"subject": "",
|
||||
"description": "",
|
||||
"branch_name": "",
|
||||
"status_id": "",
|
||||
"priority_id": "",
|
||||
"milestone_id": "",
|
||||
"issue_tag_ids": "",
|
||||
"assigner_ids": "",
|
||||
"attachment_ids": "",
|
||||
"start_date": ""
|
||||
"due_date":""
|
||||
"receivers_login": []
|
||||
# }
|
||||
"""
|
||||
try:
|
||||
url = self.host + f"/api/v1/{self.project}/issues"
|
||||
method = "POST"
|
||||
cookies = self.cookies
|
||||
data = kwargs.get('payload')
|
||||
response = request(url=url, method=method, cookies=cookies, json=data, timeout=5)
|
||||
logger.debug(f"新建疑修接口的响应数据是:{response.json()}")
|
||||
return response.json()
|
||||
except Exception as e:
|
||||
logger.error(f"新建疑修报错:{e}")
|
||||
return {"error": f"{e}"}
|
||||
|
||||
def new_issue_journals(self, **kwargs):
|
||||
"""
|
||||
新建疑修评论
|
||||
"""
|
||||
try:
|
||||
url = self.host + f"/api/v1/{self.project}/issues/{kwargs.get('issue_id')}/journals"
|
||||
method = "POST"
|
||||
cookies = self.cookies
|
||||
data = kwargs.get('payload')
|
||||
response = request(url=url, method=method, cookies=cookies, json=data, timeout=5)
|
||||
logger.debug(f"新建疑修评论接口的数据是:{data}")
|
||||
logger.debug(f"新建疑修评论接口的响应数据是:{response.json()}")
|
||||
return response.json()
|
||||
except Exception as e:
|
||||
logger.error(f"新建疑修评论报错:{e}")
|
||||
return {"error": f"{e}"}
|
||||
|
||||
def new_issue_journals_reply(self, **kwargs):
|
||||
"""
|
||||
新建疑修评论回复(二级评论)
|
||||
payload = {"parent_id": 271911,"reply_id": 272004,"notes": "wwww","receivers_login": []}
|
||||
"""
|
||||
try:
|
||||
url = self.host + f"/api/v1/{self.project}/issues/{kwargs.get('issue_id')}/journals"
|
||||
method = "POST"
|
||||
cookies = self.cookies
|
||||
data = kwargs.get('payload')
|
||||
response = request(url=url, method=method, cookies=cookies, json=data, timeout=5)
|
||||
logger.debug(f"新建疑修评论接口的响应数据是:{response.json()}")
|
||||
return response.json()
|
||||
except Exception as e:
|
||||
logger.error(f"新建疑修评论报错:{e}")
|
||||
return {"error": f"{e}"}
|
||||
|
||||
def new_milestone(self, **kwargs):
|
||||
"""
|
||||
新建里程碑
|
||||
payload ={name: "1", description: "1", effective_date: "2023-04-17", status: "open"}
|
||||
"""
|
||||
try:
|
||||
url = self.host + f"/api/{self.project}/milestones.json"
|
||||
method = "POST"
|
||||
cookies = self.cookies
|
||||
data = kwargs.get('payload')
|
||||
response = request(url=url, method=method, cookies=cookies, json=data, timeout=5)
|
||||
logger.debug(f"新建里程碑接口响应数据是:{response.json()}")
|
||||
return response.json()
|
||||
except Exception as e:
|
||||
logger.error(f"新建里程碑接口报错:{e}")
|
||||
return {"error": f"{e}"}
|
||||
|
||||
def new_issue_tags(self, **kwargs):
|
||||
"""
|
||||
新建项目标记
|
||||
payload ={color: "#9e804a", description: "2", name: "2"}
|
||||
"""
|
||||
try:
|
||||
url = self.host + f"/api/v1/{self.project}/issue_tags"
|
||||
method = "POST"
|
||||
cookies = self.cookies
|
||||
data = kwargs.get('payload')
|
||||
response = request(url=url, method=method, cookies=cookies, json=data, timeout=5)
|
||||
logger.debug(f"新建项目标记接口响应数据是:{response.json()}")
|
||||
return response.json()
|
||||
except Exception as e:
|
||||
logger.error(f"新建项目标记接口报错:{e}")
|
||||
return {"error": f"{e}"}
|
||||
|
||||
def get_milestone_list(self, **kwargs):
|
||||
"""
|
||||
获取里程碑列表
|
||||
"""
|
||||
try:
|
||||
url = self.host + f"/api/v1/{self.project}/milestones.json?page={kwargs.get('page')}&limit={kwargs.get('limit')}&category={kwargs.get('category')}"
|
||||
method = "GET"
|
||||
response = request(url=url, method=method, timeout=5)
|
||||
# logger.debug(f"获取里程碑列表接口响应数据是:{response.json()}")
|
||||
return response.json()
|
||||
except Exception as e:
|
||||
logger.error(f"获取里程碑列表接口报错:{e}")
|
||||
return {"error": f"{e}"}
|
||||
|
||||
def get_issue_tags_list(self, **kwargs):
|
||||
"""
|
||||
获取项目标记列表
|
||||
"""
|
||||
try:
|
||||
url = self.host + f"/api/v1/{self.project}/issue_tags?page={kwargs.get('page')}&limit={kwargs.get('limit')}"
|
||||
method = "GET"
|
||||
cookies = self.cookies
|
||||
response = request(url=url, method=method, cookies=cookies, timeout=5)
|
||||
# logger.debug(f"获取项目标记列表接口响应数据是:{response.json()}")
|
||||
return response.json()
|
||||
except Exception as e:
|
||||
logger.error(f"获取项目标记列表接口报错:{e}")
|
||||
return {"error": f"{e}"}
|
||||
|
||||
def upload_attachment(self, **kwargs):
|
||||
"""
|
||||
上传附件接口
|
||||
请求地址:/api/attachments.json
|
||||
请求方法:POST
|
||||
请求参数:data = MultipartEncoder(fields={'file': ('filename', open(r'C:\0_project_chy\autotest\Files\1.png', 'rb'), 'image/png')})
|
||||
content_type: multipart/form-data; boundary=----WebKitFormBoundaryRiL5fwKYjghMMaGc
|
||||
{"Content_Type": "multipart/form-data"}
|
||||
"""
|
||||
|
||||
try:
|
||||
|
||||
url = self.host + "/api/attachments.json"
|
||||
method = "POST"
|
||||
data = MultipartEncoder(fields={"file": (kwargs.get('filename'), open(kwargs.get("file"), "rb"))})
|
||||
headers = {
|
||||
"Referer": self.host + f"{self.project}/issues/new",
|
||||
"Content-type": data.content_type
|
||||
}
|
||||
response = request(url=url, method=method, data=data, headers=headers, cookies=self.cookies, timeout=5)
|
||||
json_data = response.json()
|
||||
if "id" in json_data.keys() and "filesize" in json_data.keys():
|
||||
logger.info(f"{kwargs.get('file')} || 上传附件成功!{json_data}")
|
||||
return response.json()
|
||||
else:
|
||||
logger.info(f"上传附件失败!{json_data}")
|
||||
except Exception as e:
|
||||
logger.error(f"上传附件接口报错:{e}")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from gitlink_api.login_api import Login
|
||||
|
||||
cookies = Login("https://testforgeplus.trustie.net").login_api(user="floraachy", pwd="12345678").cookies
|
||||
api = ProjectApi("https://testforgeplus.trustie.net", "floraachy/lalalalaa", cookies)
|
||||
print(api.upload_attachment(filename="project_api.py", file=os.path.abspath(__file__)))
|
|
@ -0,0 +1,74 @@
|
|||
from gitlink_api import HandleIssue
|
||||
from config import source_host, source_project, target_project, target_host
|
||||
import math
|
||||
from loguru import logger
|
||||
|
||||
|
||||
def get_issue_ids():
|
||||
"""
|
||||
获取源仓库所有的issue_ids
|
||||
:return:
|
||||
"""
|
||||
issue_ids = []
|
||||
page = 1
|
||||
limit = 15
|
||||
issue_api = HandleIssue(source_host)
|
||||
# 获取仓库所有issue数量
|
||||
issue_count = issue_api.get_issue_list(project=source_project, limit=limit, page=page).get("total_issues_count", 0)
|
||||
logger.debug(f"总共有{issue_count}个issue")
|
||||
# 判断当前共有多少页
|
||||
total_page = math.ceil(int(issue_count) / limit)
|
||||
# 循环请求获取所有的issue_id
|
||||
while page <= total_page:
|
||||
issues = issue_api.get_issue_list(project=source_project, page=page, limit=limit).get("issues", "")
|
||||
if issues and len(issues) > 0:
|
||||
for issue in issues:
|
||||
issue_ids.append(issue.get("project_issues_index"))
|
||||
page += 1
|
||||
print(f"获取到所有issue_ids: {issue_ids}")
|
||||
return issue_ids
|
||||
|
||||
|
||||
def get_issues_and_journals():
|
||||
"""
|
||||
根据issueID所有的issue详细信息及评论
|
||||
:return:
|
||||
"""
|
||||
issue_api = HandleIssue(source_host)
|
||||
issue_ids = get_issue_ids()
|
||||
issues_and_journals = []
|
||||
for issue_id in issue_ids:
|
||||
# 获取源仓库的某一个issue详情及评论
|
||||
issue_detail = issue_api.get_issue_detail(project=source_project, issue_id=issue_id)
|
||||
# 获取源仓库的某一个issue评论数量
|
||||
issue_journals = []
|
||||
page = 1
|
||||
limit = 50
|
||||
comment_journals_count = issue_api.get_issue_journals_detail(project=source_project, issue_id=issue_id,
|
||||
page=page,
|
||||
limit=limit).get("total_comment_journals_count", 0)
|
||||
# 当issue评论数量大于0时,去获取评论
|
||||
if comment_journals_count > 0:
|
||||
# 判断当前共有多少页
|
||||
total_page = math.ceil(int(comment_journals_count) / limit)
|
||||
# 循环请求获取所有的issue评论
|
||||
while page <= total_page:
|
||||
journals = issue_api.get_issue_journals_detail(project=source_project, issue_id=issue_id, page=page,
|
||||
limit=limit).get("journals", "")
|
||||
if journals and len(journals) > 0:
|
||||
for journal in journals:
|
||||
issue_journals.append(journal)
|
||||
page += 1
|
||||
|
||||
issues_and_journals.append(
|
||||
{
|
||||
"issue_id": issue_id,
|
||||
"issue_detail": issue_detail,
|
||||
"issue_journals": issue_journals
|
||||
}
|
||||
)
|
||||
return issues_and_journals
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(get_issues_and_journals())
|
Loading…
Reference in New Issue