File tree Expand file tree Collapse file tree 2 files changed +10
-4
lines changed
Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -63,15 +63,13 @@ def extract_tags_from(json_obj):
6363
6464
6565def extract_annotation_from (json_obj ):
66-
6766 if 'annotations' not in json_obj :
6867 return '\' \' '
6968
7069 return json_obj ['annotations' ][0 ]['description' ]
7170
7271
7372def main (old , new ):
74-
7573 start_or_stop = ''
7674
7775 # Started task.
@@ -104,7 +102,14 @@ def main(old, new):
104102
105103
106104if __name__ == "__main__" :
107- old = json .loads (input_stream .readline ().decode ("utf-8" , errors = "replace" ))
108- new = json .loads (input_stream .readline ().decode ("utf-8" , errors = "replace" ))
105+ # Hook is called with two lines input ('old', 'new') in case of an on-modify event,
106+ # but only with one line ('new') in case of an on-add event.
107+ # We want to call the hook with an emtpy 'old' ('{}') in the latter case.
108+ # Prepending '{}' makes sure this happens if only one line is added...
109+ lines = ['{}' ] + [line .decode ("utf-8" , errors = "replace" ) for line in input_stream .readlines ()]
110+
111+ new = json .loads (lines .pop ())
112+ old = json .loads (lines .pop ())
113+
109114 print (json .dumps (new ))
110115 main (old , new )
Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ WORKDIR /task-on-modify-hook
5555# Install on-modify-hook
5656RUN mkdir -p ~/.task/hooks
5757RUN cp on_modify.py ~/.task/hooks/on-modify.timewarrior
58+ RUN ln -s on-add.timewarrior on-modify.timewarrior
5859RUN chmod +x ~/.task/hooks/on-modify.timewarrior
5960
6061RUN echo "timew: $( timew --version )" ; \
You can’t perform that action at this time.
0 commit comments