Skip to content

Exit with different status code in case of existing repository#98

Merged
osmman merged 1 commit intodevelopfrom
jbouska/SECURESIGN-1855
Jun 3, 2025
Merged

Exit with different status code in case of existing repository#98
osmman merged 1 commit intodevelopfrom
jbouska/SECURESIGN-1855

Conversation

@bouskaJ
Copy link
Member

@bouskaJ bouskaJ commented May 29, 2025

A 'repository already exists' state doesn't necessarily mean an error. Using a distinct exit code for this scenario allows the tuf-job init to correctly signal success when no update is needed for an existing repository, while still ensuring it fails appropriately for misconfigurations.

Summary by Sourcery

Enhancements:

  • Return exit code 2 when the repository is already initialized to distinguish it from error conditions.

@sourcery-ai
Copy link

sourcery-ai bot commented May 29, 2025

Reviewer's Guide

Distinguish the "repository already exists" scenario by exiting with code 2 instead of 1, so that clients can treat it as a successful no-op rather than an error.

Sequence Diagram: tuf-job init Handling of tuf-repo-init.sh for Existing Repository

sequenceDiagram
    participant TJI as "tuf-job init"
    participant S as "tuf-repo-init.sh"

    TJI->>S: Execute tuf-repo-init.sh (repository exists)
    S->>S: Check if TUF_REPO_PATH/root.json exists (true)
    S->>S: Output "Repo seems to already be initialized"
    alt Before PR Change
        S-->>TJI: Exit code 1
        TJI->>TJI: Treats as Error
    else After PR Change
        S-->>TJI: Exit code 2
        TJI->>TJI: Treats as Success (no-op)
    end
Loading

Flow Diagram: Updated Exit Logic in tuf-repo-init.sh for Existing Repository

flowchart TD
    A[Execution of tuf-repo-init.sh] --> B{Is TUF_REPO_PATH/root.json present?};
    B -- Yes --> C["echo 'Repo seems to already be initialized'"];
    C --> D{Determine Exit Code};
    D -- "Logic Before PR" --> Exit1["exit 1"];
    D -- "Logic After PR (Changed)" --> Exit2["exit 2"];
    B -- No --> E["Proceed with normal repository initialization"];
    E --> F["..."];
    style Exit2 fill:#c9ffc9,stroke:#333,stroke-width:2px;
Loading

File-Level Changes

Change Details Files
Use a distinct exit code for existing-repository case
  • Replaced exit 1 with exit 2 when root.json is found
rhtas/tuf-repo-init.sh

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @bouskaJ - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

…isting repository

Signed-off-by: Jan Bouska <jbouska@redhat.com>
@bouskaJ bouskaJ force-pushed the jbouska/SECURESIGN-1855 branch from 6e8f86d to 028d5ec Compare June 2, 2025 05:49
@osmman osmman merged commit 02ce0d8 into develop Jun 3, 2025
13 checks passed
@osmman osmman deleted the jbouska/SECURESIGN-1855 branch June 3, 2025 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants