-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(v2): docusaurus deploy: ability to configure port in git url (#4545
) * Creating a way to configure the port used on the guthub deploy. * Fixing some mistakes Documenting Adding githubPort documentation on docusaurus.config.js. Addind SSH protocol prefix. ssh:// Using the default protocol port instead of define it on the code. Prettify. * Fixing some mistakes Documenting Adding githubPort documentation on docusaurus.config.js. Addind SSH protocol prefix. ssh:// Using the default protocol port instead of define it on the code. Prettify. * Isolating the logic to generate the url and testing it. * Changing all the names used on tests to something more unserstandable. * Prettify Co-authored-by: Tales Porto <[email protected]>
- Loading branch information
1 parent
4efe682
commit e99bb43
Showing
6 changed files
with
132 additions
and
8 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
57 changes: 57 additions & 0 deletions
57
packages/docusaurus/src/commands/__tests__/buildRemoteBranchUrl.test.ts
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,57 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import {buildUrl} from '../buildRemoteBranchUrl'; | ||
|
||
describe('remoteeBranchUrl', () => { | ||
test('should build a normal ssh url', async () => { | ||
const url = buildUrl( | ||
'github.com', | ||
undefined, | ||
undefined, | ||
'facebook', | ||
'docusaurus', | ||
true, | ||
); | ||
expect(url).toEqual('[email protected]:facebook/docusaurus.git'); | ||
}); | ||
test('should build a ssh url with port', async () => { | ||
const url = buildUrl( | ||
'github.com', | ||
'422', | ||
undefined, | ||
'facebook', | ||
'docusaurus', | ||
true, | ||
); | ||
expect(url).toEqual('ssh://[email protected]:422/facebook/docusaurus.git'); | ||
}); | ||
test('should build a normal http url', async () => { | ||
const url = buildUrl( | ||
'github.com', | ||
undefined, | ||
'user:pass', | ||
'facebook', | ||
'docusaurus', | ||
false, | ||
); | ||
expect(url).toEqual('https://user:[email protected]/facebook/docusaurus.git'); | ||
}); | ||
test('should build a normal http url', async () => { | ||
const url = buildUrl( | ||
'github.com', | ||
'5433', | ||
'user:pass', | ||
'facebook', | ||
'docusaurus', | ||
false, | ||
); | ||
expect(url).toEqual( | ||
'https://user:[email protected]:5433/facebook/docusaurus.git', | ||
); | ||
}); | ||
}); |
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,50 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
export function buildUrl( | ||
githubHost: string, | ||
githubPort: string | undefined, | ||
gitCredentials: string | undefined, | ||
organizationName: string, | ||
projectName: string, | ||
useSSH: boolean | undefined, | ||
) { | ||
return useSSH | ||
? buildSshUrl(githubHost, organizationName, projectName, githubPort) | ||
: buildHttpsUrl( | ||
gitCredentials, | ||
githubHost, | ||
organizationName, | ||
projectName, | ||
githubPort, | ||
); | ||
} | ||
|
||
function buildSshUrl( | ||
githubHost: string, | ||
organizationName: string, | ||
projectName: string, | ||
githubPort: string | undefined, | ||
) { | ||
if (githubPort) { | ||
return `ssh://git@${githubHost}:${githubPort}/${organizationName}/${projectName}.git`; | ||
} | ||
return `git@${githubHost}:${organizationName}/${projectName}.git`; | ||
} | ||
|
||
function buildHttpsUrl( | ||
gitCredentials: string | undefined, | ||
githubHost: string, | ||
organizationName: string, | ||
projectName: string, | ||
githubPort: string | undefined, | ||
) { | ||
if (githubPort) { | ||
return `https://${gitCredentials}@${githubHost}:${githubPort}/${organizationName}/${projectName}.git`; | ||
} | ||
return `https://${gitCredentials}@${githubHost}/${organizationName}/${projectName}.git`; | ||
} |
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
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