-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: change script to support more than 1 git repository gf-589 (#590)
* feat: script should support more than 1 local git repository gf-589 (#589) * feat: script should support more than 1 local git repository gf-589 (#589) - moved helpers into src/libs/helpers - changed functions to arrow functions
- Loading branch information
Showing
8 changed files
with
90 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
scripts/analytics/src/modules/analytics/libs/helpers/helpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { mergeStats } from "./merge-stats/merge-stats.helper.js"; |
23 changes: 23 additions & 0 deletions
23
...nalytics/src/modules/analytics/libs/helpers/merge-array-items/merge-array-items.helper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const mergeArrayItems = <T>( | ||
items: T[], | ||
compareFunction: (item1: T, item2: T) => boolean, | ||
mergeFunction: (mergedItem: T, item: T) => void, | ||
): T[] => { | ||
const mergedItems: T[] = []; | ||
|
||
for (const item of items) { | ||
const mergedItem = mergedItems.find((mergedItem) => | ||
compareFunction(mergedItem, item), | ||
); | ||
|
||
if (mergedItem) { | ||
mergeFunction(mergedItem, item); | ||
} else { | ||
mergedItems.push(item); | ||
} | ||
} | ||
|
||
return mergedItems; | ||
}; | ||
|
||
export { mergeArrayItems }; |
15 changes: 15 additions & 0 deletions
15
...nalytics/src/modules/analytics/libs/helpers/merge-stats-items/merge-stats-items.helper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { type ActivityLogCreateItemRequestDto } from "../../types/types.js"; | ||
import { mergeArrayItems } from "../merge-array-items/merge-array-items.helper.js"; | ||
|
||
const mergeStatsItems = ( | ||
items: ActivityLogCreateItemRequestDto["items"], | ||
): ActivityLogCreateItemRequestDto["items"] => | ||
mergeArrayItems( | ||
items, | ||
(item1, item2) => | ||
item1.authorEmail === item2.authorEmail && | ||
item1.authorName === item2.authorName, | ||
(mergedItem, item) => (mergedItem.commitsNumber += item.commitsNumber), | ||
); | ||
|
||
export { mergeStatsItems }; |
18 changes: 18 additions & 0 deletions
18
scripts/analytics/src/modules/analytics/libs/helpers/merge-stats/merge-stats.helper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { type ActivityLogCreateItemRequestDto } from "../../types/types.js"; | ||
import { mergeArrayItems } from "../merge-array-items/merge-array-items.helper.js"; | ||
import { mergeStatsItems } from "../merge-stats-items/merge-stats-items.helper.js"; | ||
|
||
const mergeStats = ( | ||
statsAll: ActivityLogCreateItemRequestDto[], | ||
): ActivityLogCreateItemRequestDto[] => | ||
mergeArrayItems( | ||
statsAll, | ||
(item1, item2) => item1.date === item2.date, | ||
(mergedItem, item) => | ||
(mergedItem.items = mergeStatsItems([ | ||
...mergedItem.items, | ||
...item.items, | ||
])), | ||
); | ||
|
||
export { mergeStats }; |