Skip to content

[WIP] Use RoG token for gitlab.com API GET requests#286

Open
kkaarreell wants to merge 1 commit intomainfrom
ks_rog_url_token
Open

[WIP] Use RoG token for gitlab.com API GET requests#286
kkaarreell wants to merge 1 commit intomainfrom
ks_rog_url_token

Conversation

@kkaarreell
Copy link
Collaborator

@kkaarreell kkaarreell commented Oct 31, 2025

For URLs starting with https://gitlab.com/api/ use configured RoG API token.

Currently, in order to be able to fetch a file from gitlab.com one has to tranform the URL into the following format:

https://gitlab.com/api/v4/projects/<project_id>/repository/files/<path_to_file>/raw?ref=main

where:

  • project path like redhat/rhel/tests/pkgname has to be URL encoded, i.e. redhat%2Frhel%2Ftests%2Fsetroubleshoot-plugins
  • file path has to be also URL encoded, i.e. path%2Fto%2Ffile
  • non-default branch has to be specified as well

Summary by Sourcery

Introduce support for using the RoG API token for GitLab.com GET requests and propagate the CLIContext through HTTP and YAML loading functions.

Enhancements:

  • Add optional CLIContext parameter to generic get_request and various from_yaml methods to pass settings.
  • Automatically include PRIVATE-TOKEN header for URLs targeting https://gitlab.com/api/ when a RoG token is configured in the context.
  • Propagate the new ctx argument through RecipeConfig and IssueConfig loading methods and their CLI call sites.

For URLs starting with https://gitlab.com/api/ use configured RoG
API token.

Currently, in order to be able to fetch a file from gitlab.com
one has to tranform the URL into the following format:

  https://gitlab.com/api/v4/projects/<project_id>/repository/files/<path_to_file>/raw?ref=main

where:

 - project path like redhat/rhel/tests/pkgname has to be URL encoded,
   i.e. redhat%2Frhel%2Ftests%2Fsetroubleshoot-plugins
 - file path has to be also URL encoded,
   i.e. path%2Fto%2Ffile
 - non-default branch has to be specified as well
@kkaarreell kkaarreell self-assigned this Oct 31, 2025
@sourcery-ai
Copy link

sourcery-ai bot commented Oct 31, 2025

Reviewer's Guide

Introduces support for automatically using the RoG API token when making GitLab.com API GET requests by extending the generic get_request function with a CLIContext, injecting the PRIVATE-TOKEN header when appropriate, and propagating the new context parameter through serialization helpers and CLI entry points.

Sequence diagram for GET request with RoG token injection

sequenceDiagram
    participant Caller
    participant CLIContext
    participant get_request
    participant requests
    Caller->>get_request: Call get_request(url, ctx)
    get_request->>CLIContext: Access settings.rog_token
    get_request->>requests: GET url with PRIVATE-TOKEN header (if applicable)
    requests-->>get_request: Response
    get_request-->>Caller: Return response
Loading

Class diagram for updated get_request and context propagation

classDiagram
    class CLIContext {
        settings: Settings
    }
    class Settings {
        rog_token: str
    }
    class get_request {
        +get_request(url, krb, attempts, delay, ctx, response_content)
    }
    class SerializableT {
        +from_yaml_file(filepath)
        +from_yaml_url(url, ctx)
    }
    class RecipeConfig {
        +from_yaml_with_includes(location, ctx, stack)
    }
    class IssueConfig {
        +from_yaml_with_include(location, ctx)
        +read_file(location, ctx)
    }
    CLIContext --> Settings
    SerializableT ..> get_request : uses
    RecipeConfig ..> SerializableT : uses
    IssueConfig ..> SerializableT : uses
    IssueConfig ..> RecipeConfig : uses
    get_request ..> CLIContext : uses
    get_request ..> Settings : uses
    get_request ..> requests : calls
    get_request ..> HTTPKerberosAuth : uses
    get_request ..> ResponseContentType : uses
Loading

File-Level Changes

Change Details Files
Augment get_request to accept a CLIContext and inject RoG token for GitLab.com API calls
  • Added optional ctx parameter to all get_request signatures
  • Initialized headers dict and added PRIVATE-TOKEN when URL matches gitlab.com/api and ctx.settings.rog_token
  • Passed headers into requests.get when not using Kerberos auth
