File: trigger_action.py

package info (click to toggle)
python-coverage 7.6.0%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 4,120 kB
  • sloc: python: 30,196; ansic: 1,181; javascript: 773; makefile: 293; sh: 107; xml: 48
file content (29 lines) | stat: -rw-r--r-- 770 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
# For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt

"""Trigger a repository_dispatch GitHub action."""

import sys

from session import get_session

repo_owner, event_type = sys.argv[1:]

# The GitHub URL makes no mention of which workflow to use. It's found based on
# the event_type, which matches the types in the workflow:
#
#   on:
#     repository_dispatch:
#       types:
#         - build-kits
#

url = f"https://api.github.com/repos/{repo_owner}/dispatches"
data = {"event_type": event_type}

resp = get_session().post(url, json=data)
if resp.status_code // 100 == 2:
    print("Success")
else:
    print(f"Status: {resp.status_code}")
    print(resp.text)