forked from Lesin/reposync
70 lines
2.8 KiB
Python
70 lines
2.8 KiB
Python
import json
|
|
import mysql.connector
|
|
import requests
|
|
import Token
|
|
|
|
|
|
def get_issues_detail(owner, repo, token, conn, cursor):
|
|
url = f"https://gitlink.org.cn/api/v1/{owner}/{repo}/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': f'Bearer {token}',
|
|
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
|
|
}
|
|
response = requests.request("GET", url, headers=headers, data=payload)
|
|
# print(response.text)
|
|
data = json.loads(response.text)
|
|
cursor.execute('DROP TABLE IF EXISTS gitlink_issue')
|
|
# 创建一个表
|
|
cursor.execute('''CREATE TABLE IF NOT EXISTS gitlink_issue
|
|
(id INT AUTO_INCREMENT PRIMARY KEY, issue_id VARCHAR(10), subject VARCHAR(100), description VARCHAR(1000), branch_name VARCHAR(15), start_date VARCHAR(100), due_date VARCHAR(100), priority_id INT,project_issues_index INT, status_id INT)''')
|
|
|
|
conn.commit()
|
|
for issue in data["issues"]:
|
|
issue_id = issue["id"]
|
|
|
|
# 打印每个issue的信息
|
|
url = f"https://gitlink.org.cn/api/v1/{owner}/{repo}/issues/{issue_id}.json"
|
|
|
|
headers = {
|
|
'Authorization': f'Bearer {token}',
|
|
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
|
|
}
|
|
|
|
response = requests.request("GET", url, headers=headers, data=payload)
|
|
|
|
# print(response.text)
|
|
issue_data = json.loads(response.text)
|
|
issue_id = issue_data["id"]#标识id
|
|
subject = issue_data["subject"]#标题
|
|
description = issue_data["description"]#内容
|
|
branch_name = issue_data["branch_name"]#分支名
|
|
start_date = issue_data["start_date"]#开始日期
|
|
due_date = issue_data["due_date"]#完成日期
|
|
priority_id = issue_data["priority"]["id"]#优先级 1低 2正常 3高 4紧急
|
|
project_issues_index = issue_data["project_issues_index"] # 顺序位置
|
|
status_id = issue_data["status"]["id"] #完成状态 1新增 2正在解决 3已解决 5关闭 6拒绝
|
|
cursor.execute(
|
|
"INSERT INTO gitlink_issue (issue_id,subject,description,branch_name,start_date,due_date,priority_id,project_issues_index,status_id) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s)",
|
|
(issue_id, subject, description, branch_name, start_date, due_date, priority_id, project_issues_index,
|
|
status_id))
|
|
conn.commit()
|
|
print("获取gitlink—issues成功")
|
|
|
|
# # 连接到数据库
|
|
# conn = mysql.connector.connect(
|
|
# host="localhost",
|
|
# user="root",
|
|
# password="251226X",
|
|
# database="reposyncer"
|
|
# )
|
|
# cursor = conn.cursor()
|
|
#
|
|
#
|
|
# owner= 'wuyifan'
|
|
# repo = 'wuyifan-ob-reposyncer'
|
|
# token = Token.getToken()
|
|
# get_issues_detail(owner, repo, token, conn, cursor)
|
|
#
|
|
|