You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ly...@apache.org on 2024/05/27 12:04:06 UTC
(incubator-devlake) 01/01: feat(linker): find all candidate issue keys from pr's title and description
This is an automated email from the ASF dual-hosted git repository.
lynwee pushed a commit to branch dev-1
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
commit 5b0266bb18fb2a2bfc403e5709784080d7ea46d0
Author: d4x1 <15...@qq.com>
AuthorDate: Mon May 27 20:03:53 2024 +0800
feat(linker): find all candidate issue keys from pr's title and description
---
.../plugins/linker/e2e/snapshot_tables/issues.csv | 1 +
backend/plugins/linker/tasks/link_pr_and_issue.go | 42 +++++++++++-----------
2 files changed, 23 insertions(+), 20 deletions(-)
diff --git a/backend/plugins/linker/e2e/snapshot_tables/issues.csv b/backend/plugins/linker/e2e/snapshot_tables/issues.csv
index a7d1fd0f9..81fb251ce 100644
--- a/backend/plugins/linker/e2e/snapshot_tables/issues.csv
+++ b/backend/plugins/linker/e2e/snapshot_tables/issues.csv
@@ -1,2 +1,3 @@
"id","created_at","updated_at","_raw_data_params","_raw_data_table","_raw_data_id","_raw_data_remark","url","icon_url","issue_key","title","description","epic_key","type","original_type","status","original_status","resolution_date","created_date","updated_date","lead_time_minutes","parent_issue_id","priority","story_point","original_estimate_minutes","time_spent_minutes","time_remaining_minutes","creator_id","creator_name","assignee_id","assignee_name","severity","component","original_pr [...]
"github:GithubIssue:1:1237324696","2024-05-14 10:42:37.529","2024-05-15 12:07:36.450","{""ConnectionId"":1,""Name"":""apache/incubator-devlake""}","_raw_github_graphql_issues",59,"","https://github.com/apache/incubator-devlake/issues/1884","","1884","Add a plugin for Ones","desc","","","type/feature-request,Stale,add-a-plugin","TODO","OPEN","2032-05-16 15:23:21.000","2022-05-16 15:23:21.000","2024-05-11 00:17:21.000",10,"","",11,1,12,11,"github:GithubAccount:1:14050754","Startrekzky","", [...]
+"github:GithubIssue:1:1237324696","2024-05-14 10:42:37.529","2024-05-15 12:07:36.450","{""ConnectionId"":1,""Name"":""apache/incubator-devlake""}","_raw_github_graphql_issues",59,"","https://github.com/apache/incubator-devlake/issues/1885","","1885","Add a plugin for Ones","desc","","","type/feature-request,Stale,add-a-plugin","TODO","OPEN","2032-05-16 15:23:21.000","2022-05-16 15:23:21.000","2024-05-11 00:17:21.000",10,"","",11,1,12,11,"github:GithubAccount:1:14050754","Startrekzky","", [...]
diff --git a/backend/plugins/linker/tasks/link_pr_and_issue.go b/backend/plugins/linker/tasks/link_pr_and_issue.go
index 39ad5aa8e..c8fec3330 100644
--- a/backend/plugins/linker/tasks/link_pr_and_issue.go
+++ b/backend/plugins/linker/tasks/link_pr_and_issue.go
@@ -60,41 +60,43 @@ func LinkPrToIssue(taskCtx plugin.SubTaskContext) errors.Error {
defer cursor.Close()
- // iterate all rows
enricher, err := api.NewDataEnricher(api.DataEnricherArgs[code.PullRequest]{
Ctx: taskCtx,
Name: code.PullRequest{}.TableName(),
Input: cursor,
Enrich: func(pullRequest *code.PullRequest) ([]interface{}, errors.Error) {
- issueKey := ""
+ var issueKeys []string
for _, text := range []string{pullRequest.Title, pullRequest.Description} {
- issueKey = data.PrToIssueRegexp.FindString(text)
- if issueKey != "" {
+ foundIssueKeys := data.PrToIssueRegexp.FindAllString(text, -1)
+ if foundIssueKeys != nil && len(foundIssueKeys) > 0 {
+ for _, issueKey := range foundIssueKeys {
+ issueKey = normalizeIssueKey(issueKey)
+ issueKeys = append(issueKeys, issueKey)
+ }
break
}
}
- issueKey = normalizeIssueKey(issueKey)
- if issueKey == "" {
- return nil, nil
- }
- issue := &ticket.Issue{}
- if err := db.First(issue, dal.Where("issue_key = ?", issueKey)); err != nil {
- if db.IsErrorNotFound(err) {
- return nil, nil
- }
+ var issues []*ticket.Issue
+ if err := db.All(&issues, dal.Where("issue_key in ?", issueKeys)); err != nil {
return nil, err
}
-
- pullRequestIssue := &crossdomain.PullRequestIssue{
- PullRequestId: pullRequest.Id,
- IssueId: issue.Id,
- PullRequestKey: pullRequest.PullRequestKey,
- IssueKey: issueKey,
+ if len(issues) == 0 {
+ return nil, nil
+ }
+ var result []interface{}
+ for _, issue := range issues {
+ pullRequestIssue := &crossdomain.PullRequestIssue{
+ PullRequestId: pullRequest.Id,
+ IssueId: issue.Id,
+ PullRequestKey: pullRequest.PullRequestKey,
+ IssueKey: issue.IssueKey,
+ }
+ result = append(result, pullRequestIssue)
}
- return []interface{}{pullRequestIssue}, nil
+ return result, nil
},
})
if err != nil {