|
7 | 7 |
|
8 | 8 | from collections import defaultdict |
9 | 9 | from concurrent.futures import as_completed, ThreadPoolExecutor |
10 | | -from datetime import datetime, timedelta |
| 10 | +from datetime import datetime, timezone, timedelta |
11 | 11 | from typing import Callable, Dict, List, Optional |
12 | 12 |
|
13 | 13 | import botocore.exceptions |
14 | 14 |
|
15 | | -import gitlab |
| 15 | +import github |
16 | 16 | 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 | + |
18 | 23 | from boto3.s3.transfer import TransferConfig |
19 | 24 |
|
20 | 25 | from .common import ( |
|
33 | 38 | UnexpectedURLFormatError, |
34 | 39 | ) |
35 | 40 |
|
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" |
40 | 42 | PREFIX_REGEX_V2 = re.compile(r"/build_cache/(.+)$") |
41 | 43 | PROTECTED_REF_REGEXES = [ |
42 | 44 | re.compile(r"^develop$"), |
@@ -596,23 +598,29 @@ def _process_manifest_fn(spec_hash, stack): |
596 | 598 | ################################################################################ |
597 | 599 | # |
598 | 600 | 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 |
600 | 602 |
|
601 | 603 | Filter through pipelines updated over the last_n_days to find all protected |
602 | 604 | branches that had a pipeline run. |
603 | 605 | """ |
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 | + |
608 | 609 | 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 | + |
616 | 624 | return list(recent_protected_refs) |
617 | 625 |
|
618 | 626 |
|
@@ -669,7 +677,7 @@ def main(): |
669 | 677 | "-v", |
670 | 678 | "--version", |
671 | 679 | type=int, |
672 | | - default=2, |
| 680 | + default=3, |
673 | 681 | help=("Target layout version to publish (either 2 or 3, defaults to 2)"), |
674 | 682 | ) |
675 | 683 | parser.add_argument( |
|
0 commit comments