joinGitUrlPath

Co-authored-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Johan Haals
2021-01-27 11:43:20 +01:00
parent 46211fa5be
commit 4944dcf0a7
2 changed files with 23 additions and 5 deletions
@@ -13,6 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { posix as posixPath } from 'path';
import {
TemplateEntityV1alpha1,
LOCATION_ANNOTATION,
@@ -53,3 +55,20 @@ export const parseLocationAnnotation = (
location,
};
};
export function joinGitUrlPath(repoUrl: string, path?: string): string {
const parsed = new URL(repoUrl);
if (parsed.hostname.endsWith('azure.com')) {
const templatePath = posixPath.normalize(
posixPath.join(
posixPath.dirname(parsed.searchParams.get('path') || '/'),
path || '.',
),
);
parsed.searchParams.set('path', templatePath);
return parsed.toString();
}
return new URL(path || '.', repoUrl).toString().replace(/\/$/, '');
}
@@ -27,6 +27,7 @@ import {
TemplaterValues,
PublisherBuilder,
parseLocationAnnotation,
joinGitUrlPath,
FilePreparer,
} from '../scaffolder';
import { CatalogEntityClient } from '../lib/catalog';
@@ -138,12 +139,10 @@ export async function createRouter(
const preparer = preparers.get(templateEntityLocation);
const url = new URL(
template.spec.path || '.',
const url = joinGitUrlPath(
templateEntityLocation,
)
.toString()
.replace(/\/$/, '');
template.spec.path,
);
await preparer.prepare({
url,