Pull Request Analysis Not Detecting New/Changed Code for TypeScript Project

  • SonarQube 10.2.1, Scanner 5.0.1
  • SonarQube zip installation

We are trying to enable Pull Request analysis for a TypeScript/JS project using Bamboo. The main branch analysis works properly, however PR analysis displays No code files were found for analysis.under the Code tab of the PR analysis output. I’ve enable fetching the full repository to avoid shallow clones. I’ve attached the debug logs. You can see the scanner is detecting the new/changed files, but they are not appearing in the analysis in the app.

sonar_debug_logs.txt (180.4 KB)

Cheers,
Brett

Hi Brett,

Welcome to the community!

I see this in your log:

SCM reported changed lines for 0 files in the branch

So, what actually changed in the PR’s underlying branch? Were the changes in code files or in something else (like configuration)?

 
Ann

Ann,

Thank you for your response. I had missed that line in the logs as I was focusing further down where it was reported detected changes

build 24-Jan-2024 14:54:45 14:54:45.223 DEBUG: Cache strategy set to ‘WRITE_ONLY’ for file ‘src/utils/browser.ts’ as the current file is changed
build 24-Jan-2024 14:54:45 14:54:45.223 DEBUG: Analyzing file: file:///mnt/bamboo_home/local-working-dir/113737729/SR-FOUNDATION2-JOB1/src/utils/browser.ts

Do you know the command that is used to determine changed lines in the branch? This PR that we are analyzing has a number of new and changed code files in it.

.playground/app.vue
.playground/pages/_foundation/browser.vue
.playground/public/favicon.ico
.playground/sample/desserts.ts
bamboo-specs/bamboo.yaml
nuxt.config.ts
package.json
pnpm-lock.yaml
src/app.vue
src/components/browser.vue
src/components/browser/actions.vue
src/components/browser/index.vue
src/components/browser/search.vue
src/components/browser/table.vue
src/plugins/vuetify.ts
src/utils/browser.ts
test/app.test.ts
test/components/browser.test.ts
vitest.config.ts

Cheers,
Brett

Hi Brett,

Well, I missed this the first time through:

build	23-Jan-2024 02:05:06	02:05:06.296 INFO: SCM collecting changed files in the branch
build	23-Jan-2024 02:05:06	02:05:06.304 DEBUG: loading config FileBasedConfig[/home/bamboo/.config/jgit/config]
build	23-Jan-2024 02:05:06	02:05:06.304 DEBUG: readpipe [/usr/bin/git, --version],/usr/bin
build	23-Jan-2024 02:05:06	02:05:06.310 DEBUG: readpipe may return 'git version 2.40.1'
build	23-Jan-2024 02:05:06	02:05:06.310 DEBUG: remaining output:
build	23-Jan-2024 02:05:06	
build	23-Jan-2024 02:05:06	02:05:06.310 DEBUG: readpipe [/usr/bin/git, config, --system, --show-origin, --list, -z],/usr/bin
build	23-Jan-2024 02:05:06	02:05:06.311 DEBUG: readpipe may return 'null'
build	23-Jan-2024 02:05:06	02:05:06.311 DEBUG: remaining output:
build	23-Jan-2024 02:05:06	
build	23-Jan-2024 02:05:06	02:05:06.321 DEBUG: readpipe rc=128
build	23-Jan-2024 02:05:06	02:05:06.321 DEBUG: Exception caught during execution of command '[/usr/bin/git, config, --system, --show-origin, --list, -z]' in '/usr/bin', return code '128', error message 'fatal: unable to read config file '/etc/gitconfig': No such file or directory
build	23-Jan-2024 02:05:06	'
build	23-Jan-2024 02:05:06	02:05:06.322 DEBUG: loading config FileBasedConfig[/home/bamboo/.gitconfig]
build	23-Jan-2024 02:05:06	02:05:06.349 INFO: Merge base sha1: c50da478587b2a6a85c93999c453c7d144f835e2
build	23-Jan-2024 02:05:06	02:05:06.359 INFO: SCM collecting changed files in the branch (done) | time=63ms
build	23-Jan-2024 02:05:06	02:05:06.360 DEBUG: SCM reported 0 files changed in the branch

