Skip to content

Commit b86a4fc

Browse files
committed
final fixes
1 parent 73cd449 commit b86a4fc

File tree

3 files changed

+9
-115
lines changed

3 files changed

+9
-115
lines changed

dgctl/cmd/exec.go

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,6 @@ func getRepoUsername() (string, error) {
4343
return strings.TrimSpace(string(out)), err
4444
}
4545

46-
func getDefaultBranch() (string, error) {
47-
cmd := exec.Command("git", "symbolic-ref", "refs/remotes/origin/HEAD")
48-
out, err := cmd.Output()
49-
return strings.ReplaceAll(strings.TrimSpace(string(out)), "refs/remotes/origin/", ""), err
50-
}
51-
52-
func getPrBranch() (string, error) {
53-
cmd := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD")
54-
out, err := cmd.Output()
55-
return strings.TrimSpace(string(out)), err
56-
}
57-
5846
func getRepoFullname() (string, error) {
5947
// Execute 'git config --get remote.origin.url' to get the URL of the origin remote
6048
cmd := exec.Command("git", "config", "--get", "remote.origin.url")
@@ -142,11 +130,6 @@ func GetSpec(diggerUrl string, authToken string, command string, actor string, p
142130

143131
return body, nil
144132
}
145-
func pushToBranch(prBranch string) error {
146-
cmd := exec.Command("git", "push", "origin", prBranch)
147-
_, err := cmd.Output()
148-
return err
149-
}
150133

151134
func GetWorkflowIdAndUrlFromDiggerJobId(client *github.Client, repoOwner string, repoName string, diggerJobID string) (*int64, *int64, *string, error) {
152135
timeFilter := time.Now().Add(-5 * time.Minute)
@@ -234,18 +217,6 @@ var execCmd = &cobra.Command{
234217
os.Exit(1)
235218
}
236219

237-
//defaultBanch, err := getDefaultBranch()
238-
//if err != nil {
239-
// log.Printf("could not get default branch, please enter manually:")
240-
// fmt.Scanln(&defaultBanch)
241-
//}
242-
243-
//prBranch, err := getPrBranch()
244-
//if err != nil {
245-
// log.Printf("could not get current branch, please enter manually:")
246-
// fmt.Scanln(&prBranch)
247-
//}
248-
249220
projectName := execConfig.Project
250221
command := execConfig.Command
251222
projectConfig := config.GetProject(projectName)
@@ -269,13 +240,18 @@ var execCmd = &cobra.Command{
269240
specBytes, err := GetSpec(diggerHostname, "abc123", command, actor, string(projectMarshalled), string(configMarshalled), repoFullname)
270241
if err != nil {
271242
log.Printf("failed to get spec from backend: %v", err)
243+
os.Exit(1)
272244
}
273245
var spec spec.Spec
274246
err = json.Unmarshal(specBytes, &spec)
275247

276248
// attach zip archive to backend
277249
backendToken := spec.Job.BackendJobToken
278250
zipLocation, err := utils.ArchiveGitRepo("./")
251+
if err != nil {
252+
log.Printf("error archiving zip repo: %v", err)
253+
os.Exit(1)
254+
}
279255
backendApi := backendapi.DiggerApi{DiggerHost: diggerHostname, AuthToken: backendToken}
280256
statusCode, respBody, err := backendApi.UploadJobArtefact(zipLocation)
281257
if err != nil {

dgctl/utils/backendutils.go

Lines changed: 0 additions & 84 deletions
This file was deleted.

dgctl/utils/gitio.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import (
1212
func ArchiveGitRepo(sourcePath string) (string, error) {
1313
// Generate a unique ID for the temp directory
1414
tempID := fmt.Sprintf("%d", time.Now().UnixNano())
15-
tempDir := filepath.Join(os.TempDir(), fmt.Sprintf("temp_%s", tempID))
16-
15+
tempDir, err := os.MkdirTemp("", "archive-zip-")
16+
if err != nil {
17+
return "", fmt.Errorf("failed to create temp dir: %v", err)
18+
}
1719
// Create the temp directory
1820
if err := os.MkdirAll(tempDir, 0755); err != nil {
1921
return "", fmt.Errorf("failed to create temp directory: %w", err)

0 commit comments

Comments
 (0)