Ref attempts to return the proper git ref to deploy. If a ref is provided, that will be returned. If not, it will fallback to calling headFunc. If an error is returned (not in a git repo), then it will fallback to DefaultRef.
(ref string, headFunc func() (string, error))
| 324 | // that will be returned. If not, it will fallback to calling headFunc. If an |
| 325 | // error is returned (not in a git repo), then it will fallback to DefaultRef. |
| 326 | func Ref(ref string, headFunc func() (string, error)) string { |
| 327 | if ref != "" { |
| 328 | return ref |
| 329 | } |
| 330 | |
| 331 | ref, err := headFunc() |
| 332 | if err != nil { |
| 333 | // An error means that we're either not in a GitRepo or we're |
| 334 | // not on a branch. In this case, we just fallback to the |
| 335 | // DefaultRef. |
| 336 | return DefaultRef |
| 337 | } |
| 338 | |
| 339 | // Convert `refs/heads/test-deploy` => `test-deploy` |
| 340 | return refRegex.ReplaceAllString(ref, "$1") |
| 341 | } |
| 342 | |
| 343 | // Repo will determine the correct GitHub repo to deploy to, based on a set of |
| 344 | // arguments. |