Skip to content

Commit

Permalink
fix(github): lookup wikis per-repo
Browse files Browse the repository at this point in the history
  • Loading branch information
rgmz authored and Richard Gomez committed Feb 9, 2024
1 parent 8e00cba commit 5f16975
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pkg/sources/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,13 +720,13 @@ func (s *Source) scan(ctx context.Context, installationClient *github.Client, ch
}

// Scan the wiki, if enabled, and the repo has one.
if s.conn.IncludeWikis && repoInfo.hasWiki {
if s.conn.IncludeWikis && repoInfo.hasWiki && s.hasWiki(ctx, repoURL) {
wikiURL := strings.TrimSuffix(repoURL, ".git") + ".wiki.git"
wikiCtx := context.WithValue(ctx, "repo", wikiURL)

_, err := s.cloneAndScanRepo(wikiCtx, installationClient, wikiURL, repoInfo, chunksChan)
if err != nil {
scanErrs.Add(err)
scanErrs.Add(fmt.Errorf("error scanning wiki: %s", wikiURL))
// Don't return, it still might be possible to scan comments.
}
}
Expand Down
8 changes: 2 additions & 6 deletions pkg/sources/github/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func (s *Source) processRepos(ctx context.Context, target string, listRepos repo
owner: r.GetOwner().GetLogin(),
name: r.GetName(),
fullName: r.GetFullName(),
hasWiki: s.conn.GetIncludeWikis() && s.hasWiki(ctx, r, repoURL),
hasWiki: r.GetHasWiki(),
size: r.GetSize(),
}
if r.GetPrivate() {
Expand All @@ -295,11 +295,7 @@ func (s *Source) processRepos(ctx context.Context, target string, listRepos repo

// hasWiki returns true if the "has_wiki" property is true AND https://github.com/$org/$repo/wiki is not redirected.
// Unfortunately, this isn't 100% accurate. Some repositories meet both criteria yet don't have a cloneable wiki.
func (s *Source) hasWiki(ctx context.Context, repo *github.Repository, repoURL string) bool {
if !repo.GetHasWiki() {
return false
}

func (s *Source) hasWiki(ctx context.Context, repoURL string) bool {
wikiURL := strings.TrimSuffix(repoURL, ".git") + "/wiki"
req, err := http.NewRequestWithContext(ctx, http.MethodHead, wikiURL, nil)
if err != nil {
Expand Down

0 comments on commit 5f16975

Please sign in to comment.