Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat(vcs): parse API credentials from (push) repository URL #12466

Merged
merged 1 commit into from
Sep 11, 2024

Conversation

nijel
Copy link
Member

@nijel nijel commented Sep 11, 2024

Proposed changes

This allows using fine-grained access tokens instead of instance scoped access.

Fixes #12439

Checklist

  • Lint and unit tests pass locally with my changes.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added documentation to describe my feature.
  • I have squashed my commits into logic units.
  • I have described the changes in the commit messages.

Other information

Summary by CodeRabbit

  • Documentation

    • Clarified credential management in the API configuration documentation, emphasizing the precedence of overridden credentials.
    • Enhanced the "Searching" section to allow filtering search results by object path and added details on passing merge request credentials in the repository URL.
  • New Features

    • Improved handling of repository URLs requiring authentication, enhancing credential management robustness.
  • Tests

    • Added a new test for validating the parsing of various Git repository URL formats, ensuring comprehensive coverage of the parse_repo_url functionality.

This allows using fine-grained access tokens instead of instance scoped
access.

Fixes WeblateOrg#12439
@nijel nijel added this to the 5.8 milestone Sep 11, 2024
@nijel nijel requested a review from orangesunny as a code owner September 11, 2024 06:49
Copy link

coderabbitai bot commented Sep 11, 2024

Walkthrough

The changes in this pull request enhance the documentation and functionality of the API credential management system. Key updates include clarifications on overriding API credentials in specific sections of the configuration, improvements to the parsing of repository URLs to include username and password, and the addition of new test cases to ensure the accuracy of these changes. Overall, these modifications aim to improve user understanding and the robustness of the credential management process.

Changes

Files Change Summary
docs/admin/config.rst Added clarification on overriding API credentials in component-push or component-repo sections.
docs/changes.rst Enhanced "Searching" section with filtering by object path and added merge request credentials info.
weblate/vcs/git.py Modified parse_repo_url method to return additional username and password values; updated related methods.
weblate/vcs/tests/test_vcs.py Added test_parse_repo_url to validate new functionality and modified existing test cases for accuracy.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Weblate
    participant GitLab

    User->>Weblate: Push changes with repo URL
    Weblate->>GitLab: Parse repo URL for credentials
    GitLab-->>Weblate: Return parsed credentials
    Weblate->>Weblate: Validate and use credentials
    Weblate->>GitLab: Create merge request
    GitLab-->>Weblate: Confirm merge request creation
Loading

Assessment against linked issues

Objective Addressed Explanation
Getting error "Could not create pull request 404" (12439)
Improve handling of repository URLs with authentication (12439)

Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 467b36a and 38ee38f.

Files selected for processing (4)
  • docs/admin/config.rst (1 hunks)
  • docs/changes.rst (1 hunks)
  • weblate/vcs/git.py (9 hunks)
  • weblate/vcs/tests/test_vcs.py (1 hunks)
Additional comments not posted (6)
docs/changes.rst (1)

9-9: LGTM!

The changes to the release notes are approved.

weblate/vcs/git.py (3)

Line range hint 805-834: Approved: Changes to parse_repo_url look good.

The changes to expand the return type and extract username and password from the repository URL are reasonable enhancements to support URLs with embedded credentials. The implementation looks correct.


Line range hint 883-904: Approved: Changes to get_credentials look good.

The updates to get_credentials correctly handle the expanded return type of parse_repo_url. Defaulting to the credentials dictionary for username and password if not available in the URL is a sensible fallback.


Line range hint 1220-1246: Approved: Changes to AzureDevOpsRepository.parse_repo_url look good.

The updates to unpack the expanded return value and split the URL path to extract owner and slug are correct. This matches the changes in the base parse_repo_url implementation.

weblate/vcs/tests/test_vcs.py (2)

1368-1379: LGTM!

The new test_parse_repo_url test method looks good. It covers parsing different Git repository URL formats and checks that the parse_repo_url method returns the expected structured output.


1373-1374: LGTM!

The additional test case for parsing the "github.com:WeblateOrg/test.github.io" repository URL looks good. It improves the test coverage.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range and nitpick comments (1)
docs/admin/config.rst (1)

2118-2121: LGTM, but please fix the line numbers.

The changes to the documentation are approved. The added clarification about API credential precedence is very helpful.

However, looks like the line numbers got a bit messed up, likely because the entire file was provided for context instead of a diff. The actual changes are at the end of the file. Please update the line numbers to match the correct location of the changes.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 467b36a and 38ee38f.

Files selected for processing (4)
  • docs/admin/config.rst (1 hunks)
  • docs/changes.rst (1 hunks)
  • weblate/vcs/git.py (9 hunks)
  • weblate/vcs/tests/test_vcs.py (1 hunks)
Additional comments not posted (6)
docs/changes.rst (1)

9-9: LGTM!

The changes to the release notes are approved.

weblate/vcs/git.py (3)

Line range hint 805-834: Approved: Changes to parse_repo_url look good.

The changes to expand the return type and extract username and password from the repository URL are reasonable enhancements to support URLs with embedded credentials. The implementation looks correct.


Line range hint 883-904: Approved: Changes to get_credentials look good.

The updates to get_credentials correctly handle the expanded return type of parse_repo_url. Defaulting to the credentials dictionary for username and password if not available in the URL is a sensible fallback.


Line range hint 1220-1246: Approved: Changes to AzureDevOpsRepository.parse_repo_url look good.

The updates to unpack the expanded return value and split the URL path to extract owner and slug are correct. This matches the changes in the base parse_repo_url implementation.

weblate/vcs/tests/test_vcs.py (2)

1368-1379: LGTM!

The new test_parse_repo_url test method looks good. It covers parsing different Git repository URL formats and checks that the parse_repo_url method returns the expected structured output.


1373-1374: LGTM!

The additional test case for parsing the "github.com:WeblateOrg/test.github.io" repository URL looks good. It improves the test coverage.

@nijel nijel merged commit a60d3e1 into WeblateOrg:main Sep 11, 2024
31 checks passed
@nijel nijel deleted the vcs-credentials branch September 11, 2024 08:26
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Getting Could not create pull request 404: 404 Project Not Found (-1) in a gitlab merge request integration
1 participant