Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

VCS Integration not possible with slash in URL #9544

Open
2 tasks done
FrostKiwi opened this issue Jul 12, 2023 · 4 comments
Open
2 tasks done

VCS Integration not possible with slash in URL #9544

FrostKiwi opened this issue Jul 12, 2023 · 4 comments
Labels
backlog This is not on the Weblate roadmap for now. Can be prioritized by sponsorship. enhancement Adding or requesting a new feature.

Comments

@FrostKiwi
Copy link

FrostKiwi commented Jul 12, 2023

Describe the issue

I believe the VCS platform integration doesn't work, when the target API has a slash in the name.

I have successfully configured the pushing via standard git and basic auth to a push URL of my Gitea repo. Now I want to configure Weblate to use the Gitea API to create Pull requests as per https://docs.weblate.org/en/weblate-4.18.2/vcs.html#vcs-gitea. Gitea is hosted at subdomain.domain.net/git as configured with NGINX. In my weblate settings I have:

GITEA_CREDENTIALS = {
    "subdomain.domain.net": {
        "username": "<username>",
        "token": "<token>"
    },
}

This results in the error:

Failed to push <project name>/<component name>: HTTPSConnectionPool(host='subdomain.domain.net', port=443): Max retries exceeded with url: /api/v1/repos/git/<user>/<repo>/forks (Caused by SSLError(PermissionError(13, 'Permission denied'))) 

An auth error, which I presume happens because it tries to Auth against a wrong URL. The url should be /git/api/v1/repos/git/<user>/<repo>/forks instead. The push URL is not considered when using Gitea Pull Request as Version control system in the settings tab.
The logical step would be to change GITEA_CREDENTIALS to say:

GITEA_CREDENTIALS = {
    "subdomain.domain.net/git": {
        "username": "<username>",
        "token": "<token>"
    },
}

but that doesn't work, as Weblate stops to recognize that config for Gitea with the message:

Failed to push <project name>/<component name>:  Gitea pull request API access for subdomain.domain.net is not configured

Is my deduction correct? How to solve this or debug further?

I already tried

  • I've read and searched the documentation.
  • I've searched for similar issues in this repository.

Steps to reproduce the behavior

Try to configure the Gitea Pull request integration, when Gitea is hosted not on the root path of the URL, but a slash sub-path.

Expected behavior

No response

Screenshots

No response

Exception traceback

No response

How do you run Weblate?

weblate.org service

Weblate versions

  • Weblate: 4.18.2
  • Django: 4.2.3
  • siphashc: 2.1
  • translate-toolkit: 3.9.2
  • lxml: 4.9.3
  • Pillow: 9.5.0
  • nh3: 0.2.14
  • python-dateutil: 2.8.2
  • social-auth-core: 4.4.2
  • social-auth-app-django: 5.2.0
  • django-crispy-forms: 2.0
  • oauthlib: 3.2.2
  • django-compressor: 4.4
  • djangorestframework: 3.14.0
  • django-filter: 23.2
  • django-appconf: 1.0.5
  • user-agents: 2.2.0
  • filelock: 3.12.2
  • rapidfuzz: 3.1.1
  • openpyxl: 3.1.2
  • celery: 5.3.1
  • django-celery-beat: 2.5.0
  • kombu: 5.3.1
  • translation-finder: 2.15
  • weblate-language-data: 2023.5
  • html2text: 2020.1.16
  • pycairo: 1.24.0
  • PyGObject: 3.44.1
  • diff-match-patch: 20230430
  • requests: 2.31.0
  • django-redis: 5.3.0
  • hiredis: 2.2.3
  • sentry-sdk: 1.28.0
  • Cython: 0.29.36
  • misaka: 2.1.1
  • GitPython: 3.1.32
  • borgbackup: 1.2.4
  • pyparsing: 3.0.9
  • pyahocorasick: 2.0.0
  • python-redis-lock: 4.0.0
  • charset-normalizer: 3.2.0
  • Python: 3.8.10
  • Git: 2.25.1
  • phply: 1.2.6
  • ruamel.yaml: 0.17.32
  • tesserocr: 2.6.0
  • boto3: 1.26.165
  • zeep: 4.2.1
  • aeidon: 1.12
  • iniparse: 0.5
  • Mercurial: 6.5
  • git-review: 2.3.1
  • Redis server: 5.0.7
  • PostgreSQL server: 12.15
  • Database backends: django.db.backends.postgresql
  • Cache backends: default:RedisCache, avatar:FileBasedCache
  • Email setup: django.core.mail.backends.smtp.EmailBackend: smtp-jpn.dmgmori.net
  • OS encoding: filesystem=utf-8, default=utf-8
  • Celery: redis://localhost:6379, redis://localhost:6379, regular
  • Platform: Linux 5.4.0-146-generic (x86_64)

