diff --git a/cmd/survey/tasks/codingTask.go b/cmd/survey/tasks/codingTask.go index dcc4e13..3250549 100644 --- a/cmd/survey/tasks/codingTask.go +++ b/cmd/survey/tasks/codingTask.go @@ -24,11 +24,12 @@ Please write your code below this line! ` type CodingTask struct { - app *service.App + done bool + app *service.App } func NewCodingTask(app *service.App) *CodingTask { - return &CodingTask{app: app} + return &CodingTask{app: app, done: false} } func (t *CodingTask) Config() task.Config { @@ -100,5 +101,5 @@ func (t *CodingTask) Validate(ctx context.Context) (bool, error) { return false, fmt.Errorf("the function does not contain a return statement") } - return EndTaskWithTimeout(nil, "Task completed!", 5*time.Second) + return EndTaskWithTimeout(&t.done, "Task completed!", 5*time.Second) } diff --git a/cmd/survey/tasks/createIssue.go b/cmd/survey/tasks/createIssue.go index ee96e55..189697c 100644 --- a/cmd/survey/tasks/createIssue.go +++ b/cmd/survey/tasks/createIssue.go @@ -3,6 +3,7 @@ package tasks import ( "context" "fmt" + "time" "github.com/LazyBachelor/LazyPM/internal/models" "github.com/LazyBachelor/LazyPM/internal/service" @@ -13,15 +14,18 @@ import ( const description = `You are tasked with creating a new issue in the project management system. This task will test your ability to use the issue creation workflow effectively. -Assign this task to yourself and start creating the issue. -Make sure to fill out all the necessary details, including the title, description, and assignee.` +Assign this task to yourself and start creating a new issue. +Make sure to fill out all the necessary details, including the title and description. +Once you have created the issue, mark it as closed to complete the task.` type CreateIssueTask struct { - app *service.App + done bool + app *service.App + setupTask *models.Issue } func NewCreateIssueTask(app *service.App) *CreateIssueTask { - return &CreateIssueTask{app: app} + return &CreateIssueTask{app: app, done: false} } func (t *CreateIssueTask) Config() task.Config { @@ -37,15 +41,14 @@ func (t *CreateIssueTask) Questions(interfaceType task.InterfaceType) taskui.Que } func (t *CreateIssueTask) Setup(ctx context.Context) error { - // Clear existing issues to ensure a clean state for the task if err := ClearIssues(t.app); err != nil { return err } - issue := models.NewBaseIssue(). + t.setupTask = models.NewBaseIssue(). WithTitle("Create a New Issue").WithDescription(description).Build() - return t.app.Issues.CreateIssue(ctx, &issue, "") + return t.app.Issues.CreateIssue(ctx, t.setupTask, "") } func (t *CreateIssueTask) Validate(ctx context.Context) (bool, error) { @@ -54,6 +57,12 @@ func (t *CreateIssueTask) Validate(ctx context.Context) (bool, error) { return false, err } + /* Not implemented yet, as assigning to self is not supported in the current implementation + if t.setupTask.Assignee != "Me" { + return false, fmt.Errorf("issue not assigned to self") + } + */ + if len(issues) < 2 { return false, fmt.Errorf("issue not created") } @@ -78,5 +87,15 @@ func (t *CreateIssueTask) Validate(ctx context.Context) (bool, error) { return false, fmt.Errorf("issue description is empty") } - return true, nil + /* Not implemented yet, as assigning to self is not supported in the current implementation + if createdIssue.Assignee != "Me" { + return false, fmt.Errorf("issue not assigned to self") + } + */ + + if createdIssue.Status != models.StatusClosed { + return false, fmt.Errorf("issue status is not closed") + } + + return EndTaskWithTimeout(&t.done, "Task completed!", 5*time.Second) }