Skip to content

Commit 63fdb92

Browse files
committed
dataconnect.yaml: use calculate_github_issue_for_commenting.py
1 parent 34f82ac commit 63fdb92

File tree

3 files changed

+33
-23
lines changed

3 files changed

+33
-23
lines changed

.github/workflows/dataconnect.yml

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -334,36 +334,36 @@ jobs:
334334
issues: write
335335
runs-on: ubuntu-latest
336336
steps:
337+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
338+
with:
339+
show-progress: false
340+
sparse-checkout: 'firebase-dataconnect/ci/'
341+
342+
- uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
343+
with:
344+
python-version: ${{ env.FDC_PYTHON_VERSION }}
345+
346+
- run: pip install -r firebase-dataconnect/ci/requirements.txt
347+
337348
- id: issue-id
338349
name: Determine GitHub Issue For Commenting
339350
env:
340351
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
352+
working-directory: firebase-dataconnect/ci
341353
run: |
342354
set -euo pipefail
343355
set -xv
344356
345-
# If this job was triggered by a pull request, then check to see if
346-
# the description of the PR specifies a GitHub Issue to which to post
347-
# a comment. The GitHub Issue number is specified by including a line
348-
# of the form "trksmnkncd_notification_issue=6863" in the description.
349-
# Specifying an issue number in this manner is primarily intended for
350-
# debugging/development purposes of the comment-posting logic itself.
351-
# For example, issue number 6863 was specifically created for testing.
352-
# (see https://github.com/firebase/firebase-android-sdk/issues/6863)
353-
pr_number=$(echo '${{ github.ref }}' | sed -En 's#^refs/pull/([0-9]+)/merge$#\1#p')
354-
if [[ -n $pr_number ]] ; then
355-
issue_from_pr_body=$(gh issue view "$pr_number" --json body --jq '.body' -R ${{ github.repository }} | sed -En 's#(\s|^)trksmnkncd_notification_issue=([0-9]+)(\s|$)#\2#p')
356-
fi
357-
358-
if [[ -v issue_from_pr_body ]] && [[ -n $issue_from_pr_body ]] ; then
359-
issue="$issue_from_pr_body"
360-
elif [[ '${{ github.event_name }}' == 'schedule' ]] ; then
361-
# See https://github.com/firebase/firebase-android-sdk/issues/6857
362-
issue=6857
363-
else
364-
issue=
365-
fi
357+
python \
358+
calculate_github_issue_for_commenting.py \
359+
--output-file=github_issue_number.txt \
360+
--github-ref='${{ github.ref }}' \
361+
--github-repository='${{ github.repository }}' \
362+
--github-event-name='${{ github.event_name }}' \
363+
--pr-body-github-issue-key=trksmnkncd_notification_issue \
364+
--github-issue-for-scheduled-run=6857 # https://github.com/firebase/firebase-android-sdk/issues/6857
366365
366+
issue="$(cat github_issue_number.txt)"
367367
echo "issue=$issue" >> "$GITHUB_OUTPUT"
368368
369369
- name: Post Comment on GitHub Issue

firebase-dataconnect/ci/calculate_github_issue_for_commenting.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import argparse
1818
import logging
19+
import pathlib
1920
import re
2021
import subprocess
2122
import typing
@@ -36,7 +37,9 @@ def main() -> None:
3637
pr_body_github_issue_key=args.pr_body_github_issue_key,
3738
)
3839

39-
logging.info(github_issue)
40+
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")
4043

4144

4245
def calculate_github_issue(
@@ -117,6 +120,7 @@ def github_issue_from_pr_body(pr_body: str, issue_key: str) -> int | None:
117120

118121

119122
class ParsedArgs(typing.Protocol):
123+
output_file: pathlib.Path
120124
github_ref: str
121125
github_repository: str
122126
github_event_name: str
@@ -126,6 +130,12 @@ class ParsedArgs(typing.Protocol):
126130

127131
def parse_args() -> ParsedArgs:
128132
arg_parser = argparse.ArgumentParser()
133+
arg_parser.add_argument(
134+
"--output-file",
135+
required=True,
136+
help="The file to which to write the calculated issue number"
137+
"if no issue number was found, then an empty file will be written",
138+
)
129139
arg_parser.add_argument(
130140
"--github-ref",
131141
required=True,
@@ -156,6 +166,7 @@ def parse_args() -> ParsedArgs:
156166
)
157167

158168
parse_result = arg_parser.parse_args()
169+
parse_result.output_file = pathlib.Path(parse_result.output_file)
159170
return typing.cast("ParsedArgs", parse_result)
160171

161172

firebase-dataconnect/ci/pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,3 @@ quote-style = "double"
4444
indent-style = "space"
4545
skip-magic-trailing-comma = false
4646
docstring-code-format = true
47-
SUCCESS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

0 commit comments

Comments
 (0)