| 345 | } |
| 346 | |
| 347 | func replaceAcessTokenInUrl(gitURL, newCredential string) (string, errors.Error) { |
| 348 | atIndex := strings.Index(gitURL, "@") |
| 349 | if atIndex == -1 { |
| 350 | return "", errors.Default.New("Invalid Git URL") |
| 351 | } |
| 352 | |
| 353 | protocolIndex := strings.Index(gitURL, "://") |
| 354 | if protocolIndex == -1 { |
| 355 | return "", errors.Default.New("Invalid Git URL") |
| 356 | } |
| 357 | |
| 358 | // Extract the base URL (e.g., "https://git:") |
| 359 | baseURL := gitURL[:protocolIndex+7] |
| 360 | |
| 361 | repoURL := gitURL[atIndex+1:] |
| 362 | |
| 363 | modifiedURL := fmt.Sprintf("%s%s@%s", baseURL, newCredential, repoURL) |
| 364 | |
| 365 | return modifiedURL, nil |
| 366 | } |