reposync/delete_gitee_issues.py

53 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import urllib
import requests
import mysql.connector
def delete_gitee_issues(owner, repo, cursor):
cursor.execute('SELECT issue_id FROM gitee_issue')
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 = '62b7d0577a13b75ff066047426df30cb'
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:
issue_info = response.json()
# print(f'Issue created with ID: {issue_info["number"]}')
else:
print(f"更新issue状态失败状态码{response.status_code},错误信息:{response.text}")
print("成功删除gitee—issues")
# # 连接到MySQL数据库
# conn = mysql.connector.connect(
# host="localhost",
# user="root",
# password="251226X",
# database="reposyncer"
# )
# cursor = conn.cursor()
#
# owner = 'wyf0625'
# repo = 'ob-reposyncer-gitee'
# delete_gitee_issues(owner, repo, cursor)