Skip to content

Commit

Permalink
Fix crash when opening issue in browser
Browse files Browse the repository at this point in the history
Lab crashes due to loading a non existed config file for the host url.
Since other commands work just fine without the config file, we can use
similar approach for `issue browse` command, which is detect project url
from git host and build up the url.
  • Loading branch information
letientai299 committed Jun 4, 2019
1 parent 091e8bb commit da99136
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions cmd/issue_browse.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ package cmd

import (
"log"
"net/url"
"path"
"strconv"

"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/zaquestion/lab/internal/browser"
"github.com/zaquestion/lab/internal/gitlab"
)

var browse = browser.Open
Expand All @@ -24,20 +23,17 @@ var issueBrowseCmd = &cobra.Command{
log.Fatal(err)
}

c := viper.AllSettings()["core"]
config := c.([]map[string]interface{})[0]
host := config["host"].(string)

hostURL, err := url.Parse(host)
project, err := gitlab.FindProject(rn)
if err != nil {
log.Fatal(err)
}
hostURL.Path = path.Join(hostURL.Path, rn, "issues")

issueURL := path.Join(project.WebURL, "issues")
if num > 0 {
hostURL.Path = path.Join(hostURL.Path, strconv.FormatInt(num, 10))
issueURL = path.Join(issueURL, strconv.FormatInt(num, 10))
}

err = browse(hostURL.String())
err = browse(issueURL)
if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit da99136

Please sign in to comment.