-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add `delete` command to test run. It helps to delete specified test runs or all test runs from the project.
- Loading branch information
Showing
8 changed files
with
437 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package delete | ||
|
||
import ( | ||
"fmt" | ||
"github.com/qase-tms/qasectl/cmd/flags" | ||
"github.com/qase-tms/qasectl/internal/client" | ||
"github.com/qase-tms/qasectl/internal/service/run" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
"log/slog" | ||
"time" | ||
) | ||
|
||
const ( | ||
idsFlag = "ids" | ||
allFlag = "all" | ||
startTimeFlag = "start" | ||
endTimeFlag = "end" | ||
) | ||
|
||
// Command returns a new cobra command for delete runs | ||
func Command() *cobra.Command { | ||
var ( | ||
ids []int64 | ||
all bool | ||
startTime string | ||
endTime string | ||
) | ||
|
||
cmd := &cobra.Command{ | ||
Use: "delete", | ||
Short: "Delete test runs", | ||
Example: "qli testops run delete --ids 1,2,3 --start 2024-01-02 --end 2024-12-31 --project 'PRJ' --token 'TOKEN'", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
token := viper.GetString(flags.TokenFlag) | ||
project := viper.GetString(flags.ProjectFlag) | ||
|
||
var start, end int64 = 0, 0 | ||
|
||
if startTime != "" { | ||
t, err := time.Parse(time.DateOnly, startTime) | ||
if err != nil { | ||
return fmt.Errorf("failed to parse start time: %w", err) | ||
} | ||
start = t.Unix() | ||
} | ||
|
||
if endTime != "" { | ||
t, err := time.Parse(time.DateOnly, endTime) | ||
if err != nil { | ||
return fmt.Errorf("failed to parse end time: %w", err) | ||
} | ||
end = t.Unix() | ||
} | ||
|
||
c := client.NewClientV1(token) | ||
s := run.NewService(c) | ||
|
||
err := s.DeleteRun(cmd.Context(), project, ids, all, start, end) | ||
if err != nil { | ||
return fmt.Errorf("failed to delete test runs: %w", err) | ||
} | ||
|
||
slog.Info("Test runs deleted") | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
cmd.Flags().Int64SliceVar(&ids, idsFlag, []int64{}, "IDs of test runs to delete. format: --ids 1,2,3") | ||
cmd.Flags().BoolVar(&all, allFlag, false, "delete all test runs in the project") | ||
cmd.MarkFlagsOneRequired(idsFlag, allFlag) | ||
cmd.MarkFlagsMutuallyExclusive(idsFlag, allFlag) | ||
|
||
cmd.Flags().StringVarP(&startTime, startTimeFlag, "s", "", "start date of the test runs. Format: YYYY-MM-DD") | ||
cmd.Flags().StringVarP(&endTime, endTimeFlag, "e", "", "end date of the test runs. Format: YYYY-MM-DD") | ||
|
||
return cmd | ||
} |
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 |
---|---|---|
|
@@ -15,3 +15,7 @@ type Plan struct { | |
Title string `json:"title"` | ||
ID int64 `json:"id"` | ||
} | ||
|
||
type Run struct { | ||
ID int64 `json:"id"` | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.