
import hmac
import hashlib
import json

# Secret from .env
SECRET = "zheke@703"

# Signature from User's Log
EXPECTED_SIGNATURE = "ff8b3217cdfd039866410441b0513e6e87f298d7995d56c4ed899d0214afa08a"

# Payload from User's Log
payload_dict = {
  "action": "synchronized",
  "number": 7,
  "pull_request": {
    "id": 6,
    "url": "http://localhost:3333/vinland100/SpaceSim/pulls/7",
    "number": 7,
    "user": {
      "id": 3,
      "login": "ai-bot",
      "login_name": "",
      "full_name": "",
      "email": "ai-bot@noreply.localhost",
      "avatar_url": "http://localhost:3333/avatar/6049cd56dee263bd6fb35f9c27d7a0ee",
      "language": "",
      "is_admin": False,
      "last_login": "0001-01-01T00:00:00Z",
      "created": "2025-12-31T09:57:36+08:00",
      "restricted": False,
      "active": False,
      "prohibit_login": False,
      "location": "",
      "website": "",
      "description": "",
      "visibility": "public",
      "followers_count": 0,
      "following_count": 0,
      "starred_repos_count": 0,
      "username": "ai-bot"
    },
    "title": "ai-bot PR test 5",
    "body": "ai-bot PR test 5",
    "labels": [],
    "milestone": None,
    "assignee": None,
    "assignees": None,
    "requested_reviewers": None,
    "state": "open",
    "is_locked": False,
    "comments": 0,
    "html_url": "http://localhost:3333/vinland100/SpaceSim/pulls/7",
    "diff_url": "http://localhost:3333/vinland100/SpaceSim/pulls/7.diff",
    "patch_url": "http://localhost:3333/vinland100/SpaceSim/pulls/7.patch",
    "mergeable": False,
    "merged": False,
    "merged_at": None,
    "merge_commit_sha": None,
    "merged_by": None,
    "allow_maintainer_edit": False,
    "base": {
      "label": "main",
      "ref": "main",
      "sha": "e601c85c4d762772c9ff49a781964013bb4c6377",
      "repo_id": 1,
      "repo": {
        "id": 1,
        "owner": {
          "id": 1,
          "login": "vinland100",
          "login_name": "",
          "full_name": "",
          "email": "wuyanbo5210@qq.com",
          "avatar_url": "http://localhost:3333/avatar/9807be06d1f8d640f4c605f5edbb8cdb",
          "language": "",
          "is_admin": False,
          "last_login": "0001-01-01T00:00:00Z",
          "created": "2025-12-02T09:45:59+08:00",
          "restricted": False,
          "active": False,
          "prohibit_login": False,
          "location": "",
          "website": "",
          "description": "",
          "visibility": "public",
          "followers_count": 0,
          "following_count": 0,
          "starred_repos_count": 0,
          "username": "vinland100"
        },
        "name": "SpaceSim",
        "full_name": "vinland100/SpaceSim",
        "description": "",
        "empty": False,
        "private": False,
        "fork": False,
        "template": False,
        "parent": None,
        "mirror": False,
        "size": 86,
        "language": "",
        "languages_url": "http://localhost:3333/api/v1/repos/vinland100/SpaceSim/languages",
        "html_url": "http://localhost:3333/vinland100/SpaceSim",
        "url": "http://localhost:3333/api/v1/repos/vinland100/SpaceSim",
        "link": "",
        "ssh_url": "git@localhost:vinland100/SpaceSim.git",
        "clone_url": "http://localhost:3333/vinland100/SpaceSim.git",
        "original_url": "",
        "website": "",
        "stars_count": 0,
        "forks_count": 2,
        "watchers_count": 1,
        "open_issues_count": 2,
        "open_pr_counter": 2,
        "release_counter": 0,
        "default_branch": "main",
        "archived": False,
        "created_at": "2025-12-02T09:50:22+08:00",
        "updated_at": "2025-12-31T16:05:18+08:00",
        "archived_at": "1970-01-01T08:00:00+08:00",
        "permissions": {
          "admin": False,
          "push": False,
          "pull": True
        },
        "has_issues": True,
        "internal_tracker": {
          "enable_time_tracker": True,
          "allow_only_contributors_to_track_time": True,
          "enable_issue_dependencies": True
        },
        "has_wiki": True,
        "has_pull_requests": True,
        "has_projects": True,
        "has_releases": True,
        "has_packages": True,
        "has_actions": False,
        "ignore_whitespace_conflicts": False,
        "allow_merge_commits": True,
        "allow_rebase": True,
        "allow_rebase_explicit": True,
        "allow_squash_merge": True,
        "allow_rebase_update": True,
        "default_delete_branch_after_merge": False,
        "default_merge_style": "merge",
        "default_allow_maintainer_edit": False,
        "avatar_url": "",
        "internal": False,
        "mirror_interval": "",
        "mirror_updated": "0001-01-01T00:00:00Z",
        "repo_transfer": None
      }
    },
    "head": {
      "label": "ai-bot-PR-test-5",
      "ref": "ai-bot-PR-test-5",
      "sha": "95ecf0e8a1262406c6c3bd5a36519f5e6813b00e",
      "repo_id": 8,
      "repo": {
        "id": 8,
        "owner": {
          "id": 3,
          "login": "ai-bot",
          "login_name": "",
          "full_name": "",
          "email": "1942664940@qq.com",
          "avatar_url": "http://localhost:3333/avatar/6049cd56dee263bd6fb35f9c27d7a0ee",
          "language": "",
          "is_admin": False,
          "last_login": "0001-01-01T00:00:00Z",
          "created": "2025-12-31T09:57:36+08:00",
          "restricted": False,
          "active": False,
          "prohibit_login": False,
          "location": "",
          "website": "",
          "description": "",
          "visibility": "public",
          "followers_count": 0,
          "following_count": 0,
          "starred_repos_count": 0,
          "username": "ai-bot"
        },
        "name": "SpaceSim",
        "full_name": "ai-bot/SpaceSim",
        "description": "",
        "empty": False,
        "private": False,
        "fork": True,
        "template": False,
        "parent": {
          "id": 1,
          "owner": {
            "id": 1,
            "login": "vinland100",
            "login_name": "",
            "full_name": "",
            "email": "wuyanbo5210@qq.com",
            "avatar_url": "http://localhost:3333/avatar/9807be06d1f8d640f4c605f5edbb8cdb",
            "language": "",
            "is_admin": False,
            "last_login": "0001-01-01T00:00:00Z",
            "created": "2025-12-02T09:45:59+08:00",
            "restricted": False,
            "active": False,
            "prohibit_login": False,
            "location": "",
            "website": "",
            "description": "",
            "visibility": "public",
            "followers_count": 0,
            "following_count": 0,
            "starred_repos_count": 0,
            "username": "vinland100"
          },
          "name": "SpaceSim",
          "full_name": "vinland100/SpaceSim",
          "description": "",
          "empty": False,
          "private": False,
          "fork": False,
          "template": False,
          "parent": None,
          "mirror": False,
          "size": 86,
          "language": "",
          "languages_url": "http://localhost:3333/api/v1/repos/vinland100/SpaceSim/languages",
          "html_url": "http://localhost:3333/vinland100/SpaceSim",
          "url": "http://localhost:3333/api/v1/repos/vinland100/SpaceSim",
          "link": "",
          "ssh_url": "git@localhost:vinland100/SpaceSim.git",
          "clone_url": "http://localhost:3333/vinland100/SpaceSim.git",
          "original_url": "",
          "website": "",
          "stars_count": 0,
          "forks_count": 2,
          "watchers_count": 1,
          "open_issues_count": 2,
          "open_pr_counter": 2,
          "release_counter": 0,
          "default_branch": "main",
          "archived": False,
          "created_at": "2025-12-02T09:50:22+08:00",
          "updated_at": "2025-12-31T16:05:18+08:00",
          "archived_at": "1970-01-01T08:00:00+08:00",
          "permissions": {
            "admin": False,
            "push": False,
            "pull": True
          },
          "has_issues": True,
          "internal_tracker": {
            "enable_time_tracker": True,
            "allow_only_contributors_to_track_time": True,
            "enable_issue_dependencies": True
          },
          "has_wiki": True,
          "has_pull_requests": True,
          "has_projects": True,
          "has_releases": True,
          "has_packages": True,
          "has_actions": False,
          "ignore_whitespace_conflicts": False,
          "allow_merge_commits": True,
          "allow_rebase": True,
          "allow_rebase_explicit": True,
          "allow_squash_merge": True,
          "allow_rebase_update": True,
          "default_delete_branch_after_merge": False,
          "default_merge_style": "merge",
          "default_allow_maintainer_edit": False,
          "avatar_url": "",
          "internal": False,
          "mirror_interval": "",
          "mirror_updated": "0001-01-01T00:00:00Z",
          "repo_transfer": None
        },
        "mirror": False,
        "size": 88,
        "language": "",
        "languages_url": "http://localhost:3333/api/v1/repos/ai-bot/SpaceSim/languages",
        "html_url": "http://localhost:3333/ai-bot/SpaceSim",
        "url": "http://localhost:3333/api/v1/repos/ai-bot/SpaceSim",
        "link": "",
        "ssh_url": "git@localhost:ai-bot/SpaceSim.git",
        "clone_url": "http://localhost:3333/ai-bot/SpaceSim.git",
        "original_url": "",
        "website": "",
        "stars_count": 0,
        "forks_count": 0,
        "watchers_count": 1,
        "open_issues_count": 0,
        "open_pr_counter": 0,
        "release_counter": 0,
        "default_branch": "main",
        "archived": False,
        "created_at": "2025-12-31T10:02:40+08:00",
        "updated_at": "2025-12-31T16:07:21+08:00",
        "archived_at": "1970-01-01T08:00:00+08:00",
        "permissions": {
          "admin": False,
          "push": False,
          "pull": True
        },
        "has_issues": False,
        "has_wiki": False,
        "has_pull_requests": True,
        "has_projects": False,
        "has_releases": False,
        "has_packages": False,
        "has_actions": False,
        "ignore_whitespace_conflicts": False,
        "allow_merge_commits": True,
        "allow_rebase": True,
        "allow_rebase_explicit": True,
        "allow_squash_merge": True,
        "allow_rebase_update": True,
        "default_delete_branch_after_merge": False,
        "default_merge_style": "merge",
        "default_allow_maintainer_edit": False,
        "avatar_url": "",
        "internal": False,
        "mirror_interval": "",
        "mirror_updated": "0001-01-01T00:00:00Z",
        "repo_transfer": None
      }
    },
    "merge_base": "cc82211696bdf4e5d6e32809403f388fd708fcae",
    "due_date": None,
    "created_at": "2025-12-31T16:08:27+08:00",
    "updated_at": "2025-12-31T16:10:05+08:00",
    "closed_at": None,
    "pin_order": 0
  },
  "requested_reviewer": None,
  "repository": {
    "id": 1,
    "owner": {
      "id": 1,
      "login": "vinland100",
      "login_name": "",
      "full_name": "",
      "email": "wuyanbo5210@qq.com",
      "avatar_url": "http://localhost:3333/avatar/9807be06d1f8d640f4c605f5edbb8cdb",
      "language": "",
      "is_admin": False,
      "last_login": "0001-01-01T00:00:00Z",
      "created": "2025-12-02T09:45:59+08:00",
      "restricted": False,
      "active": False,
      "prohibit_login": False,
      "location": "",
      "website": "",
      "description": "",
      "visibility": "public",
      "followers_count": 0,
      "following_count": 0,
      "starred_repos_count": 0,
      "username": "vinland100"
    },
    "name": "SpaceSim",
    "full_name": "vinland100/SpaceSim",
    "description": "",
    "empty": False,
    "private": False,
    "fork": False,
    "template": False,
    "parent": None,
    "mirror": False,
    "size": 86,
    "language": "",
    "languages_url": "http://localhost:3333/api/v1/repos/vinland100/SpaceSim/languages",
    "html_url": "http://localhost:3333/vinland100/SpaceSim",
    "url": "http://localhost:3333/api/v1/repos/vinland100/SpaceSim",
    "link": "",
    "ssh_url": "git@localhost:vinland100/SpaceSim.git",
    "clone_url": "http://localhost:3333/vinland100/SpaceSim.git",
    "original_url": "",
    "website": "",
    "stars_count": 0,
    "forks_count": 2,
    "watchers_count": 1,
    "open_issues_count": 2,
    "open_pr_counter": 2,
    "release_counter": 0,
    "default_branch": "main",
    "archived": False,
    "created_at": "2025-12-02T09:50:22+08:00",
    "updated_at": "2025-12-31T16:05:18+08:00",
    "archived_at": "1970-01-01T08:00:00+08:00",
    "permissions": {
      "admin": True,
      "push": True,
      "pull": True
    },
    "has_issues": True,
    "internal_tracker": {
      "enable_time_tracker": True,
      "allow_only_contributors_to_track_time": True,
      "enable_issue_dependencies": True
    },
    "has_wiki": True,
    "has_pull_requests": True,
    "has_projects": True,
    "has_releases": True,
    "has_packages": True,
    "has_actions": False,
    "ignore_whitespace_conflicts": False,
    "allow_merge_commits": True,
    "allow_rebase": True,
    "allow_rebase_explicit": True,
    "allow_squash_merge": True,
    "allow_rebase_update": True,
    "default_delete_branch_after_merge": False,
    "default_merge_style": "merge",
    "default_allow_maintainer_edit": False,
    "avatar_url": "",
    "internal": False,
    "mirror_interval": "",
    "mirror_updated": "0001-01-01T00:00:00Z",
    "repo_transfer": None
  },
  "sender": {
    "id": 3,
    "login": "ai-bot",
    "login_name": "",
    "full_name": "",
    "email": "ai-bot@noreply.localhost",
    "avatar_url": "http://localhost:3333/avatar/6049cd56dee263bd6fb35f9c27d7a0ee",
    "language": "",
    "is_admin": False,
    "last_login": "0001-01-01T00:00:00Z",
    "created": "2025-12-31T09:57:36+08:00",
    "restricted": False,
    "active": False,
    "prohibit_login": False,
    "location": "",
    "website": "",
    "description": "",
    "visibility": "public",
    "followers_count": 0,
    "following_count": 0,
    "starred_repos_count": 0,
    "username": "ai-bot"
  },
  "commit_id": "",
  "review": None
}

# Serialize and sign
json_payload = json.dumps(payload_dict).encode('utf-8')
calculated_signature = hmac.new(
    key=SECRET.encode(),
    msg=json_payload,
    digestmod=hashlib.sha256
).hexdigest()

print(f"Expected: {EXPECTED_SIGNATURE}")
print(f"Calculated: {calculated_signature}")
print(f"Match: {EXPECTED_SIGNATURE == calculated_signature}")
