radicle: Change review data in patch COB
* `CodeLocation` had a `blob` and `commit` field. These are redundant, since the review lives under a revision. We also change the line range to be diff-compatible, with an old and new range. The ranges are optional to account for different scenarios like file deletion, move etc. * `CodeComment` had redundant getters which were removed in favor of public fields. We also remove the `timestamp` field, as it will be the same as the review timestamp.
This commit is contained in:
parent
d4e073fe4e
commit
22360f8c25
|
|
@ -2309,16 +2309,11 @@ mod routes {
|
||||||
"inline": [
|
"inline": [
|
||||||
{
|
{
|
||||||
"location": {
|
"location": {
|
||||||
"blob": "82eb77880c693655bce074e3dbbd9fa711dc018b",
|
|
||||||
"path": "./README.md",
|
"path": "./README.md",
|
||||||
"commit": HEAD,
|
"old": null,
|
||||||
"lines": {
|
"new": null,
|
||||||
"start": 1,
|
|
||||||
"end": 3,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
"comment": "This is a comment on line 1",
|
"comment": "This is a comment on line 1",
|
||||||
"timestamp": TIMESTAMP,
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"timestamp": TIMESTAMP,
|
"timestamp": TIMESTAMP,
|
||||||
|
|
|
||||||
|
|
@ -729,18 +729,16 @@ impl fmt::Display for Verdict {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Code location, used for attaching comments.
|
/// Code location, used for attaching comments to diffs.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct CodeLocation {
|
pub struct CodeLocation {
|
||||||
/// File being commented on.
|
/// Path of file.
|
||||||
pub blob: git::Oid,
|
|
||||||
/// Path of file being commented on.
|
|
||||||
pub path: PathBuf,
|
pub path: PathBuf,
|
||||||
/// Commit commented on.
|
/// Line range on old file. `None` for added files.
|
||||||
pub commit: git::Oid,
|
pub old: Option<Range<usize>>,
|
||||||
/// Line range commented on.
|
/// Line range on new file. `None` for deleted files.
|
||||||
pub lines: Range<usize>,
|
pub new: Option<Range<usize>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialOrd for CodeLocation {
|
impl PartialOrd for CodeLocation {
|
||||||
|
|
@ -751,50 +749,19 @@ impl PartialOrd for CodeLocation {
|
||||||
|
|
||||||
impl Ord for CodeLocation {
|
impl Ord for CodeLocation {
|
||||||
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
||||||
(
|
(&self.path, &self.old.as_ref().map(|o| (o.start, o.end)))
|
||||||
&self.blob,
|
.cmp(&(&other.path, &other.new.as_ref().map(|o| (o.start, o.end))))
|
||||||
&self.path,
|
|
||||||
&self.commit,
|
|
||||||
&self.lines.start,
|
|
||||||
&self.lines.end,
|
|
||||||
)
|
|
||||||
.cmp(&(
|
|
||||||
&other.blob,
|
|
||||||
&other.path,
|
|
||||||
&other.commit,
|
|
||||||
&other.lines.start,
|
|
||||||
&other.lines.end,
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Comment on code.
|
/// Comment on code diff.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct CodeComment {
|
pub struct CodeComment {
|
||||||
/// Code location of the comment.
|
/// Code location of the comment.
|
||||||
location: CodeLocation,
|
pub location: CodeLocation,
|
||||||
/// Comment.
|
/// Comment.
|
||||||
comment: String,
|
pub comment: String,
|
||||||
/// Timestamp.
|
|
||||||
timestamp: Timestamp,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CodeComment {
|
|
||||||
/// Code location of the comment.
|
|
||||||
pub fn location(&self) -> &CodeLocation {
|
|
||||||
&self.location
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Comment.
|
|
||||||
pub fn comment(&self) -> &str {
|
|
||||||
&self.comment
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Timestamp.
|
|
||||||
pub fn timestamp(&self) -> &Timestamp {
|
|
||||||
&self.timestamp
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A patch review on a revision.
|
/// A patch review on a revision.
|
||||||
|
|
@ -1835,7 +1802,6 @@ mod test {
|
||||||
let ctx = test::setup::Context::new(&tmp);
|
let ctx = test::setup::Context::new(&tmp);
|
||||||
let signer = &ctx.signer;
|
let signer = &ctx.signer;
|
||||||
let pr = ctx.branch_with(test::setup::initial_blobs());
|
let pr = ctx.branch_with(test::setup::initial_blobs());
|
||||||
let blob = git::Oid::from_str("518d5069f94c03427f694bb494ac1cd7d133999").unwrap();
|
|
||||||
let mut patches = Patches::open(&ctx.project).unwrap();
|
let mut patches = Patches::open(&ctx.project).unwrap();
|
||||||
let mut patch = patches
|
let mut patch = patches
|
||||||
.create(
|
.create(
|
||||||
|
|
@ -1854,13 +1820,11 @@ mod test {
|
||||||
|
|
||||||
let inline = vec![CodeComment {
|
let inline = vec![CodeComment {
|
||||||
location: CodeLocation {
|
location: CodeLocation {
|
||||||
blob,
|
|
||||||
path: Path::new("file.rs").to_path_buf(),
|
path: Path::new("file.rs").to_path_buf(),
|
||||||
commit: pr.oid,
|
old: Some(1..3),
|
||||||
lines: 1..3,
|
new: Some(1..3),
|
||||||
},
|
},
|
||||||
comment: "Nice!".to_owned(),
|
comment: "Nice!".to_owned(),
|
||||||
timestamp: Timestamp::new(0),
|
|
||||||
}];
|
}];
|
||||||
patch
|
patch
|
||||||
.review(
|
.review(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue