Sha256: 15da84c623d81fe37e06869f4c38b2fbae23ed0ea4ed8581dd20bf44bab0c4d4

Contents?: true

Size: 872 Bytes

Versions: 696

Compression:

Stored size: 872 Bytes

Contents

package updater

import (
	"io/ioutil"

	"github.com/dependabot/gomodules-extracted/cmd/go/_internal_/modfile"
)

type Dependency struct {
	Name     string `json:"name"`
	Version  string `json:"version"`
	Indirect bool   `json:"indirect"`
}

type Args struct {
	Dependencies []Dependency `json:"dependencies"`
}

func UpdateDependencyFile(args *Args) (interface{}, error) {
	data, err := ioutil.ReadFile("go.mod")
	if err != nil {
		return nil, err
	}

	f, err := modfile.Parse("go.mod", data, nil)
	if err != nil {
		return nil, err
	}

	for _, dep := range args.Dependencies {
		f.AddRequire(dep.Name, dep.Version)
	}

	for _, r := range f.Require {
		for _, dep := range args.Dependencies {
			if r.Mod.Path == dep.Name {
				setIndirect(r.Syntax, dep.Indirect)
			}
		}
	}

	f.SortBlocks()
	f.Cleanup()

	newModFile, _ := f.Format()

	return string(newModFile), nil
}

Version data entries

696 entries across 696 versions & 2 rubygems

Version Path
dependabot-go_modules-0.124.4 helpers/updater/main.go
dependabot-go_modules-0.124.3 helpers/updater/main.go
dependabot-go_modules-0.124.2 helpers/updater/main.go
dependabot-go_modules-0.124.1 helpers/updater/main.go
dependabot-go_modules-0.124.0 helpers/updater/main.go
dependabot-go_modules-0.123.1 helpers/updater/main.go
dependabot-go_modules-0.123.0 helpers/updater/main.go
dependabot-go_modules-0.122.1 helpers/updater/main.go
dependabot-go_modules-0.122.0 helpers/updater/main.go
dependabot-go_modules-0.121.1 helpers/updater/main.go
dependabot-go_modules-0.121.0 helpers/updater/main.go
dependabot-go_modules-0.120.5 helpers/updater/main.go
dependabot-go_modules-0.120.4 helpers/updater/main.go
dependabot-go_modules-0.120.3 helpers/updater/main.go
dependabot-go_modules-0.120.2 helpers/updater/main.go
dependabot-go_modules-0.120.1 helpers/updater/main.go
dependabot-go_modules-0.120.0 helpers/updater/main.go
dependabot-go_modules-0.119.6 helpers/updater/main.go
dependabot-go_modules-0.119.5 helpers/updater/main.go
dependabot-go_modules-0.119.4 helpers/updater/main.go