Skip to content

Display PRs from upstream repository in forks - #9340

Merged
rafeca merged 11 commits into
developmentfrom
feature/show-prs-on-upstream
Apr 3, 2020
Merged

rafeca merged 11 commits into
developmentfrom
feature/show-prs-on-upstream

Conversation

@rafeca

@rafeca rafeca commented Mar 23, 2020

Copy link
Copy Markdown
Contributor

Closes #6383

Description

This PR changes the filtering logic of the PRs list to display the pull requests made on the upstream repository when the current repository is a fork.

As part of this PR, I've removed the logic that adds a link to the list of PRs on the upstream repository when there are no PRs (which was added in #8965). Now, the logic is not needed since the shown PRs are the ones in the upstream repository already.

Instead of removing that logic, we can also change it to show a link to the PRs page of the forked repository, but I feel that this would create more confusion than help users (since the most normal use case is to have PRs on the upstream repo).

Screenshots

Screenshot 2020-03-23 at 14 05 47

Test plan

On a forked repository:

  • The PRs from the upstream repository should be shown.
  • An empty screen should be shown when there are no PRs on the upstream repository.
  • All repository names on the PRs screens should mention the upstream repository.

On a non-forked repository:

  • The PRs from the origin repository should be shown.
  • An empty screen should be shown when there are no PRs on the origin repository.
  • All repository names on the PRs screens should mention the origin repository.

Release notes

Notes: [Improved] Show the list of pull requests from the upstream repository on forks

@rafeca
rafeca requested review from ampinsk and outofambit March 23, 2020 13:11
@rafeca

rafeca commented Mar 23, 2020

Copy link
Copy Markdown
Contributor Author

@ampinsk any feedback on the sizing of the PR list header?

Screenshot 2020-03-23 at 14 12 16

A couple of considerations:

  • It currently uses the same font size/margins as the branch list headers:
    Screenshot 2020-03-23 at 14 14 07
  • Because of the scrolling logic of filtered lists, the header must have the same height as each of the items on the list (not sure if this can be changed though).

Things I think we could do:

  • Make the header font slightly larger.
  • Move the header text a bit down (keeping the height of the header), so the space between the header and the first item gets reduced.

@ampinsk

ampinsk commented Mar 23, 2020

Copy link
Copy Markdown
Contributor

@ampinsk any feedback on the sizing of the PR list header?

Thanks for the ping @rafeca! I actually think this looks totally fine as is 👍 I think the spacing makes sense in context, and if the header was any bigger it'd probably draw too much attention.

@tierninho
tierninho self-requested a review March 23, 2020 21:02

@tierninho tierninho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The functionality works well, but I spotted a bug. Anytime you create/close a PR from the forked repo, the PR list in Desktop toggles between these two views:

Reproduce:

  • View all PRs in a forked repo on Desktop (first pic)
  • Create/close a PR from on the forked repo on Github.com
  • Click the PR load button in the PR list in Desktop
  • PR list shows no pull requests (second pic)

Screen Shot 2020-03-23 at 10 57 07 AM
Screen Shot 2020-03-23 at 11 00 03 AM

While doing above, I noticed some weird submodule and object errors, which I suspect has to do with a PR that shouldn't be there. PR #4is missing from Github.com but is present in the list :
Screen Shot 2020-03-23 at 10 56 50 AM
Screen Shot 2020-03-23 at 11 11 27 AM
Screen Shot 2020-03-23 at 11 11 40 AM

Also, just to be clear, for any forked repo on Desktop, we are only going to surface PRs from the upstream repo? No PRs will be shown in only on the forked repo on Github.com?

@rafeca

rafeca commented Mar 24, 2020

Copy link
Copy Markdown
Contributor Author

The functionality works well, but I spotted a bug. Anytime you create/close a PR from the forked repo, the PR list in Desktop toggles between these two views:

Thanks for reporting!! I've been able to reproduce and looking into it!

Also, just to be clear, for any forked repo on Desktop, we are only going to surface PRs from the upstream repo? No PRs will be shown in only on the forked repo on Github.com?

Exactly. This makes me think about what happens when the user doesn't have the parent repo as an upstream remote on their working copy, gonna test that scenario!

@rafeca

rafeca commented Mar 24, 2020

Copy link
Copy Markdown
Contributor Author

The functionality works well, but I spotted a bug. Anytime you create/close a PR from the forked repo, the PR list in Desktop toggles between these two views:

