commit 272b3813ff8cf1574a64c027cf7b0b4bf4c3cab1
parent 58a4cb2b1522a12b7cc957efb64617b70326f2ce
Author: lash <dev@holbrook.no>
Date: Tue, 15 Nov 2022 07:01:26 +0000
Preserve owner in state
Diffstat:
6 files changed, 46 insertions(+), 8 deletions(-)
diff --git a/piknik/basket.py b/piknik/basket.py
@@ -53,7 +53,6 @@ class Basket:
def get(self, issue_id):
r = self.state.get(issue_id)
- print('get content {}'.format(r))
o = Issue.from_str(r)
return o
diff --git a/piknik/identity.py b/piknik/identity.py
@@ -20,3 +20,7 @@ class Identity:
h.update(self.__id)
z = h.digest()
return 'sha256:' + z.hex()
+
+
+ def __str__(self):
+ return self.id()
diff --git a/piknik/issue.py b/piknik/issue.py
@@ -25,12 +25,14 @@ class Issue:
def from_str(s):
r = json.loads(s)
o = Issue(title=r['title'], issue_id=r['id'])
- for k in r['assigned'].keys():
- print('processing {}'.format(k))
+ for i, k in enumerate(r['assigned'].keys()):
p = Identity(k)
o.assigned.append(p)
t = datetime.datetime.utcfromtimestamp(r['assigned'][k])
o.assigned_time.append(t)
+ if r['owner'] == None or k == r['owner']:
+ r['owner'] = k
+ o.owner_idx = i
return o
@@ -84,10 +86,16 @@ class Issue:
'id': str(self.id),
'title': self.title,
'assigned': {},
+ 'owner': None,
}
- for v in self.get_assigned():
- o['assigned'][v[0].id()] = v[1].timestamp()
+ for i, v in enumerate(self.get_assigned()):
+ aid = v[0].id()
+ o['assigned'][aid] = v[1].timestamp()
+ if self.owner_idx == i:
+ o['owner'] = aid
+
+ print(o)
return json.dumps(o)
diff --git a/piknik/runnable/mod.py b/piknik/runnable/mod.py
@@ -17,6 +17,8 @@ argp.add_argument('-u', '--untag', type=str, action='append', default=[], help='
argp.add_argument('-f', '--file', type=str, action='append', help='Add message file part')
argp.add_argument('-m', '--message', type=str, action='append', default=[], help='Add message text part')
argp.add_argument('-a', '--assign', type=str, action='append', default=[], help='Assign given identity to issue')
+argp.add_argument('--unassign', type=str, action='append', default=[], help='Unassign given identity from issue')
+argp.add_argument('-o', '--owner', type=str, help='Set given identity as owner of issue')
argp.add_argument('issue_id', type=str, help='Issue id to modify')
arg = argp.parse_args(sys.argv[1:])
@@ -44,9 +46,14 @@ def main():
for v in arg.untag:
basket.untag(arg.issue_id, v)
+ for v in arg.unassign:
+ basket.unassign(arg.issue_id, v)
+
for v in arg.assign:
basket.assign(arg.issue_id, v)
-
+
+ if arg.owner:
+ basket.owner(arg.issue_id, arg.owner)
if __name__ == '__main__':
diff --git a/piknik/runnable/show.py b/piknik/runnable/show.py
@@ -20,13 +20,29 @@ def render_default(b, o, t):
print("""id: {}
title: {}
tags: {}
- """.format(
+""".format(
o.id,
o.title,
', '.join(t),
)
)
+ assigned = o.get_assigned()
+
+ if len(assigned) == 0:
+ print('(not assigned)')
+ return
+
+ print('assigned to:')
+ owner = o.owner()
+ for v in assigned:
+ o = v[0]
+ s = o.id()
+ if o == owner:
+ s += ' (owner)'
+ print('\t' + str(s))
+
+
def main():
o = basket.get(arg.issue_id)
t = basket.tags(arg.issue_id)
diff --git a/tests/test_store.py b/tests/test_store.py
@@ -120,13 +120,17 @@ class TestStore(unittest.TestCase):
self.b.assign(vb, alice)
self.b.assign(vb, bob)
self.b.owner(vb, bob)
+ r = self.b.get(vb)
+ check = Identity(bob)
+ self.assertTrue(r.owner() == check)
+
self.b.unassign(vb, alice)
r = self.b.get(vb)
check = Identity(bob)
self.assertEqual(r.owner(), check)
check_assigned = r.get_assigned()
- self.assertEqual(check_assigned[0][0], check)
+ self.assertTrue(r.owner() == check)
if __name__ == '__main__':