You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ab...@apache.org on 2024/05/27 12:16:50 UTC

(incubator-devlake) branch main updated: Find all candidate issue keys from pr's title and description (#7523)

This is an automated email from the ASF dual-hosted git repository.

abeizn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/main by this push:
     new 4667b3443 Find all candidate issue keys from pr's title and description (#7523)
4667b3443 is described below

commit 4667b34439fd4dc38183cf454339033e00b1fe3b
Author: Lynwee <li...@merico.dev>
AuthorDate: Mon May 27 20:16:43 2024 +0800

    Find all candidate issue keys from pr's title and description (#7523)
    
    * fix(apikey): abort request if api key doesn't match
    
    * feat(webhook): update deployment commit id
    
    * fix(plugins): update path parameter, adapt to latest plugin helper
    
    * feat(plugins): add new plugin linker
    
    * feat(linker): fix compile errors
    
    * feat(linker): remove `since` in options
    
    * feat(linker): add e2e test, fix dora errors
    
    * fix(test): fix test errors
    
    * docs(linker): remove some comments
    
    * fix(linker): fix plugin name
    
    * fix(linker): fix unpected error
    
    * feat(linker): find all candidate issue keys from pr's title and description
    
    * fix(test): fix lint errors
---
 .../plugins/linker/e2e/snapshot_tables/issues.csv  |  2 ++
 .../e2e/snapshot_tables/pull_request_issues.csv    |  1 +
 .../linker/e2e/snapshot_tables/pull_requests.csv   |  2 +-
 backend/plugins/linker/tasks/link_pr_and_issue.go  | 41 +++++++++++-----------
 4 files changed, 25 insertions(+), 21 deletions(-)

diff --git a/backend/plugins/linker/e2e/snapshot_tables/issues.csv b/backend/plugins/linker/e2e/snapshot_tables/issues.csv
index a7d1fd0f9..9ef9a3343 100644
--- a/backend/plugins/linker/e2e/snapshot_tables/issues.csv
+++ b/backend/plugins/linker/e2e/snapshot_tables/issues.csv
@@ -1,2 +1,4 @@
 "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:1237324697","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","", [...]
+"github:GithubIssue:1:1237324698","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/1886","","1886","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/e2e/snapshot_tables/pull_request_issues.csv b/backend/plugins/linker/e2e/snapshot_tables/pull_request_issues.csv
index 4f952b6fd..6b7d30fb8 100644
--- a/backend/plugins/linker/e2e/snapshot_tables/pull_request_issues.csv
+++ b/backend/plugins/linker/e2e/snapshot_tables/pull_request_issues.csv
@@ -1,2 +1,3 @@
 pull_request_id,issue_id,pull_request_key,issue_key,_raw_data_params,_raw_data_table,_raw_data_id,_raw_data_remark
 github:GithubPullRequest:1:1819250573,github:GithubIssue:1:1237324696,7317,1884,,,0,"pull_requests,"
+github:GithubPullRequest:1:1819250573,github:GithubIssue:1:1237324697,7317,1885,,,0,"pull_requests,"
diff --git a/backend/plugins/linker/e2e/snapshot_tables/pull_requests.csv b/backend/plugins/linker/e2e/snapshot_tables/pull_requests.csv
index bf260bf0c..22635f9b0 100644
--- a/backend/plugins/linker/e2e/snapshot_tables/pull_requests.csv
+++ b/backend/plugins/linker/e2e/snapshot_tables/pull_requests.csv
@@ -1,2 +1,2 @@
 "id","created_at","updated_at","_raw_data_params","_raw_data_table","_raw_data_id","_raw_data_remark","base_repo_id","base_ref","base_commit_sha","head_repo_id","head_ref","head_commit_sha","merge_commit_sha","status","original_status","type","component","title","description","url","author_name","author_id","parent_pr_id","pull_request_key","created_date","merged_date","closed_date"
-"github:GithubPullRequest:1:1819250573","2024-05-15 12:07:36.778","2024-05-15 12:07:36.778","{""ConnectionId"":1,""Name"":""apache/incubator-devlake""}","_raw_github_api_pull_requests",191,"","github:GithubRepo:1:384111310","main","64c52748f3529784cb6c8a372691aa0f638fa73d","github:GithubRepo:1:384111310","fix#7275","14fb6488f2208e6a65374a86efce12dd460987e0","91dbce48759da14a4a030124c3ef751f1c5d8389","CLOSED","closed","","","fix: can't GET projects which have / in their name #1884","desc" [...]
\ No newline at end of file
+"github:GithubPullRequest:1:1819250573","2024-05-15 12:07:36.778","2024-05-15 12:07:36.778","{""ConnectionId"":1,""Name"":""apache/incubator-devlake""}","_raw_github_api_pull_requests",191,"","github:GithubRepo:1:384111310","main","64c52748f3529784cb6c8a372691aa0f638fa73d","github:GithubRepo:1:384111310","fix#7275","14fb6488f2208e6a65374a86efce12dd460987e0","91dbce48759da14a4a030124c3ef751f1c5d8389","CLOSED","closed","","","fix: can't GET projects which have / in their name #1884 #1885", [...]
\ No newline at end of file
diff --git a/backend/plugins/linker/tasks/link_pr_and_issue.go b/backend/plugins/linker/tasks/link_pr_and_issue.go
index 39ad5aa8e..a920c4fe7 100644
--- a/backend/plugins/linker/tasks/link_pr_and_issue.go
+++ b/backend/plugins/linker/tasks/link_pr_and_issue.go
@@ -60,41 +60,42 @@ 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 len(foundIssueKeys) > 0 {
+					for _, issueKey := range foundIssueKeys {
+						issueKey = normalizeIssueKey(issueKey)
+						issueKeys = append(issueKeys, issueKey)
+					}
 					break
 				}
 			}
-			issueKey = normalizeIssueKey(issueKey)
-			if issueKey == "" {
+			var issues []*ticket.Issue
+			if err := db.All(&issues, dal.Where("issue_key in ?", issueKeys)); err != nil {
+				return nil, err
+			}
+			if len(issues) == 0 {
 				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 result []interface{}
+			for _, issue := range issues {
+				pullRequestIssue := &crossdomain.PullRequestIssue{
+					PullRequestId:  pullRequest.Id,
+					IssueId:        issue.Id,
+					PullRequestKey: pullRequest.PullRequestKey,
+					IssueKey:       issue.IssueKey,
 				}
-				return nil, err
-			}
-
-			pullRequestIssue := &crossdomain.PullRequestIssue{
-				PullRequestId:  pullRequest.Id,
-				IssueId:        issue.Id,
-				PullRequestKey: pullRequest.PullRequestKey,
-				IssueKey:       issueKey,
+				result = append(result, pullRequestIssue)
 			}
 
-			return []interface{}{pullRequestIssue}, nil
+			return result, nil
 		},
 	})
 	if err != nil {