After some investigation, it looks like this was an existing issue, which before this PR used to happen in the opposite way: when a PR was created/closed/updated on the upstream repository, the list of PRs went blank.

I'm looking into the logic that updates the list of PRs to find where the issue comes from.

@rafeca
rafeca force-pushed the feature/show-prs-on-upstream branch from 567cc82 to f8f54b5 Compare March 24, 2020 15:25
@rafeca

rafeca commented Mar 24, 2020 •

Copy link
Copy Markdown
Contributor Author

@tierninho I've fixed the issue that you found in 32a4222 ! That was a really good catch!!

@rafeca
rafeca force-pushed the feature/show-prs-on-upstream branch from f8f54b5 to 32a4222 Compare March 24, 2020 16:52
@rafeca

rafeca commented Mar 24, 2020

Copy link
Copy Markdown
Contributor Author

In 6760ddc I've changed a bit the logic to fetch PRs to only fetch the pull requests from the upstream repository when working on a fork.

I found that by fetching both the upstream and origin PRs but only showing the upstream ones some issues caused some issues on the logic that tries to find the correspondant PR of a branch (if for some reason the same branch was used for both a PR on the upstream and on the fork repo the Ui went a bit nuts).

Also, with this change we're fetching a bit less data.

@outofambit outofambit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

overall, this looks great! @rafeca and i are going to talk through the implications of the refactor in pull-request-coordinator tomorrow to make sure we don't regress anything tangentially related elsewhere in the app, but i think it is likely a great solution.

@outofambit outofambit self-assigned this Mar 24, 2020
@tierninho

Copy link
Copy Markdown
Contributor

I've fixed the issue that you found in 32a4222 ! That was a really good catch!!

Bug fix looks good ✅

tomorrow to make sure we don't regress anything tangentially related elsewhere in the app, but i think it is likely a great solution.

Let me know if there are any vulnerable areas that may need testing post the meeting, as I'd be happy to explore more.

@tierninho

tierninho commented Mar 25, 2020 •

Copy link
Copy Markdown
Contributor

One minor issue that may be present in a small subset of users. It looks like we center the text if the repo name is too long. Should we wrap or truncate it?

Almost too long:
Screen Shot 2020-03-24 at 12 22 21 PM

Too long:
Screen Shot 2020-03-24 at 12 21 25 PM

@rafeca

rafeca commented Mar 25, 2020

Copy link
Copy Markdown
Contributor Author

One minor issue that may be present in a small subset of users. It looks like we center the text if the repo name is too long. Should we wrap or truncate it?

Good point! gonna check how do we do it in other places and follow the same pattern

@rafeca

rafeca commented Mar 25, 2020

Copy link
Copy Markdown
Contributor Author

One minor issue that may be present in a small subset of users. It looks like we center the text if the repo name is too long. Should we wrap or truncate it?

I've seen that usually we truncate branch/repository names with ellipsis so I did the same in the latest commit:

Screenshot 2020-03-25 at 14 42 25

@rafeca

rafeca commented Mar 25, 2020

Copy link
Copy Markdown
Contributor Author

Let me know if there are any vulnerable areas that may need testing post the meeting, as I'd be happy to explore more.

I've synced with @outofambit and she mentioned two areas of potential issues:

  1. The integration with the "open this in GitHub Desktop" link on dotcom for PRs.
  2. The logic that prompts the user to create a PR on the "No local changes screen".

I've been able to find one issue (actually it's a discrepancy) between the behaviour of "open this in GitHub Desktop" button and clicking on a PR from the PRs list in desktop:

When opening a PR created to the upstream repository from a branch that also lives on the upstream repository, the behaviour is different between the two:

  • The dotcom integration creates a local branch with the same name as the original PR branch that's tracking the original branch on the upstream remote.
  • The PR list functionality creates a local branch called pr/<num_pr> that tracks the original branch in a newly created remote that points to upstream.

So after using the "open this in GitHub Desktop" button and clicking on the same PR from the PRs list on Desktop, we end up with the following local branches on git:

$ git branch -vv
  pr/1             774a131 [github-desktop-rafeca/rafeca-patch-1] assaas
  rafeca-patch-1   774a131 [upstream/rafeca-patch-1] assaas
