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

Commit98521be

Browse files
committed
refactor: extract WarnMatchedProvisioners to cliutil
1 parent1c95ffe commit98521be

File tree

2 files changed

+48
-37
lines changed

2 files changed

+48
-37
lines changed

‎cli/cliutil/provisionerwarn.go‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package cliutil
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"io"
7+
"strings"
8+
9+
"github.com/coder/coder/v2/cli/cliui"
10+
"github.com/coder/coder/v2/codersdk"
11+
)
12+
13+
var (
14+
warnNoMatchedProvisioners=`Your build has been enqueued, but there are no provisioners that accept the required tags. Once a compatible provisioner becomes available, your build will continue. Please contact your administrator.
15+
Details:
16+
Provisioner job ID : %s
17+
Requested tags : %s
18+
`
19+
warnNoAvailableProvisioners=`Provisioners that accept the required tags have not responded for longer than expected. This may delay your build. Please contact your administrator if your build does not complete.
20+
Details:
21+
Provisioner job ID : %s
22+
Requested tags : %s
23+
Most recently seen : %s
24+
`
25+
)
26+
27+
funcWarnMatchedProvisioners(w io.Writer,tv codersdk.TemplateVersion) {
28+
iftv.MatchedProvisioners==nil {
29+
// Nothing in the response, nothing to do here!
30+
return
31+
}
32+
vartagsJSON strings.Builder
33+
iferr:=json.NewEncoder(&tagsJSON).Encode(tv.Job.Tags);err!=nil {
34+
// Fall back to the less-pretty string representation.
35+
tagsJSON.Reset()
36+
_,_=tagsJSON.WriteString(fmt.Sprintf("%v",tv.Job.Tags))
37+
}
38+
iftv.MatchedProvisioners.Count==0 {
39+
cliui.Warnf(w,warnNoMatchedProvisioners,tv.Job.ID,tagsJSON.String())
40+
return
41+
}
42+
iftv.MatchedProvisioners.Available==0 {
43+
cliui.Warnf(w,warnNoAvailableProvisioners,tv.Job.ID,strings.TrimSpace(tagsJSON.String()),tv.MatchedProvisioners.MostRecentlySeen.Time)
44+
return
45+
}
46+
}

‎cli/templatepush.go‎

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cli
22

33
import (
44
"bufio"
5-
"encoding/json"
65
"errors"
76
"fmt"
87
"io"
@@ -17,6 +16,7 @@ import (
1716
"golang.org/x/xerrors"
1817

1918
"github.com/coder/coder/v2/cli/cliui"
19+
"github.com/coder/coder/v2/cli/cliutil"
2020
"github.com/coder/coder/v2/codersdk"
2121
"github.com/coder/coder/v2/provisionersdk"
2222
"github.com/coder/pretty"
@@ -416,7 +416,7 @@ func createValidTemplateVersion(inv *serpent.Invocation, args createValidTemplat
416416
iferr!=nil {
417417
returnnil,err
418418
}
419-
WarnMatchedProvisioners(inv,version)
419+
cliutil.WarnMatchedProvisioners(inv.Stderr,version)
420420
err=cliui.ProvisionerJob(inv.Context(),inv.Stdout, cliui.ProvisionerJobOptions{
421421
Fetch:func() (codersdk.ProvisionerJob,error) {
422422
version,err:=client.TemplateVersion(inv.Context(),version.ID)
@@ -482,41 +482,6 @@ func ParseProvisionerTags(rawTags []string) (map[string]string, error) {
482482
returntags,nil
483483
}
484484

485-
var (
486-
warnNoMatchedProvisioners=`Your build has been enqueued, but there are no provisioners that accept the required tags. Once a compatible provisioner becomes available, your build will continue. Please contact your administrator.
487-
Details:
488-
Provisioner job ID : %s
489-
Requested tags : %s
490-
`
491-
warnNoAvailableProvisioners=`Provisioners that accept the required tags have not responded for longer than expected. This may delay your build. Please contact your administrator if your build does not complete.
492-
Details:
493-
Provisioner job ID : %s
494-
Requested tags : %s
495-
Most recently seen : %s
496-
`
497-
)
498-
499-
funcWarnMatchedProvisioners(inv*serpent.Invocation,tv codersdk.TemplateVersion) {
500-
iftv.MatchedProvisioners==nil {
501-
// Nothing in the response, nothing to do here!
502-
return
503-
}
504-
vartagsJSON strings.Builder
505-
iferr:=json.NewEncoder(&tagsJSON).Encode(tv.Job.Tags);err!=nil {
506-
// Fall back to the less-pretty string representation.
507-
tagsJSON.Reset()
508-
_,_=tagsJSON.WriteString(fmt.Sprintf("%v",tv.Job.Tags))
509-
}
510-
iftv.MatchedProvisioners.Count==0 {
511-
cliui.Warnf(inv.Stderr,warnNoMatchedProvisioners,tv.Job.ID,tagsJSON.String())
512-
return
513-
}
514-
iftv.MatchedProvisioners.Available==0 {
515-
cliui.Warnf(inv.Stderr,warnNoAvailableProvisioners,tv.Job.ID,strings.TrimSpace(tagsJSON.String()),tv.MatchedProvisioners.MostRecentlySeen.Time)
516-
return
517-
}
518-
}
519-
520485
// prettyDirectoryPath returns a prettified path when inside the users
521486
// home directory. Falls back to dir if the users home directory cannot
522487
// discerned. This function calls filepath.Clean on the result.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp