Radish alpha
r
rad:z4D5UCArafTzTQpDZNQRuqswh3ury
Radicle desktop app
Radicle
Git
Add `repo::diff` tauri command
Open did:key:z6MkkfM3...sVz5 opened 1 year ago
7 files changed +61 -1 8aae8e66 608d2110
modified src-tauri/bindings/Patch.ts
@@ -5,6 +5,8 @@ export type Patch = {
  id: string;
  author: Author;
  title: string;
+
  base: string;
+
  head: string;
  state:
    | {
        status: "draft";
added src-tauri/bindings/Stats.ts
@@ -0,0 +1,7 @@
+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
+

+
export type Stats = {
+
  files_changed: number;
+
  insertions: number;
+
  deletions: number;
+
};
modified src-tauri/src/commands/repos.rs
@@ -1,8 +1,10 @@
use radicle::identity::RepoId;
+
use radicle::storage::ReadRepository;
use radicle::storage::ReadStorage;

use crate::error::Error;
use crate::types;
+
use crate::types::cobs;
use crate::AppState;

/// List all repos.
@@ -40,3 +42,21 @@ pub fn repo_by_id(

    Ok::<_, Error>(repo_info)
}
+

+
#[tauri::command]
+
pub async fn diff(
+
    ctx: tauri::State<'_, AppState>,
+
    rid: RepoId,
+
    base: String,
+
    head: String,
+
) -> Result<cobs::Stats, Error> {
+
    let (repo, _) = ctx.repo(rid)?;
+
    let repo = radicle_surf::Repository::open(repo.path())?;
+
    let base = repo.commit(base)?;
+
    let commit = repo.commit(head)?;
+
    let diff = repo.diff(base.id, commit.id)?;
+

+
    let stats = diff.stats();
+

+
    Ok::<_, Error>(cobs::Stats::new(stats))
+
}
modified src-tauri/src/lib.rs
@@ -140,6 +140,7 @@ pub fn run() {
            auth::authenticate,
            repos::list_repos,
            repos::repo_by_id,
+
            repos::diff,
            cobs::list_issues,
            cobs::issues_by_id,
            cobs::list_patches,
modified src-tauri/src/types/cobs.rs
@@ -78,6 +78,10 @@ pub struct Patch {
    id: String,
    author: Author,
    title: String,
+
    #[ts(as = "String")]
+
    base: git::Oid,
+
    #[ts(as = "String")]
+
    head: git::Oid,
    #[ts(type = r#"{
  status: 'draft'
} | {
@@ -104,6 +108,8 @@ impl Patch {
            author: Author::new(*patch.author().id(), aliases),
            title: patch.title().to_string(),
            state: patch.state().clone(),
+
            base: *patch.base(),
+
            head: *patch.head(),
            assignees: patch
                .assignees()
                .map(|did| Author::new(did, aliases))
@@ -458,3 +464,21 @@ impl CobOptions {
        self.announce.unwrap_or(true)
    }
}
+

+
#[derive(TS, Serialize)]
+
#[ts(export)]
+
pub struct Stats {
+
    pub files_changed: usize,
+
    pub insertions: usize,
+
    pub deletions: usize,
+
}
+

+
impl Stats {
+
    pub fn new(stats: &radicle_surf::diff::Stats) -> Self {
+
        Self {
+
            files_changed: stats.files_changed,
+
            insertions: stats.insertions,
+
            deletions: stats.deletions,
+
        }
+
    }
+
}
modified src/components/PatchTeaser.svelte
@@ -1,13 +1,16 @@
<script lang="ts">
  import type { Patch } from "@bindings/Patch";
+
  import type { Stats } from "@bindings/Stats";

  import { formatOid, formatTimestamp } from "@app/lib/utils";
+
  import { invoke } from "@tauri-apps/api/core";

  import Icon from "./Icon.svelte";
  import InlineTitle from "./InlineTitle.svelte";
  import NodeId from "./NodeId.svelte";

  export let patch: Patch;
+
  export let rid: string;

  const statusColor: Record<Patch["state"]["status"], string> = {
    draft: "var(--color-fill-gray)",
@@ -78,6 +81,9 @@
    </div>
  </div>
  <div class="global-flex">
+
    {#await invoke<Stats>( "diff", { rid, base: patch.base, head: patch.head }, ) then stats}
+
      <div>{stats.insertions} / {stats.deletions}</div>
+
    {/await}
    {#each patch.labels as label}
      <div class="global-counter txt-small">{label}</div>
    {/each}
modified src/views/repo/Patches.svelte
@@ -117,7 +117,7 @@

  <div class="list">
    {#each patches as patch}
-
      <PatchTeaser {patch} />
+
      <PatchTeaser rid={repo.rid} {patch} />
    {/each}

    {#if patches.length === 0}