From 0a1525016af333d9ea287a5b92160f117b30b725 Mon Sep 17 00:00:00 2001 From: orzroa Date: Sat, 8 Dec 2018 16:21:21 +0800 Subject: [PATCH 1/2] add search duration into conf/app.ini --- .gitignore | 4 ++++ conf/app.ini | 3 +++ util/githubsearch/gitclient.go | 10 +++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 071f5bf..e32954c 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,7 @@ test/ main test + +nohup.out +repos/ +x-patrol diff --git a/conf/app.ini b/conf/app.ini index da3c419..20c84dd 100644 --- a/conf/app.ini +++ b/conf/app.ini @@ -15,3 +15,6 @@ USER = xsec PASSWD = x@xsec.io SSL_MODE = disable PATH = data + +[search] +MONTHS = 2 diff --git a/util/githubsearch/gitclient.go b/util/githubsearch/gitclient.go index c81a60e..15327ef 100644 --- a/util/githubsearch/gitclient.go +++ b/util/githubsearch/gitclient.go @@ -26,6 +26,7 @@ package githubsearch import ( "x-patrol/models" + "x-patrol/settings" "github.com/google/go-github/github" @@ -134,6 +135,11 @@ func (c *Client) SearchCode(keyword string) ([]*github.CodeSearchResult, error) var allSearchResult []*github.CodeSearchResult var err error + cfg := settings.Cfg + sec := cfg.Section("search") + months := sec.Key("MONTHS").MustInt(2) + logger.Log.Infof("months: %v", months) + ctx := context.Background() listOpt := github.ListOptions{PerPage: 100} opt := &github.SearchOptions{Sort: "indexed", Order: "desc", TextMatch: true, ListOptions: listOpt} @@ -147,9 +153,11 @@ func (c *Client) SearchCode(keyword string) ([]*github.CodeSearchResult, error) repo, _, _ := c.Client.Repositories.GetByID(ctx, id) pushTime := repo.GetPushedAt().Time now := time.Now() - if now.Sub(pushTime).Hours()/24 <= 60 { + if now.Sub(pushTime).Hours()/24/30 <= float64(months) { logger.Log.Infof("repo: %v, pushed Time: %v, keyword: %v", repo.GetFullName(), pushTime, keyword) t = append(t, codeResult) + } else { + logger.Log.Infof("expired ==> repo: %v, pushed Time: %v, keyword: %v", repo.GetFullName(), pushTime, keyword) } } From d271634f1e5dceb9d1c9fcdf2d1ce301ffc3a0f9 Mon Sep 17 00:00:00 2001 From: orzroa Date: Sat, 8 Dec 2018 23:45:24 +0800 Subject: [PATCH 2/2] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9=E8=A7=84=E5=88=99?= =?UTF-8?q?=E7=9A=84=E6=97=B6=E5=80=99=E6=89=BE=E4=B8=8D=E5=88=B0=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E6=96=87=E4=BB=B6=E5=90=8D=E9=80=89=E9=A1=B9=EF=BC=8C?= =?UTF-8?q?=E5=B7=B2=E7=BB=8F=E4=BF=AE=E5=A4=8D=E3=80=822.=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E8=A7=84=E5=88=99=E7=9A=84=E6=97=B6=E5=80=99=E6=89=80?= =?UTF-8?q?=E6=9C=89=E4=B8=8B=E6=8B=89=E6=A1=86=E4=BC=9A=E8=A2=AB=E9=87=8D?= =?UTF-8?q?=E7=BD=AE=EF=BC=8C=E5=B7=B2=E7=BB=8F=E4=BF=AE=E5=A4=8D=E3=80=82?= =?UTF-8?q?3.=E6=96=87=E4=BB=B6=E5=90=8D=E5=8C=B9=E9=85=8D=E7=9A=84?= =?UTF-8?q?=E6=97=B6=E5=80=99=E9=9C=80=E8=A6=81=E6=96=87=E4=BB=B6=E5=90=8D?= =?UTF-8?q?=E4=B8=AD=E5=AD=98=E5=9C=A8=E8=8B=B1=E6=96=87=E5=8F=A5=E5=8F=B7?= =?UTF-8?q?=EF=BC=8C=E5=B7=B2=E7=BB=8F=E4=BF=AE=E5=A4=8D=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tasks/tasks.go | 2 +- templates/rules_edit.html | 27 ++++++++++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/tasks/tasks.go b/tasks/tasks.go index 0fc5d3c..ae22296 100644 --- a/tasks/tasks.go +++ b/tasks/tasks.go @@ -163,7 +163,7 @@ func DoSearch(reposConfig []models.RepoConfig, rules models.Rules) (map[string]* } else { // when rules.Part in ("filename", "path", "extension"), only search filename, and set rules.Pattern = "\\." opts.FileRegexp = rules.Pattern - rules.Pattern = "\\." + rules.Pattern = "." } var filesOpened int diff --git a/templates/rules_edit.html b/templates/rules_edit.html index e308976..9f73dff 100755 --- a/templates/rules_edit.html +++ b/templates/rules_edit.html @@ -95,8 +95,9 @@

@@ -127,9 +128,7 @@

- +
@@ -157,6 +156,24 @@

+ +