{"results":{"result":{"added-files":{"code-health":10.0,"old-code-health":0.0,"files":[{"file":"apps/api/tests/test_public_channel_origin.py","loc":141,"code-health":10.0},{"file":"apps/api/tests/test_public_channel_start.py","loc":190,"code-health":10.0},{"file":"apps/channels/tests/test_public_channel.py","loc":209,"code-health":10.0},{"file":"apps/chatbots/public_link.py","loc":89,"code-health":10.0},{"file":"apps/chatbots/tests/test_public_link_page.py","loc":218,"code-health":10.0}]},"external-review-url":"https://github.com/dimagi/open-chat-studio/pull/4284","old-code-health":8.947442215573195,"modified-files":{"code-health":8.907127550884349,"old-code-health":8.947442215573195,"files":[{"file":"apps/channels/models.py","loc":442,"old-loc":399,"code-health":10.0,"old-code-health":9.6882083290695},{"file":"apps/channels/registry.py","loc":41,"old-loc":40,"code-health":10.0,"old-code-health":10.0},{"file":"apps/channels/tests/test_models.py","loc":244,"old-loc":222,"code-health":10.0,"old-code-health":10.0},{"file":"apps/teams/flags.py","loc":94,"old-loc":94,"code-health":10.0,"old-code-health":10.0},{"file":"apps/api/tests/test_widget_auth_level.py","loc":209,"old-loc":191,"code-health":10.0,"old-code-health":10.0},{"file":"apps/api/authentication.py","loc":201,"old-loc":191,"code-health":10.0,"old-code-health":10.0},{"file":"apps/api/permissions.py","loc":235,"old-loc":240,"code-health":10.0,"old-code-health":10.0},{"file":"apps/web/meta.py","loc":29,"old-loc":19,"code-health":10.0,"old-code-health":10.0},{"file":"apps/api/views/chat.py","loc":804,"old-loc":753,"code-health":8.601454004310554,"old-code-health":8.235348848160976},{"file":"apps/api/tests/test_throttling.py","loc":224,"old-loc":206,"code-health":10.0,"old-code-health":10.0},{"file":"apps/api/throttling.py","loc":55,"old-loc":53,"code-health":10.0,"old-code-health":10.0},{"file":"apps/channels/forms.py","loc":732,"old-loc":655,"code-health":8.004419920565056,"old-code-health":9.065314520102435},{"file":"apps/chatbots/tests/test_chatbot_views.py","loc":1111,"old-loc":1126,"code-health":7.325861446783724,"old-code-health":7.325861446783724},{"file":"apps/channels/management/commands/list_outdated_widget_versions.py","loc":182,"old-loc":182,"code-health":10.0,"old-code-health":10.0},{"file":"apps/channels/tests/test_list_outdated_widget_versions.py","loc":170,"old-loc":161,"code-health":10.0,"old-code-health":10.0},{"file":"apps/channels/tests/test_widget_versions.py","loc":214,"old-loc":205,"code-health":10.0,"old-code-health":10.0},{"file":"apps/channels/tests/conftest.py","loc":97,"old-loc":86,"code-health":10.0,"old-code-health":10.0}]},"removed-files":{"code-health":0.0,"old-code-health":0.0,"files":[]},"external-review-id":"4284","analysis-time":"2026-08-31T08:22:07Z","negative-impact-count":1,"suppressions":{"number-of-types":0,"number-of-files-touched":0,"findings":[]},"affected-hotspots":1,"commits":["13b04ca3788012e9a95830094ccfa43732c1c460","bea119edbd2a150633534b2b046e73246fd0985f","694c48d8777ee331d3a80ad31ae95b358c9d3311","dbbac8d2875661ef9128b624a7da472b21db6955","34196acd00e6cdb8b604917cbddbf9affbc82312","a0939e0d2a5a09df7c18dddff9c7edccf32dc1a8","b85c13e77af694e28528fd748b18f17b426b9926","cad54a7d6e32065cdf1cecf5973b1f2e0d17a5c6","e39ad9936403f9d7398b337d78d3a3a36a46bc15","053fb33b8129b6af98c5097a61d8128827a99c19","19360e6f444955078979b2804c001f17d87e2d32","a9dff0c22b4528bfddbf89160e59dcf7f031faed","16dc0dd0aa062add1889e4d693676fc47143248f","218914076dc41d266ff31185fdcf4a10a7c7cc82","befa340d65ac115c59eb7ecfabcf934d9cec0d5c","a3b1ae16eb90d0213a0f9192d6cb6dc16b9a98bd","e2cbb32491968a02bb2dbfeb2a7e3c1d0bb9e70d","7dea35b2441686fa5c1b9a3e1cd70b3b75b7e839","529a9e47d326eee334ccbeea952da8dbb13f1e97","861614ca53d55beade188060e62506d7bab673a6","9d2b1a92ac17f073ca430045f9fd4f832151794a","67929e9ac9def3663168b0b5e94a5431cd60a73e","e870967c382e7ee5990397efeb2d3ba8bb7d68f1","aa95a6de297acee450c0aeba6a856e66301d9231","83b8763b375504d74765fed68d8f1ff69eb1a3f9","c6d1b13faf1207a215a7fa4a9468f1b845245416","f1280290d008337f9d6e763a41ee852d25ff76f1","451b5c02d2f0a772395d8af6e5e53584f25f98aa","8a729a8bbc70d855a3f87e011e6c08065b670b0a","92a0554f5624b7e7eff04614ba432e1c6281ec91","98ea43ed4a3bd256bd5d566cc6155ed5f5e99d1e","12e6b94dca63130bafafe4dff543264e8bbac97c","d92236a5a73665c3881371953ece9a772d28b546","4f99fc07f94c4fdc5d6c26ed9e7e07ebc433853d","494d2902f0f0ec7ece0970e6c00ffd00be18ee16","d0509ce597344e6261f12bb06c1c6725c4d97cef","45d27478625648aeaab66e44ea51ceeac2cf30c6","5a346386738aa431f34382de483b8b3f239b58c0","971b841f04b8aa5a481292256156c8379adaedd1","a4d86fbc97c9722e039a9521f89b2cb6c1f546c9","19e4d3021a2ace121a20d8691f85cf39b6358362","aaac6feeea3d588d226149e0c99a18918a89dfaf","6b0c6aef87bbe828107e99255a0fda449a1b5e44","ceccdb76a1e5067f1a25ac2f7587bf46391099fa"],"is-negative-review":true,"negative-findings":{"number-of-types":1,"number-of-files-touched":1,"findings":[{"why-it-occurs":"Cohesion is a measure of how well the elements in a file belong together. CodeScene measures cohesion using the LCOM4 metric (Lack of Cohesion Measure). With LCOM4, the functions inside a module are related if a) they access the same data members, or b) they call each other. High Cohesion is desirable as it means that all functions are related and likely to represent the same responsibility. Low Cohesion is problematic since it means that the module contains multiple behaviors. Low Cohesion leads to code that's harder to understand, requires more tests, and very often become a coordination magnet for developers.","name":"Low Cohesion","file":"apps/channels/forms.py","refactoring-examples":[{"diff":"diff --git a/low_cohesion_example.js b/low_cohesion_example.js\nindex 1ae56cf85b..209fc02c73 100644\n--- a/low_cohesion_example.js\n+++ b/low_cohesion_example.js\n@@ -2,8 +2,10 @@\n \n var userLayer = connectUsers(myConnectionProperties);\n \n-var chessEngine = startEngine(gameProperties);\n+// [Refactoring: moved the data related to chess to a new chessGame.js module]\n \n+// The module contains login related functionality that forms one behaviour: all\n+// code is related since it either a) uses the same data, or b) calls the same functions.\n export function login(newUser) {\n   val authenticated = userLayer.authenticate(newUser);\n   traceLoginFor(authenticated);\n@@ -19,11 +21,6 @@ function traceLogin(user) {\n    // ...some code...\n }\n \n-// playChess seems like a very unrelated responsibility.\n-// Should it really be within the same module?\n-\n-export function playChess(loggedInUser) {\n-   var board = chessEngine.newBoard();\n-\n-   return newGameOn(board, loggedInUser);\n-}\n+// [Refactoring: moved playChess to a new chessGame.js module\n+// As a result of this refactoring, the module maintains a\n+// single behavior where all code and data is related: high cohesion.]\n","language":"python","improvement-type":"Low Cohesion"}],"change-level":"warning","is-hotspot?":false,"what-changed":"This module has at least 7 different responsibilities amongst its 56 functions, threshold = 4","how-to-fix":"Look to modularize the code by splitting the file into more cohesive units; functions that belong together should still be located together. A common refactoring is [EXTRACT CLASS](https://refactoring.com/catalog/extractClass.html).","change-type":"introduced"}]},"positive-impact-count":6,"repo":"open-chat-studio","code-health":9.063199539486769,"version":"3.0","authors":["barry47products"],"directives":{"added":[],"removed":[]},"positive-findings":{"number-of-types":5,"number-of-files-touched":3,"findings":[{"method":"ChannelPlatform.for_dropdown","why-it-occurs":"A Complex Method has a high cyclomatic complexity. The recommended threshold for the Python language is a cyclomatic complexity lower than 11.","name":"Complex Method","file":"apps/channels/models.py","change-level":"improvement","is-hotspot?":false,"line":50,"what-changed":"ChannelPlatform.for_dropdown is no longer above the threshold for cyclomatic complexity","how-to-fix":"There are many reasons for Complex Method. Sometimes, another design approach is beneficial such as a) modeling state using an explicit state machine rather than conditionals, or b) using table lookup rather than long chains of logic. In other scenarios, the function can be split using [EXTRACT FUNCTION](https://refactoring.com/catalog/extractFunction.html). Just make sure you extract natural and cohesive functions. Complex Methods can also be addressed by identifying complex conditional expressions and then using the [DECOMPOSE CONDITIONAL](https://refactoring.com/catalog/decomposeConditional.html) refactoring.","change-type":"fixed"},{"method":"chat_send_message","why-it-occurs":"A Complex Method has a high cyclomatic complexity. The recommended threshold for the Python language is a cyclomatic complexity lower than 11.","name":"Complex Method","file":"apps/api/views/chat.py","change-level":"improvement","is-hotspot?":true,"line":610,"what-changed":"chat_send_message is no longer above the threshold for cyclomatic complexity","how-to-fix":"There are many reasons for Complex Method. Sometimes, another design approach is beneficial such as a) modeling state using an explicit state machine rather than conditionals, or b) using table lookup rather than long chains of logic. In other scenarios, the function can be split using [EXTRACT FUNCTION](https://refactoring.com/catalog/extractFunction.html). Just make sure you extract natural and cohesive functions. Complex Methods can also be addressed by identifying complex conditional expressions and then using the [DECOMPOSE CONDITIONAL](https://refactoring.com/catalog/decomposeConditional.html) refactoring.","change-type":"fixed"},{"method":"chat_send_message","why-it-occurs":"A Bumpy Road is a function that contains multiple chunks of nested conditional logic inside the same function. The deeper the nesting and the more bumps, the lower the code health.\n\nA bumpy code road represents a lack of encapsulation which becomes an obstacle to comprehension. In imperative languages there’s also an increased risk for feature entanglement, which leads to complex state management. CodeScene considers the following rules for the code health impact: 1) The deeper the nested conditional logic of each bump, the higher the tax on our working memory. 2) The more bumps inside a function, the more expensive it is to refactor as each bump represents a missing abstraction. 3) The larger each bump – that is, the more lines of code it spans – the harder it is to build up a mental model of the function. The nesting depth for what is considered a bump is  levels of conditionals.","name":"Bumpy Road Ahead","file":"apps/api/views/chat.py","change-level":"improvement","is-hotspot?":true,"line":610,"what-changed":"chat_send_message is no longer above the threshold for logical blocks with deeply nested code","how-to-fix":"Bumpy Road implementations indicate a lack of encapsulation. Check out the detailed description of the [Bumpy Road code health issue](https://codescene.com/blog/bumpy-road-code-complexity-in-context/).\n\nA Bumpy Road often suggests that the function/method does too many things. The first refactoring step is to identify the different possible responsibilities of the function. Consider extracting those responsibilities into smaller, cohesive, and well-named functions. The [EXTRACT FUNCTION](https://refactoring.com/catalog/extractFunction.html) refactoring is the primary response.","change-type":"fixed"},{"name":"Overall Code Complexity","file":"apps/api/views/chat.py","change-type":"improved","change-level":"improvement","is-hotspot?":true,"why-it-occurs":"Overall Code Complexity is measured by the mean cyclomatic complexity across all functions in the file. The lower the number, the better.\n\nCyclomatic complexity is a function level metric that measures the number of logical branches (if-else, loops, etc.). Cyclomatic complexity is a rough complexity measure, but useful as a way of estimating the minimum number of unit tests you would need. As such, prefer functions with low cyclomatic complexity (2-3 branches).","how-to-fix":"You address the overall cyclomatic complexity by a) modularizing the code, and b) abstract away the complexity. Let's look at some examples:\n\nModularizing the Code: Do an X-Ray and inspect the local hotspots. Are there any complex conditional expressions? If yes, then do a [DECOMPOSE CONDITIONAL](https://refactoring.com/catalog/decomposeConditional.html) refactoring. Extract the conditional logic into a separate function and put a good name on that function. This clarifies the intent and makes the original function easier to read. Repeat until all complex conditional expressions have been simplified.\n\n","what-changed":"The mean cyclomatic complexity decreases from 6.28 to 5.24, threshold = 4"},{"name":"Lines of Code in a Single File","file":"apps/chatbots/tests/test_chatbot_views.py","change-type":"improved","change-level":"improvement","is-hotspot?":false,"why-it-occurs":"This module has 994 lines of code (comments stripped away). This puts the module at risk of evolving into a Brain Class. Brain Classes are problematic since changes become more complex over time, harder to test, and challenging to refactor. Act now to prevent future maintenance issues.","how-to-fix":"Look for opportunities to modularize the design. This is done by identifying groups of functions that represent different responsibilities and/or operate on different data. Once you have identified the different responsibilities, then use refactorings like [EXTRACT CLASS](https://refactoring.com/catalog/extractClass.html).","what-changed":"The lines of code decreases from 1006 to 994, improve code health by reducing it to 600"},{"name":"Low Cohesion","file":"apps/chatbots/tests/test_chatbot_views.py","change-type":"improved","change-level":"improvement","is-hotspot?":false,"why-it-occurs":"Cohesion is a measure of how well the elements in a file belong together. CodeScene measures cohesion using the LCOM4 metric (Lack of Cohesion Measure). With LCOM4, the functions inside a module are related if a) they access the same data members, or b) they call each other. High Cohesion is desirable as it means that all functions are related and likely to represent the same responsibility. Low Cohesion is problematic since it means that the module contains multiple behaviors. Low Cohesion leads to code that's harder to understand, requires more tests, and very often become a coordination magnet for developers.","how-to-fix":"Look to modularize the code by splitting the file into more cohesive units; functions that belong together should still be located together. A common refactoring is [EXTRACT CLASS](https://refactoring.com/catalog/extractClass.html).","what-changed":"The number of different responsibilities decreases from 36 to 35, threshold = 4"}]},"notices":{"number-of-types":0,"number-of-files-touched":0,"findings":[]},"external-review-provider":"GitHub"},"analysistime":"2026-08-31T08:22:06.000Z","project-name":"open-chat-studio","repository":"https://github.com/dimagi/open-chat-studio.git"}}