Skip to content

Commit

Permalink
feat: update
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-timothy-albert committed Feb 7, 2025
1 parent f56d93d commit 461b8b2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
4 changes: 1 addition & 3 deletions internal/actions/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ func initAction() (*git.Git, error) {
}

g := git.New(accessToken)
r, err := g.CloneRepo(environment.GetRef())
if err != nil {
if err := g.CloneRepo(); err != nil {
return nil, err
}
g.SetRepo(r)
return g, nil
}
17 changes: 8 additions & 9 deletions internal/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,17 @@ func New(accessToken string) *Git {
}
}

func (g *Git) SetRepo(r *git.Repository) {
g.repo = r
}

func (g *Git) CloneRepo(ref string) (*git.Repository, error) {
func (g *Git) CloneRepo() error {
githubURL := os.Getenv("GITHUB_SERVER_URL")
githubRepoLocation := os.Getenv("GITHUB_REPOSITORY")

repoPath, err := url.JoinPath(githubURL, githubRepoLocation)
if err != nil {
return nil, fmt.Errorf("failed to construct repo url: %w", err)
return fmt.Errorf("failed to construct repo url: %w", err)
}

ref := environment.GetRef()

logging.Info("Cloning repo: %s from ref: %s", repoPath, ref)

workspace := environment.GetWorkspace()
Expand All @@ -74,7 +72,7 @@ func (g *Git) CloneRepo(ref string) (*git.Repository, error) {
// Flow is useful when testing locally, but we're usually in a fresh image so unnecessary most of the time
repoDir := path.Join(workspace, "repo")
if err := os.RemoveAll(repoDir); err != nil {
return nil, err
return err
}

r, err := git.PlainClone(path.Join(workspace, "repo"), false, &git.CloneOptions{
Expand All @@ -85,10 +83,11 @@ func (g *Git) CloneRepo(ref string) (*git.Repository, error) {
SingleBranch: true,
})
if err != nil {
return nil, fmt.Errorf("failed to clone repo: %w", err)
return fmt.Errorf("failed to clone repo: %w", err)
}
g.repo = r

return r, nil
return nil
}

func (g *Git) CheckDirDirty(dir string, ignoreChangePatterns map[string]string) (bool, string, error) {
Expand Down

0 comments on commit 461b8b2

Please sign in to comment.