Commit 4c16158c authored by Benjamin Fischer's avatar Benjamin Fischer
Browse files

util.GitLabIssue.issue: add per-title issue creation/lookup lock

parent 121ae284
......@@ -22,6 +22,7 @@ from contextvars import ContextVar
from contextlib import ContextDecorator, contextmanager
from time import time
from filelock import FileLock
import tempfile
from hashlib import sha1
from pathlib import Path
......@@ -659,25 +660,28 @@ class GitlabIssue:
@property
def issue(self) -> Dict:
if self.breadcrumb.exists():
return self.breadcrumb.load()["issue"]
with self.lock:
title = self.issue_title
json = self._json(
self.apiurl, params={"search": title, "in": "title", "state": "opened"}
)
if len(json):
[issue] = json
assert issue["title"] == title
else:
issue = self._json(
self.apiurl,
data={
"title": title,
"labels": "create-issue (automatic)",
},
if self.breadcrumb.exists():
return self.breadcrumb.load()["issue"]
ihash = sha1(self.issue_title.encode("utf8")).hexdigest()[:20]
with FileLock(Path(tempfile.gettempdir()) / f"gitub_issue.{ihash}.lock"):
title = self.issue_title
json = self._json(
self.apiurl, params={"search": title, "in": "title", "state": "opened"}
)
self.breadcrumb.dump({"issue": issue})
if len(json):
[issue] = json
assert issue["title"] == title
else:
issue = self._json(
self.apiurl,
data={
"title": title,
"labels": "create-issue (automatic)",
},
)
self.breadcrumb.dump({"issue": issue})
# try automatic issue linking
if m := re.match(r"^issue_(\d+)_", self.model_version):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment