mirror of
https://github.com/vee1e/gittuf.git
synced 2026-09-02 02:37:05 +00:00
Merge pull request #947 from fr0m-scratch/add-sandbox-api
luasandbox: added two apis for `luasandbox`
This commit is contained in:
commit
e1dfa9d0ea
3 changed files with 46 additions and 1 deletions
12
docs/sandbox/README.md
generated
12
docs/sandbox/README.md
generated
|
|
@ -84,6 +84,18 @@ Retrieve the remote URL for the specified Git remote.
|
|||
gitGetRemoteURL("origin") -> "example.com/example/example"
|
||||
```
|
||||
|
||||
## gitGetStagedFilePaths
|
||||
|
||||
**Signature:** `gitGetStagedFilePaths() -> paths`
|
||||
|
||||
Retrieve a Lua table of file paths that have staged changes (changes in the index).
|
||||
|
||||
### Example 1
|
||||
|
||||
```
|
||||
gitGetStagedFilePaths() -> ["foo/bar.txt", "baz/qux.py"]
|
||||
```
|
||||
|
||||
## gitGetSymbolicReferenceTarget
|
||||
|
||||
**Signature:** `gitGetSymbolicReferenceTarget(ref) -> ref`
|
||||
|
|
|
|||
|
|
@ -350,3 +350,35 @@ func (l *LuaEnvironment) apiGitGetRemoteURL() API {
|
|||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (l *LuaEnvironment) apiGitGetStagedFilePaths() API {
|
||||
return &GoAPI{
|
||||
Name: "gitGetStagedFilePaths",
|
||||
Signature: "gitGetStagedFilePaths() -> paths",
|
||||
Help: "Retrieve a Lua table of file paths that have staged changes (changes in the index).",
|
||||
Examples: []string{
|
||||
"gitGetStagedFilePaths() -> [\"foo/bar.txt\", \"baz/qux.py\"]",
|
||||
},
|
||||
Implementation: func(s *lua.LState) int {
|
||||
statuses, err := l.repository.Status()
|
||||
if err != nil {
|
||||
s.Push(lua.LString(err.Error()))
|
||||
return 1
|
||||
}
|
||||
|
||||
resultTable := s.NewTable()
|
||||
localIndex := 1
|
||||
for filePath, fileStatus := range statuses {
|
||||
if fileStatus.X != gitinterface.StatusCodeUnmodified &&
|
||||
fileStatus.X != gitinterface.StatusCodeIgnored &&
|
||||
fileStatus.X != gitinterface.StatusCodeUntracked {
|
||||
resultTable.RawSetInt(localIndex, lua.LString(filePath))
|
||||
localIndex++
|
||||
}
|
||||
}
|
||||
|
||||
s.Push(resultTable)
|
||||
return 1
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ func (l *LuaEnvironment) RunScript(script string, parameters lua.LTable) (int, e
|
|||
|
||||
// If a table is returned, then this likely means that the hook didn't
|
||||
// return an exit code. Return a 1 for safety.
|
||||
_, ok := returnValue.(*lua.LNumber)
|
||||
_, ok := returnValue.(lua.LNumber)
|
||||
if !ok {
|
||||
return 1, nil
|
||||
}
|
||||
|
|
@ -218,6 +218,7 @@ func (l *LuaEnvironment) registerAPIFunctions() error {
|
|||
"gitGetCommitMessage": l.apiGitGetCommitMessage(),
|
||||
"gitGetFilePathsChangedByCommit": l.apiGitGetFilePathsChangedByCommit(),
|
||||
"gitGetRemoteURL": l.apiGitGetRemoteURL(),
|
||||
"gitGetStagedFilePaths": l.apiGitGetStagedFilePaths(),
|
||||
}
|
||||
|
||||
for name, availableAPI := range registerAPIs {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue