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

Support for Gitea Pull Requests #7099

Closed
strk opened this issue Jan 13, 2022 · 4 comments · Fixed by #7394
Closed

Support for Gitea Pull Requests #7099

strk opened this issue Jan 13, 2022 · 4 comments · Fixed by #7394
Labels
backlog This is not on the Weblate roadmap for now. Can be prioritized by sponsorship. enhancement Adding or requesting a new feature.

Comments

@strk
Copy link

strk commented Jan 13, 2022

Describe the problem

Pull requests are currently only supported against GitHub and GitLab, we'd like to use them against Gitea instead.

Describe the solution you'd like

Add support fir Gitea pull requests.
Here's the API documentation: https://try.gitea.io/api/swagger#/repository/repoCreatePullRequest

Describe alternatives you've considered

No response

Screenshots

No response

Additional context

No response

@nijel nijel added enhancement Adding or requesting a new feature. backlog This is not on the Weblate roadmap for now. Can be prioritized by sponsorship. labels Jan 13, 2022
@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.

@strk
Copy link
Author

strk commented Jan 28, 2022

Here's the documentation for the HTTP API of Gitea: https://try.gitea.io/api/swagger
I gave a look at the GitMergeRequestBase class but I'm confused by the fact that Weblate confuses VCS with "Code Hosting" (ie: letting you choose between GitHub and Git as the VCS). I think for hosting a different set of configurations would be needed (like: where's the API URL ? What are the credentials... )

@nijel
Copy link
Member

nijel commented Feb 1, 2022

Historically, the implementation was done this way. The reason is that you need to change the VCS behavior to integrate with the code hosting site (for example, push to fork instead of pushing to original repo).

The API URL is generated from the VCS URL:

weblate/weblate/vcs/git.py

Lines 698 to 732 in 833ead3

def get_api_url(self) -> Tuple[str, str, str]:
repo = self.component.repo
parsed = urllib.parse.urlparse(repo)
host = parsed.hostname
if not host:
# Assume SSH URL
host, path = repo.split(":")
host = host.split("@")[-1]
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 (
self.API_TEMPLATE.format(
host=self.format_api_host(host),
owner=owner,
slug=slug,
owner_url=urllib.parse.quote_plus(owner),
slug_url=urllib.parse.quote_plus(slug),
),
owner,
slug,
)

It is customized per code hosting site:

weblate/weblate/vcs/git.py

Lines 839 to 846 in 833ead3

def format_api_host(self, host):
# In case the hostname of the repository does not point to "github.com" assume
# that it is on a GitHub Enterprise server, which has uses a different base URL
# for the API:
if host != "github.com":
return f"{host}/api/v3"
return "api.github.com"

The credentials are stored in the settings GITHUB_CREDENTIALS / GITLAB_CREDENTIALS / PAGURE_CREDENTIALS.

nijel added a commit to nijel/weblate that referenced this issue Mar 17, 2022
Add Gitea VCS backend similar to GitHub and GitLab.

Fixes WeblateOrg#7099
Supersedes WeblateOrg#7326

Co-authored-by: Michal Čihař <michal@cihar.com>
nijel added a commit that referenced this issue Mar 21, 2022
Add Gitea VCS backend similar to GitHub and GitLab.

Fixes #7099
Supersedes #7326

Co-authored-by: Michal Čihař <michal@cihar.com>
@github-actions
Copy link

Thank you for your report; the issue you have reported has just been fixed.

  • In case you see a problem with the fix, please comment on this issue.
  • In case you see a similar problem, please open a separate issue.
  • If you are happy with the outcome, don’t hesitate to support Weblate by making a donation.

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

Successfully merging a pull request may close this issue.

2 participants