Skip to content

Commit

Permalink
fix: remove some dead code
Browse files Browse the repository at this point in the history
stop using draft library unnecessarily
add version command

related to jenkins-x/jx#8670
  • Loading branch information
msvticket committed Jan 10, 2025
1 parent 1887069 commit c2d89cc
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 420 deletions.
17 changes: 9 additions & 8 deletions pkg/cmd/importcmd/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package importcmd
import (
"fmt"
"io"
"io/fs"
"os"
"path/filepath"
"strings"
Expand All @@ -11,7 +12,6 @@ import (
"helm.sh/helm/v3/pkg/chart/loader"
"helm.sh/helm/v3/pkg/chartutil"

"github.com/Azure/draft/pkg/osutil"
"github.com/jenkins-x/jx-helpers/v3/pkg/files"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -73,14 +73,15 @@ func (p *Pack) SaveDir(dest, packName string) error {
// save the rest of the files
for relPath, f := range p.Files {
path := filepath.Join(dest, relPath)
exists, err := osutil.Exists(path)
_, err := os.Stat(path)
if err != nil {
return errors.Wrapf(err, "failed to check if path exists %s", path)
}
if !exists {
err := saveFile(path, f)
if err != nil {
return err
if errors.Is(err, fs.ErrNotExist) {
err := saveFile(path, f)
if err != nil {
return err
}
} else {
return fmt.Errorf("failed to check if path exists %s: %w", path, err)
}
}
}
Expand Down
10 changes: 0 additions & 10 deletions pkg/cmd/root/enable/enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import (
"github.com/jenkins-x-plugins/jx-project/pkg/cmd/importcmd"
"github.com/jenkins-x/jx-helpers/v3/pkg/cobras/helper"
"github.com/jenkins-x/jx-helpers/v3/pkg/cobras/templates"
"github.com/jenkins-x/lighthouse-client/pkg/triggerconfig"
"github.com/spf13/cobra"
tektonv1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
)

// Options contains the command line options
Expand All @@ -32,14 +30,6 @@ var (
`)
)

// Trigger the found trigger configs
type Trigger struct {
Path string
Config *triggerconfig.Config
Names []string
Pipelines map[string]*tektonv1beta1.PipelineRun
}

// NewCmdPipelineEnable creates the command
func NewCmdPipelineEnable() (*cobra.Command, *Options) {
o := &Options{}
Expand Down
3 changes: 3 additions & 0 deletions pkg/cmd/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"os"

"github.com/jenkins-x-plugins/jx-project/pkg/cmd/root/version"

"github.com/jenkins-x-plugins/jx-project/pkg/cmd/root/enable"

"github.com/jenkins-x-plugins/jx-project/pkg/cmd/common"
Expand Down Expand Up @@ -83,6 +85,7 @@ func NewCmdMain() (*cobra.Command, *WizardOptions) {
cmd.AddCommand(NewCmdCreateSpring())
cmd.AddCommand(importcmd.NewCmdImport())
cmd.AddCommand(pullrequest.NewCmdCreatePullRequest())
cmd.AddCommand(version.NewCmdVersion())

return cmd, options
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/root/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type Options struct {
}

// NewCmdVersion creates a command object for the "version" command
func NewCmdVersion() (*cobra.Command, *Options) {
func NewCmdVersion() *cobra.Command {
o := &Options{}

cmd := &cobra.Command{
Expand All @@ -42,7 +42,7 @@ func NewCmdVersion() (*cobra.Command, *Options) {
helper.CheckErr(err)
},
}
return cmd, o
return cmd
}

// Run implements the command
Expand Down
40 changes: 1 addition & 39 deletions pkg/draft/draft.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,16 @@ import (
"fmt"
"io"
"os"
"path"
"path/filepath"
"strings"

"github.com/Azure/draft/pkg/draft/draftpath"
"github.com/Azure/draft/pkg/draft/pack/repo"

"github.com/Azure/draft/pkg/linguist"
"github.com/jenkins-x/jx-logging/v3/pkg/log"
)

// copied from draft so we can change the $DRAFT_HOME to ~/.jx/draft and lookup jx draft packs
// copied from draft so we can change to lookup jx draft packs
// credit original from: https://github.com/Azure/draft/blob/8e1a459/cmd/draft/create.go#L163

// DoPackDetection performs pack detection across all the packs available in $(draft home)/packs in
// alphabetical order, returning the pack dirpath and any errors that occurred during the pack detection.
func DoPackDetection(home draftpath.Home, out io.Writer, dir string) (string, error) {
log.Logger().Infof("performing pack detection in folder %s", dir)
langs, err := linguist.ProcessDir(dir)
if err != nil {
return "", fmt.Errorf("there was an error detecting the language: %s", err)
}
if len(langs) == 0 {
return "", fmt.Errorf("there was an error detecting the language")
}
for _, lang := range langs {
detectedLang := linguist.Alias(lang)
fmt.Fprintf(out, "--> Draft detected %s (%f%%)\n", detectedLang.Language, detectedLang.Percent)
for _, repository := range repo.FindRepositories(home.Packs()) {
packDir := path.Join(repository.Dir, repo.PackDirName)
packs, err := os.ReadDir(packDir)
if err != nil {
return "", fmt.Errorf("there was an error reading %s: %v", packDir, err)
}
for _, file := range packs {
if file.IsDir() {
if strings.EqualFold(detectedLang.Language, file.Name()) {
packPath := filepath.Join(packDir, file.Name())
return packPath, nil
}
}
}
}
fmt.Fprintf(out, "--> Could not find a pack for %s. Trying to find the next likely language match...\n", detectedLang.Language)
}
return "", fmt.Errorf("there was an error detecting the language using packs from %s", home.Packs())
}

// DoPackDetectionForBuildPack performs detection of the language based on a sepcific build pack
func DoPackDetectionForBuildPack(out io.Writer, dir, packDir string) (string, error) {
log.Logger().Infof("performing pack detection in folder %s", dir)
Expand Down
46 changes: 0 additions & 46 deletions pkg/matcher/matcher.go

This file was deleted.

Loading

0 comments on commit c2d89cc

Please sign in to comment.