Skip to content

Commit 1052727

Browse files
authored
Merge pull request #1218 from jescalada/fix-linter-warnings
fix: linter warnings and CI failure
2 parents 3322249 + a4671a7 commit 1052727

File tree

8 files changed

+84
-105
lines changed

8 files changed

+84
-105
lines changed

cypress/e2e/autoApproved.cy.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,9 @@ describe('Auto-Approved Push Test', () => {
6363
.local()
6464
.format('dddd, MMMM Do YYYY, h:mm:ss a');
6565

66-
cy.get('kbd')
67-
.trigger('mouseover')
68-
.then(() => {
69-
cy.get('.MuiTooltip-tooltip').should('contain', expectedTooltipTimestamp);
70-
});
66+
cy.get('kbd').trigger('mouseover');
67+
68+
cy.get('.MuiTooltip-tooltip').should('contain', expectedTooltipTimestamp);
7169

7270
cy.contains('approved this contribution').should('not.exist');
7371
});

cypress/e2e/repo.cy.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,11 @@ describe('Repo', () => {
133133
.next()
134134
.get('svg.octicon-copy')
135135
.should('exist')
136-
.click()
137-
.get('svg.octicon-copy')
138-
.should('not.exist')
139-
.get('svg.octicon-check')
140-
.should('exist');
136+
.click();
137+
138+
cy.get('svg.octicon-copy').should('not.exist');
139+
140+
cy.get('svg.octicon-check').should('exist');
141141
});
142142

