Skip to content

Commit

Permalink
Leverage project's URL instead of constructing a full one.
Browse files Browse the repository at this point in the history
Also, ensure an updated build script with commit ID is always written.
  • Loading branch information
mitchell-as committed Oct 18, 2024
1 parent 6430b81 commit 34781f0
Showing 1 changed file with 3 additions and 24 deletions.
27 changes: 3 additions & 24 deletions internal/runbits/buildscript/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package buildscript_runbit

import (
"errors"
"fmt"
"net/url"
"os"
"path/filepath"
Expand All @@ -22,9 +21,7 @@ import (
// projecter is a union between project.Project and setup.Targeter
type projecter interface {
Dir() string
Owner() string
Name() string
BranchName() string
URL() string
}

var ErrBuildscriptNotExist = errors.New("Build script does not exist")
Expand Down Expand Up @@ -87,37 +84,19 @@ func Initialize(proj projecter, auth *authentication.Auth, svcm *model.SvcModel)
return nil
}

// projectURL returns proj.URL(), but with the given, updated commitID.
func projectURL(proj projecter, commitID string) (string, error) {
// Note: cannot use api.GetPlatformURL() due to import cycle.
host := constants.DefaultAPIHost
if hostOverride := os.Getenv(constants.APIHostEnvVarName); hostOverride != "" {
host = hostOverride
}
u, err := url.Parse(fmt.Sprintf("https://%s/%s/%s", host, proj.Owner(), proj.Name()))
u, err := url.Parse(proj.URL())
if err != nil {
return "", errs.Wrap(err, "Unable to parse URL")
}
q := u.Query()
q.Set("branch", proj.BranchName())
q.Set("commitID", commitID)
u.RawQuery = q.Encode()
return u.String(), nil
}

func Update(proj projecter, newScript *buildscript.BuildScript) error {
script, err := ScriptFromProject(proj)
if err != nil {
return errs.Wrap(err, "Could not read build script")
}

equals, err := script.Equals(newScript)
if err != nil {
return errs.Wrap(err, "Could not compare build script")
}
if script != nil && equals {
return nil // no changes to write
}

// Update the new script's project field to match the current one, except for a new commit ID.
commitID, err := localcommit.Get(proj.Dir())
if err != nil {
Expand Down

0 comments on commit 34781f0

Please sign in to comment.