Skip to content

Commit

Permalink
fix(BuildPipeline): filter pipeine run based on sender annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
sahil143 committed Jun 10, 2024
1 parent 731eb36 commit ee781ec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 26 deletions.
20 changes: 8 additions & 12 deletions src/hooks/usePACState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,12 @@ const usePACState = (component: ComponentKind) => {
},
matchExpressions: [
{ key: PipelineRunLabel.PULL_REQUEST_NUMBER_LABEL, operator: 'DoesNotExist' },
{
key: PipelineRunLabel.COMMIT_USER_LABEL,
values: [prBotName],
operator: 'NotEquals',
},
{
key: PipelineRunLabel.COMMIT_USER_LABEL,
operator: 'Exists',
},
],
},
limit: 1,
// this limit is based on the assumption that user merges the PR after the component is created
limit: 10,
}),
[component.metadata.name, component.spec.application, prBotName],
[component.metadata.name, component.spec.application],
),
);

Expand All @@ -77,6 +69,10 @@ const usePACState = (component: ComponentKind) => {
[configurationTime, pipelineBuildRuns],
);

const prMerged = runsForComponent.find(
(r) => !r.metadata?.annotations?.[PipelineRunLabel.COMMIT_USER_LABEL]?.includes(prBotName),
);

return isSample
? PACState.sample
: isConfigureRequested
Expand All @@ -86,7 +82,7 @@ const usePACState = (component: ComponentKind) => {
: pacProvision === ComponentBuildState.enabled
? !pipelineBuildRunsLoaded
? PACState.loading
: runsForComponent?.length > 0
: prMerged
? PACState.ready
: PACState.pending
: !pacProvision || pacProvision === ComponentBuildState.disabled
Expand Down
22 changes: 8 additions & 14 deletions src/hooks/usePACStatesForComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,10 @@ const usePACStatesForComponents = (components: ComponentKind[]): PacStatesForCom
values: neededNames,
},
{ key: PipelineRunLabel.PULL_REQUEST_NUMBER_LABEL, operator: 'DoesNotExist' },
{
key: PipelineRunLabel.COMMIT_USER_LABEL,
values: [prBotName],
operator: 'NotEquals',
},
{
key: PipelineRunLabel.COMMIT_USER_LABEL,
operator: 'Exists',
},
],
},
}),
[application, neededNames, prBotName],
[application, neededNames],
),
);

Expand All @@ -117,15 +108,18 @@ const usePACStatesForComponents = (components: ComponentKind[]): PacStatesForCom
);
const configurationTime = buildStatus?.pac?.['configuration-time'];

const runForComponent = pipelineBuildRuns?.find(
const runsForComponent = pipelineBuildRuns?.filter(
(p) =>
p.metadata.labels?.[PipelineRunLabel.COMPONENT] === componentName &&
(configurationTime
? new Date(p.metadata.creationTimestamp) > new Date(configurationTime)
: true),
);

if (runForComponent) {
const prMerged = runsForComponent.find(
(r) =>
!r.metadata?.annotations?.[PipelineRunLabel.COMMIT_USER_LABEL]?.includes(prBotName),
);
if (prMerged) {
updates[componentName] = PACState.ready;
update = true;
} else if (!getNextPage) {
Expand All @@ -144,7 +138,7 @@ const usePACStatesForComponents = (components: ComponentKind[]): PacStatesForCom
getNextPage();
}
}
}, [components, getNextPage, neededNames, pipelineBuildRuns, pipelineBuildRunsLoaded]);
}, [components, getNextPage, neededNames, pipelineBuildRuns, pipelineBuildRunsLoaded, prBotName]);

return componentPacStates;
};
Expand Down

0 comments on commit ee781ec

Please sign in to comment.