microsoft / PR-Metrics

A GitHub Action & Azure Pipelines task for augmenting pull request titles to let reviewers quickly determine PR size and test coverage.
https://github.com/microsoft/Omex
MIT License
58 stars 12 forks source link

Cannot read property 'forEach' of null - Azure DevOps error #418

Closed ilanramos closed 1 year ago

ilanramos commented 1 year ago

With everything set up in our Azure DevOps, this error occurred to me: ##[error]Cannot read property 'forEach' of null

Since I tried with several different PRs in different repos, I assumed to be an error with the extension.

Basically how I configured: I adjusted the following template as a Build Validation:

variables:
- name: realBranchName
  value: $[replace(variables['Build.SourceBranch'], 'refs/heads/', '')]

pool:
  vmImage: ubuntu-latest

steps:
- checkout: git://$(System.TeamProject)/$(System.PullRequest.SourceRepositoryURI)@$(realBranchName)
  fetchDepth: 0

- task: PRMetrics@1
  displayName: 'PR Metrics'
  env:
    PR_METRICS_ACCESS_TOKEN: $(System.AccessToken)
  continueOnError: true

Everytime a new PR is started to main branch, this pipeline runs, however, this error always shows up. I have tried changing the PAT to a full permission. Running PR with README and python changes. Commented on some code and nothing seems to solve this error.

The logs:

Logs (at least the relevant part of it) Adjusting the base size input to '200'. Adjusting the growth rate input to '2'. Adjusting the test factor input to '1'. Adjusting the always-close-comment mode input to 'false'. Adjusting the file matching patterns input to '["**/*","!**/package-lock.json"]'. Adjusting the code file extensions input to '["js","_js","bones","cjs","es","es6","frag","gs","jake","jsb","jscad","jsfl","jsm","jss","jsx","mjs","njs","pac","sjs","ssjs","xsjs","xsjslib","epj","erb","py","cgi","fcgi","gyp","gypi","lmi","py3","pyde","pyi","pyp","pyt","pyw","rpy","smk","spec","tac","wsgi","xpy","pyx","pxd","pxi","eb","numpy","numpyw","numsc","pytb","java","jsp","ts","tsx","cs","cake","csx","linq","php","aw","ctp","fcgi","inc","php3","php4","php5","phps","phpt","cpp","c++","cc","cp","cxx","h","h++","hh","hpp","hxx","inc","inl","ino","ipp","re","tcc","tpp","c","cats","h","idc","cl","opencl","upc","xbm","xpm","pm","sh","bash","bats","cgi","command","env","fcgi","ksh","tmux","tool","zsh","fish","ebuild","eclass","ps1","psd1","psm1","tcsh","csh","rb","builder","eye","fcgi","gemspec","god","jbuilder","mspec","pluginspec","podspec","prawn","rabl","rake","rbi","rbuild","rbw","rbx","ru","ruby","spec","thor","watchr"]'. TypeError – stack: "TypeError: Cannot read property 'forEach' of null\n at Function.convertPullRequestComments (/home/vsts/work/_tasks/PRMetrics_28-6b37-4ac7-ac75-9631ee53e512/1.5.6/index.js:26390:87150)\n at AzureReposInvoker._callee2630$ (/home/vsts/work/_tasks/PRMetrics_28-6b37-4ac7-ac75-9631ee53e512/1.5.6/index.js:26390:77772)\n at tryCatch (/home/vsts/work/_tasks/PRMetrics_928-6b37-4ac7-ac75-9631ee53e512/1.5.6/index.js:1:13424)\n at Generator. (/home/vsts/work/_tasks/PRMetrics_28-6b37-4ac7-ac75-9631ee53e512/1.5.6/index.js:1:15967)\n at Generator.next (/home/vsts/work/_tasks/PRMetrics_98-6b37-4ac7-ac75-9631ee53e512/1.5.6/index.js:1:14198)\n at asyncGeneratorStep (/home/vsts/work/_tasks/PRMetrics_28-6b37-4ac7-ac75-9631ee53e512/1.5.6/index.js:1:6068)\n at _next (/home/vsts/work/_tasks/PRMetrics_8-6b37-4ac7-ac75-9631ee53e512/1.5.6/index.js:1:6382)\n at process._tickCallback (internal/process/next_tick.js:68:7)" TypeError – message: "Cannot read property 'forEach' of null" πŸ” debug – * CodeMetricsCalculator.shouldSkip ... πŸ” info – TypeError – stack: "TypeError: Cannot read property 'forEach' of null\n at Function.convertPullRequestComments (/home/vsts/work/_tasks/PRMetrics_907d8-6b37-4ac7-ac75-9631ee53e512/1.5.6/index.js:26390:87150)\n at AzureReposInvoker._callee2630$ (/home/vsts/work/_tasks/PRMetrics_28-6b37-4ac7-ac75-9631ee53e512/1.5.6/index.js:26390:77772)\n at tryCatch (/home/vsts/work/_tasks/PRMetrics_28-6b37-4ac7-ac75-9631ee53e512/1.5.6/index.js:1:13424)\n at Generator. (/home/vsts/work/_tasks/PRMetrics_8-6b37-4ac7-ac75-9631ee53e512/1.5.6/index.js:1:15967)\n at Generator.next (/home/vsts/work/_tasks/PRMetrics_28-6b37-4ac7-ac75-9631ee53e512/1.5.6/index.js:1:14198)\n at asyncGeneratorStep (/home/vsts/work/_tasks/PRMetrics_-6b37-4ac7-ac75-9631ee53e512/1.5.6/index.js:1:6068)\n at _next (/home/vsts/work/_tasks/PRMetrics_6b37-4ac7-ac75-9631ee53e512/1.5.6/index.js:1:6382)\n at process._tickCallback (internal/process/next_tick.js:68:7)" πŸ” info – TypeError – message: "Cannot read property 'forEach' of null" ##[error]Cannot read property 'forEach' of null Finishing: PR Metrics
muiriswoulfe commented 1 year ago

Hi @ilanramos,

Thanks for using PR Metrics. I've never heard or seen this issue before, so there must be something different in your environment causing it.

Unfortunately, the logs you provided aren't sufficient to help me diagnose the issue. The forEach is executed on the result of an API call, and I'd need to see what is returned by this call to determine the underlying cause of the issue. Could you provide all logs, or at least the JSON responses from the API calls? Finding the responses within the logs should be easy, as they are all in the format of JSON payloads and as such all begin with {. I understand that the logs may contain sensitive data, so feel free to redact anything you can't share, but try to avoid changing the format of the JSON payloads.

One other thing I noticed is that according to the logs, you're overriding the file matching patterns parameter. The default value for this should give you what you need without overriding it.

  '**/*',
  '!**/package-lock.json'

I don't believe that the format you're using /* will give you what you want unless you only want to include files in the root folder. If you need to try out some globs, I'd recommend using https://www.digitalocean.com/community/tools/glob.

muiriswoulfe commented 1 year ago

Closing due to inactivity and no other reports.