1
1
import cloneDeep from 'lodash/cloneDeep'
2
2
import { create , query , fetch , deleteEntity } from '../../entity'
3
+ import { Compare } from './compare'
4
+ import { MergeQueue } from './mergeQueue'
5
+ import error from '../../core/contentstackError'
3
6
4
7
/**
5
8
*
@@ -44,6 +47,29 @@ export function Branch (http, data = {}) {
44
47
*
45
48
*/
46
49
this . fetch = fetch ( http , 'branch' )
50
+
51
+ /**
52
+ * @description Compare allows you compare any or specific ContentType or GlobalFields.
53
+ * @memberof Branch
54
+ * @func compare
55
+ * @returns {Compare } Instance of Compare.
56
+ * @example
57
+ * import * as contentstack from '@contentstack/management'
58
+ * const client = contentstack.client()
59
+ *
60
+ * client.stack({ api_key: 'api_key'}).branch('branch_uid').compare('compare_uid')
61
+ *
62
+ */
63
+ this . compare = ( compareBranchUid ) => {
64
+ const compareData = { stackHeaders : this . stackHeaders }
65
+ if ( compareBranchUid ) {
66
+ compareData . branches = {
67
+ base_branch : this . uid ,
68
+ compare_branch : compareBranchUid
69
+ }
70
+ }
71
+ return new Compare ( http , compareData )
72
+ }
47
73
} else {
48
74
/**
49
75
* @description The Create a Branch call creates a new branch in a particular stack of your Contentstack account.
@@ -54,7 +80,7 @@ export function Branch (http, data = {}) {
54
80
* @example
55
81
* import * as contentstack from '@contentstack/management'
56
82
* const client = contentstack.client()
57
- * const branch = {
83
+ * const branch = {
58
84
* name: 'branch_name',
59
85
* source: 'master'
60
86
* }
@@ -77,6 +103,68 @@ export function Branch (http, data = {}) {
77
103
* .then((collection) => { console.log(collection) })
78
104
*/
79
105
this . query = query ( { http, wrapperCollection : BranchCollection } )
106
+
107
+ /**
108
+ * @description Merge allows user to merge branches in a Stack.
109
+ * @memberof Branch
110
+ * @func merge
111
+ * @returns {Object } Response Object
112
+ *
113
+ * @example
114
+ * import * as contentstack from '@contentstack/management'
115
+ * const client = contentstack.client()
116
+ *
117
+ * const params = {
118
+ * base_branch: "main",
119
+ * compare_branch: "dev",
120
+ * default_merge_strategy: "merge_prefer_base",
121
+ * merge_comment: "Merging dev into main",
122
+ * no_revert: true,
123
+ * }
124
+ * const mergeObj = {
125
+ * item_merge_strategies: [
126
+ * {
127
+ * uid: "global_field_uid",
128
+ * type: "global_field",
129
+ * merge_strategy: "merge_prefer_base"
130
+ * }
131
+ * ],
132
+ * }
133
+ *
134
+ * client.stack({ api_key: 'api_key'}).branch().merge(mergeObj, params)
135
+ */
136
+ this . merge = async ( mergeObj , params ) => {
137
+ const url = '/stacks/branches_merge'
138
+ const header = {
139
+ headers : { ...cloneDeep ( this . stackHeaders ) } ,
140
+ params : params
141
+ }
142
+ try {
143
+ const response = await http . post ( url , mergeObj , header )
144
+ if ( response . data ) return response . data
145
+ else throw error ( response )
146
+ } catch ( e ) {
147
+ throw error ( e )
148
+ }
149
+ }
150
+
151
+ /**
152
+ * @description Merge Queue provides list of all recent merge jobs in a Stack.
153
+ * @memberof Branch
154
+ * @func mergeQueue
155
+ * @returns {MergeQueue } Instance of MergeQueue
156
+ *
157
+ * @example
158
+ * import * as contentstack from '@contentstack/management'
159
+ * const client = contentstack.client()
160
+ *
161
+ * client.stack({ api_key: 'api_key'}).branch().mergeQueue()
162
+ *
163
+ */
164
+ this . mergeQueue = ( uid ) => {
165
+ const mergeData = { stackHeaders : this . stackHeaders , uid }
166
+ return new MergeQueue ( http , mergeData )
167
+ }
80
168
}
81
169
return this
82
170
}
0 commit comments