Skip to content

Conversation

@loilo
Copy link
Contributor

@loilo loilo commented Mar 11, 2020

This PR adds the new show-open-prs-of-forks feature. It triggers in all your repositories which are forks. Because of the user-centric nature of this feature, I unfortunately can not provide test links.

Repo Headline Hints

This feature adds a hint in the secondary repo headline, linking to your open PRs in the original repo:

Single Pull Request

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

If there is just one open pull request, the link will directly point there (for this screenshot: mautic/mautic#8106).

Multiple Pull Requests

Head area of the loilo/pull-request-target repo with the secondary headline stating "forked from loilo-archive/pull-request-target with 2 open pull requests" with the "2 open pull requests" part as a link

If there are multiple open pull requests, the link will point to a list of them (for this screenshot: loilo-archive/pull-request-target/pulls?q=is:pr+is:open+sort:updated-desc+author:loilo).

Repo Deletion Warnings

The feature also adds a paragraph to the repo deletion dialog, raising your awareness that there are unmerged outgoing PRs from this repo which you will abandon. (I ran a quick test for this — PRs are not actually deleted when the fork is gone, they're just attributed to an "unknown repo", so the warning will be about the loss of write access to the PR.)

Confirmation dialog of repository deletion with added paragraph warning about the open pull requests that will be abandoned when the repo is deleted

Rules for link targets are the same as in the headline hints layed out above.


Closes #2268


IssueHunt Summary

Referenced issues

This pull request has been submitted to:


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

@loilo
Copy link
Contributor Author

loilo commented Mar 13, 2020

I think I've addressed all points from the previous review, except one thing: I could not move the isRepoWithAccess() check outside the function because it always returned false in that case (probably because it relies on a DOM check).

Also, besides the suggested simplification of the findForkedRepo function, I moved it to utils.ts (since it is also used in the forked-to feature) and renamed it to getForkedRepo (to be more in line with naming of other utility functions).

Also, my question about GHE still needs to be sorted out.

@loilo loilo requested a review from fregante March 13, 2020 21:52
@fregante
Copy link
Member

I could not move the isRepoWithAccess() check outside the function

The reason is that you're using nowAndOnAjaxedPages; that only works if you use elementReady somewhere, otherwise it's run too soon.

Since isRepoWithAccess basically just checks for the Settings tab, you could implement that manually, still outside the function, as if(await elementReady('settings tab selector'))

Co-Authored-By: Federico Brigante <github@bfred.it>
@loilo
Copy link
Contributor Author

loilo commented Mar 14, 2020

Sorry, I'm a little bit stumped on your last example. To do that ouside the function, we'd need top-level await (which we don't have, do we?)

Or are you suggesting to put it into a Promise?

const hasSettings = elementReady('settings tab selector');

@fregante
Copy link
Member

It should go inside the init functions

@loilo
Copy link
Contributor Author

loilo commented Mar 14, 2020

Okay, so that's basically how I had it in the first place. I ultimately outsourced all those checks into the getOpenPullRequestsData function purely as a matter of code deduplication (which is also why the function originally did not have any parameters). I can see how the function currently has too many unrelated responsibilities though.

Going to continue working on this tomorrow, it's getting late here and my coding as well as my writing is getting noticeably worse. 😁

@loilo
Copy link
Contributor Author

loilo commented Mar 14, 2020

Okay, I've renamed getOpenPullRequestsData to getRawOpenPullRequestsData which returns Promise<[number, number] | false> to reduce the cache footprint. Init functions still call getOpenPullRequestsData, which is responsible for getting the raw (cached) data and assembles the object structure, including the URL.

- Adds proper support for `nowAndOnAjaxedPages`
- Reduces duplication
@fregante
Copy link
Member

fregante commented Mar 16, 2020

I've renamed getOpenPullRequestsData to getRawOpenPullRequestsData

Good idea! I reorganized the code so "getOpenPullRequestsData" returns the full required data, which is count and url, so they can be used directly without further if/else

I'm resolving the conflicts

Copy link
Member

@fregante fregante left a comment

Choose a reason for hiding this comment

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

🤩

@fregante fregante merged commit 47bae5f into refined-github:master Mar 16, 2020
return {ownerName, repoName};
};

export function getForkedRepo(): string | undefined {
Copy link
Member

@fregante fregante Mar 25, 2020

Choose a reason for hiding this comment

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

This is ambiguous. Is it the repo that was forked or the fork itself?

The correct term would be "source repo". Perhaps getForkSourceRepo would be the correct term.

Can you change this name everywhere? Including const forkedRepo = ... (but not isForkedRepo, that's more clear, I think)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought so as well, but I trusted the existing naming (the function existed before, I just moved it to utils).

Yes, I'll take care of it when I'm going to handle #2934.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, there's already a function with that name in the forked-to feature.

const getForkSourceRepo = (): string => getForkedRepo() ?? getRepoURL();

Copy link
Member

Choose a reason for hiding this comment

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

How about

  • getParentRepo: only works if there’s a parent)
  • getSourceRepo: always gets the source repo, whether it’s the parent or the current

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sound's good to me. I'll do some refactoring of these, but I think I'll open a separate PR for that.

};

export function getForkedRepo(): string | undefined {
return select<HTMLAnchorElement>('.fork-flag a')?.pathname.slice(1);
Copy link
Member

Choose a reason for hiding this comment

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

Also you could use the same meta tags I used in the isForkedRepo since they're available earlier on the page:

<meta name="octolytics-dimension-repository_parent_nwo" content="sindresorhus/refined-github" />
Suggested change
return select<HTMLAnchorElement>('.fork-flag a')?.pathname.slice(1);
return select<HTMLMetaElement>('[name="octolytics-dimension-repository_parent_nwo"]')?.content;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Find open PRs on your forks

4 participants