From 90cf62b0274c85f8b10c38ad6d046e1c5aa868ae Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Tue, 16 May 2023 17:32:01 +0200 Subject: [PATCH] cob: Redesign merge state Move `merges` from `Revision` to `Patch`, and key them by actor. This ensures that only one merge is possible per actor. We also make sure that only one revision can be merged at a time, and signal a conflict if more than one revision is considered merged. Finally, we make sure that merges have the same target-branch commit to be considered equal. --- radicle-httpd/src/api.rs | 4 ++-- radicle-httpd/src/api/json.rs | 9 ++++++- radicle-httpd/src/api/v1/projects.rs | 36 +++++++++++++++------------- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/radicle-httpd/src/api.rs b/radicle-httpd/src/api.rs index a370a150e..750a2984a 100644 --- a/radicle-httpd/src/api.rs +++ b/radicle-httpd/src/api.rs @@ -153,10 +153,10 @@ pub enum PatchState { impl PatchState { pub fn matches(&self, patch: &patch::State) -> bool { match self { - Self::Open => matches!(patch, patch::State::Open), + Self::Open => matches!(patch, patch::State::Open { .. }), Self::Draft => matches!(patch, patch::State::Draft), Self::Archived => matches!(patch, patch::State::Archived), - Self::Merged => matches!(patch, patch::State::Merged), + Self::Merged => matches!(patch, patch::State::Merged { .. }), } } } diff --git a/radicle-httpd/src/api/json.rs b/radicle-httpd/src/api/json.rs index 2f20e2e04..88fc3caa4 100644 --- a/radicle-httpd/src/api/json.rs +++ b/radicle-httpd/src/api/json.rs @@ -123,6 +123,14 @@ pub(crate) fn patch( "state": patch.state(), "target": patch.target(), "tags": patch.tags().collect::>(), + "merges": patch.merges().map(|(a, m)| { + json!({ + "author": a, + "revision": m.revision, + "commit": m.commit, + "timestamp": m.timestamp + }) + }).collect::>(), "revisions": patch.revisions().map(|(id, rev)| { json!({ "id": id, @@ -130,7 +138,6 @@ pub(crate) fn patch( "base": rev.base(), "oid": rev.head(), "refs": get_refs(repo, patch.author().id(), &rev.head()).unwrap_or(vec![]), - "merges": rev.merges().collect::>(), "discussions": rev.discussion().comments() .map(|(id, comment)| Comment::new(id, comment, rev.discussion(), aliases)) .collect::>(), diff --git a/radicle-httpd/src/api/v1/projects.rs b/radicle-httpd/src/api/v1/projects.rs index ae1c3daee..c6baea27c 100644 --- a/radicle-httpd/src/api/v1/projects.rs +++ b/radicle-httpd/src/api/v1/projects.rs @@ -1745,6 +1745,7 @@ mod routes { "state": { "status": "open" }, "target": "delegates", "tags": [], + "merges": [], "revisions": [ { "id": CONTRIBUTOR_PATCH_ID, @@ -1754,7 +1755,6 @@ mod routes { "refs": [ "refs/heads/master", ], - "merges": [], "discussions": [], "timestamp": TIMESTAMP, "reviews": [], @@ -1784,6 +1784,7 @@ mod routes { "state": { "status": "open" }, "target": "delegates", "tags": [], + "merges": [], "revisions": [ { "id": CONTRIBUTOR_PATCH_ID, @@ -1793,7 +1794,6 @@ mod routes { "refs": [ "refs/heads/master", ], - "merges": [], "discussions": [], "timestamp": TIMESTAMP, "reviews": [], @@ -1862,6 +1862,7 @@ mod routes { "state": { "status": "open" }, "target": "delegates", "tags": [], + "merges": [], "revisions": [ { "id": CREATED_PATCH_ID, @@ -1871,7 +1872,6 @@ mod routes { "refs": [ "refs/heads/master", ], - "merges": [], "discussions": [], "timestamp": TIMESTAMP, "reviews": [], @@ -1925,6 +1925,7 @@ mod routes { "bug", "design" ], + "merges": [], "revisions": [ { "id": CONTRIBUTOR_PATCH_ID, @@ -1934,7 +1935,6 @@ mod routes { "refs": [ "refs/heads/master", ], - "merges": [], "discussions": [], "timestamp": TIMESTAMP, "reviews": [], @@ -1985,6 +1985,7 @@ mod routes { "state": { "status": "open" }, "target": "delegates", "tags": [], + "merges": [], "revisions": [ { "id": CONTRIBUTOR_PATCH_ID, @@ -1994,7 +1995,6 @@ mod routes { "refs": [ "refs/heads/master", ], - "merges": [], "discussions": [], "timestamp": TIMESTAMP, "reviews": [], @@ -2007,7 +2007,6 @@ mod routes { "refs": [ "refs/heads/master", ], - "merges": [], "discussions": [], "timestamp": TIMESTAMP, "reviews": [], @@ -2058,6 +2057,7 @@ mod routes { "state": { "status": "open" }, "target": "delegates", "tags": [], + "merges": [], "revisions": [ { "id": CONTRIBUTOR_PATCH_ID, @@ -2067,7 +2067,6 @@ mod routes { "refs": [ "refs/heads/master", ], - "merges": [], "discussions": [], "timestamp": TIMESTAMP, "reviews": [], @@ -2140,6 +2139,7 @@ mod routes { "state": { "status": "open" }, "target": "delegates", "tags": [], + "merges": [], "revisions": [ { "id": CONTRIBUTOR_PATCH_ID, @@ -2149,7 +2149,6 @@ mod routes { "refs": [ "refs/heads/master", ], - "merges": [], "discussions": [ { "id": CONTRIBUTOR_COMMENT_1, @@ -2236,6 +2235,7 @@ mod routes { "state": { "status": "open" }, "target": "delegates", "tags": [], + "merges": [], "revisions": [ { "id": CONTRIBUTOR_PATCH_ID, @@ -2245,7 +2245,6 @@ mod routes { "refs": [ "refs/heads/master", ], - "merges": [], "discussions": [], "timestamp": TIMESTAMP, "reviews": [ @@ -2316,9 +2315,19 @@ mod routes { }, "title": "A new `hello world`", "description": "change `hello world` in README to something else", - "state": { "status": "merged" }, + "state": { + "status": "merged", + "revision": CONTRIBUTOR_PATCH_ID, + "commit": PARENT, + }, "target": "delegates", "tags": [], + "merges": [{ + "author": CONTRIBUTOR_NID, + "revision": CONTRIBUTOR_PATCH_ID, + "commit": PARENT, + "timestamp": TIMESTAMP, + }], "revisions": [ { "id": CONTRIBUTOR_PATCH_ID, @@ -2328,13 +2337,6 @@ mod routes { "refs": [ "refs/heads/master", ], - "merges": [ - { - "node": CONTRIBUTOR_NID, - "commit": PARENT, - "timestamp": TIMESTAMP, - }, - ], "discussions": [], "timestamp": TIMESTAMP, "reviews": [],