Kentico/gatsby-source-kontent

View on GitHub
packages/gatsby-source/src/webhookProcessor.ts

Summary

Maintainability
D
2 days
Test Coverage

Function handleIncomingWebhook has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
Open

const handleIncomingWebhook = async (
  api: SourceNodesArgs,
  pluginConfig: CustomPluginOptions,
  itemTypes: string[],
): Promise<void> => {
Severity: Minor
Found in packages/gatsby-source/src/webhookProcessor.ts - About 4 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function handleDeleteItem has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
Open

const handleDeleteItem = async (
  api: SourceNodesArgs,
  pluginConfig: CustomPluginOptions
): Promise<string[]> => {
Severity: Minor
Found in packages/gatsby-source/src/webhookProcessor.ts - About 2 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function handleIncomingWebhook has 70 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const handleIncomingWebhook = async (
  api: SourceNodesArgs,
  pluginConfig: CustomPluginOptions,
  itemTypes: string[],
): Promise<void> => {
Severity: Major
Found in packages/gatsby-source/src/webhookProcessor.ts - About 2 hrs to fix

    Function handleDeleteItem has 58 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    const handleDeleteItem = async (
      api: SourceNodesArgs,
      pluginConfig: CustomPluginOptions
    ): Promise<string[]> => {
    
    Severity: Major
    Found in packages/gatsby-source/src/webhookProcessor.ts - About 2 hrs to fix

      Consider simplifying this complex logical expression.
      Open

        else if ((api.webhookBody as IWebhookWorkflowResponse)?.message?.api_name === "content_management") {
          const parsedBody = api.webhookBody as IWebhookWorkflowResponse;
      
          const isCorrectStructure = parsedBody?.data?.items?.every(item => item.language && item.transition_from && item.transition_to && item.item.id)
            && parsedBody?.message?.api_name
      Severity: Major
      Found in packages/gatsby-source/src/webhookProcessor.ts - About 1 hr to fix

        Function handleUpsertItem has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

        const handleUpsertItem = async (
          api: SourceNodesArgs,
          pluginConfig: CustomPluginOptions,
          itemId: string,
          itemLanguage?: string,
        Severity: Minor
        Found in packages/gatsby-source/src/webhookProcessor.ts - About 55 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function parseKontentWebhookBody has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

        const parseKontentWebhookBody = (api: SourceNodesArgs): IWebhookDeliveryResponse | IWebhookWorkflowResponse | null => {
        
          if ((api.webhookBody as IWebhookDeliveryResponse)?.message?.api_name === "delivery_preview" || (api.webhookBody as IWebhookDeliveryResponse)?.message?.api_name === "delivery_production") {
            const parsedBody = api.webhookBody as IWebhookDeliveryResponse;
        
        Severity: Minor
        Found in packages/gatsby-source/src/webhookProcessor.ts - About 55 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Consider simplifying this complex logical expression.
        Open

          if ((api.webhookBody as IWebhookDeliveryResponse)?.message?.api_name === "delivery_preview" || (api.webhookBody as IWebhookDeliveryResponse)?.message?.api_name === "delivery_production") {
            const parsedBody = api.webhookBody as IWebhookDeliveryResponse;
        
            const isCorrectStructure = parsedBody?.data?.items?.every(item => item.language && item.id)
              && parsedBody?.message?.api_name
        Severity: Major
        Found in packages/gatsby-source/src/webhookProcessor.ts - About 40 mins to fix

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

                for (const key in modularKontent) {
                  if (Object.prototype.hasOwnProperty.call(modularKontent, key)) {
                    const modularKontentItem = modularKontent[key];
                    const nodeId = createNodeFromRawKontentItem(api, modularKontentItem, pluginConfig.includeRawContent, lang);
                    touchedItemsIds.push(nodeId);
          Severity: Major
          Found in packages/gatsby-source/src/webhookProcessor.ts and 1 other location - About 2 hrs to fix
          packages/gatsby-source/src/webhookProcessor.ts on lines 103..109

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 77.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

              for (const key in modularKontent) {
                if (Object.prototype.hasOwnProperty.call(modularKontent, key)) {
                  const modularKontentItem = modularKontent[key];
                  const nodeId = createNodeFromRawKontentItem(api, modularKontentItem, pluginConfig.includeRawContent, lang);
                  createdItemsIds.push(nodeId);
          Severity: Major
          Found in packages/gatsby-source/src/webhookProcessor.ts and 1 other location - About 2 hrs to fix
          packages/gatsby-source/src/webhookProcessor.ts on lines 175..181

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 77.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

            if (pluginConfig.includeTaxonomies) {
              const taxonomies = api.getNodesByType(getKontentTaxonomyTypeName());
              for (const taxonomy of taxonomies) {
                api.actions.touchNode(taxonomy);
              }
          Severity: Major
          Found in packages/gatsby-source/src/webhookProcessor.ts and 1 other location - About 1 hr to fix
          packages/gatsby-source/src/webhookProcessor.ts on lines 294..299

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 57.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

            if (pluginConfig.includeTypes) {
              const types = api.getNodesByType(getKontentTypeTypeName());
              for (const type of types) {
                api.actions.touchNode(type);
              }
          Severity: Major
          Found in packages/gatsby-source/src/webhookProcessor.ts and 1 other location - About 1 hr to fix
          packages/gatsby-source/src/webhookProcessor.ts on lines 287..292

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 57.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

              if (webhook.message.operation === "archive") {
                const processedIds = await handleDeleteItem(api, pluginConfig);
                processedItemIds.push(...processedIds);
              }
          Severity: Minor
          Found in packages/gatsby-source/src/webhookProcessor.ts and 1 other location - About 35 mins to fix
          packages/gatsby-source/src/webhookProcessor.ts on lines 255..258

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 46.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

              if (webhook.message.operation === "unpublish") {
                const processedIds = await handleDeleteItem(api, pluginConfig);
                processedItemIds.push(...processedIds);
              }
          Severity: Minor
          Found in packages/gatsby-source/src/webhookProcessor.ts and 1 other location - About 35 mins to fix
          packages/gatsby-source/src/webhookProcessor.ts on lines 238..241

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 46.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          There are no issues that match your filters.

          Category
          Status