Skip to content

Commit

Permalink
Ignore test branches for auto-approval workflow (#1358)
Browse files Browse the repository at this point in the history
* Ignore test branches

* bump version

* Make the forked repo setup more robust

* more sleep

* use min instead of max
  • Loading branch information
cbartz authored May 3, 2024
1 parent 9ce0b74 commit 61492dd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/bot_pr_approval.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: Provide approval for bot PRs

on:
pull_request:
branches-ignore:
- '**test-branch/**'

jobs:
bot_pr_approval:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[tool.poetry]
name = "repo-policy-compliance"
version = "1.8.0"
version = "1.8.1"
description = "Checks GitHub repository settings for compliance with policy"
authors = ["Canonical IS DevOps <launchpad.net/~canonical-is-devops>"]
license = "Apache 2.0"
Expand Down
2 changes: 1 addition & 1 deletion rockcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

name: repo-policy-compliance
base: [email protected]
version: '1.8.0'
version: '1.8.1'
summary: Check the repository setup for policy compliance
description: |
Used to check whether a GitHub repository complies with expected policies.
Expand Down
37 changes: 24 additions & 13 deletions tests/app/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import os
from time import sleep
from typing import Iterator, cast
from typing import Any, Callable, Iterator, cast

import pytest
from github import Github
Expand Down Expand Up @@ -75,22 +75,33 @@ def fixture_forked_github_repository(
github_repository: Repository,
) -> Iterator[Repository]:
"""Create a fork for a GitHub repository."""
forked_repository = github_repository.create_fork()
forked_repository = _simple_retry(github_repository.create_fork)

# Wait for repo to be ready
for _ in range(10):
try:
sleep(10)
forked_repository.get_branches()
break
except GithubException:
pass
else:
assert False, "timed out whilst waiting for repository creation"
# Wait for repo to be ready. We assume its ready if we can get the default branch.
_simple_retry(forked_repository.get_branch, github_repository.default_branch)

yield forked_repository

forked_repository.delete()
_simple_retry(forked_repository.delete)


def _simple_retry(func: Callable[..., Any], *args: Any, **kwargs: Any) -> Any:
"""Retry a function 10 times before failing.
Args:
func: The function to retry.
args: The positional arguments to pass to the function.
kwargs: The keyword arguments to pass to the function.
Returns:
The result of the function.
"""
for i in range(10):
try:
return func(*args, **kwargs)
except GithubException:
sleep(min(10 + i * 10, 60))
assert False, f"timed out while waiting for func {func.__name__} to complete"


@pytest.fixture(name="github_branch")
Expand Down

0 comments on commit 61492dd

Please sign in to comment.