Add DiffOps playground
This commit is contained in:
@@ -6,7 +6,7 @@ use tokio::sync::OwnedRwLockReadGuard;
|
||||
use crate::{
|
||||
api,
|
||||
query::{self, Query, fetch_query},
|
||||
util::file,
|
||||
util::{self, file},
|
||||
};
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
@@ -79,8 +79,8 @@ impl query::QueryFn for FetchFileContent {
|
||||
|
||||
fn key(&self) -> query::Key {
|
||||
match &self.reff {
|
||||
| Some(reff) => format!("repo/fetch/{}/{}/{}", self.repo_slug, self.path, reff).into(),
|
||||
| None => format!("repo/fetch/{}/{}", self.repo_slug, self.path).into(),
|
||||
| Some(reff) => format!("repo/fetch/{}/{}/{}", self.repo_slug, self.path, reff).into(),
|
||||
| None => format!("repo/fetch/{}/{}", self.repo_slug, self.path).into(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,11 +95,11 @@ impl query::QueryFn for FetchFileContent {
|
||||
}
|
||||
|
||||
let path = match &self.reff {
|
||||
| Some(reff) => format!(
|
||||
"/repos/{}/contents/{}?ref={}",
|
||||
self.repo_slug, self.path, reff
|
||||
),
|
||||
| None => format!("/repos/{}/contents/{}", self.repo_slug, self.path),
|
||||
| Some(reff) => format!(
|
||||
"/repos/{}/contents/{}?ref={}",
|
||||
self.repo_slug, self.path, reff
|
||||
),
|
||||
| None => format!("/repos/{}/contents/{}", self.repo_slug, self.path),
|
||||
};
|
||||
|
||||
let res = c
|
||||
@@ -113,13 +113,13 @@ impl query::QueryFn for FetchFileContent {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct QueryFileDiff {
|
||||
pub struct FetchFileDiff {
|
||||
pub base: FileRef,
|
||||
pub head: FileRef,
|
||||
}
|
||||
|
||||
impl query::QueryFn for QueryFileDiff {
|
||||
type Data = Option<()>;
|
||||
impl query::QueryFn for FetchFileDiff {
|
||||
type Data = util::diff::ContentDiff;
|
||||
type Error = api::Error;
|
||||
type Context = api::QueryContext;
|
||||
|
||||
@@ -134,11 +134,11 @@ impl query::QueryFn for QueryFileDiff {
|
||||
async fn run(&self, c: &Self::Context) -> Result<Self::Data, Self::Error> {
|
||||
async fn fetch_content(
|
||||
r: &FileRef,
|
||||
c: &<QueryFileDiff as query::QueryFn>::Context,
|
||||
c: &<FetchFileDiff as query::QueryFn>::Context,
|
||||
) -> Result<Option<bytes::Bytes>, api::Error> {
|
||||
let path = match &r.reff {
|
||||
| Some(reff) => format!("/repos/{}/contents/{}?ref={}", r.repo_slug, r.path, reff),
|
||||
| None => format!("/repos/{}/contents/{}", r.repo_slug, r.path),
|
||||
| Some(reff) => format!("/repos/{}/contents/{}?ref={}", r.repo_slug, r.path, reff),
|
||||
| None => format!("/repos/{}/contents/{}", r.repo_slug, r.path),
|
||||
};
|
||||
|
||||
let res = c
|
||||
@@ -160,17 +160,10 @@ impl query::QueryFn for QueryFileDiff {
|
||||
let (old, new) = tokio::join!(fetch_content(&self.base, c), fetch_content(&self.head, c),);
|
||||
|
||||
match (old, new) {
|
||||
| (Ok(Some(ref old)), Ok(Some(ref new))) => {
|
||||
let diff = similar::TextDiff::from_lines::<[u8]>(old, new);
|
||||
for change in diff.iter_all_changes() {}
|
||||
}
|
||||
| _ => {
|
||||
return Err(api::Error::MalformedResponse(
|
||||
| (Ok(Some(old)), Ok(Some(new))) => Ok(util::diff::diff_content(old, new)),
|
||||
| _ => Err(api::Error::MalformedResponse(
|
||||
"failed to fetch content".to_string(),
|
||||
));
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user