-
-
Notifications
You must be signed in to change notification settings - Fork 300
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
1 parent
305b7f2
commit 395f83c
Showing
3 changed files
with
56 additions
and
0 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
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; |
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 |
---|---|---|
@@ -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(); | ||
}); | ||
}); |