gh-get-current-pr icon indicating copy to clipboard operation
gh-get-current-pr copied to clipboard

the action doesn't not return data on closed pr

Open whiteRave1234 opened this issue 2 years ago • 5 comments

Subject of the issue

the action doesn't return api data on closed pr event

Your git environment

I have two github jobs one is to get the data using this repo action and one is a job that triggered when a pr is closed

jobs:
  get-pr:
    runs-on: ubuntu-latest
    outputs:
      PR: ${{steps.PR.outputs.pr}}
    steps:
      - name: Find Pull Request
        uses: 8BitJonny/[email protected]
        id: PR
        with:
          sha: ${{ github.event.pull_request.head.sha }}

closed_by_user:
    timeout-minutes: 30
    needs: get-pr
    if:  needs.get-pr.outputs.PR != '' && github.event.pull_request.merged == false && github.event.pull_request.closed
    runs-on: ubuntu-latest
    steps: 
         .....

Steps to reproduce

with the following if condition on the job

needs.get-pr.outputs.PR != '' && github.event.pull_request.merged == false && github.event.pull_request.closed

Expected behaviour

needs.get-pr.outputs.PR return json data , the job will triggered

Actual behaviour

the closed_by_user jobs didn't run because the needs.get-pr.outputs.PR didn't return any json data

when I removed the needs.get-pr.outputs.PR != '' the job is triggered, but got error since I need a data from the API, but the data is empty

whiteRave1234 avatar Oct 13 '22 12:10 whiteRave1234

I had same issue similar like this, waiting for solution regarding this

rhgenius avatar Oct 13 '22 12:10 rhgenius

I'm gonna check it out over this weekend and get back to you 👍🏼

8BitJonny avatar Oct 14 '22 09:10 8BitJonny

yep, can confirm the issue/bug. It's because Github's Api Endpoint completely ignores closed PRs and only cares about merged and open PRs. Will think about possibilities and come back to this issue

8BitJonny avatar Oct 14 '22 10:10 8BitJonny

Still thinking about this one. But yeah, currently I'm leaning towards either just marking this as a limitation in the Readme for now.

This library purely functions and acts on the current commit sha and lets GithubApi do all the heavy lifting, whether we have a PR for that commit or not. And if this library should extend its functionality to also find closed PRs, I currently can't think of a different way other than:

  • fetching all closed PRs for the current Repository (this should be done via Github Api)
  • then fetching all commits for all closed PRs and checking if we find our commit.

This is very much bruteforce and doesn't scale well with old repos (=many PRs) or big PRs(=many commits). There is definitely some optimisations like not looking at all PRs that we're closed before the searched commit was created

But yeah, sadly I'm not able to tell you that this is something that will be resolved soonish

8BitJonny avatar Oct 27 '22 10:10 8BitJonny

Do any of you want to give the implementation a shot? @rhgenius @GagahGK

8BitJonny avatar Oct 27 '22 10:10 8BitJonny