GitRoot
craft your forge, build your project, grow your community freely
1// SPDX-FileCopyrightText: 2025 Romain Maneschi <romain@gitroot.dev>
2//
3// SPDX-License-Identifier: MIT
4
5package gitroot
6
7import (
8 "github.com/tidwall/gjson"
9 "gitroot.dev/libs/golang/plugin/model"
10)
11
12//go:wasmexport init
13func Init(repoNamePtr, repoNameSize, confHasChangedPtr, confHasChangedSize, confPtr, confSize uint32) {
14 repoName := ptrToString(repoNamePtr, repoNameSize)
15 serializedConf := ptrToString(confPtr, confSize)
16 confHasChanged := ptrToString(confHasChangedPtr, confHasChangedSize)
17 server.plugin.Init(repoName, confHasChanged == "true", serializedConf)
18}
19
20//go:wasmexport startCommit
21func StartCommit(jsonPtr, jsonSize uint32) {
22 jsonConf := gjson.Parse(ptrToString(jsonPtr, jsonSize))
23 commit := model.Commit{
24 Branch: jsonConf.Get("Branch").String(),
25 Hash: jsonConf.Get("Hash").String(),
26 Message: jsonConf.Get("Message").String(),
27 Date: jsonConf.Get("Date").Time(),
28 Committer: jsonConf.Get("Committer").String(),
29 ParentHash: jsonConf.Get("ParentHash").String(),
30 }
31 server.plugin.StartCommit(commit)
32}
33
34//go:wasmexport addFile
35func AddFile(ptr, size uint32) {
36 server.plugin.AddFile(ptrToString(ptr, size))
37}
38
39//go:wasmexport modFile
40func ModFile(fromPtr, fromSize, toPtr, toSize uint32) {
41 server.plugin.ModFile(ptrToString(fromPtr, fromSize), ptrToString(toPtr, toSize))
42}
43
44//go:wasmexport delFile
45func DelFile(ptr, size uint32) {
46 server.plugin.DelFile(ptrToString(ptr, size))
47}
48
49//go:wasmexport endCommit
50func EndCommit(jsonPtr, jsonSize uint32) {
51 jsonConf := gjson.Parse(ptrToString(jsonPtr, jsonSize))
52 commit := model.Commit{
53 Branch: jsonConf.Get("Branch").String(),
54 Hash: jsonConf.Get("Hash").String(),
55 Message: jsonConf.Get("Message").String(),
56 Date: jsonConf.Get("Date").Time(),
57 Committer: jsonConf.Get("Committer").String(),
58 ParentHash: jsonConf.Get("ParentHash").String(),
59 }
60 server.plugin.EndCommit(commit)
61}
62
63//go:wasmexport finish
64func Finish() {
65 server.plugin.Finish()
66}
67
68//go:wasmexport defaultRun
69func DefaultRun() uint64 {
70 ptr, size := stringToLeakedPtr(server.run)
71 return (uint64(ptr) << uint64(32)) | uint64(size)
72}