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
2 changes: 2 additions & 0 deletions backend/plugins/linker/e2e/snapshot_tables/issues.csv
Original file line number Diff line number Diff line change
@@ -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_project","urgency"
"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","","","","","",""
Original file line number Diff line number Diff line change
@@ -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,"
Original file line number Diff line number Diff line change
@@ -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","https://github.com/apache/incubator-devlake/pull/7317","abeizn","github:GithubAccount:1:101256042","",7317,"2024-04-12 05:31:43.000","2024-04-13 05:31:43.000","2024-04-12 06:44:27.000"
"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","desc","https://github.com/apache/incubator-devlake/pull/7317","abeizn","github:GithubAccount:1:101256042","",7317,"2024-04-12 05:31:43.000","2024-04-13 05:31:43.000","2024-04-12 06:44:27.000"
41 changes: 21 additions & 20 deletions backend/plugins/linker/tasks/link_pr_and_issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down