@elisra-devops/docgen-data-provider 1.69.0 → 1.69.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/modules/PipelinesDataProvider.d.ts +104 -22
- package/bin/modules/PipelinesDataProvider.js +364 -58
- package/bin/modules/PipelinesDataProvider.js.map +1 -1
- package/bin/tests/modules/pipelineDataProvider.test.js +207 -8
- package/bin/tests/modules/pipelineDataProvider.test.js.map +1 -1
- package/package.json +1 -1
- package/src/modules/PipelinesDataProvider.ts +404 -60
- package/src/tests/modules/pipelineDataProvider.test.ts +232 -8
|
@@ -262,8 +262,8 @@ describe('PipelinesDataProvider', () => {
|
|
|
262
262
|
null
|
|
263
263
|
);
|
|
264
264
|
expect(result).toEqual({
|
|
265
|
-
count:
|
|
266
|
-
value: mockResponse.value,
|
|
265
|
+
count: 2,
|
|
266
|
+
value: mockResponse.value.filter((r) => r.result !== 'failed' && r.result !== 'canceled'),
|
|
267
267
|
});
|
|
268
268
|
});
|
|
269
269
|
|
|
@@ -704,13 +704,15 @@ describe('PipelinesDataProvider', () => {
|
|
|
704
704
|
id: 123,
|
|
705
705
|
url: 'https://dev.azure.com/org/project/_apis/pipelines/123?revision=1',
|
|
706
706
|
},
|
|
707
|
+
runId: 789,
|
|
707
708
|
},
|
|
708
709
|
},
|
|
709
710
|
},
|
|
710
711
|
} as unknown as PipelineRun;
|
|
711
712
|
|
|
712
713
|
const mockBuildResponse = {
|
|
713
|
-
|
|
714
|
+
id: 789,
|
|
715
|
+
definition: { id: 123, type: 'build' },
|
|
714
716
|
buildNumber: '20231201.1',
|
|
715
717
|
project: { name: 'project1' },
|
|
716
718
|
repository: { type: 'TfsGit' },
|
|
@@ -725,8 +727,8 @@ describe('PipelinesDataProvider', () => {
|
|
|
725
727
|
expect(result).toHaveLength(1);
|
|
726
728
|
expect((result as any[])[0]).toEqual({
|
|
727
729
|
name: 'myPipeline',
|
|
728
|
-
buildId:
|
|
729
|
-
definitionId:
|
|
730
|
+
buildId: 789,
|
|
731
|
+
definitionId: 123,
|
|
730
732
|
buildNumber: '20231201.1',
|
|
731
733
|
teamProject: 'project1',
|
|
732
734
|
provider: 'TfsGit',
|
|
@@ -743,6 +745,7 @@ describe('PipelinesDataProvider', () => {
|
|
|
743
745
|
id: 123,
|
|
744
746
|
url: 'https://dev.azure.com/org/project/_apis/pipelines/123?revision=1',
|
|
745
747
|
},
|
|
748
|
+
runId: 789,
|
|
746
749
|
},
|
|
747
750
|
},
|
|
748
751
|
},
|
|
@@ -755,12 +758,233 @@ describe('PipelinesDataProvider', () => {
|
|
|
755
758
|
|
|
756
759
|
// Assert
|
|
757
760
|
expect(result).toEqual([]);
|
|
758
|
-
|
|
761
|
+
});
|
|
762
|
+
|
|
763
|
+
it('should resolve resource pipeline by buildNumber when runId is missing and version is semantic', async () => {
|
|
764
|
+
// Arrange
|
|
765
|
+
const inPipeline = {
|
|
766
|
+
url: 'https://dev.azure.com/org/project1/_apis/pipelines/10/runs/200',
|
|
767
|
+
resources: {
|
|
768
|
+
pipelines: {
|
|
769
|
+
SOME_PACKAGE: {
|
|
770
|
+
pipeline: {
|
|
771
|
+
id: 123,
|
|
772
|
+
url: 'https://dev.azure.com/org/project1/_apis/pipelines/123?revision=1',
|
|
773
|
+
},
|
|
774
|
+
project: { name: 'project1' },
|
|
775
|
+
source: 'project1-system-package',
|
|
776
|
+
version: '1.0.56',
|
|
777
|
+
branch: 'main',
|
|
778
|
+
},
|
|
779
|
+
},
|
|
780
|
+
},
|
|
781
|
+
} as unknown as PipelineRun;
|
|
782
|
+
|
|
783
|
+
const mockListBuildsResponse = {
|
|
784
|
+
value: [
|
|
785
|
+
{
|
|
786
|
+
id: 789,
|
|
787
|
+
},
|
|
788
|
+
],
|
|
789
|
+
};
|
|
790
|
+
const mockBuildResponse = {
|
|
791
|
+
id: 789,
|
|
792
|
+
definition: { id: 123, type: 'build' },
|
|
793
|
+
buildNumber: '1.0.56',
|
|
794
|
+
project: { name: 'project1' },
|
|
795
|
+
repository: { type: 'TfsGit' },
|
|
796
|
+
};
|
|
797
|
+
|
|
798
|
+
(TFSServices.getItemContent as jest.Mock)
|
|
799
|
+
.mockResolvedValueOnce(mockListBuildsResponse) // findBuildByDefinitionAndBuildNumber
|
|
800
|
+
.mockResolvedValueOnce(mockBuildResponse); // getPipelineBuildByBuildId
|
|
801
|
+
|
|
802
|
+
// Act
|
|
803
|
+
const result = await pipelinesDataProvider.getPipelineResourcePipelinesFromObject(inPipeline);
|
|
804
|
+
|
|
805
|
+
// Assert
|
|
806
|
+
expect(result).toHaveLength(1);
|
|
807
|
+
expect((result as any[])[0]).toEqual({
|
|
808
|
+
name: 'SOME_PACKAGE',
|
|
809
|
+
buildId: 789,
|
|
810
|
+
definitionId: 123,
|
|
811
|
+
buildNumber: '1.0.56',
|
|
812
|
+
teamProject: 'project1',
|
|
813
|
+
provider: 'TfsGit',
|
|
814
|
+
});
|
|
815
|
+
|
|
816
|
+
// Ensure branch normalization was applied in the build search URL
|
|
817
|
+
expect((TFSServices.getItemContent as jest.Mock).mock.calls[0][0]).toContain('branchName=refs%2Fheads%2Fmain');
|
|
818
|
+
expect((TFSServices.getItemContent as jest.Mock).mock.calls[0][0]).toContain('buildNumber=1.0.56');
|
|
819
|
+
expect((TFSServices.getItemContent as jest.Mock).mock.calls[0][0]).toContain('definitions=123');
|
|
820
|
+
});
|
|
821
|
+
|
|
822
|
+
it('should fall back to pipeline run history when buildNumber lookup returns no builds', async () => {
|
|
823
|
+
// Arrange
|
|
824
|
+
const inPipeline = {
|
|
825
|
+
url: 'https://dev.azure.com/org/project1/_apis/pipelines/10/runs/200',
|
|
826
|
+
resources: {
|
|
827
|
+
pipelines: {
|
|
828
|
+
SOME_PACKAGE: {
|
|
829
|
+
pipeline: {
|
|
830
|
+
id: 123,
|
|
831
|
+
url: 'https://dev.azure.com/org/project1/_apis/pipelines/123?revision=1',
|
|
832
|
+
},
|
|
833
|
+
project: { name: 'project1' },
|
|
834
|
+
source: 'project1-system-package',
|
|
835
|
+
version: '20251109.1',
|
|
836
|
+
branch: 'main',
|
|
837
|
+
},
|
|
838
|
+
},
|
|
839
|
+
},
|
|
840
|
+
} as unknown as PipelineRun;
|
|
841
|
+
|
|
842
|
+
const mockListBuildsResponseEmpty = { value: [] };
|
|
843
|
+
const mockRunHistoryResponse = {
|
|
844
|
+
value: [{ id: 789, name: '20251109.1', result: 'succeeded' }],
|
|
845
|
+
};
|
|
846
|
+
const mockBuildResponse = {
|
|
847
|
+
id: 789,
|
|
848
|
+
definition: { id: 123, type: 'build' },
|
|
849
|
+
buildNumber: '20251109.1',
|
|
850
|
+
project: { name: 'project1' },
|
|
851
|
+
repository: { type: 'TfsGit' },
|
|
852
|
+
};
|
|
853
|
+
|
|
854
|
+
(TFSServices.getItemContent as jest.Mock)
|
|
855
|
+
.mockResolvedValueOnce(mockListBuildsResponseEmpty) // findBuildByDefinitionAndBuildNumber
|
|
856
|
+
.mockResolvedValueOnce(mockListBuildsResponseEmpty) // findBuildByBuildNumber (no definition)
|
|
857
|
+
.mockResolvedValueOnce(mockRunHistoryResponse) // GetPipelineRunHistory
|
|
858
|
+
.mockResolvedValueOnce(mockBuildResponse); // getPipelineBuildByBuildId
|
|
859
|
+
|
|
860
|
+
// Act
|
|
861
|
+
const result = await pipelinesDataProvider.getPipelineResourcePipelinesFromObject(inPipeline);
|
|
862
|
+
|
|
863
|
+
// Assert
|
|
864
|
+
expect(result).toHaveLength(1);
|
|
865
|
+
expect((result as any[])[0]).toEqual({
|
|
866
|
+
name: 'SOME_PACKAGE',
|
|
867
|
+
buildId: 789,
|
|
868
|
+
definitionId: 123,
|
|
869
|
+
buildNumber: '20251109.1',
|
|
870
|
+
teamProject: 'project1',
|
|
871
|
+
provider: 'TfsGit',
|
|
872
|
+
});
|
|
873
|
+
});
|
|
874
|
+
|
|
875
|
+
it('should fall back to buildNumber-only lookup when definition-based lookup returns no builds', async () => {
|
|
876
|
+
const inPipeline = {
|
|
877
|
+
url: 'https://dev.azure.com/org/project1/_apis/pipelines/10/runs/200',
|
|
878
|
+
resources: {
|
|
879
|
+
pipelines: {
|
|
880
|
+
SOME_PACKAGE: {
|
|
881
|
+
pipeline: {
|
|
882
|
+
id: 770,
|
|
883
|
+
url: 'https://dev.azure.com/org/project1/_apis/pipelines/770?revision=1',
|
|
884
|
+
},
|
|
885
|
+
project: { name: 'project1' },
|
|
886
|
+
source: 'project1-system-package',
|
|
887
|
+
version: '20251109.1',
|
|
888
|
+
branch: 'main',
|
|
889
|
+
},
|
|
890
|
+
},
|
|
891
|
+
},
|
|
892
|
+
} as unknown as PipelineRun;
|
|
893
|
+
|
|
894
|
+
const mockListBuildsResponseEmpty = { value: [] };
|
|
895
|
+
const mockListBuildsByNumber = {
|
|
896
|
+
value: [
|
|
897
|
+
{
|
|
898
|
+
id: 789,
|
|
899
|
+
definition: { id: 123, name: 'project1-system-package' },
|
|
900
|
+
},
|
|
901
|
+
],
|
|
902
|
+
};
|
|
903
|
+
const mockBuildResponse = {
|
|
904
|
+
id: 789,
|
|
905
|
+
definition: { id: 123, type: 'build' },
|
|
906
|
+
buildNumber: '20251109.1',
|
|
907
|
+
project: { name: 'project1' },
|
|
908
|
+
repository: { type: 'TfsGit' },
|
|
909
|
+
};
|
|
910
|
+
|
|
911
|
+
(TFSServices.getItemContent as jest.Mock)
|
|
912
|
+
.mockResolvedValueOnce(mockListBuildsResponseEmpty) // findBuildByDefinitionAndBuildNumber
|
|
913
|
+
.mockResolvedValueOnce(mockListBuildsByNumber) // findBuildByBuildNumber (no definition)
|
|
914
|
+
.mockResolvedValueOnce(mockBuildResponse); // getPipelineBuildByBuildId
|
|
915
|
+
|
|
916
|
+
const result = await pipelinesDataProvider.getPipelineResourcePipelinesFromObject(inPipeline);
|
|
917
|
+
|
|
918
|
+
expect(result).toHaveLength(1);
|
|
919
|
+
expect((result as any[])[0]).toEqual({
|
|
920
|
+
name: 'SOME_PACKAGE',
|
|
921
|
+
buildId: 789,
|
|
922
|
+
definitionId: 123,
|
|
923
|
+
buildNumber: '20251109.1',
|
|
924
|
+
teamProject: 'project1',
|
|
925
|
+
provider: 'TfsGit',
|
|
926
|
+
});
|
|
927
|
+
|
|
928
|
+
// Ensure the second call is the buildNumber-only lookup (no definitions= filter)
|
|
929
|
+
expect((TFSServices.getItemContent as jest.Mock).mock.calls[1][0]).toContain('buildNumber=20251109.1');
|
|
930
|
+
expect((TFSServices.getItemContent as jest.Mock).mock.calls[1][0]).not.toContain('definitions=');
|
|
931
|
+
});
|
|
932
|
+
|
|
933
|
+
it('should resolve project name when pipeline resource provides project id (GUID)', async () => {
|
|
934
|
+
const inPipeline = {
|
|
935
|
+
url: 'https://dev.azure.com/org/project1/_apis/pipelines/10/runs/200',
|
|
936
|
+
resources: {
|
|
937
|
+
pipelines: {
|
|
938
|
+
SOME_PACKAGE: {
|
|
939
|
+
pipeline: {
|
|
940
|
+
id: 123,
|
|
941
|
+
url: 'https://dev.azure.com/org/1488cb19-7369-4afc-92bf-251d368b85be/_apis/pipelines/123?revision=1',
|
|
942
|
+
},
|
|
943
|
+
project: { name: '1488cb19-7369-4afc-92bf-251d368b85be' },
|
|
944
|
+
source: 'project1-system-package',
|
|
945
|
+
version: '20251109.1',
|
|
946
|
+
branch: 'main',
|
|
947
|
+
},
|
|
948
|
+
},
|
|
949
|
+
},
|
|
950
|
+
} as unknown as PipelineRun;
|
|
951
|
+
|
|
952
|
+
const mockProjectResponse = { id: '1488cb19-7369-4afc-92bf-251d368b85be', name: 'Test CMMI' };
|
|
953
|
+
const mockListBuildsResponse = { value: [{ id: 789 }] };
|
|
954
|
+
const mockBuildResponse = {
|
|
955
|
+
id: 789,
|
|
956
|
+
definition: { id: 123, type: 'build' },
|
|
957
|
+
buildNumber: '20251109.1',
|
|
958
|
+
project: { name: 'Test CMMI' },
|
|
959
|
+
repository: { type: 'TfsGit' },
|
|
960
|
+
};
|
|
961
|
+
|
|
962
|
+
(TFSServices.getItemContent as jest.Mock)
|
|
963
|
+
.mockResolvedValueOnce(mockProjectResponse) // normalizeProjectName
|
|
964
|
+
.mockResolvedValueOnce(mockListBuildsResponse) // findBuildByDefinitionAndBuildNumber
|
|
965
|
+
.mockResolvedValueOnce(mockBuildResponse); // getPipelineBuildByBuildId
|
|
966
|
+
|
|
967
|
+
const result = await pipelinesDataProvider.getPipelineResourcePipelinesFromObject(inPipeline);
|
|
968
|
+
|
|
969
|
+
expect(result).toHaveLength(1);
|
|
970
|
+
expect((result as any[])[0]).toEqual({
|
|
971
|
+
name: 'SOME_PACKAGE',
|
|
972
|
+
buildId: 789,
|
|
973
|
+
definitionId: 123,
|
|
974
|
+
buildNumber: '20251109.1',
|
|
975
|
+
teamProject: 'Test CMMI',
|
|
976
|
+
provider: 'TfsGit',
|
|
977
|
+
});
|
|
978
|
+
|
|
979
|
+
// Ensure project-id normalization API was called
|
|
980
|
+
expect((TFSServices.getItemContent as jest.Mock).mock.calls[0][0]).toContain(
|
|
981
|
+
`${mockOrgUrl}_apis/projects/1488cb19-7369-4afc-92bf-251d368b85be`
|
|
982
|
+
);
|
|
759
983
|
});
|
|
760
984
|
});
|
|
761
985
|
|
|
762
986
|
describe('getPipelineResourceRepositoriesFromObject', () => {
|
|
763
|
-
it('should return empty
|
|
987
|
+
it('should return empty array when no repository resources exist', async () => {
|
|
764
988
|
// Arrange
|
|
765
989
|
const inPipeline = {
|
|
766
990
|
resources: {},
|
|
@@ -774,7 +998,7 @@ describe('PipelinesDataProvider', () => {
|
|
|
774
998
|
);
|
|
775
999
|
|
|
776
1000
|
// Assert
|
|
777
|
-
expect(result).toEqual(
|
|
1001
|
+
expect(result).toEqual([]);
|
|
778
1002
|
});
|
|
779
1003
|
|
|
780
1004
|
it('should extract repository resources from pipeline object', async () => {
|