Skip to content

Commit

Permalink
Merge pull request #149 from redkyn/betterer-timestamp-parsing
Browse files Browse the repository at this point in the history
Re-do Gitlab timestamp parsing
  • Loading branch information
LinuxMercedes authored Sep 4, 2020
2 parents b8b24e5 + d82536e commit 8711521
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.2

- Fix bugs with and severely de-cruft Gitlab timestamp parsing

## 2.0.1

- Fix issue where ASCII-only terminals cannot display progress bars
Expand Down
17 changes: 14 additions & 3 deletions assigner/backends/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,20 @@ def get_last_HEAD_commit(self, ref="master"):
# Gitlab's commit created_at time uses the git metadata;
# rather than trusting students, we get the time the commit was pushed at
if matching_pushes and HEAD['id'] == matching_pushes[0]['push_data']['commit_to']:
# For whatever reason, Gitlab uses a different time format here than for commits...
unmangled_time = matching_pushes[0]['created_at'][:-1] + "-0000"
HEAD['created_at'] = unmangled_time
created_at = matching_pushes[0]['created_at']

if created_at.endswith('Z'): # convert 'Z' to appropriate UTC offset
created_at = created_at[:-1] + "-0000"
else:
# Fix UTC offset format in GitLab's datetime: prior to py3.7, UTC offsets could not contain colons
# timezone specifier starts with - or +; look for - first and if that fails then look for +
tz_start = created_at.rfind('-')
if tz_start == -1:
tz_start = created_at.rfind('+')
if tz_start != -1:
created_at = created_at[:tz_start] + created_at[tz_start:].replace(':', '')

HEAD['created_at'] = created_at

return HEAD

Expand Down
5 changes: 0 additions & 5 deletions assigner/commands/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ def status(conf, backend, args):
row[6] = head["short_id"]
row[7] = head["author_name"]
created_at = head["created_at"]
# Fix UTC offset format in GitLab's datetime: prior to py3.7, UTC offsets could not contain colons
created_at = created_at[:-7] + created_at[-7:].replace(':', '')
# Remove odd postfix and add missing 0 to UTC offset
if created_at.endswith('-0000'):
created_at = created_at[:-5] + '0'
row[8] = datetime.strptime(
created_at, "%Y-%m-%dT%H:%M:%S.%f%z"
).astimezone().strftime("%c")
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pyapi-gitlab==7.8.5
pyflakes==2.1.1
requests==2.21.0
six==1.12
smmap==0.9.0
smmap==3.0.1
wheel==0.24.0
PTable==0.9.2
progressbar2==3.10.1
Expand Down

0 comments on commit 8711521

Please sign in to comment.