Compare commits

...
3 Commits
Author SHA1 Message Date
Hadi 325397dfef Check repositories length
Signed-off-by: Hadi <[email protected]>
2025-09-17 21:10:35 +02:00
Hadi dab0ba2b38 now retrying to get commits
Signed-off-by: Hadi <[email protected]>
2025-09-17 21:07:16 +02:00
Hadi 98769561c3 Add author.email in levenshtein distance for authors
Signed-off-by: Hadi <[email protected]>
2025-09-17 20:47:12 +02:00
2 changed files with 34 additions and 15 deletions
+21 -14
View File
@@ -2,6 +2,7 @@ package recon
import ( import (
"math/rand" "math/rand"
"time"
github_recon_settings "github.com/anotherhadi/github-recon/settings" github_recon_settings "github.com/anotherhadi/github-recon/settings"
"github.com/anotherhadi/github-recon/utils" "github.com/anotherhadi/github-recon/utils"
@@ -99,21 +100,27 @@ func Spoofing(s github_recon_settings.Settings) (response *SpoofingResult) {
} }
utils.WaitForRateLimit(s, resp) utils.WaitForRateLimit(s, resp)
commits, _, err := s.Client.Repositories.ListCommits(s.Ctx, repo.Owner.GetLogin(), name, nil) const maxRetries = 5
if err != nil { const retryDelay = 2 * time.Second
s.Logger.Error("Error while listing commits", "err", err) for i := 0; i < maxRetries; i++ {
return commits, _, err := s.Client.Repositories.ListCommits(s.Ctx, repo.Owner.GetLogin(), name, nil)
} if err != nil {
s.Logger.Error("Error while listing commits", "err", err)
return
}
if len(commits) > 1 { if len(commits) > 1 {
last := commits[0] last := commits[0]
response.Username = last.GetAuthor().GetLogin() response.Username = last.GetAuthor().GetLogin()
response.Name = last.GetAuthor().GetName() response.Name = last.GetAuthor().GetName()
response.Email = last.GetAuthor().GetEmail() response.Email = last.GetAuthor().GetEmail()
response.Url = last.GetAuthor().GetHTMLURL() response.Url = last.GetAuthor().GetHTMLURL()
response.AvatarURL = last.GetAuthor().GetAvatarURL() response.AvatarURL = last.GetAuthor().GetAvatarURL()
} else { break
s.Logger.Error("Only one commit found, something went wrong.", "commits", commits) }
s.Logger.Info("Only one commit found, retrying...", "attempt", i+1)
time.Sleep(retryDelay)
} }
if response.Username == "" && response.Name == "" && response.Email == "" { if response.Username == "" && response.Name == "" && response.Email == "" {
+13 -1
View File
@@ -139,6 +139,11 @@ func DeepScan(s github_recon_settings.Settings) (response DeepScanResult) {
} }
s.Logger.Info("Cloned all repositories", "path", tmp_folder) s.Logger.Info("Cloned all repositories", "path", tmp_folder)
if len(repositories) == 0 {
s.Logger.Info("No repositories found for the user, skipping deep scan.")
return
}
authorOccurrences := Authors{} authorOccurrences := Authors{}
mapAuthorToIndex := make(map[string]int) mapAuthorToIndex := make(map[string]int)
for _, repo := range repositories { for _, repo := range repositories {
@@ -202,7 +207,7 @@ func DeepScan(s github_recon_settings.Settings) (response DeepScanResult) {
Name: authorName, Name: authorName,
Email: authorEmail, Email: authorEmail,
FoundIn: []string{repoIdentifier}, FoundIn: []string{repoIdentifier},
Levenshtein: utils.LevenshteinDistance(s.Target, authorName), Levenshtein: levenshteinDistanceAuthor(s.Target, authorName, authorEmail),
}) })
mapAuthorToIndex[trimmedLine] = len(authorOccurrences) - 1 mapAuthorToIndex[trimmedLine] = len(authorOccurrences) - 1
} }
@@ -380,3 +385,10 @@ func findEmailsAndOccurrencesInDir(rootPath string, username string) (Emails, er
return results, nil return results, nil
} }
func levenshteinDistanceAuthor(target, name, email string) int {
if strings.Contains(email, "@") {
email = strings.SplitN(email, "@", 2)[0]
}
return slices.Min([]int{utils.LevenshteinDistance(target, name), utils.LevenshteinDistance(target, email)})
}