Parfuemerie-Douglas / scaffolder-backend-module-azure-repositories

A collection of Backstage scaffolder backend modules for Azure repositories.
https://www.npmjs.com/package/@parfuemerie-douglas/scaffolder-backend-module-azure-repositories
Apache License 2.0
9 stars 21 forks source link

Clone action should support RepoPicker's RepoURL #23

Open jmezach opened 8 months ago

jmezach commented 8 months ago

While trying out these actions in a template we've noticed that the clone action doesn't support the URL format that the RepoPicker component generates. Looking at the code it seems to use the provided URL directly, while the built-in publish:azure action actually processes that URL through the parseRepoUrl function from the scaffolder-backend package as can be seen here. I think these actions should do the same.

jmezach commented 8 months ago

I found out that the parseRepoUrl function isn't publicly available, so that won't work. So what I'm doing now is using the parseRepoUrl filter within the template to generate the actual URL I need like this:

    - id: cloneAzureRepo
      name: Clone Azure Repo
      action: azure:repo:clone
      input:
        remoteUrl: https://dev.azure.com/<org>/${{ parameters.repoUrl | parseRepoUrl | pick('project') }}/_git/${{ parameters.repoUrl | parseRepoUrl | pick('repo') }}
        branch: "master"
        targetPath: ./sub-directory

I could have used the same pattern for the <org> parameter as well, but since we have only one org it doesn't matter to us.

That being said this does feel a bit cumbersome because now the author of the template needs to know the details of how these URL's are structured. Ideally I think this should be a concern of the action itself. According to this note in the docs it should be possible to pass in a complex object to the action which contains all the needed details already which seems like what we want so that we can then construct the proper URL within the action.