ReactFlow前端拖拽模型与参数配置功能MVP
This commit is contained in:
1 parent
70c91ed019
commit
d3b99304fb
2001 files changed
+349044
-548
No files matched your search
+108
@@ -0,0 +1,108 @@
|
||||
const Definition = require('@npmcli/config/lib/definitions/definition.js')
|
||||
const globalDefinitions = require('@npmcli/config/lib/definitions/definitions.js')
|
||||
const TrustCommand = require('../../trust-cmd.js')
|
||||
const { trustDefinitions } = require('../../trust-cmd.js')
|
||||
const path = require('node:path')
|
||||
|
||||
class TrustGitLab extends TrustCommand {
|
||||
static description = 'Create a trusted relationship between a package and GitLab CI/CD'
|
||||
static name = 'gitlab'
|
||||
static positionals = 1 // expects at most 1 positional (package name)
|
||||
static providerName = 'GitLab CI/CD'
|
||||
static providerEntity = 'GitLab project'
|
||||
static providerFile = 'GitLab CI/CD Pipeline'
|
||||
static providerHostname = 'https://gitlab.com'
|
||||
|
||||
// entity means project / repository
|
||||
static entityKey = 'project'
|
||||
|
||||
static usage = [
|
||||
'[package] --file [--project|--repo|--repository] [--env|--environment] [--allow-publish] [--allow-stage-publish] [-y|--yes]',
|
||||
]
|
||||
|
||||
static definitions = [
|
||||
new Definition('file', {
|
||||
default: null,
|
||||
type: String,
|
||||
required: true,
|
||||
description: 'Name of pipeline file (e.g., .gitlab-ci.yml)',
|
||||
}),
|
||||
new Definition('project', {
|
||||
default: null,
|
||||
type: String,
|
||||
description: 'Name of the project in the format group/project or group/subgroup/project',
|
||||
}),
|
||||
new Definition('environment', {
|
||||
default: null,
|
||||
type: String,
|
||||
description: 'CI environment name',
|
||||
alias: ['env'],
|
||||
}),
|
||||
trustDefinitions['allow-publish'],
|
||||
trustDefinitions['allow-stage-publish'],
|
||||
// globals are alphabetical
|
||||
globalDefinitions['dry-run'],
|
||||
globalDefinitions.json,
|
||||
globalDefinitions.registry,
|
||||
globalDefinitions.yes,
|
||||
]
|
||||
|
||||
getEntityUrl ({ providerHostname, file, entity }) {
|
||||
if (file) {
|
||||
return new URL(`${entity}/-/blob/HEAD/${file}`, providerHostname).toString()
|
||||
}
|
||||
return new URL(entity, providerHostname).toString()
|
||||
}
|
||||
|
||||
validateEntity (entity) {
|
||||
if (entity.split('/').length < 2) {
|
||||
throw new Error(`${this.constructor.providerEntity} must be specified in the format group/project or group/subgroup/project`)
|
||||
}
|
||||
}
|
||||
|
||||
validateFile (file) {
|
||||
if (file !== path.basename(file)) {
|
||||
throw new Error('GitLab CI/CD pipeline file must be just a file not a path')
|
||||
}
|
||||
}
|
||||
|
||||
static optionsToBody (options) {
|
||||
const { file, project, environment } = options
|
||||
const trustConfig = {
|
||||
type: 'gitlab',
|
||||
claims: {
|
||||
project_path: project,
|
||||
// this looks off, but this is correct
|
||||
/** The ref path to the top-level pipeline definition, for example, gitlab.example.com/my-group/my-project//.gitlab-ci.yml@refs/heads/main. Introduced in GitLab 16.2. This claim is null unless the pipeline definition is located in the same project. */
|
||||
ci_config_ref_uri: {
|
||||
file,
|
||||
},
|
||||
...(environment) && { environment },
|
||||
},
|
||||
}
|
||||
return trustConfig
|
||||
}
|
||||
|
||||
// Convert API response body to options
|
||||
static bodyToOptions (body) {
|
||||
const file = body.claims?.ci_config_ref_uri?.file
|
||||
const project = body.claims?.project_path
|
||||
const environment = body.claims?.environment
|
||||
return {
|
||||
...(body.id) && { id: body.id },
|
||||
...(body.type) && { type: body.type },
|
||||
...(file) && { file },
|
||||
...(project) && { project },
|
||||
...(environment) && { environment },
|
||||
}
|
||||
}
|
||||
|
||||
async exec (positionalArgs, flags) {
|
||||
await this.createConfigCommand({
|
||||
positionalArgs,
|
||||
flags,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TrustGitLab
|
||||
Reference in new issue
Block a user