Skip to content

Commit

Permalink
Include flags for unpushed and uncommitted changes
Browse files Browse the repository at this point in the history
Record which codespaces have uncommited and/or unpushed changes
in order to support reporting on which codespaces users might be
at risk of losing data upon codespace deletion.
  • Loading branch information
Jongmassey committed Nov 4, 2024
1 parent cd4b457 commit 3b70937
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions metrics/github/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ class Codespace:
user: str
created_at: datetime.datetime
last_used_at: datetime.datetime
has_uncommitted_changes: bool
has_unpushed_changes: bool

@classmethod
def from_dict(cls, data, org):
Expand All @@ -124,6 +126,8 @@ def from_dict(cls, data, org):
user=data["owner"]["login"],
created_at=data["created_at"],
last_used_at=data["last_used_at"],
has_uncommitted_changes=data["git_status"]["has_uncommitted_changes"],
has_unpushed_changes=data["git_status"]["has_unpushed_changes"],
)


Expand Down
2 changes: 2 additions & 0 deletions metrics/github/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ def convert_codespaces_to_dicts(codespaces):
"user": c.user,
"created_at": c.created_at,
"last_used_at": c.last_used_at,
"has_uncommitted_changes": c.has_uncommitted_changes,
"has_unpushed_changes": c.has_unpushed_changes,
}
for c in codespaces
]
2 changes: 2 additions & 0 deletions metrics/timescaledb/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
Column("repo", Text, primary_key=True),
Column("user", Text, primary_key=True),
Column("last_used_at", TIMESTAMP(timezone=True)),
Column("has_uncommitted_changes", Boolean),
Column("has_unpushed_changes", Boolean),
)

GitHubRepos = Table(
Expand Down
4 changes: 4 additions & 0 deletions tests/metrics/github/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ def test_codespaces(patch):
"repository": {"name": "testrepo"},
"created_at": datetime.datetime.now().isoformat(),
"last_used_at": datetime.datetime.now().isoformat(),
"git_status": {
"has_uncommitted_changes": True,
"has_unpushed_changes": False,
},
},
]
},
Expand Down

0 comments on commit 3b70937

Please sign in to comment.