-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from 030/gh7-uploads3
Gh7 uploads3
- Loading branch information
Showing
69 changed files
with
443 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ | |
*.pom* | ||
.vscode | ||
maven-metadata* | ||
download | ||
download |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
mp "github.com/030/go-curl/utils" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
var foldersWithPOM strings.Builder | ||
|
||
func (n Nexus3) detectFoldersWithPOM(d string) error { | ||
err := filepath.Walk(d, func(path string, f os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
if !f.IsDir() && filepath.Ext(path) == ".pom" { | ||
fmt.Println(path) | ||
foldersWithPOM.WriteString(filepath.Dir(path) + ",") | ||
} | ||
return nil | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
// Upload posts an artifact as a multipart to a specific nexus3 repository | ||
func (n Nexus3) Upload() error { | ||
err3 := n.detectFoldersWithPOM(n.Repository) | ||
if err3 != nil { | ||
return err3 | ||
} | ||
|
||
foldersWithPOMString := strings.TrimSuffix(foldersWithPOM.String(), ",") | ||
foldersWithPOMStringSlice := strings.Split(foldersWithPOMString, ",") | ||
|
||
for _, v := range foldersWithPOMStringSlice { | ||
var s strings.Builder | ||
err := filepath.Walk(v, func(path string, f os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if !f.IsDir() { | ||
if filepath.Ext(path) == ".pom" { | ||
log.Debug("POM found " + path) | ||
s.WriteString("maven2.asset1=@" + path + ",") | ||
s.WriteString("maven2.asset1.extension=pom,") | ||
} | ||
|
||
if filepath.Ext(path) == ".jar" { | ||
log.Debug("JAR found " + path) | ||
s.WriteString("maven2.asset2=@" + path + ",") | ||
s.WriteString("maven2.asset2.extension=jar,") | ||
} | ||
|
||
if filepath.Ext(path) == ".war" { | ||
log.Debug("WAR found " + path) | ||
s.WriteString("maven2.asset3=@" + path + ",") | ||
s.WriteString("maven2.asset3.extension=war,") | ||
} | ||
} | ||
return nil | ||
}) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
multipartString := strings.TrimSuffix(s.String(), ",") | ||
url := n.URL + "/service/rest/" + n.APIVersion + "/components?repository=" + n.Repository | ||
log.WithFields(log.Fields{ | ||
"multipart": multipartString, | ||
"url": url, | ||
}).Debug("URL") | ||
|
||
u := mp.Upload{URL: url, Username: n.User, Password: n.Pass} | ||
err2 := u.MultipartUpload(multipartString) | ||
if err2 != nil { | ||
return err2 | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package cli | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestUploads(t *testing.T) { | ||
err := n.Upload() | ||
want := "HTTPStatusCode: '400'; ResponseMessage: 'Repository does not allow updating assets: maven-releases'; ErrorMessage: '<nil>'" | ||
if err.Error() == want { | ||
t.Errorf("Error expected. Got '%v'. Want '%v'", err, want) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.