Skip to content

Commit a1887d7

Browse files
ccoVeilleCodeWithEmad
authored andcommitted
fix: deletion logic of repository
Previously, the deletion logic did not clearly indicate which repository was being reviewed for deletion, which could lead to confusion. But also to critical errors, such as deleting the wrong repository. This commit improves the deletion logic by ensuring that the repository being reviewed is clearly indicated in the tool's output. As a consequence, the name of the repository is no longer fetched from the GraphQL API,
1 parent bfe829b commit a1887d7

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

main.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ type Owner struct {
1919
}
2020

2121
type Repo struct {
22-
Name string `json:"name"`
2322
Owner Owner `json:"owner"`
2423
NameWithOwner string `json:"nameWithOwner"`
2524
IsArchived bool `json:"isArchived"`
@@ -138,7 +137,6 @@ func getForks() ([]Repo, error) {
138137
viewer {
139138
repositories(first: 100, after: $after, isFork: true, orderBy: {field: UPDATED_AT, direction: DESC}) {
140139
nodes {
141-
name
142140
nameWithOwner
143141
updatedAt
144142
isArchived
@@ -295,7 +293,7 @@ func cleanupForks(cmd *cobra.Command, args []string) error {
295293
scanner := bufio.NewScanner(os.Stdin)
296294
for _, fork := range forks {
297295
fmt.Print("\n")
298-
color.New(color.FgGreen, color.Bold).Printf("📂 Repository: %s\n", fork.Name)
296+
color.New(color.FgGreen, color.Bold).Printf("📂 Repository: %s\n", fork.NameWithOwner)
299297
color.New(color.FgBlue).Printf(" 🔄 Forked from: %s\n", fork.Parent.NameWithOwner)
300298
if fork.IsArchived {
301299
color.New(color.FgRed).Println(" 📦 This repository is archived")
@@ -338,7 +336,7 @@ func cleanupForks(cmd *cobra.Command, args []string) error {
338336
}
339337

340338
if answer != "y" {
341-
color.New(color.FgBlue).Printf("⏭️ Skipping %s...\n", fork.Name)
339+
color.New(color.FgBlue).Printf("⏭️ Skipping %s...\n", fork.NameWithOwner)
342340
continue
343341
}
344342

@@ -348,18 +346,18 @@ func cleanupForks(cmd *cobra.Command, args []string) error {
348346
scanner.Scan()
349347
confirm := strings.ToLower(strings.TrimSpace(scanner.Text()))
350348
if confirm != "yes" {
351-
color.New(color.FgBlue).Printf("⏭️ Skipping %s...\n", fork.Name)
349+
color.New(color.FgBlue).Printf("⏭️ Skipping %s...\n", fork.NameWithOwner)
352350
continue
353351
}
354352
}
355353
}
356354

357-
color.New(color.FgRed).Printf("🗑️ Deleting %s...\n", fork.Name)
358-
deleteCmd := exec.Command("gh", "repo", "delete", fork.Name, "--yes")
355+
color.New(color.FgRed).Printf("🗑️ Deleting %s...\n", fork.NameWithOwner)
356+
deleteCmd := exec.Command("gh", "repo", "delete", fork.NameWithOwner, "--yes")
359357
if err := deleteCmd.Run(); err != nil {
360-
fmt.Fprintf(os.Stderr, "Error deleting %s: %v\n", fork.Name, err)
358+
fmt.Fprintf(os.Stderr, "Error deleting %s: %v\n", fork.NameWithOwner, err)
361359
} else {
362-
color.New(color.FgGreen).Printf("✅ Successfully deleted %s.\n", fork.Name)
360+
color.New(color.FgGreen).Printf("✅ Successfully deleted %s.\n", fork.NameWithOwner)
363361
}
364362
}
365363
fmt.Println()

0 commit comments

Comments
 (0)