-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Improve issue autolinks #6273
Improve issue autolinks #6273
Conversation
Codecov Report
@@ Coverage Diff @@
## master #6273 +/- ##
==========================================
+ Coverage 40.45% 40.46% +0.01%
==========================================
Files 405 405
Lines 54320 54350 +30
==========================================
+ Hits 21976 21994 +18
- Misses 29322 29332 +10
- Partials 3022 3024 +2
Continue to review full report at Codecov.
|
Update autolinks to match what github does here: Issue in same repo: #1 Issue in different repo: org/repo#1 Fixes go-gitea#6264
Using setting.AppURL here is a more reliable way of parsing the current URL and what other functions in this file seem to use.
Now that we include the user and repo name inside context metas, update various code and tests for this new logic
d5d0f20
to
102bcff
Compare
Updated this PR per above comments. One question: While this slightly modifies some API code, it doesn't actually change anything that is documented so I'm not sure if any documentation needs to be updated/changed. |
func (repo *Repository) ComposeMetas() map[string]string { | ||
unit, err := repo.GetUnit(UnitTypeExternalTracker) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the repo don't have external tracker, then just return nil. So why move it below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't return nil at all anymore, since we also want the metas if using the local issue tracker (for this specific case of checking to see what repo a user is in when writing an issue number and deciding how to link it). We should always want to have the username and repo name in context if possible because if not people are just scraping the URL for many of the HTML / Markdown processing functions which isn't accurate always.
These changes are discussed in detail in this comment by @zeripath if that helps: https://github.com/go-gitea/gitea/pull/6273/files/102bcffcb6aa60c5bee1054d5c31daa483f2c0a0#discussion_r266227788
Which is where a few of these commits come from.
I tried to edit the description of the to include that information as well, sorry if it was not clear.
@@ -573,6 +573,8 @@ func RegisterRoutes(m *macaron.Macaron) { | |||
Patch(reqToken(), reqRepoWriter(models.UnitTypeIssues, models.UnitTypePullRequests), bind(api.EditLabelOption{}), repo.EditLabel). | |||
Delete(reqToken(), reqRepoWriter(models.UnitTypeIssues, models.UnitTypePullRequests), repo.DeleteLabel) | |||
}) | |||
m.Post("/markdown", bind(api.MarkdownOption{}), misc.Markdown) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an extra changes not related with the title.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I edited the description of the PR after the discussions above but didn't change the title. I can if you want.
This is the same as above where the change is discussed here: https://github.com/go-gitea/gitea/pull/6273/files/102bcffcb6aa60c5bee1054d5c31daa483f2c0a0#discussion_r266227788
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah the issue is that in order to correctly render markdown issue links you need some context. The old /api/markdown
is insufficient - if say I want to render #6273 as a link to go-gitea/gitea#6273
I need to know that I'm rendering for go-gitea/gitea. Now we could just keep the old markdown api but we'd need to add query params etc and add the code to load them - or - we just simply add new markdown render pathways that will do that automatically for us.
@lunny needs your review |
Since go-gitea#6273 was merged, we now have access to proper context metas always. Update SHA generated links to use these instead of urlPrefix. Update tests as well. Fixes go-gitea#4536.
Update autolinks to match what github does here:
Issue in same repo: #1
Issue in different repo: org/repo#1
Fixes #6264
As per discussion below and commits by @zeripath this also introduces a change where we ComposeMetas always returns a username and repo (previously it only returned if using an external issue tracker) and we run ComposeMetas in the Markdown API if in a repo context.
This gives a much more reliable source of user/repo information and eliminates the need for URL parsing and guessing (which is not reliable).
Updated testing for all of this new behavior.