import { cloneDeep } from 'lodash'; import React from 'react'; import { ArtifactEditor } from '../ArtifactEditor'; import { ArtifactTypePatterns } from '../../../../../artifact/ArtifactTypes'; import type { IArtifactEditorProps, IArtifactKindConfig } from '../../../../../domain'; import { singleFieldArtifactEditor } from '../singleFieldArtifactEditor'; import { StageConfigField } from '../../../stages/common'; import { SpelText } from '../../../../../widgets/spelText/SpelText'; const TYPE = 'github/file'; export const GithubMatch: IArtifactKindConfig = { label: 'GitHub', description: 'A file stored in git, hosted by GitHub.', key: 'github', typePattern: ArtifactTypePatterns.GITHUB_FILE, type: TYPE, isDefault: false, isMatch: true, editCmp: singleFieldArtifactEditor( 'name', TYPE, 'File path', 'manifests/frontend.yaml', 'pipeline.config.expectedArtifact.git.name', ), }; export const GithubDefault: IArtifactKindConfig = { label: 'GitHub', typePattern: ArtifactTypePatterns.GITHUB_FILE, type: TYPE, description: 'A file stored in git, hosted by GitHub.', key: 'default.github', isDefault: true, isMatch: false, editCmp: class extends ArtifactEditor { constructor(props: IArtifactEditorProps) { super(props, TYPE); } private pathRegex = new RegExp('/repos/[^/]*/[^/]*/contents/(.*)$'); private onReferenceChange = (reference: string) => { const results = this.pathRegex.exec(reference); const clonedArtifact = cloneDeep(this.props.artifact); if (results !== null) { clonedArtifact.name = results[1]; clonedArtifact.reference = reference; } else { clonedArtifact.name = reference; clonedArtifact.reference = reference; } this.props.onChange(clonedArtifact); }; public render() { return ( <> ); } }, };