Sha256: 43d8659cf5bd741953741dac0e5d4bca930fcfacedc24cdea1e21719ce610dc7

Contents?: true

Size: 1.63 KB

Versions: 64

Compression:

Stored size: 1.63 KB

Contents

package main

import (
	"encoding/json"
	"fmt"
	"log"
	"os"

	"github.com/dependabot/dependabot-core/helpers/go/importresolver"
	"github.com/dependabot/dependabot-core/helpers/go/updatechecker"
	"github.com/dependabot/dependabot-core/helpers/go/updater"
)

type HelperParams struct {
	Function string          `json:"function"`
	Args     json.RawMessage `json:"args"`
}

type Output struct {
	Error  string      `json:"error,omitempty"`
	Result interface{} `json:"result,omitempty"`
}

func main() {
	d := json.NewDecoder(os.Stdin)
	helperParams := &HelperParams{}
	if err := d.Decode(helperParams); err != nil {
		abort(err)
	}

	var (
		funcOut interface{}
		funcErr error
	)
	switch helperParams.Function {
	case "getUpdatedVersion":
		var args updatechecker.Args
		parseArgs(helperParams.Args, &args)
		funcOut, funcErr = updatechecker.GetUpdatedVersion(&args)
	case "updateDependencyFile":
		var args updater.Args
		parseArgs(helperParams.Args, &args)
		funcOut, funcErr = updater.UpdateDependencyFile(&args)
	case "getVcsRemoteForImport":
		var args importresolver.Args
		parseArgs(helperParams.Args, &args)
		funcOut, funcErr = importresolver.VCSRemoteForImport(&args)
	default:
		abort(fmt.Errorf("Unrecognised function '%s'", helperParams.Function))
	}

	if funcErr != nil {
		abort(funcErr)
	}

	output(&Output{Result: funcOut})
}

func parseArgs(data []byte, args interface{}) {
	if err := json.Unmarshal(data, args); err != nil {
		abort(err)
	}
}

func output(o *Output) {
	bytes, jsonErr := json.Marshal(o)
	if jsonErr != nil {
		log.Fatal(jsonErr)
	}

	os.Stdout.Write(bytes)
}

func abort(err error) {
	output(&Output{Error: err.Error()})
	os.Exit(1)
}

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
dependabot-core-0.86.25 helpers/go/main.go
dependabot-core-0.86.24 helpers/go/main.go
dependabot-core-0.86.23 helpers/go/main.go
dependabot-core-0.86.22 helpers/go/main.go
dependabot-core-0.86.21 helpers/go/main.go
dependabot-core-0.86.20 helpers/go/main.go
dependabot-core-0.86.19 helpers/go/main.go
dependabot-core-0.86.18 helpers/go/main.go
dependabot-core-0.86.17 helpers/go/main.go
dependabot-core-0.86.16 helpers/go/main.go
dependabot-core-0.86.15 helpers/go/main.go
dependabot-core-0.86.14 helpers/go/main.go
dependabot-core-0.86.13 helpers/go/main.go
dependabot-core-0.86.12 helpers/go/main.go
dependabot-core-0.86.11 helpers/go/main.go
dependabot-core-0.86.10 helpers/go/main.go
dependabot-core-0.86.9 helpers/go/main.go
dependabot-core-0.86.8 helpers/go/main.go
dependabot-core-0.86.7 helpers/go/main.go
dependabot-core-0.86.6 helpers/go/main.go