Skip to content

Commit 5211fdf

Browse files
committed
add pr info
1 parent 4d5f215 commit 5211fdf

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

firebase-dataconnect/ci/calculate_github_issue_for_commenting.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from __future__ import annotations
1616

1717
import argparse
18+
import dataclasses
1819
import logging
1920
import pathlib
2021
import re
@@ -29,17 +30,30 @@ def main() -> None:
2930
args = parse_args()
3031
logging.basicConfig(format="%(message)s", level=logging.INFO)
3132

32-
github_issue = calculate_github_issue(
33+
calculated_result = calculate_github_issue(
3334
github_event_name=args.github_event_name,
3435
github_issue_for_scheduled_run=args.github_issue_for_scheduled_run,
3536
github_ref=args.github_ref,
3637
github_repository=args.github_repository,
3738
pr_body_github_issue_key=args.pr_body_github_issue_key,
3839
)
3940

40-
file_text = "" if github_issue is None else str(github_issue)
41-
logging.info("Writing '%s' to %s", file_text, args.issue_output_file)
42-
args.issue_output_file.write_text(file_text, encoding="utf8", errors="replace")
41+
github_issue = calculated_result.issue
42+
github_pr = calculated_result.pr
43+
44+
issue_file_text = "" if github_issue is None else str(github_issue)
45+
logging.info("Writing '%s' to %s", issue_file_text, args.issue_output_file)
46+
args.issue_output_file.write_text(issue_file_text, encoding="utf8", errors="replace")
47+
48+
pr_file_text = "" if github_pr is None else str(github_pr)
49+
logging.info("Writing '%s' to %s", pr_file_text, args.pr_output_file)
50+
args.pr_output_file.write_text(pr_file_text, encoding="utf8", errors="replace")
51+
52+
53+
@dataclasses.dataclass(frozen=True)
54+
class CalculatedGitHubIssue:
55+
issue: int | None
56+
pr: int | None
4357

4458

4559
def calculate_github_issue(
@@ -48,21 +62,24 @@ def calculate_github_issue(
4862
github_ref: str,
4963
github_repository: str,
5064
pr_body_github_issue_key: str,
51-
) -> int | None:
65+
) -> CalculatedGitHubIssue:
5266
if github_event_name == "schedule":
5367
logging.info(
5468
"GitHub Event name is: %s; using GitHub Issue: %s",
5569
github_event_name,
5670
github_issue_for_scheduled_run,
5771
)
58-
return github_issue_for_scheduled_run
72+
return CalculatedGitHubIssue(
73+
issue=github_issue_for_scheduled_run,
74+
pr=None, # scheduled runs are, by definition, not associated with a PR.
75+
)
5976

6077
logging.info("Extracting PR number from string: %s", github_ref)
61-
pr_number: int | None = pr_number_from_github_ref(github_ref)
62-
78+
pr_number = pr_number_from_github_ref(github_ref)
6379
if pr_number is None:
6480
logging.info("No PR number extracted")
65-
return None
81+
return CalculatedGitHubIssue(None, None)
82+
typing.assert_type(pr_number, int)
6683

6784
logging.info("PR number extracted: %s", pr_number)
6885
logging.info("Loading body text of PR: %s", pr_number)
@@ -79,10 +96,11 @@ def calculate_github_issue(
7996

8097
if github_issue is None:
8198
logging.info("No GitHub Issue key found in PR body")
82-
return None
99+
return CalculatedGitHubIssue(issue=None, pr=pr_number)
100+
typing.assert_type(github_issue, int)
83101

84102
logging.info("Found GitHub Issue key in PR body: %s", github_issue)
85-
return github_issue
103+
return CalculatedGitHubIssue(issue=github_issue, pr=pr_number)
86104

87105

88106
def pr_number_from_github_ref(github_ref: str) -> int | None:

firebase-dataconnect/ci/post_comment_for_job_results.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,14 @@ def main() -> None:
4949

5050

5151
def generate_message_lines(data: ParsedArgs) -> Iterable[str]:
52-
pr_str = data.triggering_pr.strip()
5352
pr: int | None
54-
if len(pr) == 0:
53+
if len(data.triggering_pr) == 0:
5554
pr = None
5655
else:
5756
try:
58-
pr = int(pr)
57+
pr = int(data.triggering_pr)
5958
except ValueError:
60-
logging.warning("WARNING: unable to parse PR number as an int: %s", pr)
59+
logging.warning("WARNING: unable to parse PR number as an int: %s", data.triggering_pr)
6160
pr = None
6261

6362
yield f"Posting from Pull Request {pr}: {data.github_repository_html_url}/pull/{pr}"

0 commit comments

Comments
 (0)