Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug-fix: attempting to update review comment from issue branch, path mismatch #48

Open
wants to merge 35 commits into
base: main
Choose a base branch
from

Conversation

adrian-kong
Copy link

@adrian-kong adrian-kong commented Sep 28, 2023

There seems to be a call to update a review comment under the issue comment branch which leads to issue #47

This also patches path mismatches where coverity results json outputs

             /__w/repo/src/...
/home/runner/work/repo/

cannot substring using github workspace as shown above,
we want to return src/ here.

This PR has been packaged and tested.

@adrian-kong
Copy link
Author

adrian-kong commented Sep 28, 2023

npm install could not run due to internal artifactory,
package-lock.json was regenerated with the same versions though

the changes in dist/ might be incorrect

@adrian-kong adrian-kong changed the title Bug-fix: attempting to update review comment from issue branch Bug-fix: attempting to update review comment from issue branch, path mismatch Sep 28, 2023
@@ -105,7 +105,7 @@ async function run(): Promise<void> {
for (const comment of actionIssueComments) {
if (comment.body !== undefined && isPresent(comment.body)) {
info(`Comment ${comment.id} represents a Coverity issue which is no longer present, updating comment to reflect resolution.`)
updateExistingReviewComment(comment.id, createNoLongerPresentMessage(comment.body))
updateExistingIssueComment(comment.id, createNoLongerPresentMessage(comment.body))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

main bug causing http error, attempting to call update review under issue branch

@@ -128,7 +128,7 @@ async function run(): Promise<void> {
}

function isInDiff(issue: IssueOccurrence, diffMap: DiffMap): boolean {
const diffHunks = diffMap.get(issue.mainEventFilePathname)
const diffHunks = diffMap.get(relativizePath(issue.mainEventFilePathname))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this also needs to be normalized otherwise they won't match

Comment on lines +67 to +76
function zTable(input: string) {
let table = new Array<number>(input.length).fill(0)
for (let i = 1; i < input.length; i++) {
for (let j = 0; j < input.length - i; j ++) {
if (input.charAt(j) != input.charAt(i + j)) continue
table[i]++
}
}
return table
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be optimized by terminating early but not really necessary since path are tiny

Comment on lines +85 to +89
// this should give `diff --git a/path b/path`
// to get the file itself, we can use longest string match on `path b/path`
// since we definitely know paths are equal, path must be the longest string
path = line.substring("diff --git a/".length)
path = path.substring(0, Math.max(...zTable(path)))
Copy link
Author

@adrian-kong adrian-kong Sep 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

basically doing a naive longest string match with prefix here to find the path without splitting

Comment on lines +36 to +39
let length = (process.env.GITHUB_WORKSPACE ?? "undefined").length
// if workspace is /__w, replace as /home/runner/work
if (path.startsWith("/__w")) {
path = "/home/runner/work" + path.substring("/__w".length)
Copy link
Author

@adrian-kong adrian-kong Sep 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

json outputs

      "mainEventFilePathname" : "/__w/starling-core/starling-core/public_types/src/external_functions.cc",

with /__w prefix, due to running in docker.
this doesn't fix general case but patches at the moment.
this needs to be raised as issue #49

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant