Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitabdea72

Browse files
authored
feat(cli): add ability to create tasks for other users (#20012)
1 parentf2f4ed1 commitabdea72

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

‎cli/exp_task_create.go‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func (r *RootCmd) taskCreate() *serpent.Command {
1717
var (
1818
orgContext=NewOrganizationContext()
1919

20+
ownerArgstring
2021
taskNamestring
2122
templateNamestring
2223
templateVersionNamestring
@@ -40,6 +41,14 @@ func (r *RootCmd) taskCreate() *serpent.Command {
4041
Required:false,
4142
Default:"",
4243
},
44+
{
45+
Name:"owner",
46+
Flag:"owner",
47+
Description:"Specify the owner of the task. Defaults to the current user.",
48+
Value:serpent.StringOf(&ownerArg),
49+
Required:false,
50+
Default:codersdk.Me,
51+
},
4352
{
4453
Name:"template",
4554
Flag:"template",
@@ -177,7 +186,7 @@ func (r *RootCmd) taskCreate() *serpent.Command {
177186
templateVersionPresetID=preset.ID
178187
}
179188

180-
task,err:=expClient.CreateTask(ctx,codersdk.Me, codersdk.CreateTaskRequest{
189+
task,err:=expClient.CreateTask(ctx,ownerArg, codersdk.CreateTaskRequest{
181190
Name:taskName,
182191
TemplateVersionID:templateVersionID,
183192
TemplateVersionPresetID:templateVersionPresetID,

‎cli/exp_task_create_test.go‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestTaskCreate(t *testing.T) {
3434
taskID=uuid.New()
3535
)
3636

37-
templateAndVersionFoundHandler:=func(t*testing.T,ctx context.Context,orgID uuid.UUID,templateName,templateVersionName,presetName,prompt,taskNamestring) http.HandlerFunc {
37+
templateAndVersionFoundHandler:=func(t*testing.T,ctx context.Context,orgID uuid.UUID,templateName,templateVersionName,presetName,prompt,taskName,usernamestring) http.HandlerFunc {
3838
t.Helper()
3939

4040
returnfunc(w http.ResponseWriter,r*http.Request) {
@@ -69,7 +69,7 @@ func TestTaskCreate(t *testing.T) {
6969
ActiveVersionID:templateVersionID,
7070
},
7171
})
72-
case"/api/experimental/tasks/me":
72+
casefmt.Sprintf("/api/experimental/tasks/%s",username):
7373
varreq codersdk.CreateTaskRequest
7474
if!httpapi.Read(ctx,w,r,&req) {
7575
return
@@ -114,80 +114,87 @@ func TestTaskCreate(t *testing.T) {
114114
stdin:"reads prompt from stdin",
115115
expectOutput:fmt.Sprintf("The task %s has been created at %s!",cliui.Keyword("task-wild-goldfish-27"),cliui.Timestamp(taskCreatedAt)),
116116
handler:func(t*testing.T,ctx context.Context) http.HandlerFunc {
117-
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","my-template-version","","reads prompt from stdin","task-wild-goldfish-27")
117+
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","my-template-version","","reads prompt from stdin","task-wild-goldfish-27",codersdk.Me)
118118
},
119119
},
120120
{
121121
args: []string{"my custom prompt"},
122122
expectOutput:fmt.Sprintf("The task %s has been created at %s!",cliui.Keyword("task-wild-goldfish-27"),cliui.Timestamp(taskCreatedAt)),
123123
handler:func(t*testing.T,ctx context.Context) http.HandlerFunc {
124-
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","my-template-version","","my custom prompt","task-wild-goldfish-27")
124+
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","my-template-version","","my custom prompt","task-wild-goldfish-27",codersdk.Me)
125+
},
126+
},
127+
{
128+
args: []string{"my custom prompt","--owner","someone-else"},
129+
expectOutput:fmt.Sprintf("The task %s has been created at %s!",cliui.Keyword("task-wild-goldfish-27"),cliui.Timestamp(taskCreatedAt)),
130+
handler:func(t*testing.T,ctx context.Context) http.HandlerFunc {
131+
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","my-template-version","","my custom prompt","task-wild-goldfish-27","someone-else")
125132
},
126133
},
127134
{
128135
args: []string{"--name","abc123","my custom prompt"},
129136
expectOutput:fmt.Sprintf("The task %s has been created at %s!",cliui.Keyword("abc123"),cliui.Timestamp(taskCreatedAt)),
130137
handler:func(t*testing.T,ctx context.Context) http.HandlerFunc {
131-
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","my-template-version","","my custom prompt","abc123")
138+
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","my-template-version","","my custom prompt","abc123",codersdk.Me)
132139
},
133140
},
134141
{
135142
args: []string{"my custom prompt","--template","my-template","--template-version","my-template-version","--org",organizationID.String()},
136143
expectOutput:fmt.Sprintf("The task %s has been created at %s!",cliui.Keyword("task-wild-goldfish-27"),cliui.Timestamp(taskCreatedAt)),
137144
handler:func(t*testing.T,ctx context.Context) http.HandlerFunc {
138-
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","my-template-version","","my custom prompt","task-wild-goldfish-27")
145+
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","my-template-version","","my custom prompt","task-wild-goldfish-27",codersdk.Me)
139146
},
140147
},
141148
{
142149
args: []string{"my custom prompt","--template","my-template","--org",organizationID.String()},
143150
env: []string{"CODER_TASK_TEMPLATE_VERSION=my-template-version"},
144151
expectOutput:fmt.Sprintf("The task %s has been created at %s!",cliui.Keyword("task-wild-goldfish-27"),cliui.Timestamp(taskCreatedAt)),
145152
handler:func(t*testing.T,ctx context.Context) http.HandlerFunc {
146-
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","my-template-version","","my custom prompt","task-wild-goldfish-27")
153+
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","my-template-version","","my custom prompt","task-wild-goldfish-27",codersdk.Me)
147154
},
148155
},
149156
{
150157
args: []string{"my custom prompt","--org",organizationID.String()},
151158
env: []string{"CODER_TASK_TEMPLATE_NAME=my-template","CODER_TASK_TEMPLATE_VERSION=my-template-version"},
152159
expectOutput:fmt.Sprintf("The task %s has been created at %s!",cliui.Keyword("task-wild-goldfish-27"),cliui.Timestamp(taskCreatedAt)),
153160
handler:func(t*testing.T,ctx context.Context) http.HandlerFunc {
154-
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","my-template-version","","my custom prompt","task-wild-goldfish-27")
161+
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","my-template-version","","my custom prompt","task-wild-goldfish-27",codersdk.Me)
155162
},
156163
},
157164
{
158165
args: []string{"my custom prompt","--template","my-template","--org",organizationID.String()},
159166
expectOutput:fmt.Sprintf("The task %s has been created at %s!",cliui.Keyword("task-wild-goldfish-27"),cliui.Timestamp(taskCreatedAt)),
160167
handler:func(t*testing.T,ctx context.Context) http.HandlerFunc {
161-
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","","","my custom prompt","task-wild-goldfish-27")
168+
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","","","my custom prompt","task-wild-goldfish-27",codersdk.Me)
162169
},
163170
},
164171
{
165172
args: []string{"my custom prompt","--template","my-template","--preset","my-preset","--org",organizationID.String()},
166173
expectOutput:fmt.Sprintf("The task %s has been created at %s!",cliui.Keyword("task-wild-goldfish-27"),cliui.Timestamp(taskCreatedAt)),
167174
handler:func(t*testing.T,ctx context.Context) http.HandlerFunc {
168-
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","","my-preset","my custom prompt","task-wild-goldfish-27")
175+
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","","my-preset","my custom prompt","task-wild-goldfish-27",codersdk.Me)
169176
},
170177
},
171178
{
172179
args: []string{"my custom prompt","--template","my-template"},
173180
env: []string{"CODER_TASK_PRESET_NAME=my-preset"},
174181
expectOutput:fmt.Sprintf("The task %s has been created at %s!",cliui.Keyword("task-wild-goldfish-27"),cliui.Timestamp(taskCreatedAt)),
175182
handler:func(t*testing.T,ctx context.Context) http.HandlerFunc {
176-
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","","my-preset","my custom prompt","task-wild-goldfish-27")
183+
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","","my-preset","my custom prompt","task-wild-goldfish-27",codersdk.Me)
177184
},
178185
},
179186
{
180187
args: []string{"my custom prompt","-q"},
181188
expectOutput:taskID.String(),
182189
handler:func(t*testing.T,ctx context.Context) http.HandlerFunc {
183-
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","my-template-version","","my custom prompt","task-wild-goldfish-27")
190+
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","my-template-version","","my custom prompt","task-wild-goldfish-27",codersdk.Me)
184191
},
185192
},
186193
{
187194
args: []string{"my custom prompt","--template","my-template","--preset","not-real-preset"},
188195
expectError:`preset "not-real-preset" not found`,
189196
handler:func(t*testing.T,ctx context.Context) http.HandlerFunc {
190-
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","","my-preset","my custom prompt","task-wild-goldfish-27")
197+
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","","my-preset","my custom prompt","task-wild-goldfish-27",codersdk.Me)
191198
},
192199
},
193200
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp