forked from Lesin/reposync
54 lines
1.4 KiB
Python
54 lines
1.4 KiB
Python
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}")
|
||
|
||
|