Skip to content

Commit 395f83c

Browse files
jetersenjdalrymple
authored andcommitted
feat: Add push rule service (#143)
1 parent 305b7f2 commit 395f83c

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

src/services/PushRule.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { BaseService, RequestHelper } from '../infrastructure';
2+
3+
class PushRule extends BaseService {
4+
5+
create(projectId, options) {
6+
const pId = encodeURIComponent(projectId);
7+
8+
return RequestHelper.post(this, `projects/${pId}/push_rule`, options);
9+
}
10+
11+
async edit(projectId, { upsert, ...options } = {}) {
12+
const pId = encodeURIComponent(projectId);
13+
14+
if (upsert) {
15+
const pushRule = await this.show(projectId);
16+
17+
if (!pushRule) return this.create(projectId, options)
18+
}
19+
20+
return RequestHelper.put(this, `projects/${pId}/push_rule`, args);
21+
}
22+
23+
remove(projectId) {
24+
const pId = encodeURIComponent(projectId);
25+
26+
return RequestHelper.delete(this, `projects/${pId}/push_rule`);
27+
}
28+
29+
show(projectId) {
30+
const pId = encodeURIComponent(projectId);
31+
32+
return RequestHelper.get(this, `projects/${pId}/push_rule`);
33+
}
34+
35+
}
36+
37+
export default PushRule;

src/services/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export { default as Services } from './Services';
6363
export { default as Tags } from './Tags';
6464
export { default as Todos } from './Todos';
6565
export { default as Triggers } from './Triggers';
66+
export { default as PushRule } from './PushRule';
6667

6768
// General
6869
export { default as ApplicationSettings } from './ApplicationSettings';

test/tests/services/PushRule.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { PushRule } from '../../../src';
2+
3+
describe('PushRule', () => {
4+
it('should create or edit push rule on upsert', async () => {
5+
const service = new PushRule({
6+
url: process.env.GITLAB_URL,
7+
token: process.env.PERSONAL_ACCESS_TOKEN,
8+
});
9+
const pushRules = {
10+
upsert: true,
11+
member_check: true
12+
}
13+
const result = await service.edit(1, pushRules);
14+
15+
expect(result).toBeInstanceOf(Object);
16+
expect(result.member_check).toBeTrue();
17+
});
18+
});

0 commit comments

Comments
 (0)