Skip to content

Add support for Organization Discussions #158

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

Merged
merged 4 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- name: install
run: npm ci || npm install
- name: XO
Expand All @@ -26,9 +23,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- name: install
run: npm ci || npm install
- name: build
Expand Down
17 changes: 14 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export const isOrganizationProfile = (): boolean => exists('meta[name="hovercard

export const isOrganizationRepo = (): boolean => Boolean(document.querySelector<HTMLElement>('[data-owner-scoped-search-url]')?.dataset['ownerScopedSearchUrl']!.startsWith('/org'));

export const isTeamDiscussion = (url: URL | HTMLAnchorElement | Location = location): boolean => /^orgs\/[^/]+\/teams\/[^/]+($|\/discussions)/.test(getCleanPathname(url));
export const isTeamDiscussion = (url: URL | HTMLAnchorElement | Location = location): boolean => Boolean(getOrg(url)?.path.startsWith('teams'));
addTests('isTeamDiscussion', [
'https://github.com/orgs/refined-github/teams/core-team/discussions?pinned=1',
'https://github.com/orgs/refined-github/teams/core-team/discussions/1',
Expand All @@ -207,14 +207,16 @@ addTests('isProjects', [
'https://github.com/sindresorhus/refined-github/projects',
]);

export const isDiscussion = (url: URL | HTMLAnchorElement | Location = location): boolean => /^discussions\/\d+/.test(getRepo(url)?.path!);
export const isDiscussion = (url: URL | HTMLAnchorElement | Location = location): boolean => /^discussions\/\d+/.test(getRepo(url)?.path ?? getOrg(url)?.path!);
addTests('isDiscussion', [
'https://github.com/tophf/mpiv/discussions/50',
'https://github.com/orgs/community/discussions/11202',
]);

export const isDiscussionList = (url: URL | HTMLAnchorElement | Location = location): boolean => getRepo(url)?.path === 'discussions';
export const isDiscussionList = (url: URL | HTMLAnchorElement | Location = location): boolean => getRepo(url)?.path === 'discussions' || getOrg(url)?.path === 'discussions';
addTests('isDiscussionList', [
'https://github.com/tophf/mpiv/discussions',
'https://github.com/orgs/community/discussions',
]);

export const isPR = (url: URL | HTMLAnchorElement | Location = location): boolean => /^pull\/\d+/.test(getRepo(url)?.path!) && !isPRConflicts(url);
Expand Down Expand Up @@ -728,6 +730,15 @@ const getCleanGistPathname = (url: URL | HTMLAnchorElement | Location = location
return gist === 'gist' ? parts.join('/') : undefined;
};

const getOrg = (url: URL | HTMLAnchorElement | Location = location): {name: string; path: string} | undefined => {
const [, orgs, name, ...path] = url.pathname.split('/');
if (orgs === 'orgs' && name) {
return {name, path: path.join('/')};
}

return undefined;
};

export type RepositoryInfo = {
owner: string;
name: string;
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "github-url-detection",
"version": "7.0.0",
"version": "7.0.1-0",
"description": "Which GitHub page are you on? Is it an issue? Is it a list? Perfect for your WebExtension or userscript.",
"keywords": [
"github",
Expand Down