feat(bulk-import): perform more dry-run checks in the `POST /imports` backend endpoint [RHIDP-3339]
What does this PR do / why we need it:
The POST /imports endpoint supports a dryRun parameter, which currently only checks if the specified entities do exist in the catalog. It won't attempt to create any PRs in the specified repos.
This PR adds additional checks:
- if the repo already has a catalog-info YAML file in its default branch; it adds a new possible error string:
CATALOG_INFO_FILE_EXISTS_IN_REPO - if the repo is empty; it adds a new possible error string:
REPO_EMPTY
This is needed to improve the related frontend plugin.
BREAKING CHANGES:
- The error when the specified entity already exists in the catalog has been renamed from
CONFLICTtoCATALOG_ENTITY_CONFLICT - Previous, when the
dryRunquery param was set totrue, all items in the request body needed to have a non-blankcatalogEntityNamefield, otherwise a400 Bad Requestwas returned. This field is no longer mandatory. If it is missing, the catalog entity check will be skipped, but the new checks will still be performed. So the API now always returns a202status with the checks errors.
Which issue(s) this PR fixes:
Fixes https://issues.redhat.com/browse/RHIDP-3339
PR acceptance criteria:
-
[x] Unit tests
-
[ ] Integration tests
-
[x] Documentation
How to test changes / Special notes to the reviewer:
- Add at least one GitHub integration - see https://github.com/janus-idp/backstage-plugins/tree/main/plugins/bulk-import-backend#usage
- Start the bulk import backend:
yarn workspace @janus-idp/backstage-plugin-bulk-import-backend run start
- Example response:
[
{
"errors": [],
"catalogEntityName": "animated-happiness",
"repository": {
"url": "https://github.com/lemra-org-ent-2/animated-happiness",
"name": "animated-happiness",
"organization": "lemra-org-ent-2"
}
},
{
"errors": [
"CATALOG_ENTITY_CONFLICT",
"CATALOG_INFO_FILE_EXISTS_IN_REPO"
],
"catalogEntityName": "java-quarkus-starter",
"repository": {
"url": "https://github.com/lemra-org-ent-1/java-quarkus-starter",
"name": "java-quarkus-starter",
"organization": "lemra-org-ent-1"
}
},
{
"errors": [
"REPO_EMPTY"
],
"catalogEntityName": "reimagined-octo-spork-empty",
"repository": {
"url": "https://github.com/lemra-org/reimagined-octo-spork-empty",
"name": "reimagined-octo-spork-empty",
"organization": "lemra-org"
}
}
]
[APPROVALNOTIFIER] This PR is NOT APPROVED
This pull-request has been approved by: Once this PR has been reviewed and has the lgtm label, please ask for approval from rm3l. For more information see the Kubernetes Code Review Process.
The full list of commands accepted by this bot can be found here.
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment
/cc @debsmita1 @ciiay
Quality Gate passed
Issues
0 New issues
0 Accepted issues
Measures
0 Security Hotspots
0.0% Coverage on New Code
1.9% Duplication on New Code
CATALOG_INFO_FILE_EXISTS_IN_REPO
curl -X POST http://localhost:7007/api/bulk-import-backend/imports?dryRun=true -d '[{"catalogEntityName": "test-node","repository": {"url": "https://github.com/test-org-pat/test-node", "defaultBranch": "main"}, "catalogInfoContent": "---\napiVersion: backstage.io/v1alpha1\nkind: Component\nmetadata:\n name: catalog-test-repo\n annotations:\n github.com/project-slug: test-org-pat/catalog-test-repo\nspec:\n type: other\n lifecycle: unknown\n owner: user:default/pataknight\n---\n"}]' -H "Content-Type: application/json" -H "Authorization: Bearer $token" -v | jq [ { "errors": [ "CATALOG_ENTITY_CONFLICT", "CATALOG_INFO_FILE_EXISTS_IN_REPO" ], "catalogEntityName": "test-node", "repository": { "url": "https://github.com/test-org-pat/test-node", "name": "test-node", "organization": "test-org-pat" } } ]REPO_EMPTY
curl -X POST http://localhost:7007/api/bulk-import-backend/imports?dryRun=true -d '[{"catalogEntityName": "catalog-test-repo","repository": {"url": "https://github.com/test-org-pat/catalog-test-repo", "defaultBranch": "main"}, "catalogInfoContent": "---\napiVersion: backstage.io/v1alpha1\nkind: Component\nmetadata:\n name: catalog-test-repo\n annotations:\n github.com/project-slug: test-org-pat/catalog-test-repo\nspec:\n type: other\n lifecycle: unknown\n owner: user:default/pataknight\n---\n"}]' -H "Content-Type: application/json" -H "Authorization: Bearer $token" -v | jq [ { "errors": [ "REPO_EMPTY" ], "catalogEntityName": "catalog-test-repo", "repository": { "url": "https://github.com/test-org-pat/catalog-test-repo", "name": "catalog-test-repo", "organization": "test-org-pat" } } ]Overall, it looks good. Quick question, were you planning on resolving the sonarcloud issue in this PR?
@PatAKnight Thanks for reviewing this PR. I've refactored it to fix the issues reported by SonarCloud (mostly code duplication).