Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@graphaelli
Last active February 3, 2020 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save graphaelli/714f4965ecf9530c45c77b69334030b5 to your computer and use it in GitHub Desktop.
Save graphaelli/714f4965ecf9530c45c77b69334030b5 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import json
import os
def direct_dep(pkg):
for d in {
"github.com/Bowery/prompt",
"github.com/apache/thrift",
"github.com/cespare/xxhash",
"github.com/dchest/safefile",
"github.com/elastic/apm-agent-go",
"github.com/elastic/beats",
"github.com/elastic/go-elasticsearch",
"github.com/go-sourcemap/sourcemap",
"github.com/gofrs/uuid",
"github.com/gogo",
"github.com/golang/groupcache/lru",
"github.com/golang/lint",
"github.com/google/addlicense",
"github.com/google/go-github/github",
"github.com/google/go-querystring",
"github.com/google/pprof",
"github.com/google/shlex",
"github.com/grpc-ecosystem/grpc-gateway",
"github.com/hashicorp/golang-lru",
"github.com/haya14busa/errorformat",
"github.com/haya14busa/reviewdog",
"github.com/jaegertracing/jaeger",
"github.com/kabukky/httpscerts",
"github.com/kardianos/govendor",
"github.com/mattn/go-shellwords",
"github.com/open-telemetry/opentelemetry-collector",
"github.com/opentracing/opentracing-go",
"github.com/patrickmn/go-cache",
"github.com/pierrre/gotestcover",
"github.com/reviewdog/errorformat",
"github.com/reviewdog/reviewdog",
"github.com/ryanuber/go-glob",
"github.com/santhosh-tekuri/jsonschema",
"github.com/sergi/go-diff/diffmatchpatch",
"github.com/stretchr/testify",
"github.com/t-yuki/gocover-cobertura",
"github.com/uber/tchannel-go",
"github.com/xanzy/go-gitlab",
"github.com/yudai/gojsondiff",
"go.elastic.co/apm",
"golang.org/x/lint",
"golang.org/x/net/netutil",
"golang.org/x/sync/errgroup",
"golang.org/x/tools/cmd/benchcmp",
"golang.org/x/tools/cmd/goimports",
"golang.org/x/tools/go/ast/astutil",
"golang.org/x/tools/imports",
"golang.org/x/tools/internal/fastwalk",
"golang.org/x/tools/internal/gopathwalk",
}:
if pkg.startswith(d):
return True
def main():
with open("vendor/vendor.json") as f:
vendor = json.load(f)
with open("_beats/vendor/vendor.json") as f:
beats_vendor = json.load(f)
beats_packages = [p["path"] for p in beats_vendor["package"]]
packages = []
for package in vendor["package"]:
origin = package.get("origin")
path = package["path"]
pkg_vendor_path = os.path.join("vendor", path)
if not os.path.exists(pkg_vendor_path):
print(f"{path} is missing, removing...")
continue
if "origin" in package:
if pkg_vendor_path not in package["origin"]:
print(f"{path} origin {origin} is incorrect")
else:
if direct_dep(path):
pass
elif path in beats_packages:
print(f"{path} has no origin but pulled in from beats")
package["origin"] = f"github.com/elastic/beats/vendor/{path}"
else: # not direct_dep(path):
print(f"{path} missing origin but it's not from beats")
packages.append(package)
vendor["package"] = packages
with open("vendor/vendor.json", "w") as f:
json.dump(vendor, f, indent="\t", sort_keys=True)
f.write("\n")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment