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

Default (infer) "Repository browser" link template from "Source code repository" #7865

Closed
WofWca opened this issue Jul 10, 2022 · 7 comments · Fixed by #8156
Closed

Default (infer) "Repository browser" link template from "Source code repository" #7865

WofWca opened this issue Jul 10, 2022 · 7 comments · Fixed by #8156
Assignees
Labels
enhancement Adding or requesting a new feature.
Milestone

Comments

@WofWca
Copy link
Contributor

WofWca commented Jul 10, 2022

Describe the problem

Unless you explicitly specify "Repository browser" link template, repository browser links will never be generated (they'll remain as text). But we can infer them (at least for popular services like GitHub, GitLab, Bitbucket).

Describe the solution you'd like

Either fill the "Repository browser" field automatically, or default here:

template = self.repoweb

Describe alternatives you've considered

No response

Screenshots

image

Additional context

Inspired by this comment #7738 (comment)

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

nijel commented Jul 11, 2022

Currently, these are configured separately, so it's up to the admin to configure it or not. In case it will be automatically generated from VCS location, it should honor the vcs.view permission when rendering - to avoid exposing VCS location when not desired. I think it's safe to guard existing repository browser links with this permission.

@ParthS007
Copy link
Member

@nijel Can you please add some implementation details here. Thanks 👍

@nijel
Copy link
Member

nijel commented Sep 20, 2022

The following code needs to be expanded to fall back to repo URL-based template if repoweb is not set:

template = self.repoweb

  • The get_repoweb_link needs to take User parameter to check vcs.view permission, all callers have to be adjusted to pass it
  • The template will be generated for known services based on the repository URL
  • If VCS is using merge requests integration (GitHub/GitLab/...) it should get the service type from that
  • Otherwise detection should be based on repository URL

@ParthS007
Copy link
Member

I started working it and I have following findings:

  • I am assuming the repo URL-based template refers to link of the file in vcs on github/gitlab/.. etc!

  • I went through vcs/git.py to look for merge requests integration check but I couldn't find any relevant code, where I can see if a VCS is using merge requests integration?

  • For now, I created a draft on 1 assumption and returning template as path to the repo url + branch.

@nijel
Copy link
Member

nijel commented Sep 27, 2022

The integration is selected by the vcs attribute, I'd probably go with something generic like this:

   template = getattr(self, f"get_{self.vcs}_repoweb_template", self.get_git_repoweb_template)()

def get_git_repoweb_template(self):
   # Do a repo URL based detection here
   if self.repo looks like GitHub:
        return self.get_github_repoweb_template()
   ...
   return None

def get_github_repoweb_template(self):
   # Extract domain, owner and slug from the repo URL
   return f"https://{domain}/{owner}/{slug}/blob/{{branch}}/{{filename}}#L{{line}}"

For parsing the URLs and detecting the services, you might utilize URL detection in the hooks (though that one is for the opposite direction):

BITBUCKET_GIT_REPOS = (
"ssh://git@{server}/{full_name}.git",
"ssh://git@{server}/{full_name}",
"git@{server}:{full_name}.git",
"git@{server}:{full_name}",
"https://{server}/{full_name}.git",
"https://{server}/{full_name}",
)
BITBUCKET_HG_REPOS = (
"https://{server}/{full_name}",
"ssh://hg@{server}/{full_name}",
"hg::ssh://hg@{server}/{full_name}",
"hg::https://{server}/{full_name}",
)
GITHUB_REPOS = (
"git://github.com/%(owner)s/%(slug)s.git",
"git://github.com/%(owner)s/%(slug)s",
"https://github.com/%(owner)s/%(slug)s.git",
"https://github.com/%(owner)s/%(slug)s",
"git@github.com:%(owner)s/%(slug)s.git",
"git@github.com:%(owner)s/%(slug)s",
)
PAGURE_REPOS = (
"https://{server}/{project}",
"https://{server}/{project}.git",
"ssh://git@{server}/{project}",
"ssh://git@{server}/{project}.git",
)
AZURE_REPOS = (
"https://dev.azure.com/{organization}/{project}/_git/{repository}",
"https://dev.azure.com/{organization}/{projectId}/_git/{repositoryId}",
"git@ssh.dev.azure.com:v3/{organization}/{project}/{repository}",
"https://{organization}.visualstudio.com/{project}/_git/{repository}",
"{organization}@vs-ssh.visualstudio.com:v3/{organization}/{project}/{repository}",
)

@ParthS007
Copy link
Member

I added the url detection for services, I was not sure on how the URL will look like for services other than github, so kept them as to do for now. Please let me know if it is the right direction and how can I test the functionality. I went through the tests, i am assuming now I have to test something like this? https://github.com/WeblateOrg/weblate/blob/main/weblate/trans/tests/test_templatetags.py#L129-L149

@nijel nijel added this to the 4.15 milestone Nov 21, 2022
@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
enhancement Adding or requesting a new feature.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants