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

No Pull Request comment added on push #62

Open
MichaelJHaywood opened this issue Aug 7, 2023 · 6 comments
Open

No Pull Request comment added on push #62

MichaelJHaywood opened this issue Aug 7, 2023 · 6 comments
Assignees
Milestone

Comments

@MichaelJHaywood
Copy link

I've been having trouble trying to get the plugin to add a comment to the PR. I've enabled debug-mode and it successfully finds the Jacoco xml file. It outputs messages about the changes but doesn't mention trying to add a comment. The action is successful.

- name: Publish code coverage results
  id: jacoco
  uses: madrapps/jacoco-report@v1.6.1
  with:
    paths: |
      jacoco/jacocoTestReport.xml
    token: ${{ github.token }}
    min-coverage-overall: 40
    min-coverage-changed-files: 60
    title: Code Coverage
    update-comment: true
    debug-mode: true
    continue-on-error: false

Logs

Run madrapps/jacoco-report@v1.6.1
Event is push
passEmoji: :green_apple:
failEmoji: :x:
base sha: ...
head sha: ...
reportPaths: jacoco/jacocoTestReport.xml
Resolved files: ...
file: {
...
]
project: {
...
}
skip: false
prNumber: undefined

I can successfully add comments myself using a separate github action so I don't believe this is permission related.

Adds a comment successfully

- name: PR Comment Test
  uses: mshick/add-pr-comment@v2
  with:
    message: |
      **Test**

Am I using this incorrectly? Should it fail if it doesn't add a comment?

@MichaelJHaywood MichaelJHaywood changed the title No Pull Request comment added No Pull Request comment added on push Aug 8, 2023
@MichaelJHaywood
Copy link
Author

The problem seems to be here:

action.ts

if (prNumber != null && !skip) {

If the prNumber is undefined we don't add a comment. In the case of a "push" there is no prNumber set.

I've managed to get this working by getting the PR number associated with the commit.

case 'push':
  base = github.context.payload.before
  head = github.context.payload.after

  const prs: any[] = (await client.rest.repos.listPullRequestsAssociatedWithCommit({
    commit_sha: github.context.sha,
    owner: github.context.repo.owner,
    repo: github.context.repo.repo,
  })).data

  if(prs.length > 0){
     prNumber = prs[0].number
  }

  break

Overall this means pushing changes will not update the code coverage comment without this change (or similar).

@patrykosak
Copy link

@thsaravana
Can you reopen issue and apply this fix on master branch?

@thsaravana
Copy link
Member

I am already making some changes in 1.7 in this area. So I will test this as well and will fix this in 1.7 properly.

@thsaravana thsaravana reopened this Dec 26, 2023
@thsaravana thsaravana self-assigned this Dec 26, 2023
@thsaravana thsaravana added this to the 1.7 milestone Dec 26, 2023
@vincent-fuchs
Copy link

isn't the workaround also to trigger the workflow not on push event, but on pull_request opened / reopened / synchronize ? I think a push in a branch for which there's a PR always generates a synchronize. and you would not want the action to run on a push if there's no PR associated to the branch, right ?

@guus-bloemsma
Copy link

isn't the workaround also to trigger the workflow not on push event, but on pull_request opened / reopened / synchronize ? I think a push in a branch for which there's a PR always generates a synchronize. and you would not want the action to run on a push if there's no PR associated to the branch, right ?

The problem with that is that you always want to build and test on push, at least in main. Adding a comment to an associated PR is an optional addition. I wouldn't want to rebuild/retest everything just for the coverage comment.

@sheepdreamofandroids
Copy link

Is there still any progress on this?

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

No branches or pull requests

6 participants