Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to delete a module version #256

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions internal/cmd/module/delete_version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package module

import (
"fmt"

"github.com/shurcooL/graphql"
"github.com/spacelift-io/spacectl/internal/cmd/authenticated"
"github.com/urfave/cli/v2"
)

func deleteVersion(cliCtx *cli.Context) error {
moduleID := cliCtx.String(flagModuleID.Name)
versionID := cliCtx.String(flagVersionID.Name)

var mutation struct {
DeleteModuleVersion struct {
Number string `graphql:"number"`
} `graphql:"versionDelete(id: $id, module: $module)"`
}

variables := map[string]interface{}{
"id": graphql.ID(versionID),
"module": graphql.ID(moduleID),
}

if err := authenticated.Client.Mutate(cliCtx.Context, &mutation, variables); err != nil {
return err
}

fmt.Printf("Module version %q has been deleted\n", mutation.DeleteModuleVersion.Number)
return nil
}
6 changes: 6 additions & 0 deletions internal/cmd/module/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ var flagModuleID = &cli.StringFlag{
Required: true,
}

var flagVersionID = &cli.StringFlag{
Name: "versionid",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a fan of this, but life is life. unless someone has a better idea?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could provide the version itself, not the ID?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that would require changes in the backend, so i'd rather not do that :/

Usage: "[Required] User-facing `ID` (slug) of the version",
Required: true,
}

var flagCommitSHA = &cli.StringFlag{
Name: "sha",
Usage: "Commit `SHA` to use for the module version",
Expand Down
12 changes: 12 additions & 0 deletions internal/cmd/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ func Command() *cli.Command {
Before: authenticated.Ensure,
ArgsUsage: cmd.EmptyArgsUsage,
},
{
Category: "Module management",
Name: "delete-version",
Usage: "Delete a version of a module",
Flags: []cli.Flag{
flagModuleID,
flagVersionID,
},
Action: deleteVersion,
Before: authenticated.Ensure,
ArgsUsage: cmd.EmptyArgsUsage,
},
{
Category: "Module management",
Name: "local-preview",
Expand Down
Loading