Skip to content

Add an option to refresh the cache #720

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
19 changes: 15 additions & 4 deletions scripts/pkg_in_pipe/pkg_in_pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def find_commits(gh, repo, start_sha, end_sha) -> list[Commit]:
A commit older that the end_sha commit and added by a merge commit won't appear in this list.
"""
cache_key = f'commits-2-{start_sha}-{end_sha}'
if cache_key in CACHE:
if not args.re_cache and cache_key in CACHE:
return cast(list[Commit], CACHE[cache_key])
commits = []
if gh:
Expand All @@ -236,7 +236,7 @@ def find_pull_requests(gh, repo, start_sha, end_sha):
prs = set()
for commit in find_commits(gh, repo, start_sha, end_sha):
cache_key = f'commit-prs-3-{commit.sha}'
if cache_key in CACHE:
if not args.re_cache and cache_key in CACHE:
prs.update(cast(list[PullRequest], CACHE[cache_key]))
elif gh:
commit_prs = list(commit.get_pulls())
Expand All @@ -263,11 +263,21 @@ def find_pull_requests(gh, repo, start_sha, end_sha):
'--github-token', help="The token used to access the Github api", default=os.environ.get('GITHUB_TOKEN')
)
parser.add_argument('--cache', help="The cache path", default="/tmp/pkg_in_pipe.cache")
parser.add_argument(
'--tag', '-t', dest='tags', help="The koji tags to include in the report", action='append', default=[]
)
parser.add_argument(
'--package', '-p', dest='packages', help="The packages to include in the report", action='append', default=[]
)
parser.add_argument('--re-cache', help="Refresh the cache", action='store_true')
args = parser.parse_args()

CACHE = diskcache.Cache(args.cache)
RETENTION_TIME = 24 * 60 * 60 # 24 hours

DEFAULT_TAGS = [f'v{v}-{p}' for v in ['8.2', '8.3'] for p in ['incoming', 'ci', 'testing', 'candidates', 'lab']]
tags = args.tags or DEFAULT_TAGS

# load the issues from plane, so we can search for the plane card related to a build
try:
resp = requests.get(
Expand Down Expand Up @@ -299,7 +309,6 @@ def find_pull_requests(gh, repo, start_sha, end_sha):
print_plane_warning(out)
if not gh:
print_github_warning(out)
tags = [f'v{v}-{p}' for v in ['8.2', '8.3'] for p in ['incoming', 'ci', 'testing', 'candidates', 'lab']]
with io.StringIO() as temp_out:
try:
# open koji session
Expand All @@ -308,7 +317,9 @@ def find_pull_requests(gh, repo, start_sha, end_sha):
session.ssl_login(config['cert'], None, config['serverca'])
for tag in tags:
print_table_header(temp_out, tag)
for tagged in sorted(session.listTagged(tag), key=lambda build: int(build['build_id']), reverse=True):
taggeds = sorted(session.listTagged(tag), key=lambda build: int(build['build_id']), reverse=True)
taggeds = [t for t in taggeds if t['package_name'] in args.packages or args.packages == []]
for tagged in taggeds:
build = session.getBuild(tagged['build_id'])
prs: list[PullRequest] = []
maintained_by = None
Expand Down