File tree Expand file tree Collapse file tree 3 files changed +56
-0
lines changed Expand file tree Collapse file tree 3 files changed +56
-0
lines changed Original file line number Diff line number Diff line change
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 ;
Original file line number Diff line number Diff line change @@ -63,6 +63,7 @@ export { default as Services } from './Services';
63
63
export { default as Tags } from './Tags' ;
64
64
export { default as Todos } from './Todos' ;
65
65
export { default as Triggers } from './Triggers' ;
66
+ export { default as PushRule } from './PushRule' ;
66
67
67
68
// General
68
69
export { default as ApplicationSettings } from './ApplicationSettings' ;
Original file line number Diff line number Diff line change
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments