Skip to content

Commit

Permalink
Merge main into v2
Browse files Browse the repository at this point in the history
  • Loading branch information
greenbonebot committed Jul 7, 2023
2 parents aec76f3 + 4536c4b commit a2658b6
Showing 1 changed file with 39 additions and 13 deletions.
52 changes: 39 additions & 13 deletions conventional-commits/action/commits.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
import os
import sys
from argparse import ArgumentParser, Namespace
from json import JSONDecodeError
from pathlib import Path
from typing import NoReturn, Optional

import httpx
from pontos.changelog.conventional_commits import ConventionalCommits
from pontos.github.actions import Console, GitHubEvent
from pontos.github.api import GitHubAsyncRESTApi
Expand Down Expand Up @@ -71,6 +73,9 @@ def __init__(
event = GitHubEvent(event_path)
self.pull_request = event.pull_request.number

if os.environ.get("RUNNER_DEBUG") == "1":
Console.debug(event)

async def run(self) -> int:
os.chdir(self.working_directory)

Expand Down Expand Up @@ -119,18 +124,39 @@ async def run(self) -> int:
):
cc_report_comment = comment.id

if cc_report_comment is None:
await api.pull_requests.add_comment(
self.repository,
self.pull_request,
"\n".join(comment_lines),
)
else:
await api.pull_requests.update_comment(
self.repository,
cc_report_comment,
"\n".join(comment_lines),
)
try:
if cc_report_comment is None:
await api.pull_requests.add_comment(
self.repository,
self.pull_request,
"\n".join(comment_lines),
)
else:
await api.pull_requests.update_comment(
self.repository,
cc_report_comment,
"\n".join(comment_lines),
)
except httpx.HTTPStatusError as e:
try:
json = e.response.json()
message = json.get("message")
except JSONDecodeError:
message = None

if message:
raise CommitsError(
"Could not create Pull Request comment. A HTTP "
f"{e.response.status_code} error occurred while doing "
f"a {e.request.method} request to {e.request.url}. "
f"Error was {message}"
) from e
else:
raise CommitsError(
"Could not create Pull Request comment. A HTTP "
f"{e.response.status_code} error occurred while doing a "
f"{e.request.method} request to {e.request.url}."
) from e

return 0 if has_cc else 1

Expand All @@ -151,7 +177,7 @@ def main() -> NoReturn:
)
sys.exit(0)
except CommitsError as e:
Console.error(f"{e} ❌.")
Console.error(f"{e}")
sys.exit(1)


Expand Down

0 comments on commit a2658b6

Please sign in to comment.