首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当dart_code_metrics检测到的警告达到一定数量时,如何禁止gitlab上的管道?

当dart_code_metrics检测到的警告达到一定数量时,如何禁止gitlab上的管道?
EN

Stack Overflow用户
提问于 2022-03-21 09:10:18
回答 1查看 246关注 0票数 2

我正在使用dart_code_metrics进行皮棉测试,当dart_code_metrics检测到的警告达到一定数量时,如何禁止gitlab上的管道?

以下是当前使用的脚本om:

代码语言:javascript
复制
stages:          # List of stages for jobs, and their order of execution
  # - build
  - test
  # - deploy
before_script:
  - flutter clean
  - flutter pub get
  - gem install bundler
  - bundle install

code_quality:
  stage: test
  # tags:
  #   - flutter
  image: "cirrusci/flutter:stable"
  before_script:
    - pub global activate dart_code_metrics
    - export PATH="$PATH:$HOME/.pub-cache/bin"
  script:
    - metrics lib -r codeclimate  > gl-code-quality-report.json
  artifacts:
    reports:
      codequality: gl-code-quality-report.json
test:
  stage: test
  # tags:
  #   - flutter
  image: "cirrusci/flutter:stable"
  before_script:
    - flutter pub get
    - pub run build_runner build --delete-conflicting-outputs
    - pub global activate junitreport
    - export PATH="$PATH:$HOME/.pub-cache/bin"
  script:
    - flutter test --coverage
    - genhtml coverage/lcov.info --output=coverage
  coverage: '/lines\.*: \d+\.\d+\%/'
  artifacts:
    name: coverage
    paths:
      - $CI_PROJECT_DIR/coverage
    reports:
      junit: report.xml

编辑:

gl代码质量报告.below的输出如下所示:

