|
|
|
@ -1,7 +1,9 @@ |
|
|
|
|
import { RepositoryView } from 'app/api/clients/provisioning'; |
|
|
|
|
import { WorkflowOption } from 'app/features/provisioning/types'; |
|
|
|
|
|
|
|
|
|
export function getDefaultWorkflow(config?: RepositoryView) { |
|
|
|
|
export function getDefaultWorkflow(config?: RepositoryView, loadedFromRef?: string) { |
|
|
|
|
if (loadedFromRef && loadedFromRef !== config?.branch) { |
|
|
|
|
return 'write'; // use write when the value targets an explicit ref
|
|
|
|
|
} |
|
|
|
|
return config?.workflows?.[0]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -19,11 +21,14 @@ export function getWorkflowOptions(config?: RepositoryView, ref?: string) { |
|
|
|
|
ref = config.branch; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const availableOptions: Array<{ label: string; value: WorkflowOption }> = [ |
|
|
|
|
{ label: ref ? `Push to ${ref}` : 'Save', value: 'write' }, |
|
|
|
|
{ label: 'Push to different branch', value: 'branch' }, |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
// Filter options based on the workflows in the config
|
|
|
|
|
return availableOptions.filter((option) => config.workflows?.includes(option.value)); |
|
|
|
|
// Return the workflows in the configured order
|
|
|
|
|
return config.workflows.map((value) => { |
|
|
|
|
switch (value) { |
|
|
|
|
case 'write': |
|
|
|
|
return { label: ref ? `Push to ${ref}` : 'Save', value }; |
|
|
|
|
case 'branch': |
|
|
|
|
return { label: 'Push to a new branch', value }; |
|
|
|
|
} |
|
|
|
|
return { label: value, value }; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|