Skip to content

Commit 75f0f06

Browse files
committed
added new core changes
1 parent 3b7657e commit 75f0f06

File tree

3 files changed

+44
-8
lines changed

3 files changed

+44
-8
lines changed

artifactory/commands/npm/npmPublishHandler.go

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,35 @@ import (
1010
"github.com/jfrog/jfrog-client-go/artifactory/services"
1111
specutils "github.com/jfrog/jfrog-client-go/artifactory/services/utils"
1212
"github.com/jfrog/jfrog-client-go/utils/log"
13+
"strings"
1314
)
1415

1516
type npmPublish struct {
1617
*NpmPublishCommand
1718
}
1819

19-
func (npu *npmPublish) upload() (err error) {
20+
func (npu *npmPublish) upload() error {
2021
for _, packedFilePath := range npu.packedFilePaths {
2122

22-
if err = npu.readPackageInfoFromTarball(packedFilePath); err != nil {
23+
if err := npu.readPackageInfoFromTarball(packedFilePath); err != nil {
2324
return err
2425
}
25-
target := fmt.Sprintf("%s/%s", npu.repo, npu.packageInfo.GetDeployPath())
26+
27+
targetRepo, err := npu.getTargetRepo()
28+
if err != nil {
29+
return err
30+
}
31+
target := fmt.Sprintf("%s/%s", targetRepo, npu.packageInfo.GetDeployPath())
2632

2733
// If requested, perform a Xray binary scan before deployment. If a FailBuildError is returned, skip the deployment.
2834
if npu.xrayScan {
2935
if err = performXrayScan(packedFilePath, npu.repo, npu.serverDetails, npu.scanOutputFormat); err != nil {
30-
return
36+
return err
3137
}
3238
}
3339
err = errors.Join(err, npu.publishPackage(npu.executablePath, packedFilePath, npu.serverDetails, target))
3440
}
35-
return err
41+
return nil
3642
}
3743

3844
func (npu *npmPublish) getBuildArtifacts() ([]buildinfo.Artifact, error) {
@@ -82,3 +88,33 @@ func (npu *npmPublish) publishPackage(executablePath, filePath string, serverDet
8288
}
8389
return nil
8490
}
91+
92+
func (npu *NpmPublishCommand) getTargetRepo() (string, error) {
93+
var registryString string
94+
scope := npu.packageInfo.Scope
95+
if scope == "" {
96+
registryString = "registry"
97+
} else {
98+
registryString = scope + ":registry"
99+
}
100+
configCommand := gofrogcmd.Command{
101+
Executable: npu.executablePath,
102+
CmdName: "config",
103+
CmdArgs: []string{"get", registryString},
104+
}
105+
data, err := configCommand.RunWithOutput()
106+
repoConfig := string(data)
107+
if err != nil {
108+
log.Error("Error occurred while running npm config get: ", err)
109+
npu.result.SetFailCount(npu.result.FailCount() + 1)
110+
return "", err
111+
}
112+
return extractRepoName(repoConfig), nil
113+
}
114+
115+
func extractRepoName(configUrl string) string {
116+
url := strings.TrimSpace(configUrl)
117+
urlParts := strings.Split(url, "/")
118+
repoName := urlParts[len(urlParts)-1]
119+
return repoName
120+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ require (
121121
sigs.k8s.io/yaml v1.4.0 // indirect
122122
)
123123

124-
replace github.com/jfrog/jfrog-cli-core/v2 => github.com/fluxxBot/jfrog-cli-core/v2 v2.31.1-0.20250413220436-b46ff5daaf5e
124+
replace github.com/jfrog/jfrog-cli-core/v2 => github.com/fluxxBot/jfrog-cli-core/v2 v2.31.1-0.20250420214742-c12c4050641f
125125

126126
replace github.com/jfrog/jfrog-client-go => github.com/fluxxBot/jfrog-client-go v1.28.1-0.20250413214704-1b6cdf0520c6
127127

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ github.com/elazarl/goproxy v1.7.2 h1:Y2o6urb7Eule09PjlhQRGNsqRfPmYI3KKQLFpCAV3+o
5454
github.com/elazarl/goproxy v1.7.2/go.mod h1:82vkLNir0ALaW14Rc399OTTjyNREgmdL2cVoIbS6XaE=
5555
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
5656
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
57-
github.com/fluxxBot/jfrog-cli-core/v2 v2.31.1-0.20250413220436-b46ff5daaf5e h1:q0BinSmz7ZhYbkuow5I+R3DhOIHFIcKk/ZxkE/GSW1w=
58-
github.com/fluxxBot/jfrog-cli-core/v2 v2.31.1-0.20250413220436-b46ff5daaf5e/go.mod h1:eV3CTP/F4nEYE7p4WojZc4ruU1/3sXj0o/ctnjmO5fw=
57+
github.com/fluxxBot/jfrog-cli-core/v2 v2.31.1-0.20250420214742-c12c4050641f h1:SdMa2iO2PqNegvh57uHkWy/00RySEO/CeiZCSa9rT8w=
58+
github.com/fluxxBot/jfrog-cli-core/v2 v2.31.1-0.20250420214742-c12c4050641f/go.mod h1:nrKlwWRT7BT9TqE51WSIpUlO8uQR6qWHlp3UiKqC4nc=
5959
github.com/fluxxBot/jfrog-client-go v1.28.1-0.20250413214704-1b6cdf0520c6 h1:krAN+7hGggGDXfAlcC8eni2QxWfW7I5JVNPvhI3vS4U=
6060
github.com/fluxxBot/jfrog-client-go v1.28.1-0.20250413214704-1b6cdf0520c6/go.mod h1:uRmT8Q1SJymIzId01v0W1o8mGqrRfrwUF53CgEMsH0U=
6161
github.com/forPelevin/gomoji v1.3.0 h1:WPIOLWB1bvRYlKZnSSEevLt3IfKlLs+tK+YA9fFYlkE=

0 commit comments

Comments
 (0)