This is an automated email from the ASF dual-hosted git repository. warren pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
commit 2c9023cc9f900941559b24a8ec8644f47d21f3d6 Author: Nddtfjiang <[email protected]> AuthorDate: Wed Jun 8 02:12:52 2022 +0000 refactor: add type commitpair and pairlist Add type RefCommitPair Add type RefPairList Add type RefCommitPairs Add type RefPairLists Nddtfjiang <[email protected]> --- plugins/refdiff/tasks/ref_commit_diff_calculator.go | 12 ++++++------ plugins/refdiff/tasks/ref_issue_diff_calculator.go | 10 +++++----- plugins/refdiff/tasks/refdiff_task_data.go | 4 ++++ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/plugins/refdiff/tasks/ref_commit_diff_calculator.go b/plugins/refdiff/tasks/ref_commit_diff_calculator.go index 420ed963..606d1462 100644 --- a/plugins/refdiff/tasks/ref_commit_diff_calculator.go +++ b/plugins/refdiff/tasks/ref_commit_diff_calculator.go @@ -28,7 +28,7 @@ import ( ) // Calculate the commits pairs both from Options.Pairs and TagPattern -func CalculateCommitsPairs(taskCtx core.SubTaskContext) ([][4]string, error) { +func CalculateCommitsPairs(taskCtx core.SubTaskContext) (RefCommitPairs, error) { data := taskCtx.GetData().(*RefdiffTaskData) repoId := data.Options.RepoId pairs := data.Options.Pairs @@ -37,13 +37,13 @@ func CalculateCommitsPairs(taskCtx core.SubTaskContext) ([][4]string, error) { rs, err := CaculateTagPattern(taskCtx) if err != nil { - return [][4]string{}, err + return RefCommitPairs{}, err } if tagsLimit > rs.Len() { tagsLimit = rs.Len() } - commitPairs := make([][4]string, 0, tagsLimit+len(pairs)) + commitPairs := make(RefCommitPairs, 0, tagsLimit+len(pairs)) for i := 1; i < tagsLimit; i++ { commitPairs = append(commitPairs, [4]string{rs[i-1].CommitSha, rs[i].CommitSha, rs[i-1].Name, rs[i].Name}) } @@ -67,14 +67,14 @@ func CalculateCommitsPairs(taskCtx core.SubTaskContext) ([][4]string, error) { // get new ref's commit sha newCommit, err := ref2sha(refPair.NewRef) if err != nil { - return [][4]string{}, fmt.Errorf("failed to load commit sha for NewRef on pair #%d: %w", i, err) + return RefCommitPairs{}, fmt.Errorf("failed to load commit sha for NewRef on pair #%d: %w", i, err) } // get old ref's commit sha oldCommit, err := ref2sha(refPair.OldRef) if err != nil { - return [][4]string{}, fmt.Errorf("failed to load commit sha for OleRef on pair #%d: %w", i, err) + return RefCommitPairs{}, fmt.Errorf("failed to load commit sha for OleRef on pair #%d: %w", i, err) } - commitPairs = append(commitPairs, [4]string{newCommit, oldCommit, refPair.NewRef, refPair.OldRef}) + commitPairs = append(commitPairs, RefCommitPair{newCommit, oldCommit, refPair.NewRef, refPair.OldRef}) } return commitPairs, nil diff --git a/plugins/refdiff/tasks/ref_issue_diff_calculator.go b/plugins/refdiff/tasks/ref_issue_diff_calculator.go index 5b9d92a7..aed0f4e8 100644 --- a/plugins/refdiff/tasks/ref_issue_diff_calculator.go +++ b/plugins/refdiff/tasks/ref_issue_diff_calculator.go @@ -27,7 +27,7 @@ import ( ) // Calculate the pair list both from Options.Pairs and TagPattern -func CaculatePairList(taskCtx core.SubTaskContext) ([][2]string, error) { +func CaculatePairList(taskCtx core.SubTaskContext) (RefPairLists, error) { data := taskCtx.GetData().(*RefdiffTaskData) repoId := data.Options.RepoId pairs := data.Options.Pairs @@ -35,19 +35,19 @@ func CaculatePairList(taskCtx core.SubTaskContext) ([][2]string, error) { rs, err := CaculateTagPattern(taskCtx) if err != nil { - return [][2]string{}, err + return RefPairLists{}, err } if tagsLimit > rs.Len() { tagsLimit = rs.Len() } - pairList := make([][2]string, 0, tagsLimit+len(pairs)) + pairList := make(RefPairLists, 0, tagsLimit+len(pairs)) for i := 1; i < tagsLimit; i++ { - pairList = append(pairList, [2]string{fmt.Sprintf("%s:%s", repoId, rs[i-1].Id), fmt.Sprintf("%s:%s", repoId, rs[i].Id)}) + pairList = append(pairList, RefPairList{fmt.Sprintf("%s:%s", repoId, rs[i-1].Id), fmt.Sprintf("%s:%s", repoId, rs[i].Id)}) } for _, pair := range pairs { - pairList = append(pairList, [2]string{fmt.Sprintf("%s:%s", repoId, pair.NewRef), fmt.Sprintf("%s:%s", repoId, pair.OldRef)}) + pairList = append(pairList, RefPairList{fmt.Sprintf("%s:%s", repoId, pair.NewRef), fmt.Sprintf("%s:%s", repoId, pair.OldRef)}) } return pairList, nil diff --git a/plugins/refdiff/tasks/refdiff_task_data.go b/plugins/refdiff/tasks/refdiff_task_data.go index 648f671e..ad36b2c1 100644 --- a/plugins/refdiff/tasks/refdiff_task_data.go +++ b/plugins/refdiff/tasks/refdiff_task_data.go @@ -46,6 +46,10 @@ type RefPair struct { NewRef string OldRef string } +type RefCommitPair [4]string +type RefPairList [2]string +type RefCommitPairs []RefCommitPair +type RefPairLists []RefPairList type Refs []code.Ref type RefsAlphabetically Refs
