12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- from flask import Flask, request, jsonify
- from auth import login, get_csrf_token
- from milestone import update_milestone, get_milestone, append_item_to_identifier
- from utils import find_username_id, generate_evoluz_link, find_task_type
- app = Flask(__name__)
- EVOLUZ_URL = "http://192.168.1.33:5050/apps/team/detail?"
- @app.route('/webhook', methods=['POST'])
- def handle_webhook():
- try:
- payload = request.get_json()
- if not payload:
- return 'Invalid JSON payload', 400
- if 'pull_request' in payload:
- pr = payload.get('pull_request', {})
- pr_title = pr.get('title')
- pr_username = pr.get('user').get('username')
- pr_branch = pr.get('head_branch')
- pr_branch_data = find_task_type(pr_branch)
- pr_data = {
- 'title': pr_title,
- 'username': pr_username.capitalize(),
- 'branch': pr_branch,
- 'task_type': pr_branch_data.get("task_type"),
- 'user_id': find_username_id(pr_username),
- 'link_evoluz': generate_evoluz_link(find_username_id(pr_username), pr_branch_data.get("task_id"), EVOLUZ_URL)
- }
- if update_milestone(pr_data):
- print("Milestone updated successfully.")
- else:
- print("Failed to update milestone.")
- return jsonify({'status': 'success'}), 200
- except Exception as e:
- print(f"Error: {e}")
- return 'Internal server error', 500
- @app.route('/', methods=['GET'])
- def index():
- return "Webhook server is running."
- if __name__ == '__main__':
- if login():
- print("Initial login successful.")
- else:
- print("Initial login failed.")
- app.run(port=4001)
|