-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Ensure isSSH is set whenever DISABLE_HTTP_GIT is set #19022
Conversation
In clone_buttons.tmpl the defer block sets the javascript isSSH variable. When DISABLE_HTTP_GIT is set we should always set this to true. Fix go-gitea#10920 Signed-off-by: Andrew Thornton <[email protected]>
Great lint is not allowing the obvious solution. |
Signed-off-by: Andrew Thornton <[email protected]>
{{if not (and $.DisableHTTP $.DisableSSH)}} | ||
<script defer> | ||
const isSSH = localStorage.getItem('repo-clone-protocol') === 'ssh'; | ||
const isSSH = httpsDisabled || localStorage.getItem('repo-clone-protocol') === 'ssh'; |
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.
const isSSH = httpsDisabled || localStorage.getItem('repo-clone-protocol') === 'ssh'; | |
const isSSH = {{if $.DisableHTTP}}true || {{end}}localStorage.getItem('repo-clone-protocol') === 'ssh'; |
A suggestion: this changes this PR to one line vs 10. Feel free to take it or discard, although if discarded then the above code chunk could have some de-duplication.
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.
that will fail our lint
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 tried this orignally)
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.
But how about when they disabled both HTTP and SSH? Just use the UI?
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, I see.
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 these JS code should be refactored. For example: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script
|
It could be refactored to the following code. Benefits:
{{if not (and $.DisableHTTP $.DisableSSH)}}
<script>
<!-- /* eslint-disable */ -->
window.config.pageData['repoCloneButtons'] = {httpsDisabled: {{$.DisableHTTP}}};
</script>
<script>
(() => {
const tmplData = window.config.pageData.repoCloneButtons;
const isSSH = tmplData.httpsDisabled || localStorage.getItem('repo-clone-protocol') === 'ssh';
const sshButton = document.getElementById('repo-clone-ssh');
const httpsButton = document.getElementById('repo-clone-https');
const input = document.getElementById('repo-clone-url');
if (input) input.value = (isSSH ? sshButton : httpsButton).getAttribute('data-link');
if (sshButton) sshButton.classList[isSSH ? 'add' : 'remove']('primary');
if (httpsButton) httpsButton.classList[isSSH ? 'remove' : 'add']('primary');
setTimeout(() => {
if (sshButton) sshButton.classList.remove('no-transition');
if (httpsButton) httpsButton.classList.remove('no-transition');
}, 100);
})();
</script>
{{end}} |
I shall defer to @wxiaoguang |
The new #19028 is based on this one 🙏, it could pass the lint. |
In clone_buttons.tmpl the defer block sets the javascript isSSH variable.
When DISABLE_HTTP_GIT is set we should always set this to true.
Fix #19020
Signed-off-by: Andrew Thornton [email protected]