Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added priority input field for target based trigger map items #1449

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const TriggerItem = (props: TriggerItemProps) => {
conditions={conditions}
isDraftPr={trigger.draft_enabled}
triggerType={triggerType}
priority={trigger.priority}
triggerDisabled={globalDisabled || triggerDisabled}
/>
<OverflowMenu>
Expand Down Expand Up @@ -171,7 +172,7 @@ const Triggers = (props: TriggersProps) => {

const triggerConditions: Record<string, any> = {};
(Object.keys(trigger) as (keyof typeof trigger)[]).forEach((key) => {
if (key !== 'enabled' && key !== 'draft_enabled') {
if (key !== 'enabled' && key !== 'draft_enabled' && key !== 'priority') {
if (typeof trigger[key] === 'string') {
triggerConditions[key] = { wildcard: trigger[key] };
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export type TriggerItem = {
source: TriggerType;
isDraftPr?: boolean;
isActive: boolean;
priority?: number | string;
};

export interface FormItems extends Omit<TriggerItem, 'conditions'> {
Expand All @@ -54,6 +55,7 @@ export interface FormItems extends Omit<TriggerItem, 'conditions'> {
}[];
isDraftPr?: boolean;
isActive: boolean;
priority?: number | string;
}

type StringOrRegex =
Expand All @@ -73,6 +75,7 @@ export type TargetBasedTriggerItem = {
source_branch?: StringOrRegex;
target_branch?: StringOrRegex;
tag?: StringOrRegex;
priority?: number;
};

export type TargetBasedTriggers = WorkflowYmlObject['triggers'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const getConditionList = (trigger: TargetBasedTriggerItem) => {
const conditions: Condition[] = [];
const triggerKeys = Object.keys(trigger) as (keyof TargetBasedTriggerItem)[];
triggerKeys.forEach((key) => {
if (!['enabled', 'pipelineableId', 'pipelineableType', 'type', 'draft_enabled'].includes(key)) {
if (!['enabled', 'pipelineableId', 'pipelineableType', 'type', 'draft_enabled', 'priority'].includes(key)) {
const isRegex = isObject(trigger[key]);
conditions.push({
isRegex,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useMemo } from 'react';
import { Box, Button, ButtonGroup, Checkbox, Link, Text, Tooltip } from '@bitrise/bitkit';
import { Box, Button, ButtonGroup, Checkbox, Input, Link, Text, Tooltip } from '@bitrise/bitkit';
import { FormProvider, useFieldArray, useForm } from 'react-hook-form';
import { isEqual } from 'es-toolkit';
import { segmentTrack } from '@/utils/segmentTracking';
Expand Down Expand Up @@ -40,12 +40,13 @@ const AddTrigger = (props: AddTriggerProps) => {
defaultValues: {
conditions: defaultConditions,
isDraftPr: editedItem?.draft_enabled !== false,
priority: editedItem?.priority || '',
},
});

const { control, handleSubmit, setValue, reset, watch } = formMethods;

const { conditions, isDraftPr } = watch();
const { conditions, isDraftPr, priority } = watch();

const { append, fields, remove } = useFieldArray({
control,
Expand Down Expand Up @@ -85,6 +86,11 @@ const AddTrigger = (props: AddTriggerProps) => {
delete newTrigger.draft_enabled;
}

if (data.priority === undefined || data.priority === '0' || data.priority === 0 || data.priority === '') {
delete newTrigger.priority;
} else {
newTrigger.priority = Number(data.priority);
}
onSubmit(newTrigger);
};

Expand Down Expand Up @@ -114,7 +120,11 @@ const AddTrigger = (props: AddTriggerProps) => {

let isSameTriggerExist = false;
currentTriggers.forEach((trigger) => {
if (isEqual(getConditionList(trigger), conditions) && isEqual(trigger.draft_enabled !== false, isDraftPr)) {
if (
isEqual(getConditionList(trigger), conditions) &&
isEqual(trigger.draft_enabled !== false, isDraftPr) &&
isEqual(trigger.priority || '', priority)
) {
isSameTriggerExist = true;
}
});
Expand Down Expand Up @@ -186,6 +196,15 @@ const AddTrigger = (props: AddTriggerProps) => {
Include draft pull requests
</Checkbox>
)}
<Input
value={priority}
type="number"
min={-100}
max={100}
label="Priority"
marginBlockStart="24"
onChange={(e) => setValue(`priority`, e.target.value)}
/>
</Box>
<ButtonGroup spacing="16" paddingY="24" paddingBlockStart="32" marginBlockStart="auto">
<Tooltip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type TriggerConditionsProps = {
isDraftPr?: boolean;
triggerType?: TriggerType;
triggerDisabled?: boolean;
priority?: number;
};

const iconMap: Record<LegacyConditionType | ConditionType, TypeIconName> = {
Expand Down Expand Up @@ -44,7 +45,7 @@ const toolTip: Record<LegacyConditionType | ConditionType, string> = {
};

const TriggerConditions = (props: TriggerConditionsProps) => {
const { conditions, isDraftPr, triggerDisabled, triggerType } = props;
const { conditions, isDraftPr, triggerDisabled, triggerType, priority } = props;
return (
<Box display="flex" alignItems="center" flexWrap="wrap" rowGap="8" columnGap="4">
{(!conditions || conditions.length === 0) && <Tag size="sm">No conditions.</Tag>}
Expand Down Expand Up @@ -72,6 +73,11 @@ const TriggerConditions = (props: TriggerConditionsProps) => {
• Draft PRs excluded
</Text>
)}
{priority !== undefined && (
<Text textStyle="body/md/regular" color="text/secondary">
• Priority: {priority}
</Text>
)}
</Box>
);
};
Expand Down
3 changes: 3 additions & 0 deletions source/javascripts/core/models/BitriseYml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,15 @@ type GraphPipelineWorkflowModel = {

type PushTriggerModel = {
enabled?: boolean;
priority?: number;
branch?: string | TriggerMapItemModelRegexCondition;
commit_message?: string | TriggerMapItemModelRegexCondition;
changed_files?: string | TriggerMapItemModelRegexCondition;
};

type PullrequestTriggerModel = {
enabled?: boolean;
priority?: number;
draft_enabled?: boolean;
source_branch?: string | TriggerMapItemModelRegexCondition;
target_branch?: string | TriggerMapItemModelRegexCondition;
Expand All @@ -235,6 +237,7 @@ type PullrequestTriggerModel = {

type TagTriggerModel = {
enabled?: boolean;
priority?: number;
name?: string | TriggerMapItemModelRegexCondition;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ const TargetBasedTriggers = (props: TargetBasedTriggersProps) => {
<TriggerConditions
conditions={getConditionList(trigger)}
isDraftPr={trigger.draft_enabled}
priority={trigger.priority}
triggerType={trigger.type}
/>
</Td>
Expand Down
7 changes: 5 additions & 2 deletions spec/integration/test_bitrise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ pipelines:
- branch: main
workflows:
tmp:
parallel: 4
depends_on:
- wf1
parallel: 4
wf1: {}
wf2:
depends_on:
Expand Down Expand Up @@ -298,6 +298,8 @@ workflows:
summary: Second workflow
description: Second, but definitely not the last
triggers:
pull_request:
- target_branch: '*'
tag:
- name:
regex: '*'
Expand All @@ -314,7 +316,8 @@ workflows:
steps:
- git::https://github.com/bitrise-steplib/steps-script:
title: A script step referenced by git URL
summary: All non-overwritten attributes should be the step's default value from step.yml in the step's repository.
summary: All non-overwritten attributes should be the step's default value
from step.yml in the step's repository.
inputs:
- content: |
#!/usr/bin/env bash
Expand Down