# Shared Code Health Submission Pipeline

**CRITICAL:** Do not execute this file unless explicitly invoked by a skill.

When invoked, the calling skill provides specific context variables (Skill Name,
Branch Name, Commit Hashtag, Cleanup Title, Cleanup Description, Parent Bug,
Cleaned Component, File Count, and optionally a pre-resolved `Bug ID`).

First, prompt the user using `ask_question` with the question: *"Create a
branch, commit these changes, file a bug, and upload a CL to Gerrit?"* and
choices "Yes, submit this cleanup" and "No, keep local changes uncommitted".

- **If the user chooses "No":** Print a summary of the changes, print a success
  message, leave the changes uncommitted in the local working directory, and end
  the workflow here.

- **If the user chooses "Yes":** The following steps must be performed
  sequentially, one by one, in the exact order specified, without skipping or
  jumping:

  1. **Branch Creation**: Run `git new-branch <Branch Name>`.
  2. **Bug Tracking (Specific Bug ID)**:
     - **If a specific, pre-resolved `Bug ID` is provided as a context variable
       (distinct from the general `Parent Bug`):** Set `<Bug ID>` to the
       provided value. (If the value is `"none"`, set `<Bug ID>` to `"none"`).
     - **Otherwise (if a specific `Bug ID` was not provided by the calling
       skill):** File a new Buganizer issue using the `create_buganizer_issue`
       tool with the following properties:
       - **Title:** `[<Commit Hashtag>] <Cleanup Title>`
       - **commentMarkdown:**
         `*"Note: This bug was automatically generated by the Chrome Code Health AI."*\n\n<Cleanup Description>`
       - **componentId:** `1456931`
       - **hotlistIds:** `["8218789"]`
       - **issueType:** `INTERNAL_CLEANUP`
       - **priority:** `P2`
       - **assignee:** Set to the user's LDAP email.
       - *Retrieve the new bug ID from the tool output and set `<Bug ID>` to
         this value.*
  3. **Commit**:
     - Stage the modified files using `git add`.
     - Draft a commit message with the following format and display it to the
       user:
       ```text
       [<Commit Hashtag>] <Cleanup Title>

       <Cleanup Description>

       This change was generated using the skill <Skill Name>.

       Bug: <Parent Bug>, <Bug ID>
       ```
       **CRITICAL**: The first line (subject line) of the commit message must be
       under 72 characters. Use a shortened component name if necessary.
       **CRITICAL**: Explicitly omit any `TAG=` or `CONV=` lines from the commit
       message. Do NOT include them.
     - Commit the changes using `git commit -m "<drafted message>"`.
  4. **Upload**: Run
     `git pull origin main --rebase > /dev/null 2>&1 && gclient sync -D > /dev/null 2>&1`
     followed by `git cl upload --force --bypass-hooks -a -d`.
  5. **Address Presubmit Feedback:** If the upload fails due to presubmit
     errors, the output must be analyzed, issues in the code resolved, and the
     upload re-attempted. These checks must not be bypassed.
  6. **Summary**: Print a summary including the CL link, the Bug ID, the commit
     message, and the `<File Count>`.
