Skip to content

Commit 3cff44b

Browse files
committed
add missing slug hashing fn
1 parent d56faf7 commit 3cff44b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

binderhub/repoproviders.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import urllib.parse
1717
from datetime import datetime, timedelta, timezone
1818
from urllib.parse import urlparse, urlunparse
19+
from hashlib import md5
1920

2021
import escapism
2122
from prometheus_client import Gauge
@@ -263,6 +264,15 @@ def get_build_slug(self):
263264
return f"zenodo-{self.record_id}"
264265

265266

267+
def get_hashed_slug(url, changes_with_content):
268+
"""Return a unique slug that is invariant to query parameters in the url"""
269+
parsed_url = urlparse(url)
270+
stripped_url = urlunparse(
271+
(parsed_url.scheme, parsed_url.netloc, parsed_url.path, "", "", "")
272+
)
273+
274+
return "meca-" + md5(f"{stripped_url}-{changes_with_content}".encode()).hexdigest()
275+
266276
class MecaRepoProvider(RepoProvider):
267277
"""BinderHub Provider that can handle the contents of a MECA bundle
268278

0 commit comments

Comments
 (0)