chore(x2a): project name and short id used in target repo#2764
chore(x2a): project name and short id used in target repo#2764eloycoto merged 2 commits intoredhat-developer:mainfrom
Conversation
Review Summary by QodoUse sanitized project name with short UUID for target repo directories
WalkthroughsDescription• Replace UUID-based directory naming with sanitized project name + short UUID • Improve user experience with human-readable directory structure • Update script logic to generate sanitized names from project names • Simplify project abbreviation documentation Diagramflowchart LR
A["Project Name + Full UUID"] -->|Sanitize & Shorten| B["Sanitized Name + Short UUID"]
B -->|Format| C["Directory: my-chef-migration-0d52e6"]
D["PROJECT_NAME"] -->|Transform| E["SANITIZED_NAME"]
F["PROJECT_ID"] -->|Extract First 6| G["SHORT_UUID"]
E -->|Combine| C
G -->|Combine| C
File Changes1. workspaces/x2a/plugins/x2a-backend/src/services/types.ts
|
Code Review by Qodo
|
Changed Packages
|
| SANITIZED_NAME=$(echo "${PROJECT_NAME}" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9-]/-/g' | sed 's/--*/-/g' | sed 's/^-//;s/-$//') | ||
| SHORT_UUID="${PROJECT_ID:0:6}" | ||
| PROJECT_DIR="${SANITIZED_NAME}-${SHORT_UUID}" | ||
| PROJECT_PATH="${TARGET_BASE}/${PROJECT_DIR}" | ||
|
|
||
| # Create project directory in target |
There was a problem hiding this comment.
1. Project dir too long 🐞 Bug ≡ Correctness
x2a-job-script.sh uses the full sanitized PROJECT_NAME in PROJECT_DIR without any length bound, so long project names can exceed filesystem filename limits and cause mkdir/copy steps to fail and abort the job.
Agent Prompt
## Issue description
`PROJECT_DIR` is derived from the full sanitized `PROJECT_NAME` with no maximum length. Very long project names (explicitly covered by existing tests) can produce a directory component that exceeds filesystem limits, causing the job script to fail during `mkdir -p`, `cp`, and later phases.
## Issue Context
- `PROJECT_NAME` comes directly from backend env injection.
- OpenAPI schema does not constrain `name` length.
- Existing tests demonstrate very long `projectName` values.
## Fix Focus Areas
- workspaces/x2a/plugins/x2a-backend/templates/x2a-job-script.sh[235-245]
## Implementation notes
- After sanitization, truncate `SANITIZED_NAME` to a safe component length (e.g., 60–120 chars) before building `PROJECT_DIR`.
- Keep the short id suffix to preserve uniqueness/readability.
- Example approach:
- `SANITIZED_NAME=${SANITIZED_NAME:0:80}` (or compute by bytes if needed)
- Then `PROJECT_DIR="${SANITIZED_NAME}-${SHORT_UUID}"`
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| SANITIZED_NAME=$(echo "${PROJECT_NAME}" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9-]/-/g' | sed 's/--*/-/g' | sed 's/^-//;s/-$//') | ||
| SHORT_UUID="${PROJECT_ID:0:6}" | ||
| PROJECT_DIR="${SANITIZED_NAME}-${SHORT_UUID}" |
There was a problem hiding this comment.
2. Empty sanitized name breaks args 🐞 Bug ☼ Reliability
If PROJECT_NAME sanitizes to an empty string, PROJECT_DIR becomes -<short_uuid> and is passed to downstream commands (e.g., app.py publish-project), which can treat a leading - as an option and fail argument parsing.
Agent Prompt
## Issue description
`SANITIZED_NAME` may become empty after normalization. When that happens, `PROJECT_DIR` becomes `-${SHORT_UUID}` which can be interpreted as an option by downstream CLIs (and is generally a problematic identifier), causing publish steps (and potentially git operations) to fail.
## Issue Context
Sanitization strips all characters outside `[a-z0-9-]` and trims leading/trailing `-`. For names containing only invalid chars, the result is empty.
## Fix Focus Areas
- workspaces/x2a/plugins/x2a-backend/templates/x2a-job-script.sh[235-245]
- workspaces/x2a/plugins/x2a-backend/templates/x2a-job-script.sh[443-471]
## Implementation notes
- Add a fallback after sanitization, e.g.:
- `if [ -z "${SANITIZED_NAME}" ]; then SANITIZED_NAME="project"; fi`
- Consider also hardening consumers:
- `git add -- "${PROJECT_DIR}"`
- If supported by the Python CLI, pass `--` before positional args.
- Also consider replacing `echo "${PROJECT_NAME}"` with `printf '%s' "${PROJECT_NAME}"` to avoid `echo` option quirks.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
|
By having that, we can completely remove the project abbreviation. |
Maybe we should? anyway that removal would be in a seperate pr |
Review Summary by QodoUse sanitized project name with short UUID for target directories
WalkthroughsDescription• Replace UUID-based directory naming with sanitized project name + short UUID • Improve user experience with readable directory structure in target repository • Update script to generate sanitized project name from PROJECT_NAME variable • Simplify git add command to use PROJECT_DIR variable consistently Diagramflowchart LR
A["PROJECT_ID + PROJECT_NAME"] -->|Sanitize name| B["SANITIZED_NAME"]
A -->|Extract first 6 chars| C["SHORT_UUID"]
B -->|Combine| D["PROJECT_DIR: name-uuid"]
D -->|Create directory| E["Target repository structure"]
File Changes1. workspaces/x2a/plugins/x2a-backend/src/services/types.ts
|
Code Review by Qodo
|
The abbreviation and changes in this PR share the use-case. There is no additional use for it when we merge this. |
| TARGET_BASE="/workspace/target" | ||
| SOURCE_BASE="/workspace/source" | ||
| PROJECT_DIR="${PROJECT_ID}.${PROJECT_ABBREV}" | ||
| SANITIZED_NAME=$(echo "${PROJECT_NAME}" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9-]/-/g' | sed 's/--*/-/g' | sed 's/^-//;s/-$//') |
There was a problem hiding this comment.
The SANITIZED_NAME can become very long, what about limiting it to 64 characters or similar? Taking first and last part of the project name? Or truncate at least.
Using a default for empty project name? This should not happen thanks to our other checks, but... If this happens, the name will start with a dash which should be avoided in any case (like project name starts with "-n ; echo I am malicious".
There was a problem hiding this comment.
good points, let me apply some guards
| @@ -47,7 +47,7 @@ export interface JobCreateParams { | |||
| projectId: string; | |||
There was a problem hiding this comment.
What about if we create a ValueObject called Project:
https://khalilstemmler.com/articles/typescript-value-object/
And from here, we can say:
Project.name () -> self.projectName+self.abbre+self.id.slice(0, 5)?
Project.id() -> self.id
Project.base_name: self.projectName+sefl.abbr
And we have all in there, so we can skip the bash changes? and we can do all sanitization here?
|
|
@eloycoto @mareklibra Thank you for the review |



instead of a long UUID representing a project in the target repo, now a combination of a sanitzed project name + UUID[0:6] chars will be used. This will enhance user experience
related to https://redhat.atlassian.net/browse/FLPATH-4020