Weblate deploy checks

No response

Additional context

No response

@nijel nijel added the enhancement Adding or requesting a new feature. label Jul 12, 2023
@nijel
Copy link
Member

nijel commented Jul 12, 2023

The API URL currently cannot be customized:

API_TEMPLATE = "{scheme}://{host}/api/v1/repos/{owner}/{slug}"

@nijel nijel added the backlog This is not on the Weblate roadmap for now. Can be prioritized by sponsorship. label Jul 12, 2023
@github-actions
Copy link

This issue has been added to the backlog. It is not scheduled on the Weblate roadmap, but it eventually might be implemented.

In case you need this feature soon, please consider helping or push it by funding the development.

@FrostKiwi
Copy link
Author

FrostKiwi commented Jul 12, 2023

The API URL currently cannot be customized:

@nijel

API_TEMPLATE = "{scheme}://{host}/api/v1/repos/{owner}/{slug}"

Tried overriding it, but still couldn't get it to work.
Also take a look at what's happening with the URL. weblate insists on inserting a /git/ after repos and before the {owner} even though that makes the API url invalid.
/api/v1/repos/git/<user>/<repo>/forks It seem that {owner} somehow resolves to /git/repownername
I tried patching it out with this horrific workaround and adding my needed slash git:

class GiteaRepository(GitMergeRequestBase):
    name = gettext_lazy("Gitea pull request")
    identifier = "gitea"
    _version = None
    API_TEMPLATE = "{scheme}://{host}/git/api/v1/repos/{owner}/{slug}"
    push_label = gettext_lazy("This will push changes and create a Gitea pull request.")

    def create_fork(self, credentials: Dict):
        fork_url = "{}/forks".format(credentials["url"])
        print(fork_url)
        if fork_url.count("/git/") == 2:
            fork_url = fork_url[::-1].replace("/git/"[::-1], "/"[::-1], 1)[::-1]
        print(fork_url)

The URL was generated correctly in the end and I could see the result from the API Json response straight in the browser, when copypasting the url manually. However, Weblate still failed with:
Failed to push project/component: HTTPSConnectionPool(host='subdomain.domain.net', port=443): Max retries exceeded with url: /git/api/v1/repos/owner/repo/forks (Caused by SSLError(PermissionError(13, 'Permission denied')))
I have confirmed, that https://docs.weblate.org/en/latest/admin/install.html#using-custom-certificate-authority is setup correctly for our case, as the error with a misconfigured SSL cert is a different one.

@nijel
Copy link
Member

nijel commented Jul 12, 2023

Also take a look at what's happening with the URL. weblate insists on inserting a /git/ after repos and before the {owner} even though that makes the API url invalid.

Yes, Weblate parses the repository URL and assumes that /git/ is part of the repository URL:

weblate/weblate/vcs/git.py

Lines 746 to 772 in b1a55c7

def parse_repo_url(self) -> Tuple[str, str, str, str]:
repo = self.component.repo
parsed = urllib.parse.urlparse(repo)
host = parsed.hostname
scheme = parsed.scheme
if not host:
# Assume SSH URL
host, path = repo.split(":")
host = host.split("@")[-1]
scheme = None
else:
path = parsed.path
parts = path.split(":")[-1].rstrip("/").split("/")
last_part = parts[-1]
if last_part.endswith(".git"):
last_part = last_part[:-4]
slug_parts = [last_part]
owner = ""
for part in parts[:-1]:
if not part:
continue
if not owner:
owner = part
continue
slug_parts.insert(-1, part)
slug = "/".join(slug_parts)
return (scheme, host, owner, slug)

SSLError(PermissionError(13, 'Permission denied'))

This looks like a permission issue with the installed SSL cert.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog This is not on the Weblate roadmap for now. Can be prioritized by sponsorship. enhancement Adding or requesting a new feature.
Projects
None yet
Development

No branches or pull requests

2 participants