Skip to content

Commit fc434bd

Browse files
Corentin MorsMikescops
Corentin Mors
authored andcommitted
Get MRs as reviewer
1 parent d028df1 commit fc434bd

11 files changed

+15531
-100
lines changed

package-lock.json

+15,396-37
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gitlab-notify",
3-
"version": "1.4.2",
3+
"version": "1.4.3",
44
"description": "Don't miss any GitLab merge requests and rocket up your productivity.",
55
"main": "index.js",
66
"repository": "https://github.com/Mikescops/gitlab-notify-extension",
@@ -22,11 +22,11 @@
2222
"last 2 Firefox versions"
2323
],
2424
"dependencies": {
25-
"6d": "^1.0.63",
2625
"@gitbeaker/browser": "^28.2.0",
2726
"@primer/components": "^25.0.0",
28-
"@primer/css": "^16.0.2",
27+
"@primer/css": "^16.1.1",
2928
"@primer/octicons-react": "^12.1.0",
29+
"6d": "^1.0.63",
3030
"async": "^3.2.0"
3131
},
3232
"devDependencies": {
@@ -35,7 +35,7 @@
3535
"@neutrinojs/standardjs": "^9.5.0",
3636
"@neutrinojs/style-loader": "^9.5.0",
3737
"@types/async": "^3.2.5",
38-
"@types/react-dom": "^17.0.0",
38+
"@types/react-dom": "^17.0.3",
3939
"@types/styled-components": "^5.1.9",
4040
"@typescript-eslint/eslint-plugin": "^4.19.0",
4141
"@typescript-eslint/parser": "^4.19.0",
@@ -50,8 +50,8 @@
5050
"neutrino-webextension": "^1.2.1",
5151
"neutrinojs-typescript": "^1.1.6",
5252
"prettier": "^2.2.1",
53-
"react": "^17.0.1",
54-
"react-dom": "^17.0.1",
53+
"react": "^17.0.2",
54+
"react-dom": "^17.0.2",
5555
"react-hot-loader": "^4.13.0",
5656
"sinon-chrome": "^3.0.1",
5757
"styled-components": "^5.2.1",
@@ -62,4 +62,4 @@
6262
"webpack-cli": "^3.3.12",
6363
"webpack-dev-server": "^3.11.0"
6464
}
65-
}
65+
}

src/background/endpoints/getLatestDataFromGitLab.ts

