From 595da56eef722f0aa57e41d2069da39f1df90689 Mon Sep 17 00:00:00 2001 From: zricethezav Date: Sat, 27 Jan 2018 15:35:25 -0500 Subject: [PATCH] [update] regexp work --- checks.go | 26 ++++++++++++++++++++++++++ main.go | 38 +++++++++++++++++++++++++++----------- 2 files changed, 53 insertions(+), 11 deletions(-) create mode 100644 checks.go diff --git a/checks.go b/checks.go new file mode 100644 index 00000000..770bc3b6 --- /dev/null +++ b/checks.go @@ -0,0 +1,26 @@ +package main + +import ( + "bytes" + _ "fmt" + "regexp" +) + +func checkRegex(diff []byte) { + var re *regexp.Regexp + var found string + lines := bytes.Split(diff, []byte("\n")) + for _, line := range lines { + if len(line) == 0 { + continue + } + + for _, v := range regexes { + re = regexp.MustCompile(v) + found = re.FindString(string(line)) + if len(found) == 0 { + continue + } + } + } +} diff --git a/main.go b/main.go index bd9b6ce7..27ba5967 100644 --- a/main.go +++ b/main.go @@ -13,20 +13,29 @@ import ( // gotta be fast type Repo struct { - url string - name string - path string - branches *Branch -} - -type Branch struct { + url string name string + path string } +// memoization for commit1+commit2 hash +var cache map[string]bool var appRoot string +var regexes map[string]string +var strictRegexes map[string]string func init() { appRoot, _ = os.Getwd() + cache = make(map[string]bool) + regexes = map[string]string{ + "github": "[g|G][i|I][t|T][h|H][u|U][b|B].*", + "aws": "[a|A][w|W][s|S].*", + "heroku": "[h|H][e|E][r|R][o|O][k|K][u|U].*", + "facebook": "[f|F][a|A][c|C][e|E][b|B][o|O][o|O][k|K].*", + "twitter": "[t|T][w|W][i|I][t|T][t|T][e|E][r|R].*", + "reddit": "[r|R][e|E][d|D][d|D][i|I][t|T].*", + "twilio": "[t|T][w|W][i|I][l|L][i|I][o|O].*", + } } func main() { @@ -51,7 +60,7 @@ func repoStart(repo_url string) { log.Fatal(err) } - repo := Repo{repo_url, repo_name, "", nil} + repo := Repo{repo_url, repo_name, ""} repo.audit() repo.cleanup() } @@ -96,16 +105,23 @@ func (repo Repo) audit() { if j == len(commits)-2 { break } + + // TODO need a memoization structure for commitB vs commits[j+1] + // memoize the actual diff function diff(string(commitB), string(commits[j+1])) } } } func diff(commit1 string, commit2 string) { - // fmt.Println(commit1, commit2) - _, err := exec.Command("git", "diff", commit1, commit2).Output() + _, seen := cache[commit1+commit2] + if seen { + return + } + out, err := exec.Command("git", "diff", commit1, commit2).Output() if err != nil { log.Fatalf("error retrieving commits %v\n", err) } - //fmt.Printf("%s\n", out) + cache[commit1+commit2] = true + checkRegex(out) }