feat(repository): update the lastPushedAt on every push
+ 31
- 13
@@ -1,5 +1,5 @@
 {
-  "_generatedAtUnix": 1663967797508,
+  "_generatedAtUnix": 1663972400490,
   "_hashAlgorithm": "sha1",
   "_version": 2,
   "islands": {

...
@@ -10,7 +10,7 @@
       "pathSourceMap": "./public/.islands/InstantRouterIndicator.bundle.js.map"
     },
     "RepositoriesList": {
-      "hash": "d0e1a580d6857fbf98a08bf5a6242ec5902dac9b",
+      "hash": "b1598428395388bf85a5734a8bc4b14eb7798396",
       "pathSource": "./app/islands/RepositoriesList.tsx",
       "pathBundle": "./public/.islands/RepositoriesList.bundle.js",
       "pathSourceMap": "./public/.islands/RepositoriesList.bundle.js.map"

app/islands/RepositoriesList.tsx
@@ -29,6 +29,11 @@ const RepositoriesList: ReactIsland<RepositoriesListProps> = ({
           </h1>
           <div>
             <p>{repo.shortDescription}</p>
+            {repo.lastPushedAt != null && (
+              <p style={{ margin: 0, marginTop: 8 }}>
+                Last push: {new Date(repo.lastPushedAt).toUTCString()}
+              </p>
+            )}
           </div>
         </div>
       ))}

app/services/gitServer/onPushEvent.ts
@@ -9,26 +9,39 @@ const makeOnPushEvent: ServiceMethodFactory<
   GitServerServiceDeps,
   [GitServer.Event],
   void
-> = (_) => {
+> = ({ request }) => {
   return ({ data, message }) => {
     message.write("\n");
     if (data.packType === GitServer.PackType.RECEIVE) {
-      const receiveBuffer = [] as string[];
-
-      message.stream.on("data", (chunk) => receiveBuffer.push(chunk));
-      message.stream.on("close", () => {
-        console.log(
-          "message.stream::data:",
-          Buffer.from(receiveBuffer.join("")).toString("utf-8")
-        );
-      });
+      const [orgSlug, repoSlug] = data.repoSlug.split("/");
+      request.prisma.repository
+        .findFirst({
+          where: {
+            slug: repoSlug,
+            organization: {
+              slug: orgSlug,
+            },
+          },
+        })
+        .then(async (repo) => {
+          if (repo == null) return Promise.resolve(null);
+          const updatedRepo = await request.prisma.repository.update({
+            where: {
+              id: repo.id,
+            },
+            data: {
+              lastPushedAt: new Date(Date.now()),
+            },
+          });
+          return updatedRepo;
+        });
 
       // client has done something like "git push"
       // it is uploading, we are receiving
       console.log("receive-pack");
       message.write("🖖 See the details of your push at:\n");
       message.write(
-        `🧲 ${Env.DEPLOYMENT_SCHEME}://${Env.DEPLOYMENT_DOMAIN}/${data.repoSlug}/commits/some_commit_hash\n`
+        `🧲 ${Env.DEPLOYMENT_SCHEME}://${Env.DEPLOYMENT_DOMAIN}/${orgSlug}/${repoSlug}\n`
       );
     } else if (data.packType === GitServer.PackType.UPLOAD) {
       // client has done something like "git clone"