-
Notifications
You must be signed in to change notification settings - Fork 147
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
[JENKINS-74996] Get the current markup formatter to display the descr… #496
Conversation
Another solution would be to add a boolean (default false) in ObjectMetadataAction in the SCM Api to display as formatted text if true (and wouldnt change the initial behavior otherwise), but it would involve 3 packages to modify. |
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 does not smell right. The markup formatter is global and is intended for text entered by users inside Jenkins, which this is not.
https://javadoc.jenkins.io/plugin/scm-api/jenkins/scm/api/metadata/ObjectMetadataAction.html#getObjectDescription() clearly says
Consumers should assume the content is plain text
From the issue description, it seems that the Gitea plugin is loading HTML from Gitea and then incorrectly returning that raw markup from a Jenkins API method which is expecting plain text. If so, the correct fix would be in that branch source, to strip markup.
From my analyze, the ObjectMetadataAction is instanciated in the Gitea plugin to display this description, and this last is used in Branch API to display this field. We wish to display the text formatted as HTML, not only strip markup. That is why I used this formatter getter. I don't know if I am clear enough... I apologize. A solution may be to create a Class implementing an Action which would be the same as ObjectMetadataAction in Gitea plugin or in SCM API, and use it in DescriptionColumn (dependency to Gitea plugin or SCM API, but I didn't check the dependencies tree yet). Do you agree ? Or did you have in mind to override the DescriptionColumn behavior in Gitea plugin ? |
Then you would need to define a new API method (could be added to Use of |
I hope I understand well. I had something like that in mind as a second proposal (see comment under the initial one). My solution would be:
I don't want to let Branch API display RAW data because I guess that other plugins may wish to treat the description field value as raw data when incoming. |
That is one option, but it puts the burden on the caller ( interface X { // v1
int m();
} ⇒ interface X {{ /v2
default int m() {
if (Util.isOverridden(X.class, getClass(), "m2")) {
return Integer.parseInt(m2());
} else {
throw new AbstractMethodError("implement either m() or m2()");
}
}
default String m2() {
if (Util.isOverridden(X.class, getClass(), "m")) {
return Integer.toString(m());
} else {
throw new AbstractMethodError("implement either m() or m2()");
}
}
} It may be simpler to just deprecate the existing interface and define a new
But again, the markup formatter is not the right choice for this, because the markup formatter is intended solely to format user-entered text inside Jenkins textareas such as project descriptions, and could be in any format (plain text, simple HTML, Markdown, AsciiDoc, …). For purposes of this issue, the format coming from Gitea is known to be HTML. |
I understand now. I had a problem with the |
The same options are available for |
I think I understand what you mean. I need to create an Abstract class DefaultMetadataAction with the default behavior of the original ObjectMetadataAction class (all the getters + toString because it will be the same). The v2 of ObjectMetadataAction will only implement the abstract method getCustomObjectDescription return objectDescription which will be declared and getObjectDescription will return getCustomObjectDescription. I will have another class FormattedObjectMetadataAction which will implement getCustomObjectDescription method and return the formatted description. In the DescriptionColumn, I will have to add the |
Ah I see that https://github.com/jenkinsci/scm-api-plugin/blob/a02381dd8a83b2bc23d5d0126d13c793502fda51/src/main/java/jenkins/scm/api/metadata/ObjectMetadataAction.java#L61 is actually a concrete class; it is just up to the branch source to create an instance via published constructor. I guess the simplest change would be to add a new constructor (or a setter) to add a field |
That is what I tried to explain. I wasn't clear at all. I m sorry. So I would set the value Html if required, and else I do the same as for now. Great. |
6f7c7f9
to
4ba3da2
Compare
The description colum (DescriptionColumn Java class) gets the current markup formatter to display the description column text as HTML when safeHTML is activated, instead of a simple escape.
Testing done
This issue causes the issue JENKINS-73226 in the Gitea plugin. It has been tested with both a local Jenkins and Gitea instance. In Gitea, an organization test is created with a repository dummy-test. The repository is visible in the Jenkins Gitea organization. Several tests have been performed:
The screenshot below shows the result as example:
Submitter checklist