mitchspano / sfdx-scan-pull-request

Runs sfdx-scanner on a pull request and generates in-line comments with the findings.
Apache License 2.0
73 stars 25 forks source link

Findings identified when file name changes can go outside "commentable" scope of the Pull Request #37

Closed mitchspano closed 1 year ago

mitchspano commented 1 year ago

When renaming a file, it is possible for the action to attempt to comment on lines which it rightly identifies as part of the git difference, but are outside of the range of allowed lines for the GitHub REST API to generate a comment for.

In this example, the MyClass.cls file was renamed to SomeClass.cls:

image

The scanner identified a finding which was applicable to the whole class, but the 12th line was not included in the "commentable" lines for GitHub REST API.

Error while uploading comments! RequestError [HttpError]: Validation Failed: {"resource":"PullRequestReviewComment","code":"custom","field":"pull_request_review_thread.line","message":"pull_request_review_thread.line must be part of the diff"}, {"resource":"PullRequestReviewComment","code":"custom","field":"pull_request_review_thread.start_line","message":"pull_request_review_thread.start_line must be part of the same hunk as the line."}, {"resource":"PullRequestReviewComment","code":"missing_field","field":"pull_request_review_thread.diff_hunk"}

 // ...

 request: {
    method: 'POST',
    url: 'https://api.github.com/repos/mitchspano/testActions/pulls/10/comments',
    headers: {
      accept: 'application/vnd.github.v3+json',
      'user-agent': 'octokit-action.js/4.0.4 octokit-core.js/4.0.4 Node.js/16.16.0 (linux; x64)',
      authorization: 'token [REDACTED]',
      'content-type': 'application/json; charset=utf-8'
    },
    body: '{"commit_id":"a5e8db9b9acf40490da7a62077f5650b1304fa72","path":"SomeClass.cls","start_line":1,"start_side":"RIGHT","side":"RIGHT","line":12,"body":"| Engine | Category | Rule | Severity | Type | Message | File |\\n  | --- | --- | --- | --- | --- | --- | --- |\\n| pmd | Best Practices | AvoidGlobalModifier | 3 | Error | [Avoid using global modifier](https://pmd.github.io/pmd-6.54.0/pmd_rules_apex_bestpractices.html#avoidglobalmodifier) | [SomeClass.cls](../tree/a5e8db9b9acf40490da7a62077f5650b1304fa72/SomeClass.cls) |"}',
    request: {
      agent: ProxyAgent { promisifiedCallback: [Function (anonymous)] },
      hook: [Function: bound bound register]
    }
mitchspano commented 1 year ago

This should be resolved with the latest release of 0.1.8 with the improved scope filtering.

The action's output will now also print out the changed lines for each file to help identify issues like this in the future.