]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-14872 Scope api calls to project only
authorPhilippe Perrin <philippe.perrin@sonarsource.com>
Tue, 29 Jun 2021 14:10:52 +0000 (16:10 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 30 Jun 2021 20:03:13 +0000 (20:03 +0000)
server/sonar-web/src/main/js/app/components/ComponentContainer.tsx
server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx

index d1cf0ae7c1846aafff262ceb1c564b9940065368..31f7ea3ecf6f70b64558df9bb5e7471f03fd1cfe 100644 (file)
@@ -133,7 +133,10 @@ export class ComponentContainer extends React.PureComponent<Props, State> {
 
     const { branchLike, branchLikes } = await this.fetchBranches(componentWithQualifier);
 
-    const projectBinding = await getProjectAlmBinding(key).catch(() => undefined);
+    let projectBinding;
+    if (componentWithQualifier.qualifier === ComponentQualifier.Project) {
+      projectBinding = await getProjectAlmBinding(key).catch(() => undefined);
+    }
 
     if (this.mounted) {
       this.setState({
@@ -247,7 +250,11 @@ export class ComponentContainer extends React.PureComponent<Props, State> {
   };
 
   fetchProjectBindingErrors = async (component: T.Component) => {
-    if (component.analysisDate === undefined && this.props.appState.branchesEnabled) {
+    if (
+      component.qualifier === ComponentQualifier.Project &&
+      component.analysisDate === undefined &&
+      this.props.appState.branchesEnabled
+    ) {
       const projectBindingErrors = await validateProjectAlmBinding(component.key).catch(
         () => undefined
       );
index 84fc4a8bb52bb2bfba4f14c7a75a382d53a32ef5..e46025122e9d34d8f75bd2728fc082a9aec48e43 100644 (file)
@@ -97,6 +97,13 @@ it('changes component', () => {
 });
 
 it('loads the project binding, if any', async () => {
+  const component = mockComponent({
+    breadcrumbs: [{ key: 'foo', name: 'foo', qualifier: ComponentQualifier.Project }]
+  });
+  (getComponentNavigation as jest.Mock).mockResolvedValueOnce({});
+  (getComponentData as jest.Mock<any>)
+    .mockResolvedValueOnce({ component })
+    .mockResolvedValueOnce({ component });
   (getProjectAlmBinding as jest.Mock).mockResolvedValueOnce(undefined).mockResolvedValueOnce({
     alm: AlmKeys.GitHub,
     key: 'foo'
@@ -340,6 +347,27 @@ describe('should correctly validate the project binding depending on the context
   });
 });
 
+it.each([
+  [ComponentQualifier.Application],
+  [ComponentQualifier.Portfolio],
+  [ComponentQualifier.SubPortfolio]
+])(
+  'should not care about PR decoration settings for %s',
+  async (componentQualifier: ComponentQualifier) => {
+    const component = mockComponent({
+      breadcrumbs: [{ key: 'foo', name: 'Foo', qualifier: componentQualifier }]
+    });
+    (getComponentNavigation as jest.Mock).mockResolvedValueOnce({});
+    (getComponentData as jest.Mock<any>).mockResolvedValueOnce({ component });
+
+    const wrapper = shallowRender();
+    await waitAndUpdate(wrapper);
+
+    expect(getProjectAlmBinding).not.toHaveBeenCalled();
+    expect(validateProjectAlmBinding).not.toHaveBeenCalled();
+  }
+);
+
 function shallowRender(props: Partial<ComponentContainer['props']> = {}) {
   return shallow<ComponentContainer>(
     <ComponentContainer