Skip to content

Commit aeea58f

Browse files
Update protected publish to use github refs instead of gitlab
1 parent 036c7e5 commit aeea58f

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

images/protected-publish/pkg/publish.py

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@
77

88
from collections import defaultdict
99
from concurrent.futures import as_completed, ThreadPoolExecutor
10-
from datetime import datetime, timedelta
10+
from datetime import datetime, timezone, timedelta
1111
from typing import Callable, Dict, List, Optional
1212

1313
import botocore.exceptions
1414

15-
import gitlab
15+
import github
1616
import requests
17-
import sentry_sdk
17+
try:
18+
import sentry_sdk
19+
sentry_sdk.init(traces_sample_rate=1.0)
20+
except ImportError:
21+
print("Sentry Disabled")
22+
1823
from boto3.s3.transfer import TransferConfig
1924

2025
from .common import (
@@ -33,10 +38,7 @@
3338
UnexpectedURLFormatError,
3439
)
3540

36-
sentry_sdk.init(traces_sample_rate=1.0)
37-
38-
GITLAB_URL = "https://gitlab.spack.io"
39-
GITLAB_PROJECT = "spack/spack"
41+
GITHUB_PROJECT = "spack/spack-packages"
4042
PREFIX_REGEX_V2 = re.compile(r"/build_cache/(.+)$")
4143
PROTECTED_REF_REGEXES = [
4244
re.compile(r"^develop$"),
@@ -596,23 +598,29 @@ def _process_manifest_fn(spec_hash, stack):
596598
################################################################################
597599
#
598600
def get_recently_run_protected_refs(last_n_days):
599-
"""Query gitlab pipelines to get recently run refs
601+
"""Query Github for recently updated refs
600602
601603
Filter through pipelines updated over the last_n_days to find all protected
602604
branches that had a pipeline run.
603605
"""
604-
gl = gitlab.Gitlab(GITLAB_URL)
605-
project = gl.projects.get(GITLAB_PROJECT)
606-
now = datetime.now()
607-
previous = now - timedelta(days=last_n_days)
606+
gh = github.Github()
607+
repo = gh.get_repo(GITHUB_PROJECT)
608+
608609
recent_protected_refs = set()
609-
print(f"Piplines in the last {last_n_days} day(s):")
610-
for pipeline in project.pipelines.list(
611-
iterator=True, updated_before=now, updated_after=previous
612-
):
613-
print(f" {pipeline.id}: {pipeline.ref}")
614-
if is_ref_protected(pipeline.ref):
615-
recent_protected_refs.add(pipeline.ref)
610+
now = datetime.now(timezone.utc)
611+
previous = now - timedelta(days=last_n_days)
612+
for branch in repo.get_branches():
613+
if not branch.protected:
614+
continue
615+
if branch.commit.commit.author.date < previous:
616+
continue
617+
recent_protected_refs.add(branch.name)
618+
619+
for tag in repo.get_tags():
620+
if tag.last_modified_datetime < previous:
621+
continue
622+
recent_protected_refs.add(tag.name)
623+
616624
return list(recent_protected_refs)
617625

618626

@@ -669,7 +677,7 @@ def main():
669677
"-v",
670678
"--version",
671679
type=int,
672-
default=2,
680+
default=3,
673681
help=("Target layout version to publish (either 2 or 3, defaults to 2)"),
674682
)
675683
parser.add_argument(

0 commit comments

Comments
 (0)