Skip to content
Merged
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: 1 addition & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,8 @@ GITHUB_ISSUE_PRIORITY='^(highest|high|medium|low)$'
GITHUB_ISSUE_TYPE_BUG='^(bug|failure|error)$'
GITHUB_ISSUE_TYPE_REQUIREMENT='^(feat|feature|proposal|requirement)$'
GITHUB_ISSUE_TYPE_INCIDENT=
# GITHUB_PR_BODY_CLOSE_PATTERN='(?mi)(fix|close|resolve|fixes|closes|resolves|fixed|closed|resolved)[\s]*.*(((and )?'
# GITHUB_PR_BODY_CLOSE_PATTERN='(?mi)(fix|close|resolve|fixes|closes|resolves|fixed|closed|resolved)[\s]*.*(((and )?(#|https:\/\/github.com\/%s\/%s\/issues\/)(\d+)[ ]*)+)'
GITHUB_PR_BODY_CLOSE_PATTERN=
# GITHUB_PR_BODY_NUMBER_PREFIX='(#|https:\/\/github.com\/%s\/%s\/issues\/)'
GITHUB_PR_BODY_NUMBER_PREFIX=
# GITHUB_PR_TITLE_PATTERN='.*\(#(\d+)\)'
GITHUB_PR_TITLE_PATTERN=

Expand Down
2 changes: 1 addition & 1 deletion models/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func init() {
}
sqlDB.SetMaxIdleConns(10)
sqlDB.SetMaxOpenConns(100)
sqlDB.SetConnMaxLifetime(time.Hour)
sqlDB.SetConnMaxLifetime(time.Hour * 24)
migrateDB()
}

Expand Down
1 change: 0 additions & 1 deletion plugins/github/README-zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
### 正则配置
在.env文件中,可以配置
- GITHUB_PR_BODY_CLOSE_PATTERN: 定义了pr body关联issue的关键字,可查看.env.example里面的示例
- GITHUB_PR_BODY_NUMBER_PREFIX: 定义了pr body中issue的前缀(在pr中关联issue有两种可能的表示方法,分别是#100和https://github.com/{owner}/{repo}/issues/1000)

## 示例

Expand Down
1 change: 0 additions & 1 deletion plugins/github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ Click **Save Settings** to update additional settings.
### 正则配置
Define regex pattern in .env
- GITHUB_PR_BODY_CLOSE_PATTERN: Define key word to associate issue in pr body, please check the example in .env.example
- GITHUB_PR_BODY_NUMBER_PREFIX: Define the prefix of issue number in pr(issue can be shown as two types: 1. #1000, 2. https://github.com/{owner}/{repo}/issues/1000), please check the example in .env.example

## Sample Request

Expand Down
4 changes: 2 additions & 2 deletions plugins/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,8 @@ var PluginEntry Github //nolint
// standalone mode for debugging
func main() {
//args := os.Args[1:]
owner := "pingcap"
repo := "tidb"
owner := "ClickHouse"
repo := "ClickHouse"
//if len(args) > 0 {
// owner = args[0]
//}
Expand Down
24 changes: 12 additions & 12 deletions plugins/github/tasks/github_pull_request_issue_enricher.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,18 @@ func EnrichPullRequestIssues(ctx context.Context, repoId int, owner string, repo
//the pattern before the issue number, sometimes, the issue number is #1098, sometimes it is https://xxx/#1098
var prBodyCloseRegex *regexp.Regexp
var prBodyClosePattern string
var numberPrefix string

v := config.GetConfig()
prBodyClosePattern = v.GetString("GITHUB_PR_BODY_CLOSE_PATTERN")
numberPrefix = v.GetString("GITHUB_PR_BODY_NUMBER_PREFIX")

numberPattern := fmt.Sprintf(numberPrefix+`\d+[ ]*)+)`, owner, repo)
prBodyClosePattern = strings.Replace(prBodyClosePattern, "%s", owner, 1)
prBodyClosePattern = strings.Replace(prBodyClosePattern, "%s", repo, 1)
if len(prBodyClosePattern) > 0 {
prPattern := prBodyClosePattern + numberPattern
prBodyCloseRegex = regexp.MustCompile(prPattern)
prBodyCloseRegex = regexp.MustCompile(prBodyClosePattern)
}
numberPrefixRegex := regexp.MustCompile(numberPrefix)
charPattern := regexp.MustCompile(`[a-zA-Z\s,]+`)
githubPullRequst := &githubModels.GithubPullRequest{}
cursor, err := lakeModels.Db.Model(&githubPullRequst).
Where("repo_id = ?", repoId).
Where("repo_id = ?", repoId).Order("github_id desc").
Rows()
if err != nil {
return err
Expand All @@ -49,15 +45,18 @@ func EnrichPullRequestIssues(ctx context.Context, repoId int, owner string, repo
if err != nil {
return err
}
issueNumberListStr := ""

//find the matched string in body
issueNumberListStr := ""

if prBodyCloseRegex != nil {
issueNumberListStr = prBodyCloseRegex.FindString(githubPullRequst.Body)
}
//replace https:// to #, then we can process it later
if strings.Contains(issueNumberListStr, "https") {
issueNumberListStr = numberPrefixRegex.ReplaceAllString(issueNumberListStr, "#")

if issueNumberListStr == "" {
return nil
}

issueNumberListStr = charPattern.ReplaceAllString(issueNumberListStr, "#")
//split the string by '#'
issueNumberList := strings.Split(issueNumberListStr, "#")
Expand Down Expand Up @@ -89,6 +88,7 @@ func EnrichPullRequestIssues(ctx context.Context, repoId int, owner string, repo
if err != nil {
return err
}
fmt.Println(githubPullRequstIssue.PullNumber)
}
}
return nil
Expand Down
10 changes: 8 additions & 2 deletions plugins/refdiff/tasks/refs_issues_diffs_calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ func CalculateIssuesDiff(ctx context.Context, pairs []RefPair, progress chan<- f
pairList[i] = [2]string{fmt.Sprintf("%s:%s", repoId, pair.NewRef), fmt.Sprintf("%s:%s", repoId, pair.OldRef)}
}
db := lakeModels.Db.Table("refs_commits_diffs").
Joins("left join pull_requests on pull_requests.merge_commit_sha = refs_commits_diffs.commit_sha").
Joins("left join pull_request_issues on pull_request_issues.pull_request_id = pull_requests.id").
Joins("left join ( "+
"select pull_request_id as id, commit_sha from pull_request_commits "+
"left join pull_requests p on pull_request_commits.pull_request_id = p.id "+
"where p.repo_id = '"+repoId+
"' union "+
"select id, merge_commit_sha as commit_sha from pull_requests where repo_id = '"+repoId+"') _combine_pr "+
"on _combine_pr.commit_sha = refs_commits_diffs.commit_sha").
Joins("left join pull_request_issues on pull_request_issues.pull_request_id = _combine_pr.id").
Joins("left join refs on refs.commit_sha = refs_commits_diffs.new_ref_commit_sha").
Order("refs_commits_diffs.new_ref_name ASC").
Where("refs.repo_id = ? and pull_request_issues.issue_number > 0 and (refs_commits_diffs.new_ref_name, refs_commits_diffs.old_ref_name) in ?",
Expand Down