Skip to content

Commit

Permalink
refactor: patch requests -> patchsets -> patches
Browse files Browse the repository at this point in the history
Previously a patch request contained a series of patches.  This worked
great as an MVP but we are starting to see some issues with this impl.

Previously the contrib and reviewer would push patches to git-pr similar
to github pull requests.  They all get merged into a single patchset.
This mostly works until you want to start editing previous commits to
keep the commit history tidy and relevant.  For many workflows, going
back to a previous commit and amending it to address feedback is
desirable.

This creates a new model, patchset, which is a mostly immutable
container for patches.  1-to-many patch request to patchsets and
1-to-many patchset to patches.  Think of these patchsets as revisions.

This allows us to better organize collaboration and enable features like
`git range-diff` to see changes between revisions.

BREAKING CHANGE: sqlite dbs will have to be recreated as the new models
are fundamentally different. Sorry for the inconvenience!
  • Loading branch information
neurosnap committed Jul 18, 2024
1 parent 8460ee0 commit 8085b4f
Show file tree
Hide file tree
Showing 12 changed files with 763 additions and 336 deletions.
326 changes: 202 additions & 124 deletions cli.go

Large diffs are not rendered by default.

136 changes: 83 additions & 53 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,35 +42,43 @@ type PatchRequest struct {
LastUpdated string `db:"last_updated"`
}

type Patchset struct {
ID int64 `db:"id"`
UserID int64 `db:"user_id"`
PatchRequestID int64 `db:"patch_request_id"`
Review bool `db:"review"`
CreatedAt time.Time `db:"created_at"`
}

// Patch is a database model for a single entry in a patchset.
// This usually corresponds to a git commit.
type Patch struct {
ID int64 `db:"id"`
UserID int64 `db:"user_id"`
PatchRequestID int64 `db:"patch_request_id"`
AuthorName string `db:"author_name"`
AuthorEmail string `db:"author_email"`
AuthorDate string `db:"author_date"`
Title string `db:"title"`
Body string `db:"body"`
BodyAppendix string `db:"body_appendix"`
CommitSha string `db:"commit_sha"`
ContentSha string `db:"content_sha"`
BaseCommitSha sql.NullString `db:"base_commit_sha"`
Review bool `db:"review"`
RawText string `db:"raw_text"`
CreatedAt time.Time `db:"created_at"`
ID int64 `db:"id"`
UserID int64 `db:"user_id"`
PatchsetID int64 `db:"patchset_id"`
AuthorName string `db:"author_name"`
AuthorEmail string `db:"author_email"`
AuthorDate string `db:"author_date"`
Title string `db:"title"`
Body string `db:"body"`
BodyAppendix string `db:"body_appendix"`
CommitSha string `db:"commit_sha"`
ContentSha string `db:"content_sha"`
BaseCommitSha sql.NullString `db:"base_commit_sha"`
RawText string `db:"raw_text"`
CreatedAt time.Time `db:"created_at"`
}

// EventLog is a event log for RSS or other notification systems.
type EventLog struct {
ID int64 `db:"id"`
UserID int64 `db:"user_id"`
RepoID string `db:"repo_id"`
PatchRequestID int64 `db:"patch_request_id"`
Event string `db:"event"`
Data string `db:"data"`
CreatedAt time.Time `db:"created_at"`
ID int64 `db:"id"`
UserID int64 `db:"user_id"`
RepoID string `db:"repo_id"`
PatchRequestID sql.NullInt64 `db:"patch_request_id"`
PatchsetID sql.NullInt64 `db:"patchset_id"`
Event string `db:"event"`
Data string `db:"data"`
CreatedAt time.Time `db:"created_at"`
}

