Skip to content

Commit

Permalink
refactor(gh): remove useless defer
Browse files Browse the repository at this point in the history
  • Loading branch information
crhntr committed Jul 20, 2023
1 parent 22eeb47 commit 53f0cca
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions internal/gh/uri.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gh

import (
"errors"
"fmt"
"net/url"
"path/filepath"
Expand All @@ -11,22 +10,20 @@ import (
// RepositoryOwnerAndNameFromPath is from the github-release-source branch
// once that one is merged we should that one instead of this one
func RepositoryOwnerAndNameFromPath(urlStr string) (owner, repo string, err error) {
defer func() {
if err != nil {
err = fmt.Errorf("failed to parse owner and repo name from URI %q: %w", urlStr, err)
}
}()
wrapError := func(urlStr string, err error) error {
return fmt.Errorf("failed to parse owner and repo name from URI %q: %w", urlStr, err)
}
urlStr = strings.TrimPrefix(urlStr, "[email protected]:")
u, err := url.Parse(urlStr)
if err != nil {
return "", "", err
return "", "", wrapError(urlStr, err)
}
if filepath.Ext(u.Path) == ".git" {
u.Path = strings.TrimSuffix(u.Path, ".git")
}
owner, repo, found := strings.Cut(strings.TrimPrefix(u.Path, "/"), "/")
if !found || owner == "" || repo == "" {
return owner, repo, errors.New("path missing expected parts")
return owner, repo, wrapError(urlStr, fmt.Errorf("path missing expected parts"))
}
return owner, repo, nil
}

0 comments on commit 53f0cca

Please sign in to comment.