Skip to content

Commit

Permalink
Merge pull request #77 from serverless-cd/fix/lhx-dev
Browse files Browse the repository at this point in the history
fix:适配仓库代码
  • Loading branch information
loganhz authored May 11, 2024
2 parents 56b4f7e + f79b951 commit 46fea2f
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/app-card-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"typings": "dist/esm/index.d.ts",
"dependencies": {
"@alicloud/console-components-slide-panel": "^2.2.14",
"@serverless-cd/ui-help": "^0.0.9",
"@serverless-cd/ui-help": "^0.0.12",
"axios": "^1.2.2",
"qs": "^6.11.0",
"react-markdown": "^8.0.4",
Expand Down
5 changes: 5 additions & 0 deletions packages/trigger-ui/src/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@
width: 100% !important;
}

.full-width99 {
width: 98%!important;
}


.trigger-form {
position: relative;
display: flex;
Expand Down
97 changes: 88 additions & 9 deletions packages/trigger-ui/src/strict-mode/PrMatchNewContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,69 @@ const FORM_LAYOUT = {
labelTextAlign: 'left' as Align,
};

function extractPatterns(patternString) {
// 使用正则表达式匹配圆括号中的内容
const regex = /\(([^)]+)\)/g;
let matches;
const patterns = [];

// 使用循环来找到所有匹配项
while ((matches = regex.exec(patternString)) !== null) {
// 将匹配到的值添加到patterns数组中
patterns.push(matches[1]);
}

return patterns;
}



// 用于转义正则特殊字符的辅助函数
function createRegexStringFromArray(array) {
const escapedElements = array.map(element => `(${element})`);
const combinedPattern = escapedElements.join('|');
if (array.length !== 0) {
return `^${combinedPattern}$`;
}
return ``;
}


function getPipeSourceBranch(trigger, source){
if (trigger === 'manual') {
const manualSourceBranch = source&&Array.isArray(source)&&!isEmpty(source)? createRegexStringFromArray(source) :''
return manualSourceBranch
}

if (trigger === 'reg') {
if (source && typeof source==='string') {
// if (source.split(',').length) {// 如果转换过后, 符合规则, 那么也返回匹配之后的值
// const sourceArr = source.split(',')
// return createRegexStringFromArray(sourceArr)
// }
let pre = '^'
let deil = '$'
if (source.startsWith('^')) {
pre=''
}
if (source.endsWith('$')) {
deil=''
}
if (!source.startsWith('(')) {
source = '('+source
}

if (!source.endsWith(')')) {
source = source + ')'
}
return pre+source+deil
}
if (source && Array.isArray(source)) {
return createRegexStringFromArray(source)
}
}
}


