SonarSource-Demos / sonar-golc

GoLC counts physical lines of source code in numerous programming languages supported by the Developer, Enterprise, and Data Center editions of SonarQube across your Bitbucket Cloud, Bitbucket Data Center, GitHub, GitLab, and Azure DevOps repositories.
MIT License
4 stars 0 forks source link

getCommitDetails problem on Azure #6

Open sylvain-combe-sonarsource opened 1 week ago

sylvain-combe-sonarsource commented 1 week ago

For some projects the handleNonDefaultBranch method of the getazure package will fail. This part of the code is responsible:

    branches, err := gitClient.GetBranches(ctx, git.GetBranchesArgs{
        RepositoryId: &repoID,
        Project:      &projectID,
    })
    if err != nil {
        return "", 0, 0, err
    }

An error there breaks the entire script, it should be handled gracefully.

pstember commented 4 days ago

Can you try with the version on this branch? I have added an error log to get more insights.

    branches, err := gitClient.GetBranches(ctx, git.GetBranchesArgs{
        RepositoryId: &repoID,
        Project:      &projectID,
    })
    if err != nil {
        loggers.Errorf("Error get GetBranches for repository and branch %s - %s: %v", repoID, defaultBranch, err)
        return "", 0, 0, err
    }

Once we understand the problem and where to gracefully handle it, we will still need a fix.

We could also add a trace log before each function is called, to have the full path followed by the code. This would take more time but can be done if needed, from there, it should be easy to handle the error

sylvain-combe-sonarsource commented 1 day ago

image

I believe there is no point logging the dafultBranch parameter in the handleNonDefaultBranch method.

Your comment's code (I don't see your commit) does not handle errors more gracefully than the existing code.