-
-
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
When issue template name ends with .yaml/.yml call the yamlParser #23719
When issue template name ends with .yaml/.yml call the yamlParser #23719
Conversation
I may have the wrong end of the stick here - but this seems more like the correct solution. |
I think the root problem is here: https://github.com/go-gitea/gitea/pull/22976/files#diff-39f732f012278472d9dc6f19b2deb4c63e1283f649a33203ed4ced67e804f8a2R54-R61 It shouldn't remove the ext-name of these files. Without the correct ext-name, other code has to "guess" the file name again and again, then various bugs would come. I think it's better to keep the ext-names, and only remove the ext-name when rendering the dropdown UI (or, just keep the ext-names on UI) |
Codecov Report
@@ Coverage Diff @@
## main #23719 +/- ##
==========================================
- Coverage 47.14% 47.12% -0.02%
==========================================
Files 1149 1155 +6
Lines 151446 152401 +955
==========================================
+ Hits 71397 71817 +420
- Misses 71611 72108 +497
- Partials 8438 8476 +38
... and 45 files with indirect coverage changes Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
This is probably 1/2 the issue. This removes the extensions from the files in the label directory. Why does it have to be stripped? just acknowledge that you could have
True this possibly will cause other issues but that's probably what is going on here.
The bigger question though is it isn't solving the issue. Original code:
Thus a file with a yaml (or yml) is parsed twice and thus the WebUI will show one valid option and one invalid as one of the parsers could fail. Likewise it could be a yaml file but legacy format My proposal
An attempt was made to only parse once for a file in the list. Your proposal
A yaml file will be parsed three times and have the WebUI issue. A yml file will be parsed twice and have the WebUI issue The solution will be merging aspects of the three MR as each attack the issue from where the issue is found. There is then the decision what todo if three files exist: {foo,foo.yml,foo.yaml} should the yaml take priority of the shorted extension and should it override the legacy fileformat of the same basename? |
TBH, I don't know, while I don't see a strong reason to strip the extensions. Why not just keep them and show all of them to end users? Since these files are configured by the site admin, end users won't be surprised.
In my mind, if there is no clearly defined behavior, bugs can't be completely eliminated. If we can define the behavior clearly (eg: like above, make every |
OK I understand this a bit better. I think GetTemplateFile was always correct - the issue is in modules/repository/init.go. I'll push up a change. |
…o options The previous code did not remove the .yaml/.yml extension from label files within the customPath. This would lead to duplicate lists of labels. Fix go-gitea#23715 Close go-gitea#23717 Signed-off-by: Andrew Thornton <[email protected]>
5fef66a
to
5f19f54
Compare
removeExtension := func(f string) string { | ||
ext := strings.ToLower(filepath.Ext(f)) | ||
if ext == ".yaml" || ext == ".yml" { | ||
return f[:len(f)-len(ext)] | ||
} | ||
return f | ||
} |
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.
I do not understand why it should remove the extensions. It looks hacky and forces other code to "guess" the file name again and again.
And could there be a case like this:
- Gitea has builtin Advanced.yaml
- A user puts a customized Advance.yml
- Then still the builtin Advanced.yaml is used when guessing the name "Advanced"?
IIRC the options
package tries the custom directory first and then the builtin assets.
- If there are two files:
custom/Advance.yml
andstatic/Advance.yaml
- If
load("Advance")
triesAdvance.yaml
first, it would always loadstatic/Advance.yaml
?
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.
I think it's completely reasonable to hide the extension - however, this does make overriding a little bit more complex.
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.
Or could the extension just be hidden on the UI? But always use the filename with extension internally?
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.
Or could the extension just be hidden on the UI? But always use the filename with extension internally?
How do you think about this proposal? I think it has more Pros and less Cons than current PR's approach.
We have already been doing the best to avoid guess "refs" for branch/tag/commits. Now, I don't think it makes sense to guess the extensions.
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.
you can't guarantee that the templates file hasn't been changed on the filesystem. So - therefore you cannot know the extension at the time of looking up the file.
Therefore you need to guess.
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.
My proposal is Respect the origin file names of option items #23749
I think we do not need to guess. If you think there is any problem, please help to design a case for it (to help me to understand the problem).
Signed-off-by: Andrew Thornton <[email protected]>
Signed-off-by: Andrew Thornton <[email protected]>
Signed-off-by: Andrew Thornton <[email protected]>
#23749 will break functionality allowing users to drop-in replacements for labels whilst gitea is running |
But this PR doesn't fix it either. Please show a real case. I can show more cases based on your cases for this PR too. |
Let's imagine a case:
For your case:
And even more, if your PR sees "Advance.yaml" and "Adanvce.yml" at the same time in custom template directory, which one would it use? Would it make users feel surprised that only one is used? My PR just loads both of them, I would say my PR's behavior is better: more stable, more consistent, no surprise. |
There is a 3rd option... Warn. So the problem statement is the label parser can be triggered "at least" twice if a yaml file is present resulting in an invalid WebUI when a yaml file is parsed by the Legacy Parser options/label/test -> call parseLegacyFormat What happens when all three are present? right now only the legacy format is usable BUT the two appear in the WebUI, with their extensions... while they are parsed the "data" is thrownaway. Lets assume the parsing actually worked and all three were parsed, selectable and usable... Should they be? Option 1Parse all 3 and display all 3 Pro: Permissively accept a clear admin error Option 2permit only extension yaml when presented with test or test.yaml. Pro: Simpler, aligns with the advice to prefer the advance format as stated here: https://docs.gitea.io/en-us/customizing-gitea/#labels Option 3Warn that a shadow file exists via some WebUI banner (like UTF-8 stuff) Pro: clearly indicates there is an issue Its not unusual for a toolsuite to warn about shadow files and not use them ( example of Matlab: https://uk.mathworks.com/help/simulink/ug/manage-shadowed-and-dirty-model-files.html ) but as stated, that would appear a lot of work... Personally Option2 would be the simplest and cleanest. |
Either Option 1 or Option 2 could be implemented in my proposal too. At the moment , I think Option 1 is the best (the current #23749). Because :
That's really site admin's duty to make sure the files in custom directory are all correct. And now site admin could "hide" builtin label files by putting an empty file in the custom directory, which is better. Before, I guess it was impossible.
It has bugs. For example, you have builtin I do not think Option 2 is a complete solution.
I do not think it needs to be that complex, because it's only a site admin work, and usually it only needs to be done once (or only a few times). End users do not need to know any detail of it. Actually I think my proposal #23749 is simple and clear enough, and I can not see a bad case for it (if there is one, feel free to provide more details and I'd like to learn more). |
@wxiaoguang the problem with passing the filename to the UI is that it is fundamentally the wrong thing. Users are NOT choosing a file for the labels - they're choosing a label-set. |
I have strong objection about this approach.
This PR makes things unnecessarily complicated, make code difficult to maintain, brings no real benefit to end users. |
I agree with @zeripath in as far as the choice is a label set and those that choose a label set are owners of repositories or org... Does such users care it's legacy,yml or yaml as long as the choice they need exists. Thing is ... I agree with @wxiaoguang if different files exist they might be different labels . This comes back to the comment in the other PR, this is a site admin mistake as the existance of such files is just systematically wrong. How much accomodation for bad file customisation should gitea accommodate ? This simplifies the discussion to legacyparser Vs yamlparser and thus "show both" with a plan to depreciate legacy in say.... v1.100 |
IMO Gitea shouldn't spend time on accommodating bad file, so I prefer to just show them as they are, let the site admin handle them. In history, there were too many dirty patches in Gitea's code base, many patches becomes technical debt today and causes new bugs. I would say "guessing" option file extensions is also a kind of technical debt, it makes the logic and behavior unclear, and it's difficult to maintain or test. |
One case I like is this allows an admin to override Does yours allow for that @wxiaoguang? |
Yes, put an empty |
And I can have another approach without putting an empty file: If I didn't do that because I already impelmented the Update: done in 18a5258 , since many people like it. |
Fundamentally the problem with #23749 is that it is the case that it doesn't matter what is being presented to the user as the name - the filename with/or without the extension is being presented as the internal API - when it fundamentally was not the API.
By all means we can simplify the look-up code here - i.e. attempt to pre-cache the filenames using a watcher informed system etc. but it's not correct to pass the filename up to the user. I do not believe that the filename should be the API and I don't believe that others intend to make it so. #23749 makes the filename part of both the internal API and /api/v1. #23749 is breaking and worse it's not even being acknowledged that this is the case. |
Actually, It doesn't make sense to use complex patches to avoid some trivial breakings. I have made many "breaking" PRs, IMO there are all good to the whole project. Update: to address the "breaking" concern, the commit 964d81b only uses And for "I do not believe that the filename should be the API and I don't believe that others intend to make it so.": Actually, the "label" package expects to see "file name", you can find such design in old code, including the |
And now |
This commit addresses your "breaking" concern, but still strictly follows the no-guessing rule. And it has tests to cover the priority logic. |
…-legacy-for-yaml-templates
I give up |
Fix #23715 Other related PRs: * #23717 * #23716 * #23719 This PR is different from others, it tries to resolve the problem fundamentally (and brings more benefits) Although it looks like some more lines are added, actually many new lines are for tests. ---- Before, the code was just "guessing" the file type and try to parse them. <details> ![image](https://user-images.githubusercontent.com/2114189/228002245-57d58e27-1078-4da9-bf42-5bc0b264c6ce.png) </details> This PR: * Always remember the original option file names, and always use correct parser for them. * Another benefit is that we can sort the Label Templates now (before there was a map, its key order is undefined) ![image](https://user-images.githubusercontent.com/2114189/228002432-931b9f18-3908-484b-a36b-04760c9ad132.png)
…23749) Fix go-gitea#23715 Other related PRs: * go-gitea#23717 * go-gitea#23716 * go-gitea#23719 This PR is different from others, it tries to resolve the problem fundamentally (and brings more benefits) Although it looks like some more lines are added, actually many new lines are for tests. ---- Before, the code was just "guessing" the file type and try to parse them. <details> ![image](https://user-images.githubusercontent.com/2114189/228002245-57d58e27-1078-4da9-bf42-5bc0b264c6ce.png) </details> This PR: * Always remember the original option file names, and always use correct parser for them. * Another benefit is that we can sort the Label Templates now (before there was a map, its key order is undefined) ![image](https://user-images.githubusercontent.com/2114189/228002432-931b9f18-3908-484b-a36b-04760c9ad132.png) # Conflicts: # modules/label/parser.go # routers/web/org/setting.go # routers/web/repo/issue_label.go # templates/repo/create.tmpl # templates/repo/issue/labels/label_load_template.tmpl
When the issue template name ends with .yaml/.yml call the yamlParser directly.
Fix #23715
Close #23717