Skip to content

Conversation

@richm
Copy link
Contributor

@richm richm commented Oct 10, 2025

Show how to configure package repos for use with ostree
image building and linux-system-roles/tox-lsr#213

Signed-off-by: Rich Megginson rmeggins@redhat.com

Summary by Sourcery

Enhance get_ostree_data.sh to not only list packages but also collect and format repository configurations in various formats (json, yaml, raw, toml) using shared suffix logic.

New Features:

  • Add support for extracting and formatting repository definitions (repos) for ostree image building

Enhancements:

  • Refactor file-suffix handling with a unified suffix_list for both packages and repos
  • Extend script usage to handle a 'repos' command and update output format descriptions

Show how to configure package repos for use with ostree
image building and linux-system-roles/tox-lsr#213

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
@richm richm requested a review from spetrosi as a code owner October 10, 2025 20:17
@sourcery-ai
Copy link

sourcery-ai bot commented Oct 10, 2025

Reviewer's Guide

This PR extends get_ostree_data.sh to support collecting and formatting repository definitions in addition to packages, refactors suffix handling into a reusable list, and updates usage documentation accordingly.

Class diagram for new repo formatting functions in get_ostree_data.sh

classDiagram
    class get_repos {
        +get_repos(ostree_dir)
    }
    class format_repos_json {
        +format_repos_json()
    }
    class format_repos_raw {
        +format_repos_raw()
    }
    class format_repos_yaml {
        +format_repos_yaml()
    }
    get_repos --> format_repos_json
    get_repos --> format_repos_raw
    get_repos --> format_repos_yaml
Loading

Flow diagram for new repo data collection in get_ostree_data.sh

flowchart TD
    A["User calls get_ostree_data.sh with 'repos' argument"] --> B["get_repos() called"]
    B --> C["Iterate repotype in pkgtypes"]
    C --> D["Iterate suff in suffix_list"]
    D --> E["Check for repos-<repotype><suff>.repo file"]
    E -->|If exists| F["cat repo file contents"]
    C --> G["Check for roles-<repotype>.txt file"]
    G -->|If exists| H["Iterate roles in file"]
    H --> I["get_rolepath for each role"]
    I -->|If found| J["Recursively call get_repos on rolepath"]
Loading

File-Level Changes

Change Details Files
Add repo support in get_ostree_data.sh
  • Introduce get_repos() to locate and output repo files recursively
  • Add format_repos_{json,yaml,raw} to convert INI repos into desired formats
  • Integrate 'repos' subcommand alongside 'packages'
  • Include new repos-runtime-CentOS-9.repo sample file
.ostree/get_ostree_data.sh
.ostree/repos-runtime-CentOS-9.repo
Refactor suffix logic for package and repo discovery
  • Define suffix_list array based on distro and version
  • Replace hardcoded suffix loops in get_packages() with suffix_list
  • Reuse suffix_list in get_repos()
.ostree/get_ostree_data.sh
Update usage and documentation
  • Expand usage banner to include 'repos' target and raw repo format
  • Clarify toml output for osbuild-composer repos
  • Add 'repos' to the description of supported output formats
.ostree/get_ostree_data.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

@richm richm marked this pull request as draft October 10, 2025 20:18
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 there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `.ostree/get_ostree_data.sh:141` </location>
<code_context>
+            for role in $roles; do
+                rolepath="$(get_rolepath "$ostree_dir" "$role")"
+                if [ -z "$rolepath" ]; then
+                    1>&2 echo ERROR - could not find role "$role" - please use ANSIBLE_COLLECTIONS_PATH
+                    exit 2
+                fi
+                get_repos "$rolepath"
</code_context>

<issue_to_address>
**suggestion:** Error message could be more actionable for users.

Consider updating the error message to include specific steps or an example for setting ANSIBLE_COLLECTIONS_PATH, so users know how to resolve the issue.

```suggestion
                    1>&2 echo "ERROR - could not find role \"$role\". Please set ANSIBLE_COLLECTIONS_PATH to include the directory containing your Ansible roles. Example: export ANSIBLE_COLLECTIONS_PATH=/path/to/collections"
```
</issue_to_address>

### Comment 2
<location> `.ostree/get_ostree_data.sh:150` </location>
<code_context>
+    done
+}
+
+format_repos_json() {
+    python -c 'import sys; import json; import configparser
+cp = configparser.ConfigParser()
</code_context>

<issue_to_address>
**question:** Potential risk with shell variable expansion in repo_str.replace.

Review whether escaping dollar signs in repo_str is required, as it may affect legitimate values. If necessary, clarify the reasoning in the documentation.
</issue_to_address>

### Comment 3
<location> `.ostree/get_ostree_data.sh:177` </location>
<code_context>
+}
+
+format_repos_yaml() {
+    python -c 'import sys; import yaml; import configparser
+cp = configparser.ConfigParser()
+cp.read_file(sys.stdin)
</code_context>

<issue_to_address>
**suggestion:** yaml.safe_dump may not preserve ordering of repo fields.

If field order matters for downstream use, consider using OrderedDict or sorting keys before dumping.

Suggested implementation:

```
+    python -c 'import sys; import yaml; import configparser; from collections import OrderedDict
+cp = configparser.ConfigParser()
+cp.read_file(sys.stdin)

```

```
ret = []
# supported is from osbuild-mpp
supported = ["baseurl", "metalink", "mirrorlist",
             "enabled", "metadata_expire", "gpgcheck", "username", "password", "priority",
             "sslverify", "sslcacert", "sslclientkey", "sslclientcert",
             "skip_if_unavailable"]
for section in cp.sections():
    repo = OrderedDict()
    repo["id"] = section
    for option in supported:
        if cp.has_option(section, option):

```

```
    repo = {"id": section}
    for option in supported:
        if cp.has_option(section, option):
            repo[option] = cp.get(section, option)
    ret.append(repo)
print(yaml.safe_dump(ret, sort_keys=False))
'

```
</issue_to_address>

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.

done
}

format_repos_json() {
Copy link

Choose a reason for hiding this comment

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

question: Potential risk with shell variable expansion in repo_str.replace.

Review whether escaping dollar signs in repo_str is required, as it may affect legitimate values. If necessary, clarify the reasoning in the documentation.

}

format_repos_yaml() {
python -c 'import sys; import yaml; import configparser
Copy link

Choose a reason for hiding this comment

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

suggestion: yaml.safe_dump may not preserve ordering of repo fields.

If field order matters for downstream use, consider using OrderedDict or sorting keys before dumping.

Suggested implementation:

+    python -c 'import sys; import yaml; import configparser; from collections import OrderedDict
+cp = configparser.ConfigParser()
+cp.read_file(sys.stdin)

ret = []
# supported is from osbuild-mpp
supported = ["baseurl", "metalink", "mirrorlist",
             "enabled", "metadata_expire", "gpgcheck", "username", "password", "priority",
             "sslverify", "sslcacert", "sslclientkey", "sslclientcert",
             "skip_if_unavailable"]
for section in cp.sections():
    repo = OrderedDict()
    repo["id"] = section
    for option in supported:
        if cp.has_option(section, option):

    repo = {"id": section}
    for option in supported:
        if cp.has_option(section, option):
            repo[option] = cp.get(section, option)
    ret.append(repo)
print(yaml.safe_dump(ret, sort_keys=False))
'

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.

1 participant