-
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: 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
Artem Zahorodniuk
authored and
Artem Zahorodniuk
committed
Oct 2, 2024
1 parent
aff30fd
commit f73b4ed
Showing
5 changed files
with
54 additions
and
46 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
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, | ||
) => { | ||
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 }; |
13 changes: 13 additions & 0 deletions
13
...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,13 @@ | ||
import type { ActivityLogCreateItemRequestDto } from "../../types/types.js"; | ||
import { mergeArrayItems } from "../merge-array-items/merge-array-items.helper.js"; | ||
|
||
const mergeStatsItems = (items: ActivityLogCreateItemRequestDto["items"]) => | ||
mergeArrayItems( | ||
items, | ||
(item1, item2) => | ||
item1.authorEmail === item2.authorEmail && | ||
item1.authorName === item2.authorName, | ||
(mergedItem, item) => (mergedItem.commitsNumber += item.commitsNumber), | ||
); | ||
|
||
export { mergeStatsItems }; |
16 changes: 16 additions & 0 deletions
16
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,16 @@ | ||
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[]) => | ||
mergeArrayItems( | ||
statsAll, | ||
(item1, item2) => item1.date === item2.date, | ||
(mergedItem, item) => | ||
(mergedItem.items = mergeStatsItems([ | ||
...mergedItem.items, | ||
...item.items, | ||
])), | ||
); | ||
|
||
export { mergeStats }; |