143143
after(() => {

src/db/file/repo.ts

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,19 @@ export const createRepo = async (repo: Repo): Promise<Repo> => {
106106

107107
export const addUserCanPush = async (_id: string, user: string): Promise<void> => {
108108
user = user.toLowerCase();
109-
return new Promise(async (resolve, reject) => {
110-
const repo = await getRepoById(_id);
111-
if (!repo) {
112-
reject(new Error('Repo not found'));
113-
return;
114-
}
115-
116-
if (repo.users?.canPush.includes(user)) {
117-
resolve();
118-
return;
119-
}
120-
repo.users?.canPush.push(user);
121-
122-
const options = { multi: false, upsert: false };
109+
const repo = await getRepoById(_id);
110+
if (!repo) {
111+
throw new Error('Repo not found');
112+
}
113+
114+
if (repo.users?.canPush.includes(user)) {
115+
return;
116+
}
117+
repo.users?.canPush.push(user);
118+
119+
const options = { multi: false, upsert: false };
120+
121+
return new Promise<void>((resolve, reject) => {
123122
db.update({ _id: _id }, repo, options, (err) => {
124123
// ignore for code coverage as neDB rarely returns errors even for an invalid query
125124
/* istanbul ignore if */
@@ -134,21 +133,20 @@ export const addUserCanPush = async (_id: string, user: string): Promise<void> =
134133

135134
export const addUserCanAuthorise = async (_id: string, user: string): Promise<void> => {
136135
user = user.toLowerCase();
137-
return new Promise(async (resolve, reject) => {
138-
const repo = await getRepoById(_id);
139-
if (!repo) {
140-
reject(new Error('Repo not found'));
141-
return;
142-
}
136+
const repo = await getRepoById(_id);
137+
if (!repo) {
138+
throw new Error('Repo not found');
139+
}
143140

144-
if (repo.users.canAuthorise.includes(user)) {
145-
resolve();
146-
return;
147-
}
141+
if (repo.users.canAuthorise.includes(user)) {
142+
return;
143+
}
148144

149-
repo.users.canAuthorise.push(user);
145+
repo.users.canAuthorise.push(user);
150146

151-
const options = { multi: false, upsert: false };
147+
const options = { multi: false, upsert: false };
148+
149+
return new Promise((resolve, reject) => {
152150
db.update({ _id: _id }, repo, options, (err) => {
153151
// ignore for code coverage as neDB rarely returns errors even for an invalid query
154152
/* istanbul ignore if */
@@ -163,16 +161,16 @@ export const addUserCanAuthorise = async (_id: string, user: string): Promise<vo
163161

164162
export const removeUserCanAuthorise = async (_id: string, user: string): Promise<void> => {
165163
user = user.toLowerCase();
166-
return new Promise(async (resolve, reject) => {
167-
const repo = await getRepoById(_id);
168-
if (!repo) {
169-
reject(new Error('Repo not found'));
170-
return;
171-
}
164+
const repo = await getRepoById(_id);
165+
if (!repo) {
166+
throw new Error('Repo not found');
167+
}
172168

173-
repo.users.canAuthorise = repo.users.canAuthorise.filter((x: string) => x != user);
169+
repo.users.canAuthorise = repo.users.canAuthorise.filter((x: string) => x != user);
174170

175-
const options = { multi: false, upsert: false };
171+
const options = { multi: false, upsert: false };
172+
173+
return new Promise<void>((resolve, reject) => {
176174
db.update({ _id: _id }, repo, options, (err) => {
177175
// ignore for code coverage as neDB rarely returns errors even for an invalid query
178176
/* istanbul ignore if */
@@ -187,16 +185,16 @@ export const removeUserCanAuthorise = async (_id: string, user: string): Promise
187185

188186
export const removeUserCanPush = async (_id: string, user: string): Promise<void> => {
189187
user = user.toLowerCase();
190-
return new Promise(async (resolve, reject) => {
191-
const repo = await getRepoById(_id);
192-
if (!repo) {
193-
reject(new Error('Repo not found'));
194-
return;
195-
}
188+
const repo = await getRepoById(_id);
189+
if (!repo) {
190+
throw new Error('Repo not found');
191+
}
192+
193+
repo.users.canPush = repo.users.canPush.filter((x) => x != user);
196194

197-
repo.users.canPush = repo.users.canPush.filter((x) => x != user);
195+
const options = { multi: false, upsert: false };
198196

199-
const options = { multi: false, upsert: false };
197+
return new Promise<void>((resolve, reject) => {
200198
db.update({ _id: _id }, repo, options, (err) => {
201199
// ignore for code coverage as neDB rarely returns errors even for an invalid query
202200
/* istanbul ignore if */

src/db/index.ts

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -100,57 +100,44 @@ export const createRepo = async (repo: AuthorisedRepo) => {
100100

101101
export const isUserPushAllowed = async (url: string, user: string) => {
102102
user = user.toLowerCase();
103-
return new Promise<boolean>(async (resolve) => {
104-
const repo = await getRepoByUrl(url);
105-
if (!repo) {
106-
resolve(false);
107-
return;
108-
}
109-
110-
if (repo.users?.canPush.includes(user) || repo.users?.canAuthorise.includes(user)) {
111-
resolve(true);
112-
} else {
113-
resolve(false);
114-
}
115-
});
103+
const repo = await getRepoByUrl(url);
104+
if (!repo) {
105+
return false;
106+
}
107+
108+
return repo.users?.canPush.includes(user) || repo.users?.canAuthorise.includes(user);
116109
};
117110

118111
export const canUserApproveRejectPush = async (id: string, user: string) => {
119-
return new Promise(async (resolve) => {
120-
const action = await getPush(id);
121-
if (!action) {
122-
resolve(false);
123-
return;
124-
}
125-
126-
const theRepo = await sink.getRepoByUrl(action.url);
127-
128-
if (theRepo?.users?.canAuthorise?.includes(user)) {
129-
console.log(`user ${user} can approve/reject for repo ${action.url}`);
130-
resolve(true);
131-
} else {
132-
console.log(`user ${user} cannot approve/reject for repo ${action.url}`);
133-
resolve(false);
134-
}
135-
});
112+
const action = await getPush(id);
113+
if (!action) {
114+
return false;
115+
}
116+
117+
const theRepo = await sink.getRepoByUrl(action.url);
118+
119+
if (theRepo?.users?.canAuthorise?.includes(user)) {
120+
console.log(`user ${user} can approve/reject for repo ${action.url}`);
121+
return true;
122+
} else {
123+
console.log(`user ${user} cannot approve/reject for repo ${action.url}`);
124+
return false;
125+
}
136126
};
137127

138128
export const canUserCancelPush = async (id: string, user: string) => {
139-
return new Promise(async (resolve) => {
140-
const action = await getPush(id);
141-
if (!action) {
142-
resolve(false);
143-
return;
144-
}
145-
146-
const isAllowed = await isUserPushAllowed(action.url, user);
147-
148-
if (isAllowed) {
149-
resolve(true);
150-
} else {
151-
resolve(false);
152-
}
153-
});
129+
const action = await getPush(id);
130+
if (!action) {
131+
return false;
132+
}
133+
134+
const isAllowed = await isUserPushAllowed(action.url, user);
135+
136+
if (isAllowed) {
137+
return true;
138+
} else {
139+
return false;
140+
}
154141
};
155142

156143
export const getSessionStore = (): MongoDBStore | null =>

src/proxy/routes/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ import { ProxyOptions } from 'express-http-proxy';
88

99
enum ActionType {
1010
ALLOWED = 'Allowed',
11-
1211
ERROR = 'Error',
13-
1412
BLOCKED = 'Blocked',
1513
}
1614

test/chain.test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ const mockPreProcessors = {
5858
parseAction: sinon.stub(),
5959
};
6060

61-
let mockPushProcessors;
62-
6361
const clearCache = (sandbox) => {
6462
delete require.cache[require.resolve('../src/proxy/processors')];
6563
delete require.cache[require.resolve('../src/proxy/chain')];

test/integration/forcePush.integration.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('Force Push Integration Test', () => {
1515
let rebasedCommitSHA;
1616

1717
before(async function () {
18-
this.timeout(10000); // eslint-disable-line no-invalid-this
18+
this.timeout(10000);
1919

2020
tempDir = path.join(__dirname, '../temp-integration-repo');
2121
await fs.mkdir(tempDir, { recursive: true });
@@ -58,7 +58,7 @@ describe('Force Push Integration Test', () => {
5858

5959
describe('Complete force push pipeline', () => {
6060
it('should handle valid diff after rebase scenario', async function () {
61-
this.timeout(5000); // eslint-disable-line no-invalid-this
61+
this.timeout(5000);
6262

6363
// Create action simulating force push with valid SHAs that have actual changes
6464
const action = new Action(
@@ -101,7 +101,7 @@ describe('Force Push Integration Test', () => {
101101
});
102102

103103
it('should handle unreachable commit SHA error', async function () {
104-
this.timeout(5000); // eslint-disable-line no-invalid-this
104+
this.timeout(5000);
105105

106106
// Invalid SHA to trigger error
107107
const action = new Action(

test/testProxy.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ describe('Proxy', () => {
264264
await proxy.start();
265265

266266
// simulate error in server close
267-
mockHttpServer.close.callsFake((callback) => {
267+
mockHttpServer.close.callsFake(() => {
268268
throw new Error('Server close error');
269269
});
270270

0 commit comments

Comments
 (0)