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

Find open PRs on your forks #2268

Closed
fregante opened this issue Jul 24, 2019 · 13 comments · Fixed by #2880
Closed

Find open PRs on your forks #2268

fregante opened this issue Jul 24, 2019 · 13 comments · Fixed by #2880

Comments

@fregante
Copy link
Member

fregante commented Jul 24, 2019

Issuehunt badges

Usually forks are only useful to send PRs. When your open PRs are merged, they should be deleted.

Finding out whether your fork is still needed takes too long (open source repo, go to PRs, look for your PRs).

Refined GitHub should mention your open PRs in:

  • your forked repo's header (perhaps even adding a tab next to the original "Pull requests (0)" tab)
  • In the "Delete repo" lightbox ("you have x PRs open" or "no PRs are open, you can delete it")

Ideally this should check whether there are any branches ahead of source like https://github.com/denis-sokolov/remove-github-forks does, but checking for PRs alone would make this feature a good companion to that CLI tool.


IssueHunt Summary

loilo loilo has been rewarded.

Backers (Total: $5.00)

Submitted pull Requests


Tips


IssueHunt has been backed by the following sponsors. Become a sponsor

@fregante
Copy link
Member Author

fregante commented Aug 5, 2019

Possible starting point: https://stackoverflow.com/a/55125453/288906

@Esemesek
Copy link
Contributor

Esemesek commented Aug 7, 2019

I can take care of it. Already played with GraphQL queries for this and I found a possible solution.

{
  search(query: "repo:sindresorhus/refined-github is:pr is:open author:Esemesek", type: ISSUE, last: 100) {
    edges {
      node {
        ... on PullRequest {
          url
          title
          createdAt
          isCrossRepository
          headRepository {
            owner {
              login
            }
            name
          }
        }
      }
    }
  }
}

With this query, we should be able to find out all the open PRs for a fork.

@fregante
Copy link
Member Author

fregante commented Aug 7, 2019

Sounds good

@issuehunt-oss
Copy link

issuehunt-oss bot commented Nov 3, 2019

@jerone has funded $5.00 to this issue.


@issuehunt-oss issuehunt-oss bot added the 💵 Funded on Issuehunt This issue has been funded on Issuehunt label Nov 3, 2019
@dertieran
Copy link
Contributor

dertieran commented Dec 5, 2019

I think there are two approachs to do this

  1. By checking the PRs of the parent repository
  2. Or by checking the refs/branches of the fork for open PRs

I think this really depends on what this feature should do.
With the second aproach it would be possible to check if there are any open PRs on any repository.

The query for this could look like this:
(Maybe also hoping no one has over 100 branches in their fork 🙈)

{
  repository(name: "refined-github", owner: "busches") {
    refs(refPrefix: "refs/heads/", first: 100) {
      nodes {
        associatedPullRequests(states: OPEN) {
          totalCount
        }
      }
    }
  }
}
Example Response
{
  "data": {
    "repository": {
      "refs": {
        "nodes": [
          {
            "associatedPullRequests": {
              "totalCount": 1
            }
          },
          {
            "associatedPullRequests": {
              "totalCount": 0
            }
          }
        ]
      }
    }
  }
}

If the sum of all associatedPullRequests is greater then zero then this repo should probably not be deleted.
But these PRs could also include open PRs to the fork itself, not sure if that should be handled.

It would also be possible to check for isCrossRepository and get the url of the PR if that is needed.

I already have a working example for this here.

Screenshots

image
image

So I guess it now depends what should be displayed where and if all PRs of the fork count or just cross repository or even only to the parent.

@fregante
Copy link
Member Author

fregante commented Dec 6, 2019

My guess is that associatedPullRequests includes both local and cross-repo PRs, so if if there are 5 local PRs and 2 cross repo, the count returned should be 7. The Pull Request tab would show 5 and we could attach a +2 right next to it.

Additionally we could show “there are X open PRs from this repo” on the deletion page/popup

@dertieran
Copy link
Contributor

dertieran commented Dec 6, 2019

This might require to only count the isCrossRepository PRs, because the PR tab could also contain PRs from other repository (e.g. if the fork got forked again).
Maybe we could also just ignore those edgecases but I just wanted to point that out.

So the query would then be like this:
(I included the PR count of the current repository, we can also just parse the html)

{
  repository(name: "refined-github", owner: "busches") {
    pullRequests(states: OPEN) {
      totalCount
    }
    refs(refPrefix: "refs/heads/", first: 100) {
      nodes {
        associatedPullRequests(states: OPEN, first: 100) {
          nodes {
            isCrossRepository
          }
        }
      }
    }
  }
}

@fregante
Copy link
Member Author

fregante commented Dec 6, 2019

No you don’t need to query it from the API because the number is already in the tab itself, right?

@dertieran
Copy link
Contributor

No you don’t need to query it from the API because the number is already in the tab itself, right?

Yes it wouldn't be needed but it doesn't really complicate the query so I think it wouldn't matter where to get it from.
It might be usfull if we also would like to know how many pullRequests are cross repository.

@loilo
Copy link
Contributor

loilo commented Mar 10, 2020

Wow, I did not find anything about this via search, so I just typed out a whole issue to suggest this feature... but I guess GitHub's "similar issues" feature got the better of me. 😁

I'm not familiar with the v4 API, but I found a very easy v3 request to get the according PRs using the /search/issues endpoint (example for my fork of mautic/mautic):

https://api.github.com/search/issues?q=repo:mautic/mautic+is:pr+is:open+author:loilo


I'd be happy to implement this. The visualization in the header could be like this:

Head area of the loilo/mautic repo with the secondary headline stating "forked from mautic/mautic with 1 open PR" with the "1 open PR" part as a link

What do you think?

@fregante
Copy link
Member Author

fregante commented Mar 10, 2020

It looks great! API v4 should work similarly, the query should be something like, off of my head:

{
  search(query: 'blah blah', type: ISSUE) {
    issueCount
  }
}

You can use GitHub GraphQL Explorer to figure it out. The good part is that the response will literally be 20 bytes of text instead of KBs of useless data that the v3 API returns.

@loilo
Copy link
Contributor

loilo commented Mar 10, 2020

Good point. I'll try to figure it out.

@issuehunt-oss
Copy link

issuehunt-oss bot commented Mar 31, 2020

@sindresorhus has rewarded $4.50 to @loilo. See it on IssueHunt

  • 💰 Total deposit: $5.00
  • 🎉 Repository reward(0%): $0.00
  • 🔧 Service fee(10%): $0.50

@issuehunt-oss issuehunt-oss bot added 🎁 Rewarded on Issuehunt and removed 💵 Funded on Issuehunt This issue has been funded on Issuehunt labels Mar 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

4 participants