Skip to content

Commit

Permalink
feat: Add push rule service (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
jetersen authored and jdalrymple committed Aug 11, 2018
1 parent 305b7f2 commit 395f83c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/services/PushRule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { BaseService, RequestHelper } from '../infrastructure';

class PushRule extends BaseService {

create(projectId, options) {
const pId = encodeURIComponent(projectId);

return RequestHelper.post(this, `projects/${pId}/push_rule`, options);
}

async edit(projectId, { upsert, ...options } = {}) {
const pId = encodeURIComponent(projectId);

if (upsert) {
const pushRule = await this.show(projectId);

if (!pushRule) return this.create(projectId, options)
}

return RequestHelper.put(this, `projects/${pId}/push_rule`, args);
}

remove(projectId) {
const pId = encodeURIComponent(projectId);

return RequestHelper.delete(this, `projects/${pId}/push_rule`);
}

show(projectId) {
const pId = encodeURIComponent(projectId);

return RequestHelper.get(this, `projects/${pId}/push_rule`);
}

}

export default PushRule;
1 change: 1 addition & 0 deletions src/services/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export { default as Services } from './Services';
export { default as Tags } from './Tags';
export { default as Todos } from './Todos';
export { default as Triggers } from './Triggers';
export { default as PushRule } from './PushRule';

// General
export { default as ApplicationSettings } from './ApplicationSettings';
Expand Down
18 changes: 18 additions & 0 deletions test/tests/services/PushRule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { PushRule } from '../../../src';

describe('PushRule', () => {
it('should create or edit push rule on upsert', async () => {
const service = new PushRule({
url: process.env.GITLAB_URL,
token: process.env.PERSONAL_ACCESS_TOKEN,
});
const pushRules = {
upsert: true,
member_check: true
}
const result = await service.edit(1, pushRules);

expect(result).toBeInstanceOf(Object);
expect(result.member_check).toBeTrue();
});
});

0 comments on commit 395f83c

Please sign in to comment.