+103-43
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@ import { browser } from 'webextension-polyfill-ts';
33
import { Gitlab } from '@gitbeaker/browser';
44
import { getSettings } from '../utils/getSettings';
55
import { fetchMRExtraInfo } from '../utils/fetchMRExtraInfo';
6-
import { MergeRequests, GetSettingsResponse, MergeRequestsDetails, Todo, GitlabAPI, Issue } from '../types';
6+
import {
7+
MergeRequests,
8+
GetSettingsResponse,
9+
MergeRequestsDetails,
10+
Todo,
11+
GitlabAPI,
12+
Issue,
13+
CurrentUser
14+
} from '../types';
715
import { setBadge } from '../utils/setBadge';
816
import {
917
FailFetchIssues,
@@ -14,10 +22,11 @@ import {
1422
GitLabAddressNotSet,
1523
GitLabTokenNotSet
1624
} from '../errors';
25+
import { removeDuplicateObjectFromArray } from '../../popup/helpers';
1726

1827
export const getLatestDataFromGitLab = (cb: CallbackErrorOnly) => {
19-
interface ReviewRequests {
20-
mrAssigned: MergeRequestsDetails[];
28+
interface ReviewReceived {
29+
mrReceived: MergeRequestsDetails[];
2130
mrToReview: number;
2231
}
2332

@@ -29,7 +38,10 @@ export const getLatestDataFromGitLab = (cb: CallbackErrorOnly) => {
2938
interface AsyncResults {
3039
getSettings: GetSettingsResponse;
3140
gitlabApi: GitlabAPI;
32-
reviewRequests: ReviewRequests;
41+
currentUser: CurrentUser;
42+
assignedRequests: MergeRequests[];
43+
reviewerRequests: MergeRequests[];
44+
receivedRequests: ReviewReceived;
3345
givenRequests: ReviewGiven;
3446
issuesAssigned: Issue[];
3547
todos: Todo[];
@@ -65,46 +77,53 @@ export const getLatestDataFromGitLab = (cb: CallbackErrorOnly) => {
6577
return cb(null, api);
6678
}
6779
],
68-
reviewRequests: [
69-
'getSettings',
80+
currentUser: [
7081
'gitlabApi',
7182
(results, cb) => {
72-
const { gitlabApi, getSettings } = results;
83+
const { gitlabApi } = results;
84+
gitlabApi.Users.current()
85+
.then((currentUser: CurrentUser) => {
86+
return cb(null, currentUser);
87+
})
88+
.catch((error: Error) => {
89+
if (error) {
90+
return cb(error);
91+
}
92+
});
93+
}
94+
],
95+
assignedRequests: [
96+
'gitlabApi',
97+
(results, cb) => {
98+
const { gitlabApi } = results;
7399

74100
gitlabApi.MergeRequests.all({
75101
state: 'opened',
76-
scope: 'assigned_to_me',
77-
wip: 'no'
102+
scope: 'assigned_to_me'
78103
})
79-
.then((mrAssigned: MergeRequests[]) => {
80-
return fetchMRExtraInfo(
81-
{
82-
gitlabApi,
83-
mrList: mrAssigned,
84-
gitlabCE: getSettings.gitlabCE
85-
},
86-
(error, mrAssignedDetails) => {
87-
if (error) {
88-
return cb(error);
89-
}
90-
91-
if (!mrAssignedDetails) {
92-
return cb(new FailFetchMergeRequestsAssigned());
93-
}
94-
95-
let mrToReview = 0;
96-
mrAssignedDetails.forEach((mr) => {
97-
if (!mr.approvals.user_has_approved) {
98-
mrToReview += 1;
99-
}
100-
});
104+
.then((mrReceived: MergeRequests[]) => {
105+
return cb(null, mrReceived);
106+
})
107+
.catch((error: Error) => {
108+
if (error) {
109+
return cb(error);
110+
}
111+
});
112+
}
113+
],
114+
reviewerRequests: [
115+
'gitlabApi',
116+
'currentUser',
117+
(results, cb) => {
118+
const { gitlabApi, currentUser } = results;
101119

102-
return cb(null, {
103-
mrAssigned: mrAssignedDetails,
104-
mrToReview
105-
});
106-
}
107-
);
120+
gitlabApi.MergeRequests.all({
121+
state: 'opened',
122+
scope: 'all',
123+
reviewer_id: currentUser.id
124+
})
125+
.then((mrReceived: MergeRequests[]) => {
126+
return cb(null, mrReceived);
108127
})
109128
.catch((error: Error) => {
110129
if (error) {
@@ -113,6 +132,46 @@ export const getLatestDataFromGitLab = (cb: CallbackErrorOnly) => {
113132
});
114133
}
115134
],
135+
receivedRequests: [
136+
'getSettings',
137+
'gitlabApi',
138+
'assignedRequests',
139+
'reviewerRequests',
140+
(results, cb) => {
141+
const { gitlabApi, getSettings, assignedRequests, reviewerRequests } = results;
142+
143+
const requests = removeDuplicateObjectFromArray([...assignedRequests, ...reviewerRequests], 'iid');
144+
145+
return fetchMRExtraInfo(
146+
{
147+
gitlabApi,
148+
mrList: requests,
149+
gitlabCE: getSettings.gitlabCE
150+
},
151+
(error, mrReceivedDetails) => {
152+
if (error) {
153+
return cb(error);
154+
}
155+
156+
if (!mrReceivedDetails) {
157+
return cb(new FailFetchMergeRequestsAssigned());
158+
}
159+
160+
let mrToReview = 0;
161+
mrReceivedDetails.forEach((mr) => {
162+
if (!mr.approvals.user_has_approved) {
163+
mrToReview += 1;
164+
}
165+
});
166+
167+
return cb(null, {
168+
mrReceived: mrReceivedDetails,
169+
mrToReview
170+
});
171+
}
172+
);
173+
}
174+
],
116175
givenRequests: [
117176
'getSettings',
118177
'gitlabApi',
@@ -189,7 +248,8 @@ export const getLatestDataFromGitLab = (cb: CallbackErrorOnly) => {
189248
const { gitlabApi } = results;
190249

191250
gitlabApi.Todos.all({
192-
state: 'pending'
251+
state: 'pending',
252+
per_page: 100
193253
})
194254
.then((todos: Todo[]) => {
195255
if (!todos) {
@@ -207,14 +267,14 @@ export const getLatestDataFromGitLab = (cb: CallbackErrorOnly) => {
207267
],
208268
updateBadge: [
209269
'getSettings',
210-
'reviewRequests',
270+
'receivedRequests',
211271
'givenRequests',
212272
'issuesAssigned',
213273
'todos',
214274
(results, cb) => {
215275
const {
216276
getSettings: { alertBadgeCounters },
217-
reviewRequests: { mrToReview },
277+
receivedRequests: { mrToReview },
218278
givenRequests: { mrReviewed },
219279
issuesAssigned,
220280
todos
@@ -249,19 +309,19 @@ export const getLatestDataFromGitLab = (cb: CallbackErrorOnly) => {
249309
}
250310
],
251311
saveLocalStorage: [
252-
'reviewRequests',
312+
'receivedRequests',
253313
'givenRequests',
254314
'issuesAssigned',
255315
'todos',
256316
(results, cb) => {
257-
const { mrAssigned, mrToReview } = results.reviewRequests;
317+
const { mrReceived, mrToReview } = results.receivedRequests;
258318
const { mrGiven, mrReviewed } = results.givenRequests;
259319
const { todos, issuesAssigned } = results;
260320
const lastUpdateDateUnix = new Date().getTime();
261321

262322
browser.storage.local
263323
.set({
264-
mrAssigned,
324+
mrReceived,
265325
mrToReview,
266326
mrGiven,
267327
mrReviewed,

src/background/endpoints/getLocalData.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const getLocalData = (global_error: Error | null) => {
77

88
return Promise.resolve(
99
browser.storage.local.get([
10-
'mrAssigned',
10+
'mrReceived',
1111
'mrGiven',
1212
'mrToReview',
1313
'mrReviewed',

src/background/types.ts

+12
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ export interface User {
3939
avatar_url: string;
4040
}
4141

42+
export interface CurrentUser {
43+
id: number;
44+
username: string;
45+
email: string;
46+
name: string;
47+
state: string;
48+
avatar_url: string;
49+
web_url: string;
50+
created_at: string;
51+
// missing types here
52+
}
53+
4254
export interface Comment {
4355
system: boolean;
4456
// missing types here

src/background/utils/fetchMRExtraInfo.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ interface FetchMRExtraInfoParams {
99

1010
export const fetchMRExtraInfo = (params: FetchMRExtraInfoParams, cb: Callback<MergeRequestsDetails[]>) => {
1111
const { gitlabApi, mrList, gitlabCE } = params;
12-
const mrAssignedWithDetails: MergeRequestsDetails[] = [];
12+
const mrWithDetails: MergeRequestsDetails[] = [];
1313

1414
async.forEach(
1515
mrList,
@@ -21,7 +21,7 @@ export const fetchMRExtraInfo = (params: FetchMRExtraInfoParams, cb: Callback<Me
2121
approved_by: []
2222
};
2323

24-
mrAssignedWithDetails.push({
24+
mrWithDetails.push({
2525
...mr,
2626
approvals: alternateResponse
2727
});
@@ -34,7 +34,7 @@ export const fetchMRExtraInfo = (params: FetchMRExtraInfoParams, cb: Callback<Me
3434
})
3535
.then((response: Approvals) => {
3636
const details = response;
37-
mrAssignedWithDetails.push({
37+
mrWithDetails.push({
3838
...mr,
3939
approvals: details
4040
});
@@ -55,7 +55,7 @@ export const fetchMRExtraInfo = (params: FetchMRExtraInfoParams, cb: Callback<Me
5555
if (error) {
5656
return cb(error);
5757
}
58-
const mrAssignedSorted = mrAssignedWithDetails
58+
const mrSorted = mrWithDetails
5959
.sort((a, b) => (a.created_at < b.created_at ? 1 : -1))
6060
.sort((a, b) => {
6161
if (a.approvals.user_has_approved === b.approvals.user_has_approved) {
@@ -69,7 +69,7 @@ export const fetchMRExtraInfo = (params: FetchMRExtraInfoParams, cb: Callback<Me
6969
}
7070
return 0;
7171
});
72-
return cb(null, mrAssignedSorted);
72+
return cb(null, mrSorted);
7373
}
7474
);
7575
};

src/manifest/common.manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"manifest_version": 2,
3-
"version": "1.4.2",
3+
"version": "1.4.3",
44
"name": "GitLab Notify",
55
"short_name": "GitLab Notify",
66
"description": "Don't miss any GitLab merge requests or issues and rocket up your productivity.",

src/popup/App.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const App = () => {
1414
const [appStatus, setAppStatus] = useState<AppStatus>('idle');
1515
const [errorMessage, setErrorMessage] = useState('');
1616
const [mrData, setMrData] = useState<MergeRequestSendMessageReply>({
17-
mrAssigned: [],
17+
mrReceived: [],
1818
mrToReview: 0,
1919
mrGiven: [],
2020
mrReviewed: 0,

src/popup/components/Content.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export const Content = (props: Props) => {
8383
// show data
8484
let mrList: MergeRequestsDetails[] = [];
8585
if (currentTab === 0) {
86-
mrList = mrData.mrAssigned;
86+
mrList = mrData.mrReceived;
8787
} else {
8888
mrList = mrData.mrGiven;
8989
}

src/popup/components/Footer.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const Footer = (props: Props) => {
2626
let mrNumber = 0;
2727
let mrTotal = 0;
2828
if (currentTab === 0) {
29-
mrTotal = mrData.mrAssigned.length;
29+
mrTotal = mrData.mrReceived.length;
3030
mrNumber = mrTotal - mrData.mrToReview;
3131
} else if (currentTab === 1) {
3232
mrTotal = mrData.mrGiven.length;

0 commit comments

Comments
 (0)