@itentialopensource/adapter-git 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -1
- package/adapter.js +111 -1
- package/package.json +1 -1
- package/pronghorn.json +78 -2
- package/refs?service=git-upload-pack +0 -0
- package/test/integration/adapterTestIntegration.js +52 -0
- package/test/unit/adapterTestUnit.js +52 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
|
|
2
|
+
## 0.2.0 [03-09-2023]
|
|
3
|
+
|
|
4
|
+
* Add tasks to create and checkout branch
|
|
5
|
+
|
|
6
|
+
See merge request itentialopensource/adapters/devops-netops/adapter-git!1
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
2
10
|
## 0.1.1 [03-07-2023]
|
|
3
11
|
|
|
4
12
|
* Bug fixes and performance improvements
|
|
@@ -6,4 +14,3 @@
|
|
|
6
14
|
See commit caed158
|
|
7
15
|
|
|
8
16
|
---
|
|
9
|
-
|
package/adapter.js
CHANGED
|
@@ -252,6 +252,72 @@ class Git extends EventEmitterCl {
|
|
|
252
252
|
}
|
|
253
253
|
}
|
|
254
254
|
|
|
255
|
+
createBranch(options, callback) {
|
|
256
|
+
const meth = 'adapter-createBranch';
|
|
257
|
+
const origin = `${this.id}-${meth}`;
|
|
258
|
+
log.trace(origin);
|
|
259
|
+
try {
|
|
260
|
+
// verify the required data has been provided
|
|
261
|
+
if (options === undefined || options === null || options === '') {
|
|
262
|
+
const errorObj = formatErrorObject(origin, 'Missing Data', ['options'], null, null, null);
|
|
263
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
264
|
+
return callback(null, errorObj);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const copiedOptions = { ...options };
|
|
268
|
+
copiedOptions.fs = fs;
|
|
269
|
+
git.branch(copiedOptions)
|
|
270
|
+
.then(() => callback({
|
|
271
|
+
status: 'success',
|
|
272
|
+
code: 200
|
|
273
|
+
}))
|
|
274
|
+
.catch((err) => {
|
|
275
|
+
const errorObj = formatErrorObject(origin, 'Creating new branch failed', null, null, null, err);
|
|
276
|
+
log.error('error:', err);
|
|
277
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
278
|
+
return callback(null, errorObj);
|
|
279
|
+
});
|
|
280
|
+
} catch (ex) {
|
|
281
|
+
const errorObj = formatErrorObject(origin, 'Caught Exception', null, null, null, ex);
|
|
282
|
+
log.error(ex);
|
|
283
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
284
|
+
return callback(null, errorObj);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
checkoutBranch(options, callback) {
|
|
289
|
+
const meth = 'adapter-checkoutBranch';
|
|
290
|
+
const origin = `${this.id}-${meth}`;
|
|
291
|
+
log.trace(origin);
|
|
292
|
+
try {
|
|
293
|
+
// verify the required data has been provided
|
|
294
|
+
if (options === undefined || options === null || options === '') {
|
|
295
|
+
const errorObj = formatErrorObject(origin, 'Missing Data', ['options'], null, null, null);
|
|
296
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
297
|
+
return callback(null, errorObj);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const copiedOptions = { ...options };
|
|
301
|
+
copiedOptions.fs = fs;
|
|
302
|
+
git.checkout(copiedOptions)
|
|
303
|
+
.then(() => callback({
|
|
304
|
+
status: 'success',
|
|
305
|
+
code: 200
|
|
306
|
+
}))
|
|
307
|
+
.catch((err) => {
|
|
308
|
+
const errorObj = formatErrorObject(origin, 'Checking out failed', null, null, null, err);
|
|
309
|
+
log.error('error:', err);
|
|
310
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
311
|
+
return callback(null, errorObj);
|
|
312
|
+
});
|
|
313
|
+
} catch (ex) {
|
|
314
|
+
const errorObj = formatErrorObject(origin, 'Caught Exception', null, null, null, ex);
|
|
315
|
+
log.error(ex);
|
|
316
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
317
|
+
return callback(null, errorObj);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
255
321
|
removeFile(options, callback) {
|
|
256
322
|
const meth = 'adapter-removeFile';
|
|
257
323
|
const origin = `${this.id}-${meth}`;
|
|
@@ -456,7 +522,7 @@ class Git extends EventEmitterCl {
|
|
|
456
522
|
}
|
|
457
523
|
}
|
|
458
524
|
|
|
459
|
-
removeAndPushFile(cloneOptions, removeFileOptions, commitOptions, pushOptions, callback) {
|
|
525
|
+
removeAndPushFile(cloneOptions, createAndCheckoutNewBranch = false, checkoutExistingBranch = false, branchOptions, checkoutOptions, removeFileOptions, commitOptions, pushOptions, callback) {
|
|
460
526
|
const meth = 'adapter-removeAndPushFile';
|
|
461
527
|
const origin = `${this.id}-${meth}`;
|
|
462
528
|
log.trace(origin);
|
|
@@ -483,6 +549,24 @@ class Git extends EventEmitterCl {
|
|
|
483
549
|
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
484
550
|
return callback(null, errorObj);
|
|
485
551
|
}
|
|
552
|
+
if (createAndCheckoutNewBranch) {
|
|
553
|
+
if (branchOptions === undefined || branchOptions === null || branchOptions === '') {
|
|
554
|
+
const errorObj = formatErrorObject(origin, 'Missing Data', ['branch options'], null, null, null);
|
|
555
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
556
|
+
return callback(null, errorObj);
|
|
557
|
+
}
|
|
558
|
+
if (checkoutOptions === undefined || checkoutOptions === null || checkoutOptions === '') {
|
|
559
|
+
const errorObj = formatErrorObject(origin, 'Missing Data', ['checkout options'], null, null, null);
|
|
560
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
561
|
+
return callback(null, errorObj);
|
|
562
|
+
}
|
|
563
|
+
} else if (!createAndCheckoutNewBranch && checkoutExistingBranch) {
|
|
564
|
+
if (checkoutOptions === undefined || checkoutOptions === null || checkoutOptions === '') {
|
|
565
|
+
const errorObj = formatErrorObject(origin, 'Missing Data', ['checkout options'], null, null, null);
|
|
566
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
567
|
+
return callback(null, errorObj);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
486
570
|
|
|
487
571
|
const copiedCloneOptions = { ...cloneOptions };
|
|
488
572
|
copiedCloneOptions.fs = fs;
|
|
@@ -512,6 +596,32 @@ class Git extends EventEmitterCl {
|
|
|
512
596
|
task: 'clone',
|
|
513
597
|
result: 'success'
|
|
514
598
|
});
|
|
599
|
+
if (createAndCheckoutNewBranch) {
|
|
600
|
+
const copiedBranchOptions = { ...branchOptions };
|
|
601
|
+
const copiedCheckoutOptions = { ...checkoutOptions };
|
|
602
|
+
copiedBranchOptions.fs = fs;
|
|
603
|
+
copiedCheckoutOptions.fs = fs;
|
|
604
|
+
return git.branch(copiedBranchOptions)
|
|
605
|
+
.then(() => git.checkout(copiedCheckoutOptions));
|
|
606
|
+
}
|
|
607
|
+
if (checkoutExistingBranch) {
|
|
608
|
+
const copiedCheckoutOptions = { ...checkoutOptions };
|
|
609
|
+
copiedCheckoutOptions.fs = fs;
|
|
610
|
+
return git.checkout(copiedCheckoutOptions);
|
|
611
|
+
}
|
|
612
|
+
})
|
|
613
|
+
.then(() => {
|
|
614
|
+
if (createAndCheckoutNewBranch) {
|
|
615
|
+
successfulResult.results.push({
|
|
616
|
+
task: 'create and checkout new branch',
|
|
617
|
+
result: 'success'
|
|
618
|
+
});
|
|
619
|
+
} else if (!createAndCheckoutNewBranch && checkoutExistingBranch) {
|
|
620
|
+
successfulResult.results.push({
|
|
621
|
+
task: 'checkout existing branch',
|
|
622
|
+
result: 'success'
|
|
623
|
+
});
|
|
624
|
+
}
|
|
515
625
|
if (Array.isArray(removeFileOptions.filepath)) {
|
|
516
626
|
return Promise.all(
|
|
517
627
|
removeFileOptions.filepath.map((file) => {
|
package/package.json
CHANGED
package/pronghorn.json
CHANGED
|
@@ -191,10 +191,62 @@
|
|
|
191
191
|
],
|
|
192
192
|
"task": true
|
|
193
193
|
},
|
|
194
|
+
{
|
|
195
|
+
"name": "createBranch",
|
|
196
|
+
"summary": "Create a branch",
|
|
197
|
+
"description": "Create a branch",
|
|
198
|
+
"input": [
|
|
199
|
+
{
|
|
200
|
+
"name": "options",
|
|
201
|
+
"type": "object",
|
|
202
|
+
"info": "options to create a branch",
|
|
203
|
+
"required": true
|
|
204
|
+
}
|
|
205
|
+
],
|
|
206
|
+
"output": {
|
|
207
|
+
"name": "result",
|
|
208
|
+
"type": "object",
|
|
209
|
+
"description": "A JSON Object containing status, code and the result"
|
|
210
|
+
},
|
|
211
|
+
"route": {
|
|
212
|
+
"verb": "POST",
|
|
213
|
+
"path": "/createBranch"
|
|
214
|
+
},
|
|
215
|
+
"roles": [
|
|
216
|
+
"admin"
|
|
217
|
+
],
|
|
218
|
+
"task": true
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
"name": "checkoutBranch",
|
|
222
|
+
"summary": "Checkout a branch",
|
|
223
|
+
"description": "Checkout a branch",
|
|
224
|
+
"input": [
|
|
225
|
+
{
|
|
226
|
+
"name": "options",
|
|
227
|
+
"type": "object",
|
|
228
|
+
"info": "options to checkout a branch",
|
|
229
|
+
"required": true
|
|
230
|
+
}
|
|
231
|
+
],
|
|
232
|
+
"output": {
|
|
233
|
+
"name": "result",
|
|
234
|
+
"type": "object",
|
|
235
|
+
"description": "A JSON Object containing status, code and the result"
|
|
236
|
+
},
|
|
237
|
+
"route": {
|
|
238
|
+
"verb": "POST",
|
|
239
|
+
"path": "/checkoutBranch"
|
|
240
|
+
},
|
|
241
|
+
"roles": [
|
|
242
|
+
"admin"
|
|
243
|
+
],
|
|
244
|
+
"task": true
|
|
245
|
+
},
|
|
194
246
|
{
|
|
195
247
|
"name": "removeAndPushFile",
|
|
196
|
-
"summary": "Clone the repo, remove a file, commit then push",
|
|
197
|
-
"description": "Clone the repo, remove a file, commit then push",
|
|
248
|
+
"summary": "Clone the repo, checkout branch, remove a file, commit then push",
|
|
249
|
+
"description": "Clone the repo, checkout branch, remove a file, commit then push",
|
|
198
250
|
"input": [
|
|
199
251
|
{
|
|
200
252
|
"name": "cloneOptions",
|
|
@@ -202,6 +254,30 @@
|
|
|
202
254
|
"info": "options to clone a repo",
|
|
203
255
|
"required": true
|
|
204
256
|
},
|
|
257
|
+
{
|
|
258
|
+
"name": "createAndCheckoutNewBranch",
|
|
259
|
+
"type": "boolean",
|
|
260
|
+
"info": "whether to create and checkout a new branch",
|
|
261
|
+
"required": false
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
"name": "checkoutExistingBranch",
|
|
265
|
+
"type": "boolean",
|
|
266
|
+
"info": "whether to checkout an existing branch",
|
|
267
|
+
"required": false
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
"name": "branchOptions",
|
|
271
|
+
"type": "object",
|
|
272
|
+
"info": "options to create a new branch",
|
|
273
|
+
"required": false
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
"name": "checkoutOptions",
|
|
277
|
+
"type": "object",
|
|
278
|
+
"info": "options to checkout a branch",
|
|
279
|
+
"required": false
|
|
280
|
+
},
|
|
205
281
|
{
|
|
206
282
|
"name": "removeFileOptions",
|
|
207
283
|
"type": "object",
|
|
Binary file
|
|
@@ -182,6 +182,58 @@ describe('[integration] Git Adapter Test', () => {
|
|
|
182
182
|
}
|
|
183
183
|
});
|
|
184
184
|
|
|
185
|
+
const branchOptions = {
|
|
186
|
+
dir: '../../test',
|
|
187
|
+
ref: 'patch/test'
|
|
188
|
+
};
|
|
189
|
+
describe('#createBranch', () => {
|
|
190
|
+
if (!stub) {
|
|
191
|
+
it('should create a new branch', (done) => {
|
|
192
|
+
try {
|
|
193
|
+
a.createBranch(branchOptions, (data, error) => {
|
|
194
|
+
try {
|
|
195
|
+
runCommonAsserts(data, error);
|
|
196
|
+
assert.equal(200, data.code);
|
|
197
|
+
done();
|
|
198
|
+
} catch (ex) {
|
|
199
|
+
log.error(`Test Failure: ${ex}`);
|
|
200
|
+
done(ex);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
} catch (exc) {
|
|
204
|
+
log.error(`Adapter Exception: ${exc}`);
|
|
205
|
+
done(exc);
|
|
206
|
+
}
|
|
207
|
+
}).timeout(attemptTimeout);
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
const checkoutOptions = {
|
|
212
|
+
dir: '../../test',
|
|
213
|
+
ref: 'patch/test'
|
|
214
|
+
};
|
|
215
|
+
describe('#checkoutBranch', () => {
|
|
216
|
+
if (!stub) {
|
|
217
|
+
it('should checkout a branch', (done) => {
|
|
218
|
+
try {
|
|
219
|
+
a.checkoutBranch(checkoutOptions, (data, error) => {
|
|
220
|
+
try {
|
|
221
|
+
runCommonAsserts(data, error);
|
|
222
|
+
assert.equal(200, data.code);
|
|
223
|
+
done();
|
|
224
|
+
} catch (ex) {
|
|
225
|
+
log.error(`Test Failure: ${ex}`);
|
|
226
|
+
done(ex);
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
} catch (exc) {
|
|
230
|
+
log.error(`Adapter Exception: ${exc}`);
|
|
231
|
+
done(exc);
|
|
232
|
+
}
|
|
233
|
+
}).timeout(attemptTimeout);
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
|
|
185
237
|
const removeOptions = {
|
|
186
238
|
dir: '../../test',
|
|
187
239
|
filepath: 'README.md'
|
|
@@ -551,6 +551,54 @@ describe('[unit] Git Adapter Test', () => {
|
|
|
551
551
|
}).timeout(attemptTimeout);
|
|
552
552
|
});
|
|
553
553
|
|
|
554
|
+
describe('#createBranch - errors', () => {
|
|
555
|
+
it('should have a createBranch function', (done) => {
|
|
556
|
+
assert.equal(true, typeof a.createBranch === 'function');
|
|
557
|
+
done();
|
|
558
|
+
});
|
|
559
|
+
it('should error on createBranch - no options', (done) => {
|
|
560
|
+
try {
|
|
561
|
+
a.createBranch(null, (data, error) => {
|
|
562
|
+
try {
|
|
563
|
+
const displayE = 'options is required';
|
|
564
|
+
runErrorAsserts(data, error, 'AD.300', 'Test-Git-adapter-createBranch', displayE);
|
|
565
|
+
done();
|
|
566
|
+
} catch (ex) {
|
|
567
|
+
log.error(`Test Failure: ${ex}`);
|
|
568
|
+
done(ex);
|
|
569
|
+
}
|
|
570
|
+
});
|
|
571
|
+
} catch (exc) {
|
|
572
|
+
log.error(`Adapter Exception: ${exc}`);
|
|
573
|
+
done(exc);
|
|
574
|
+
}
|
|
575
|
+
}).timeout(attemptTimeout);
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
describe('#checkoutBranch - errors', () => {
|
|
579
|
+
it('should have a checkoutBranch function', (done) => {
|
|
580
|
+
assert.equal(true, typeof a.checkoutBranch === 'function');
|
|
581
|
+
done();
|
|
582
|
+
});
|
|
583
|
+
it('should error on checkoutBranch - no options', (done) => {
|
|
584
|
+
try {
|
|
585
|
+
a.checkoutBranch(null, (data, error) => {
|
|
586
|
+
try {
|
|
587
|
+
const displayE = 'options is required';
|
|
588
|
+
runErrorAsserts(data, error, 'AD.300', 'Test-Git-adapter-checkoutBranch', displayE);
|
|
589
|
+
done();
|
|
590
|
+
} catch (ex) {
|
|
591
|
+
log.error(`Test Failure: ${ex}`);
|
|
592
|
+
done(ex);
|
|
593
|
+
}
|
|
594
|
+
});
|
|
595
|
+
} catch (exc) {
|
|
596
|
+
log.error(`Adapter Exception: ${exc}`);
|
|
597
|
+
done(exc);
|
|
598
|
+
}
|
|
599
|
+
}).timeout(attemptTimeout);
|
|
600
|
+
});
|
|
601
|
+
|
|
554
602
|
describe('#removeAndPushFile - errors', () => {
|
|
555
603
|
it('should have a removeAndPushFile function', (done) => {
|
|
556
604
|
assert.equal(true, typeof a.removeAndPushFile === 'function');
|
|
@@ -558,7 +606,7 @@ describe('[unit] Git Adapter Test', () => {
|
|
|
558
606
|
});
|
|
559
607
|
it('should error on removeAndPushFile - no cloneOptions', (done) => {
|
|
560
608
|
try {
|
|
561
|
-
a.removeAndPushFile(null, null, null, null, (data, error) => {
|
|
609
|
+
a.removeAndPushFile(null, null, null, null, null, null, null, null, (data, error) => {
|
|
562
610
|
try {
|
|
563
611
|
const displayE = 'clone options is required';
|
|
564
612
|
runErrorAsserts(data, error, 'AD.300', 'Test-Git-adapter-removeAndPushFile', displayE);
|
|
@@ -575,7 +623,7 @@ describe('[unit] Git Adapter Test', () => {
|
|
|
575
623
|
}).timeout(attemptTimeout);
|
|
576
624
|
it('should error on removeAndPushFile - no removeFileOptions', (done) => {
|
|
577
625
|
try {
|
|
578
|
-
a.removeAndPushFile({}, null, null, null, (data, error) => {
|
|
626
|
+
a.removeAndPushFile({}, null, null, null, null, null, null, null, (data, error) => {
|
|
579
627
|
try {
|
|
580
628
|
const displayE = 'remove file options is required';
|
|
581
629
|
runErrorAsserts(data, error, 'AD.300', 'Test-Git-adapter-removeAndPushFile', displayE);
|
|
@@ -592,7 +640,7 @@ describe('[unit] Git Adapter Test', () => {
|
|
|
592
640
|
}).timeout(attemptTimeout);
|
|
593
641
|
it('should error on removeAndPushFile - no commitOptions', (done) => {
|
|
594
642
|
try {
|
|
595
|
-
a.removeAndPushFile({}, {}, null, null, (data, error) => {
|
|
643
|
+
a.removeAndPushFile({}, null, null, null, null, {}, null, null, (data, error) => {
|
|
596
644
|
try {
|
|
597
645
|
const displayE = 'commit options is required';
|
|
598
646
|
runErrorAsserts(data, error, 'AD.300', 'Test-Git-adapter-removeAndPushFile', displayE);
|
|
@@ -609,7 +657,7 @@ describe('[unit] Git Adapter Test', () => {
|
|
|
609
657
|
}).timeout(attemptTimeout);
|
|
610
658
|
it('should error on removeAndPushFile - no pushOptions', (done) => {
|
|
611
659
|
try {
|
|
612
|
-
a.removeAndPushFile({}, {}, {}, null, (data, error) => {
|
|
660
|
+
a.removeAndPushFile({}, null, null, null, null, {}, {}, null, (data, error) => {
|
|
613
661
|
try {
|
|
614
662
|
const displayE = 'push options is required';
|
|
615
663
|
runErrorAsserts(data, error, 'AD.300', 'Test-Git-adapter-removeAndPushFile', displayE);
|