【竞赛赛题提交】包含全部任务 #15
|
|
@ -0,0 +1,40 @@
|
|||
version: 2
|
||||
name: devops
|
||||
description: ""
|
||||
global:
|
||||
concurrent: 1
|
||||
trigger:
|
||||
webhook: gitlink@1.0.0
|
||||
event:
|
||||
- ref: push
|
||||
ruleset:
|
||||
- param-ref: branch
|
||||
operator: EQ
|
||||
value: '"master"'
|
||||
ruleset-operator: AND
|
||||
workflow:
|
||||
- ref: start
|
||||
name: 开始
|
||||
task: start
|
||||
- ref: ssh_cmd_0
|
||||
name: ssh执行命令
|
||||
task: ssh_cmd@1.1.1
|
||||
input:
|
||||
ssh_pass: ((ssh_key.ssh_key))
|
||||
ssh_ip: '"47.96.136.178"'
|
||||
ssh_port: '"22"'
|
||||
ssh_user: '"root"'
|
||||
ssh_cmd: "\"docker stop repo && docker rm repo && rm -r reposync && git clone
|
||||
https://gitlink.org.cn/Dongjiaqi/reposync.git && cd reposync && docker
|
||||
build -t reposync:v2.0 . && docker run -it -d -e CEROBOT_MYSQL_HOST=''
|
||||
-e CEROBOT_MYSQL_PORT=3306 -e CEROBOT_MYSQL_USER=rtsw -e
|
||||
CEROBOT_MYSQL_PWD='123456' -e CEROBOT_MYSQL_DB='reposyncer' -e
|
||||
BOOT_MODE='app' -p 8089:8000 --name repo reposync:v2.0 \""
|
||||
needs:
|
||||
- start
|
||||
- ref: end
|
||||
name: 结束
|
||||
task: end
|
||||
needs:
|
||||
- ssh_cmd_0
|
||||
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
|
|
@ -0,0 +1 @@
|
|||
main.py
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (reposync)" project-jdk-type="Python SDK" />
|
||||
<component name="PyCharmProfessionalAdvertiser">
|
||||
<option name="shown" value="true" />
|
||||
</component>
|
||||
<component name="PyPackaging">
|
||||
<option name="earlyReleasesAsUpgrades" value="true" />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/reposync.iml" filepath="$PROJECT_DIR$/.idea/reposync.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.9 (reposync)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="PyDocumentationSettings">
|
||||
<option name="format" value="PLAIN" />
|
||||
<option name="myDocStringFormat" value="Plain" />
|
||||
</component>
|
||||
</module>
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,472 @@
|
|||
import urllib
|
||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||
import requests
|
||||
import json
|
||||
import mysql.connector
|
||||
|
||||
|
||||
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
|
||||
|
||||
def do_GET(self):
|
||||
# 处理 GET 请求的代码保持不变
|
||||
self.send_response(200)
|
||||
self.send_header('Content-type', 'text/html')
|
||||
self.end_headers()
|
||||
self.wfile.write(b"Hello, World! This is a simple HTTP server running on port 8080.")
|
||||
|
||||
def do_POST(self):
|
||||
# 设置响应状态码为200
|
||||
self.send_response(200)
|
||||
# 设置响应头,这里可以根据需要设置不同的内容类型
|
||||
self.send_header('Content-type', 'text/plain')
|
||||
self.end_headers()
|
||||
|
||||
# 读取请求体中的内容
|
||||
# 注意:这里使用了self.rfile来读取数据,但通常需要知道内容的长度
|
||||
# 这里我们假设内容很短,并且使用简单的读取方式
|
||||
content_length = int(self.headers['Content-Length'])
|
||||
post_data = self.rfile.read(content_length)
|
||||
# 打印接收到的数据
|
||||
print("Received POST data:", post_data.decode('utf-8'))
|
||||
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="rtsw",
|
||||
password="123456",
|
||||
database="reposyncer"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS last_subject_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, last_subject VARCHAR(100))''')
|
||||
|
||||
information = json.loads(post_data.decode('utf-8'))
|
||||
|
||||
if 'pull_request' not in information:
|
||||
issue_information = information['issue']
|
||||
print(issue_information)
|
||||
|
||||
if 'subject' in issue_information:#这里是判别是gitlink平台发来的消息 需要对gitee和github平台进行相应的同步
|
||||
|
||||
cursor.execute('SELECT last_subject FROM last_subject_list ORDER BY id DESC LIMIT 1')
|
||||
result = cursor.fetchone()
|
||||
subject_last = result[0]
|
||||
if subject_last != issue_information['subject']:
|
||||
|
||||
# 这里对gitee平台进行同步
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
# 创建issue的标题和内容
|
||||
issue_title = issue_information['subject']
|
||||
issue_body = issue_information['description']
|
||||
# Gitee创建issue的API URL
|
||||
url = f"https://gitee.com/api/v5/repos/{owner}/issues"
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"title": issue_title,
|
||||
"body": issue_body
|
||||
}
|
||||
response = requests.post(url, headers=headers, json=data)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 201:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(f'Issue created with ID: {issue_info["number"]}')
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
#这里对github平台进行同步
|
||||
|
||||
# GitHub创建issue的API URL
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/issues"
|
||||
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"title": issue_title,
|
||||
"body": issue_body
|
||||
}
|
||||
response = requests.post(url, headers=headers, json=data, verify=False)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 201:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上GitHub可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(f'Issue created with ID: {issue_info["number"]}')
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
sql = "INSERT INTO last_subject_list (last_subject) VALUES (%s)"
|
||||
# 执行 SQL 语句,注意 issue_subject 需要被放在一个元组中
|
||||
cursor.execute(sql, (issue_information['subject'],))
|
||||
|
||||
else:#还要判断一下是gitee or github 发来的消息
|
||||
|
||||
if 'gitee' in issue_information['url']: #这里说明是gitee传来的消息
|
||||
cursor.execute('SELECT last_subject FROM last_subject_list ORDER BY id DESC LIMIT 1')
|
||||
result = cursor.fetchone()
|
||||
subject_last = result[0]
|
||||
if subject_last != issue_information['title']:
|
||||
subject = issue_information['title']
|
||||
description = issue_information['body']
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues.json"
|
||||
|
||||
payload = json.dumps({
|
||||
"status_id": 1, # status对应 1对应新增 2对应正在解决 3对应已解决
|
||||
"priority_id": 2, # priority对应 1对应低 2对应正常 3对应高优先级
|
||||
"subject": subject,
|
||||
"description": description,
|
||||
})
|
||||
# 替换为您的实际访问令牌
|
||||
access_token = 'HXn433Vth2ksJmpv3yVqaE7qgK1yJbDFwc_xnITcM-o'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
|
||||
print(response.text)
|
||||
|
||||
# GitHub创建issue的API URL
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/issues"
|
||||
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"title": subject,
|
||||
"body": description
|
||||
}
|
||||
response = requests.post(url, headers=headers, json=data, verify=False)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 201:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上GitHub可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(f'Issue created with ID: {issue_info["number"]}')
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
sql = "INSERT INTO last_subject_list (last_subject) VALUES (%s)"
|
||||
# 执行 SQL 语句,注意 issue_subject 需要被放在一个元组中
|
||||
cursor.execute(sql, (issue_information['title'],))
|
||||
|
||||
else:#这里是github发来的消息
|
||||
|
||||
cursor.execute('SELECT last_subject FROM last_subject_list ORDER BY id DESC LIMIT 1')
|
||||
result = cursor.fetchone()
|
||||
subject_last = result[0]
|
||||
if subject_last != issue_information['title']:
|
||||
subject = issue_information['title']
|
||||
description = issue_information['body']
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues.json"
|
||||
|
||||
payload = json.dumps({
|
||||
"status_id": 1, # status对应 1对应新增 2对应正在解决 3对应已解决
|
||||
"priority_id": 2, # priority对应 1对应低 2对应正常 3对应高优先级
|
||||
"subject": subject,
|
||||
"description": description,
|
||||
})
|
||||
# 替换为您的实际访问令牌
|
||||
access_token = '_LSPz_Q_g9h7j-Zo64hO2MDPMjDTS_o6rqD809mxWgQ'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
|
||||
print(response.text)
|
||||
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
# Gitee创建issue的API URL
|
||||
url = f"https://gitee.com/api/v5/repos/{owner}/issues"
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"title": subject,
|
||||
"body": description
|
||||
}
|
||||
response = requests.post(url, headers=headers, json=data)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 201:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(f'Issue created with ID: {issue_info["number"]}')
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
|
||||
sql = "INSERT INTO last_subject_list (last_subject) VALUES (%s)"
|
||||
# 执行 SQL 语句,注意 issue_subject 需要被放在一个元组中
|
||||
cursor.execute(sql, (issue_information['title'],))
|
||||
|
||||
|
||||
# 提交事务
|
||||
conn.commit()
|
||||
# 关闭游标和连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
else:
|
||||
|
||||
pr_information = information['pull_request']
|
||||
pr_user_information = pr_information['user']
|
||||
pr_user_url_information = pr_user_information['avatar_url']
|
||||
|
||||
if 'gitee' in pr_user_url_information: #gitee平台发来请求
|
||||
pr_target_branch = information['target_branch']
|
||||
pr_source_branch = information['source_branch']
|
||||
pr_title = information['title']
|
||||
pr_body = information['body']
|
||||
#对gitlink的同步
|
||||
url = "https://gitlink.org.cn/api/xumingyang21/reposyncer2/pulls.json"
|
||||
payload = json.dumps({
|
||||
"title": pr_title,
|
||||
"priority_id": "2",
|
||||
"body": pr_body,
|
||||
"head": pr_source_branch,
|
||||
"base": pr_target_branch,
|
||||
"is_original": False,
|
||||
"fork_project_id": "",
|
||||
"files_count": 1,
|
||||
"commits_count": 1,
|
||||
"reviewer_ids": [],
|
||||
"receivers_login": []
|
||||
})
|
||||
access_token = '_LSPz_Q_g9h7j-Zo64hO2MDPMjDTS_o6rqD809mxWgQ'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
data = response.json()
|
||||
print(data)
|
||||
print(response.text)
|
||||
|
||||
#对github的同步
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/pulls"
|
||||
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"head": pr_source_branch,
|
||||
"base": pr_target_branch,
|
||||
"title": pr_title,
|
||||
"body": pr_body
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, json=data, verify=False)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 201:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上GitHub可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(f'Issue created with ID: {issue_info["number"]}')
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
elif 'gitlink' in pr_user_url_information:
|
||||
|
||||
|
||||
gitlink_pr_info = information['pull_request']
|
||||
pr_title = gitlink_pr_info['title']
|
||||
pr_body = gitlink_pr_info['body']
|
||||
head_info = gitlink_pr_info['head']
|
||||
pr_head = head_info['label']
|
||||
base_info = gitlink_pr_info['base']
|
||||
pr_base = base_info['label']
|
||||
|
||||
#对gitee进行同步
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
# Gitee获取issue的API URL
|
||||
url = f'https://gitee.com/api/v5/repos/{owner}/{repo}/pulls'
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
# 发送POST请求 获取状态为open的issue
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"title": pr_title,
|
||||
"body": pr_body,
|
||||
"head": pr_head,
|
||||
"base": pr_base
|
||||
}
|
||||
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url = f"{url}?{query_string}"
|
||||
response = requests.post(full_url, headers=headers, json=data)
|
||||
if response.status_code == 201:
|
||||
pr_info = response.json()
|
||||
print(pr_info)
|
||||
else:
|
||||
print(f"获取pr失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
#对github进行同步
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/pulls"
|
||||
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"head": pr_head,
|
||||
"base": pr_base,
|
||||
"title": pr_title,
|
||||
"body": pr_body
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, json=data, verify=False)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 201:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上GitHub可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(f'Issue created with ID: {issue_info["number"]}')
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
else:
|
||||
github_pr_info = information['pull_request']
|
||||
pr_title = github_pr_info['title']
|
||||
pr_body = github_pr_info['body']
|
||||
head_info = github_pr_info['head']
|
||||
pr_head = head_info['ref']
|
||||
base_info = github_pr_info['base']
|
||||
pr_base = base_info['ref']
|
||||
|
||||
# 对gitee进行同步
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
# Gitee获取issue的API URL
|
||||
url = f'https://gitee.com/api/v5/repos/{owner}/{repo}/pulls'
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
# 发送POST请求 获取状态为open的issue
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"title": pr_title,
|
||||
"body": pr_body,
|
||||
"head": pr_head,
|
||||
"base": pr_base
|
||||
}
|
||||
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url = f"{url}?{query_string}"
|
||||
response = requests.post(full_url, headers=headers, json=data)
|
||||
if response.status_code == 201:
|
||||
pr_info = response.json()
|
||||
print(pr_info)
|
||||
else:
|
||||
print(f"获取pr失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/pulls"
|
||||
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"head": pr_head,
|
||||
"base": pr_base,
|
||||
"title": pr_title,
|
||||
"body": pr_body
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, json=data, verify=False)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 201:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上GitHub可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(f'Issue created with ID: {issue_info["number"]}')
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
|
||||
# 向客户端发送响应体(可选)
|
||||
# 例如,我们可以回显接收到的数据
|
||||
self.wfile.write(b"POST data received and echoed back.")
|
||||
|
||||
|
||||
def run(server_class=HTTPServer, handler_class=SimpleHTTPRequestHandler):
|
||||
server_address = ('', 8080)
|
||||
httpd = server_class(server_address, handler_class)
|
||||
print(f"Starting httpd server on {server_address[0]}:{server_address[1]}")
|
||||
httpd.serve_forever()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
run()
|
||||
10
Dockerfile
10
Dockerfile
|
|
@ -1,16 +1,18 @@
|
|||
FROM centos:7
|
||||
|
||||
RUN curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
|
||||
|
||||
RUN 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 wget -P /data/ob-tool https://repo.huaweicloud.com:8443/artifactory/python-local/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
|
||||
|
||||
ADD ./ /data/ob-robot/
|
||||
RUN cd /data/ob-robot/ && \
|
||||
pip3.9 install -r /data/ob-robot/requirement.txt
|
||||
pip3.9 install -r /data/ob-robot/requirement.txt -i https://mirrors.aliyun.com/pypi/simple/
|
||||
|
||||
RUN yum install -y git openssh-server
|
||||
RUN yum install -y git openssh-server
|
||||
|
||||
ENV GIT_SSH_COMMAND='ssh -o StrictHostKeyChecking=no -i /root/.ssh/id_rsa'
|
||||
RUN yum install -y autoconf gettext && \
|
||||
|
|
@ -24,4 +26,4 @@ RUN yum install -y autoconf gettext && \
|
|||
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
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
import requests
|
||||
|
||||
# 你的Gitee用户名(或用于认证的token)
|
||||
# 注意:出于安全考虑,通常不建议在代码中硬编码密码,而是使用token
|
||||
|
||||
# 你的仓库信息
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
|
||||
# 创建issue的标题和内容
|
||||
comment_body = '这是一个issue的详细描述'
|
||||
number = 'IAV16B'
|
||||
# Gitee创建issue的API URL
|
||||
url = f"https://gitee.com/api/v5/repos/{owner}/{repo}/issues/{number}/comments"
|
||||
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"access_token":token,
|
||||
"owner":owner,
|
||||
"repo":repo,
|
||||
"body": comment_body
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, json=data)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 201:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
import requests
|
||||
import json
|
||||
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues/8/journals.json"
|
||||
|
||||
payload = json.dumps({
|
||||
"notes": "gitlink评论尝试3",
|
||||
"receivers_login": [
|
||||
"string"
|
||||
]
|
||||
})
|
||||
access_token = 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
|
||||
print(response.text)
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
import urllib
|
||||
|
||||
import requests
|
||||
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5' # 假设这是您的有效token
|
||||
# 你的仓库信息
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
number = '206035'
|
||||
# Gitee删除issue的API URL
|
||||
url = f'https://gitee.com/api/v5/repos/{owner}/{repo}/milestones/{number}'
|
||||
|
||||
# 构造请求头
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
data = {
|
||||
"access_token":token,
|
||||
"owner":owner,
|
||||
"repo":repo,
|
||||
"number": number
|
||||
}
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url1 = f"{url}?{query_string}"
|
||||
|
||||
response = requests.delete(full_url1, headers=headers, json=data)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
|
||||
# 检查响应状态码
|
||||
if response.status_code == 204:
|
||||
print('Issue已成功删除。')
|
||||
else:
|
||||
print(f"删除issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
import requests
|
||||
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues/8/journals/399256.json"
|
||||
|
||||
payload={}
|
||||
access_token = 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
|
||||
}
|
||||
|
||||
response = requests.request("DELETE", url, headers=headers, data=payload)
|
||||
|
||||
print(response.text)
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
import urllib
|
||||
import requests
|
||||
import mysql.connector
|
||||
|
||||
# # 连接到MySQL数据库
|
||||
# conn = mysql.connector.connect(
|
||||
# host="localhost",
|
||||
# user="root",
|
||||
# password="185102xmy",
|
||||
# database="db1"
|
||||
# )
|
||||
# cursor = conn.cursor()
|
||||
# cursor.execute('DROP TABLE IF EXISTS gitee_comments_list')
|
||||
# # 创建一个表
|
||||
# cursor.execute('''CREATE TABLE IF NOT EXISTS gitee_comments_list
|
||||
# (id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), title VARCHAR(100), body VARCHAR(1000), state VARCHAR(15), priority INT)''')
|
||||
# 你的仓库信息
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
|
||||
# Gitee获取issue的API URL
|
||||
url = f"https://gitee.com/api/v5/repos/{owner}/{repo}/issues/comments"
|
||||
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
# 发送POST请求 获取状态为open的issue
|
||||
data = {
|
||||
"access_token":token,
|
||||
"owner":owner,
|
||||
"repo":repo,
|
||||
"sort":'updated',
|
||||
"direction":'asc',
|
||||
"since":'2024-10-28T00:00:00Z'
|
||||
}
|
||||
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url1 = f"{url}?{query_string}"
|
||||
|
||||
response = requests.get(full_url1, headers=headers, json=data)
|
||||
# 打印响应
|
||||
# print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 200:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(issue_info)
|
||||
else:
|
||||
print(f"创建issue失败12,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
# # 提交事务
|
||||
# conn.commit()
|
||||
# # 关闭游标和连接
|
||||
# cursor.close()
|
||||
# conn.close()
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
import requests
|
||||
import json
|
||||
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues/7/journals.json"
|
||||
|
||||
payload = {}
|
||||
access_token = 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers, data=payload)
|
||||
info = json.loads(response.text)
|
||||
print(json.loads(response.text))
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
import urllib
|
||||
import requests
|
||||
import mysql.connector
|
||||
|
||||
# # 连接到MySQL数据库
|
||||
# conn = mysql.connector.connect(
|
||||
# host="localhost",
|
||||
# user="root",
|
||||
# password="185102xmy",
|
||||
# database="db1"
|
||||
# )
|
||||
# cursor = conn.cursor()
|
||||
# cursor.execute('DROP TABLE IF EXISTS gitee_comments_list')
|
||||
# # 创建一个表
|
||||
# cursor.execute('''CREATE TABLE IF NOT EXISTS gitee_comments_list
|
||||
# (id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), title VARCHAR(100), body VARCHAR(1000), state VARCHAR(15), priority INT)''')
|
||||
# 你的仓库信息
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
number = 'IAV16B'
|
||||
# Gitee获取issue的API URL
|
||||
url = f"https://gitee.com/api/v5/repos/{owner}/{repo}/issues/{number}/comments"
|
||||
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
# 发送POST请求 获取状态为open的issue
|
||||
data = {
|
||||
"access_token":token,
|
||||
"owner":owner,
|
||||
"repo":repo,
|
||||
#"state":'all',
|
||||
"sort":'created',
|
||||
"direction":'asc'
|
||||
}
|
||||
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url1 = f"{url}?{query_string}"
|
||||
|
||||
response = requests.get(full_url1, headers=headers, json=data)
|
||||
# 打印响应
|
||||
# print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 200:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(issue_info)
|
||||
else:
|
||||
print(f"创建issue失败12,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
# # 提交事务
|
||||
# conn.commit()
|
||||
# # 关闭游标和连接
|
||||
# cursor.close()
|
||||
# conn.close()
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
import urllib
|
||||
import requests
|
||||
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
id = '33264649'
|
||||
# Gitee创建issue的API URL
|
||||
url = f'https://gitee.com/api/v5/repos/{owner}/{repo}/issues/comments/{id}'
|
||||
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"body" : '尝试更改评论'
|
||||
}
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url1 = f"{url}?{query_string}"
|
||||
response = requests.patch(full_url1, headers=headers, json=data)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 200:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,124 @@
|
|||
import re
|
||||
|
||||
def parse_git_output(output):
|
||||
# 定义正则表达式模式
|
||||
commit_pattern = re.compile(r'commit\s+([a-f0-9]+)')
|
||||
author_pattern = re.compile(r'Author:\s+(.+)')
|
||||
date_pattern = re.compile(r'Date:\s+(.+)')
|
||||
|
||||
# 使用正则表达式搜索并提取信息
|
||||
commit_hash = commit_pattern.search(output).group(1) if commit_pattern.search(output) else None
|
||||
author = author_pattern.search(output).group(1) if author_pattern.search(output) else None
|
||||
date = date_pattern.search(output).group(1) if date_pattern.search(output) else None
|
||||
|
||||
return commit_hash, author, date
|
||||
|
||||
def extract_diff_content(git_diff_output):
|
||||
# 定义正则表达式,匹配从 'diff --git' 开始到 'index' 之前的文本
|
||||
pattern = re.compile(r'diff --git(.+?)(?=\nindex|$)', re.DOTALL)
|
||||
|
||||
# 使用正则表达式查找所有匹配项
|
||||
matches = pattern.findall(git_diff_output)
|
||||
|
||||
# 存储截取的内容
|
||||
extracted_contents = []
|
||||
|
||||
# 遍历所有匹配项
|
||||
for match in matches:
|
||||
# 去除每个匹配项中的空白行,并添加到结果列表
|
||||
cleaned_match = '\n'.join(line for line in match.strip().split('\n') if line)
|
||||
extracted_contents.append(cleaned_match)
|
||||
|
||||
return extracted_contents
|
||||
|
||||
def extract_changes_since_last_diff(diff_output):
|
||||
# 定义正则表达式,匹配 '+++ b' 后面的内容,直到下一个 'diff' 或文本末尾
|
||||
pattern = re.compile(r'\+\+\+ b/(.+?)(?=\ndiff --git|$)', re.DOTALL)
|
||||
|
||||
# 使用正则表达式查找所有匹配项
|
||||
matches = pattern.findall(diff_output)
|
||||
|
||||
# 处理匹配结果,每项匹配结果是一个元组,包含从 '+++ b/' 到下一个 'diff' 或文本末尾的内容
|
||||
extracted_content = []
|
||||
for match in matches:
|
||||
# 去除匹配内容中的 '\ No newline at end of file' 行
|
||||
content = '\n'.join([line for line in match.strip().split('\n') if line and line != '\\ No newline at end of file'])
|
||||
extracted_content.append(content)
|
||||
|
||||
return extracted_content
|
||||
|
||||
git_diff_output = """
|
||||
Last commit hash before push: commit d5f594d3bc9bf2fabf1f97cd375f1ca8be821d60
|
||||
Author: xmy <1926207361@qq.com>
|
||||
Date: Wed Jun 26 08:02:53 2024 +0800
|
||||
closer
|
||||
diff --git a/src/Merry_Christmas.txt b/src/Merry_Christmas.txt
|
||||
new file mode 100644
|
||||
index 0000000..8f3694f
|
||||
--- /dev/null
|
||||
+++ b/src/Merry_Christmas.txt
|
||||
@@ -0,0 +1 @@
|
||||
+坂本龙一
|
||||
\ No newline at end of file
|
||||
diff --git a/src/changsha.txt b/src/changsha.txt
|
||||
index 7df336a..f007879 100644
|
||||
--- a/src/changsha.txt
|
||||
+++ b/src/changsha.txt
|
||||
@@ -1 +1,3 @@
|
||||
-抗洪抢险 党员优先
|
||||
\ No newline at end of file
|
||||
+抗洪抢险 党员优先
|
||||
+
|
||||
+新增调试
|
||||
\ No newline at end of file
|
||||
"""
|
||||
|
||||
commit_hash, author, date = parse_git_output(git_diff_output)
|
||||
print("Commit Hash:", commit_hash)
|
||||
print("Author:", author)
|
||||
print("Date:", date)
|
||||
print("\n")
|
||||
|
||||
extracted_contents = extract_diff_content(git_diff_output)
|
||||
|
||||
# 提取 '+++ b' 后面的内容
|
||||
changes_since_last_diff = extract_changes_since_last_diff(git_diff_output)
|
||||
|
||||
# 打印提取的内容
|
||||
for content in extracted_contents:
|
||||
if 'new file' in content:
|
||||
pattern = re.compile(r' b/(.+?)(?=\nnew|$)', re.DOTALL)
|
||||
# 使用正则表达式查找所有匹配项
|
||||
matches = pattern.findall(content)
|
||||
# 存储截取的内容
|
||||
add_files = []
|
||||
# 遍历所有匹配项
|
||||
for match in matches:
|
||||
# 去除每个匹配项中的空白行,并添加到结果列表
|
||||
cleaned_match = '\n'.join(line for line in match.strip().split('\n') if line)
|
||||
add_files.append(cleaned_match)
|
||||
|
||||
print('ADD_FILES:', add_files)
|
||||
|
||||
for add_file in add_files:
|
||||
for change in changes_since_last_diff:
|
||||
if add_file in change:
|
||||
print("\n"+change)
|
||||
print("\n--- End of Extracted Content ---\n")
|
||||
else:
|
||||
pattern = re.compile(r'a/(.+?)(?=b|$)', re.DOTALL)
|
||||
# 使用正则表达式查找所有匹配项
|
||||
matches = pattern.findall(content)
|
||||
# 存储截取的内容
|
||||
modified_files = []
|
||||
# 遍历所有匹配项
|
||||
for match in matches:
|
||||
# 去除每个匹配项中的空白行,并添加到结果列表
|
||||
cleaned_match = '\n'.join(line for line in match.strip().split('\n') if line)
|
||||
modified_files.append(cleaned_match)
|
||||
print('MODIFIED_FILES:', modified_files)
|
||||
for modified_file in modified_files:
|
||||
for change in changes_since_last_diff:
|
||||
if modified_file in change:
|
||||
print("\n"+ change)
|
||||
print("\n--- End of Extracted Content ---\n")
|
||||
|
|
@ -0,0 +1,841 @@
|
|||
import urllib
|
||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||
import requests
|
||||
import json
|
||||
import mysql.connector
|
||||
|
||||
|
||||
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
|
||||
|
||||
def do_GET(self):
|
||||
# 处理 GET 请求的代码保持不变
|
||||
self.send_response(200)
|
||||
self.send_header('Content-type', 'text/html')
|
||||
self.end_headers()
|
||||
self.wfile.write(b"Hello, World! This is a simple HTTP server running on port 8080.")
|
||||
|
||||
def do_POST(self):
|
||||
# 设置响应状态码为200
|
||||
self.send_response(200)
|
||||
# 设置响应头,这里可以根据需要设置不同的内容类型
|
||||
self.send_header('Content-type', 'text/plain')
|
||||
self.end_headers()
|
||||
|
||||
# 读取请求体中的内容
|
||||
# 注意:这里使用了self.rfile来读取数据,但通常需要知道内容的长度
|
||||
# 这里我们假设内容很短,并且使用简单的读取方式
|
||||
content_length = int(self.headers['Content-Length'])
|
||||
post_data = self.rfile.read(content_length)
|
||||
# 打印接收到的数据
|
||||
print("Received POST data:", post_data.decode('utf-8'))
|
||||
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="rtsw",
|
||||
password="123456",
|
||||
database="reposyncer"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS last_subject_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, last_subject VARCHAR(100))''')
|
||||
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS last_comment_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, last_comment VARCHAR(100))''')
|
||||
|
||||
information = json.loads(post_data.decode('utf-8'))
|
||||
|
||||
if 'comment' in information:#这里是gitee或者是github有关于comment的
|
||||
comment_issue_information = information['issue']
|
||||
comment_information = information['comment']
|
||||
comment_body = comment_information['body']
|
||||
comment_issue_title= comment_issue_information['title']
|
||||
if 'gitee' in comment_issue_information['user']['url']:#这里说明是gitee创建comment传来的信息
|
||||
cursor.execute('SELECT last_comment FROM last_comment_list ORDER BY id DESC LIMIT 1')
|
||||
result = cursor.fetchone()
|
||||
comment_last = result[0]
|
||||
if comment_last != comment_body:
|
||||
# 在gitlink上面创建comment 首先需要获取gitlink上面所有的issue
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues.json?category&participant_category&keyword&author_id&milestone_id&assigner_id&status_id&sort_by&sort_direction&issue_tag_ids&page&limit&debug=admin"
|
||||
|
||||
payload = {}
|
||||
headers = {
|
||||
'Authorization': 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg',
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
|
||||
}
|
||||
response = requests.request("GET", url, headers=headers, data=payload)
|
||||
data = response.json()
|
||||
for issue in data['issues']:
|
||||
if comment_issue_title == issue['subject']:
|
||||
url = f"https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues/{issue['project_issues_index']}/journals.json"
|
||||
|
||||
payload = json.dumps({
|
||||
"notes": comment_body,
|
||||
"receivers_login": [
|
||||
"string"
|
||||
]
|
||||
})
|
||||
access_token = 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
print(response.text)
|
||||
# 在GitHub的对应issue中创建评论 先不填 留着
|
||||
|
||||
sql = "INSERT INTO last_comment_list (last_comment) VALUES (%s)"
|
||||
# 执行 SQL 语句,注意 issue_subject 需要被放在一个元组中
|
||||
cursor.execute(sql, (comment_body,))
|
||||
conn.commit()
|
||||
|
||||
else: #这时候说明 是GitHub传来的信息
|
||||
cursor.execute('SELECT last_comment FROM last_comment_list ORDER BY id DESC LIMIT 1')
|
||||
result = cursor.fetchone()
|
||||
comment_last = result[0]
|
||||
if comment_last != comment_body:
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues.json?category&participant_category&keyword&author_id&milestone_id&assigner_id&status_id&sort_by&sort_direction&issue_tag_ids&page&limit&debug=admin"
|
||||
|
||||
payload = {}
|
||||
headers = {
|
||||
'Authorization': 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg',
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers, data=payload)
|
||||
data = response.json()
|
||||
for issue in data['issues']:
|
||||
if issue['subject'] == comment_issue_title:
|
||||
url = f"https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues/{issue['project_issues_index']}/journals.json"
|
||||
|
||||
payload = json.dumps({
|
||||
"notes": comment_body,
|
||||
"receivers_login": [
|
||||
"string"
|
||||
]
|
||||
})
|
||||
access_token = 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
print(response.text)
|
||||
|
||||
# 在gitee中对应的issue中创建comment
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
# Gitee获取issue的API URL
|
||||
url = f"https://gitee.com/api/v5/repos/{owner}/{repo}/issues"
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
# 发送POST请求 获取状态为open的issue
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
# "state":'all',
|
||||
"sort": 'created',
|
||||
"direction": 'asc'
|
||||
}
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url1 = f"{url}?{query_string}"
|
||||
response = requests.get(full_url1, headers=headers, json=data)
|
||||
issue_info = response.json()
|
||||
for single_issue in issue_info:
|
||||
if single_issue['title'] == comment_issue_title:
|
||||
number = single_issue['number']
|
||||
# Gitee创建issue的API URL
|
||||
url = f"https://gitee.com/api/v5/repos/{owner}/{repo}/issues/{number}/comments"
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"body": comment_body
|
||||
}
|
||||
response = requests.post(url, headers=headers, json=data)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
|
||||
sql = "INSERT INTO last_comment_list (last_comment) VALUES (%s)"
|
||||
# 执行 SQL 语句,注意 issue_subject 需要被放在一个元组中
|
||||
cursor.execute(sql, (comment_body,))
|
||||
# 提交事务
|
||||
conn.commit()
|
||||
|
||||
elif 'journal' in information:#这里是gitlink有关comment的
|
||||
issue_information = information['issue']
|
||||
issue_subject = issue_information['subject']
|
||||
comment_body = information['journal']['notes']
|
||||
|
||||
cursor.execute('SELECT last_comment FROM last_comment_list ORDER BY id DESC LIMIT 1')
|
||||
result = cursor.fetchone()
|
||||
comment_last = result[0]
|
||||
if comment_last != comment_body:
|
||||
# 在gitee同步评论
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
# Gitee获取issue的API URL
|
||||
url = f"https://gitee.com/api/v5/repos/{owner}/{repo}/issues"
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
# 发送POST请求 获取状态为open的issue
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
# "state":'all',
|
||||
"sort": 'created',
|
||||
"direction": 'asc'
|
||||
}
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url1 = f"{url}?{query_string}"
|
||||
response = requests.get(full_url1, headers=headers, json=data)
|
||||
issue_info = response.json()
|
||||
for single_issue in issue_info:
|
||||
if single_issue['title'] == issue_subject:
|
||||
number = single_issue['number']
|
||||
# Gitee创建issue的API URL
|
||||
url = f"https://gitee.com/api/v5/repos/{owner}/{repo}/issues/{number}/comments"
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"body": comment_body
|
||||
}
|
||||
response = requests.post(url, headers=headers, json=data)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
|
||||
# 在这里进行GitHub的评论同步
|
||||
|
||||
sql = "INSERT INTO last_comment_list (last_comment) VALUES (%s)"
|
||||
# 执行 SQL 语句,注意 issue_subject 需要被放在一个元组中
|
||||
cursor.execute(sql, (comment_body,))
|
||||
conn.commit()
|
||||
|
||||
elif 'pull_request' in information:
|
||||
pr_information = information['pull_request']
|
||||
pr_user_information = pr_information['user']
|
||||
pr_user_url_information = pr_user_information['avatar_url']
|
||||
|
||||
if 'gitee' in pr_user_url_information: #gitee平台发来请求
|
||||
pr_target_branch = information['target_branch']
|
||||
pr_source_branch = information['source_branch']
|
||||
pr_title = information['title']
|
||||
pr_body = information['body']
|
||||
#对gitlink的同步
|
||||
url = "https://gitlink.org.cn/api/xumingyang21/reposyncer2/pulls.json"
|
||||
payload = json.dumps({
|
||||
"title": pr_title,
|
||||
"priority_id": "2",
|
||||
"body": pr_body,
|
||||
"head": pr_source_branch,
|
||||
"base": pr_target_branch,
|
||||
"is_original": False,
|
||||
"fork_project_id": "",
|
||||
"files_count": 1,
|
||||
"commits_count": 1,
|
||||
"reviewer_ids": [],
|
||||
"receivers_login": []
|
||||
})
|
||||
access_token = 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
data = response.json()
|
||||
print(data)
|
||||
print(response.text)
|
||||
|
||||
#对github的同步
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/pulls"
|
||||
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"head": pr_source_branch,
|
||||
"base": pr_target_branch,
|
||||
"title": pr_title,
|
||||
"body": pr_body
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, json=data, verify=False)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 201:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上GitHub可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(f'Issue created with ID: {issue_info["number"]}')
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
elif 'gitlink' in pr_user_url_information:
|
||||
|
||||
|
||||
gitlink_pr_info = information['pull_request']
|
||||
pr_title = gitlink_pr_info['title']
|
||||
pr_body = gitlink_pr_info['body']
|
||||
head_info = gitlink_pr_info['head']
|
||||
pr_head = head_info['label']
|
||||
base_info = gitlink_pr_info['base']
|
||||
pr_base = base_info['label']
|
||||
|
||||
#对gitee进行同步
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
# Gitee获取issue的API URL
|
||||
url = f'https://gitee.com/api/v5/repos/{owner}/{repo}/pulls'
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
# 发送POST请求 获取状态为open的issue
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"title": pr_title,
|
||||
"body": pr_body,
|
||||
"head": pr_head,
|
||||
"base": pr_base
|
||||
}
|
||||
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url = f"{url}?{query_string}"
|
||||
response = requests.post(full_url, headers=headers, json=data)
|
||||
if response.status_code == 201:
|
||||
pr_info = response.json()
|
||||
print(pr_info)
|
||||
else:
|
||||
print(f"获取pr失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
#对github进行同步
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/pulls"
|
||||
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"head": pr_head,
|
||||
"base": pr_base,
|
||||
"title": pr_title,
|
||||
"body": pr_body
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, json=data, verify=False)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 201:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上GitHub可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(f'Issue created with ID: {issue_info["number"]}')
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
else:
|
||||
github_pr_info = information['pull_request']
|
||||
pr_title = github_pr_info['title']
|
||||
pr_body = github_pr_info['body']
|
||||
head_info = github_pr_info['head']
|
||||
pr_head = head_info['ref']
|
||||
base_info = github_pr_info['base']
|
||||
pr_base = base_info['ref']
|
||||
|
||||
# 对gitee进行同步
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
# Gitee获取issue的API URL
|
||||
url = f'https://gitee.com/api/v5/repos/{owner}/{repo}/pulls'
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
# 发送POST请求 获取状态为open的issue
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"title": pr_title,
|
||||
"body": pr_body,
|
||||
"head": pr_head,
|
||||
"base": pr_base
|
||||
}
|
||||
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url = f"{url}?{query_string}"
|
||||
response = requests.post(full_url, headers=headers, json=data)
|
||||
if response.status_code == 201:
|
||||
pr_info = response.json()
|
||||
print(pr_info)
|
||||
else:
|
||||
print(f"获取pr失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/pulls"
|
||||
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"head": pr_head,
|
||||
"base": pr_base,
|
||||
"title": pr_title,
|
||||
"body": pr_body
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, json=data, verify=False)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 201:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上GitHub可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(f'Issue created with ID: {issue_info["number"]}')
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
else:
|
||||
issue_information = information['issue']
|
||||
print(issue_information)
|
||||
|
||||
#这里要判断一下是什么操作 创建还是删除
|
||||
if information['action'] == 'open' or information['action'] == 'opened':
|
||||
if 'subject' in issue_information: # 这里是判别是gitlink平台发来的消息 需要对gitee和github平台进行相应的同步
|
||||
|
||||
cursor.execute('SELECT last_subject FROM last_subject_list ORDER BY id DESC LIMIT 1')
|
||||
result = cursor.fetchone()
|
||||
subject_last = result[0]
|
||||
if subject_last != issue_information['subject']:
|
||||
|
||||
# 这里对gitee平台进行同步
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
# 创建issue的标题和内容
|
||||
issue_title = issue_information['subject']
|
||||
issue_body = issue_information['description']
|
||||
# Gitee创建issue的API URL
|
||||
url = f"https://gitee.com/api/v5/repos/{owner}/issues"
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"title": issue_title,
|
||||
"body": issue_body
|
||||
}
|
||||
response = requests.post(url, headers=headers, json=data)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 201:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(f'Issue created with ID: {issue_info["number"]}')
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
# 这里对github平台进行同步
|
||||
|
||||
# GitHub创建issue的API URL
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/issues"
|
||||
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"title": issue_title,
|
||||
"body": issue_body
|
||||
}
|
||||
response = requests.post(url, headers=headers, json=data, verify=False)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 201:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上GitHub可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(f'Issue created with ID: {issue_info["number"]}')
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
sql = "INSERT INTO last_subject_list (last_subject) VALUES (%s)"
|
||||
# 执行 SQL 语句,注意 issue_subject 需要被放在一个元组中
|
||||
cursor.execute(sql, (issue_information['subject'],))
|
||||
|
||||
else: # 还要判断一下是gitee or github 发来的消息
|
||||
|
||||
if 'gitee' in issue_information['user']['url']: # 这里说明是gitee传来的消息
|
||||
cursor.execute('SELECT last_subject FROM last_subject_list ORDER BY id DESC LIMIT 1')
|
||||
result = cursor.fetchone()
|
||||
subject_last = result[0]
|
||||
if subject_last != issue_information['title']:
|
||||
subject = issue_information['title']
|
||||
description = issue_information['body']
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues.json"
|
||||
|
||||
payload = json.dumps({
|
||||
"status_id": 1, # status对应 1对应新增 2对应正在解决 3对应已解决
|
||||
"priority_id": 2, # priority对应 1对应低 2对应正常 3对应高优先级
|
||||
"subject": subject,
|
||||
"description": description,
|
||||
})
|
||||
# 替换为您的实际访问令牌
|
||||
access_token = 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
|
||||
print(response.text)
|
||||
|
||||
# GitHub创建issue的API URL
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/issues"
|
||||
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"title": subject,
|
||||
"body": description
|
||||
}
|
||||
response = requests.post(url, headers=headers, json=data, verify=False)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 201:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上GitHub可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(f'Issue created with ID: {issue_info["number"]}')
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
sql = "INSERT INTO last_subject_list (last_subject) VALUES (%s)"
|
||||
# 执行 SQL 语句,注意 issue_subject 需要被放在一个元组中
|
||||
cursor.execute(sql, (issue_information['title'],))
|
||||
|
||||
else: # 这里是github发来的消息
|
||||
|
||||
cursor.execute('SELECT last_subject FROM last_subject_list ORDER BY id DESC LIMIT 1')
|
||||
result = cursor.fetchone()
|
||||
subject_last = result[0]
|
||||
if subject_last != issue_information['title']:
|
||||
subject = issue_information['title']
|
||||
description = issue_information['body']
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues.json"
|
||||
|
||||
payload = json.dumps({
|
||||
"status_id": 1, # status对应 1对应新增 2对应正在解决 3对应已解决
|
||||
"priority_id": 2, # priority对应 1对应低 2对应正常 3对应高优先级
|
||||
"subject": subject,
|
||||
"description": description,
|
||||
})
|
||||
# 替换为您的实际访问令牌
|
||||
access_token = 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
|
||||
print(response.text)
|
||||
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
# Gitee创建issue的API URL
|
||||
url = f"https://gitee.com/api/v5/repos/{owner}/issues"
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"title": subject,
|
||||
"body": description
|
||||
}
|
||||
response = requests.post(url, headers=headers, json=data)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 201:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(f'Issue created with ID: {issue_info["number"]}')
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
sql = "INSERT INTO last_subject_list (last_subject) VALUES (%s)"
|
||||
# 执行 SQL 语句,注意 issue_subject 需要被放在一个元组中
|
||||
cursor.execute(sql, (issue_information['title'],))
|
||||
|
||||
elif information['action'] == 'delete':#这里只能是gitee发出来 然后对gitlink进行删除操作
|
||||
|
||||
#删除gitlink中对应的issue
|
||||
issue_title = issue_information['title']
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues.json?category&participant_category&keyword&author_id&milestone_id&assigner_id&status_id&sort_by&sort_direction&issue_tag_ids&page&limit&debug=admin"
|
||||
|
||||
payload = {}
|
||||
headers = {
|
||||
'Authorization': 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg',
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
|
||||
}
|
||||
response = requests.request("GET", url, headers=headers, data=payload)
|
||||
data = response.json()
|
||||
for issue in data['issues']:
|
||||
if issue['subject'] == issue_title:
|
||||
#删除对应的issue
|
||||
url = f"https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues/{issue['id']}.json"
|
||||
|
||||
payload = {}
|
||||
access_token = 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
|
||||
}
|
||||
response = requests.request("DELETE", url, headers=headers, data=payload)
|
||||
print(response.text)
|
||||
|
||||
elif information['action'] == 'closed':#说明是github传来的信息 只能对gitee操作
|
||||
issue_title = issue_information['title']
|
||||
#这里更新gitee的issue状态
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
|
||||
# Gitee获取issue的API URL
|
||||
url = f"https://gitee.com/api/v5/repos/{owner}/{repo}/issues"
|
||||
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
# 发送POST请求 获取状态为open的issue
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
# "state":'all',
|
||||
"sort": 'created',
|
||||
"direction": 'asc'
|
||||
}
|
||||
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url1 = f"{url}?{query_string}"
|
||||
|
||||
response = requests.get(full_url1, headers=headers, json=data)
|
||||
gitee_issue_info = response.json()
|
||||
|
||||
for single_gitee_issue_info in gitee_issue_info:
|
||||
if single_gitee_issue_info['title'] == issue_title:
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
# Gitee创建issue的API URL
|
||||
url = f'https://gitee.com/api/v5/repos/{owner}/issues/{single_gitee_issue_info["number"]}'
|
||||
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"number": single_gitee_issue_info['number'],
|
||||
"state": 'closed',
|
||||
}
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url1 = f"{url}?{query_string}"
|
||||
response = requests.patch(full_url1, headers=headers, json=data)
|
||||
print(response.text)
|
||||
|
||||
#这里更新gitlink的issue状态为closed
|
||||
|
||||
elif information['action'] == 'edited':
|
||||
gitlink_issue_title = issue_information['subject']
|
||||
#将gitee中对应的issue close
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
|
||||
# Gitee获取issue的API URL
|
||||
url = f"https://gitee.com/api/v5/repos/{owner}/{repo}/issues"
|
||||
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
# 发送POST请求 获取状态为open的issue
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
# "state":'all',
|
||||
"sort": 'created',
|
||||
"direction": 'asc'
|
||||
}
|
||||
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url1 = f"{url}?{query_string}"
|
||||
|
||||
response = requests.get(full_url1, headers=headers, json=data)
|
||||
gitee_issue_info = response.json()
|
||||
|
||||
for single_gitee_issue_info in gitee_issue_info:
|
||||
if single_gitee_issue_info['title'] == gitlink_issue_title:
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
# Gitee创建issue的API URL
|
||||
url = f'https://gitee.com/api/v5/repos/{owner}/issues/{single_gitee_issue_info["number"]}'
|
||||
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"number": single_gitee_issue_info['number'],
|
||||
"state": 'closed',
|
||||
}
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url1 = f"{url}?{query_string}"
|
||||
response = requests.patch(full_url1, headers=headers, json=data)
|
||||
print(response.text)
|
||||
|
||||
#将github中的issue关闭
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/issues"
|
||||
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
|
||||
}
|
||||
response = requests.get(url, headers=headers, json=data, verify=False)
|
||||
github_issue_info = response.json()
|
||||
for single_github_issue_info in github_issue_info:
|
||||
if single_github_issue_info['title'] == gitlink_issue_title:
|
||||
# GitHub创建issue的API URL
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/issues/{single_github_issue_info['number']}"
|
||||
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"state": 'closed'
|
||||
}
|
||||
response = requests.patch(url, headers=headers, json=data, verify=False)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
|
||||
|
||||
# 提交事务
|
||||
conn.commit()
|
||||
# 关闭游标和连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
# 向客户端发送响应体(可选)
|
||||
# 例如,我们可以回显接收到的数据
|
||||
self.wfile.write(b"POST data received and echoed back.")
|
||||
|
||||
|
||||
def run(server_class=HTTPServer, handler_class=SimpleHTTPRequestHandler):
|
||||
server_address = ('', 8080)
|
||||
httpd = server_class(server_address, handler_class)
|
||||
print(f"Starting httpd server on {server_address[0]}:{server_address[1]}")
|
||||
httpd.serve_forever()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
run()
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
import requests
|
||||
|
||||
# 你的Gitee用户名(或用于认证的token)
|
||||
# 注意:出于安全考虑,通常不建议在代码中硬编码密码,而是使用token
|
||||
|
||||
# 你的仓库信息
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
|
||||
# 创建issue的标题和内容
|
||||
issue_title = 'issue自动同步13'
|
||||
issue_body = '这是一个issue的详细描述'
|
||||
|
||||
# Gitee创建issue的API URL
|
||||
url = f"https://gitee.com/api/v5/repos/{owner}/issues"
|
||||
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"access_token":token,
|
||||
"owner":owner,
|
||||
"repo":repo,
|
||||
"title": issue_title,
|
||||
"body": issue_body
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, json=data)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 201:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(f'Issue created with ID: {issue_info["number"]}')
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
import requests
|
||||
import json
|
||||
|
||||
# 你的GitHub用户名(或用于认证的token)
|
||||
# 注意:出于安全考虑,通常不建议在代码中硬编码密码,而是使用token
|
||||
|
||||
# 你的仓库信息
|
||||
owner = 'fuxingtamu'
|
||||
repo = 'yundingzhiyi'
|
||||
|
||||
# 创建issue的标题和内容
|
||||
issue_title = 'issue自动同步5'
|
||||
issue_body = '这是一个issue的详细描述'
|
||||
|
||||
# GitHub创建issue的API URL
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/issues"
|
||||
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"title": issue_title,
|
||||
"body": issue_body
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, json=data,verify=False)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 201:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上GitHub可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(f'Issue created with ID: {issue_info["number"]}')
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
import requests
|
||||
import json
|
||||
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues.json"
|
||||
|
||||
payload = json.dumps({
|
||||
"status_id": 1, #status对应 1对应新增 2对应正在解决 3对应已解决
|
||||
"priority_id":2, #priority对应 1对应低 2对应正常 3对应高优先级
|
||||
"subject": "issue自动同步10",
|
||||
"description": "123455好吧",
|
||||
})
|
||||
# 替换为您的实际访问令牌
|
||||
access_token = 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
|
||||
print(response.text)
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
import requests
|
||||
import json
|
||||
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues/batch_destroy.json"
|
||||
|
||||
payload = json.dumps({
|
||||
"ids": [
|
||||
117173,117180,117183,117184
|
||||
]
|
||||
})
|
||||
access_token = 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
response = requests.request("DELETE", url, headers=headers, data=payload)
|
||||
|
||||
print(response.text)
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
import urllib
|
||||
|
||||
import requests
|
||||
import mysql.connector
|
||||
# 连接到MySQL数据库
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="185102xmy",
|
||||
database="db1"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('SELECT number,title,body,state,priority FROM gitee_issue_list')
|
||||
result = cursor.fetchall()
|
||||
for row in result:
|
||||
issue_number = row[0]
|
||||
# 你的Gitee用户名(或用于认证的token)
|
||||
# 注意:出于安全考虑,通常不建议在代码中硬编码密码,而是使用token
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5' # 假设这是您的有效token
|
||||
# 你的仓库信息
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
|
||||
# Gitee删除issue的API URL
|
||||
url = f'https://gitee.com/api/v5/repos/{owner}/{repo}/issues/{issue_number}'
|
||||
|
||||
# 构造请求头
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
data = {
|
||||
"access_token":token,
|
||||
"owner":owner,
|
||||
"repo":repo,
|
||||
"number":issue_number,
|
||||
}
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url1 = f"{url}?{query_string}"
|
||||
|
||||
response = requests.delete(full_url1, headers=headers, json=data)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
|
||||
# 检查响应状态码
|
||||
if response.status_code == 204:
|
||||
print('Issue已成功删除。')
|
||||
else:
|
||||
print(f"删除issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
import requests
|
||||
import json
|
||||
|
||||
# 你的GitHub用户名(或用于认证的token)
|
||||
# 注意:出于安全考虑,通常不建议在代码中硬编码密码,而是使用token
|
||||
|
||||
# 你的仓库信息
|
||||
owner = 'fuxingtamu'
|
||||
repo = 'yundingzhiyi'
|
||||
|
||||
# 创建issue的标题和内容
|
||||
issue_title = '这是一个issue标题准备删除'
|
||||
issue_body = '这是一个issue的详细描述'
|
||||
|
||||
# GitHub创建issue的API URL
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/issues/1"
|
||||
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
'owner':'fuxingtamu',
|
||||
'repo':'yundingzhiyi',
|
||||
'issue_number':2,
|
||||
'state':'closed'
|
||||
}
|
||||
|
||||
response = requests.patch(url, headers=headers, json=data,verify=False)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 201:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上GitHub可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(f'Issue created with ID: {issue_info["number"]}')
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
import requests
|
||||
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues/117188.json"
|
||||
|
||||
payload={}
|
||||
access_token = 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
|
||||
}
|
||||
|
||||
response = requests.request("DELETE", url, headers=headers, data=payload)
|
||||
|
||||
print(response.text)
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
import requests
|
||||
import json
|
||||
|
||||
|
||||
|
||||
# GitHub创建issue的API URL
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/issues/2"
|
||||
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
|
||||
}
|
||||
response = requests.get(url, headers=headers, json=data,verify=False)
|
||||
issue = response.json()
|
||||
print('title:',issue['title'])
|
||||
print('body:',issue['body'])
|
||||
print('number',issue['number'])#这个可以用来获取单个issue
|
||||
print('id',issue['id'])
|
||||
|
||||
# 打印响应
|
||||
#print(response.text)
|
||||
# 检查响应状态码
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
import urllib
|
||||
import requests
|
||||
|
||||
url = f"https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues/1.json"
|
||||
|
||||
payload = {}
|
||||
# 替换为您的实际访问令牌
|
||||
access_token = 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
response = requests.request("GET", url, headers=headers, data=payload)
|
||||
print(response.text)
|
||||
|
|
@ -0,0 +1,180 @@
|
|||
import urllib
|
||||
import requests
|
||||
import mysql.connector
|
||||
|
||||
# 连接到MySQL数据库
|
||||
# conn = mysql.connector.connect(
|
||||
# host="localhost",
|
||||
# user="root",
|
||||
# password="185102xmy",
|
||||
# database="db1"
|
||||
# )
|
||||
# cursor = conn.cursor()
|
||||
# cursor.execute('DROP TABLE IF EXISTS gitee_issue_list')
|
||||
# # 创建一个表
|
||||
# cursor.execute('''CREATE TABLE IF NOT EXISTS gitee_issue_list
|
||||
# (id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), title VARCHAR(100), body VARCHAR(1000), state VARCHAR(15), priority INT)''')
|
||||
# 你的仓库信息
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
|
||||
# Gitee获取issue的API URL
|
||||
url = f"https://gitee.com/api/v5/repos/{owner}/{repo}/issues"
|
||||
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
# 发送POST请求 获取状态为open的issue
|
||||
data = {
|
||||
"access_token":token,
|
||||
"owner":owner,
|
||||
"repo":repo,
|
||||
"state":'progressing',
|
||||
"sort":'updated',
|
||||
"direction":'asc'
|
||||
}
|
||||
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url1 = f"{url}?{query_string}"
|
||||
|
||||
response = requests.get(full_url1, headers=headers, json=data)
|
||||
# 打印响应
|
||||
# print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 200:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(issue_info)
|
||||
# cnt=0
|
||||
for issue in issue_info:
|
||||
print('number1:',issue['number'])
|
||||
print('state1:',issue['state'])
|
||||
print('title1:',issue['title'])
|
||||
print('body1:',issue['body'])
|
||||
print('priority:',issue['priority'])
|
||||
# cursor.execute('INSERT INTO gitee_issue_list (number, title, body, state, priority) VALUES (%s, %s, %s, %s, %s)',
|
||||
# (issue['number'],issue['title'],issue['body'],issue['state'],issue['priority']))
|
||||
# cnt+=1
|
||||
# print(cnt)
|
||||
else:
|
||||
print(f"创建issue失败12,状态码:{response.status_code},错误信息:{response.text}")
|
||||
#
|
||||
# # 提交事务
|
||||
# conn.commit()
|
||||
# # 关闭游标和连接
|
||||
# cursor.close()
|
||||
# conn.close()
|
||||
|
||||
# # 发送POST请求 获取状态为rejected的请求
|
||||
# data1 = {
|
||||
# # "access_token":token,
|
||||
# "owner":owner,
|
||||
# "repo":repo,
|
||||
# "state":'rejected',
|
||||
# "sort":'created',
|
||||
# "direction":'asc'
|
||||
# }
|
||||
# # 将字典转换为查询字符串
|
||||
# query_string = urllib.parse.urlencode(data1)
|
||||
#
|
||||
# # 完整的请求 URL,包括查询字符串
|
||||
# full_url2 = f"{url}?{query_string}"
|
||||
#
|
||||
# response2 = requests.get(full_url2, headers=headers)
|
||||
# # 打印响应
|
||||
# # print(response.text)
|
||||
# # 检查响应状态码
|
||||
# if response2.status_code == 200:
|
||||
# # 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# # 你需要根据实际的响应结构来调整以下代码
|
||||
# issue_info2 = response2.json()
|
||||
# for issue in issue_info2:
|
||||
# print('number:',issue['number'])
|
||||
# print('state:',issue['state'])
|
||||
# print('title:',issue['title'])
|
||||
# print('body:',issue['body'])
|
||||
# cursor.execute('INSERT INTO gitee_issue_list (number, title, body, state) VALUES (%s, %s, %s, %s)',
|
||||
# (issue['number'],issue['title'],issue['body'],issue['state']))
|
||||
#
|
||||
# else:
|
||||
# print(f"创建issue失败12,状态码:{response2.status_code},错误信息:{response2.text}")
|
||||
#
|
||||
# # 发送POST请求 获取状态为rejected的请求
|
||||
# data2 = {
|
||||
# # "access_token":token,
|
||||
# "owner":owner,
|
||||
# "repo":repo,
|
||||
# "state":'progressing',
|
||||
# "sort":'created',
|
||||
# "direction":'asc'
|
||||
# }
|
||||
# # 将字典转换为查询字符串
|
||||
# query_string = urllib.parse.urlencode(data1)
|
||||
#
|
||||
# # 完整的请求 URL,包括查询字符串
|
||||
# full_url3 = f"{url}?{query_string}"
|
||||
#
|
||||
# response3 = requests.get(full_url3, headers=headers)
|
||||
# # 打印响应
|
||||
# # print(response.text)
|
||||
# # 检查响应状态码
|
||||
# if response3.status_code == 200:
|
||||
# # 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# # 你需要根据实际的响应结构来调整以下代码
|
||||
# issue_info3 = response3.json()
|
||||
# for issue in issue_info3:
|
||||
# print('number:',issue['number'])
|
||||
# print('state:',issue['state'])
|
||||
# print('title:',issue['title'])
|
||||
# print('body:',issue['body'])
|
||||
# cursor.execute('INSERT INTO gitee_issue_list (number, title, body, state) VALUES (%s, %s, %s, %s)',
|
||||
# (issue['number'],issue['title'],issue['body'],issue['state']))
|
||||
#
|
||||
# else:
|
||||
# print(f"创建issue失败12,状态码:{response3.status_code},错误信息:{response3.text}")
|
||||
#
|
||||
#
|
||||
# # 发送POST请求 获取状态为rejected的请求
|
||||
# data2 = {
|
||||
# # "access_token":token,
|
||||
# "owner":owner,
|
||||
# "repo":repo,
|
||||
# "state":'closed',
|
||||
# "sort":'created',
|
||||
# "direction":'asc'
|
||||
# }
|
||||
# # 将字典转换为查询字符串
|
||||
# query_string = urllib.parse.urlencode(data1)
|
||||
#
|
||||
# # 完整的请求 URL,包括查询字符串
|
||||
# full_url3 = f"{url}?{query_string}"
|
||||
#
|
||||
# response4 = requests.get(full_url3, headers=headers)
|
||||
# # 打印响应
|
||||
# # print(response.text)
|
||||
# # 检查响应状态码
|
||||
# if response4.status_code == 200:
|
||||
# # 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# # 你需要根据实际的响应结构来调整以下代码
|
||||
# issue_info4 = response4.json()
|
||||
# for issue in issue_info4:
|
||||
# print('number:',issue['number'])
|
||||
# print('state:',issue['state'])
|
||||
# print('title:',issue['title'])
|
||||
# print('body:',issue['body'])
|
||||
# cursor.execute('INSERT INTO issue_list (number, title, body, state) VALUES (%s, %s, %s, %s)',
|
||||
# (issue['number'],issue['title'],issue['body'],issue['state']))
|
||||
#
|
||||
# # 提交事务
|
||||
# conn.commit()
|
||||
# # 关闭游标和连接
|
||||
# cursor.close()
|
||||
# conn.close()
|
||||
#
|
||||
# else:
|
||||
# print(f"创建issue失败12,状态码:{response4.status_code},错误信息:{response4.text}")
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
import requests
|
||||
import json
|
||||
|
||||
|
||||
|
||||
# GitHub创建issue的API URL
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/issues"
|
||||
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
|
||||
}
|
||||
response = requests.get(url, headers=headers, json=data,verify=False)
|
||||
issue_info = response.json()
|
||||
print(issue_info)
|
||||
for issue in issue_info:
|
||||
|
||||
print('title:',issue['title'])
|
||||
print('body:',issue['body'])
|
||||
print('number',issue['number'])
|
||||
print('id',issue['id'])
|
||||
# 打印响应
|
||||
#print(response.text)
|
||||
# 检查响应状态码
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
import requests
|
||||
import mysql.connector
|
||||
import json
|
||||
|
||||
# 连接到MySQL数据库
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="185102xmy",
|
||||
database="db1"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('DROP TABLE IF EXISTS gitlink_issue_list')
|
||||
# 创建一个表
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS gitlink_issue_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), subject VARCHAR(100), description VARCHAR(1000), status_name VARCHAR(15), priority_name VARCHAR(15))''')
|
||||
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues.json?category&participant_category&keyword&author_id&milestone_id&assigner_id&status_id&sort_by&sort_direction&issue_tag_ids&page&limit&debug=admin"
|
||||
|
||||
payload={}
|
||||
headers = {
|
||||
'Authorization': 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg',
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers, data=payload)
|
||||
data = response.json()
|
||||
# print(data)
|
||||
print(data['issues'])
|
||||
for issue in data['issues']:
|
||||
|
||||
url = f"https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues/{issue['id']}.json"
|
||||
|
||||
payload = {}
|
||||
|
||||
access_token = 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}',
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
|
||||
}
|
||||
|
||||
response1 = requests.get(url, headers=headers, data=payload)
|
||||
data1 = response1.json()
|
||||
# print(response.text)
|
||||
# print(data)
|
||||
print(issue['id'])
|
||||
print(issue['subject'])
|
||||
print(data1['description'])
|
||||
print(issue['status_name'])
|
||||
# print(issue[])
|
||||
cursor.execute('INSERT INTO gitlink_issue_list (number, subject, description, status_name, priority_name) VALUES (%s, %s, %s, %s, %s)',
|
||||
(issue['id'], issue['subject'],data1['description'], issue['status_name'], issue['priority_name']))
|
||||
# 提交事务
|
||||
conn.commit()
|
||||
# 关闭游标和连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
print(response.text)
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
import requests
|
||||
import json
|
||||
|
||||
url = "https://gitlink.org.cn/oauth/token"
|
||||
|
||||
payload = json.dumps({
|
||||
"grant_type": "password",
|
||||
"username": "xumingyang21",
|
||||
"password": "185102xmy",
|
||||
"client_id": "cPY5xnUHvNjcG6pon2IizuPzmci7PDjtndbgxjNKJDM",
|
||||
"client_secret": "yb-2WGqGm6RercEJq0o_QM6aZtHzRExhQB5TiAQ-Z1M"
|
||||
})
|
||||
|
||||
access_token = 'e8c55cbb234637593fd6e97e59f3947120d5a3c0'
|
||||
headers = {
|
||||
'Cookie': 'autologin_trustie=89968cdf00f5d75ffd06e679402a646ba2fa7671',
|
||||
'Authorization': f'Bearer {access_token}',
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
|
||||
print(response.text)
|
||||
|
|
@ -0,0 +1,178 @@
|
|||
import urllib
|
||||
import requests
|
||||
import mysql.connector
|
||||
import json
|
||||
|
||||
def main():
|
||||
########获取gitee里的issue并且放到数据库中#######################
|
||||
# 连接到MySQL数据库
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="185102xmy",
|
||||
database="db1"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('DROP TABLE IF EXISTS gitee_issue_list')
|
||||
# 创建一个表
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS gitee_issue_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), title VARCHAR(100), body VARCHAR(1000), state VARCHAR(15), priority INT)''')
|
||||
# 你的仓库信息
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
|
||||
# Gitee获取issue的API URL
|
||||
url = f"https://gitee.com/api/v5/repos/{owner}/{repo}/issues"
|
||||
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
# 发送POST请求 获取状态为open的issue
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"sort": 'created',
|
||||
"direction": 'asc'
|
||||
}
|
||||
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url1 = f"{url}?{query_string}"
|
||||
|
||||
response = requests.get(full_url1, headers=headers, json=data)
|
||||
# 打印响应
|
||||
# print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 200:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
for issue in issue_info:
|
||||
print('number1:', issue['number'])
|
||||
print('state1:', issue['state'])
|
||||
print('title1:', issue['title'])
|
||||
print('body1:', issue['body'])
|
||||
cursor.execute(
|
||||
'INSERT INTO gitee_issue_list (number, title, body, state, priority) VALUES (%s, %s, %s, %s, %s)',
|
||||
(issue['number'], issue['title'], issue['body'], issue['state'], issue['priority']))
|
||||
|
||||
|
||||
else:
|
||||
print(f"创建issue失败12,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
# 提交事务
|
||||
conn.commit()
|
||||
# 关闭游标和连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
########获取gitlink里的issue并且放到数据库中#######################
|
||||
# 连接到MySQL数据库
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="185102xmy",
|
||||
database="db1"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('DROP TABLE IF EXISTS github_issue_list')
|
||||
# 创建一个表
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS github_issue_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), title VARCHAR(100), body VARCHAR(1000), status_name VARCHAR(15))''')
|
||||
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/issues"
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
# 发送POST请求
|
||||
data = {
|
||||
}
|
||||
response = requests.get(url, headers=headers, json=data, verify=False)
|
||||
issue_info = response.json()
|
||||
column_data=[]
|
||||
for issue in issue_info:
|
||||
print('title:', issue['title'])
|
||||
print('body:', issue['body'])
|
||||
print('number', issue['number'])
|
||||
print('id', issue['id'])
|
||||
|
||||
cursor.execute(
|
||||
'INSERT INTO github_issue_list (number, title, body, status_name) VALUES (%s, %s, %s, %s)',
|
||||
(issue['number'], issue['title'], issue['body'], issue['id']))
|
||||
# 执行查询
|
||||
cursor.execute('SELECT number FROM github_issue_list')
|
||||
# 获取所有结果
|
||||
results = cursor.fetchall()
|
||||
# 提取列数据到列表中
|
||||
column_data = [row[0] for row in results]
|
||||
|
||||
##################删除gitlink仓库中的所有的issue###########################
|
||||
for number in column_data:
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/issues/{number}"
|
||||
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
'owner': 'fuxingtamu',
|
||||
'repo': 'yundingzhiyi',
|
||||
'issue_number': number,
|
||||
'state': 'closed'
|
||||
}
|
||||
|
||||
response = requests.patch(url, headers=headers, json=data, verify=False)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
|
||||
##################将gitee中的issue创建到gitlink中###########################
|
||||
# GitHub创建issue的API URL
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/issues"
|
||||
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
|
||||
|
||||
# 执行查询
|
||||
cursor.execute('SELECT title,body,state,priority FROM gitee_issue_list')
|
||||
# 获取所有结果
|
||||
result = cursor.fetchall()
|
||||
for row in result:
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"title": row[0],
|
||||
"body": row[1]
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, json=data, verify=False)
|
||||
print(response.text)
|
||||
|
||||
# 提交事务
|
||||
conn.commit()
|
||||
# 关闭游标和连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
|
@ -0,0 +1,312 @@
|
|||
import urllib
|
||||
import requests
|
||||
import mysql.connector
|
||||
import json
|
||||
|
||||
def main():
|
||||
########获取gitee里的issue并且放到数据库中#######################
|
||||
# 连接到MySQL数据库
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="185102xmy",
|
||||
database="db1"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('DROP TABLE IF EXISTS gitee_issue_list')
|
||||
# 创建一个表
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS gitee_issue_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), title VARCHAR(100), body VARCHAR(1000), state VARCHAR(15), priority INT)''')
|
||||
# 你的仓库信息
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
|
||||
# Gitee获取issue的API URL
|
||||
url = f"https://gitee.com/api/v5/repos/{owner}/{repo}/issues"
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
# 发送POST请求 获取状态为open的issue
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"state": 'progressing',
|
||||
"sort": 'updated',
|
||||
"direction": 'asc'
|
||||
}
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url1 = f"{url}?{query_string}"
|
||||
response = requests.get(full_url1, headers=headers, json=data)
|
||||
# 打印响应
|
||||
# print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 200:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
for issue in issue_info:
|
||||
print('number1:', issue['number'])
|
||||
print('state1:', issue['state'])
|
||||
print('title1:', issue['title'])
|
||||
print('body1:', issue['body'])
|
||||
cursor.execute(
|
||||
'INSERT INTO gitee_issue_list (number, title, body, state, priority) VALUES (%s, %s, %s, %s, %s)',
|
||||
(issue['number'], issue['title'], issue['body'], issue['state'], issue['priority']))
|
||||
else:
|
||||
print(f"创建issue失败12,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
|
||||
# Gitee获取issue的API URL
|
||||
url = f"https://gitee.com/api/v5/repos/{owner}/{repo}/issues"
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
# 发送POST请求 获取状态为open的issue
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"state": 'open',
|
||||
"sort": 'updated',
|
||||
"direction": 'asc'
|
||||
}
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url1 = f"{url}?{query_string}"
|
||||
response = requests.get(full_url1, headers=headers, json=data)
|
||||
# 打印响应
|
||||
# print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 200:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
for issue in issue_info:
|
||||
print('number1:', issue['number'])
|
||||
print('state1:', issue['state'])
|
||||
print('title1:', issue['title'])
|
||||
print('body1:', issue['body'])
|
||||
cursor.execute(
|
||||
'INSERT INTO gitee_issue_list (number, title, body, state, priority) VALUES (%s, %s, %s, %s, %s)',
|
||||
(issue['number'], issue['title'], issue['body'], issue['state'], issue['priority']))
|
||||
else:
|
||||
print(f"创建issue失败12,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
# 提交事务
|
||||
conn.commit()
|
||||
# 关闭游标和连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
########获取gitlink里的issue并且放到数据库中#######################
|
||||
# 连接到MySQL数据库
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="185102xmy",
|
||||
database="db1"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('DROP TABLE IF EXISTS gitlink_issue_list')
|
||||
# 创建一个表
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS gitlink_issue_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, project_issues_index VARCHAR(10), number VARCHAR(10), subject VARCHAR(100), description VARCHAR(1000), status_name VARCHAR(15), gitee_number VARCHAR(15))''')
|
||||
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues.json?category&participant_category&keyword&author_id&milestone_id&assigner_id&status_id&sort_by&sort_direction&issue_tag_ids&page&limit&debug=admin"
|
||||
|
||||
payload = {}
|
||||
headers = {
|
||||
'Authorization': 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg',
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers, data=payload)
|
||||
data = response.json()
|
||||
# print(data)
|
||||
print(data['issues'])
|
||||
for issue in data['issues']:
|
||||
url = f"https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues/{issue['id']}.json"
|
||||
|
||||
payload = {}
|
||||
|
||||
access_token = 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}',
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
|
||||
}
|
||||
|
||||
response1 = requests.request("GET", url, headers=headers, data=payload)
|
||||
data1 = response1.json()
|
||||
print(issue['id'])
|
||||
print(issue['project_issues_index'])
|
||||
print(issue['subject'])
|
||||
print(data1['description'])
|
||||
print(issue['status_name'])
|
||||
|
||||
cursor.execute(
|
||||
'INSERT INTO gitlink_issue_list (project_issues_index, number, subject, description, status_name) VALUES (%s, %s, %s, %s, %s)',
|
||||
(issue['project_issues_index'], issue['id'], issue['subject'], data1['description'], issue['status_name']))
|
||||
# 执行查询
|
||||
cursor.execute('SELECT number FROM gitlink_issue_list')
|
||||
# 获取所有结果
|
||||
results = cursor.fetchall()
|
||||
# 提取列数据到列表中
|
||||
column_data = [row[0] for row in results]
|
||||
|
||||
##################删除gitlink仓库中的所有的issue###########################
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues/batch_destroy.json"
|
||||
|
||||
payload = json.dumps({
|
||||
"ids": column_data
|
||||
})
|
||||
access_token = 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
response = requests.request("DELETE", url, headers=headers, data=payload)
|
||||
|
||||
print(response.text)
|
||||
|
||||
##################将gitee中的issue创建到gitlink中###########################
|
||||
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues.json"
|
||||
|
||||
# 替换为您的实际访问令牌
|
||||
access_token = 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
# 执行查询
|
||||
cursor.execute('SELECT title, body, state, priority, number FROM gitee_issue_list')
|
||||
# 获取所有结果
|
||||
result = cursor.fetchall()
|
||||
title_list = []
|
||||
body_list = []
|
||||
# cnt = 0
|
||||
for row in result:
|
||||
title_list.append(row[0])
|
||||
body_list.append(row[1])
|
||||
if row[2] == 'open':
|
||||
status = 1
|
||||
if row[2] == 'progressing':
|
||||
status = 2
|
||||
if row[2] == 'closed':
|
||||
status = 3
|
||||
if row[2] == 'rejected':
|
||||
continue
|
||||
if row[3] == 0:
|
||||
priority = 1
|
||||
if row[3] == 1:
|
||||
priority = 1
|
||||
if row[3] == 2:
|
||||
priority = 2
|
||||
if row[3] == 3:
|
||||
priority = 2
|
||||
if row[3] == 4:
|
||||
priority = 3
|
||||
|
||||
payload = json.dumps({
|
||||
|
||||
"status_id": status, # status对应 1对应新增 2对应正在解决 3对应已解决
|
||||
"priority_id": priority, # priority对应 1对应低 2对应正常 3对应高优先级
|
||||
"subject": row[0],
|
||||
"description": row[1],
|
||||
})
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
print(response.text)
|
||||
gitlink_issue_info = response.json()
|
||||
#在这里新添加对应的gitee的issue_number, 为了方便后面的添加相应的评论
|
||||
cursor.execute(
|
||||
'INSERT INTO gitlink_issue_list (project_issues_index, number, subject, description, gitee_number) VALUES (%s, %s, %s, %s, %s)',
|
||||
(gitlink_issue_info['project_issues_index'], gitlink_issue_info['id'], gitlink_issue_info['subject'], gitlink_issue_info['description'], row[4]))
|
||||
|
||||
|
||||
#这边开始写评论的同步
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
# Gitee获取issue中的comments
|
||||
url = f"https://gitee.com/api/v5/repos/{owner}/{repo}/issues/comments"
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
# 发送POST请求 获取状态为open的issue
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"sort": 'created',
|
||||
"direction": 'asc',
|
||||
"since":'2024-10-28T00:00:00Z'
|
||||
}
|
||||
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url1 = f"{url}?{query_string}"
|
||||
response = requests.get(full_url1, headers=headers, json=data)
|
||||
# 打印响应
|
||||
# print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 200:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
comment_info = response.json()
|
||||
print(comment_info)
|
||||
else:
|
||||
print(f"创建issue失败12,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
cursor.execute('DROP TABLE IF EXISTS gitee_comment_list')
|
||||
# 创建一个表
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS gitee_comment_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, body VARCHAR(100), gitee_number VARCHAR(10))''')
|
||||
for comment in comment_info:
|
||||
cursor.execute(
|
||||
'INSERT INTO gitee_comment_list (body, gitee_number) VALUES (%s, %s)',
|
||||
(comment['body'], comment['target']['issue']['number']))
|
||||
|
||||
cursor.execute('SELECT project_issues_index, gitee_number FROM gitlink_issue_list')
|
||||
comment_result = cursor.fetchall()
|
||||
for row in comment_result:
|
||||
if comment['target']['issue']['number'] == row[1]:
|
||||
#这里要执行创建gitlink的评论操作
|
||||
url = f"https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues/{row[0]}/journals.json"
|
||||
|
||||
payload = json.dumps({
|
||||
"notes": comment['body'],
|
||||
"receivers_login": [
|
||||
"string"
|
||||
]
|
||||
})
|
||||
access_token = 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
print(response.text)
|
||||
# 提交事务
|
||||
conn.commit()
|
||||
# 关闭游标和连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
@ -0,0 +1,182 @@
|
|||
import urllib
|
||||
import requests
|
||||
import mysql.connector
|
||||
import json
|
||||
|
||||
def main():
|
||||
########获取gitee里的issue并且放到数据库中#######################
|
||||
# 连接到MySQL数据库
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="185102xmy",
|
||||
database="db1"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('DROP TABLE IF EXISTS gitee_issue_list')
|
||||
# 创建一个表
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS gitee_issue_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), title VARCHAR(100), body VARCHAR(1000), state VARCHAR(15), priority INT)''')
|
||||
# 你的仓库信息
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
|
||||
# Gitee获取issue的API URL
|
||||
url = f"https://gitee.com/api/v5/repos/{owner}/{repo}/issues"
|
||||
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
# 发送POST请求 获取状态为open的issue
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"sort": 'created',
|
||||
"direction": 'asc'
|
||||
}
|
||||
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url1 = f"{url}?{query_string}"
|
||||
|
||||
response = requests.get(full_url1, headers=headers, json=data)
|
||||
# 打印响应
|
||||
# print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 200:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
for issue in issue_info:
|
||||
print('number1:', issue['number'])
|
||||
print('state1:', issue['state'])
|
||||
print('title1:', issue['title'])
|
||||
print('body1:', issue['body'])
|
||||
cursor.execute(
|
||||
'INSERT INTO gitee_issue_list (number, title, body, state, priority) VALUES (%s, %s, %s, %s, %s)',
|
||||
(issue['number'], issue['title'], issue['body'], issue['state'], issue['priority']))
|
||||
|
||||
else:
|
||||
print(f"创建issue失败12,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
########获取gitlink里的issue并且放到数据库中#######################
|
||||
# 连接到MySQL数据库
|
||||
cursor.execute('DROP TABLE IF EXISTS github_issue_list')
|
||||
# 创建一个表
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS github_issue_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), title VARCHAR(100), body VARCHAR(1000), status_name VARCHAR(15))''')
|
||||
|
||||
# GitHub创建issue的API URL
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/issues"
|
||||
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
|
||||
}
|
||||
response = requests.get(url, headers=headers, json=data, verify=False)
|
||||
issue_info = response.json()
|
||||
for issue in issue_info:
|
||||
print('title:', issue['title'])
|
||||
print('body:', issue['body'])
|
||||
print('number', issue['number'])
|
||||
print('id', issue['id'])
|
||||
|
||||
cursor.execute(
|
||||
'INSERT INTO github_issue_list (number, title, body, status_name) VALUES (%s, %s, %s, %s)',
|
||||
(issue['number'], issue['title'], issue['body'], issue['id']))
|
||||
|
||||
|
||||
##################将gitee仓库中的issue状态更新为关闭closed###########################
|
||||
cursor.execute('SELECT number FROM gitee_issue_list')
|
||||
gitee_results = cursor.fetchall()
|
||||
for row in gitee_results:
|
||||
issue_number = row[0]
|
||||
url = f'https://gitee.com/api/v5/repos/{owner}/issues/{issue_number}'
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"number": issue_number,
|
||||
"state": 'closed',
|
||||
"labels": 'wait_for_delete'
|
||||
}
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url1 = f"{url}?{query_string}"
|
||||
response = requests.patch(full_url1, headers=headers, json=data)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 200:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(f'Issue created with ID: {issue_info["number"]}')
|
||||
else:
|
||||
print(f"更新issue状态失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
##################将gitlink中的issue创建到gitee中###########################
|
||||
|
||||
cursor.execute('DROP TABLE IF EXISTS gitee_issue_list')
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS gitee_issue_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), title VARCHAR(100), body VARCHAR(1000), state VARCHAR(15), priority INT)''')
|
||||
|
||||
cursor.execute('SELECT title, body FROM github_issue_list')
|
||||
|
||||
gitlink_result = cursor.fetchall()
|
||||
|
||||
for row in gitlink_result:
|
||||
# Gitee创建issue的API URL
|
||||
url = f"https://gitee.com/api/v5/repos/{owner}/issues"
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"title": row[0],
|
||||
"body": row[1]
|
||||
}
|
||||
response = requests.post(url, headers=headers, json=data)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 201:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(f'Issue created with ID: {issue_info["number"]}')
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
# 提交事务
|
||||
|
||||
conn.commit()
|
||||
# 关闭游标和连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
@ -0,0 +1,162 @@
|
|||
import urllib
|
||||
import requests
|
||||
import mysql.connector
|
||||
import json
|
||||
|
||||
def main():
|
||||
########获取gitee里的issue并且放到数据库中#######################
|
||||
# 连接到MySQL数据库
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="185102xmy",
|
||||
database="db1"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('DROP TABLE IF EXISTS github_issue_list')
|
||||
# 创建一个表
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS github_issue_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), title VARCHAR(100), body VARCHAR(1000), status_name VARCHAR(15))''')
|
||||
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/issues"
|
||||
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
|
||||
}
|
||||
response = requests.get(url, headers=headers, json=data, verify=False)
|
||||
issue_info = response.json()
|
||||
for issue in issue_info:
|
||||
print('title:', issue['title'])
|
||||
print('body:', issue['body'])
|
||||
print('number', issue['number'])
|
||||
print('id', issue['id'])
|
||||
|
||||
cursor.execute(
|
||||
'INSERT INTO github_issue_list (number, title, body, status_name) VALUES (%s, %s, %s, %s)',
|
||||
(issue['number'], issue['title'], issue['body'], issue['id']))
|
||||
|
||||
# 提交事务
|
||||
conn.commit()
|
||||
# 关闭游标和连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
########获取gitlink里的issue并且放到数据库中#######################
|
||||
# 连接到MySQL数据库
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="185102xmy",
|
||||
database="db1"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('DROP TABLE IF EXISTS gitlink_issue_list')
|
||||
# 创建一个表
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS gitlink_issue_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), subject VARCHAR(100), description VARCHAR(1000), status_name VARCHAR(15))''')
|
||||
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues.json?category&participant_category&keyword&author_id&milestone_id&assigner_id&status_id&sort_by&sort_direction&issue_tag_ids&page&limit&debug=admin"
|
||||
|
||||
payload = {}
|
||||
headers = {
|
||||
'Authorization': 'HXn433Vth2ksJmpv3yVqaE7qgK1yJbDFwc_xnITcM-o',
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers, data=payload)
|
||||
data = response.json()
|
||||
# print(data)
|
||||
print(data['issues'])
|
||||
for issue in data['issues']:
|
||||
url = f"https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues/{issue['id']}.json"
|
||||
|
||||
payload = {}
|
||||
|
||||
access_token = 'HXn433Vth2ksJmpv3yVqaE7qgK1yJbDFwc_xnITcM-o'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}',
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
|
||||
}
|
||||
|
||||
response1 = requests.request("GET", url, headers=headers, data=payload)
|
||||
data1 = response1.json()
|
||||
# print(response.text)
|
||||
# print(data)
|
||||
print(issue['id'])
|
||||
print(issue['subject'])
|
||||
print(data1['description'])
|
||||
print(issue['status_name'])
|
||||
|
||||
cursor.execute(
|
||||
'INSERT INTO gitlink_issue_list (number, subject, description, status_name) VALUES (%s, %s, %s, %s)',
|
||||
(issue['id'], issue['subject'], data1['description'], issue['status_name']))
|
||||
# 执行查询
|
||||
cursor.execute('SELECT number FROM gitlink_issue_list')
|
||||
# 获取所有结果
|
||||
results = cursor.fetchall()
|
||||
# 提取列数据到列表中
|
||||
column_data = [row[0] for row in results]
|
||||
|
||||
##################删除gitlink仓库中的所有的issue###########################
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues/batch_destroy.json"
|
||||
|
||||
payload = json.dumps({
|
||||
"ids": column_data
|
||||
})
|
||||
access_token = 'HXn433Vth2ksJmpv3yVqaE7qgK1yJbDFwc_xnITcM-o'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
response = requests.request("DELETE", url, headers=headers, data=payload)
|
||||
|
||||
print(response.text)
|
||||
|
||||
##################将gitee中的issue创建到gitlink中###########################
|
||||
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues.json"
|
||||
|
||||
# 替换为您的实际访问令牌
|
||||
access_token = 'HXn433Vth2ksJmpv3yVqaE7qgK1yJbDFwc_xnITcM-o'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
# 执行查询
|
||||
cursor.execute('SELECT title,body FROM github_issue_list')
|
||||
# 获取所有结果
|
||||
result = cursor.fetchall()
|
||||
|
||||
for row in result:
|
||||
payload = json.dumps({
|
||||
|
||||
"status_id": 1, # status对应 1对应新增 2对应正在解决 3对应已解决
|
||||
"priority_id": 2, # priority对应 1对应低 2对应正常 3对应高优先级
|
||||
"subject": row[0],
|
||||
"description": row[1],
|
||||
})
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
print(response.text)
|
||||
|
||||
# 提交事务
|
||||
conn.commit()
|
||||
# 关闭游标和连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
@ -0,0 +1,281 @@
|
|||
import urllib
|
||||
import requests
|
||||
import mysql.connector
|
||||
import json
|
||||
|
||||
def main():
|
||||
########获取gitee里的issue并且放到数据库中#######################
|
||||
# 连接到MySQL数据库
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="185102xmy",
|
||||
database="db1"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('DROP TABLE IF EXISTS gitee_issue_list')
|
||||
# 创建一个表
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS gitee_issue_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), title VARCHAR(100), body VARCHAR(1000), state VARCHAR(15), priority INT)''')
|
||||
# 你的仓库信息
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
|
||||
# Gitee获取issue的API URL
|
||||
url = f"https://gitee.com/api/v5/repos/{owner}/{repo}/issues"
|
||||
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
# 发送POST请求 获取状态为open的issue
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"sort": 'created',
|
||||
"direction": 'asc'
|
||||
}
|
||||
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url1 = f"{url}?{query_string}"
|
||||
|
||||
response = requests.get(full_url1, headers=headers, json=data)
|
||||
# 打印响应
|
||||
# print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 200:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
for issue in issue_info:
|
||||
print('number1:', issue['number'])
|
||||
print('state1:', issue['state'])
|
||||
print('title1:', issue['title'])
|
||||
print('body1:', issue['body'])
|
||||
cursor.execute(
|
||||
'INSERT INTO gitee_issue_list (number, title, body, state, priority) VALUES (%s, %s, %s, %s, %s)',
|
||||
(issue['number'], issue['title'], issue['body'], issue['state'], issue['priority']))
|
||||
|
||||
else:
|
||||
print(f"创建issue失败12,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
########获取gitlink里的issue并且放到数据库中#######################
|
||||
# 连接到MySQL数据库
|
||||
cursor.execute('DROP TABLE IF EXISTS gitlink_issue_list')
|
||||
# 创建一个表
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS gitlink_issue_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, project_issues_index VARCHAR(10), number VARCHAR(10), subject VARCHAR(100), description VARCHAR(1000), status_name VARCHAR(15), priority_name VARCHAR(15))''')
|
||||
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues.json?category&participant_category&keyword&author_id&milestone_id&assigner_id&status_id&sort_by&sort_direction&issue_tag_ids&page&limit&debug=admin"
|
||||
|
||||
payload = {}
|
||||
headers = {
|
||||
'Authorization': 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg',
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers, data=payload)
|
||||
data = response.json()
|
||||
# print(data)
|
||||
print(data['issues'])
|
||||
for issue in data['issues']:
|
||||
url = f"https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues/{issue['id']}.json"
|
||||
|
||||
payload = {}
|
||||
|
||||
access_token = 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}',
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers, data=payload)
|
||||
data = response.json()
|
||||
# print(response.text)
|
||||
# print(data)
|
||||
print(issue['id'])
|
||||
print(issue['subject'])
|
||||
print(data['description'])
|
||||
print(issue['status_name'])
|
||||
|
||||
cursor.execute(
|
||||
'INSERT INTO gitlink_issue_list (project_issues_index, number, subject, description, status_name, priority_name) VALUES (%s, %s, %s, %s, %s, %s)',
|
||||
(issue['project_issues_index'], issue['id'], issue['subject'], data['description'], issue['status_name'], issue['priority_name']))
|
||||
|
||||
##################将gitee仓库中的issue状态更新为关闭closed###########################
|
||||
cursor.execute('SELECT number FROM gitee_issue_list')
|
||||
gitee_results = cursor.fetchall()
|
||||
for row in gitee_results:
|
||||
issue_number = row[0]
|
||||
url = f'https://gitee.com/api/v5/repos/{owner}/issues/{issue_number}'
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"number": issue_number,
|
||||
"state": 'closed',
|
||||
"labels": 'wait_for_delete'
|
||||
}
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url1 = f"{url}?{query_string}"
|
||||
response = requests.patch(full_url1, headers=headers, json=data)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 200:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(f'Issue created with ID: {issue_info["number"]}')
|
||||
else:
|
||||
print(f"更新issue状态失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
##################将gitlink中的issue创建到gitee中###########################
|
||||
|
||||
cursor.execute('DROP TABLE IF EXISTS gitee_issue_list')
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS gitee_issue_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), title VARCHAR(100), body VARCHAR(1000), state VARCHAR(15), priority INT)''')
|
||||
|
||||
cursor.execute('SELECT subject, description, status_name, priority_name, project_issues_index FROM gitlink_issue_list')
|
||||
|
||||
gitlink_result = cursor.fetchall()
|
||||
|
||||
for row in gitlink_result:
|
||||
# Gitee创建issue的API URL
|
||||
url = f"https://gitee.com/api/v5/repos/{owner}/issues"
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"title": row[0],
|
||||
"body": row[1]
|
||||
}
|
||||
response = requests.post(url, headers=headers, json=data)
|
||||
issue_info = response.json()
|
||||
if row[2] == '新增':
|
||||
state = 'open'
|
||||
if row[2] == '正在解决':
|
||||
state = 'progressing'
|
||||
if row[2] == '已解决':
|
||||
state = 'closed'
|
||||
cursor.execute(
|
||||
'INSERT INTO gitee_issue_list (number, title, body, state) VALUES (%s, %s, %s, %s)',
|
||||
(issue_info['number'], row[0], row[1], state))
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 201:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(f'Issue created with ID: {issue_info["number"]}')
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
#获取gitlink里面的issue的comment
|
||||
url = f"https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues/{row[4]}/journals.json"
|
||||
payload = {}
|
||||
access_token = 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
response = requests.request("GET", url, headers=headers, data=payload)
|
||||
info = json.loads(response.text)
|
||||
print(json.loads(response.text))
|
||||
for gitlink_comment_info in info['journals']:
|
||||
if 'notes' in gitlink_comment_info:
|
||||
#这里执行对gitee上的评论的添加
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
# Gitee创建issue的API URL
|
||||
url = f"https://gitee.com/api/v5/repos/{owner}/{repo}/issues/{issue_info['number']}/comments"
|
||||
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"body": gitlink_comment_info['notes']
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, json=data)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 201:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
comment_info = response.json()
|
||||
print(comment_info)
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
# 提交事务
|
||||
###########################更改已经创建好的issue的状态和优先级###############################
|
||||
|
||||
cursor.execute('SELECT number, title, body, state, priority FROM gitee_issue_list')
|
||||
# Gitee更新issue的API URL
|
||||
gitee_update_result = cursor.fetchall()
|
||||
for row in gitee_update_result:
|
||||
issue_number = row[0]
|
||||
state = row[3]
|
||||
url = f'https://gitee.com/api/v5/repos/{owner}/issues/{issue_number}'
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"number": issue_number,
|
||||
"state": state
|
||||
}
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url1 = f"{url}?{query_string}"
|
||||
response = requests.patch(full_url1, headers=headers, json=data)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 200:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(f'Issue created with ID: {issue_info["number"]}')
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
conn.commit()
|
||||
# 关闭游标和连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
@ -0,0 +1,178 @@
|
|||
import urllib
|
||||
import requests
|
||||
import mysql.connector
|
||||
import json
|
||||
|
||||
def main():
|
||||
########获取gitee里的issue并且放到数据库中#######################
|
||||
# 连接到MySQL数据库
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="185102xmy",
|
||||
database="db1"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('DROP TABLE IF EXISTS github_issue_list')
|
||||
# 创建一个表
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS github_issue_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), title VARCHAR(100), body VARCHAR(1000), state VARCHAR(15))''')
|
||||
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/issues"
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
|
||||
}
|
||||
response = requests.get(url, headers=headers, json=data, verify=False)
|
||||
issue_info = response.json()
|
||||
for issue in issue_info:
|
||||
print('title:', issue['title'])
|
||||
print('body:', issue['body'])
|
||||
print('number', issue['number'])
|
||||
print('id', issue['id'])
|
||||
cursor.execute(
|
||||
'INSERT INTO github_issue_list (number, title, body, state) VALUES (%s, %s, %s, %s)',
|
||||
(issue['number'], issue['title'], issue['body'], issue['state']))
|
||||
|
||||
########获取gitlink里的issue并且放到数据库中#######################
|
||||
# 连接到MySQL数据库
|
||||
cursor.execute('DROP TABLE IF EXISTS gitlink_issue_list')
|
||||
# 创建一个表
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS gitlink_issue_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), subject VARCHAR(100), description VARCHAR(1000), status_name VARCHAR(15), priority_name VARCHAR(15))''')
|
||||
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues.json?category&participant_category&keyword&author_id&milestone_id&assigner_id&status_id&sort_by&sort_direction&issue_tag_ids&page&limit&debug=admin"
|
||||
|
||||
payload = {}
|
||||
headers = {
|
||||
'Authorization': 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg',
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers, data=payload)
|
||||
data = response.json()
|
||||
# print(data)
|
||||
print(data['issues'])
|
||||
for issue in data['issues']:
|
||||
url = f"https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues/{issue['id']}.json"
|
||||
|
||||
payload = {}
|
||||
|
||||
access_token = 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}',
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
|
||||
}
|
||||
|
||||
response1 = requests.request("GET", url, headers=headers, data=payload)
|
||||
data1 = response1.json()
|
||||
# print(response.text)
|
||||
# print(data)
|
||||
print(issue['id'])
|
||||
print(issue['subject'])
|
||||
print(data1['description'])
|
||||
print(issue['status_name'])
|
||||
|
||||
cursor.execute(
|
||||
'INSERT INTO gitlink_issue_list (number, subject, description, status_name, priority_name) VALUES (%s, %s, %s, %s, %s)',
|
||||
(issue['id'], issue['subject'], data1['description'], issue['status_name'], issue['priority_name']))
|
||||
# # 执行查询
|
||||
# cursor.execute('SELECT number FROM gitlink_issue_list')
|
||||
# # 获取所有结果
|
||||
# results = cursor.fetchall()
|
||||
# # 提取列数据到列表中
|
||||
# column_data = [row[0] for row in results]
|
||||
|
||||
##################将gitee仓库中的issue状态更新为关闭closed###########################
|
||||
cursor.execute('SELECT number FROM github_issue_list')
|
||||
gitee_results = cursor.fetchall()
|
||||
for row in gitee_results:
|
||||
issue_number = row[0]
|
||||
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/issues/{issue_number}"
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
# 发送POST请求
|
||||
data = {
|
||||
'owner': 'fuxingtamu',
|
||||
'repo': 'yundingzhiyi',
|
||||
'issue_number': issue_number,
|
||||
'state': 'closed'
|
||||
}
|
||||
response = requests.patch(url, headers=headers, json=data, verify=False)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 201:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上GitHub可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(f'Issue created with ID: {issue_info["number"]}')
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
##################将gitlink中的issue创建到github中###########################
|
||||
|
||||
cursor.execute('DROP TABLE IF EXISTS github_issue_list')
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS github_issue_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), title VARCHAR(100), body VARCHAR(1000), state VARCHAR(15))''')
|
||||
|
||||
cursor.execute('SELECT subject, description, status_name, priority_name FROM gitlink_issue_list')
|
||||
|
||||
gitlink_result = cursor.fetchall()
|
||||
|
||||
for row in gitlink_result:
|
||||
|
||||
# GitHub创建issue的API URL
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/issues"
|
||||
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"title": row[0],
|
||||
"body": row[1]
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, json=data, verify=False)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 201:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上GitHub可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(f'Issue created with ID: {issue_info["number"]}')
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
# 提交事务
|
||||
|
||||
###########################更改已经创建好的issue的状态和优先级###############################
|
||||
|
||||
conn.commit()
|
||||
# 关闭游标和连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
import requests
|
||||
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues/117187.json"
|
||||
|
||||
payload={}
|
||||
|
||||
access_token = 'XtR67a232J5u1VU_8yvm7RCVfMX0XMM76m8yMAGblDY'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}',
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers, data=payload)
|
||||
data=response.json()
|
||||
# print(response.text)
|
||||
print(data)
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
import urllib
|
||||
|
||||
import requests
|
||||
import mysql.connector
|
||||
# 连接到MySQL数据库
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="185102xmy",
|
||||
database="db1"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('SELECT number,title,body,state,priority FROM gitee_issue_list')
|
||||
result = cursor.fetchall()
|
||||
for row in result:
|
||||
issue_number = row[0]
|
||||
# 你的Gitee用户名(或用于认证的token)
|
||||
# 注意:出于安全考虑,通常不建议在代码中硬编码密码,而是使用token
|
||||
# 你的仓库信息
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
|
||||
# Gitee创建issue的API URL
|
||||
url = f'https://gitee.com/api/v5/repos/{owner}/issues/{issue_number}'
|
||||
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"number": issue_number,
|
||||
"state": 'closed',
|
||||
"labels": 'wait_for_delete'
|
||||
}
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url1 = f"{url}?{query_string}"
|
||||
response = requests.patch(full_url1, headers=headers, json=data)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 200:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(f'Issue created with ID: {issue_info["number"]}')
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
import requests
|
||||
import json
|
||||
|
||||
# 你的GitHub用户名(或用于认证的token)
|
||||
# 注意:出于安全考虑,通常不建议在代码中硬编码密码,而是使用token
|
||||
|
||||
# 你的仓库信息
|
||||
owner = 'fuxingtamu'
|
||||
repo = 'yundingzhiyi'
|
||||
|
||||
|
||||
|
||||
# GitHub创建issue的API URL
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/issues/255"
|
||||
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"state":'open'
|
||||
}
|
||||
|
||||
response = requests.patch(url, headers=headers, json=data,verify=False)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
import requests
|
||||
import json
|
||||
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/issues/14.json"
|
||||
|
||||
payload = json.dumps({
|
||||
"status_id": "5",
|
||||
# "priority_id": 0,
|
||||
# "milestone_id": 0,
|
||||
})
|
||||
access_token = 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
|
||||
}
|
||||
|
||||
response = requests.request("PATCH", url, headers=headers, data=payload)
|
||||
|
||||
print(response.text)
|
||||
2
main.py
2
main.py
|
|
@ -25,7 +25,7 @@ app.include_router(LOG)
|
|||
app.include_router(AUTH)
|
||||
app.include_router(SYNC_CONFIG)
|
||||
|
||||
app.mount("/", StaticFiles(directory="web/dist"), name="static")
|
||||
app.mount("/", StaticFiles(directory="web"), name="static")
|
||||
|
||||
if __name__ == '__main__':
|
||||
# workers 参数仅在命令行使用uvicorn启动时有效 或使用环境变量 WEB_CONCURRENCY
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
import requests
|
||||
|
||||
# 你的Gitee用户名(或用于认证的token)
|
||||
# 注意:出于安全考虑,通常不建议在代码中硬编码密码,而是使用token
|
||||
|
||||
# 你的仓库信息
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
|
||||
# 创建issue的标题和内容
|
||||
milestone_title = 'milestone的标题0'
|
||||
milestone_description = '这是一个milestone的详细描述'
|
||||
due_on = '2024-10-28'
|
||||
# Gitee创建issue的API URL
|
||||
url = f"https://gitee.com/api/v5/repos/{owner}/{repo}/milestones"
|
||||
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"access_token":token,
|
||||
"owner":owner,
|
||||
"repo":repo,
|
||||
"title":milestone_title,
|
||||
"description":milestone_description,
|
||||
"due_on":due_on
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, json=data)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 201:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
import requests
|
||||
|
||||
# 你的仓库信息
|
||||
owner = 'fuxingtamu'
|
||||
repo = 'yundingzhiyi'
|
||||
|
||||
|
||||
milestone_title = '测试milestone2'
|
||||
due_on = '2024-11-30T00:00:00Z'
|
||||
milestone_description = '这是milestone的具体描述'
|
||||
|
||||
# GitHub创建issue的API URL
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/milestones"
|
||||
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
'title': milestone_title,
|
||||
'description' : milestone_description,
|
||||
'due_on' : due_on
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, json=data,verify=False)
|
||||
milestone_info = response.json()
|
||||
# 打印响应
|
||||
print(milestone_info)
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
import requests
|
||||
import json
|
||||
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/milestones.json"
|
||||
milestone_name = '这是一个gitlink的milestone_name1'
|
||||
milestone_description = '这是一个gitlink的milestone_description1'
|
||||
milestone_effect_date = '2024-10-30'
|
||||
|
||||
payload = json.dumps({
|
||||
"name": milestone_name,
|
||||
"description": milestone_description,
|
||||
"effective_date": milestone_effect_date
|
||||
})
|
||||
access_token = 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
|
||||
print(response.text)
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
import urllib
|
||||
|
||||
import requests
|
||||
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5' # 假设这是您的有效token
|
||||
# 你的仓库信息
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
number = '206035'
|
||||
# Gitee删除issue的API URL
|
||||
url = f'https://gitee.com/api/v5/repos/{owner}/{repo}/milestones/{number}'
|
||||
|
||||
# 构造请求头
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
data = {
|
||||
"access_token":token,
|
||||
"owner":owner,
|
||||
"repo":repo,
|
||||
"number": number
|
||||
}
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url1 = f"{url}?{query_string}"
|
||||
|
||||
response = requests.delete(full_url1, headers=headers, json=data)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 204:
|
||||
print('Issue已成功删除。')
|
||||
else:
|
||||
print(f"删除issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
import requests
|
||||
import json
|
||||
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/milestones/2691.json"
|
||||
|
||||
payload = json.dumps({
|
||||
"name": "string",
|
||||
"description": "string",
|
||||
"effective_date": "string"
|
||||
})
|
||||
access_token = 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
response = requests.request("DELETE", url, headers=headers, data=payload)
|
||||
|
||||
print(response.text)
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
import urllib
|
||||
import requests
|
||||
import mysql.connector
|
||||
|
||||
# # 连接到MySQL数据库
|
||||
# conn = mysql.connector.connect(
|
||||
# host="localhost",
|
||||
# user="root",
|
||||
# password="185102xmy",
|
||||
# database="db1"
|
||||
# )
|
||||
# cursor = conn.cursor()
|
||||
# cursor.execute('DROP TABLE IF EXISTS gitee_comments_list')
|
||||
# # 创建一个表
|
||||
# cursor.execute('''CREATE TABLE IF NOT EXISTS gitee_comments_list
|
||||
# (id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), title VARCHAR(100), body VARCHAR(1000), state VARCHAR(15), priority INT)''')
|
||||
# 你的仓库信息
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
|
||||
# Gitee获取issue的API URL
|
||||
url = f"https://gitee.com/api/v5/repos/{owner}/{repo}/milestones"
|
||||
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
# 发送POST请求 获取状态为open的issue
|
||||
data = {
|
||||
"access_token":token,
|
||||
"owner":owner,
|
||||
"repo":repo,
|
||||
#"state":'all',
|
||||
}
|
||||
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url1 = f"{url}?{query_string}"
|
||||
|
||||
response = requests.get(full_url1, headers=headers, json=data)
|
||||
# 打印响应
|
||||
# print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 200:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(issue_info)
|
||||
else:
|
||||
print(f"创建issue失败12,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
# # 提交事务
|
||||
# conn.commit()
|
||||
# # 关闭游标和连接
|
||||
# cursor.close()
|
||||
# conn.close()
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
import requests
|
||||
|
||||
# GitHub创建issue的API URL
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/milestones"
|
||||
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
}
|
||||
|
||||
response = requests.get(url, headers=headers, json=data,verify=False)
|
||||
# 打印响应
|
||||
#print(response.text)
|
||||
milestones_info = response.json()
|
||||
print(milestones_info)
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
import requests
|
||||
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/milestones.json"
|
||||
|
||||
payload={}
|
||||
access_token = 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
response = requests.request("GET", url, headers=headers, data=payload)
|
||||
|
||||
print(response.text)
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
import urllib
|
||||
import requests
|
||||
import mysql.connector
|
||||
import json
|
||||
|
||||
def main():
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="185102xmy",
|
||||
database="db1"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('DROP TABLE IF EXISTS gitee_milestone_list')
|
||||
# 创建一个表
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS gitee_milestone_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), title VARCHAR(100), description VARCHAR(100), due_on VARCHAR(15))''')
|
||||
# 你的仓库信息
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
url = f"https://gitee.com/api/v5/repos/{owner}/{repo}/milestones"
|
||||
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
# 发送POST请求 获取状态为open的issue
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
# "state":'all',
|
||||
}
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url1 = f"{url}?{query_string}"
|
||||
response = requests.get(full_url1, headers=headers, json=data)
|
||||
if response.status_code == 200:
|
||||
milestone_info = response.json()
|
||||
print(milestone_info)
|
||||
for single_milestone in milestone_info:
|
||||
cursor.execute(
|
||||
'INSERT INTO gitee_milestone_list (number, title, description, due_on) VALUES (%s, %s, %s, %s)',
|
||||
(single_milestone['number'], single_milestone['title'], single_milestone['description'], single_milestone['due_on']))
|
||||
else:
|
||||
print(f"创建issue失败12,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
# 提交事务
|
||||
conn.commit()
|
||||
# 关闭游标和连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
#获取gitlink中的milestone
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="185102xmy",
|
||||
database="db1"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('DROP TABLE IF EXISTS gitlink_milestone_list')
|
||||
# 创建一个表
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS gitlink_milestone_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, milestone_index VARCHAR(100), name VARCHAR(100), description VARCHAR(100), due_on VARCHAR(100))''')
|
||||
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/milestones.json"
|
||||
|
||||
payload = {}
|
||||
access_token = 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
response = requests.request("GET", url, headers=headers, data=payload)
|
||||
print(response.text)
|
||||
gitlink_milestone = response.json()['milestones']
|
||||
for gitlink_single_milestone in gitlink_milestone:
|
||||
cursor.execute(
|
||||
'INSERT INTO gitlink_milestone_list (milestone_index, name, description, due_on) VALUES (%s, %s, %s, %s)',
|
||||
(gitlink_single_milestone['id'], gitlink_single_milestone['name'], gitlink_single_milestone['description'],
|
||||
gitlink_single_milestone['effective_date']))
|
||||
#删除gitlink中的milestone
|
||||
url = f"https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/milestones/{gitlink_single_milestone['id']}.json"
|
||||
|
||||
payload = json.dumps({
|
||||
"name": "string",
|
||||
"description": "string",
|
||||
"effective_date": "string"
|
||||
})
|
||||
access_token = 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
response = requests.request("DELETE", url, headers=headers, data=payload)
|
||||
print(response.text)
|
||||
#重新创建gitlink上的milestone
|
||||
cursor.execute('SELECT title, description, due_on FROM gitee_milestone_list')
|
||||
milestone_result = cursor.fetchall()
|
||||
for row in milestone_result:
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/milestones.json"
|
||||
milestone_name = row[0]
|
||||
milestone_description = row[1]
|
||||
milestone_effect_date = row[2]
|
||||
|
||||
payload = json.dumps({
|
||||
"name": milestone_name,
|
||||
"description": milestone_description,
|
||||
"effective_date": milestone_effect_date
|
||||
})
|
||||
access_token = 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
print(response.text)
|
||||
# 提交事务
|
||||
conn.commit()
|
||||
# 关闭游标和连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,153 @@
|
|||
import urllib
|
||||
import requests
|
||||
import mysql.connector
|
||||
import json
|
||||
|
||||
def main():
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="185102xmy",
|
||||
database="db1"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('DROP TABLE IF EXISTS github_milestone_list')
|
||||
# 创建一个表
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS github_milestone_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, milestone_index VARCHAR(100), title VARCHAR(100), description VARCHAR(100), due_on VARCHAR(100))''')
|
||||
|
||||
#获取gitlink中的所有milestone
|
||||
|
||||
# GitHub创建issue的API URL
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/milestones"
|
||||
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
}
|
||||
|
||||
response = requests.get(url, headers=headers, json=data, verify=False)
|
||||
# 打印响应
|
||||
# print(response.text)
|
||||
milestones_info = response.json()
|
||||
for github_single_milestone in milestones_info:
|
||||
cursor.execute(
|
||||
'INSERT INTO github_milestone_list (milestone_index, title, description, due_on) VALUES (%s, %s, %s, %s)',
|
||||
(github_single_milestone['id'], github_single_milestone['title'], github_single_milestone['description'],
|
||||
github_single_milestone['due_on']))
|
||||
|
||||
#删除掉gitee的milestone
|
||||
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
# Gitee获取issue的API URL
|
||||
url = f"https://gitee.com/api/v5/repos/{owner}/{repo}/milestones"
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
# 发送POST请求 获取状态为open的issue
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
# "state":'all',
|
||||
}
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url1 = f"{url}?{query_string}"
|
||||
|
||||
response = requests.get(full_url1, headers=headers, json=data)
|
||||
# 打印响应
|
||||
# print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 200:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
milestone_info = response.json()
|
||||
print(milestone_info)
|
||||
else:
|
||||
print(f"创建issue失败12,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
for single_milestone in milestone_info:
|
||||
#删除gitee上面的milestone
|
||||
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5' # 假设这是您的有效token
|
||||
# 你的仓库信息
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
number = '206035'
|
||||
# Gitee删除issue的API URL
|
||||
url = f'https://gitee.com/api/v5/repos/{owner}/{repo}/milestones/{single_milestone["number"]}'
|
||||
# 构造请求头
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"number": number
|
||||
}
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url1 = f"{url}?{query_string}"
|
||||
|
||||
response = requests.delete(full_url1, headers=headers, json=data)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 204:
|
||||
print('milestone已成功删除。')
|
||||
else:
|
||||
print(f"删除issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
#创建新的giteemilestone
|
||||
cursor.execute('SELECT title, description, due_on FROM github_milestone_list')
|
||||
milestone_result = cursor.fetchall()
|
||||
for row in milestone_result:
|
||||
url = f"https://gitee.com/api/v5/repos/{owner}/{repo}/milestones"
|
||||
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
date_only = row[2].split('T')[0]
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"title": row[0],
|
||||
"description": row[1],
|
||||
"due_on": date_only
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, json=data)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 201:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
else:
|
||||
print(f"创建milestone失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
# 提交事务
|
||||
conn.commit()
|
||||
# 关闭游标和连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
@ -0,0 +1,144 @@
|
|||
import urllib
|
||||
import requests
|
||||
import mysql.connector
|
||||
import json
|
||||
|
||||
def main():
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="185102xmy",
|
||||
database="db1"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('DROP TABLE IF EXISTS gitlink_milestone_list')
|
||||
# 创建一个表
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS gitlink_milestone_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, milestone_index VARCHAR(100), name VARCHAR(100), description VARCHAR(100), due_on VARCHAR(100))''')
|
||||
|
||||
#获取gitlink中的所有milestone
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/milestones.json"
|
||||
|
||||
payload = {}
|
||||
access_token = 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
response = requests.request("GET", url, headers=headers, data=payload)
|
||||
print(response.text)
|
||||
gitlink_milestone = response.json()['milestones']
|
||||
for gitlink_single_milestone in gitlink_milestone:
|
||||
cursor.execute(
|
||||
'INSERT INTO gitlink_milestone_list (milestone_index, name, description, due_on) VALUES (%s, %s, %s, %s)',
|
||||
(gitlink_single_milestone['id'], gitlink_single_milestone['name'], gitlink_single_milestone['description'],
|
||||
gitlink_single_milestone['effective_date']))
|
||||
|
||||
#删除掉gitee的milestone
|
||||
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
# Gitee获取issue的API URL
|
||||
url = f"https://gitee.com/api/v5/repos/{owner}/{repo}/milestones"
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
# 发送POST请求 获取状态为open的issue
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
# "state":'all',
|
||||
}
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url1 = f"{url}?{query_string}"
|
||||
|
||||
response = requests.get(full_url1, headers=headers, json=data)
|
||||
# 打印响应
|
||||
# print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 200:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
milestone_info = response.json()
|
||||
print(milestone_info)
|
||||
else:
|
||||
print(f"创建issue失败12,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
for single_milestone in milestone_info:
|
||||
#删除gitee上面的milestone
|
||||
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5' # 假设这是您的有效token
|
||||
# 你的仓库信息
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
number = '206035'
|
||||
# Gitee删除issue的API URL
|
||||
url = f'https://gitee.com/api/v5/repos/{owner}/{repo}/milestones/{single_milestone["number"]}'
|
||||
# 构造请求头
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"number": number
|
||||
}
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url1 = f"{url}?{query_string}"
|
||||
|
||||
response = requests.delete(full_url1, headers=headers, json=data)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 204:
|
||||
print('milestone已成功删除。')
|
||||
else:
|
||||
print(f"删除issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
#创建新的giteemilestone
|
||||
cursor.execute('SELECT name, description, due_on FROM gitlink_milestone_list')
|
||||
milestone_result = cursor.fetchall()
|
||||
for row in milestone_result:
|
||||
url = f"https://gitee.com/api/v5/repos/{owner}/{repo}/milestones"
|
||||
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"title": row[0],
|
||||
"description": row[1],
|
||||
"due_on": row[2]
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, json=data)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 201:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
else:
|
||||
print(f"创建milestone失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
# 提交事务
|
||||
conn.commit()
|
||||
# 关闭游标和连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
import urllib
|
||||
import requests
|
||||
import mysql.connector
|
||||
|
||||
# 连接到MySQL数据库
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="185102xmy",
|
||||
database="db1"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
# cursor.execute('DROP TABLE IF EXISTS gitee_pr_list')
|
||||
# # 创建一个表
|
||||
# cursor.execute('''CREATE TABLE IF NOT EXISTS gitee_pr_list
|
||||
# (id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), state VARCHAR(15), title VARCHAR(100), body VARCHAR(1000), head VARCHAR(15), base VARCHAR(15))''')
|
||||
# 你的仓库信息
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
|
||||
# Gitee获取issue的API URL
|
||||
url = f'https://gitee.com/api/v5/repos/{owner}/{repo}/pulls'
|
||||
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
# 发送POST请求 获取状态为open的issue
|
||||
data = {
|
||||
"access_token":token,
|
||||
"owner":owner,
|
||||
"repo":repo,
|
||||
"title":'新增pr尝试123',
|
||||
"head":'xumingyang',
|
||||
"body":'jiuzaijintian',
|
||||
"base":'master'
|
||||
}
|
||||
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url = f"{url}?{query_string}"
|
||||
response = requests.post(full_url, headers=headers, json=data)
|
||||
# 打印响应
|
||||
# print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 201:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
pr_info = response.json()
|
||||
print(pr_info)
|
||||
# for pr in pr_info:
|
||||
# print('number:',pr['id'])
|
||||
# print('state:',pr['state'])
|
||||
# print('title:',pr['title'])
|
||||
# print('body:',pr['body'])
|
||||
# print('head:',pr['head']['label'])
|
||||
# print('base:',pr['base']['label'])
|
||||
# cursor.execute('INSERT INTO gitee_pr_list (number, state, title, body, head, base) VALUES (%s, %s, %s, %s, %s, %s)',
|
||||
# (pr['id'], pr['state'], pr['title'], pr['body'], pr['head']['label'], pr['base']['label']))
|
||||
|
||||
else:
|
||||
print(f"获取pr失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
# 提交事务
|
||||
conn.commit()
|
||||
# 关闭游标和连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
import requests
|
||||
|
||||
|
||||
# 你的GitHub用户名(或用于认证的token)
|
||||
# 注意:出于安全考虑,通常不建议在代码中硬编码密码,而是使用token
|
||||
|
||||
# 你的仓库信息
|
||||
owner = 'fuxingtamu'
|
||||
repo = 'yundingzhiyi'
|
||||
|
||||
# 创建issue的标题和内容
|
||||
pr_title = '这是一个issue标题准备删除25'
|
||||
pr_body = '这是一个issue的详细描述'
|
||||
|
||||
|
||||
# GitHub创建issue的API URL
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/pulls"
|
||||
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"head":'xumingyang',
|
||||
"base":'master',
|
||||
"title": pr_title,
|
||||
"body": pr_body
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, json=data,verify=False)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 201:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上GitHub可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(f'Issue created with ID: {issue_info["number"]}')
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
import requests
|
||||
import json
|
||||
|
||||
url = "https://gitlink.org.cn/api/xumingyang21/reposyncer2/pulls.json"
|
||||
|
||||
payload = json.dumps({
|
||||
"title": "同步之后",
|
||||
"priority_id": "2",
|
||||
"body": "312",
|
||||
"head": "xumingyang",
|
||||
"base": "master",
|
||||
"is_original": False,
|
||||
"fork_project_id": "",
|
||||
"files_count": 1,
|
||||
"commits_count": 1,
|
||||
"reviewer_ids": [],
|
||||
"receivers_login": []
|
||||
})
|
||||
|
||||
access_token = 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
data = response.json()
|
||||
print(data)
|
||||
print(response.text)
|
||||
|
||||
###起始的时候是两个仓库完全相同的状态
|
||||
###然后当前仓库在一个分支上创建了pr
|
||||
###想要把这个pr同步过去 但其实每一个分支只能创建一个pr
|
||||
|
||||
#####PR同步应当是先将目标仓库的pr全部合并或者关闭
|
||||
##然后获取当前仓库的pr
|
||||
##应当先进行分支同步
|
||||
##然后再创建新的pr
|
||||
####创建新的pr时 如果是merge的就应当先创建再合并#####发现没有必要已经合并的pr没有重要性
|
||||
####新的pr就直接创建
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
import urllib
|
||||
import requests
|
||||
import mysql.connector
|
||||
|
||||
# 连接到MySQL数据库
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="185102xmy",
|
||||
database="db1"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('DROP TABLE IF EXISTS gitee_pr_list')
|
||||
# 创建一个表
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS gitee_pr_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), index2 VARCHAR(10), state VARCHAR(15), title VARCHAR(100), body VARCHAR(1000), head VARCHAR(100), base VARCHAR(15))''')
|
||||
# 你的仓库信息
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
|
||||
# Gitee获取issue的API URL
|
||||
url=f'https://gitee.com/api/v5/repos/{owner}/{repo}/pulls'
|
||||
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
# 发送POST请求 获取状态为open的issue
|
||||
data = {
|
||||
"access_token":token,
|
||||
"owner":owner,
|
||||
"repo":repo,
|
||||
"state":'all',
|
||||
}
|
||||
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url = f"{url}?{query_string}"
|
||||
|
||||
response = requests.get(full_url, headers=headers, json=data)
|
||||
# 打印响应
|
||||
# print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 200:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
pr_info = response.json()
|
||||
# print(pr_info)
|
||||
for pr in pr_info:
|
||||
print('id:',pr['id'])
|
||||
print('state:',pr['state'])
|
||||
print('title:',pr['title'])
|
||||
print('body:',pr['body'])
|
||||
print('head:',pr['head']['label'])
|
||||
print('base:',pr['base']['label'])
|
||||
cursor.execute('INSERT INTO gitee_pr_list (number, index2, state, title, body, head, base) VALUES (%s, %s, %s, %s, %s, %s, %s)',
|
||||
(pr['number'], pr['id'], pr['state'], pr['title'], pr['body'], pr['head']['label'], pr['base']['label']))
|
||||
|
||||
else:
|
||||
print(f"获取pr失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
# 提交事务
|
||||
conn.commit()
|
||||
# 关闭游标和连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
import requests
|
||||
|
||||
|
||||
# 你的GitHub用户名(或用于认证的token)
|
||||
# 注意:出于安全考虑,通常不建议在代码中硬编码密码,而是使用token
|
||||
|
||||
# 你的仓库信息
|
||||
|
||||
|
||||
|
||||
# GitHub创建issue的API URL
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/pulls"
|
||||
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
|
||||
}
|
||||
|
||||
response = requests.get(url, headers=headers, json=data,verify=False)
|
||||
# 打印响应
|
||||
#print(response.text)
|
||||
pr_info = response.json()
|
||||
for pr in pr_info:
|
||||
print(pr['title'])
|
||||
print(pr['state'])
|
||||
print(pr['body'])
|
||||
print(pr['number'])
|
||||
print(pr['base']['ref'])
|
||||
print(pr['head']['ref'])
|
||||
|
||||
# 检查响应状态码
|
||||
if response.status_code == 200:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上GitHub可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(f'Issue created with ID: {issue_info["number"]}')
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
import requests
|
||||
import mysql.connector
|
||||
# 连接到MySQL数据库
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="185102xmy",
|
||||
database="db1"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('DROP TABLE IF EXISTS gitlink_pr_list')
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS gitlink_pr_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), state VARCHAR(15), title VARCHAR(100), body VARCHAR(1000), head VARCHAR(15), base VARCHAR(15))''')
|
||||
|
||||
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/pulls.json?keyword&status&priority_id&issue_tag_id&version_id&reviewer_id&assign_user_id&sort_by&sort_direction"
|
||||
|
||||
payload={}
|
||||
|
||||
access_token = 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers, data=payload)
|
||||
data = response.json()
|
||||
for pr_info in data['pulls']:
|
||||
print('id:', pr_info['id'])
|
||||
print('state:', pr_info['status'])
|
||||
print('title:', pr_info['title'])
|
||||
print('body:', pr_info['body'])
|
||||
print('head:', pr_info['head'])
|
||||
print('base:', pr_info['base'])
|
||||
cursor.execute(
|
||||
'INSERT INTO gitlink_pr_list (number, state, title, body, head, base) VALUES (%s, %s, %s, %s, %s, %s)',
|
||||
(pr_info['id'], pr_info['status'], pr_info['title'], pr_info['body'], pr_info['head'], pr_info['base']))
|
||||
print(response.text)
|
||||
|
||||
# 提交事务
|
||||
conn.commit()
|
||||
# 关闭游标和连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
import urllib
|
||||
import requests
|
||||
import mysql.connector
|
||||
|
||||
# 连接到MySQL数据库
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="185102xmy",
|
||||
database="db1"
|
||||
)
|
||||
# cursor = conn.cursor()
|
||||
# cursor.execute('DROP TABLE IF EXISTS gitee_pr_list')
|
||||
# # 创建一个表
|
||||
# cursor.execute('''CREATE TABLE IF NOT EXISTS gitee_pr_list
|
||||
# (id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), state VARCHAR(15), title VARCHAR(100), body VARCHAR(1000), head VARCHAR(15), base VARCHAR(15))''')
|
||||
# # 你的仓库信息
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
number = 1
|
||||
|
||||
# Gitee获取issue的API URL
|
||||
url = f'https://gitee.com/api/v5/repos/{owner}/{repo}/pulls/{number}'
|
||||
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
# 发送POST请求 获取状态为open的issue
|
||||
data = {
|
||||
"access_token":token,
|
||||
"owner":owner,
|
||||
"repo":repo,
|
||||
"number": number
|
||||
}
|
||||
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url = f"{url}?{query_string}"
|
||||
|
||||
response = requests.get(full_url, headers=headers, json=data)
|
||||
# 打印响应
|
||||
# print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 200:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
pr_info = response.json()
|
||||
print(pr_info)
|
||||
# for pr in pr_info:
|
||||
# print('number:',pr['id'])
|
||||
# print('state:',pr['state'])
|
||||
# print('title:',pr['title'])
|
||||
# print('body:',pr['body'])
|
||||
# print('head:',pr['head']['label'])
|
||||
# print('base:',pr['base']['label'])
|
||||
# cursor.execute('INSERT INTO gitee_pr_list (number, state, title, body, head, base) VALUES (%s, %s, %s, %s, %s, %s)',
|
||||
# (pr['id'], pr['state'], pr['title'], pr['body'], pr['head']['label'], pr['base']['label']))
|
||||
|
||||
else:
|
||||
print(f"获取pr失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
# # 提交事务
|
||||
# conn.commit()
|
||||
# # 关闭游标和连接
|
||||
# cursor.close()
|
||||
# conn.close()
|
||||
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
import requests
|
||||
index = 7616
|
||||
url = f"https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/pulls/{index}.json"
|
||||
|
||||
payload={}
|
||||
access_token = 'XtR67a232J5u1VU_8yvm7RCVfMX0XMM76m8yMAGblDY'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers, data=payload)
|
||||
|
||||
print(response.text)
|
||||
|
|
@ -0,0 +1,191 @@
|
|||
####################首先先将gitlink中的所有pr设置成merge的#############################
|
||||
import json
|
||||
import urllib
|
||||
import requests
|
||||
import mysql.connector
|
||||
# 连接到MySQL数据库
|
||||
def prework():
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="185102xmy",
|
||||
database="db1"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('DROP TABLE IF EXISTS github_pr_list')
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS github_pr_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), title VARCHAR(100), body VARCHAR(1000), head VARCHAR(100), base VARCHAR(15), state VARCHAR(10))''')
|
||||
|
||||
# GitHub创建issue的API URL
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/pulls"
|
||||
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
# 发送POST请求
|
||||
data = {
|
||||
|
||||
}
|
||||
response = requests.get(url, headers=headers, json=data, verify=False)
|
||||
# 打印响应
|
||||
# print(response.text)
|
||||
pr_info = response.json()
|
||||
for pr in pr_info:
|
||||
print(pr['title'])
|
||||
print(pr['state'])
|
||||
print(pr['body'])
|
||||
print(pr['number'])
|
||||
print(pr['base']['ref'])
|
||||
print(pr['head']['ref'])
|
||||
|
||||
if pr['state'] == 'open':
|
||||
# GitHub创建issue的API URL
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/pulls/{pr['number']}"
|
||||
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
'state': 'closed'
|
||||
}
|
||||
|
||||
response = requests.patch(url, headers=headers, json=data, verify=False)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 200:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上GitHub可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(f'Issue created with ID: {issue_info["number"]}')
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
|
||||
#######################获取gitee仓库上的pr信息##################################
|
||||
cursor.execute('DROP TABLE IF EXISTS gitee_pr_list')
|
||||
# 创建一个表
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS gitee_pr_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), index2 VARCHAR(10), state VARCHAR(15), title VARCHAR(100), body VARCHAR(1000), head VARCHAR(100), base VARCHAR(15))''')
|
||||
# 你的仓库信息
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
|
||||
# Gitee获取issue的API URL
|
||||
url = f'https://gitee.com/api/v5/repos/{owner}/{repo}/pulls'
|
||||
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
# 发送POST请求 获取状态为open的issue
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"state": 'all',
|
||||
}
|
||||
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url = f"{url}?{query_string}"
|
||||
|
||||
response = requests.get(full_url, headers=headers, json=data)
|
||||
# 打印响应
|
||||
# print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 200:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
pr_info = response.json()
|
||||
# print(pr_info)
|
||||
for pr in pr_info:
|
||||
print('id:', pr['id'])
|
||||
print('state:', pr['state'])
|
||||
print('title:', pr['title'])
|
||||
print('body:', pr['body'])
|
||||
print('head:', pr['head']['label'])
|
||||
print('base:', pr['base']['label'])
|
||||
cursor.execute(
|
||||
'INSERT INTO gitee_pr_list (number, index2, state, title, body, head, base) VALUES (%s, %s, %s, %s, %s, %s, %s)',
|
||||
(
|
||||
pr['number'], pr['id'], pr['state'], pr['title'], pr['body'], pr['head']['label'], pr['base']['label']))
|
||||
|
||||
else:
|
||||
print(f"获取pr失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
# 提交事务
|
||||
conn.commit()
|
||||
# 关闭游标和连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
|
||||
########################这一块应当先进行代码仓库的同步#################################################
|
||||
|
||||
#####################查找其中state为open的pr并将其创建到gitlink上面#####################################
|
||||
def pushwork():
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="185102xmy",
|
||||
database="db1"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('SELECT state, title, body, head, base FROM gitee_pr_list')
|
||||
pr_info = cursor.fetchall()
|
||||
for row in pr_info:
|
||||
pr_state = row[0]
|
||||
pr_title = row[1]
|
||||
pr_body = row[2]
|
||||
pr_head = row[3]
|
||||
pr_base = row[4]
|
||||
if pr_state == 'open':
|
||||
# GitHub创建issue的API URL
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/pulls"
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"head": pr_head,
|
||||
"base": pr_base,
|
||||
"title": pr_title,
|
||||
"body": pr_body
|
||||
}
|
||||
response = requests.post(url, headers=headers, json=data, verify=False)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 200:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上GitHub可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(f' Github PR created with ID: {issue_info["number"]}')
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
# 提交事务
|
||||
conn.commit()
|
||||
# 关闭游标和连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
prework()
|
||||
pushwork()
|
||||
|
|
@ -0,0 +1,166 @@
|
|||
####################首先先将gitlink中的所有pr设置成merge的#############################
|
||||
import json
|
||||
import urllib
|
||||
import requests
|
||||
import mysql.connector
|
||||
# 连接到MySQL数据库
|
||||
def prework():
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="185102xmy",
|
||||
database="db1"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('DROP TABLE IF EXISTS gitlink_pr_list')
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS gitlink_pr_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), state VARCHAR(15), title VARCHAR(100), body VARCHAR(1000), head VARCHAR(100), base VARCHAR(15))''')
|
||||
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/pulls.json?keyword&status&priority_id&issue_tag_id&version_id&reviewer_id&assign_user_id&sort_by&sort_direction"
|
||||
|
||||
payload = {}
|
||||
|
||||
access_token = 'HXn433Vth2ksJmpv3yVqaE7qgK1yJbDFwc_xnITcM-o'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers, data=payload)
|
||||
data = response.json()
|
||||
for pr_info in data['pulls']:
|
||||
print('id:', pr_info['id'])
|
||||
print('state:', pr_info['status'])
|
||||
print('title:', pr_info['title'])
|
||||
print('body:', pr_info['body'])
|
||||
print('head:', pr_info['head'])
|
||||
print('base:', pr_info['base'])
|
||||
cursor.execute(
|
||||
'INSERT INTO gitlink_pr_list (number, state, title, body, head, base) VALUES (%s, %s, %s, %s, %s, %s)',
|
||||
(pr_info['id'], pr_info['status'], pr_info['title'], pr_info['body'], pr_info['head'], pr_info['base']))
|
||||
if pr_info['status'] == 'open':
|
||||
index = pr_info['id']
|
||||
url_update = f"https://gitlink.org.cn/api/xumingyang21/reposyncer2/pulls/{index}/refuse_merge.json"
|
||||
payload = {}
|
||||
access_token = 'HXn433Vth2ksJmpv3yVqaE7qgK1yJbDFwc_xnITcM-o'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}',
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
|
||||
}
|
||||
response_update = requests.request("POST", url_update, headers=headers, data=payload)
|
||||
print(response_update.text)
|
||||
print(response.text)
|
||||
|
||||
#######################获取gitee仓库上的pr信息##################################
|
||||
cursor.execute('DROP TABLE IF EXISTS gitee_pr_list')
|
||||
# 创建一个表
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS gitee_pr_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), index2 VARCHAR(10), state VARCHAR(15), title VARCHAR(100), body VARCHAR(1000), head VARCHAR(100), base VARCHAR(15))''')
|
||||
# 你的仓库信息
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
|
||||
# Gitee获取issue的API URL
|
||||
url = f'https://gitee.com/api/v5/repos/{owner}/{repo}/pulls'
|
||||
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
# 发送POST请求 获取状态为open的issue
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"state": 'all',
|
||||
}
|
||||
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url = f"{url}?{query_string}"
|
||||
|
||||
response = requests.get(full_url, headers=headers, json=data)
|
||||
# 打印响应
|
||||
# print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 200:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
pr_info = response.json()
|
||||
# print(pr_info)
|
||||
for pr in pr_info:
|
||||
print('id:', pr['id'])
|
||||
print('state:', pr['state'])
|
||||
print('title:', pr['title'])
|
||||
print('body:', pr['body'])
|
||||
print('head:', pr['head']['label'])
|
||||
print('base:', pr['base']['label'])
|
||||
cursor.execute(
|
||||
'INSERT INTO gitee_pr_list (number, index2, state, title, body, head, base) VALUES (%s, %s, %s, %s, %s, %s, %s)',
|
||||
(
|
||||
pr['number'], pr['id'], pr['state'], pr['title'], pr['body'], pr['head']['label'], pr['base']['label']))
|
||||
|
||||
else:
|
||||
print(f"获取pr失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
# 提交事务
|
||||
conn.commit()
|
||||
# 关闭游标和连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
|
||||
########################这一块应当先进行代码仓库的同步#################################################
|
||||
|
||||
#####################查找其中state为open的pr并将其创建到gitlink上面#####################################
|
||||
def pushwork():
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="185102xmy",
|
||||
database="db1"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('SELECT state, title, body, head, base FROM gitee_pr_list')
|
||||
pr_info = cursor.fetchall()
|
||||
for row in pr_info:
|
||||
pr_state = row[0]
|
||||
pr_title = row[1]
|
||||
pr_body = row[2]
|
||||
pr_head = row[3]
|
||||
pr_base = row[4]
|
||||
if pr_state == 'open':
|
||||
url = "https://gitlink.org.cn/api/xumingyang21/reposyncer2/pulls.json"
|
||||
payload = json.dumps({
|
||||
"title": pr_title,
|
||||
"priority_id": "2",
|
||||
"body": pr_body,
|
||||
"head": pr_head,
|
||||
"base": pr_base,
|
||||
"is_original": False,
|
||||
"fork_project_id": "",
|
||||
"files_count": 1,
|
||||
"commits_count": 1,
|
||||
"reviewer_ids": [],
|
||||
"receivers_login": []
|
||||
})
|
||||
access_token = 'HXn433Vth2ksJmpv3yVqaE7qgK1yJbDFwc_xnITcM-o'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
data = response.json()
|
||||
print(data)
|
||||
print(response.text)
|
||||
# 提交事务
|
||||
conn.commit()
|
||||
# 关闭游标和连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
if __name__ == '__main__':
|
||||
prework()
|
||||
pushwork()
|
||||
|
|
@ -0,0 +1,217 @@
|
|||
import urllib
|
||||
import requests
|
||||
import mysql.connector
|
||||
|
||||
####################################先将gitee的pr状态更改为合并#####################################
|
||||
def prework():
|
||||
# 连接到MySQL数据库
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="185102xmy",
|
||||
database="db1"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('DROP TABLE IF EXISTS gitee_pr_list')
|
||||
# 创建一个表
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS gitee_pr_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), index2 VARCHAR(10), state VARCHAR(15), title VARCHAR(100), body VARCHAR(1000), head VARCHAR(100), base VARCHAR(15))''')
|
||||
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
|
||||
# Gitee获取issue的API URL
|
||||
url = f'https://gitee.com/api/v5/repos/{owner}/{repo}/pulls'
|
||||
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
# 发送POST请求 获取状态为open的issue
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"state": 'all',
|
||||
}
|
||||
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url = f"{url}?{query_string}"
|
||||
|
||||
response = requests.get(full_url, headers=headers, json=data)
|
||||
# 打印响应
|
||||
# print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 200:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
pr_info = response.json()
|
||||
# print(pr_info)
|
||||
for pr in pr_info:
|
||||
print('id:', pr['id'])
|
||||
print('state:', pr['state'])
|
||||
print('title:', pr['title'])
|
||||
print('body:', pr['body'])
|
||||
print('head:', pr['head']['label'])
|
||||
print('base:', pr['base']['label'])
|
||||
cursor.execute(
|
||||
'INSERT INTO gitee_pr_list (number, index2, state, title, body, head, base) VALUES (%s, %s, %s, %s, %s, %s, %s)',
|
||||
(pr['number'], pr['id'], pr['state'], pr['title'], pr['body'], pr['head']['label'],
|
||||
pr['base']['label']))
|
||||
|
||||
else:
|
||||
print(f"获取pr失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
cursor.execute('SELECT number, state FROM gitee_pr_list')
|
||||
|
||||
gitee_pr_info = cursor.fetchall()
|
||||
for row in gitee_pr_info:
|
||||
number = row[0]
|
||||
state = row[1]
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
if state == 'open':
|
||||
# Gitee获取issue的API URL
|
||||
url = f'https://gitee.com/api/v5/repos/{owner}/{repo}/pulls/{number}'
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
# 发送POST请求 获取状态为open的issue
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"state": 'closed'
|
||||
}
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url = f"{url}?{query_string}"
|
||||
response = requests.patch(full_url, headers=headers, json=data)
|
||||
|
||||
if response.status_code == 200:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
pr_info = response.json()
|
||||
print(pr_info)
|
||||
else:
|
||||
print(f"获取pr失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
#########################获取github中的信息#########################################
|
||||
|
||||
cursor.execute('DROP TABLE IF EXISTS github_pr_list')
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS github_pr_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), title VARCHAR(100), body VARCHAR(1000), head VARCHAR(100), base VARCHAR(15), state VARCHAR(10))''')
|
||||
|
||||
# GitHub创建issue的API URL
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/pulls"
|
||||
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
# 发送POST请求
|
||||
data = {
|
||||
}
|
||||
response = requests.get(url, headers=headers, json=data, verify=False)
|
||||
# 打印响应
|
||||
# print(response.text)
|
||||
pr_info = response.json()
|
||||
for pr in pr_info:
|
||||
print('title:', pr['title'])
|
||||
print('body:', pr['body'])
|
||||
print('head:', pr['head']['label'])
|
||||
print('base:', pr['base']['label'])
|
||||
cursor.execute(
|
||||
'INSERT INTO github_pr_list (number, title, body, head, base, state) VALUES (%s, %s, %s, %s, %s, %s)',
|
||||
(
|
||||
pr['number'], pr['title'], pr['body'], pr['head']['ref'], pr['base']['ref'], pr['state']))
|
||||
|
||||
# 检查响应状态码
|
||||
if response.status_code == 200:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上GitHub可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
for pr in issue_info:
|
||||
print(f'Issue created with ID: {pr["number"]}')
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
# 提交事务
|
||||
conn.commit()
|
||||
# 关闭游标和连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
|
||||
#################################这个地方执行仓库的同步########################################
|
||||
|
||||
|
||||
################################在gitee里面添加新的pr#######################################
|
||||
def push():
|
||||
# 连接到MySQL数据库
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="185102xmy",
|
||||
database="db1"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
cursor.execute('SELECT state, title, body, head, base FROM github_pr_list')
|
||||
github_pr_info = cursor.fetchall()
|
||||
for row in github_pr_info:
|
||||
github_state = row[0]
|
||||
github_title = row[1]
|
||||
github_body = row[2]
|
||||
github_head = row[3]
|
||||
github_base = row[4]
|
||||
if github_state == 'open':
|
||||
# Gitee创建pr的API URL
|
||||
url = f'https://gitee.com/api/v5/repos/{owner}/{repo}/pulls'
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
# 发送POST请求 获取状态为open的issue
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"title": github_title,
|
||||
"body": github_body,
|
||||
"head": github_head,
|
||||
"base": github_base
|
||||
}
|
||||
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url = f"{url}?{query_string}"
|
||||
response = requests.post(full_url, headers=headers, json=data)
|
||||
# 打印响应
|
||||
# print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 201:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
pr_info = response.json()
|
||||
print(pr_info)
|
||||
|
||||
else:
|
||||
print(f"获取pr失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
# 提交事务
|
||||
conn.commit()
|
||||
# 关闭游标和连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
prework()
|
||||
push()
|
||||
|
|
@ -0,0 +1,159 @@
|
|||
####################首先先将gitlink中的所有pr设置成merge的#############################
|
||||
import json
|
||||
import urllib
|
||||
import requests
|
||||
import mysql.connector
|
||||
# 连接到MySQL数据库
|
||||
def prework():
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="185102xmy",
|
||||
database="db1"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('DROP TABLE IF EXISTS gitlink_pr_list')
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS gitlink_pr_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), state VARCHAR(15), title VARCHAR(100), body VARCHAR(1000), head VARCHAR(100), base VARCHAR(15))''')
|
||||
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/pulls.json?keyword&status&priority_id&issue_tag_id&version_id&reviewer_id&assign_user_id&sort_by&sort_direction"
|
||||
|
||||
payload = {}
|
||||
|
||||
access_token = 'HXn433Vth2ksJmpv3yVqaE7qgK1yJbDFwc_xnITcM-o'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers, data=payload)
|
||||
data = response.json()
|
||||
for pr_info in data['pulls']:
|
||||
print('id:', pr_info['id'])
|
||||
print('state:', pr_info['status'])
|
||||
print('title:', pr_info['title'])
|
||||
print('body:', pr_info['body'])
|
||||
print('head:', pr_info['head'])
|
||||
print('base:', pr_info['base'])
|
||||
cursor.execute(
|
||||
'INSERT INTO gitlink_pr_list (number, state, title, body, head, base) VALUES (%s, %s, %s, %s, %s, %s)',
|
||||
(pr_info['id'], pr_info['status'], pr_info['title'], pr_info['body'], pr_info['head'], pr_info['base']))
|
||||
if pr_info['status'] == 'open':
|
||||
index = pr_info['id']
|
||||
url_update = f"https://gitlink.org.cn/api/xumingyang21/reposyncer2/pulls/{index}/refuse_merge.json"
|
||||
payload = {}
|
||||
access_token = '_LSPz_Q_g9h7j-Zo64hO2MDPMjDTS_o6rqD809mxWgQ'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}',
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
|
||||
}
|
||||
response_update = requests.request("POST", url_update, headers=headers, data=payload)
|
||||
print(response_update.text)
|
||||
print(response.text)
|
||||
|
||||
#######################获取gitee仓库上的pr信息##################################
|
||||
cursor.execute('DROP TABLE IF EXISTS github_pr_list')
|
||||
# 创建一个表
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS github_pr_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), title VARCHAR(100), body VARCHAR(1000), head VARCHAR(100), base VARCHAR(15), state VARCHAR(10))''')
|
||||
|
||||
# GitHub创建issue的API URL
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/pulls"
|
||||
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
|
||||
}
|
||||
|
||||
response = requests.get(url, headers=headers, json=data, verify=False)
|
||||
# 打印响应
|
||||
# print(response.text)
|
||||
pr_info = response.json()
|
||||
for pr in pr_info:
|
||||
print('title:', pr['title'])
|
||||
print('body:', pr['body'])
|
||||
print('head:', pr['head']['label'])
|
||||
print('base:', pr['base']['label'])
|
||||
cursor.execute(
|
||||
'INSERT INTO github_pr_list (number, title, body, head, base, state) VALUES (%s, %s, %s, %s, %s, %s)',
|
||||
(
|
||||
pr['number'], pr['title'], pr['body'], pr['head']['ref'], pr['base']['ref'], pr['state']))
|
||||
|
||||
# 检查响应状态码
|
||||
if response.status_code == 200:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上GitHub可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
for pr in issue_info:
|
||||
print(f'Issue created with ID: {pr["number"]}')
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
# 提交事务
|
||||
conn.commit()
|
||||
# 关闭游标和连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
|
||||
########################这一块应当先进行代码仓库的同步#################################################
|
||||
|
||||
#####################查找其中state为open的pr并将其创建到gitlink上面#####################################
|
||||
def pushwork():
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="185102xmy",
|
||||
database="db1"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('SELECT state, title, body, head, base FROM github_pr_list')
|
||||
pr_info = cursor.fetchall()
|
||||
for row in pr_info:
|
||||
pr_state = row[0]
|
||||
pr_title = row[1]
|
||||
pr_body = row[2]
|
||||
pr_head = row[3]
|
||||
pr_base = row[4]
|
||||
if pr_state == 'open':
|
||||
url = "https://gitlink.org.cn/api/xumingyang21/reposyncer2/pulls.json"
|
||||
payload = json.dumps({
|
||||
"title": pr_title,
|
||||
"priority_id": "2",
|
||||
"body": pr_body,
|
||||
"head": pr_head,
|
||||
"base": pr_base,
|
||||
"is_original": False,
|
||||
"fork_project_id": "",
|
||||
"files_count": 1,
|
||||
"commits_count": 1,
|
||||
"reviewer_ids": [],
|
||||
"receivers_login": []
|
||||
})
|
||||
access_token = 'HXn433Vth2ksJmpv3yVqaE7qgK1yJbDFwc_xnITcM-o'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
data = response.json()
|
||||
print(data)
|
||||
print(response.text)
|
||||
# 提交事务
|
||||
conn.commit()
|
||||
# 关闭游标和连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
prework()
|
||||
pushwork()
|
||||
|
|
@ -0,0 +1,153 @@
|
|||
import urllib
|
||||
import requests
|
||||
import mysql.connector
|
||||
|
||||
####################################先将gitee的pr状态更改为合并#####################################
|
||||
def prework():
|
||||
# 连接到MySQL数据库
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="185102xmy",
|
||||
database="db1"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('SELECT number, state FROM gitee_pr_list')
|
||||
|
||||
gitee_pr_info = cursor.fetchall()
|
||||
for row in gitee_pr_info:
|
||||
number = row[0]
|
||||
state = row[1]
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
if state == 'open':
|
||||
# Gitee获取issue的API URL
|
||||
url = f'https://gitee.com/api/v5/repos/{owner}/{repo}/pulls/{number}'
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
# 发送POST请求 获取状态为open的issue
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"title": '尝试更改pr',
|
||||
"body": '好冲',
|
||||
"state": 'closed'
|
||||
}
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url = f"{url}?{query_string}"
|
||||
response = requests.patch(full_url, headers=headers, json=data)
|
||||
|
||||
if response.status_code == 200:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
pr_info = response.json()
|
||||
print(pr_info)
|
||||
else:
|
||||
print(f"获取pr失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
#########################获取gitlink中的信息#########################################
|
||||
|
||||
cursor.execute('DROP TABLE IF EXISTS gitlink_pr_list')
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS gitlink_pr_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), state VARCHAR(15), title VARCHAR(100), body VARCHAR(1000), head VARCHAR(15), base VARCHAR(15))''')
|
||||
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/pulls.json?keyword&status&priority_id&issue_tag_id&version_id&reviewer_id&assign_user_id&sort_by&sort_direction"
|
||||
|
||||
payload = {}
|
||||
|
||||
access_token = 'HXn433Vth2ksJmpv3yVqaE7qgK1yJbDFwc_xnITcM-o'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers, data=payload)
|
||||
data = response.json()
|
||||
for pr_info in data['pulls']:
|
||||
print('id:', pr_info['id'])
|
||||
print('state:', pr_info['status'])
|
||||
print('title:', pr_info['title'])
|
||||
print('body:', pr_info['body'])
|
||||
print('head:', pr_info['head'])
|
||||
print('base:', pr_info['base'])
|
||||
cursor.execute(
|
||||
'INSERT INTO gitlink_pr_list (number, state, title, body, head, base) VALUES (%s, %s, %s, %s, %s, %s)',
|
||||
(pr_info['id'], pr_info['status'], pr_info['title'], pr_info['body'], pr_info['head'], pr_info['base']))
|
||||
print(response.text)
|
||||
|
||||
# 提交事务
|
||||
conn.commit()
|
||||
# 关闭游标和连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
|
||||
#################################这个地方执行仓库的同步########################################
|
||||
|
||||
|
||||
################################在gitee里面添加新的pr#######################################
|
||||
def push():
|
||||
# 连接到MySQL数据库
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="185102xmy",
|
||||
database="db1"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
cursor.execute('SELECT state, title, body, head, base FROM gitlink_pr_list')
|
||||
gitlink_pr_info = cursor.fetchall()
|
||||
for row in gitlink_pr_info:
|
||||
gitlink_state = row[0]
|
||||
gitlink_title = row[1]
|
||||
gitlink_body = row[2]
|
||||
gitlink_head = row[3]
|
||||
gitlink_base = row[4]
|
||||
if gitlink_state == 'open':
|
||||
# Gitee创建pr的API URL
|
||||
url = f'https://gitee.com/api/v5/repos/{owner}/{repo}/pulls'
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
# 发送POST请求 获取状态为open的issue
|
||||
data = {
|
||||
"access_token": token,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"title": gitlink_title,
|
||||
"body": gitlink_body,
|
||||
"head": gitlink_head,
|
||||
"base": gitlink_base
|
||||
}
|
||||
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url = f"{url}?{query_string}"
|
||||
response = requests.post(full_url, headers=headers, json=data)
|
||||
# 打印响应
|
||||
# print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 201:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
pr_info = response.json()
|
||||
print(pr_info)
|
||||
|
||||
else:
|
||||
print(f"获取pr失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
# 提交事务
|
||||
conn.commit()
|
||||
# 关闭游标和连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
if __name__ == '__main__':
|
||||
prework()
|
||||
push()
|
||||
|
|
@ -0,0 +1,170 @@
|
|||
import urllib
|
||||
import requests
|
||||
import mysql.connector
|
||||
|
||||
####################################先将gitee的pr状态更改为合并#####################################
|
||||
def prework():
|
||||
# 连接到MySQL数据库
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="185102xmy",
|
||||
database="db1"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('DROP TABLE IF EXISTS github_pr_list')
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS github_pr_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), title VARCHAR(100), body VARCHAR(1000), head VARCHAR(100), base VARCHAR(15), state VARCHAR(10))''')
|
||||
|
||||
# GitHub创建issue的API URL
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/pulls"
|
||||
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
# 发送POST请求
|
||||
data = {
|
||||
|
||||
}
|
||||
response = requests.get(url, headers=headers, json=data, verify=False)
|
||||
# 打印响应
|
||||
# print(response.text)
|
||||
pr_info = response.json()
|
||||
for pr in pr_info:
|
||||
print(pr['title'])
|
||||
print(pr['state'])
|
||||
print(pr['body'])
|
||||
print(pr['number'])
|
||||
print(pr['base']['ref'])
|
||||
print(pr['head']['ref'])
|
||||
|
||||
if pr['state'] == 'open':
|
||||
# GitHub创建issue的API URL
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/pulls/{pr['number']}"
|
||||
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
'state': 'closed'
|
||||
}
|
||||
|
||||
response = requests.patch(url, headers=headers, json=data, verify=False)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 200:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上GitHub可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(f'Issue created with ID: {issue_info["number"]}')
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
#########################获取gitlink中的信息#########################################
|
||||
|
||||
cursor.execute('DROP TABLE IF EXISTS gitlink_pr_list')
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS gitlink_pr_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), state VARCHAR(15), title VARCHAR(100), body VARCHAR(1000), head VARCHAR(15), base VARCHAR(15))''')
|
||||
|
||||
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/pulls.json?keyword&status&priority_id&issue_tag_id&version_id&reviewer_id&assign_user_id&sort_by&sort_direction"
|
||||
|
||||
payload = {}
|
||||
|
||||
access_token = 'zo07-W-W6vnU1mvQhVhIdfyyVY3K1R1piil_jfvS1bg'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers, data=payload)
|
||||
data = response.json()
|
||||
for pr_info in data['pulls']:
|
||||
print('id:', pr_info['id'])
|
||||
print('state:', pr_info['status'])
|
||||
print('title:', pr_info['title'])
|
||||
print('body:', pr_info['body'])
|
||||
print('head:', pr_info['head'])
|
||||
print('base:', pr_info['base'])
|
||||
cursor.execute(
|
||||
'INSERT INTO gitlink_pr_list (number, state, title, body, head, base) VALUES (%s, %s, %s, %s, %s, %s)',
|
||||
(pr_info['id'], pr_info['status'], pr_info['title'], pr_info['body'], pr_info['head'], pr_info['base']))
|
||||
print(response.text)
|
||||
|
||||
# 提交事务
|
||||
conn.commit()
|
||||
# 关闭游标和连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
|
||||
#################################这个地方执行仓库的同步########################################
|
||||
|
||||
|
||||
################################在gitee里面添加新的pr#######################################
|
||||
def push():
|
||||
# 连接到MySQL数据库
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="185102xmy",
|
||||
database="db1"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
cursor.execute('SELECT state, title, body, head, base FROM gitlink_pr_list')
|
||||
gitlink_pr_info = cursor.fetchall()
|
||||
for row in gitlink_pr_info:
|
||||
gitlink_state = row[0]
|
||||
gitlink_title = row[1]
|
||||
gitlink_body = row[2]
|
||||
gitlink_head = row[3]
|
||||
gitlink_base = row[4]
|
||||
if gitlink_state == 'open':
|
||||
# Gitee创建pr的API URL
|
||||
# GitHub创建issue的API URL
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/pulls"
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
# 发送POST请求
|
||||
data = {
|
||||
"head": gitlink_head,
|
||||
"base": gitlink_base,
|
||||
"title": gitlink_title,
|
||||
"body": gitlink_body
|
||||
}
|
||||
response = requests.post(url, headers=headers, json=data, verify=False)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 200:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上GitHub可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(f' Github PR created with ID: {issue_info["number"]}')
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
# 提交事务
|
||||
conn.commit()
|
||||
# 关闭游标和连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
if __name__ == '__main__':
|
||||
prework()
|
||||
push()
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
import urllib
|
||||
import requests
|
||||
import mysql.connector
|
||||
|
||||
# 连接到MySQL数据库
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="185102xmy",
|
||||
database="db1"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
# cursor.execute('DROP TABLE IF EXISTS gitee_pr_list')
|
||||
# # 创建一个表
|
||||
# cursor.execute('''CREATE TABLE IF NOT EXISTS gitee_pr_list
|
||||
# (id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), state VARCHAR(15), title VARCHAR(100), body VARCHAR(1000), head VARCHAR(15), base VARCHAR(15))''')
|
||||
# 你的仓库信息
|
||||
owner = 'xumingyang21'
|
||||
repo = 'reposyncer2'
|
||||
number = 3
|
||||
# Gitee获取issue的API URL
|
||||
url = f'https://gitee.com/api/v5/repos/{owner}/{repo}/pulls/{number}'
|
||||
|
||||
# 构造请求头
|
||||
token = 'f2be2313581c1fde50b16bf35bb655c5'
|
||||
headers = {'Authorization': f'token {token}'}
|
||||
|
||||
# 发送POST请求 获取状态为open的issue
|
||||
data = {
|
||||
"access_token":token,
|
||||
"owner":owner,
|
||||
"repo":repo,
|
||||
"title":'尝试更改pr',
|
||||
"body":'好冲',
|
||||
"state":'closed'
|
||||
}
|
||||
|
||||
# 将字典转换为查询字符串
|
||||
query_string = urllib.parse.urlencode(data)
|
||||
# 完整的请求 URL,包括查询字符串
|
||||
full_url = f"{url}?{query_string}"
|
||||
response = requests.patch(full_url, headers=headers, json=data)
|
||||
# 打印响应
|
||||
# print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 200:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上Gitee可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
pr_info = response.json()
|
||||
print(pr_info)
|
||||
# for pr in pr_info:
|
||||
# print('number:',pr['id'])
|
||||
# print('state:',pr['state'])
|
||||
# print('title:',pr['title'])
|
||||
# print('body:',pr['body'])
|
||||
# print('head:',pr['head']['label'])
|
||||
# print('base:',pr['base']['label'])
|
||||
# cursor.execute('INSERT INTO gitee_pr_list (number, state, title, body, head, base) VALUES (%s, %s, %s, %s, %s, %s)',
|
||||
# (pr['id'], pr['state'], pr['title'], pr['body'], pr['head']['label'], pr['base']['label']))
|
||||
|
||||
else:
|
||||
print(f"获取pr失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
||||
# 提交事务
|
||||
conn.commit()
|
||||
# 关闭游标和连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
import requests
|
||||
|
||||
|
||||
# 你的GitHub用户名(或用于认证的token)
|
||||
# 注意:出于安全考虑,通常不建议在代码中硬编码密码,而是使用token
|
||||
|
||||
|
||||
# GitHub创建issue的API URL
|
||||
url = f"https://api.github.com/repos/fuxingtamu/yundingzhiyi/pulls/41"
|
||||
|
||||
# 构造请求头
|
||||
token = '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'
|
||||
# 构造请求头
|
||||
headers = {
|
||||
'Authorization': f'token {token}',
|
||||
'Accept': 'application/vnd.github+json'
|
||||
}
|
||||
|
||||
# 发送POST请求
|
||||
data = {
|
||||
'state':'closed'
|
||||
}
|
||||
|
||||
response = requests.patch(url, headers=headers, json=data,verify=False)
|
||||
# 打印响应
|
||||
print(response.text)
|
||||
# 检查响应状态码
|
||||
if response.status_code == 200:
|
||||
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID,但实际上GitHub可能返回不同的结构
|
||||
# 你需要根据实际的响应结构来调整以下代码
|
||||
issue_info = response.json()
|
||||
print(f'Issue created with ID: {issue_info["number"]}')
|
||||
else:
|
||||
print(f"创建issue失败,状态码:{response.status_code},错误信息:{response.text}")
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
import requests
|
||||
|
||||
url = "https://gitlink.org.cn/api/xumingyang21/reposyncer2/pulls/7633/refuse_merge.json"
|
||||
|
||||
payload={}
|
||||
access_token = 'I9uyRzjEIObdgsD8fegdQoN2d3p3cU_7_uaNGV03S_Q'
|
||||
headers = {
|
||||
'Authorization': f'Bearer {access_token}',
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
|
||||
}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
|
||||
print(response.text)
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Black">
|
||||
<option name="sdkName" value="Python 3.9" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
|
||||
<component name="PyCharmProfessionalAdvertiser">
|
||||
<option name="shown" value="true" />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/repo-plugin.iml" filepath="$PROJECT_DIR$/.idea/repo-plugin.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
|
|
@ -0,0 +1,150 @@
|
|||
document.addEventListener('DOMContentLoaded', function() {
|
||||
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
|
||||
var currentTab = tabs[0];
|
||||
if (currentTab.url.startsWith("https://gitee.com/")) {
|
||||
// 如果当前标签页的 URL 以 "https://gitee.com/" 开头
|
||||
var syncOption1Label = document.getElementById('syncOption1label');
|
||||
var syncOption1Input = document.querySelector('input#syncOption1');
|
||||
var syncOption2Label = document.getElementById('syncOption2label');
|
||||
var syncOption2Input = document.querySelector('input#syncOption2');
|
||||
var syncOption3Label = document.getElementById('syncOption3label');
|
||||
var syncOption3Input = document.querySelector('input#syncOption3');
|
||||
if (syncOption2Label && syncOption2Input) {
|
||||
// 隐藏标签和输入框
|
||||
syncOption2Label.style.display = 'none';
|
||||
syncOption2Input.style.display = 'none';
|
||||
syncOption1Input.style.top='15px';
|
||||
syncOption1Input.style.left='280px';
|
||||
syncOption1Label.style.top='20px';
|
||||
syncOption1Label.style.left='340px';
|
||||
syncOption3Input.style.top='15px';
|
||||
syncOption3Input.style.left='430px';
|
||||
syncOption3Label.style.top='20px';
|
||||
syncOption3Label.style.left='490px';
|
||||
}
|
||||
}
|
||||
if (currentTab.url.startsWith("https://www.gitlink")) {
|
||||
// 如果当前标签页的 URL 以 "https://www.gitlink" 开头
|
||||
var syncOption1Label = document.getElementById('syncOption1label');
|
||||
var syncOption1Input = document.querySelector('input#syncOption1');
|
||||
var syncOption2Label = document.getElementById('syncOption2label');
|
||||
var syncOption2Input = document.querySelector('input#syncOption2');
|
||||
var syncOption3Label = document.getElementById('syncOption3label');
|
||||
var syncOption3Input = document.querySelector('input#syncOption3');
|
||||
if (syncOption1Label && syncOption1Input) {
|
||||
// 隐藏标签和输入框
|
||||
syncOption1Label.style.display = 'none';
|
||||
syncOption1Input.style.display = 'none';
|
||||
syncOption2Input.style.top='15px';
|
||||
syncOption2Input.style.left='280px';
|
||||
syncOption2Label.style.top='20px';
|
||||
syncOption2Label.style.left='340px';
|
||||
syncOption3Input.style.top='15px';
|
||||
syncOption3Input.style.left='430px';
|
||||
syncOption3Label.style.top='20px';
|
||||
syncOption3Label.style.left='490px';
|
||||
}
|
||||
}
|
||||
if (currentTab.url.startsWith("https://github")) {
|
||||
// 如果当前标签页的 URL 以 "https://github" 开头
|
||||
var syncOption1Label = document.getElementById('syncOption1label');
|
||||
var syncOption1Input = document.querySelector('input#syncOption1');
|
||||
var syncOption2Label = document.getElementById('syncOption2label');
|
||||
var syncOption2Input = document.querySelector('input#syncOption2');
|
||||
var syncOption3Label = document.getElementById('syncOption3label');
|
||||
var syncOption3Input = document.querySelector('input#syncOption3');
|
||||
if (syncOption3Label && syncOption3Input) {
|
||||
// 隐藏标签和输入框
|
||||
syncOption3Label.style.display = 'none';
|
||||
syncOption3Input.style.display = 'none';
|
||||
syncOption1Input.style.top='15px';
|
||||
syncOption1Input.style.left='280px';
|
||||
syncOption1Label.style.top='20px';
|
||||
syncOption1Label.style.left='340px';
|
||||
syncOption2Input.style.top='15px';
|
||||
syncOption2Input.style.left='430px';
|
||||
syncOption2Label.style.top='20px';
|
||||
syncOption2Label.style.left='490px';
|
||||
}
|
||||
}
|
||||
if (!currentTab.url.startsWith("https://gitee.com/")&&!currentTab.url.startsWith("https://www.gitlink")&&!currentTab.url.startsWith("https://github")) {
|
||||
document.body.innerHTML = `
|
||||
<h1 class="title">Extension Disabled</h1>
|
||||
<style>
|
||||
.title {
|
||||
color: #333;
|
||||
font-family: Arial, sans-serif;
|
||||
text-align: center;
|
||||
margin-top: 50px;
|
||||
}
|
||||
body {
|
||||
background-color: #f4f4f4;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
`;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// 获取所有按钮并为它们添加事件监听器
|
||||
const buttons = document.querySelectorAll('.styled-button');
|
||||
buttons.forEach(button => {
|
||||
button.addEventListener('click', function(event) {
|
||||
|
||||
|
||||
|
||||
const url = document.querySelector('.url-input').value;
|
||||
const token = document.querySelector('.token-input').value;
|
||||
const repository1 = document.querySelector('.repository1-input').value;
|
||||
const branch1 = document.querySelector('.branch1-input').value;
|
||||
const repository2 = document.querySelector('.repository2-input').value;
|
||||
const branch2 = document.querySelector('.branch2-input').value;
|
||||
const syncOption1Input = document.querySelector('#syncOption1').checked;
|
||||
const syncOption2Input = document.querySelector('#syncOption2').checked;
|
||||
const syncOption3Input = document.querySelector('#syncOption3').checked;
|
||||
|
||||
const data = {
|
||||
url: url,
|
||||
token: token,
|
||||
repository1: repository1,
|
||||
branch1: branch1,
|
||||
repository2: repository2,
|
||||
branch2: branch2,
|
||||
type: this.id, // 确保 this 指向按钮
|
||||
syncOption1Input: syncOption1Input,
|
||||
syncOption2Input: syncOption2Input,
|
||||
syncOption3Input: syncOption3Input
|
||||
};
|
||||
|
||||
const sendRequest = () => {
|
||||
fetch('http://localhost:8080/sync', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(data)
|
||||
})
|
||||
|
||||
};
|
||||
|
||||
sendRequest();
|
||||
// 定义输入框数组
|
||||
document.querySelector('.url-input').value = '';
|
||||
document.querySelector('.token-input').value = '';
|
||||
document.querySelector('.repository1-input').value = '';
|
||||
document.querySelector('.branch1-input').value = '';
|
||||
document.querySelector('.repository2-input').value = '';
|
||||
document.querySelector('.branch2-input').value = '';
|
||||
document.querySelector('#syncOption1').checked = false;
|
||||
document.querySelector('#syncOption2').checked = false;
|
||||
document.querySelector('#syncOption3').checked = false;
|
||||
event.preventDefault();//按钮点击后阻止默认行为
|
||||
});
|
||||
});
|
||||
});
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 6.7 KiB |
|
|
@ -0,0 +1,161 @@
|
|||
document.addEventListener('DOMContentLoaded', function() {
|
||||
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
|
||||
var currentTab = tabs[0];
|
||||
const url = tabs[0].url;
|
||||
const data1 = {
|
||||
url: url,
|
||||
};
|
||||
const sendRequest1 = () => {
|
||||
fetch('http://localhost:8080/sync', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(data1)
|
||||
})
|
||||
|
||||
};
|
||||
sendRequest1();
|
||||
if (currentTab.url.startsWith("https://gitee.com/")) {
|
||||
// 如果当前标签页的 URL 以 "https://gitee.com/" 开头
|
||||
var syncOption1Label = document.getElementById('syncOption1label');
|
||||
var syncOption1Input = document.querySelector('input#syncOption1');
|
||||
var syncOption2Label = document.getElementById('syncOption2label');
|
||||
var syncOption2Input = document.querySelector('input#syncOption2');
|
||||
var syncOption3Label = document.getElementById('syncOption3label');
|
||||
var syncOption3Input = document.querySelector('input#syncOption3');
|
||||
if (syncOption2Label && syncOption2Input) {
|
||||
// 隐藏标签和输入框
|
||||
syncOption2Label.style.display = 'none';
|
||||
syncOption2Input.style.display = 'none';
|
||||
syncOption1Input.style.top='15px';
|
||||
syncOption1Input.style.left='280px';
|
||||
syncOption1Label.style.top='20px';
|
||||
syncOption1Label.style.left='340px';
|
||||
syncOption3Input.style.top='15px';
|
||||
syncOption3Input.style.left='430px';
|
||||
syncOption3Label.style.top='20px';
|
||||
syncOption3Label.style.left='490px';
|
||||
}
|
||||
}
|
||||
if (currentTab.url.startsWith("https://www.gitlink")) {
|
||||
// 如果当前标签页的 URL 以 "https://www.gitlink" 开头
|
||||
var syncOption1Label = document.getElementById('syncOption1label');
|
||||
var syncOption1Input = document.querySelector('input#syncOption1');
|
||||
var syncOption2Label = document.getElementById('syncOption2label');
|
||||
var syncOption2Input = document.querySelector('input#syncOption2');
|
||||
var syncOption3Label = document.getElementById('syncOption3label');
|
||||
var syncOption3Input = document.querySelector('input#syncOption3');
|
||||
if (syncOption1Label && syncOption1Input) {
|
||||
// 隐藏标签和输入框
|
||||
syncOption1Label.style.display = 'none';
|
||||
syncOption1Input.style.display = 'none';
|
||||
syncOption2Input.style.top='15px';
|
||||
syncOption2Input.style.left='280px';
|
||||
syncOption2Label.style.top='20px';
|
||||
syncOption2Label.style.left='340px';
|
||||
syncOption3Input.style.top='15px';
|
||||
syncOption3Input.style.left='430px';
|
||||
syncOption3Label.style.top='20px';
|
||||
syncOption3Label.style.left='490px';
|
||||
}
|
||||
}
|
||||
if (currentTab.url.startsWith("https://github")) {
|
||||
// 如果当前标签页的 URL 以 "https://github" 开头
|
||||
var syncOption1Label = document.getElementById('syncOption1label');
|
||||
var syncOption1Input = document.querySelector('input#syncOption1');
|
||||
var syncOption2Label = document.getElementById('syncOption2label');
|
||||
var syncOption2Input = document.querySelector('input#syncOption2');
|
||||
var syncOption3Label = document.getElementById('syncOption3label');
|
||||
var syncOption3Input = document.querySelector('input#syncOption3');
|
||||
if (syncOption3Label && syncOption3Input) {
|
||||
// 隐藏标签和输入框
|
||||
syncOption3Label.style.display = 'none';
|
||||
syncOption3Input.style.display = 'none';
|
||||
syncOption1Input.style.top='15px';
|
||||
syncOption1Input.style.left='280px';
|
||||
syncOption1Label.style.top='20px';
|
||||
syncOption1Label.style.left='340px';
|
||||
syncOption2Input.style.top='15px';
|
||||
syncOption2Input.style.left='430px';
|
||||
syncOption2Label.style.top='20px';
|
||||
syncOption2Label.style.left='490px';
|
||||
}
|
||||
}
|
||||
if (!currentTab.url.startsWith("https://gitee.com/")&&!currentTab.url.startsWith("https://www.gitlink")&&!currentTab.url.startsWith("https://github")) {
|
||||
document.body.innerHTML = `
|
||||
<h1 class="title">Extension Disabled</h1>
|
||||
<style>
|
||||
.title {
|
||||
color: #333;
|
||||
font-family: Arial, sans-serif;
|
||||
text-align: center;
|
||||
margin-top: 50px;
|
||||
}
|
||||
body {
|
||||
background-color: #f4f4f4;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
`;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// 获取所有按钮并为它们添加事件监听器
|
||||
const buttons = document.querySelectorAll('.styled-button');
|
||||
buttons.forEach(button => {
|
||||
button.addEventListener('click', function(event) {
|
||||
|
||||
const repository1_user = document.querySelector('.repository1-user-input').value;
|
||||
const repository1 = document.querySelector('.repository1-input').value;
|
||||
const repository1_token = document.querySelector('.repository1-token-input').value;
|
||||
const repository2_token = document.querySelector('.repository2-token-input').value;
|
||||
|
||||
const syncOption1Input = document.querySelector('#syncOption1').checked;
|
||||
const syncOption2Input = document.querySelector('#syncOption2').checked;
|
||||
const syncOption3Input = document.querySelector('#syncOption3').checked;
|
||||
|
||||
const data = {
|
||||
repository1_user:repository1_user,
|
||||
repository1: repository1,
|
||||
repository1_token:repository1_token,
|
||||
repository2_token: repository2_token,
|
||||
|
||||
type: this.id, // 确保 this 指向按钮
|
||||
syncOption1Input: syncOption1Input,
|
||||
syncOption2Input: syncOption2Input,
|
||||
syncOption3Input: syncOption3Input
|
||||
|
||||
};
|
||||
|
||||
const sendRequest = () => {
|
||||
fetch('http://localhost:8080/sync', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(data)
|
||||
})
|
||||
|
||||
};
|
||||
|
||||
sendRequest();
|
||||
// 定义输入框数组
|
||||
|
||||
document.querySelector('.repository1-user-input').value = '';
|
||||
document.querySelector('.repository1-input').value = '';
|
||||
document.querySelector('.repository1-token-input').value = '';
|
||||
document.querySelector('.repository2-token-input').value = '';
|
||||
document.querySelector('#syncOption1').checked = false;
|
||||
document.querySelector('#syncOption2').checked = false;
|
||||
document.querySelector('#syncOption3').checked = false;
|
||||
event.preventDefault();//按钮点击后阻止默认行为
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"manifest_version": 3,
|
||||
"name": "repo-try",
|
||||
"version":"0.0.1",
|
||||
"permissions": ["tabs"],
|
||||
"description":"My Chrome Repo-Plugin",
|
||||
"icons":{
|
||||
"128":"img/logo.png",
|
||||
"48":"img/logo.png",
|
||||
"16":"img/logo.png"
|
||||
},
|
||||
"action":{
|
||||
"default_icon":"img/logo.png",
|
||||
"default_popup":"popup.html",
|
||||
"dafault_title":"RepoSyncer-Extension"
|
||||
},
|
||||
"author":"DJQ",
|
||||
"host_permissions":[
|
||||
"http://*:8080/*"
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>I am Repo</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel="stylesheet" type="text/css" href="styles.css">
|
||||
</head>
|
||||
<body style="width: 750px;height: 500px;">
|
||||
<p class="greeting">您好,欢迎使用Reposyncer插件!</p>
|
||||
<p class="choose">请选择要进行同步的开源网站</p>
|
||||
<form id="dataForm">
|
||||
<div class="content">
|
||||
<div class="app">
|
||||
<div class="header">
|
||||
<div class="menu-circle"></div>
|
||||
<div class="header-menu">
|
||||
<div class="choose">
|
||||
<label id="syncOption1label">To-GitLink</label>
|
||||
<input type="radio" id="syncOption1" name="syncOptions" value="gitlink">
|
||||
<label id="syncOption2label">To-Gitee</label>
|
||||
<input type="radio" id="syncOption2" name="syncOptions" value="gitee">
|
||||
<label id="syncOption3label">To-GitHub</label>
|
||||
<input type="radio" id="syncOption3" name="syncOptions" value="github">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="side-repository1-username">同步仓库的用户名</div>
|
||||
<input type="text" class="repository1-user-input" placeholder="请输入同步仓库的用户名">
|
||||
|
||||
<div class="side-repository1">同步的仓库名称</div>
|
||||
<input type="text" class="repository1-input" placeholder="请输入同步的仓库名称">
|
||||
|
||||
<div class="side-repository1-token">同步的仓库token</div>
|
||||
<input type="text" class="repository1-token-input" placeholder="请输入同步的仓库token">
|
||||
|
||||
<div class="side-repository2-token">当前仓库的token</div>
|
||||
<input type="text" class="repository2-token-input" placeholder="请输入当前仓库的token">
|
||||
|
||||
<div class="button-container">
|
||||
<button class="styled-button" id="button1">分支同步</button>
|
||||
<button class="styled-button" id="button2">PR同步</button>
|
||||
<button class="styled-button" id="button3">Issue同步</button>
|
||||
<button class="styled-button" id="button4">里程碑同步</button>
|
||||
<button class="styled-button" id="button5">评论同步</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<script src="js/popup.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,456 @@
|
|||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
padding: 20px;
|
||||
max-width: 1000px;
|
||||
margin: 0 auto;
|
||||
text-align: center; /* 设置整个body的文本居中 */
|
||||
}
|
||||
|
||||
h1 {
|
||||
text-align: center; /* 单独设置标题居中 */
|
||||
}
|
||||
|
||||
|
||||
label {
|
||||
margin-bottom: 5px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
input[value="gitlink"]{
|
||||
height: 20px;
|
||||
width: 100px;
|
||||
top:15px;
|
||||
left:180px;
|
||||
position: absolute;
|
||||
}
|
||||
.choose label[id="syncOption1label"]{
|
||||
height: 20px;
|
||||
width: 100px;
|
||||
top:20px;
|
||||
left:260px;
|
||||
position: absolute;
|
||||
}
|
||||
input[value="gitee"]{
|
||||
height: 20px;
|
||||
width: 100px;
|
||||
top:15px;
|
||||
left:330px;
|
||||
position: absolute;
|
||||
}
|
||||
.choose label[id="syncOption2label"]{
|
||||
height: 20px;
|
||||
width: 100px;
|
||||
top:20px;
|
||||
left:410px;
|
||||
position: absolute;
|
||||
}
|
||||
input[value="github"]{
|
||||
height: 20px;
|
||||
width: 100px;
|
||||
top:15px;
|
||||
left:480px;
|
||||
position: absolute;
|
||||
}
|
||||
.choose label[id="syncOption3label"]{
|
||||
height: 20px;
|
||||
width: 100px;
|
||||
top:20px;
|
||||
left:560px;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
/* 为label添加鼠标悬停效果 */
|
||||
.choose label:hover:before {
|
||||
background-color: #f0f0f0; /* 鼠标悬停时的背景颜色 */
|
||||
}
|
||||
.wrapper {
|
||||
display: flex;
|
||||
flex-grow: 1;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.side-repository1-username {
|
||||
color: var(--inactive-color);
|
||||
height: 20px;
|
||||
width: 150px;
|
||||
left: 20px;
|
||||
top: 50px;
|
||||
position: absolute;
|
||||
}
|
||||
.repository1-user-input{
|
||||
color: var(--inactive-color);
|
||||
height: 30px;
|
||||
width: 500px;
|
||||
left: 200px;
|
||||
top: 45px;
|
||||
position: absolute;
|
||||
}
|
||||
.side-repository1{
|
||||
color: var(--inactive-color);
|
||||
height: 20px;
|
||||
width: 150px;
|
||||
left: 20px;
|
||||
top: 100px;
|
||||
position: absolute;
|
||||
}
|
||||
.repository1-input{
|
||||
color: var(--inactive-color);
|
||||
height: 30px;
|
||||
width: 500px;
|
||||
left: 200px;
|
||||
top: 95px;
|
||||
position: absolute;
|
||||
}
|
||||
.side-repository1-token{
|
||||
color: var(--inactive-color);
|
||||
height: 20px;
|
||||
width: 150px;
|
||||
left: 20px;
|
||||
top: 150px;
|
||||
position: absolute;
|
||||
}
|
||||
.repository1-token-input{
|
||||
color: var(--inactive-color);
|
||||
height: 30px;
|
||||
width: 500px;
|
||||
left: 200px;
|
||||
top: 145px;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.side-repository2-token{
|
||||
color: var(--inactive-color);
|
||||
height: 20px;
|
||||
width: 150px;
|
||||
left: 20px;
|
||||
top: 200px;
|
||||
position: absolute;
|
||||
}
|
||||
.repository2-token-input{
|
||||
color: var(--inactive-color);
|
||||
height: 30px;
|
||||
width: 500px;
|
||||
left: 200px;
|
||||
top: 195px;
|
||||
position: absolute;
|
||||
}
|
||||
.styled-button {
|
||||
padding: 10px 20px;
|
||||
background-color: #007BFF; /* 蓝色背景 */
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
margin: 5px;
|
||||
transition: background-color 0.3s, transform 0.1s;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
outline: none; /* 移除焦点时的轮廓 */
|
||||
font-size: 16px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.styled-button:hover {
|
||||
background-color: #0056b3; /* 鼠标悬停时的深色背景 */
|
||||
transform: translateY(-2px); /* 轻微上移 */
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.styled-button:active {
|
||||
transform: translateY(0); /* 点击时恢复原位 */
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.styled-button:focus {
|
||||
outline: none; /* 移除焦点轮廓 */
|
||||
box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.5); /* 添加焦点时的蓝色光晕 */
|
||||
}
|
||||
|
||||
input[id="syncOption1"]:hover{
|
||||
background-color: #6daaeb; /* 鼠标悬停时的深色背景 */
|
||||
transform: translateY(-2px); /* 轻微上移 */
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0);
|
||||
}
|
||||
input[id="syncOption1"]:active {
|
||||
transform: translateY(0); /* 点击时恢复原位 */
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0);
|
||||
}
|
||||
input[id="syncOption1"]:focus {
|
||||
transform: translateY(-2px); /* 点击时恢复原位 */
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0);
|
||||
}
|
||||
input[id="syncOption2"]:hover{
|
||||
background-color: #6daaeb; /* 鼠标悬停时的深色背景 */
|
||||
transform: translateY(-2px); /* 轻微上移 */
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0);
|
||||
}
|
||||
input[id="syncOption2"]:active {
|
||||
transform: translateY(0); /* 点击时恢复原位 */
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0);
|
||||
}
|
||||
input[id="syncOption2"]:focus {
|
||||
transform: translateY(-2px); /* 点击时恢复原位 */
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0);
|
||||
}
|
||||
input[id="syncOption3"]:hover{
|
||||
background-color: #6daaeb; /* 鼠标悬停时的深色背景 */
|
||||
transform: translateY(-2px); /* 轻微上移 */
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0);
|
||||
}
|
||||
input[id="syncOption3"]:active {
|
||||
transform: translateY(0); /* 点击时恢复原位 */
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0);
|
||||
}
|
||||
input[id="syncOption3"]:focus {
|
||||
transform: translateY(-2px); /* 点击时恢复原位 */
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
#button1{
|
||||
width:120px;
|
||||
height:42px;
|
||||
top: 360px;
|
||||
left: 25px;
|
||||
position: absolute;
|
||||
background-color: #f96057;
|
||||
color: #00000074;
|
||||
}
|
||||
#button2{
|
||||
width:120px;
|
||||
height:42px;
|
||||
top: 360px;
|
||||
left: 160px;
|
||||
position: absolute;
|
||||
background-color: #f8ce52;
|
||||
color: #00000074;
|
||||
}
|
||||
#button3{
|
||||
width:120px;
|
||||
height:42px;
|
||||
top: 360px;
|
||||
left: 295px;
|
||||
position: absolute;
|
||||
background-color: #5fcf5f;
|
||||
color: #00000074;
|
||||
}
|
||||
#button4{
|
||||
width:120px;
|
||||
height:42px;
|
||||
top: 360px;
|
||||
left: 430px;
|
||||
position: absolute;
|
||||
background-color: #b871ff;
|
||||
color: #00000074;
|
||||
}
|
||||
#button5{
|
||||
width:120px;
|
||||
height:42px;
|
||||
top: 360px;
|
||||
left: 565px;
|
||||
position: absolute;
|
||||
background-color: #71d4ff;
|
||||
color: #00000074;
|
||||
}
|
||||
.app {
|
||||
background-color: var(--theme-bg-color);
|
||||
max-width: 1000px;
|
||||
max-height: 800px;
|
||||
height: 90vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
width: 100%;
|
||||
border-radius: 14px;
|
||||
backdrop-filter: blur(20px);
|
||||
-webkit-backdrop-filter: blur(20px);
|
||||
font-size: 15px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-shrink: 0;
|
||||
height: 58px;
|
||||
width: 100%;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
padding: 0 30px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.menu-circle {
|
||||
width: 15px;
|
||||
height: 15px;
|
||||
background-color: #f96057;
|
||||
border-radius: 50%;
|
||||
box-shadow: 24px 0 0 0 #f8ce52, 48px 0 0 0 #5fcf65, 72px 0 0 0#b871ff, 96px 0 0 0#71d4ff, 120px 0 0 0#070707f6;
|
||||
margin-right: 170px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.header-menu {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.header-menu a {
|
||||
padding: 20px 30px;
|
||||
text-decoration: none;
|
||||
color: var(--inactive-color);
|
||||
border-bottom: 2px solid transparent;
|
||||
transition: 0.3s;
|
||||
}
|
||||
|
||||
.menu-link-main {
|
||||
text-decoration: none;
|
||||
color: var(--theme-color);
|
||||
padding: 0 30px;
|
||||
}
|
||||
|
||||
.greeting {
|
||||
font-size: 24px;
|
||||
color: #4a4a4a;
|
||||
font-family: 'Times New Roman', serif;
|
||||
padding: 20px;
|
||||
border: 2px solid #000000;
|
||||
border-radius: 10px;
|
||||
background: #fff;
|
||||
box-shadow: 5px 5px 5px rgba(73, 22, 239, 0.3);
|
||||
display: inline-block;
|
||||
margin: -5px;
|
||||
position: relative;
|
||||
/* 增加一些艺术感的装饰 */
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.greeting:before, .greeting:after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
background: linear-gradient(to right, transparent, rgba(255, 255, 255, 0.5), transparent);
|
||||
transform: scaleY(0.2);
|
||||
transform-origin: 0 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* 定义渐变动画 */
|
||||
@keyframes gradientAnimation {
|
||||
0% { background-position: 0% 50%; }
|
||||
50% { background-position: 100% 50%; }
|
||||
100% { background-position: 0% 50%; }
|
||||
}
|
||||
|
||||
/* 应用渐变动画 */
|
||||
.greeting {
|
||||
animation: gradientAnimation 3s ease infinite;
|
||||
background: linear-gradient(270deg, rgba(230, 100, 101, 0.5), rgba(145, 152, 229, 0.5), rgba(52, 232, 158, 0.5));
|
||||
background-size: 200% 200%;
|
||||
}
|
||||
|
||||
.greeting:after {
|
||||
transform-origin: 100% 100%;
|
||||
transform: scaleY(0.2);
|
||||
}
|
||||
|
||||
/* 增加一些动态效果 */
|
||||
.greeting:hover {
|
||||
box-shadow: 10px 10px 30px rgba(0, 0, 0, 0.4);
|
||||
}
|
||||
|
||||
.choose {
|
||||
font-size: 16px; /* 增大字体大小 */
|
||||
color: #683434; /* 设置字体颜色 */
|
||||
}
|
||||
|
||||
/* 输入框样式 */
|
||||
.input-group {
|
||||
position: relative;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.input-group label {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 10px;
|
||||
transform: translateY(-50%);
|
||||
background-color: #ffffff;
|
||||
padding: 0 5px;
|
||||
color: #999;
|
||||
font-size: 16px;
|
||||
transition: 0.3s ease all;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
|
||||
/* 输入框样式 */
|
||||
.url-input,
|
||||
.token-input,
|
||||
.repository1-input,
|
||||
.branch1-input,
|
||||
.repository2-input,
|
||||
.branch2-input {
|
||||
width: 500px;
|
||||
padding: 12px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
font-size: 16px;
|
||||
transition: border-color 0.3s, box-shadow 0.3s;
|
||||
}
|
||||
|
||||
/* 聚焦时的输入框样式 */
|
||||
.url-input:focus,
|
||||
.token-input:focus,
|
||||
.repository1-input:focus,
|
||||
.branch1-input:focus,
|
||||
.repository2-input:focus,
|
||||
.branch2-input:focus {
|
||||
border-color: #007bff;
|
||||
outline: none;
|
||||
box-shadow: 0 0 10px rgba(0, 123, 255, 0.2);
|
||||
}
|
||||
.url-input:focus + label,
|
||||
.token-input:focus + label,
|
||||
.repository1-input:focus + label,
|
||||
.branch1-input:focus + label,
|
||||
.repository2-input:focus + label,
|
||||
.branch2-input:focus + label {
|
||||
color: #3498db;
|
||||
transform: translateY(-150%);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
|
||||
/* 标签样式 */
|
||||
.side-token,
|
||||
.side-repository1,
|
||||
.side-branch1,
|
||||
.side-repository2,
|
||||
.side-branch2 {
|
||||
display: block;
|
||||
color: #333;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
|
||||
/* 设置背景图片 */
|
||||
body {
|
||||
background-image: url('https://bpic.588ku.com/back_pic/17/30/17/27630d6124e6d48.jpg');
|
||||
background-position: center center;
|
||||
background-size: cover;
|
||||
background-attachment: fixed;
|
||||
}
|
||||
|
||||
/* 内容样式 */
|
||||
.content {
|
||||
position: relative;
|
||||
z-index: 100;
|
||||
background: rgba(255, 255, 255, 0.5); /* 半透明背景 */
|
||||
padding: 20px;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
|
@ -8,4 +8,5 @@ aiomysql==0.0.21
|
|||
requests==2.26.0
|
||||
loguru==0.6.0
|
||||
typing-extensions==4.1.1
|
||||
aiofiles==0.8.0
|
||||
aiofiles==0.8.0
|
||||
mysql-connector-python==9.0.0
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
from flask import Flask, request, jsonify
|
||||
import mysql.connector
|
||||
from issue_sync import issue_github_to_gitee, issue_gitee_to_gitlink, issue_gitlink_to_github, issue_gitlink_to_gitee, issue_github_to_gitlink, issue_gitee_to_github
|
||||
from pr_sync import pr_gitlink_to_gitee, pr_gitee_to_gitlink, pr_github_to_gitee, pr_github_to_gitlink, pr_gitee_to_github, pr_gitlink_to_github
|
||||
from milestone_sync import milestone_gitee_to_gitlink, milestone_gitlink_to_gitee, milestone_github_to_gitee
|
||||
app = Flask(__name__)
|
||||
import re
|
||||
|
||||
@app.route('/sync', methods=['POST'])
|
||||
def sync_data():
|
||||
data = request.get_json() # 获取 JSON 数据
|
||||
print('Received data:', data)
|
||||
#需要数据库去存储现在的source_url
|
||||
conn = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="185102xmy",
|
||||
database="db1"
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS source_url_list
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY, source_url VARCHAR(15))''')
|
||||
#我在这里获取url
|
||||
if 'url' in data:
|
||||
url = str(data['url'])
|
||||
if 'gitee' in url:
|
||||
source_url = 'gitee'
|
||||
sql = "INSERT INTO source_url_list (source_url) VALUES (%s)"
|
||||
# 执行 SQL 语句,注意 issue_subject 需要被放在一个元组中
|
||||
cursor.execute(sql, (source_url,))
|
||||
elif 'gitlink' in url:
|
||||
source_url = 'gitlink'
|
||||
sql = "INSERT INTO source_url_list (source_url) VALUES (%s)"
|
||||
# 执行 SQL 语句,注意 issue_subject 需要被放在一个元组中
|
||||
cursor.execute(sql, (source_url,))
|
||||
elif 'github' in url:
|
||||
source_url = 'github'
|
||||
sql = "INSERT INTO source_url_list (source_url) VALUES (%s)"
|
||||
# 执行 SQL 语句,注意 issue_subject 需要被放在一个元组中
|
||||
cursor.execute(sql, (source_url,))
|
||||
conn.commit()
|
||||
else:
|
||||
cursor.execute('SELECT source_url FROM source_url_list ORDER BY id DESC LIMIT 1')
|
||||
result = cursor.fetchone()
|
||||
source_url = result[0]
|
||||
if source_url == 'gitee':
|
||||
if str(data.get('syncOption1Input')) == 'True':#说明是从gitee到gitlink
|
||||
if (str(data.get('type')) == 'button3'):
|
||||
issue_gitee_to_gitlink.main()
|
||||
elif (str(data.get('type')) == 'button2'):
|
||||
pr_gitee_to_gitlink.prework()
|
||||
pr_gitee_to_gitlink.pushwork()
|
||||
elif (str(data.get('type')) == 'button4'):
|
||||
milestone_gitee_to_gitlink.main()
|
||||
else:#这里说明是从gitee到GitHub
|
||||
if (str(data.get('type')) == 'button3'):
|
||||
issue_gitee_to_github.main()
|
||||
elif (str(data.get('type')) == 'button2'):
|
||||
pr_gitee_to_github.prework()
|
||||
pr_gitee_to_github.pushwork()
|
||||
elif (str(data.get('type')) == 'button4'):
|
||||
milestone_gitee_to_gitlink.main()#这里在更改
|
||||
|
||||
elif source_url == 'gitlink':
|
||||
if str(data.get('syncOption2Input')) == 'True': #说明是从gitlink到gitee
|
||||
if (str(data.get('type')) == 'button3'):
|
||||
issue_gitlink_to_gitee.main()
|
||||
elif (str(data.get('type')) == 'button2'):
|
||||
pr_gitlink_to_gitee.prework()
|
||||
pr_gitlink_to_gitee.push()
|
||||
elif (str(data.get('type')) == 'button4'):
|
||||
milestone_gitlink_to_gitee.main()
|
||||
else:
|
||||
if (str(data.get('type')) == 'button3'):
|
||||
issue_gitlink_to_github.main()
|
||||
elif (str(data.get('type')) == 'button2'):
|
||||
pr_gitlink_to_github.prework()
|
||||
pr_gitlink_to_github.push()
|
||||
elif (str(data.get('type')) == 'button4'):
|
||||
milestone_gitee_to_gitlink.main() # 这里在更改
|
||||
else:
|
||||
if str(data.get('syncOption2Input')) == 'True':#说明是到gitee的
|
||||
if (str(data.get('type')) == 'button3'):
|
||||
issue_github_to_gitee.main()
|
||||
elif (str(data.get('type')) == 'button2'):
|
||||
pr_github_to_gitee.prework()
|
||||
pr_github_to_gitee.push()
|
||||
elif (str(data.get('type')) == 'button4'):
|
||||
milestone_github_to_gitee.main() # 这里在更改
|
||||
else:
|
||||
if (str(data.get('type')) == 'button3'):
|
||||
issue_github_to_gitlink.main()
|
||||
elif (str(data.get('type')) == 'button2'):
|
||||
pr_github_to_gitlink.prework()
|
||||
pr_github_to_gitlink.pushwork()
|
||||
elif (str(data.get('type')) == 'button4'):
|
||||
milestone_github_to_gitee.main() # 这里在更改
|
||||
cursor.close()
|
||||
conn.close()
|
||||
# 返回响应
|
||||
return jsonify({'status': 'success', 'message': 'Data received successfully'})
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0', port=8080, debug=True)
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
--同步仓库信息映射表
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `sync_repo_mapping` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
|
||||
|
|
@ -13,7 +12,6 @@ CREATE TABLE IF NOT EXISTS `sync_repo_mapping` (
|
|||
UNIQUE KEY (`repo_name`)
|
||||
) DEFAULT CHARACTER SET = utf8mb4 COMMENT = '同步仓库映射表';
|
||||
|
||||
--同步分支信息映射表
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `sync_branch_mapping`(
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
|
||||
|
|
@ -26,7 +24,6 @@ CREATE TABLE IF NOT EXISTS `sync_branch_mapping`(
|
|||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET = utf8mb4 COMMENT = '同步分支映射表';
|
||||
|
||||
--日志信息表
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `repo_sync_log`(
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ from src.router import SYNC_CONFIG as router
|
|||
from src.do.sync_config import SyncDirect
|
||||
from src.dto.sync_config import SyncRepoDTO, SyncBranchDTO, LogDTO, ModifyRepoDTO
|
||||
from src.service.sync_config import SyncService, LogService
|
||||
from src.service.cronjob import sync_repo_task, sync_branch_task, modify_repos, delete_repo_dir
|
||||
from src.service.cronjob import sync_repo_task, sync_branch_task, modify_repos, delete_repo_dir, sync_issue_task, sync_pr_task
|
||||
from src.base.status_code import Status, SYNCResponse, SYNCException
|
||||
from src.service.cronjob import GITMSGException
|
||||
|
||||
|
|
@ -38,11 +38,11 @@ class SyncDirection(Controller):
|
|||
dto: SyncRepoDTO = Body(..., description="绑定同步仓库信息")
|
||||
):
|
||||
api_log(LogType.INFO, f"用户 {user} 使用 POST 方法访问接口 {request.url.path} ", user)
|
||||
if not base.check_addr(dto.external_repo_address) or not base.check_addr(dto.internal_repo_address):
|
||||
return SYNCResponse(
|
||||
code_status=Status.REPO_ADDR_ILLEGAL.code,
|
||||
msg=Status.REPO_ADDR_ILLEGAL.msg
|
||||
)
|
||||
# if not base.check_addr(dto.external_repo_address) or not base.check_addr(dto.internal_repo_address):
|
||||
# return SYNCResponse(
|
||||
# code_status=Status.REPO_ADDR_ILLEGAL.code,
|
||||
# msg=Status.REPO_ADDR_ILLEGAL.msg
|
||||
# )
|
||||
|
||||
if dto.sync_granularity not in [1, 2]:
|
||||
return SYNCResponse(code_status=Status.SYNC_GRAN_ILLEGAL.code, msg=Status.SYNC_GRAN_ILLEGAL.msg)
|
||||
|
|
@ -104,6 +104,60 @@ class SyncDirection(Controller):
|
|||
msg=Status.SUCCESS.msg
|
||||
)
|
||||
|
||||
@router.post("/repo/{repo_name}/issue", response_model=SYNCResponse, description='执行issue同步')
|
||||
async def sync_issue(
|
||||
self, request: Request, user: str = Depends(user),
|
||||
repo_name: str = Path(..., description="仓库名称"),
|
||||
sync_direct: int = Query(..., description="同步方向: 1 表示内部仓库同步到外部, 2 表示外部仓库同步到内部"),
|
||||
# force_flag: bool = Query(False, description="是否强制同步")
|
||||
):
|
||||
api_log(LogType.INFO, f"用户 {user} 使用 POST 方法访问接口 {request.url.path} ", user)
|
||||
repo = await self.service.get_repo(repo_name=repo_name)
|
||||
if repo is None:
|
||||
return SYNCResponse(code_status=Status.REPO_NOTFOUND.code, msg=Status.REPO_NOTFOUND.msg)
|
||||
if not repo.enable:
|
||||
return SYNCResponse(code_status=Status.NOT_ENABLE.code, msg=Status.NOT_ENABLE.msg)
|
||||
|
||||
try:
|
||||
await sync_issue_task(repo, user, sync_direct)
|
||||
except GITMSGException as GITError:
|
||||
return SYNCResponse(
|
||||
code_status=GITError.status,
|
||||
msg=GITError.msg
|
||||
)
|
||||
|
||||
return SYNCResponse(
|
||||
code_status=Status.SUCCESS.code,
|
||||
msg=Status.SUCCESS.msg
|
||||
)
|
||||
|
||||
@router.post("/repo/{repo_name}/pull_request", response_model=SYNCResponse, description='执行pr同步')
|
||||
async def sync_pull_request(
|
||||
self, request: Request, user: str = Depends(user),
|
||||
repo_name: str = Path(..., description="仓库名称"),
|
||||
sync_direct: int = Query(..., description="同步方向: 1 表示内部仓库同步到外部, 2 表示外部仓库同步到内部"),
|
||||
# force_flag: bool = Query(False, description="是否强制同步")
|
||||
):
|
||||
api_log(LogType.INFO, f"用户 {user} 使用 POST 方法访问接口 {request.url.path} ", user)
|
||||
repo = await self.service.get_repo(repo_name=repo_name)
|
||||
if repo is None:
|
||||
return SYNCResponse(code_status=Status.REPO_NOTFOUND.code, msg=Status.REPO_NOTFOUND.msg)
|
||||
if not repo.enable:
|
||||
return SYNCResponse(code_status=Status.NOT_ENABLE.code, msg=Status.NOT_ENABLE.msg)
|
||||
|
||||
try:
|
||||
await sync_pr_task(repo, user, sync_direct)
|
||||
except GITMSGException as GITError:
|
||||
return SYNCResponse(
|
||||
code_status=GITError.status,
|
||||
msg=GITError.msg
|
||||
)
|
||||
|
||||
return SYNCResponse(
|
||||
code_status=Status.SUCCESS.code,
|
||||
msg=Status.SUCCESS.msg
|
||||
)
|
||||
|
||||
@router.get("/{repo_name}/branch", response_model=SYNCResponse, description='获取仓库对应的同步分支信息')
|
||||
async def get_sync_branches(
|
||||
self, request: Request, user: str = Depends(user),
|
||||
|
|
|
|||
|
|
@ -33,11 +33,11 @@ buc_key and ConfigsUtil.set_obfastapi_config('buc_key', buc_key)
|
|||
DB_ENV = getenv('DB_ENV', 'test_env')
|
||||
DB = {
|
||||
'test_env': {
|
||||
'host': getenv('CEROBOT_MYSQL_HOST', ''),
|
||||
'port': getenv('CEROBOT_MYSQL_PORT', 2883, int),
|
||||
'user': getenv('CEROBOT_MYSQL_USER', ''),
|
||||
'passwd': getenv('CEROBOT_MYSQL_PWD', ''),
|
||||
'dbname': getenv('CEROBOT_MYSQL_DB', '')
|
||||
'host': getenv('CEROBOT_MYSQL_HOST', 'localhost'),
|
||||
'port': getenv('CEROBOT_MYSQL_PORT', 3306, int),
|
||||
'user': getenv('CEROBOT_MYSQL_USER', 'root'),
|
||||
'passwd': getenv('CEROBOT_MYSQL_PWD', '185102xmy'),
|
||||
'dbname': getenv('CEROBOT_MYSQL_DB', 'reposyncer3'),
|
||||
},
|
||||
'local': {
|
||||
'host': getenv('CEROBOT_MYSQL_HOST', ''),
|
||||
|
|
|
|||
|
|
@ -5,14 +5,15 @@ import shlex
|
|||
import subprocess
|
||||
from typing import List
|
||||
from src.base import config
|
||||
from src.base.status_code import GITMSGException, Status, git_error_mapping
|
||||
from src.base.status_code import GITMSGException, Status, git_error_mapping, SYNCResponse
|
||||
from src.base.config import SYNC_DIR
|
||||
from src.dao.sync_config import SyncRepoDAO, SyncBranchDAO
|
||||
from src.do.sync_config import SyncDirect, SyncType
|
||||
from src.dto.sync_config import SyncBranchDTO
|
||||
from src.utils.sync_log import sync_log, LogType, log_path, api_log
|
||||
from src.service.sync_config import LogService
|
||||
|
||||
from issue_sync import issue_gitee_to_gitlink, issue_gitlink_to_gitee
|
||||
from pr_sync import pr_gitee_to_gitlink, pr_gitlink_to_gitee
|
||||
sync_repo_dao = SyncRepoDAO()
|
||||
sync_branch_dao = SyncBranchDAO()
|
||||
log_service = LogService()
|
||||
|
|
@ -47,6 +48,66 @@ def delete_repo_dir(repo_name, user: str):
|
|||
repo_dir = os.path.join(SYNC_DIR, repo_name)
|
||||
os.path.exists(repo_dir) and shutil.rmtree(repo_dir)
|
||||
|
||||
def parse_git_output(output):
|
||||
# 定义正则表达式模式
|
||||
commit_pattern = re.compile(r'commit\s+([a-f0-9]+)')
|
||||
author_pattern = re.compile(r'Author:\s+(.+)')
|
||||
date_pattern = re.compile(r'Date:\s+(.+)')
|
||||
|
||||
#使用正则表达式搜索并提取信息
|
||||
commit_hash = commit_pattern.search(output).group(1) if commit_pattern.search(output) else None
|
||||
author = author_pattern.search(output).group(1) if author_pattern.search(output) else None
|
||||
date = date_pattern.search(output).group(1) if date_pattern.search(output) else None
|
||||
|
||||
return commit_hash, author, date
|
||||
|
||||
def extract_diff_content(git_diff_output):
|
||||
# 定义正则表达式,匹配从 'diff --git' 开始到 'index' 之前的文本
|
||||
pattern = re.compile(r'diff --git(.+?)(?=\nindex|$)', re.DOTALL)
|
||||
# 使用正则表达式查找所有匹配项
|
||||
matches = pattern.findall(git_diff_output)
|
||||
# 存储截取的内容
|
||||
extracted_contents = []
|
||||
# 遍历所有匹配项
|
||||
for match in matches:
|
||||
# 去除每个匹配项中的空白行,并添加到结果列表
|
||||
cleaned_match = '\n'.join(line for line in match.strip().split('\n') if line)
|
||||
extracted_contents.append(cleaned_match)
|
||||
|
||||
return extracted_contents
|
||||
|
||||
def extract_changes_since_last_diff(diff_output):
|
||||
# 定义正则表达式,匹配 '+++ b' 后面的内容,直到下一个 'diff' 或文本末尾
|
||||
pattern = re.compile(r'\+\+\+ b/(.+?)(?=\ndiff --git|$)', re.DOTALL)
|
||||
|
||||
# 使用正则表达式查找所有匹配项
|
||||
matches = pattern.findall(diff_output)
|
||||
|
||||
# 处理匹配结果,每项匹配结果是一个元组,包含从 '+++ b/' 到下一个 'diff' 或文本末尾的内容
|
||||
extracted_content = []
|
||||
for match in matches:
|
||||
# 去除匹配内容中的 '\ No newline at end of file' 行
|
||||
content = '\n'.join([line for line in match.strip().split('\n') if line and line != '\\ No newline at end of file'])
|
||||
extracted_content.append(content)
|
||||
|
||||
return extracted_content
|
||||
|
||||
|
||||
def log_last_commit(repo_path):
|
||||
try:
|
||||
# 使用 git show 获取最后一次提交的详细信息
|
||||
# 格式选项包括:%H (提交哈希), %an (作者名字), %ae (作者邮箱), %s (提交信息)
|
||||
result = subprocess.run(
|
||||
["git", "show"],
|
||||
cwd=repo_path,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
encoding='utf-8'
|
||||
)
|
||||
return result.stdout.strip()
|
||||
except subprocess.CalledProcessError as e:
|
||||
print("Failed to show last commit:", e)
|
||||
return None
|
||||
|
||||
def shell(cmd, dire: str, log_name: str, user: str):
|
||||
log = f'Execute cmd: ' + cmd
|
||||
|
|
@ -98,6 +159,80 @@ def inter_to_outer(repo, branch, log_name: str, user: str, force_flag):
|
|||
# 将本地仓库的inter_name分支推送到external仓库的outer_name分支上。
|
||||
if force_flag:
|
||||
shell(f"git push --force external {inter_name}:{outer_name}", repo_dir, log_name, user)
|
||||
|
||||
diff_result = shell(f"git diff --name-status HEAD~1 HEAD", repo_dir, log_name, user)
|
||||
added = []
|
||||
modefied = []
|
||||
deleted = []
|
||||
for line in diff_result.stdout.split('\n'):
|
||||
if line:
|
||||
status, filename = line.split('\t')
|
||||
if status == 'A': # 新加的文件
|
||||
added.append(filename)
|
||||
elif status == 'M': # 修改的文件
|
||||
modefied.append(filename)
|
||||
elif status == 'D': # 删除的文件
|
||||
deleted.append(filename)
|
||||
git_show_output = log_last_commit("/tmp/sync_dir/reposyncer1.0")
|
||||
commit_hash, author, date = parse_git_output(git_show_output)
|
||||
commit_hash_str = str(commit_hash)
|
||||
author_str = str(author)
|
||||
date_str = str(date)
|
||||
base_information = '\n' + '基本信息:'+ '\n' + "Commit Hash:" + commit_hash_str + '\n' + "Author:" + author_str + '\n' + "Date:" + date_str + '\n'
|
||||
|
||||
extracted_contents = extract_diff_content(git_show_output)
|
||||
# 提取 '+++ b' 后面的内容
|
||||
changes_since_last_diff = extract_changes_since_last_diff(git_show_output)
|
||||
|
||||
detail_information = '详细信息:' + '\n' + 'DELETE_FILES:' + str(deleted) + '\n';
|
||||
|
||||
# print('DELETE_FILES:', deleted)
|
||||
# print("\n--- End of Extracted Content ---\n")
|
||||
# 打印提取的内容
|
||||
for content in extracted_contents:
|
||||
if 'new file' in content:
|
||||
pattern = re.compile(r' b/(.+?)(?=\nnew|$)', re.DOTALL)
|
||||
# 使用正则表达式查找所有匹配项
|
||||
matches = pattern.findall(content)
|
||||
# 存储截取的内容
|
||||
add_files = []
|
||||
# 遍历所有匹配项
|
||||
for match in matches:
|
||||
# 去除每个匹配项中的空白行,并添加到结果列表
|
||||
cleaned_match = '\n'.join(line for line in match.strip().split('\n') if line)
|
||||
add_files.append(cleaned_match)
|
||||
|
||||
# print('ADD_FILES:', add_files)
|
||||
|
||||
detail_information += 'ADD_FILES:' + str(added) + '\n'
|
||||
|
||||
for add_file in added:
|
||||
for change in changes_since_last_diff:
|
||||
if add_file in change:
|
||||
# print("\n" + change)
|
||||
detail_information += change
|
||||
# print("\n--- End of Extracted Content ---\n")
|
||||
detail_information += "\n--- End of Extracted Content ---\n"
|
||||
else:
|
||||
pattern = re.compile(r'a/(.+?)(?=b|$)', re.DOTALL)
|
||||
# 使用正则表达式查找所有匹配项
|
||||
matches = pattern.findall(content)
|
||||
# 存储截取的内容
|
||||
modified_files = []
|
||||
# 遍历所有匹配项
|
||||
for match in matches:
|
||||
# 去除每个匹配项中的空白行,并添加到结果列表
|
||||
cleaned_match = '\n'.join(line for line in match.strip().split('\n') if line)
|
||||
modified_files.append(cleaned_match)
|
||||
print('MODIFIED_FILES:', modefied)
|
||||
detail_information += 'MODIFIED_FILES:' + str(modefied) + '\n'
|
||||
|
||||
for modified_file in modefied:
|
||||
for change in changes_since_last_diff:
|
||||
if modified_file in change:
|
||||
detail_information += change
|
||||
detail_information += "\n--- End of Extracted Content ---\n"
|
||||
all_information = base_information + detail_information
|
||||
else:
|
||||
shell(f"git push external {inter_name}:{outer_name}", repo_dir, log_name, user)
|
||||
# commit id
|
||||
|
|
@ -106,6 +241,7 @@ def inter_to_outer(repo, branch, log_name: str, user: str, force_flag):
|
|||
result = shell(f'git log -1 --format="%H"', repo_dir, log_name, user)
|
||||
commit_id = result.stdout[0:7]
|
||||
sync_log(LogType.INFO, f'[COMMIT ID: {commit_id}]', log_name, user)
|
||||
sync_log(LogType.INFO, all_information, log_name, user)
|
||||
return commit_id
|
||||
except Exception as e:
|
||||
raise
|
||||
|
|
@ -136,10 +272,34 @@ def outer_to_inter(repo, branch, log_name: str, user: str, force_flag):
|
|||
raise
|
||||
|
||||
|
||||
|
||||
async def sync_issue_task(repo, user, sync_direct):
|
||||
if sync_direct == 1:
|
||||
issue_gitee_to_gitlink.main()
|
||||
if sync_direct == 2:
|
||||
issue_gitlink_to_gitee.main()
|
||||
|
||||
async def sync_pr_task(repo,user,sync_direct):
|
||||
if sync_direct ==1:
|
||||
pr_gitee_to_gitlink.prework()
|
||||
try:
|
||||
await sync_repo_task(repo, user, True)
|
||||
except GITMSGException as GITError:
|
||||
return SYNCResponse(
|
||||
code_status=GITError.status,
|
||||
msg=GITError.msg
|
||||
)
|
||||
pr_gitee_to_gitlink.pushwork()
|
||||
|
||||
if sync_direct ==2:
|
||||
pr_gitlink_to_gitee.prework()
|
||||
await sync_repo_task(repo, user, True)
|
||||
pr_gitlink_to_gitee.push()
|
||||
|
||||
async def sync_repo_task(repo, user, force_flag):
|
||||
if repo.sync_granularity == SyncType.one:
|
||||
branches = await sync_branch_dao.sync_branch(repo_id=repo.id)
|
||||
await sync_branch_task(repo, branches, repo.sync_direction, user)
|
||||
await sync_branch_task(repo, branches, repo.sync_direction, user,force_flag)
|
||||
else:
|
||||
log_name = f'sync_{repo.repo_name}.log'
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -112,14 +112,14 @@ class SyncService(Service):
|
|||
if repo is None:
|
||||
return SYNCException(Status.REPO_NOTFOUND)
|
||||
update_fields = {}
|
||||
if dto.internal_repo_address is not None:
|
||||
if not base.check_addr(dto.internal_repo_address):
|
||||
return SYNCException(Status.REPO_ADDR_ILLEGAL)
|
||||
update_fields['internal_repo_address'] = dto.internal_repo_address
|
||||
if dto.external_repo_address is not None:
|
||||
if not base.check_addr(dto.external_repo_address):
|
||||
return SYNCException(Status.REPO_ADDR_ILLEGAL)
|
||||
update_fields['external_repo_address'] = dto.external_repo_address
|
||||
# if dto.internal_repo_address is not None:
|
||||
# if not base.check_addr(dto.internal_repo_address):
|
||||
# return SYNCException(Status.REPO_ADDR_ILLEGAL)
|
||||
update_fields['internal_repo_address'] = dto.internal_repo_address
|
||||
# if dto.external_repo_address is not None:
|
||||
# if not base.check_addr(dto.external_repo_address):
|
||||
# return SYNCException(Status.REPO_ADDR_ILLEGAL)
|
||||
update_fields['external_repo_address'] = dto.external_repo_address
|
||||
if dto.inter_token is not None:
|
||||
update_fields['inter_token'] = dto.inter_token
|
||||
if dto.exter_token is not None:
|
||||
|
|
|
|||
|
|
@ -47,7 +47,6 @@ def sync_log(log_type: str, msg: str, log_name: str, user="robot"):
|
|||
datefmt='%Y-%m-%d %H:%M:%S')
|
||||
formatter.converter = time_formatter
|
||||
file_handler.setFormatter(formatter)
|
||||
|
||||
# 创建一个logger
|
||||
logger = logging.getLogger('logger')
|
||||
logger.setLevel(logging.INFO)
|
||||
|
|
|
|||
Loading…
Reference in New Issue