代码语言:javascript
复制
{"type":"issue","check_name":"maximum-nesting-level","description":"This method has a nesting level of 6, which exceeds the maximum of 5 allowed.","categories":["Complexity"],"location":{"path":"lib/features/lesi_management/domain/usecase/SendSubManagementRequestUsecase.dart","positions":{"begin":{"line":7,"column":3},"end":{"line":61,"column":4}}},"severity":"info","fingerprint":"59993c63f8f1d9467d82b29527726c77"}�
{"type":"issue","check_name":"cyclomatic-complexity","description":"This method has a cyclomatic complexity of 27, which exceeds the maximum of 20 allowed.","categories":["Complexity"],"location":{"path":"lib/features/lesi_display/presentation/controller/HistoryPageViewModel.dart","positions":{"begin":{"line":90,"column":3},"end":{"line":296,"column":4}}},"severity":"info","fingerprint":"8cfa962ce15b32b130289076f407ae8d"}�
{"type":"issue","check_name":"cyclomatic-complexity","description":"This method has a cyclomatic complexity of 26, which exceeds the maximum of 20 allowed.","categories":["Complexity"],"location":{"path":"lib/features/lesi_display/presentation/controller/DeviceOverallPageViewModel.dart","positions":{"begin":{"line":40,"column":3},"end":{"line":331,"column":4}}},"severity":"info","fingerprint":"80372c845392ad7035c29867cbe673ad"}�
{"type":"issue","check_name":"maximum-nesting-level","description":"This method has a nesting level of 9, which exceeds the maximum of 5 allowed.","categories":["Complexity"],"location":{"path":"lib/features/lesi_display/presentation/controller/DeviceOverallPageViewModel.dart","positions":{"begin":{"line":40,"column":3},"end":{"line":331,"column":4}}},"severity":"info","fingerprint":"021e0c56368d8e67414381546f1ab15f"}�
{"type":"issue","check_name":"cyclomatic-complexity","description":"This method has a cyclomatic complexity of 22, which exceeds the maximum of 20 allowed.","categories":["Complexity"],"location":{"path":"lib/features/lesi_display/presentation/controller/GroupDetailPageViewModel.dart","positions":{"begin":{"line":37,"column":3},"end":{"line":372,"column":4}}},"severity":"info","fingerprint":"22a66ed322d4249f37f1c2e058de89f7"}�
{"type":"issue","check_name":"maximum-nesting-level","description":"This method has a nesting level of 7, which exceeds the maximum of 5 allowed.","categories":["Complexity"],"location":{"path":"lib/features/lesi_display/presentation/controller/GroupDetailPageViewModel.dart","positions":{"begin":{"line":37,"column":3},"end":{"line":372,"column":4}}},"severity":"info","fingerprint":"81532d7118b1de5d9ec56162c76b92ff"}�
{"type":"issue","check_name":"long-method","description":"Long method. This method contains 281 lines with code.","categories":[],"location":{"path":"lib/features/lesi_display/presentation/page/GroupDetailPage.dart","positions":{"begin":{"line":19,"column":3},"end":{"line":316,"column":4}}},"severity":"info","fingerprint":"3e658604a193d549b8f4636920d0fd09"}�
{"type":"issue","check_name":"long-method","description":"Long method. This method contains 616 lines with code.","categories":[],"location":{"path":"lib/features/lesi_display/presentation/page/HistoryPage.dart","positions":{"begin":{"line":20,"column":3},"end":{"line":651,"column":4}}},"severity":"info","fingerprint":"b5d6efa9421e921a976bce60c1001a96"}�
{"type":"issue","check_name":"maximum-nesting-level","description":"This method has a nesting level of 6, which exceeds the maximum of 5 allowed.","categories":["Complexity"],"location":{"path":"lib/features/core/data/repositories/MyFirebase.dart","positions":{"begin":{"line":47,"column":3},"end":{"line":114,"column":4}}},"severity":"info","fingerprint":"3e3dc0388e9170a4ba51ce6810d0519a"}�
{"type":"issue","check_name":"long-method","description":"Long method. This method contains 228 lines with code.","categories":[],"location":{"path":"lib/features/auth/presentation/page/ResetPasswordPage.dart","positions":{"begin":{"line":22,"column":3},"end":{"line":254,"column":4}}},"severity":"info","fingerprint":"389a81c52dc649d2fbff209ae0ed69f2"}�
{"type":"issue","check_name":"long-method","description":"Long method. This method contains 204 lines with code.","categories":[],"location":{"path":"lib/features/auth/presentation/page/SettingPage.dart","positions":{"begin":{"line":17,"column":3},"end":{"line":226,"column":4}}},"severity":"info","fingerprint":"7a79c4556f9fb778c0f34ef46615b55a"}�
{"type":"issue","check_name":"long-method","description":"Long method. This method contains 555 lines with code.","categories":[],"location":{"path":"lib/features/auth/presentation/page/SignUpPage.dart","positions":{"begin":{"line":44,"column":3},"end":{"line":621,"column":4}}},"severity":"info","fingerprint":"5fb25f05e1db240b94c591c353de8517"}�
{"type":"issue","check_name":"long-method","description":"Long method. This method contains 219 lines with code.","categories":[],"location":{"path":"lib/features/auth/presentation/page/ChangePasswordPage.dart","positions":{"begin":{"line":41,"column":3},"end":{"line":265,"column":4}}},"severity":"info","fingerprint":"3ff3509f7a9622a865df4b1c888a5d20"}�
{"type":"issue","check_name":"long-method","description":"Long method. This method contains 352 lines with code.","categories":[],"location":{"path":"lib/features/auth/presentation/page/UserProfilePage.dart","positions":{"begin":{"line":39,"column":3},"end":{"line":392,"column":4}}},"severity":"info","fingerprint":"02fd160a313535cb6575e7d73abb6368"}�
{"type":"issue","check_name":"long-method","description":"Long method. This method contains 225 lines with code.","categories":[],"location":{"path":"lib/features/auth/presentation/page/SignInPage.dart","positions":{"begin":{"line":27,"column":3},"end":{"line":266,"column":4}}},"severity":"info","fingerprint":"0c6e34f7270108f1fb8d9c5ce0ed5cbb"}�
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-03-31 22:55:23

您可以创建一个脚本来读取代码质量报告json文件,并计数出现的问题--当计数超过预期计数时失败作业。

如果每一次进攻都是在一条单独的线上,你甚至可以使用wc来计算行数。

代码语言:javascript
复制
  script:
    - metrics lib -r codeclimate  > gl-code-quality-report.json
    - |
      report_lines="$(wc -l gl-code-quality-report.json | cut -f1 -d" ")"
      if [[ $report_lines -gt 20 ]]; then
          echo "more then 20 issues found"
          exit 1  # fail the job
      fi
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71555127

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档