mirror of
https://github.com/Pythagora-io/gpt-pilot.git
synced 2026-01-09 21:27:53 -05:00
show last project update time in JSON list
This commit is contained in:
@@ -194,6 +194,7 @@ async def list_projects_json(db: SessionManager):
|
||||
|
||||
data = []
|
||||
for project in projects:
|
||||
last_updated = None
|
||||
p = {
|
||||
"name": project.name,
|
||||
"id": project.id.hex,
|
||||
@@ -206,6 +207,8 @@ async def list_projects_json(db: SessionManager):
|
||||
"steps": [],
|
||||
}
|
||||
for state in branch.states:
|
||||
if not last_updated or state.created_at > last_updated:
|
||||
last_updated = state.created_at
|
||||
s = {
|
||||
"name": state.action or f"Step #{state.step_index}",
|
||||
"step": state.step_index,
|
||||
@@ -214,7 +217,9 @@ async def list_projects_json(db: SessionManager):
|
||||
if b["steps"]:
|
||||
b["steps"][-1]["name"] = "Latest step"
|
||||
p["branches"].append(b)
|
||||
p["updated_at"] = last_updated.isoformat() if last_updated else None
|
||||
data.append(p)
|
||||
|
||||
print(json.dumps(data, indent=2))
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import json
|
||||
from argparse import ArgumentParser, ArgumentTypeError
|
||||
from datetime import datetime
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
@@ -167,9 +168,9 @@ async def test_list_projects_json(mock_StateManager, capsys):
|
||||
branch = MagicMock(
|
||||
id=MagicMock(hex="1234"),
|
||||
states=[
|
||||
MagicMock(step_index=1, action="foo"),
|
||||
MagicMock(step_index=2, action=None),
|
||||
MagicMock(step_index=3, action="baz"),
|
||||
MagicMock(step_index=1, action="foo", created_at=datetime(2021, 1, 1)),
|
||||
MagicMock(step_index=2, action=None, created_at=datetime(2021, 1, 2)),
|
||||
MagicMock(step_index=3, action="baz", created_at=datetime(2021, 1, 3)),
|
||||
],
|
||||
)
|
||||
branch.name = "branch1"
|
||||
@@ -191,6 +192,7 @@ async def test_list_projects_json(mock_StateManager, capsys):
|
||||
{
|
||||
"name": "project1",
|
||||
"id": "abcd",
|
||||
"updated_at": "2021-01-03T00:00:00",
|
||||
"branches": [
|
||||
{
|
||||
"name": "branch1",
|
||||
|
||||
Reference in New Issue
Block a user