Skip to content

Commit

Permalink
Fix link preview for end of file lines
Browse files Browse the repository at this point in the history
  • Loading branch information
ribtoks committed Jun 14, 2024
1 parent b268181 commit 32bb59a
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 13 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ go 1.14
require (
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
github.com/google/go-github/v49 v49.1.0
gitlab.com/ribtoks/tdg v0.0.6
gitlab.com/ribtoks/tdg v0.0.7-1
golang.org/x/oauth2 v0.15.0
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -862,8 +862,8 @@ github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN
github.com/zeebo/xxh3 v1.0.2/go.mod h1:5NWz9Sef7zIDm2JHfFlcQvNekmcEl9ekUZQQKCYaDcA=
github.com/zieckey/goini v0.0.0-20180118150432-0da17d361d26 h1:E0lEWrifmR0ACbGf5PLji1XbW6rtIXLHCXO/YOqi0AE=
github.com/zieckey/goini v0.0.0-20180118150432-0da17d361d26/go.mod h1:TQpdgg7I9+PFIkatlx/dnZyZb4iZyCUx1HJj4rXi3+E=
gitlab.com/ribtoks/tdg v0.0.6 h1:d1ilbYxq/FKTReQI8Nyi1hAAcsrDTVgsF0B3CKKkgj0=
gitlab.com/ribtoks/tdg v0.0.6/go.mod h1:XDYfJNbUbnnCW6lGCC2TLumDieEI04L0VtjVbgDKz1w=
gitlab.com/ribtoks/tdg v0.0.7-1 h1:nKyCntmUgAZiz55y6nSmCKZc4dNJczQJZhT2qEXTK+g=
gitlab.com/ribtoks/tdg v0.0.7-1/go.mod h1:XDYfJNbUbnnCW6lGCC2TLumDieEI04L0VtjVbgDKz1w=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
Expand Down
24 changes: 18 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type env struct {
type service struct {
ctx context.Context
client *github.Client
tdg *tdglib.ToDoGenerator
env *env
wg sync.WaitGroup
newIssuesMap map[string]*github.Issue
Expand Down Expand Up @@ -200,11 +201,17 @@ func (s *service) fetchGithubIssues() ([]*github.Issue, error) {

func escapePath(path string) string {
parts := strings.Split(path, "/")
result := make([]string, 0, len(parts))
for i := range parts {
parts[i] = url.PathEscape(parts[i])
part := strings.TrimSpace(parts[i])
if len(part) == 0 {
continue
}

result = append(result, url.PathEscape(part))
}

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

func (s *service) createFileLink(c *tdglib.ToDoComment) string {
Expand All @@ -214,15 +221,20 @@ func (s *service) createFileLink(c *tdglib.ToDoComment) string {
}

end := c.Line + contextLinesDown
if maxLines := s.tdg.FileLines(c.File); (start < maxLines) && (maxLines < end) {
end = maxLines
}

root := s.env.root
root = strings.TrimPrefix(root, ".")
root = strings.TrimPrefix(root, "/")
root = strings.TrimSuffix(root, "/")

filepath := c.File
if root != "." {
if (root != ".") && (root != "/") && (root != "") {
filepath = fmt.Sprintf("%v/%v", root, c.File)
} else if (root == "/") && !strings.HasPrefix(c.File, "/") {
filepath = "/" + c.File
}

safeFilepath := escapePath(filepath)
Expand Down Expand Up @@ -525,15 +537,15 @@ func main() {
excludePatterns = append(excludePatterns, env.excludeRE)
}

td := tdglib.NewToDoGenerator(env.sourceRoot(),
svc.tdg = tdglib.NewToDoGenerator(env.sourceRoot(),
includePatterns,
excludePatterns,
env.assignFromBlame,
env.minWords,
env.minChars,
env.concurrency)

comments, err := td.Generate()
comments, err := svc.tdg.Generate()
if err != nil {
log.Panic(err)
}
Expand Down Expand Up @@ -563,5 +575,5 @@ func main() {
svc.assignNewIssues()
}

fmt.Println(fmt.Sprintf(`::set-output name=scannedIssues::%s`, "1"))
fmt.Println(`::set-output name=scannedIssues::1`)
}
30 changes: 27 additions & 3 deletions vendor/gitlab.com/ribtoks/tdg/pkg/tdglib/todogenerator.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ github.com/google/go-github/v49/github
github.com/google/go-querystring/query
# github.com/zieckey/goini v0.0.0-20180118150432-0da17d361d26
github.com/zieckey/goini
# gitlab.com/ribtoks/tdg v0.0.6
# gitlab.com/ribtoks/tdg v0.0.7-1
## explicit
gitlab.com/ribtoks/tdg/pkg/tdglib
# golang.org/x/crypto v0.16.0
Expand Down

0 comments on commit 32bb59a

Please sign in to comment.