// DB is the interface for a pico/git database.
Expand Down Expand Up @@ -111,54 +119,76 @@ CREATE TABLE IF NOT EXISTS patch_requests (
ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS patches (
CREATE TABLE IF NOT EXISTS patchsets (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL,
patch_request_id INTEGER NOT NULL,
author_name TEXT NOT NULL,
author_email TEXT NOT NULL,
author_date DATETIME NOT NULL,
title TEXT NOT NULL,
body TEXT NOT NULL,
body_appendix TEXT NOT NULL,
commit_sha TEXT NOT NULL,
content_sha TEXT NOT NULL,
review BOOLEAN NOT NULL DEFAULT false,
raw_text TEXT NOT NULL,
base_commit_sha TEXT,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT pr_id_fk
FOREIGN KEY(patch_request_id) REFERENCES patch_requests(id)
CONSTRAINT patchset_user_id_fk
FOREIGN KEY(user_id) REFERENCES app_users(id)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT patches_user_id_fk
FOREIGN KEY(user_id) REFERENCES app_users(id)
CONSTRAINT patchset_patch_request_id_fk
FOREIGN KEY(patch_request_id) REFERENCES patch_requests(id)
ON DELETE CASCADE
ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS patches (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL,
patchset_id INTEGER NOT NULL,
author_name TEXT NOT NULL,
author_email TEXT NOT NULL,
author_date DATETIME NOT NULL,
title TEXT NOT NULL,
body TEXT NOT NULL,
body_appendix TEXT NOT NULL,
commit_sha TEXT NOT NULL,
content_sha TEXT NOT NULL,
raw_text TEXT NOT NULL,
base_commit_sha TEXT,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT patches_user_id_fk
FOREIGN KEY(user_id) REFERENCES app_users(id)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT patches_patchset_id_fk
FOREIGN KEY(patchset_id) REFERENCES patchsets(id)
ON DELETE CASCADE
ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS event_logs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL,
repo_id TEXT,
patch_request_id INTEGER,
event TEXT NOT NULL,
data TEXT,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT event_logs_pr_id_fk
FOREIGN KEY(patch_request_id) REFERENCES patch_requests(id)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT event_logs_user_id_fk
FOREIGN KEY(user_id) REFERENCES app_users(id)
ON DELETE CASCADE
ON UPDATE CASCADE
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL,
repo_id TEXT,
patch_request_id INTEGER,
patchset_id INTEGER,
event TEXT NOT NULL,
data TEXT,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT event_logs_pr_id_fk
FOREIGN KEY(patch_request_id) REFERENCES patch_requests(id)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT event_logs_patchset_id_fk
FOREIGN KEY(patchset_id) REFERENCES patchsets(id)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT event_logs_user_id_fk
FOREIGN KEY(user_id) REFERENCES app_users(id)
ON DELETE CASCADE
ON UPDATE CASCADE
);
`

var sqliteMigrations = []string{
"", // migration #0 is reserved for schema initialization
"ALTER TABLE patches ADD COLUMN base_commit_sha TEXT",
`
`,
}

// Open opens a database connection.
Expand Down Expand Up @@ -199,7 +229,7 @@ func (db *DB) upgrade() error {
return fmt.Errorf("git-pr (version %d) older than schema (version %d)", len(sqliteMigrations), version)
}

tx, err := db.Begin()
tx, err := db.Beginx()
if err != nil {
return err
}
Expand Down
18 changes: 18 additions & 0 deletions fixtures/single.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
diff --git a/README.md b/README.md
index 586bc0d..8f3a780 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,3 @@
-# test
+# Let's build an RNN

-testing git pr
+This repo demonstrates building an RNN using `pytorch`
diff --git a/train.py b/train.py
new file mode 100644
index 0000000..5c027f4
--- /dev/null
+++ b/train.py
@@ -0,0 +1,2 @@
+if __name__ == "__main__":
+ print("train!")
31 changes: 31 additions & 0 deletions fixtures/single.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
From 59456574a0bfee9f71c91c13046173c820152346 Mon Sep 17 00:00:00 2001
From: Eric Bower <[email protected]>
Date: Wed, 3 Jul 2024 15:18:47 -0400
Subject: [PATCH] feat: lets build an rnn

---
README.md | 4 ++--
train.py | 2 ++
2 files changed, 4 insertions(+), 2 deletions(-)
create mode 100644 train.py

diff --git a/README.md b/README.md
index 586bc0d..8f3a780 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,3 @@
-# test
+# Let's build an RNN

-testing git pr
+This repo demonstrates building an RNN using `pytorch`
diff --git a/train.py b/train.py
new file mode 100644
index 0000000..5c027f4
--- /dev/null
+++ b/train.py
@@ -0,0 +1,2 @@
+if __name__ == "__main__":
+ print("train!")
--
2.45.2
4 changes: 3 additions & 1 deletion mdw.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package git

import (
"fmt"

"github.com/charmbracelet/ssh"
"github.com/charmbracelet/wish"
)
Expand All @@ -14,7 +16,7 @@ func GitPatchRequestMiddleware(be *Backend, pr GitPatchRequest) wish.Middleware
err := cli.Run(margs)
if err != nil {
be.Logger.Error("error when running cli", "err", err)
wish.Fatalln(sesh, err)
wish.Fatalln(sesh, fmt.Errorf("err: %w", err))
next(sesh)
return
}
Expand Down
Loading

0 comments on commit 8085b4f

Please sign in to comment.