Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Use private-repo enabled github token for annotations #29677

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion misc/python/materialize/cli/ci_annotate_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,10 @@ def annotate_logged_errors(
step_key: str = os.getenv("BUILDKITE_STEP_KEY", "")
buildkite_label: str = os.getenv("BUILDKITE_LABEL", "")

(known_issues, issues_with_invalid_regex) = get_known_issues_from_github()
token = os.getenv("GITHUB_CI_ISSUE_REFERENCE_CHECKER_TOKEN") or os.getenv(
"GITHUB_TOKEN"
)
(known_issues, issues_with_invalid_regex) = get_known_issues_from_github(token)
unknown_errors: list[ObservedBaseError] = []
unknown_errors.extend(issues_with_invalid_regex)

Expand Down
14 changes: 7 additions & 7 deletions misc/python/materialize/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ def to_markdown(self) -> str:
return f'<a href="{self.issue_url}">{self.issue_title} (#{self.issue_number})</a>: Invalid regex in ci-regexp: {self.regex_pattern}, ignoring'


def get_known_issues_from_github_page(page: int = 1) -> Any:
def get_known_issues_from_github_page(token: str | None, page: int = 1) -> Any:
headers = {
"Accept": "application/vnd.github+json",
"X-GitHub-Api-Version": "2022-11-28",
}
if token := os.getenv("GITHUB_TOKEN"):
if token:
headers["Authorization"] = f"Bearer {token}"

response = requests.get(
Expand All @@ -61,14 +61,14 @@ def get_known_issues_from_github_page(page: int = 1) -> Any:
return issues_json


def get_known_issues_from_github() -> (
tuple[list[KnownGitHubIssue], list[GitHubIssueWithInvalidRegexp]]
):
def get_known_issues_from_github(
token: str | None = os.getenv("GITHUB_TOKEN"),
) -> tuple[list[KnownGitHubIssue], list[GitHubIssueWithInvalidRegexp]]:
page = 1
issues_json = get_known_issues_from_github_page(page)
issues_json = get_known_issues_from_github_page(token, page)
while issues_json["total_count"] > len(issues_json["items"]):
page += 1
next_page_json = get_known_issues_from_github_page(page)
next_page_json = get_known_issues_from_github_page(token, page)
if not next_page_json["items"]:
break
issues_json["items"].extend(next_page_json["items"])
Expand Down
Loading