github.com/drone/go-convert@v0.0.0-20240307072510-6bd371c65e61/convert/jenkins/option.go (about) 1 // Copyright 2022 Harness, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package jenkins 16 17 import "strings" 18 19 // Option configures a Converter option. 20 type Option func(*Converter) 21 22 // WithDockerhub returns an option to set the default 23 // dockerhub registry connector. 24 func WithDockerhub(connector string) Option { 25 return func(d *Converter) { 26 d.dockerhubConn = connector 27 } 28 } 29 30 // WithKubernetes returns an option to set the default 31 // runtime to Kubernetes. 32 func WithKubernetes(namespace, connector string) Option { 33 return func(d *Converter) { 34 d.kubeNamespace = namespace 35 d.kubeConnector = connector 36 } 37 } 38 39 // WithAttempts returns an option to set the number 40 // of retry attempts. 41 func WithAttempts(attempts int) Option { 42 return func(d *Converter) { 43 d.attempts = attempts 44 } 45 } 46 47 // WithToken returns an option to set the API token 48 // for Chat GPT. 49 func WithToken(token string) Option { 50 return func(d *Converter) { 51 d.token = token 52 } 53 } 54 55 // WithDebug returns an option to use debug mode. 56 func WithDebug() Option { 57 return func(d *Converter) { 58 d.debug = true 59 } 60 } 61 62 // WithFormat returns an option to customize 63 // the intermediate format. 64 func WithFormat(format Format) Option { 65 return func(d *Converter) { 66 d.format = format 67 } 68 } 69 70 // WithFormat returns an option to customize 71 // the intermediate format. 72 func WithFormatString(format string) Option { 73 return func(d *Converter) { 74 format = strings.TrimSpace(format) 75 format = strings.ToLower(format) 76 switch format { 77 case "github": 78 d.format = FromGithub 79 case "gitlab": 80 d.format = FromGitlab 81 case "drone": 82 d.format = FromDrone 83 } 84 } 85 }