newa/__init__.py
Propagate ctx parameter through YAML-based serializers
  • Extended from_yaml_url to accept ctx and forward it to get_request
  • Updated RecipeConfig.from_yaml_with_includes to include ctx in recursive calls
  • Modified IssueConfig.from_yaml_with_include and read_file to accept and pass ctx
newa/__init__.py
Update CLI commands to supply CLIContext to config loaders
  • Added ctx argument to IssueConfig.read_file invocation in cmd_jira
  • Supplied ctx when calling RecipeConfig.from_yaml_with_includes in job processing
newa/cli.py

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 there - I've reviewed your changes - here's some feedback:

Blocking issues:

  • Detected a 'requests' call without a timeout set. By default, 'requests' calls wait until the connection is closed. This means a 'requests' call without a timeout will hang the program if a response is never received. Consider setting a timeout for all 'requests'. (link)
  • Detected a 'requests' call without a timeout set. By default, 'requests' calls wait until the connection is closed. This means a 'requests' call without a timeout will hang the program if a response is never received. Consider setting a timeout for all 'requests'. (link)

General comments:

  • Consider simplifying context propagation by using a shared request session or config object instead of adding ctx to every method signature and call site.
  • The get_request implementation only injects the token header in the non-Kerberos branch—unify the request invocation so headers are applied consistently even when krb=True.
  • Double-check that all get_request callers pass the new ctx argument, as any missing call sites could break GitLab API requests when the RoG token is required.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider simplifying context propagation by using a shared request session or config object instead of adding `ctx` to every method signature and call site.
- The `get_request` implementation only injects the token header in the non-Kerberos branch—unify the request invocation so headers are applied consistently even when `krb=True`.
- Double-check that all `get_request` callers pass the new `ctx` argument, as any missing call sites could break GitLab API requests when the RoG token is required.

## Individual Comments

### Comment 1
<location> `newa/__init__.py:359-362` </location>
<code_context>
            r = requests.get(
                url,
                auth=HTTPKerberosAuth(delegate=True),
                ) if krb else requests.get(url, headers=headers)
</code_context>

<issue_to_address>
**security (python.requests.best-practice.use-timeout):** Detected a 'requests' call without a timeout set. By default, 'requests' calls wait until the connection is closed. This means a 'requests' call without a timeout will hang the program if a response is never received. Consider setting a timeout for all 'requests'.

```suggestion
            r = requests.get(
                url,
                auth=HTTPKerberosAuth(delegate=True),
                , timeout=30) if krb else requests.get(url, headers=headers)
```

*Source: opengrep*
</issue_to_address>

### Comment 2
<location> `newa/__init__.py:362` </location>
<code_context>
                ) if krb else requests.get(url, headers=headers)
</code_context>

<issue_to_address>
**security (python.requests.best-practice.use-timeout):** Detected a 'requests' call without a timeout set. By default, 'requests' calls wait until the connection is closed. This means a 'requests' call without a timeout will hang the program if a response is never received. Consider setting a timeout for all 'requests'.

```suggestion
                ) if krb else requests.get(url, headers=headers, timeout=30)
```

*Source: opengrep*
</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.

Comment on lines 359 to +362
r = requests.get(
url,
auth=HTTPKerberosAuth(delegate=True),
) if krb else requests.get(url)
) if krb else requests.get(url, headers=headers)
Copy link

Choose a reason for hiding this comment

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

security (python.requests.best-practice.use-timeout): Detected a 'requests' call without a timeout set. By default, 'requests' calls wait until the connection is closed. This means a 'requests' call without a timeout will hang the program if a response is never received. Consider setting a timeout for all 'requests'.

Suggested change
r = requests.get(
url,
auth=HTTPKerberosAuth(delegate=True),
) if krb else requests.get(url)
) if krb else requests.get(url, headers=headers)
r = requests.get(
url,
auth=HTTPKerberosAuth(delegate=True),
, timeout=30) if krb else requests.get(url, headers=headers)

Source: opengrep

url,
auth=HTTPKerberosAuth(delegate=True),
) if krb else requests.get(url)
) if krb else requests.get(url, headers=headers)
Copy link

Choose a reason for hiding this comment

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

security (python.requests.best-practice.use-timeout): Detected a 'requests' call without a timeout set. By default, 'requests' calls wait until the connection is closed. This means a 'requests' call without a timeout will hang the program if a response is never received. Consider setting a timeout for all 'requests'.

Suggested change
) if krb else requests.get(url, headers=headers)
) if krb else requests.get(url, headers=headers, timeout=30)

Source: opengrep

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