-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add tasks schema, fix up object owned mixin
Signed-off-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com>
- Loading branch information
1 parent
e4d5efa
commit a01741e
Showing
141 changed files
with
55,983 additions
and
12,332 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
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,93 @@ | ||
package task | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/theopenlane/core/cmd/cli/cmd" | ||
"github.com/theopenlane/core/pkg/enums" | ||
"github.com/theopenlane/core/pkg/openlaneclient" | ||
) | ||
|
||
var createCmd = &cobra.Command{ | ||
Use: "create", | ||
Short: "create a new task", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
err := create(cmd.Context()) | ||
cobra.CheckErr(err) | ||
}, | ||
} | ||
|
||
func init() { | ||
command.AddCommand(createCmd) | ||
|
||
// command line flags for the create command | ||
createCmd.Flags().StringP("title", "t", "", "title of the task") | ||
createCmd.Flags().StringP("description", "d", "", "description of the task") | ||
createCmd.Flags().StringP("status", "s", "", "status of the task") | ||
createCmd.Flags().StringP("assignee", "a", "", "assignee (user ID) of the task") | ||
createCmd.Flags().Duration("due", 0, "time until due date of the task") | ||
createCmd.Flags().StringP("organization", "o", "", "organization ID of the task to own the task, this will give the organization access to the task") | ||
createCmd.Flags().StringP("group", "g", "", "group ID of the task to own the task, this will give the group access to the task") | ||
} | ||
|
||
// createValidation validates the required fields for the command | ||
func createValidation() (input openlaneclient.CreateTaskInput, err error) { | ||
// validation of required fields for the create command | ||
// output the input struct with the required fields and optional fields based on the command line flags | ||
input.Title = cmd.Config.String("title") | ||
if input.Title == "" { | ||
return input, cmd.NewRequiredFieldMissingError("task title") | ||
} | ||
|
||
description := cmd.Config.String("description") | ||
if description != "" { | ||
input.Description = &description | ||
} | ||
|
||
status := cmd.Config.String("status") | ||
if status != "" { | ||
input.Status = enums.ToTaskStatus(status) | ||
} | ||
|
||
assignee := cmd.Config.String("assignee") | ||
if assignee != "" { | ||
input.Assignee = &assignee | ||
} | ||
|
||
due := cmd.Config.Duration("due") | ||
if due != 0 { | ||
dueDate := time.Now().Add(due) | ||
input.Due = &dueDate | ||
} | ||
|
||
organization := cmd.Config.String("organization") | ||
if organization != "" { | ||
input.OrganizationIDs = []string{organization} | ||
} | ||
|
||
group := cmd.Config.String("group") | ||
if group != "" { | ||
input.GroupIDs = []string{group} | ||
} | ||
|
||
return input, nil | ||
} | ||
|
||
// create a new task | ||
func create(ctx context.Context) error { | ||
// setup http client | ||
client, err := cmd.SetupClientWithAuth(ctx) | ||
cobra.CheckErr(err) | ||
defer cmd.StoreSessionCookies(client) | ||
|
||
input, err := createValidation() | ||
cobra.CheckErr(err) | ||
|
||
o, err := client.CreateTask(ctx, input) | ||
cobra.CheckErr(err) | ||
|
||
return consoleOutput(o) | ||
} |
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,50 @@ | ||
package task | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/theopenlane/core/cmd/cli/cmd" | ||
) | ||
|
||
var deleteCmd = &cobra.Command{ | ||
Use: "delete", | ||
Short: "delete an existing task", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
err := delete(cmd.Context()) | ||
cobra.CheckErr(err) | ||
}, | ||
} | ||
|
||
func init() { | ||
command.AddCommand(deleteCmd) | ||
|
||
deleteCmd.Flags().StringP("id", "i", "", "task id to delete") | ||
} | ||
|
||
// deleteValidation validates the required fields for the command | ||
func deleteValidation() (string, error) { | ||
id := cmd.Config.String("id") | ||
if id == "" { | ||
return "", cmd.NewRequiredFieldMissingError("task id") | ||
} | ||
|
||
return id, nil | ||
} | ||
|
||
// delete an existing task in the platform | ||
func delete(ctx context.Context) error { | ||
// setup http client | ||
client, err := cmd.SetupClientWithAuth(ctx) | ||
cobra.CheckErr(err) | ||
defer cmd.StoreSessionCookies(client) | ||
|
||
id, err := deleteValidation() | ||
cobra.CheckErr(err) | ||
|
||
o, err := client.DeleteTask(ctx, id) | ||
cobra.CheckErr(err) | ||
|
||
return consoleOutput(o) | ||
} |
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,2 @@ | ||
// Package task is our cobra cli for task endpoints | ||
package task |
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,48 @@ | ||
package task | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/theopenlane/core/cmd/cli/cmd" | ||
) | ||
|
||
var getCmd = &cobra.Command{ | ||
Use: "get", | ||
Short: "get an existing task", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
err := get(cmd.Context()) | ||
cobra.CheckErr(err) | ||
}, | ||
} | ||
|
||
func init() { | ||
command.AddCommand(getCmd) | ||
|
||
getCmd.Flags().StringP("id", "i", "", "task id to query") | ||
} | ||
|
||
// get an existing task in the platform | ||
func get(ctx context.Context) error { | ||
// setup http client | ||
client, err := cmd.SetupClientWithAuth(ctx) | ||
cobra.CheckErr(err) | ||
defer cmd.StoreSessionCookies(client) | ||
// filter options | ||
id := cmd.Config.String("id") | ||
|
||
// if an task ID is provided, filter on that task, otherwise get all | ||
if id != "" { | ||
o, err := client.GetTaskByID(ctx, id) | ||
cobra.CheckErr(err) | ||
|
||
return consoleOutput(o) | ||
} | ||
|
||
// get all will be filtered for the authorized organization(s) | ||
o, err := client.GetAllTasks(ctx) | ||
cobra.CheckErr(err) | ||
|
||
return consoleOutput(o) | ||
} |
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,106 @@ | ||
package task | ||
|
||
import ( | ||
"encoding/json" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/theopenlane/utils/cli/tables" | ||
|
||
"github.com/theopenlane/core/cmd/cli/cmd" | ||
"github.com/theopenlane/core/pkg/openlaneclient" | ||
) | ||
|
||
// command represents the base task command when called without any subcommands | ||
var command = &cobra.Command{ | ||
Use: "task", | ||
Short: "the subcommands for working with tasks", | ||
} | ||
|
||
func init() { | ||
cmd.RootCmd.AddCommand(command) | ||
} | ||
|
||
// consoleOutput prints the output in the console | ||
func consoleOutput(e any) error { | ||
// check if the output format is JSON and print the tasks in JSON format | ||
if strings.EqualFold(cmd.OutputFormat, cmd.JSONOutput) { | ||
return jsonOutput(e) | ||
} | ||
|
||
// check the type of the tasks and print them in a table format | ||
switch v := e.(type) { | ||
case *openlaneclient.GetAllTasks: | ||
var nodes []*openlaneclient.GetAllTasks_Tasks_Edges_Node | ||
|
||
for _, i := range v.Tasks.Edges { | ||
nodes = append(nodes, i.Node) | ||
} | ||
|
||
e = nodes | ||
case *openlaneclient.GetTasks: | ||
var nodes []*openlaneclient.GetTasks_Tasks_Edges_Node | ||
|
||
for _, i := range v.Tasks.Edges { | ||
nodes = append(nodes, i.Node) | ||
} | ||
|
||
e = nodes | ||
case *openlaneclient.GetTaskByID: | ||
e = v.Task | ||
case *openlaneclient.CreateTask: | ||
e = v.CreateTask.Task | ||
case *openlaneclient.UpdateTask: | ||
e = v.UpdateTask.Task | ||
case *openlaneclient.DeleteTask: | ||
deletedTableOutput(v) | ||
return nil | ||
} | ||
|
||
s, err := json.Marshal(e) | ||
cobra.CheckErr(err) | ||
|
||
var list []openlaneclient.Task | ||
|
||
err = json.Unmarshal(s, &list) | ||
if err != nil { | ||
var in openlaneclient.Task | ||
err = json.Unmarshal(s, &in) | ||
cobra.CheckErr(err) | ||
|
||
list = append(list, in) | ||
} | ||
|
||
tableOutput(list) | ||
|
||
return nil | ||
} | ||
|
||
// jsonOutput prints the output in a JSON format | ||
func jsonOutput(out any) error { | ||
s, err := json.Marshal(out) | ||
cobra.CheckErr(err) | ||
|
||
return cmd.JSONPrint(s) | ||
} | ||
|
||
// tableOutput prints the output in a table format | ||
func tableOutput(out []openlaneclient.Task) { | ||
// create a table writer | ||
writer := tables.NewTableWriter(command.OutOrStdout(), "ID", "Title", "Description", "Details", "Assignee", "Assigner", "Status", "Due") | ||
for _, i := range out { | ||
writer.AddRow(i.ID, i.Title, *i.Description, i.Details, *i.Assignee, i.Assigner, i.Status, i.Due) | ||
} | ||
|
||
writer.Render() | ||
} | ||
|
||
// deleteTableOutput prints the deleted id in a table format | ||
func deletedTableOutput(e *openlaneclient.DeleteTask) { | ||
writer := tables.NewTableWriter(command.OutOrStdout(), "DeletedID") | ||
|
||
writer.AddRow(e.DeleteTask.DeletedID) | ||
|
||
writer.Render() | ||
} |
Oops, something went wrong.