Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

主要修复了规则配置的一些问题 #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ test/
main

test

nohup.out
repos/
x-patrol
3 changes: 3 additions & 0 deletions conf/app.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ USER = xsec
PASSWD = [email protected]
SSL_MODE = disable
PATH = data

[search]
MONTHS = 2
2 changes: 1 addition & 1 deletion tasks/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 22 additions & 5 deletions templates/rules_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ <h1>

<div class="col-sm-10">
<select class="form-control" name="part">
<option value="keyword" selected>keyword</option>
<option value="github">github keyword</option>
<option value="keyword" selected>本地检测文件内容</option>
<option value="filename">本地检测文件名</option>
<option value="github">github搜索</option>
</select>
</div>
</div>
Expand Down Expand Up @@ -127,9 +128,7 @@ <h1>
<label for="desc" class="col-sm-2 control-label">描述</label>

<div class="col-sm-10">
<textarea name="desc" id="desc" class="form-control">
{{.rules.Description}}
</textarea>
<textarea name="desc" id="desc" class="form-control">{{.rules.Description}}</textarea>
</div>
</div>
<div class="form-group">
Expand Down Expand Up @@ -157,6 +156,24 @@ <h1>
</div>
</div>

<script type="text/javascript">
function enableSelection(optionName, selectedValue){
options = document.getElementsByName(optionName)[0];
for(i = 0; i < options.length; i++){
console.log(options[i].value + "==" + selectedValue + "?")
if(options[i].value == selectedValue){
options[i].selected = true;
break;
}
}
}

enableSelection('part', {{.rules.Part}})
enableSelection('type', {{.rules.Type}})
enableSelection('status', {{.rules.Status}})

</script>

<!-- jQuery 2.2.3 -->
<script src="/lib/jQuery/jquery-2.2.3.min.js"></script>
<!-- Bootstrap 3.3.6 -->
Expand Down
10 changes: 9 additions & 1 deletion util/githubsearch/gitclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ package githubsearch

import (
"x-patrol/models"
"x-patrol/settings"

"github.com/google/go-github/github"

Expand Down Expand Up @@ -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}
Expand All @@ -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)
}
}

Expand Down