MCPcopy Create free account
hub / github.com/OctopusDeploy/cli / ParseGitResourceGitRefString

Function ParseGitResourceGitRefString

pkg/gitresources/gitResources.go:176–223  ·  view source on GitHub ↗
(gitResourceRef string)

Source from the content-addressed store, hash-verified

174}
175
176func ParseGitResourceGitRefString(gitResourceRef string) (*GitResourceGitRef, error) {
177 if strings.TrimSpace(gitResourceRef) == "" {
178 return nil, errors.New("empty git resource git reference specification")
179 }
180
181 delimiters := []rune{':', '='}
182
183 chosenDelimiterIndex := slices.IndexFunc(delimiters, func(char int32) bool {
184 return strings.ContainsRune(gitResourceRef, char)
185 })
186
187 if chosenDelimiterIndex < 0 {
188 return nil, fmt.Errorf("git resource git reference specification \"%s\" does not use an expected format", gitResourceRef)
189 }
190
191 //for consistency with the server-side code, we only support one type of delimiter at once
192 components := util.SplitString(gitResourceRef, []rune{delimiters[chosenDelimiterIndex]})
193 actionName, gitResourceName, gitRef := "", "", ""
194
195 // We support 2 formats of git resource
196 // {StepName}:{GitRef} - This targets the primary git resource for a step only
197 // {StepName}:{GitResourceName}:{GitRef} - This targets a secondary git resource
198
199 actionName = strings.TrimSpace(components[0])
200 switch len(components) {
201 case 2:
202 gitRef = strings.TrimSpace(components[1])
203 case 3:
204 gitResourceName = strings.TrimSpace(components[1])
205 gitRef = strings.TrimSpace(components[2])
206 default:
207 return nil, fmt.Errorf("git resource git reference specification \"%s\" does not use an expected format", gitResourceRef)
208 }
209
210 if actionName == "" {
211 return nil, fmt.Errorf("git resource git reference specification \"%s\" cannot have an empty step name", gitResourceRef)
212 }
213
214 if gitRef == "" {
215 return nil, fmt.Errorf("git resource git reference specification \"%s\" cannot have an empty git ref", gitResourceRef)
216 }
217
218 return &GitResourceGitRef{
219 ActionName: actionName,
220 GitRef: gitRef,
221 GitResourceName: gitResourceName,
222 }, nil
223}
224
225func ResolveGitResourceOverride(override *GitResourceGitRef, baseline []*GitResourceGitRef) (*GitResourceGitRef, error) {
226 index := slices.IndexFunc(baseline, func(grgr *GitResourceGitRef) bool {

Callers 3

createRunFunction · 0.92

Calls 1

SplitStringFunction · 0.92