-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Corentin Mors
committed
Jun 30, 2024
1 parent
c8bfe08
commit 3e15a54
Showing
8 changed files
with
125 additions
and
77 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
export * from './getLatestDataFromGitLab'; | ||
export * from './getMembersOfGroup'; | ||
export * from './getProjectsList'; | ||
export * from './routine'; | ||
export * from './setTodoAsDone'; |
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,74 @@ | ||
import * as browser from 'webextension-polyfill'; | ||
import { NoAccountSet } from '../../common/errors'; | ||
import { FailFetchSettings } from '../errors'; | ||
import { getSettings } from '../utils/getSettings'; | ||
import { setBadge } from '../utils/setBadge'; | ||
import { getLatestDataFromGitLab } from './getLatestDataFromGitLab'; | ||
|
||
export const routine = async (): Promise<void> => { | ||
console.log('>> POLLING GITLAB API'); | ||
|
||
const settings = await getSettings(); | ||
|
||
if (!settings) { | ||
throw new FailFetchSettings(); | ||
} | ||
|
||
if (!settings.accounts) { | ||
throw new NoAccountSet(); | ||
} | ||
|
||
const result = await Promise.all( | ||
settings.accounts.map(async (account) => { | ||
return { accountId: account.address, data: await getLatestDataFromGitLab({ account }) }; | ||
}) | ||
); | ||
|
||
const mrReceivedDetails = result.flatMap((r) => r.data.mrReceivedDetails); | ||
const mrToReview = result.reduce((acc, r) => acc + r.data.mrToReview, 0); | ||
const mrGivenDetailsNoDraft = result.flatMap((r) => r.data.mrGivenDetailsNoDraft); | ||
const mrReviewed = result.reduce((acc, r) => acc + r.data.mrReviewed, 0); | ||
const myDrafts = result.flatMap((r) => r.data.myDrafts); | ||
const issues = result.flatMap((r) => r.data.issues); | ||
const todos = result.flatMap((r) => r.data.todos); | ||
|
||
/** Save the fetched data */ | ||
|
||
const lastUpdateDateUnix = new Date().getTime(); | ||
|
||
await browser.storage.local.set({ | ||
mrReceived: mrReceivedDetails, | ||
mrToReview, | ||
mrGiven: mrGivenDetailsNoDraft, | ||
mrReviewed, | ||
myDrafts, | ||
issues, | ||
todos, | ||
lastUpdateDateUnix | ||
}); | ||
|
||
/** Update alert badge */ | ||
|
||
const alertBadgeCounters = settings.alertBadgeCounters; | ||
const badgeText = []; | ||
let badgeColor = 'black'; | ||
|
||
if (alertBadgeCounters.includes(0) && (mrToReview > 0 || alertBadgeCounters.length > 1)) { | ||
badgeText.push(mrToReview); | ||
badgeColor = '#dc3545'; // red | ||
} | ||
if (alertBadgeCounters.includes(1) && (mrReviewed > 0 || alertBadgeCounters.length > 1)) { | ||
badgeText.push(mrReviewed); | ||
badgeColor = '#28a745'; // green | ||
} | ||
if (alertBadgeCounters.includes(2) && (issues.length > 0 || alertBadgeCounters.length > 1)) { | ||
badgeText.push(issues.length); | ||
badgeColor = '#fd7e14'; // orange | ||
} | ||
if (alertBadgeCounters.includes(3) && (todos.length > 0 || alertBadgeCounters.length > 1)) { | ||
badgeText.push(todos.length); | ||
badgeColor = '#1f78d1'; // blue | ||
} | ||
|
||
await setBadge(badgeText.length > 0 ? badgeText.join('⋅') : '', badgeColor); | ||
}; |
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