fluentci_graphql/schema/objects/
git.rs1use std::sync::{Arc, Mutex};
2
3use async_graphql::{Context, Error, Object, ID};
4use fluentci_common::git as common_git;
5use fluentci_core::deps::Graph;
6use fluentci_types::git as types;
7
8use super::directory::Directory;
9
10#[derive(Debug, Clone, Default)]
11pub struct Git {
12 pub id: ID,
13}
14
15#[Object]
16impl Git {
17 async fn id(&self) -> &ID {
18 &self.id
19 }
20
21 async fn branch(&self, ctx: &Context<'_>, name: String) -> Result<&Git, Error> {
22 let graph = ctx.data::<Arc<Mutex<Graph>>>().unwrap();
23 common_git::branch(graph.clone(), name)?;
24 Ok(&self)
25 }
26
27 async fn commit(&self, ctx: &Context<'_>) -> Result<String, Error> {
28 let graph = ctx.data::<Arc<Mutex<Graph>>>().unwrap();
29 let commit = common_git::commit(graph.clone())?;
30 Ok(commit)
31 }
32
33 async fn tree(&self, ctx: &Context<'_>) -> Result<Directory, Error> {
34 let graph = ctx.data::<Arc<Mutex<Graph>>>().unwrap();
35 let directory = common_git::tree(graph.clone())?;
36 Ok(Directory::from(directory))
37 }
38}
39
40impl From<types::Git> for Git {
41 fn from(git: types::Git) -> Self {
42 Self { id: ID(git.id) }
43 }
44}