$ git remote -v
github-desktop-rafeca	https://github.com/rafeca/test-forks.git (fetch)
github-desktop-rafeca	https://github.com/rafeca/test-forks.git (push)
origin	                https://github.com/rafeca-fork/test-forks.git (fetch)
origin	                https://github.com/rafeca-fork/test-forks.git (push)
upstream	        https://github.com/rafeca/test-forks.git (fetch)
upstream        	https://github.com/rafeca/test-forks.git (push)

Based on this, I think that the behaviour of the "open this in GitHub Desktop" integration is the correct one (we don't need to duplicate the upstream remote), so I'm going to try to change the logic of the PRs list to match it.

@rafeca

rafeca commented Mar 25, 2020

Copy link
Copy Markdown
Contributor Author

I've been able to fix the issue described in #9340 (comment) via 0a33f90

Now the behaviour between the dotcom integration and the PRs list is consistent.

Before:

before

After:

after

@tierninho

Copy link
Copy Markdown
Contributor

@rafeca For above, possible to share the reproduction steps? I ran into a fast-forward error (I think its an existing issue) and I wanted to make sure I was testing the steps in the right way.

Screen Shot 2020-03-25 at 2 41 01 PM

Note there was some recent PR work done in this area, see here: #9138 I do not believe we have released it yet.

@rafeca

rafeca commented Mar 26, 2020

Copy link
Copy Markdown
Contributor Author

@rafeca For above, possible to share the reproduction steps? I ran into a fast-forward error (I think its an existing issue) and I wanted to make sure I was testing the steps in the right way.

I've used the following setup with a repository and two forks, where there are 3 PRs, each of these based on a branch from each of the repositories:

excalidraw-2020326142448 (1)

Then I add one of the forked repositories to GitHub Desktop and do the following actions for each of the PRs:

  1. Click on the "open this in GitHub Desktop" link from dotcom.
  2. Click on the PR from the lists of PRs inside GitHub Desktop.

I expect both actions to do exactly the same, no matter which of these gets done first.

The expected result is to checkout the branch from either the origin or upstream repository (in the case of PR #1 and PR #2) or add the remote, fetch it and checkout the branch (in the case of PR #3). Does this makes sense to you?

I ran into a fast-forward error (I think its an existing issue) and I wanted to make sure I was testing the steps in the right way.

Do you remember under which conditions this happened? I haven't run into this yet

@tierninho

tierninho commented Mar 26, 2020 •

Copy link
Copy Markdown
Contributor

Do you remember under which conditions this happened? I haven't run into this yet

Yes, this occurred when I clicked the Open in Desktop link from a PR in the forked repo. The PR wanted to merge commits into master (fork) from branchX (upstream). See here: kuychaco/urban-potato#3. Upon clicking the link, Desktop opened the PR in the forked repo, and the error was surfaced. Note: The branch was not published. Also, make sure you are on the master branch in Desktop before clicking the link.)

Based on the steps you outlined above, I will recreate the entire setup from scratch and retest.

@tierninho

Copy link
Copy Markdown
Contributor

I expect both actions to do exactly the same, no matter which of these gets done first.

Confirming the steps you outlined above result in the expected actions. The "open this in GitHub Desktop" link and the clicking on the PR from inside GitHub Desktop led to the same result. ✅

@rafeca

rafeca commented Mar 27, 2020

Copy link
Copy Markdown
Contributor Author

Yes, this occurred when I clicked the Open in Desktop link from a PR in the forked repo. The PR wanted to merge commits into master (fork) from branchX (upstream). See here: kuychaco/urban-potato#3. Upon clicking the link, Desktop opened the PR in the forked repo, and the error was surfaced. Note: The branch was not published. Also, make sure you are on the master branch in Desktop before clicking the link.)

I think I know what happened here: local branches for PRs that are started on forks are named pr/<number_pr> (e.g pr/4). If there are PRs on both the fork and the upstream repository and you try to checkout the same PR number from both repositories, the second one will give an error.

This happens with kuychaco/urban-potato#3 and not-kuychaco/urban-potato#3 . If you try to checkout both of these PRs from dotcom you'll probably get an error for the second one (I guess this even happens in production).

Right now this kind of problems are a little bit hard to fix, since the logic to checkout a PR is duplicated (the logic for checking out a PR internally is not the same as the one used by the interceptor in dotcom).

I can try to unify this logic so it's going to be easier to make fixes (plus the functionality will be uniform between both).

@outofambit outofambit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is great @rafeca! left a couple notes and questions inline but i don't think any of them are too major.

Comment on lines +318 to +285
const matches = new Array<RepositoryWithGitHubRepository>(),
forks = new Array<RepositoryWithGitHubRepository>()
const matches = new Array<RepositoryWithGitHubRepository>()

for (const r of repositories) {
if (r.gitHubRepository.dbID === dbID) {
matches.push(r)
} else if (
r.gitHubRepository.parent !== null &&
r.gitHubRepository.parent.dbID === dbID
) {
forks.push(r)
matches.push(r)
}
}

return { matches, forks }
return matches

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i think this can compacted down now to

return repositories.filter(r => r.gitHubRepository.dbID === dbID)

since we are using getNonForkGitHubRepository(), i think we no longer want to match the GitHubRepository and its parent, which could introduce strange behavior if a fork of a fork (a grand-fork, if you will) ends up in this code path. does that sound right? i think getNonForkGitHubRepository() means we don't have to worry about multiple GitHubRepositories here anymore.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh yes! good point!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've thought a bit about this and indeed I think that the current code will cause issues with grandforks, but I think that it should be changed to:

return repositories.filter(
  repository => getNonForkGitHubRepository(repository).dbID === dbID
)

The reasoning is that this method is used to map GitHubRepository object to any Repository

used to calculate which Repository objects need to be updated after receiving an updated list of PRs. Since we fetch the list of PRs of a Repository by getting its GitHubRepository via getNonForkGitHubRepository(), we need to use the same method when trying to map back a GitHubRepository to the potential list of Repository objects. Does this make sense?


However, this raises a different question about which PRs to show when opening a grandfork. Currently if we have a repo, a fork and a grandfork, when opening grandfork on Desktop the PRs from fork will be shown.

I feel that it would make more sense to show the PRs from repo, but I don't have strong opinions about it. @billygriffin do you have any thoughts about this? (if we decide to change this we can do it in a separate PR).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

used to calculate which Repository objects need to be updated after receiving an updated list of PRs. Since we fetch the list of PRs of a Repository by getting its GitHubRepository via getNonForkGitHubRepository(), we need to use the same method when trying to map back a GitHubRepository to the potential list of Repository objects. Does this make sense?

@rafeca oh yes, great point! i agree that this is the right solution for this method

return repositories.filter(
  repository => getNonForkGitHubRepository(repository).dbID === dbID
)

thus far, we've explicitly tried to avoid allowing any repo to cause parent traversals more than one level (ie no repo should never have info/data from a repo that is a grandparent or higher), but also i don't think grandforks are a common enough use case to worry about beyond "will the app crash?". this logic maintains that line which i think is enough for now, but happy to reconsider more if you or @billygriffin have more thoughts!

Comment thread app/src/models/repository.ts Resolved
Comment thread app/src/lib/stores/app-store.ts Resolved
@rafeca
rafeca force-pushed the feature/show-prs-on-upstream branch from c04d94e to b964a3b Compare April 2, 2020 12:31
@rafeca
rafeca requested a review from outofambit April 2, 2020 12:32
@rafeca

rafeca commented Apr 2, 2020

Copy link
Copy Markdown
Contributor Author

I've just moved 6b1d68d to #9382 .

This PR now is only focused on displaying the PRs from upstream repositories when working on forks.

Anything to do with the consistency between checking out a PR in dotcom and in Desktop is fixed by #9382.

@billygriffin

Copy link
Copy Markdown
Contributor

Thanks for the questions @rafeca! I don't think my comment here changes anything on this PR, but I just wanted to summarize the conversation I had with @outofambit about this for posterity in case we're revisiting this in the future or trying to understand it better.

Our assumption is that if you're on a fork, we only care about the parent of the fork - so we only go one level up, and never traverse through multiple forks. If your fork's parent repo also happens to be a fork, that's irrelevant to how things work for you in Desktop.

@outofambit outofambit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎉

@rafeca

rafeca commented Apr 3, 2020

Copy link
Copy Markdown
Contributor Author

Thanks everyone for your comments! Gonna merge this one! 😃

@rafeca
rafeca merged commit 370ffa0 into development Apr 3, 2020
@outofambit
outofambit deleted the feature/show-prs-on-upstream branch April 3, 2020 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

display PRs from upstream repository in your fork

5 participants