reposync/server.py

105 lines
5.0 KiB
Python

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)