1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-08-11 17:50:58 +00:00

feat: add fromJSON support (#352)

This commit is contained in:
Owen 2020-09-02 04:55:29 +08:00 committed by GitHub
parent 80d5153dc3
commit 8d723eb376
2 changed files with 17 additions and 0 deletions

View file

@ -132,6 +132,7 @@ func (rc *RunContext) newVM() *otto.Otto {
vmFormat,
vmJoin,
vmToJSON,
vmFromJSON,
vmAlways,
rc.vmCancelled(),
rc.vmSuccess(),
@ -219,6 +220,20 @@ func vmToJSON(vm *otto.Otto) {
_ = vm.Set("toJson", toJSON)
}
func vmFromJSON(vm *otto.Otto) {
fromJSON := func(str string) map[string]interface{} {
var dat map[string]interface{}
err := json.Unmarshal([]byte(str), &dat)
if err != nil {
logrus.Errorf("Unable to unmarshal: %v", err)
return dat
}
return dat
}
_ = vm.Set("fromJSON", fromJSON)
_ = vm.Set("fromJson", fromJSON)
}
func (rc *RunContext) vmHashFiles() func(*otto.Otto) {
return func(vm *otto.Otto) {
_ = vm.Set("hashFiles", func(path string) string {