|
8 | 8 | LOGGER = LoggerSetup.get_logger("gardenlinux.github.release", logging.INFO) |
9 | 9 |
|
10 | 10 |
|
11 | | -def create_github_release( |
12 | | - owner: str, repo: str, tag: str, commitish: str, latest: bool, body: str |
13 | | -) -> int | None: |
14 | | - token = os.environ.get("GITHUB_TOKEN") |
15 | | - if not token: |
16 | | - raise ValueError("GITHUB_TOKEN environment variable not set") |
17 | | - |
18 | | - headers = { |
19 | | - "Authorization": f"token {token}", |
20 | | - "Accept": "application/vnd.github.v3+json", |
21 | | - } |
22 | | - |
23 | | - data = { |
24 | | - "tag_name": tag, |
25 | | - "target_commitish": commitish, |
26 | | - "name": tag, |
27 | | - "body": body, |
28 | | - "draft": False, |
29 | | - "prerelease": False, |
30 | | - "make_latest": "true" if latest else "false", |
31 | | - } |
32 | | - |
33 | | - response = requests.post( |
34 | | - f"https://api.github.com/repos/{owner}/{repo}/releases", |
35 | | - headers=headers, |
36 | | - data=json.dumps(data), |
37 | | - timeout=REQUESTS_TIMEOUTS, |
38 | | - ) |
39 | | - |
40 | | - if response.status_code == 201: |
41 | | - LOGGER.info("Release created successfully") |
42 | | - response_json = response.json() |
43 | | - return int(response_json.get("id")) # Will raise KeyError if missing |
44 | | - else: |
45 | | - LOGGER.error("Failed to create release") |
46 | | - LOGGER.debug(response.json()) |
47 | | - response.raise_for_status() |
48 | | - |
49 | | - return None # Simply to make mypy happy. should not be reached. |
50 | | - |
51 | | - |
52 | 11 | def write_to_release_id_file(release_id: str | int) -> None: |
53 | 12 | try: |
54 | 13 | with open(RELEASE_ID_FILE, "w") as file: |
|
0 commit comments