Skip to content

Commit 4d5f215

Browse files
committed
work
1 parent d242e67 commit 4d5f215

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

firebase-dataconnect/ci/calculate_github_issue_for_commenting.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ def main() -> None:
3838
)
3939

4040
file_text = "" if github_issue is None else str(github_issue)
41-
logging.info("Writing '%s' to %s", file_text, args.output_file)
42-
args.output_file.write_text(file_text, encoding="utf8", errors="replace")
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")
4343

4444

4545
def calculate_github_issue(
@@ -120,7 +120,8 @@ def github_issue_from_pr_body(pr_body: str, issue_key: str) -> int | None:
120120

121121

122122
class ParsedArgs(typing.Protocol):
123-
output_file: pathlib.Path
123+
issue_output_file: pathlib.Path
124+
pr_output_file: pathlib.Path
124125
github_ref: str
125126
github_repository: str
126127
github_event_name: str
@@ -131,11 +132,17 @@ class ParsedArgs(typing.Protocol):
131132
def parse_args() -> ParsedArgs:
132133
arg_parser = argparse.ArgumentParser()
133134
arg_parser.add_argument(
134-
"--output-file",
135+
"--issue-output-file",
135136
required=True,
136137
help="The file to which to write the calculated issue number"
137138
"if no issue number was found, then an empty file will be written",
138139
)
140+
arg_parser.add_argument(
141+
"--pr-output-file",
142+
required=True,
143+
help="The file to which to write the calculated triggering PR number"
144+
"if no PR was found, then an empty file will be written",
145+
)
139146
arg_parser.add_argument(
140147
"--github-ref",
141148
required=True,
@@ -166,7 +173,8 @@ def parse_args() -> ParsedArgs:
166173
)
167174

168175
parse_result = arg_parser.parse_args()
169-
parse_result.output_file = pathlib.Path(parse_result.output_file)
176+
parse_result.issue_output_file = pathlib.Path(parse_result.issue_output_file)
177+
parse_result.pr_output_file = pathlib.Path(parse_result.pr_output_file)
170178
return typing.cast("ParsedArgs", parse_result)
171179

172180

firebase-dataconnect/ci/post_comment_for_job_results.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,20 @@ def main() -> None:
4949

5050

5151
def generate_message_lines(data: ParsedArgs) -> Iterable[str]:
52-
yield f"Result of workflows at {data.github_sha}:"
52+
pr_str = data.triggering_pr.strip()
53+
pr: int | None
54+
if len(pr) == 0:
55+
pr = None
56+
else:
57+
try:
58+
pr = int(pr)
59+
except ValueError:
60+
logging.warning("WARNING: unable to parse PR number as an int: %s", pr)
61+
pr = None
62+
63+
yield f"Posting from Pull Request {pr}: {data.github_repository_html_url}/pull/{pr}"
64+
65+
yield f"Result of workflow '{data.github_workflow}' at {data.github_sha}:"
5366

5467
for job_result in data.job_results:
5568
result_symbol = "✅" if job_result.result == "success" else "❌"
@@ -82,6 +95,7 @@ def post_issue_comment_gh_args(
8295
) -> Iterable[str]:
8396
yield "gh"
8497
yield "issue"
98+
8599
yield "comment"
86100
yield str(issue_number)
87101
yield "--body-file"
@@ -112,11 +126,13 @@ class ParsedArgs(typing.Protocol):
112126
job_results: Sequence[JobResult]
113127
github_issue: int
114128
github_repository: str
129+
github_workflow: str
115130
github_sha: str
116131
github_repository_html_url: str
117132
github_run_id: str
118133
github_run_number: str
119134
github_run_attempt: str
135+
triggering_pr: str
120136

121137

122138
class ParseError(Exception):
@@ -134,14 +150,25 @@ def parse_args() -> ParsedArgs:
134150
)
135151
arg_parser.add_argument(
136152
"--github-issue",
153+
type=int,
137154
required=True,
138155
help="The GitHub Issue number to which to post a comment",
139156
)
157+
arg_parser.add_argument(
158+
"--triggering-pr",
159+
required=True,
160+
help="The GitHub Pull Request number that triggered the workflow, or empty if not applicable.",
161+
)
140162
arg_parser.add_argument(
141163
"--github-repository",
142164
required=True,
143165
help="The value of ${{ github.repository }} in the workflow",
144166
)
167+
arg_parser.add_argument(
168+
"--github-workflow",
169+
required=True,
170+
help="The value of ${{ github.workflow }} in the workflow",
171+
)
145172
arg_parser.add_argument(
146173
"--github-sha",
147174
required=True,

0 commit comments

Comments
 (0)