Skip to content

Commit 8711521

Browse files
Merge pull request #149 from redkyn/betterer-timestamp-parsing
Re-do Gitlab timestamp parsing
2 parents b8b24e5 + d82536e commit 8711521

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.0.2
2+
3+
- Fix bugs with and severely de-cruft Gitlab timestamp parsing
4+
15
## 2.0.1
26

37
- Fix issue where ASCII-only terminals cannot display progress bars

assigner/backends/gitlab.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,20 @@ def get_last_HEAD_commit(self, ref="master"):
381381
# Gitlab's commit created_at time uses the git metadata;
382382
# rather than trusting students, we get the time the commit was pushed at
383383
if matching_pushes and HEAD['id'] == matching_pushes[0]['push_data']['commit_to']:
384-
# For whatever reason, Gitlab uses a different time format here than for commits...
385-
unmangled_time = matching_pushes[0]['created_at'][:-1] + "-0000"
386-
HEAD['created_at'] = unmangled_time
384+
created_at = matching_pushes[0]['created_at']
385+
386+
if created_at.endswith('Z'): # convert 'Z' to appropriate UTC offset
387+
created_at = created_at[:-1] + "-0000"
388+
else:
389+
# Fix UTC offset format in GitLab's datetime: prior to py3.7, UTC offsets could not contain colons
390+
# timezone specifier starts with - or +; look for - first and if that fails then look for +
391+
tz_start = created_at.rfind('-')
392+
if tz_start == -1:
393+
tz_start = created_at.rfind('+')
394+
if tz_start != -1:
395+
created_at = created_at[:tz_start] + created_at[tz_start:].replace(':', '')
396+
397+
HEAD['created_at'] = created_at
387398

388399
return HEAD
389400

assigner/commands/status.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,6 @@ def status(conf, backend, args):
8686
row[6] = head["short_id"]
8787
row[7] = head["author_name"]
8888
created_at = head["created_at"]
89-
# Fix UTC offset format in GitLab's datetime: prior to py3.7, UTC offsets could not contain colons
90-
created_at = created_at[:-7] + created_at[-7:].replace(':', '')
91-
# Remove odd postfix and add missing 0 to UTC offset
92-
if created_at.endswith('-0000'):
93-
created_at = created_at[:-5] + '0'
9489
row[8] = datetime.strptime(
9590
created_at, "%Y-%m-%dT%H:%M:%S.%f%z"
9691
).astimezone().strftime("%c")

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pyapi-gitlab==7.8.5
99
pyflakes==2.1.1
1010
requests==2.21.0
1111
six==1.12
12-
smmap==0.9.0
12+
smmap==3.0.1
1313
wheel==0.24.0
1414
PTable==0.9.2
1515
progressbar2==3.10.1

0 commit comments

Comments
 (0)