Specifically:

Exception caught during execution of command '[/usr/bin/git, config, --system, --show-origin, --list, -z]' in '/usr/bin', return code '128', error message 'fatal: unable to read config file '/etc/gitconfig': No such file or directory

Can you try setting up /etc/gitconfig and running it again?

 
Ann

Ann,

I’ve fixed the issue with /etc/gitconfig, however I am still seeing 0 files changed

build 24-Jan-2024 16:47:44 16:47:44.650 DEBUG: readpipe [/usr/bin/git, --version],/usr/bin
build 24-Jan-2024 16:47:44 16:47:44.661 DEBUG: readpipe may return ‘git version 2.40.1’
build 24-Jan-2024 16:47:44 16:47:44.661 DEBUG: remaining output:
build 24-Jan-2024 16:47:44
build 24-Jan-2024 16:47:44 16:47:44.661 DEBUG: readpipe [/usr/bin/git, config, --system, --show-origin, --list, -z],/usr/bin
build 24-Jan-2024 16:47:44 16:47:44.662 DEBUG: readpipe may return ‘null’
build 24-Jan-2024 16:47:44 16:47:44.662 DEBUG: remaining output:
build 24-Jan-2024 16:47:44
build 24-Jan-2024 16:47:44 16:47:44.663 DEBUG: loading config FileBasedConfig[/home/bamboo/.gitconfig]
build 24-Jan-2024 16:47:44 16:47:44.692 INFO: Merge base sha1: a456f3050e44663499b137dd53a76231f808da5f
build 24-Jan-2024 16:47:44 16:47:44.703 INFO: SCM collecting changed files in the branch (done)
build 24-Jan-2024 16:47:44 16:47:44.703 DEBUG: SCM reported 0 files changed in the branch

Hi,

Can we get a fresh analysis log?

 
Thx,
Ann

Ann,

Here are the latest debug logs. I’ve added the stats from git diff to the build so we can see what git thinks changed.

sonar_debug_logs.txt (188.6 KB)

Brett

1 Like

Hi Brett,

Since we’re still at

16:55:28.625 DEBUG: SCM reported 0 files changed in the branch

Can you verify the prerequisites are in place:

  • The pull request source branch is checked out in the local repository.
  • The branch being targeted by the pull request is fetched and present in the local repository.
  • The analysis is being run on a local repository with valid repository metadata (e.g. the .git folders have not been removed). Avoid any attempt at previewing the merge or actions involving your main branch.
  • The code in the local repository matches the code in the remote repository (e.g once a PR is issued, no code is added to the local branch on the CI side before analysis).

(Yes, I know we’ve got the git diff origin/main at the top of the log.)

 
Ann

Ann,

  • The pull request source branch is checked out in the local repository.
    Yes, output of git branch --show-current is feature/browser-component
  • The branch being targeted by the pull request is fetched and present in the local repository.
    Yes, main branch is fetched as shown by git diff output
  • The analysis is being run on a local repository with valid repository metadata (e.g. the .git folders have not been removed). Avoid any attempt at previewing the merge or actions involving your main branch.
    Yes
  • The code in the local repository matches the code in the remote repository (e.g once a PR is issued, no code is added to the local branch on the CI side before analysis).
    Yes

Brett

Hi Brett,

Thanks for confirming. I’m at a bit of a loss at this point, so I’ve flagged this for more expert eyes.

 
Ann

Hello @bretta-seerist ,

I’ve noticed that there is a log message about merge base mentioning following commit hash: 04fb861845fbc636bbf9167728dd3ab2bd9b9e2d.

Is this commit coming from Pull Request or from the target branch?

That hash is coming from the PR.

Okay, thanks for the answer.

The diff you have created is done against origin/main, but in fact scanner at first, is trying to execute diff against local ref main , could you execute the same scan, but do a diff against main rather than origin/main?

Something like git diff main instead git diff origin/main

Thank you for all your help. I found the issue and feel very dumb. I had the branch and base values for the PR reversed. Your comment on the merge base was the key. I finally noticed the log message INFO: Pull request 10 for merge into feature/storybook-docs from main.

2 Likes

Nice! Thank you for sharing the solution :slight_smile:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.