mirror of
https://github.com/go-gitea/gitea.git
synced 2026-07-21 00:14:37 +02:00
fix(repo): stop advertising HTTP clone URLs when DISABLE_HTTP_GIT is set (#38378)
Fixes #38339 --------- Signed-off-by: TowyTowy <towy@airreps.link> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
+10
-3
@@ -647,6 +647,10 @@ func (repo *Repository) DescriptionHTML(ctx context.Context) template.HTML {
|
||||
|
||||
// CloneLink represents different types of clone URLs of repository.
|
||||
type CloneLink struct {
|
||||
IsWikiRepo bool
|
||||
SupportSSH bool
|
||||
SupportHTTPS bool
|
||||
|
||||
SSH string
|
||||
HTTPS string
|
||||
Tea string
|
||||
@@ -698,9 +702,12 @@ func ComposeTeaCloneCommand(ctx context.Context, owner, repo string) string {
|
||||
|
||||
func (repo *Repository) cloneLink(ctx context.Context, doer *user_model.User, repoPathName string) *CloneLink {
|
||||
return &CloneLink{
|
||||
SSH: ComposeSSHCloneURL(doer, repo.OwnerName, repoPathName),
|
||||
HTTPS: ComposeHTTPSCloneURL(ctx, repo.OwnerName, repoPathName),
|
||||
Tea: ComposeTeaCloneCommand(ctx, repo.OwnerName, repoPathName),
|
||||
IsWikiRepo: strings.HasSuffix(repoPathName, ".wiki"),
|
||||
SupportHTTPS: !setting.Repository.DisableHTTPGit,
|
||||
SupportSSH: !setting.SSH.Disabled && (doer != nil || setting.SSH.ExposeAnonymous),
|
||||
SSH: ComposeSSHCloneURL(doer, repo.OwnerName, repoPathName),
|
||||
HTTPS: ComposeHTTPSCloneURL(ctx, repo.OwnerName, repoPathName),
|
||||
Tea: ComposeTeaCloneCommand(ctx, repo.OwnerName, repoPathName),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ func prepareHomeSidebarRepoTopics(ctx *context.Context) {
|
||||
ctx.Data["Topics"] = topics
|
||||
}
|
||||
|
||||
func prepareOpenWithEditorApps(ctx *context.Context) {
|
||||
func prepareClonePanel(ctx *context.Context) {
|
||||
var tmplApps []map[string]any
|
||||
apps := setting.Config().Repository.OpenWithEditorApps.Value(ctx)
|
||||
for _, app := range apps {
|
||||
@@ -93,6 +93,12 @@ func prepareOpenWithEditorApps(ctx *context.Context) {
|
||||
})
|
||||
}
|
||||
ctx.Data["OpenWithEditorApps"] = tmplApps
|
||||
|
||||
if !setting.Repository.DisableDownloadSourceArchives {
|
||||
// FIXME: here it only uses the shortname in the ref to build the link, it can't distinguish the branch/tag/commit with the same name
|
||||
// in the future, it's better to use something like "/archive/branch/the-name.zip", "/archive/tag/the-name.zip" */}}
|
||||
ctx.Data["DownloadArchiveLinkPrefix"] = ctx.Repo.RepoLink + "/archive/" + util.PathEscapeSegments(ctx.Repo.RefFullName.ShortName())
|
||||
}
|
||||
}
|
||||
|
||||
func prepareHomeSidebarCitationFile(entry *git.TreeEntry) func(ctx *context.Context) {
|
||||
@@ -439,7 +445,7 @@ func Home(ctx *context.Context) {
|
||||
isTreePathRoot := ctx.Repo.TreePath == ""
|
||||
|
||||
prepareFuncs := []func(*context.Context){
|
||||
prepareOpenWithEditorApps,
|
||||
prepareClonePanel,
|
||||
prepareHomeSidebarRepoTopics,
|
||||
checkOutdatedBranch,
|
||||
prepareToRenderDirOrFile(entry),
|
||||
|
||||
@@ -589,6 +589,7 @@ func repoAssignmentPrepareTemplateData(ctx *Context, data *repoAssignmentPrepare
|
||||
ctx.Repo.RepoLink = repo.Link()
|
||||
ctx.Data["RepoLink"] = ctx.Repo.RepoLink
|
||||
ctx.Data["FeedURL"] = ctx.Repo.RepoLink
|
||||
ctx.Data["CloneButtonOriginLink"] = repo.CloneLink(ctx, ctx.Doer) // CloneButtonOriginLink may be rewritten to the WikiCloneLink by the router middleware
|
||||
|
||||
unit, err := ctx.Repo.Repository.GetUnit(ctx, unit_model.TypeExternalTracker)
|
||||
if err == nil {
|
||||
@@ -643,18 +644,6 @@ func repoAssignmentPrepareTemplateData(ctx *Context, data *repoAssignmentPrepare
|
||||
// If multiple forks are available or if the user can fork to another account, but there is already a fork: open selection dialog
|
||||
ctx.Data["ShowForkModal"] = len(userAndOrgForks) > 1 || (canSignedUserFork && len(userAndOrgForks) > 0)
|
||||
|
||||
ctx.Data["RepoCloneLink"] = repo.CloneLink(ctx, ctx.Doer)
|
||||
|
||||
cloneButtonShowHTTPS := !setting.Repository.DisableHTTPGit
|
||||
cloneButtonShowSSH := !setting.SSH.Disabled && (ctx.IsSigned || setting.SSH.ExposeAnonymous)
|
||||
if !cloneButtonShowHTTPS && !cloneButtonShowSSH {
|
||||
// We have to show at least one link, so we just show the HTTPS
|
||||
cloneButtonShowHTTPS = true
|
||||
}
|
||||
ctx.Data["CloneButtonShowHTTPS"] = cloneButtonShowHTTPS
|
||||
ctx.Data["CloneButtonShowSSH"] = cloneButtonShowSSH
|
||||
ctx.Data["CloneButtonOriginLink"] = ctx.Data["RepoCloneLink"] // it may be rewritten to the WikiCloneLink by the router middleware
|
||||
|
||||
ctx.Data["RepoSearchEnabled"] = setting.Indexer.RepoIndexerEnabled
|
||||
if setting.Indexer.RepoIndexerEnabled {
|
||||
ctx.Data["CodeIndexerUnavailable"] = !code_indexer.IsAvailable(ctx)
|
||||
@@ -778,16 +767,6 @@ func repoAssignmentPrepareRepoTransfer(ctx *Context, data *repoAssignmentPrepare
|
||||
}
|
||||
}
|
||||
|
||||
func repoAssignmentHandleGoGet(ctx *Context, data *repoAssignmentPrepareDataStruct) {
|
||||
repo := data.repo
|
||||
if ctx.FormString("go-get") == "1" {
|
||||
ctx.Data["GoGetImport"] = ComposeGoGetImport(ctx, repo.Owner.Name, repo.Name)
|
||||
fullURLPrefix := repo.HTMLURL() + "/src/branch/" + util.PathEscapeSegments(ctx.Repo.BranchName)
|
||||
ctx.Data["GoDocDirectory"] = fullURLPrefix + "{/dir}"
|
||||
ctx.Data["GoDocFile"] = fullURLPrefix + "{/dir}/{file}#L{line}"
|
||||
}
|
||||
}
|
||||
|
||||
// RepoAssignment returns a middleware to handle repository assignment
|
||||
func RepoAssignment(ctx *Context) {
|
||||
repoAssignmentPreCheck(ctx)
|
||||
@@ -804,7 +783,6 @@ func RepoAssignment(ctx *Context) {
|
||||
repoAssignmentPrepareRepoTransfer,
|
||||
repoAssignmentPrepareBranches,
|
||||
repoAssignmentPreparePullRequests,
|
||||
repoAssignmentHandleGoGet,
|
||||
}
|
||||
for _, f := range funcs {
|
||||
f(ctx, prepareData)
|
||||
|
||||
@@ -84,7 +84,7 @@ func prepareRepoCommit(ctx context.Context, repo *repo_model.Repository, tmpDir
|
||||
return fmt.Errorf("GetRepoInitFile[%s]: %w", opts.Readme, err)
|
||||
}
|
||||
|
||||
cloneLink := repo.CloneLink(ctx, nil /* no doer so do not generate user-related SSH link */)
|
||||
cloneLink := repo.CloneLinkGeneral(ctx)
|
||||
match := map[string]string{
|
||||
"Name": repo.Name,
|
||||
"Description": util.NormalizeStringEOL(repo.Description),
|
||||
|
||||
@@ -9,10 +9,6 @@
|
||||
<meta name="description" content="{{if .Repository}}{{.Repository.Name}}{{if .Repository.Description}} - {{.Repository.Description}}{{end}}{{else}}{{MetaDescription}}{{end}}">
|
||||
<meta name="keywords" content="{{MetaKeywords}}">
|
||||
<meta name="referrer" content="same-origin">{{/* required by: 1. "redirect_to" cookie; 2. cross-origin protection */}}
|
||||
{{if .GoGetImport}}
|
||||
<meta name="go-import" content="{{.GoGetImport}} git {{.RepoCloneLink.HTTPS}}">
|
||||
<meta name="go-source" content="{{.GoGetImport}} _ {{.GoDocDirectory}} {{.GoDocFile}}">
|
||||
{{end}}
|
||||
{{if and .EnableFeed .FeedURL}}
|
||||
<link rel="alternate" type="application/atom+xml" title="" href="{{.FeedURL}}.atom">
|
||||
<link rel="alternate" type="application/rss+xml" title="" href="{{.FeedURL}}.rss">
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
<!-- there is always at least one button (guaranteed by context/repo.go) -->
|
||||
<div class="ui action small input clone-buttons-combo">
|
||||
{{if $.CloneButtonShowHTTPS}}
|
||||
<button class="ui small button repo-clone-https" data-link="{{$.CloneButtonOriginLink.HTTPS}}">HTTPS</button>
|
||||
<!-- render the clone combo only when a git protocol is available; the URL input would otherwise be empty -->
|
||||
{{$cloneLink := $.CloneButtonOriginLink}}
|
||||
{{if or $cloneLink.SupportHTTPS $cloneLink.SupportSSH}}
|
||||
<div class="ui action small input clone-buttons-combo" data-global-init="initRepoCloneButtonsCombo">
|
||||
{{if $cloneLink.SupportHTTPS}}
|
||||
<button class="ui small button repo-clone-https" data-link="{{$cloneLink.HTTPS}}">HTTPS</button>
|
||||
{{end}}
|
||||
{{if $.CloneButtonShowSSH}}
|
||||
<button class="ui small button repo-clone-ssh" data-link="{{$.CloneButtonOriginLink.SSH}}">SSH</button>
|
||||
{{if $cloneLink.SupportSSH}}
|
||||
<button class="ui small button repo-clone-ssh" data-link="{{$cloneLink.SSH}}">SSH</button>
|
||||
{{end}}
|
||||
<input size="10" class="repo-clone-url js-clone-url" value="{{$.CloneButtonOriginLink.HTTPS}}" readonly>
|
||||
<input size="10" class="repo-clone-url js-clone-url" value="{{Iif $cloneLink.SupportHTTPS $cloneLink.HTTPS $cloneLink.SSH}}" readonly>
|
||||
<button class="ui small icon button" data-clipboard-target=".repo-clone-url" data-tooltip-content="{{ctx.Locale.Tr "copy_url"}}">
|
||||
{{svg "octicon-copy" 14}}
|
||||
</button>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
@@ -1,48 +1,56 @@
|
||||
<button class="ui compact primary button js-btn-clone-panel">
|
||||
{{$cloneLink := $.CloneButtonOriginLink}}
|
||||
{{$downloadArchiveLinkPrefix := $.DownloadArchiveLinkPrefix}}
|
||||
{{$openWithEditorApps := $.OpenWithEditorApps}}
|
||||
{{$showCloneLinks := or $cloneLink.SupportHTTPS $cloneLink.SupportSSH}}
|
||||
{{$showOpenWithEditorApps := and $showCloneLinks $openWithEditorApps}}{{/* the editor apps need the clone link */}}
|
||||
{{if or $showCloneLinks $showOpenWithEditorApps $downloadArchiveLinkPrefix}}
|
||||
<button class="ui compact primary button" data-global-init="initRepoClonePanel">
|
||||
{{svg "octicon-code" 16}}
|
||||
<span>{{ctx.Locale.Tr "repo.code"}}</span>
|
||||
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
|
||||
</button>
|
||||
<div class="clone-panel-popup tippy-target">
|
||||
<div class="flex-text-block clone-panel-field">{{svg "octicon-terminal"}} Clone</div>
|
||||
|
||||
<div class="clone-panel-tab">
|
||||
<!-- there is always at least one button (guaranteed by context/repo.go) -->
|
||||
{{if $.CloneButtonShowHTTPS}}
|
||||
<button class="item repo-clone-https" data-link="{{$.CloneButtonOriginLink.HTTPS}}">HTTPS</button>
|
||||
{{end}}
|
||||
{{if $.CloneButtonShowSSH}}
|
||||
<button class="item repo-clone-ssh" data-link="{{$.CloneButtonOriginLink.SSH}}">SSH</button>
|
||||
{{end}}
|
||||
<button class="item repo-clone-tea" data-link="{{$.CloneButtonOriginLink.Tea}}">Tea CLI</button>
|
||||
</div>
|
||||
<div class="divider"></div>
|
||||
|
||||
<div class="clone-panel-field">
|
||||
<div class="ui input tiny action">
|
||||
<input size="30" class="repo-clone-url js-clone-url" value="{{$.CloneButtonOriginLink.HTTPS}}" readonly>
|
||||
<div class="ui small compact icon button" data-clipboard-target=".js-clone-url" data-tooltip-content="{{ctx.Locale.Tr "copy_url"}}">
|
||||
{{svg "octicon-copy" 14}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{if not .PageIsWiki}}
|
||||
<div class="flex-items-block clone-panel-list">
|
||||
{{range .OpenWithEditorApps}}
|
||||
<a class="item muted js-clone-url-editor" data-href-template="{{.OpenURL}}">{{.IconHTML}}{{ctx.Locale.Tr "repo.open_with_editor" .DisplayName}}</a>
|
||||
{{if $showCloneLinks}}
|
||||
<div class="flex-text-block clone-panel-field">{{svg "octicon-terminal"}} Clone</div>
|
||||
<div class="clone-panel-tab">
|
||||
<!-- tea clone also uses the git HTTPS/SSH transports, so the whole clone section is hidden when both are disabled -->
|
||||
{{if $cloneLink.SupportHTTPS}}
|
||||
<button class="item repo-clone-https" data-link="{{$cloneLink.HTTPS}}">HTTPS</button>
|
||||
{{end}}
|
||||
{{if $cloneLink.SupportSSH}}
|
||||
<button class="item repo-clone-ssh" data-link="{{$cloneLink.SSH}}">SSH</button>
|
||||
{{end}}
|
||||
{{if not $cloneLink.IsWikiRepo}}
|
||||
<button class="item repo-clone-tea" data-link="{{$cloneLink.Tea}}">Tea CLI</button>
|
||||
{{end}}
|
||||
</div>
|
||||
|
||||
{{if and (not $.DisableDownloadSourceArchives) $.RefFullName}}
|
||||
<div class="divider"></div>
|
||||
<div class="flex-items-block clone-panel-list">
|
||||
{{/* FIXME: here it only uses the shortname in the ref to build the link, it can't distinguish the branch/tag/commit with the same name
|
||||
in the future, it's better to use something like "/archive/branch/the-name.zip", "/archive/tag/the-name.zip" */}}
|
||||
<a class="item muted archive-link" href="{{$.RepoLink}}/archive/{{PathEscapeSegments $.RefFullName.ShortName}}.zip" rel="nofollow">{{svg "octicon-file-zip"}} {{ctx.Locale.Tr "repo.download_zip"}}</a>
|
||||
<a class="item muted archive-link" href="{{$.RepoLink}}/archive/{{PathEscapeSegments $.RefFullName.ShortName}}.tar.gz" rel="nofollow">{{svg "octicon-file-zip"}} {{ctx.Locale.Tr "repo.download_tar"}}</a>
|
||||
<a class="item muted archive-link" href="{{$.RepoLink}}/archive/{{PathEscapeSegments $.RefFullName.ShortName}}.bundle" rel="nofollow">{{svg "octicon-package"}} {{ctx.Locale.Tr "repo.download_bundle"}}</a>
|
||||
|
||||
<div class="clone-panel-field">
|
||||
<div class="ui input tiny action">
|
||||
<input size="30" class="repo-clone-url js-clone-url" value="{{Iif $cloneLink.SupportHTTPS $cloneLink.HTTPS $cloneLink.SSH}}" readonly>
|
||||
<div class="ui small compact icon button" data-clipboard-target=".js-clone-url" data-tooltip-content="{{ctx.Locale.Tr "copy_url"}}">
|
||||
{{svg "octicon-copy" 14}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{if $showOpenWithEditorApps}}
|
||||
<div class="flex-items-block clone-panel-list repo-clone-with-apps">
|
||||
{{range $app := $openWithEditorApps}}
|
||||
<a class="item muted js-clone-url-editor" data-href-template="{{$app.OpenURL}}">{{$app.IconHTML}}{{ctx.Locale.Tr "repo.open_with_editor" $app.DisplayName}}</a>
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{if $downloadArchiveLinkPrefix}}
|
||||
{{if $showOpenWithEditorApps}}<div class="divider"></div>{{end}}
|
||||
<div class="flex-items-block clone-panel-list">
|
||||
<a class="item muted archive-link" href="{{$downloadArchiveLinkPrefix}}.zip" rel="nofollow">{{svg "octicon-file-zip"}} {{ctx.Locale.Tr "repo.download_zip"}}</a>
|
||||
<a class="item muted archive-link" href="{{$downloadArchiveLinkPrefix}}.tar.gz" rel="nofollow">{{svg "octicon-file-zip"}} {{ctx.Locale.Tr "repo.download_tar"}}</a>
|
||||
<a class="item muted archive-link" href="{{$downloadArchiveLinkPrefix}}.bundle" rel="nofollow">{{svg "octicon-package"}} {{ctx.Locale.Tr "repo.download_bundle"}}</a>
|
||||
</div>
|
||||
{{end}}
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<div class="ui segment center">{{ctx.Locale.Tr "repo.no_branch"}}</div>
|
||||
{{else if .CanWriteCode}}
|
||||
<h4 class="ui top attached header">{{ctx.Locale.Tr "repo.quick_guide"}}</h4>
|
||||
<div class="ui attached guide table segment empty-repo-guide">
|
||||
<div class="ui attached segment empty-repo-guide flex-relaxed-list">
|
||||
<div class="item">
|
||||
<h3>{{ctx.Locale.Tr "repo.clone_this_repo"}} <small>{{ctx.Locale.Tr "repo.clone_helper" "http://git-scm.com/book/en/v2/Git-Basics-Getting-a-Git-Repository"}}</small></h3>
|
||||
|
||||
@@ -36,12 +36,15 @@
|
||||
</a>
|
||||
{{end}}
|
||||
{{end}}
|
||||
{{template "repo/clone_buttons" .}}
|
||||
{{template "repo/clone_buttons" dict "CloneButtonOriginLink" $.CloneButtonOriginLink}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{if not .Repository.IsArchived}}
|
||||
<div class="divider tw-my-0"></div>
|
||||
{{$cloneLink := $.CloneButtonOriginLink}}
|
||||
{{$showGitClientCommands := and (or $cloneLink.SupportHTTPS $cloneLink.SupportSSH) (not .Repository.IsArchived)}}
|
||||
{{/* TODO: when both HTTPS and SSH are disabled, the UI is not that good */}}
|
||||
{{if $showGitClientCommands}}
|
||||
<div class="divider"></div>
|
||||
|
||||
<div class="item">
|
||||
<h3>{{ctx.Locale.Tr "repo.create_new_repo_command"}}</h3>
|
||||
@@ -52,19 +55,19 @@ git init{{if ne .Repository.ObjectFormatName "sha1"}} --object-format={{.Reposit
|
||||
{{if ne .Repository.DefaultBranch "master"}}git checkout -b {{.Repository.DefaultBranch}}{{end}}
|
||||
git add README.md
|
||||
git commit -m "first commit"
|
||||
git remote add {{$gitRemoteName}} <span class="js-clone-url">{{$.CloneButtonOriginLink.HTTPS}}</span>
|
||||
git remote add {{$gitRemoteName}} <span class="js-clone-url">{{Iif $cloneLink.SupportHTTPS $cloneLink.HTTPS $cloneLink.SSH}}</span>
|
||||
git push -u {{$gitRemoteName}} {{.Repository.DefaultBranch}}</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="divider"></div>
|
||||
|
||||
<div class="item">
|
||||
<h3>{{ctx.Locale.Tr "repo.push_exist_repo"}}</h3>
|
||||
<div class="markup">
|
||||
<pre><code>git remote add {{$gitRemoteName}} <span class="js-clone-url">{{$.CloneButtonOriginLink.HTTPS}}</span>
|
||||
<pre><code>git remote add {{$gitRemoteName}} <span class="js-clone-url">{{Iif $cloneLink.SupportHTTPS $cloneLink.HTTPS $cloneLink.SSH}}</span>
|
||||
git push -u {{$gitRemoteName}} {{.Repository.DefaultBranch}}</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
{{else}}
|
||||
<div class="item">HTTPS and SSH clones are disabled, you can only modify the repository via Gitea's web UI.</div>
|
||||
{{end}}
|
||||
</div>
|
||||
{{else}}
|
||||
|
||||
@@ -112,7 +112,11 @@
|
||||
{{end}}
|
||||
<!-- Only show clone panel in repository home page -->
|
||||
{{if $isTreePathRoot}}
|
||||
{{template "repo/clone_panel" .}}
|
||||
{{template "repo/clone_panel" (dict
|
||||
"CloneButtonOriginLink" $.CloneButtonOriginLink
|
||||
"OpenWithEditorApps" $.OpenWithEditorApps
|
||||
"DownloadArchiveLinkPrefix" $.DownloadArchiveLinkPrefix
|
||||
)}}
|
||||
{{end}}
|
||||
{{if and (not $isTreePathRoot) (not .IsViewFile) (not .IsBlame)}}{{/* IsViewDirectory (not home), TODO: split the templates, avoid using "if" tricks */}}
|
||||
<a class="ui compact button" href="{{.RepoLink}}/commits/{{.RefTypeNameSubURL}}/{{.TreePath | PathEscapeSegments}}">
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex-text-block">
|
||||
{{template "repo/clone_panel" .}}
|
||||
{{template "repo/clone_panel" dict "CloneButtonOriginLink" $.CloneButtonOriginLink}}
|
||||
</div>
|
||||
</div>
|
||||
<h2 class="ui top header">{{ctx.Locale.Tr "repo.wiki.wiki_page_revisions"}}</h2>
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{template "repo/clone_panel" .}}
|
||||
{{template "repo/clone_panel" dict "CloneButtonOriginLink" $.CloneButtonOriginLink}}
|
||||
</div>
|
||||
<div class="ui dividing header">
|
||||
<div class="flex-text-block tw-flex-wrap tw-justify-end">
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {queryElems} from '../utils/dom.ts';
|
||||
import {queryElems, toggleElem} from '../utils/dom.ts';
|
||||
import {errorMessage} from '../modules/errors.ts';
|
||||
import {POST} from '../modules/fetch.ts';
|
||||
import {showErrorToast} from '../modules/toast.ts';
|
||||
@@ -7,6 +7,7 @@ import RepoActivityTopAuthors from '../components/RepoActivityTopAuthors.vue';
|
||||
import {createApp} from 'vue';
|
||||
import {createTippy} from '../modules/tippy.ts';
|
||||
import {localUserSettings} from '../modules/user-settings.ts';
|
||||
import {registerGlobalInitFunc} from '../modules/observer.ts';
|
||||
|
||||
async function onDownloadArchive(e: Event) {
|
||||
e.preventDefault();
|
||||
@@ -51,32 +52,33 @@ export function substituteRepoOpenWithUrl(tmpl: string, url: string): string {
|
||||
return tmpl.replace('{url}', needEncode ? encodeURIComponent(url) : url);
|
||||
}
|
||||
|
||||
function initCloneSchemeUrlSelection(parent: Element) {
|
||||
const elCloneUrlInput = parent.querySelector<HTMLInputElement>('.repo-clone-url')!;
|
||||
function initRepoCloneButtonsCombo(parent: Element) {
|
||||
// the clone section is not rendered at all when no git transport (HTTPS/SSH) is available
|
||||
const elCloneUrlInput = parent.querySelector<HTMLInputElement>('.repo-clone-url');
|
||||
if (!elCloneUrlInput) return;
|
||||
|
||||
const tabHttps = parent.querySelector('.repo-clone-https');
|
||||
const tabSsh = parent.querySelector('.repo-clone-ssh');
|
||||
const tabTea = parent.querySelector('.repo-clone-tea');
|
||||
const listOpenWithEditorApps = parent.querySelector('.repo-clone-with-apps');
|
||||
|
||||
// not every tab exists in every panel, eg: the admin may disable HTTP/SSH, and the empty repo page has no Tea CLI tab
|
||||
const tabByScheme: Record<string, Element | null> = {https: tabHttps, ssh: tabSsh, tea: tabTea};
|
||||
const updateClonePanelUi = function() {
|
||||
let scheme = localUserSettings.getString('repo-clone-protocol');
|
||||
if (!['https', 'ssh', 'tea'].includes(scheme)) {
|
||||
scheme = 'https';
|
||||
}
|
||||
|
||||
// Fallbacks if the scheme preference is not available in the tabs, for example: empty repo page, there are only HTTPS and SSH
|
||||
if (scheme === 'tea' && !tabTea) {
|
||||
scheme = 'https';
|
||||
}
|
||||
if (scheme === 'https' && !tabHttps) {
|
||||
scheme = 'ssh';
|
||||
} else if (scheme === 'ssh' && !tabSsh) {
|
||||
scheme = 'https';
|
||||
// fall back to the first available tab when the preferred scheme's tab is absent (unset preference, or disabled protocol)
|
||||
if (!tabByScheme[scheme]) {
|
||||
scheme = ['https', 'ssh', 'tea'].find((s) => tabByScheme[s]) ?? '';
|
||||
}
|
||||
|
||||
const isHttps = scheme === 'https';
|
||||
const isSsh = scheme === 'ssh';
|
||||
const isTea = scheme === 'tea';
|
||||
|
||||
if (listOpenWithEditorApps) {
|
||||
toggleElem(listOpenWithEditorApps, !isTea); // don't show the "Open with editor apps" list when "Tea" clone is selected
|
||||
}
|
||||
|
||||
if (tabHttps) {
|
||||
const link = tabHttps.getAttribute('data-link')!;
|
||||
tabHttps.textContent = link.split(':')[0].toUpperCase(); // show "HTTP" or "HTTPS"
|
||||
@@ -89,16 +91,9 @@ function initCloneSchemeUrlSelection(parent: Element) {
|
||||
tabTea.classList.toggle('active', isTea);
|
||||
}
|
||||
|
||||
let tab: Element | null = null;
|
||||
if (isHttps) {
|
||||
tab = tabHttps;
|
||||
} else if (isSsh) {
|
||||
tab = tabSsh;
|
||||
} else if (isTea) {
|
||||
tab = tabTea;
|
||||
}
|
||||
const tab = tabByScheme[scheme];
|
||||
if (!tab) return; // no protocol available at all, leave the (hidden) input untouched
|
||||
|
||||
if (!tab) return;
|
||||
const link = tab.getAttribute('data-link')!;
|
||||
|
||||
for (const el of document.querySelectorAll('.js-clone-url')) {
|
||||
@@ -132,10 +127,10 @@ function initCloneSchemeUrlSelection(parent: Element) {
|
||||
});
|
||||
}
|
||||
|
||||
function initClonePanelButton(btn: HTMLButtonElement) {
|
||||
function initRepoClonePanel(btn: HTMLButtonElement) {
|
||||
const elPanel = btn.nextElementSibling!;
|
||||
// "init" must be before the "createTippy" otherwise the "tippy-target" will be removed from the document
|
||||
initCloneSchemeUrlSelection(elPanel);
|
||||
initRepoCloneButtonsCombo(elPanel);
|
||||
createTippy(btn, {
|
||||
content: elPanel,
|
||||
trigger: 'click',
|
||||
@@ -147,8 +142,8 @@ function initClonePanelButton(btn: HTMLButtonElement) {
|
||||
}
|
||||
|
||||
export function initRepoCloneButtons() {
|
||||
queryElems(document, '.js-btn-clone-panel', initClonePanelButton);
|
||||
queryElems(document, '.clone-buttons-combo', initCloneSchemeUrlSelection);
|
||||
registerGlobalInitFunc('initRepoClonePanel', initRepoClonePanel);
|
||||
registerGlobalInitFunc('initRepoCloneButtonsCombo', initRepoCloneButtonsCombo);
|
||||
}
|
||||
|
||||
export async function updateIssuesMeta(url: string, action: string, issue_ids: string, id: string) {
|
||||
|
||||
Reference in New Issue
Block a user