]> source.dussan.org Git - sonarqube.git/commitdiff
Fix critical code smell
authorZipeng WU <zipeng.wu@sonarsource.com>
Mon, 15 Feb 2021 08:01:33 +0000 (09:01 +0100)
committersonartech <sonartech@sonarsource.com>
Mon, 15 Feb 2021 20:07:04 +0000 (20:07 +0000)
server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/PRDecorationBinding.tsx

index c38e99da161f7e058fb021d89d78c58c4c4c70b5..c00b8403d599463e44ce11abd400201167bca8bd 100644 (file)
@@ -169,9 +169,13 @@ export class PRDecorationBinding extends React.PureComponent<Props & StateProps,
     const slug = almSpecificFields?.slug;
     const monorepo = almSpecificFields?.monorepo ?? false;
 
+    if (!repository) {
+      return Promise.reject();
+    }
+
     switch (alm) {
       case AlmKeys.Azure: {
-        if (!slug || !repository) {
+        if (!slug) {
           return Promise.reject();
         }
         return setProjectAzureBinding({
@@ -183,7 +187,7 @@ export class PRDecorationBinding extends React.PureComponent<Props & StateProps,
         });
       }
       case AlmKeys.BitbucketServer: {
-        if (!repository || !slug) {
+        if (!slug) {
           return Promise.reject();
         }
         return setProjectBitbucketBinding({
@@ -195,9 +199,6 @@ export class PRDecorationBinding extends React.PureComponent<Props & StateProps,
         });
       }
       case AlmKeys.BitbucketCloud: {
-        if (!repository) {
-          return Promise.reject();
-        }
         return setProjectBitbucketCloudBinding({
           almSetting,
           project,
@@ -206,13 +207,7 @@ export class PRDecorationBinding extends React.PureComponent<Props & StateProps,
       }
       case AlmKeys.GitHub: {
         // By default it must remain true.
-        const summaryCommentEnabled =
-          almSpecificFields?.summaryCommentEnabled === undefined
-            ? true
-            : almSpecificFields?.summaryCommentEnabled;
-        if (!repository) {
-          return Promise.reject();
-        }
+        const summaryCommentEnabled = almSpecificFields?.summaryCommentEnabled ?? true;
         return setProjectGithubBinding({
           almSetting,
           project,
@@ -223,9 +218,6 @@ export class PRDecorationBinding extends React.PureComponent<Props & StateProps,
       }
 
       case AlmKeys.GitLab: {
-        if (!repository) {
-          return Promise.reject();
-        }
         return setProjectGitlabBinding({
           almSetting,
           project,