8
0
فهرست منبع

Added "addRemote" method to Git utils.

Kamil Piechaczek 9 سال پیش
والد
کامیت
e93ced6f8b
4فایلهای تغییر یافته به همراه51 افزوده شده و 8 حذف شده
  1. 10 6
      dev/tasks/dev/tasks/create-package.js
  2. 17 1
      dev/tasks/dev/utils/git.js
  3. 5 1
      dev/tests/dev/create-package.js
  4. 19 0
      dev/tests/dev/git.js

+ 10 - 6
dev/tasks/dev/tasks/create-package.js

@@ -16,12 +16,13 @@ const log = require( '../utils/log' );
  * 2. Ask for initial version.
  * 3. Ask for GitHub URL.
  * 4. Initialize repository.
- * 5. Copy files to new repository.
- * 6. Update package.json file in new package's repository.
- * 7. Update package.json file in CKEditor5 repository.
- * 8. Create initial commit.
- * 9. Link new package.
- * 10. Call `npm install` in package repository.
+ * 5. Add remote.
+ * 6. Copy files to new repository.
+ * 7. Update package.json file in new package's repository.
+ * 8. Update package.json file in CKEditor5 repository.
+ * 9. Create initial commit.
+ * 10. Link new package.
+ * 11. Call `npm install` in package repository.
  *
  * @param {String} ckeditor5Path Path to main CKEditor5 repository.
  * @param {String} workspaceRoot Relative path to workspace root.
@@ -89,6 +90,9 @@ module.exports = ( ckeditor5Path, workspaceRoot ) => {
 			log.out( `Initializing repository ${ repositoryPath }...` );
 			git.initializeRepository( repositoryPath );
 
+			log.out( `Adding remote ${ repositoryPath }...` );
+			git.addRemote( repositoryPath, gitHubUrl );
+
 			log.out( `Copying files into ${ repositoryPath }...` );
 
 			for ( let destination in fileStructure ) {

+ 17 - 1
dev/tasks/dev/utils/git.js

@@ -6,6 +6,7 @@
 'use strict';
 
 const tools = require( './tools' );
+const defaultOrigin = 'origin';
 
 module.exports = {
 
@@ -89,7 +90,7 @@ module.exports = {
 	pull( repositoryLocation, branchName ) {
 		const pullCommands = [
 			`cd ${ repositoryLocation }`,
-			`git pull origin ${ branchName }`
+			`git pull ${ defaultOrigin } ${ branchName }`
 		];
 
 		tools.shExec( pullCommands.join( ' && ' ) );
@@ -142,5 +143,20 @@ module.exports = {
 		];
 
 		tools.shExec( commitCommands.join( ' && ' ) );
+	},
+
+	/**
+	 * Adds remote to repository under specified path.
+	 *
+	 * @param {String} repositoryPath
+	 * @param {String} gitHubPath
+	 */
+	addRemote( repositoryPath, gitHubPath ) {
+		const addRemoteCommands = [
+			`cd ${ repositoryPath }`,
+			`git remote add ${ defaultOrigin } git@github.com:${ gitHubPath }.git`
+		];
+
+		tools.shExec( addRemoteCommands.join( ' && ' ) );
 	}
 };

+ 5 - 1
dev/tests/dev/create-package.js

@@ -42,7 +42,8 @@ describe( 'dev-create-package', () => {
 			initializeRepository: sinon.stub( git, 'initializeRepository' ),
 			updateJSONFile: sinon.stub( tools, 'updateJSONFile' ),
 			copy: sinon.stub( tools, 'copyTemplateFiles' ),
-			initialCommit: sinon.stub( git, 'initialCommit' )
+			initialCommit: sinon.stub( git, 'initialCommit' ),
+			addRemote: sinon.stub( git, 'addRemote' )
 		};
 	}
 
@@ -66,6 +67,9 @@ describe( 'dev-create-package', () => {
 			expect( spies.getPackageDescription.calledOnce ).to.equal( true );
 			expect( spies.initializeRepository.calledOnce ).to.equal( true );
 			expect( spies.initializeRepository.firstCall.args[ 0 ] ).to.equal( repositoryPath );
+			expect( spies.addRemote.calledOnce ).to.equal( true );
+			expect( spies.addRemote.firstCall.args[ 0 ] ).to.equal( repositoryPath );
+			expect( spies.addRemote.firstCall.args[ 1 ] ).to.equal( gitHubUrl );
 			expect( spies.copy.called ).to.equal( true );
 			expect( spies.updateJSONFile.calledTwice ).to.equal( true );
 			expect( spies.updateJSONFile.firstCall.args[ 0 ] ).to.equal( path.join( repositoryPath, 'package.json' ) );

+ 19 - 0
dev/tests/dev/git.js

@@ -243,5 +243,24 @@ describe( 'utils', () => {
 				expect( shExecStub.firstCall.args[ 0 ] ).to.equal( commitCommands.join( ' && ' ) );
 			} );
 		} );
+
+		describe( 'addRemote', () => {
+			it( 'should be defined', () => expect( git.addRemote ).to.be.a( 'function' ) );
+
+			it( 'should execute add remote commands', () => {
+				const shExecStub = sandbox.stub( tools, 'shExec' );
+				const gitHubPath = 'ckeditor5/ckeditor5-plugin-name';
+				const repositoryPath = '/path/to/repo';
+				const addRemoteCommands = [
+					`cd ${ repositoryPath }`,
+					`git remote add origin git@github.com:${ gitHubPath }.git`
+				];
+
+				git.addRemote( repositoryPath, gitHubPath );
+
+				expect( shExecStub.calledOnce ).to.equal( true );
+				expect( shExecStub.firstCall.args[ 0 ] ).to.equal( addRemoteCommands.join( ' && ' ) );
+			} );
+		} );
 	} );
 } );