commit 74b7495c72433a2405be952fdcefb0854c345b2e
parent 76e5d333c1e208e29199849e1c28f0e31308f3f1
Author: lash <dev@holbrook.no>
Date: Sat, 22 Apr 2023 20:20:59 +0100
Auto-generate valid alias when missing
Diffstat:
3 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/piknik/basket.py b/piknik/basket.py
@@ -8,6 +8,7 @@ from shep.error import StateItemNotFound
# local imports
from .error import DeadIssue
from .issue import Issue
+from .issue import id_generator
from .msg import IssueMessage
from .identity import Identity
@@ -40,6 +41,16 @@ class Basket:
self.issues_rev = {}
+ def id_generator(self):
+ while True:
+ issue_id = id_generator()
+ issue_alias = issue_id[:5]
+ try:
+ self.__alias.get(issue_alias)
+ except FileNotFoundError:
+ return issue_id
+
+
def __check_resurrect(self, st, k, f, t):
if self.no_resurrect:
if f & self.state.FINISHED > 0:
diff --git a/piknik/cli/add.py b/piknik/cli/add.py
@@ -24,6 +24,10 @@ def main():
if title != '':
title += ' '
title += s
- o = Issue(title, alias=ctx.alias)
+ if ctx.alias == None:
+ issue_id = ctx.basket.id_generator()
+ o = Issue(title, issue_id=issue_id, alias=issue_id[:5])
+ else:
+ o = Issue(title, alias=ctx.alias)
v = ctx.basket.add(o)
sys.stdout.write(v + '\n')
diff --git a/piknik/issue.py b/piknik/issue.py
@@ -9,11 +9,14 @@ from piknik.error import UnknownIdentityError
from piknik.error import ExistsError
+def id_generator():
+ return str(uuid.uuid4())
+
class Issue:
- def __init__(self, title, issue_id=None, alias=None):
+ def __init__(self, title, issue_id=None, alias=None, id_generator=id_generator):
if issue_id == None:
- issue_id = str(uuid.uuid4())
+ issue_id = id_generator()
self.id = issue_id
self.title = title
self.assigned = []