Skip to content

Commit

Permalink
fix(KFLUXBUGS-1910): add Gitlab push event type
Browse files Browse the repository at this point in the history
JIRA: KFLUXBUGS-1910
  • Loading branch information
CryptoRodeo committed Nov 25, 2024
1 parent b082a43 commit 20d8bd0
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/* eslint-disable @typescript-eslint/require-await */
/* eslint-disable @typescript-eslint/no-unsafe-argument */
/* eslint-disable @typescript-eslint/no-explicit-any */
// These checks are disabled for this test.

import '@testing-library/jest-dom';
import { useNavigate } from 'react-router-dom';
import { renderHook } from '@testing-library/react-hooks';
Expand Down Expand Up @@ -85,6 +90,45 @@ describe('usePipelinerunActions', () => {
);
});

it('should contain enabled actions for Gitlab pipeline run event type', async () => {
const { result } = renderHook(() =>
usePipelinerunActions({
metadata: {
labels: {
'pipelines.appstudio.openshift.io/type': 'build',
[PipelineRunLabel.COMMIT_EVENT_TYPE_LABEL]: PipelineRunEventType.GITLAB_PUSH,
},
},
status: { conditions: [{ type: 'Succeeded', status: runStatus.Running }] },
} as any),
);
const actions = result.current;

expect(actions[0]).toEqual(
expect.objectContaining({
label: 'Rerun',
disabled: false,
disabledTooltip: null,
}),
);

expect(actions[1]).toEqual(
expect.objectContaining({
label: 'Stop',
disabled: false,
disabledTooltip: undefined,
}),
);

expect(actions[2]).toEqual(
expect.objectContaining({
label: 'Cancel',
disabled: false,
disabledTooltip: undefined,
}),
);
});

it('should contain disabled actions for Stop and Cancel', () => {
useAccessReviewForModelMock.mockReturnValueOnce([true, true]);
const { result } = renderHook(() =>
Expand Down Expand Up @@ -134,6 +178,30 @@ describe('usePipelinerunActions', () => {
);
});

it('should contain enabled rerun actions when PAC enabled for Gitlab pipeline run event type', async () => {
useAccessReviewForModelMock.mockReturnValueOnce([true, true]);
const { result } = renderHook(() =>
usePipelinerunActions({
metadata: {
labels: {
'pipelines.appstudio.openshift.io/type': 'build',
[PipelineRunLabel.COMMIT_EVENT_TYPE_LABEL]: PipelineRunEventType.GITLAB_PUSH,
},
},
status: { conditions: [{ type: 'Succeeded', status: 'True' }] },
} as any),
);
const actions = result.current;

expect(actions[0]).toEqual(
expect.objectContaining({
label: 'Rerun',
disabled: false,
disabledTooltip: null,
}),
);
});

it('should contain disabled rerun actions for pull request builds', () => {
useAccessReviewForModelMock.mockReturnValueOnce([true, true]);
const { result } = renderHook(() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ export const usePipelinererunAction = (pipelineRun: PipelineRunKind) => {
const [snapshots, snapshotsLoaded, snapshotsError] = useSnapshots(namespace, workspace);

const snapShotLabel = pipelineRun?.metadata?.labels?.[PipelineRunLabel.SNAPSHOT];
const isPushBuildType = [PipelineRunEventType.PUSH, PipelineRunEventType.INCOMING].includes(
const isPushBuildType = [
PipelineRunEventType.PUSH,
PipelineRunEventType.GITLAB_PUSH,
PipelineRunEventType.INCOMING,
].includes(
pipelineRun?.metadata?.labels?.[
PipelineRunLabel.COMMIT_EVENT_TYPE_LABEL
] as PipelineRunEventType,
Expand Down
1 change: 1 addition & 0 deletions src/consts/pipelinerun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export enum PipelineRunType {

export enum PipelineRunEventType {
PUSH = 'push',
GITLAB_PUSH = 'Push',
PULL = 'pull_request',
INCOMING = 'incoming',
RETEST = 'retest-all-comment',
Expand Down

0 comments on commit 20d8bd0

Please sign in to comment.