GitRoot
Craft your forge, Build your project, Grow your community freely
1// SPDX-FileCopyrightText: 2026 Romain Maneschi <romain@gitroot.dev>
2//
3// SPDX-License-Identifier: EUPL-1.2
4
5#![no_main]
6
7use gitroot_plugin_sdk::{
8 model::{Commit, File, InitKind, PluginFunc, PluginRun, PluginWrite},
9 register, Plugin, Server,
10};
11
12pub use gitroot_plugin_sdk::exports::*;
13pub use gitroot_plugin_sdk::imports::*;
14use mermaid_rs_renderer::render_with_options;
15use mermaid_rs_renderer::RenderOptions;
16use serde::{Deserialize, Serialize};
17use std::collections::HashMap;
18use std::sync::Arc;
19
20struct ApexMermaid {}
21
22impl ApexMermaid {
23 fn new(server: Arc<Server>) -> Self {
24 server.export_func("renderCode", |args| {
25 if let Some(value) = args.get("code") {
26 let mut opts = RenderOptions::modern();
27 opts.theme.background = "transparent".to_string();
28 render_with_options(value, opts)
29 .map(|svg| HashMap::from([("html".to_string(), svg)]))
30 .map_err(|err| err.to_string())
31 } else {
32 Ok(HashMap::new())
33 }
34 });
35 Self {}
36 }
37}
38
39#[derive(Serialize, Deserialize)]
40struct Conf {}
41
42impl Plugin for ApexMermaid {
43 fn init(
44 &self,
45 _repo_name: String,
46 _kind_init: InitKind,
47 _serialized_conf: String,
48 ) -> Result<(), String> {
49 Ok(())
50 }
51
52 fn start_commit(&self, _commit: Commit) -> Result<(), String> {
53 Ok(())
54 }
55
56 fn add_file(&self, _file: File) -> Result<(), String> {
57 Ok(())
58 }
59
60 fn mod_file(&self, _file: File) -> Result<(), String> {
61 Ok(())
62 }
63
64 fn del_file(&self, _file: File) -> Result<(), String> {
65 Ok(())
66 }
67
68 fn end_commit(&self, _commit: Commit) -> Result<(), String> {
69 Ok(())
70 }
71
72 fn finish(&self) -> Result<(), String> {
73 Ok(())
74 }
75}
76
77#[cfg_attr(all(target_arch = "wasm32"), unsafe(export_name = "install"))]
78pub extern "C" fn install() {
79 let conf = PluginRun {
80 path: String::from(""),
81 branch: vec![],
82 when: vec![],
83 schedule: String::from(""),
84 func: vec![PluginFunc {
85 func_name: "renderCode".to_string(),
86 args: vec!["code".to_string()],
87 res: vec!["html".to_string()],
88 }],
89 write: PluginWrite {
90 git: vec![],
91 web: vec![],
92 exec: vec![],
93 call_func: vec![],
94 },
95 configuration: serde_json::to_value(Conf {}).unwrap(),
96 };
97 register(vec![conf], ApexMermaid::new);
98}
99
100#[cfg(test)]
101mod tests {
102 #[test]
103 fn test_plugin() {
104 assert_eq!(true, true);
105 }
106}