Skip to content

Commit

Permalink
Fix path for directory with spaces. closes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
ribtoks committed Aug 11, 2020
1 parent b71a9c1 commit 4a6f343
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"math"
"net/url"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -183,6 +184,15 @@ func (s *service) fetchGithubIssues() ([]*github.Issue, error) {
return allIssues, nil
}

func escapePath(path string) string {
parts := strings.Split(path, "/")
for i := range parts {
parts[i] = url.PathEscape(parts[i])
}

return strings.Join(parts, "/")
}

func (s *service) createFileLink(c *tdglib.ToDoComment) string {
start := c.Line - contextLinesUp
if start < 0 {
Expand All @@ -201,9 +211,11 @@ func (s *service) createFileLink(c *tdglib.ToDoComment) string {
filepath = fmt.Sprintf("%v/%v", root, c.File)
}

safeFilepath := escapePath(filepath)

// https://github.com/{repo}/blob/{sha}/{file}#L{startLines}-L{endLine}
return fmt.Sprintf("https://github.com/%s/%s/blob/%s/%s#L%v-L%v",
s.env.owner, s.env.repo, s.env.sha, filepath, start, end)
s.env.owner, s.env.repo, s.env.sha, safeFilepath, start, end)
}

func (s *service) labels(c *tdglib.ToDoComment) []string {
Expand Down

0 comments on commit 4a6f343

Please sign in to comment.