[DIP-4]支持DevStar模板及Git URL作为模板及其他杂项
* 支持从Git URL初始化新建的仓库 * 前端支持Git URL commit id为模板创建项目,并优化了前端代码footer等 * 在DevStar.cn上不必支持DevStar Template * 在前端扩展方式支持了DevStar Template * 增加了数据持久化存储配置方法 * 本地部署时不显示底部的API及devstar.cn的网站备案号 * update LICENSE * 完善README.md 恢复了可执行文件名称gitea
This commit is contained in:
repo.diff.committed_by
戴明辰
repo.diff.parent
1a0bb2f28a
repo.diff.commit
b23094d410
@@ -74,6 +74,13 @@ export function initGlobalTabularMenu() {
|
||||
$('.ui.menu.tabular:not(.custom) .item').tab({autoTabActivation: false});
|
||||
}
|
||||
|
||||
export function initGlobalFooterContent() {
|
||||
const isDevstar = /^(https?:\/\/)?(www\.)?(devstar\.cn)(\/.*)?$/i.test(document.URL);
|
||||
if (!isDevstar) {
|
||||
document.getElementById("beian").remove();
|
||||
document.getElementById("apiswagger").remove();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Too many users set their ROOT_URL to wrong value, and it causes a lot of problems:
|
||||
* * Cross-origin API request without correct cookie
|
||||
|
||||
@@ -1,34 +1,152 @@
|
||||
import $ from 'jquery';
|
||||
import {htmlEscape} from 'escape-goat';
|
||||
import {hideElem, showElem} from '../utils/dom.js';
|
||||
import { htmlEscape } from 'escape-goat';
|
||||
import { hideElem, showElem } from '../utils/dom.js';
|
||||
|
||||
const {appSubUrl} = window.config;
|
||||
const { appSubUrl } = window.config;
|
||||
|
||||
export function initRepoTemplateSearch() {
|
||||
function isValidGitUrl(url) {
|
||||
// 正则表达式支持两种格式的 Git URL
|
||||
const regex = /^https:\/\/([a-zA-Z0-9.-]+)\/([a-zA-Z0-9._-]+)\/([a-zA-Z0-9._-]+)(\/commit\/([a-f0-9]{40}))?$/;
|
||||
// 或者,以 .git 结尾
|
||||
const regexWithGit = /^https:\/\/([a-zA-Z0-9.-]+)\/([a-zA-Z0-9._-]+)\/([a-zA-Z0-9._-]+)\.git$/;
|
||||
return regex.test(url) || regexWithGit.test(url);
|
||||
}
|
||||
function getRepoNameFromGitUrl(url) {
|
||||
// 正则表达式支持两种格式的 Git URL
|
||||
const regexWithCommit = /^https:\/\/([a-zA-Z0-9.-]+)\/([a-zA-Z0-9._-]+)\/([a-zA-Z0-9._-]+)\/commit\/([a-f0-9]{40})$/; // 针对 commit ID 的 URL
|
||||
const regexWithoutCommit = /^https:\/\/([a-zA-Z0-9.-]+)\/([a-zA-Z0-9._-]+)\/([a-zA-Z0-9._-]+)\.git$/; // 针对 .git 结尾的 URL
|
||||
// 尝试匹配 commit URL
|
||||
let match = url.match(regexWithCommit);
|
||||
if (match) {
|
||||
return match[3]; // 返回 repo-name
|
||||
}
|
||||
// 尝试匹配 .git URL
|
||||
match = url.match(regexWithoutCommit);
|
||||
if (match) {
|
||||
return match[3]; // 返回 repo-name
|
||||
}
|
||||
return null; // 如果没有匹配,返回 null
|
||||
}
|
||||
|
||||
const isDevstar = /^(https?:\/\/)?(www\.)?(devstar\.cn)(\/.*)?$/i.test(document.URL);
|
||||
const $repoTemplate = $('#repo_template');
|
||||
const $templateUnits = $('#template_units');
|
||||
const $nonTemplate = $('#non_template');
|
||||
|
||||
const checkTemplate = function () {
|
||||
const $templateUnits = $('#template_units');
|
||||
const $nonTemplate = $('#non_template');
|
||||
if ($repoTemplate.val() !== '' && $repoTemplate.val() !== '0') {
|
||||
showElem($templateUnits);
|
||||
hideElem($nonTemplate);
|
||||
hideElem($('#git_url_template_area'));
|
||||
if ($('#devstar_template_area').length > 0 && !isDevstar) {
|
||||
$('#devstar_template').val('');
|
||||
hideElem($('#devstar_template_area'));
|
||||
}
|
||||
} else {
|
||||
if ($('#devstar_template_area').length > 0 && !isDevstar) {
|
||||
showElem($('#devstar_template_area'));
|
||||
}
|
||||
hideElem($templateUnits);
|
||||
showElem($nonTemplate);
|
||||
showElem($('#git_url_template_area'));
|
||||
}
|
||||
};
|
||||
$repoTemplate.on('change', checkTemplate);
|
||||
checkTemplate();
|
||||
|
||||
const checkGitURLTemplate = function () {
|
||||
const GitURL = document.URL.match(/[?&]template_url=([^&]*)/);
|
||||
if(GitURL && isValidGitUrl(GitURL[1])){
|
||||
$('#git_url_template').val(GitURL[1]);
|
||||
}
|
||||
if ($('#git_url_template').val() !== '' && $('#git_url_template').val() !== '0') {
|
||||
if ($('#repo_name').val() == '') {
|
||||
$('#repo_name').val(getRepoNameFromGitUrl($('#git_url_template').val()));
|
||||
}
|
||||
if ($('#description').val() == '') {
|
||||
$('#description').val($('#git_url_template').val());
|
||||
}
|
||||
hideElem($('#repo_template_area'));
|
||||
hideElem($nonTemplate);
|
||||
if ($('#devstar_template_area').length > 0 && !isDevstar) {
|
||||
$('#devstar_template').val('');
|
||||
hideElem($('#devstar_template_area'));
|
||||
}
|
||||
} else {
|
||||
if ($('#devstar_template_area').length > 0 && !isDevstar) {
|
||||
showElem($('#devstar_template_area'));
|
||||
}
|
||||
showElem($('#repo_template_area'));
|
||||
}
|
||||
};
|
||||
$('#git_url_template').on('change', checkGitURLTemplate);
|
||||
checkGitURLTemplate();
|
||||
|
||||
if ($('#devstar_template_area').length > 0 && isDevstar) {
|
||||
document.getElementById('#devstar_template_area').remove();
|
||||
}
|
||||
if ($('#devstar_template_area').length > 0 && !isDevstar) {
|
||||
const checkDevStarTemplate = function () {
|
||||
if ($('#devstar_template').val() !== '' && $('#devstar_template').val() !== '0') {
|
||||
if ($('#repo_name').val() == '') {
|
||||
$('#repo_name').val(getRepoNameFromGitUrl($('#devstar_template').val()));
|
||||
}
|
||||
if ($('#description').val() == '') {
|
||||
$('#description').val($('#devstar_template').val());
|
||||
}
|
||||
$repoTemplate.val('');
|
||||
hideElem($('#git_url_template_area'));
|
||||
hideElem($('#repo_template_area'));
|
||||
hideElem($nonTemplate);
|
||||
} else {
|
||||
showElem($('#repo_template_area'));
|
||||
showElem($('#git_url_template_area'));
|
||||
hideElem($templateUnits);
|
||||
showElem($nonTemplate);
|
||||
}
|
||||
};
|
||||
$('#devstar_template').on('change', checkDevStarTemplate);
|
||||
|
||||
const initDevStarTemplateSearch = function () {
|
||||
$('#devstar_template_search')
|
||||
.dropdown({
|
||||
apiSettings: {
|
||||
url: `https://devstar.cn/api/v1/repos/search?q={query}&template=true`,
|
||||
onResponse(response) {
|
||||
console.log(response.data);
|
||||
const filteredResponse = { success: true, results: [] };
|
||||
filteredResponse.results.push({
|
||||
name: '-----',
|
||||
value: '',
|
||||
});
|
||||
// Parse the response from the api to work with our dropdown
|
||||
$.each(response.data, (_r, repo) => {
|
||||
filteredResponse.results.push({
|
||||
name: htmlEscape("DevStar.cn/" + repo.full_name),
|
||||
value: repo.clone_url,
|
||||
});
|
||||
});
|
||||
return filteredResponse;
|
||||
},
|
||||
cache: true,
|
||||
},
|
||||
|
||||
fullTextSearch: true,
|
||||
});
|
||||
};
|
||||
initDevStarTemplateSearch();
|
||||
}
|
||||
|
||||
const changeOwner = function () {
|
||||
$('#repo_template_search')
|
||||
.dropdown({
|
||||
apiSettings: {
|
||||
url: `${appSubUrl}/repo/search?q={query}&template=true&priority_owner_id=${$('#uid').val()}`,
|
||||
onResponse(response) {
|
||||
const filteredResponse = {success: true, results: []};
|
||||
const filteredResponse = { success: true, results: [] };
|
||||
filteredResponse.results.push({
|
||||
name: '',
|
||||
name: '-----',
|
||||
value: '',
|
||||
});
|
||||
// Parse the response from the api to work with our dropdown
|
||||
|
||||
@@ -84,6 +84,7 @@ import {
|
||||
initGlobalDropdown,
|
||||
initGlobalTabularMenu,
|
||||
initHeadNavbarContentToggle,
|
||||
initGlobalFooterContent,
|
||||
} from './features/common-page.js';
|
||||
import {
|
||||
initGlobalButtonClickOnEnter,
|
||||
@@ -225,5 +226,6 @@ onDomReady(() => {
|
||||
initPdfViewer,
|
||||
initScopedAccessTokenCategories,
|
||||
initColorPickers,
|
||||
initGlobalFooterContent,
|
||||
]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user