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
42 changes: 42 additions & 0 deletions backend/plugins/linker/e2e/link_pr_and_issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,48 @@ import (
"github.com/apache/incubator-devlake/plugins/linker/tasks"
)

func TestLinkPrToIssueWithSharedRepo(t *testing.T) {
var plugin impl.Linker
dataflowTester := e2ehelper.NewDataFlowTester(t, "linker", plugin)

regexpStr := "#(\\d+)"
re, err := regexp.Compile(regexpStr)
if err != nil {
panic(err)
}
taskData := &tasks.LinkerTaskData{
Options: &tasks.LinkerOptions{
PrToIssueRegexp: regexpStr,
ProjectName: "GitHub1",
},
PrToIssueRegexp: re,
}

// Import input tables for two projects sharing repo R1
dataflowTester.ImportCsvIntoTabler("./snapshot_tables/cross_project_issues.csv", &ticket.Issue{})
dataflowTester.ImportCsvIntoTabler("./snapshot_tables/cross_project_pull_requests.csv", &code.PullRequest{})
dataflowTester.ImportCsvIntoTabler("./snapshot_tables/cross_project_project_mapping.csv", &crossdomain.ProjectMapping{})
dataflowTester.ImportCsvIntoTabler("./snapshot_tables/cross_project_board_issues.csv", &ticket.BoardIssue{})

// Pre-populate pull_request_issues with data from GitHub2's linker and from GitHub converter.
// These rows must survive when we run the linker for GitHub1.
dataflowTester.ImportCsvIntoTabler("./snapshot_tables/cross_project_pull_request_issues_before.csv", &crossdomain.PullRequestIssue{})

dataflowTester.Subtask(tasks.LinkPrToIssueMeta, taskData)

// Verify: GitHub1's links are created, GitHub2's linker link and converter link survive
dataflowTester.VerifyTable(
crossdomain.PullRequestIssue{},
"./snapshot_tables/cross_project_pull_request_issues_after.csv",
e2ehelper.ColumnWithRawData(
"pull_request_id",
"pull_request_key",
"issue_id",
"issue_key",
),
)
}

func TestLinkPrToIssue(t *testing.T) {
var plugin impl.Linker
dataflowTester := e2ehelper.NewDataFlowTester(t, "linker", plugin)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"board_id","issue_id","created_at","updated_at","_raw_data_params","_raw_data_table","_raw_data_id","_raw_data_remark"
"github:GithubRepo:1:384111310","github:GithubIssue:1:1237324696","2024-05-14 10:42:37.541","2024-05-28 00:25:41.436","{""ConnectionId"":1,""Name"":""apache/incubator-devlake""}","_raw_github_graphql_issues",69,""
"github:GithubRepo:1:384111310","github:GithubIssue:1:1237324697","2024-05-14 10:42:37.541","2024-05-28 00:25:41.436","{""ConnectionId"":1,""Name"":""apache/incubator-devlake""}","_raw_github_graphql_issues",69,""
"github:GithubRepo:2:999999999","github:GithubIssue:2:2001","2024-05-14 10:42:37.541","2024-05-28 00:25:41.436","{""ConnectionId"":2,""Name"":""other/repo""}","_raw_github_graphql_issues",70,""
Original file line number Diff line number Diff line change
@@ -0,0 +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","Issue 1884","desc","","","type/feature-request","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","Issue 1885","desc","","","type/feature-request","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:2:2001","2024-05-14 10:42:37.529","2024-05-15 12:07:36.450","{""ConnectionId"":2,""Name"":""other/repo""}","_raw_github_graphql_issues",60,"","https://github.com/other/repo/issues/2001","","2001","Issue 2001","desc","","","type/bug","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
@@ -0,0 +1,5 @@
"project_name","table","row_id","created_at","updated_at","_raw_data_params","_raw_data_table","_raw_data_id","_raw_data_remark"
"GitHub1","repos","github:GithubRepo:1:384111310","2024-05-15 12:02:13.590","2024-05-15 12:02:13.590","GitHub1","",0,""
"GitHub1","boards","github:GithubRepo:1:384111310","2024-05-15 12:02:13.590","2024-05-15 12:02:13.590","GitHub1","",0,""
"GitHub2","repos","github:GithubRepo:1:384111310","2024-05-15 12:02:13.590","2024-05-15 12:02:13.590","GitHub2","",0,""
"GitHub2","boards","github:GithubRepo:2:999999999","2024-05-15 12:02:13.590","2024-05-15 12:02:13.590","GitHub2","",0,""
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
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,"
github:GithubPullRequest:1:1819250574,github:GithubIssue:2:2001,7318,2001,,,0,"pull_requests,"
github:GithubPullRequest:1:1819250574,github:GithubIssue:1:1237324696,7318,1884,"{""ConnectionId"":1,""Name"":""apache/incubator-devlake""}",_raw_github_api_pull_requests,191,""
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
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:1819250574,github:GithubIssue:1:1237324697,7318,1885,,,0,"pull_requests,"
github:GithubPullRequest:1:1819250574,github:GithubIssue:2:2001,7318,2001,,,0,"pull_requests,"
github:GithubPullRequest:1:1819250574,github:GithubIssue:1:1237324696,7318,1884,"{""ConnectionId"":1,""Name"":""apache/incubator-devlake""}",_raw_github_api_pull_requests,191,""
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"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 #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"
"github:GithubPullRequest:1:1819250574","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",192,"","github:GithubRepo:1:384111310","main","64c52748f3529784cb6c8a372691aa0f638fa73d","github:GithubRepo:1:384111310","fix#2001","14fb6488f2208e6a65374a86efce12dd460987e0","","MERGED","merged","","","fix: something related to #2001","desc","https://github.com/apache/incubator-devlake/pull/7318","abeizn","github:GithubAccount:1:101256042","",7318,"2024-04-12 05:31:43.000","2024-04-13 05:31:43.000","2024-04-12 06:44:27.000"
18 changes: 14 additions & 4 deletions backend/plugins/linker/tasks/link_pr_and_issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,23 @@ func clearHistoryData(db dal.Dal, data *LinkerTaskData) errors.Error {
WHERE pull_request_id IN (
SELECT pr.id
FROM pull_requests pr
LEFT JOIN project_mapping pm
INNER JOIN project_mapping pm
ON pm.table = 'repos'
AND pm.row_id = pr.base_repo_id
AND pm.project_name = ?
)
WHERE pm.project_name = ?
)
AND issue_id IN (
SELECT bi.issue_id
FROM board_issues bi
INNER JOIN project_mapping pm2
ON pm2.table = 'boards'
AND pm2.row_id = bi.board_id
WHERE pm2.project_name = ?
)
AND (_raw_data_table = '' OR _raw_data_table IS NULL)
AND _raw_data_remark LIKE '%pull_requests,%'
`
return db.Exec(sql, data.Options.ProjectName)
return db.Exec(sql, data.Options.ProjectName, data.Options.ProjectName)
}

func LinkPrToIssue(taskCtx plugin.SubTaskContext) errors.Error {
Expand Down
Loading