const PrMatchNewContent = (props: IProps) => {
const {
Expand All @@ -49,13 +112,14 @@ const PrMatchNewContent = (props: IProps) => {

const filterTargetValue = (value) => {
if (isEmpty(branchList)) return [];
return map(branchList, (branchItem) => {
let newItem = { ...branchItem };
newItem.disabled = newItem.value === value;
return newItem;

return branchList.filter((branchItem) => {
return branchItem.value !== value;
});

};


return (
<Form field={field} {...FORM_LAYOUT}>
<Form.Item
Expand Down Expand Up @@ -84,7 +148,7 @@ const PrMatchNewContent = (props: IProps) => {
<Form.Item
required
label={i18n('ui.trigger.target.branch')}
className="full-width"
className="full-width99"
extra={
isEmpty(branchList) && !loading ? (
<span style={{ color: '#ed6a0c' }}>{i18n('ui.strict.branch.list.null.help')}</span>
Expand Down Expand Up @@ -126,7 +190,7 @@ const PrMatchNewContent = (props: IProps) => {
</Form.Item>
<Form.Item
label={i18n('ui.trigger.source.branch')}
className="full-width"
className="full-width99"
help={i18n('ui.strict.on.pr.source.help')}
>
<RadioGroup
Expand All @@ -136,8 +200,22 @@ const PrMatchNewContent = (props: IProps) => {
onChange: (value) => {
if (value === 'manual') {// 切换手动选择, 如果输入框为字符串,则晴空Source
if (typeof getValue(`${type}Source`)==='string') {
const sourcebranchs = extractPatterns(get(initValue, `${type}Source`))
let newSelectSource = []
if (sourcebranchs.length!=0) {
newSelectSource = sourcebranchs
}

field.setValues({
[`${type}Source`]: newSelectSource,
});
}
}

if (value === 'reg') {// 切换正则选择
if (initValue[`${type}Source`] ) {
field.setValues({
[`${type}Source`]: [],
[`${type}Source`]: getPipeSourceBranch('reg', initValue[`${type}Source`]),
});
}
}
Expand All @@ -163,14 +241,15 @@ const PrMatchNewContent = (props: IProps) => {
disabled={disabled || loading}
state={loading ? 'loading' : undefined}
mode='tag'
hasSelectAll
/>
{isRefresh && <Refresh style={{ top: 0 }} onRefresh={onRefresh} />}
</div>
) : (
<Input
className="full-width"
{...init(`${type}Source`, {
initValue: initValue[`${type}Source`],
initValue: initValue[`${type}Source`]||'',
})}
placeholder={i18n('ui.trigger.match.source.branch')}
disabled={disabled || loading}
Expand All @@ -182,4 +261,4 @@ const PrMatchNewContent = (props: IProps) => {
);
};

export default PrMatchNewContent;
export default PrMatchNewContent;
8 changes: 4 additions & 4 deletions packages/trigger-ui/src/utils/i18n/zh.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default {
'ui.trigger.match.branch.precise.value': '请填写完整分支名称',
'ui.trigger.match.branch.include.value': '请填写正则表达式',
'ui.trigger.match.branch.exclude.value': '请填写完整分支名称',
'ui.trigger.match.tag.prefix.value': '请填写Tag前缀,不填默认监听所有Tag',
'ui.trigger.match.tag.prefix.value': '正则表达式过滤标签,不填写默认件套所有标签',
'ui.trigger.match.tag.precise.value': '请填写完整Tag名称',
'ui.trigger.match.tag.include.value': '请填写正则表达式',
'ui.trigger.match.tag.exclude.value': '请填写完整Tag名称',
Expand Down Expand Up @@ -46,9 +46,9 @@ export default {
'ui.notifiy.atUserIds.tips': '多个用户之间以,分隔',
'ui.notifiy.atUserIds.placeholder': '输入你要@的用户',
'ui.branch.verify.text': '分支是必填项',
'ui.strict.on.push.label': 'Push到指定分支触发',
'ui.strict.on.tag.label': 'Tag / Release事件',
'ui.strict.on.pr.label': 'Merge / Pull Request事件',
'ui.strict.on.push.label': '代码提交事件',
'ui.strict.on.tag.label': '标签创建事件',
'ui.strict.on.pr.label': '合并请求相关事件',
'ui.strict.on.push.help': '当代码被Push到当前分支,进行流水线的触发',
'ui.strict.on.tag.help': '在Github中该类事件用Release表示,在Gitlab 中用Tag表示',
'ui.strict.on.pr.help': '在Github中该类事件用Pull Request表示,在Gitlab中用Merge Request表示',
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-help/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@serverless-cd/ui-help",
"version": "0.0.11",
"version": "0.0.12",
"description": "ui help library",
"main": "lib/index.js",
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions packages/ui-help/src/parse-readme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ const parseReadme = (readmeStr: string) => {
const mattersStr = trimTag(readmeStr, "matters", ' id="flushContent"');
if (mattersStr) {
data.matters = mattersStr;
}else{
data.matters = ' '// 如果没有注意事项不显示
}

// 项目注意事项
Expand Down

0 comments on commit 46fea2f

Please sign in to comment.