Created
February 27, 2024 08:20
-
-
Save leozhang2018/acd485357a9d67fd77e0858c73926f3e to your computer and use it in GitHub Desktop.
run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async getRepoInfo (originRepos) { | |
if (!originRepos || originRepos.length === 0) return | |
const reposQuery = originRepos.filter(re => re.source_from !== 'param').map(re => { | |
return { | |
source: re.source, | |
repo_owner: re.repo_owner, | |
repo: re.repo_name, | |
default_branch: re.branch, | |
codehost_id: re.codehost_id, | |
repo_namespace: re.repo_namespace, | |
filter_regexp: re.filter_regexp | |
} | |
}) | |
const commitRepos = originRepos.filter(re => re.source_from !== 'param' && re.enable_commit) | |
const payload = { infos: reposQuery } | |
// b = branch, p = pr, t = tag | |
const res = await getAllBranchInfoAPI(payload) | |
// make these repo info more friendly | |
res.forEach(repo => { | |
if (repo.prs) { | |
repo.prs.forEach(element => { | |
element.pr = element.id | |
}) | |
repo.branchPRsMap = this.$utils.arrayToMapOfArrays( | |
repo.prs, | |
'targetBranch' | |
) | |
} else { | |
repo.branchPRsMap = {} | |
} | |
if (repo.branches) { | |
repo.branchNames = repo.branches.map(b => b.name) | |
} else { | |
repo.branchNames = [] | |
} | |
}) | |
const repoInfoMap = keyBy(res, repo => { | |
return `${repo.repo_owner}/${repo.repo}` | |
}) | |
const commitInfoMap = {} | |
if (commitRepos.length > 0) { | |
for (const index in commitRepos) { | |
const repo = commitRepos[index] | |
const codehostId = repo.codehost_id | |
const repoOwner = repo.repo_owner | |
const repoNamespace = repo.repo_namespace | |
const repoName = repo.repo_name | |
const branchName = repo.branch | |
const commits = await getBranchCommitInfoAPI( | |
codehostId, | |
repoNamespace, | |
repoName, | |
branchName | |
) | |
if (commits) { | |
commitInfoMap[`${repoOwner}/${repoName}`] = commits | |
} | |
} | |
} | |
for (const repo of originRepos) { | |
this.$set(repo, '_id_', `${repo.repo_owner}/${repo.repo_name}`) | |
const repoInfo = repoInfoMap[repo._id_] | |
this.$set(repo, 'branchNames', repoInfo && repoInfo.branchNames) | |
this.$set(repo, 'branchPRsMap', repoInfo && repoInfo.branchPRsMap) | |
this.$set(repo, 'commits', commitInfoMap[repo._id_] ? commitInfoMap[repo._id_] : []) | |
this.$set(repo, 'tags', repoInfo && repoInfo.tags ? repoInfo.tags : []) | |
this.$set(repo, 'prNumberPropName', 'pr') | |
if (repoInfo) { | |
this.$set(repo, 'errorMsg', repoInfo.error_msg || '') | |
} | |
this.$set(repo, 'branch', repo.branch || '') | |
this.$set( | |
repo, | |
repo.prNumberPropName, | |
repo[repo.prNumberPropName] || null | |
) | |
this.$set(repo, 'tag', repo.tag || '') | |
let branchOrTag = null | |
if (repo.branch) { | |
branchOrTag = { | |
type: 'branch', | |
id: `branch-${repo.branch}`, | |
name: repo.branch | |
} | |
} else if (repo.tag) { | |
branchOrTag = { | |
type: 'tag', | |
id: `tag-${repo.tag}`, | |
name: repo.tag | |
} | |
} | |
this.$set(repo, 'branchOrTag', branchOrTag) | |
this.$set(repo, 'branchAndTagList', [ | |
{ | |
label: 'Branches', | |
options: (repo.branchNames || []).map(name => { | |
return { | |
type: 'branch', | |
id: `branch-${name}`, | |
name | |
} | |
}) | |
}, | |
{ | |
label: 'Tags', | |
options: (repo.tags || []).map(tag => { | |
return { | |
type: 'tag', | |
id: `tag-${tag.name}`, | |
name: tag.name | |
} | |
}) | |
} | |
]) | |
} | |
}, | |
async handleEnv (init = true) { | |
this.payload.stages.forEach((stage, stageIndex) => { | |
stage.jobs.forEach((job, jobIndex) => { | |
if (job.run_policy !== 'default_not_run') { | |
this.activeName.push(`${stageIndex}${jobIndex}`) | |
} | |
if (!job.pickedTargets) { | |
this.$set(job, 'pickedTargets', []) | |
} | |
if (job.spec && job.spec.service_and_builds) { | |
job.spec.service_and_builds.forEach(service => { | |
this.getRepoInfo(service.repos) | |
service.key_vals.forEach(item => { | |
if ( | |
item.value.includes('<+fixed>') || | |
item.value.includes('{{') | |
) { | |
item.isShow = false | |
} else { | |
item.isShow = true | |
} | |
}) | |
service.value = `${service.service_name}/${service.service_module}` | |
}) | |
// 如果只有一个组件 默认选上 | |
if (job.spec.service_and_builds.length === 1) { | |
job.pickedTargets = job.spec.service_and_builds | |
} | |
} | |
}) | |
}) | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment