getRepositorySlugFromRemoteForPath extracts the repository slug (owner/repo) from the git remote URL of the repository containing the specified file path. It prefers the 'upstream' remote when available, and otherwise follows standard remote resolution (origin first, then single-remote fallback).
(path string)
| 288 | // It prefers the 'upstream' remote when available, and otherwise follows standard |
| 289 | // remote resolution (origin first, then single-remote fallback). |
| 290 | func getRepositorySlugFromRemoteForPath(path string) string { |
| 291 | gitLog.Printf("Getting repository slug for path: %s", path) |
| 292 | |
| 293 | // Get absolute path first |
| 294 | absPath, err := filepath.Abs(path) |
| 295 | if err != nil { |
| 296 | gitLog.Printf("Failed to get absolute path: %v", err) |
| 297 | return "" |
| 298 | } |
| 299 | |
| 300 | // Validate the absolute path |
| 301 | absPath, err = fileutil.ValidateAbsolutePath(absPath) |
| 302 | if err != nil { |
| 303 | gitLog.Printf("Invalid path: %v", err) |
| 304 | return "" |
| 305 | } |
| 306 | |
| 307 | // Use the directory containing the file |
| 308 | dir := filepath.Dir(absPath) |
| 309 | |
| 310 | return getRepositorySlugFromDirPreferringUpstream(dir) |
| 311 | } |
| 312 | |
| 313 | func stageWorkflowChanges() { |
| 314 | // Find git root and add .github/workflows relative to it |