Skip to content

Commit

Permalink
Fixed failing tests and addressed PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Carlson committed Mar 28, 2023
1 parent 5482fb0 commit e6bc410
Show file tree
Hide file tree
Showing 13 changed files with 414 additions and 467 deletions.
16 changes: 8 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
github.com/buildpacks/imgutil v0.0.0-20220527150729-7a271a852e31
github.com/buildpacks/lifecycle v0.14.1
github.com/ghodss/yaml v1.0.0
github.com/go-git/go-billy/v5 v5.4.0
github.com/go-git/go-git/v5 v5.6.0
github.com/google/go-cmp v0.5.9
github.com/google/go-containerregistry v0.12.1
Expand All @@ -27,7 +26,7 @@ require (
github.com/vdemeester/k8s-pkg-credentialprovider v1.22.4
github.com/whilp/git-urls v1.0.0
go.uber.org/zap v1.23.0
golang.org/x/crypto v0.3.0
golang.org/x/crypto v0.7.0
golang.org/x/sync v0.1.0
k8s.io/api v0.24.8
k8s.io/apimachinery v0.24.8
Expand Down Expand Up @@ -133,6 +132,7 @@ require (
github.com/fullstorydev/grpcurl v1.8.7 // indirect
github.com/go-chi/chi v4.1.2+incompatible // indirect
github.com/go-git/gcfg v1.5.0 // indirect
github.com/go-git/go-billy/v5 v5.4.0 // indirect
github.com/go-kit/log v0.2.0 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-logr/logr v1.2.3 // indirect
Expand Down Expand Up @@ -294,14 +294,14 @@ require (
go.uber.org/automaxprocs v1.5.1 // indirect
go.uber.org/multierr v1.8.0 // indirect
golang.org/x/exp v0.0.0-20220823124025-807a23277127 // indirect
golang.org/x/mod v0.6.0 // indirect
golang.org/x/net v0.2.0 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/oauth2 v0.1.0 // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/term v0.2.0 // indirect
golang.org/x/text v0.4.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/term v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af // indirect
golang.org/x/tools v0.2.0 // indirect
golang.org/x/tools v0.6.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/api v0.99.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand Down
21 changes: 14 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1728,8 +1728,9 @@ golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
golang.org/x/crypto v0.3.0 h1:a06MkbcxBrEFc0w0QIZWXrH/9cCX6KJyWbBOIwAn+7A=
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down Expand Up @@ -1771,8 +1772,9 @@ golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.5.0/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.6.0 h1:b9gGHsz9/HhJ3HF5DHQytPpuwocVTChQJK3AvoLRD5I=
golang.org/x/mod v0.6.0/go.mod h1:4mET923SAdbXp2ki8ey+zGs1SLqsuM2Y0uvdZR/fUNI=
golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -1851,8 +1853,9 @@ golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e/go.mod h1:XRhObCWvk6IyKnWLug
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
golang.org/x/net v0.2.0 h1:sZfSu1wtKLGlWI4ZZayP0ck9Y73K1ynO6gqzTdBVdPU=
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -2015,17 +2018,19 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.2.0 h1:z85xZCsEl7bi/KwbNADeBYoOP0++7W1ipu+aGnpwzRM=
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw=
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand All @@ -2035,8 +2040,9 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down Expand Up @@ -2132,8 +2138,9 @@ golang.org/x/tools v0.1.6-0.20210820212750-d4cc65f0b2ff/go.mod h1:YD9qOF0M9xpSpd
golang.org/x/tools v0.1.10-0.20220218145154-897bd77cd717/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.2.0 h1:G6AHpWxTMGY1KyEYoAQ5WTtIekUUvDNjan3ugu60JvE=
golang.org/x/tools v0.2.0/go.mod h1:y4OqIKeOV/fWJetJ8bXPU1sEVniLMIyDAZWeHdV+NTA=
golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
4 changes: 2 additions & 2 deletions hack/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function compile() {
completion_image=${IMAGE_PREFIX}completion
lifecycle_image=${IMAGE_PREFIX}lifecycle

pack_build ${controller_image} "./cmd/controller" -e BP_GIT2GO_ENABLED=true -e BP_GIT2GO_USE_LIBSSL=true
pack_build ${controller_image} "./cmd/controller"
controller_image=${resolved_image_name}

pack_build ${build_waiter_image} "./cmd/build-waiter"
Expand All @@ -44,7 +44,7 @@ function compile() {
pack_build ${webhook_image} "./cmd/webhook"
webhook_image=${resolved_image_name}

pack_build ${build_init_image} "./cmd/build-init" -e BP_GIT2GO_ENABLED=true -e BP_GIT2GO_USE_LIBSSL=true
pack_build ${build_init_image} "./cmd/build-init"
build_init_image=${resolved_image_name}

pack_build ${rebase_image} "./cmd/rebase"
Expand Down
113 changes: 49 additions & 64 deletions pkg/git/fetch.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package git

import (
"github.com/BurntSushi/toml"
gogit "github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"log"
"net/http"
"net/url"
"os"
"path"
"time"

// import RemoteConfig
"github.com/BurntSushi/toml"
gogit "github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/config"

"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/transport"
"github.com/go-git/go-git/v5/plumbing/transport/client"
githttp "github.com/go-git/go-git/v5/plumbing/transport/http"
"github.com/pkg/errors"
)

Expand All @@ -21,8 +25,11 @@ type Fetcher struct {

func (f Fetcher) Fetch(dir, gitURL, gitRevision, metadataDir string) error {
f.Logger.Printf("Cloning %q @ %q...", gitURL, gitRevision)
auth, err := f.Keychain.Resolve(gitURL)
if err != nil {
return err
}

// Initialize a repository in the directory using gogit.Init
repository, err := gogit.PlainInit(dir, false)
if err != nil {
return errors.Wrap(err, "initializing repo")
Expand All @@ -36,44 +43,37 @@ func (f Fetcher) Fetch(dir, gitURL, gitRevision, metadataDir string) error {
return errors.Wrap(err, "creating remote")
}

err = remote.Fetch(&gogit.FetchOptions{
RefSpecs: []config.RefSpec{
config.RefSpec("refs/*:refs/*"),
},
Auth: nil,
Tags: gogit.AllTags,
RemoteName: defaultRemote,
})
httpsTransport, err := getHttpsTransport()
if err != nil {
return errors.Wrap(err, "fetching remote")
return err
}
client.InstallProtocol("https", httpsTransport)

hash, err := resolveRevision(repository, gitRevision)
if err != nil {
return errors.Wrap(err, "resolving revision")
err = remote.Fetch(&gogit.FetchOptions{
RefSpecs: []config.RefSpec{"refs/*:refs/*"},
Auth: auth,
})
if err != nil && err != transport.ErrAuthenticationRequired {
return errors.Wrapf(err, "unable to fetch references for repository")
} else if err == transport.ErrAuthenticationRequired {
return errors.Wrapf(err, "invalid credentials for repository")
}

// Look up the commit using the hash
commit, err := repository.CommitObject(*hash)
worktree, err := repository.Worktree()
if err != nil {
return errors.Wrap(err, "looking up commit")
return errors.Wrapf(err, "getting worktree for repository")
}

worktree, err := repository.Worktree()
hash, err := repository.ResolveRevision(plumbing.Revision(gitRevision))
if err != nil {
return errors.Wrap(err, "getting worktree")
return errors.Wrapf(err, "resolving revision")
}

err = worktree.Checkout(&gogit.CheckoutOptions{})
err = worktree.Checkout(&gogit.CheckoutOptions{Hash: *hash})
if err != nil {
return errors.Wrap(err, "checking out blank")
return errors.Wrapf(err, "checking out revision")
}

err = worktree.Checkout(&gogit.CheckoutOptions{
Hash: plumbing.NewHash(hash.String()),
Create: false,
})

// Write the git revision to the metadata directory
projectMetadataFile, err := os.Create(path.Join(metadataDir, "project-metadata.toml"))
if err != nil {
Expand All @@ -89,7 +89,7 @@ func (f Fetcher) Fetch(dir, gitURL, gitRevision, metadataDir string) error {
Revision: gitRevision,
},
Version: version{
Commit: commit.Hash.String(),
Commit: hash.String(),
},
},
}
Expand All @@ -101,42 +101,27 @@ func (f Fetcher) Fetch(dir, gitURL, gitRevision, metadataDir string) error {
return nil
}

// Implement resolveRevision and return a plumbing.Hash and error
func resolveRevision(repository *gogit.Repository, gitRevision string) (*plumbing.Hash, error) {
ref, err := repository.ResolveRevision(plumbing.Revision(gitRevision))
if err != nil {
return resolveCommit(gitRevision)
}
return ref, nil
}

func resolveCommit(gitRevision string) (*plumbing.Hash, error) {
// Use plumbing.NewHash to create a new hash
hash := plumbing.NewHash(gitRevision)
// if hash is empty
if hash == plumbing.ZeroHash {
return nil, errors.Errorf("could not find reference: %s", gitRevision) //invalid hash
func getHttpsTransport() (transport.Transport, error) {
if httpsProxy, exists := os.LookupEnv("HTTPS_PROXY"); exists {
parsedUrl, err := url.Parse(httpsProxy)
if err != nil {
return nil, errors.Wrap(err, "parsing HTTPS_PROXY url")
}
proxyClient := &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyURL(parsedUrl),
},
Timeout: 15 * time.Second,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
}
return githttp.NewClient(proxyClient), nil
} else {
return githttp.DefaultClient, nil
}
return &hash, nil
}

//func resolveRevision(repository *git2go.Repository, gitRevision string) (*git2go.Oid, error) {
// ref, err := repository.References.Dwim(gitRevision)
// if err != nil {
// return resolveCommit(gitRevision)
// }
//
// return ref.Target(), nil
//}

//func resolveCommit(gitRevision string) (*git2go.Oid, error) {
// oid, err := git2go.NewOid(gitRevision)
// if err != nil {
// return nil, errors.Errorf("could not find reference: %s", gitRevision) //invalid oid
// }
// return oid, nil
//}

type project struct {
Source source `toml:"source"`
}
Expand Down
Loading

0 comments on commit e6bc410

Please sign in to comment.