Skip to content

Commit 2bab6f7

Browse files
authored
Add support for Organization Discussions (#158)
1 parent dab74f6 commit 2bab6f7

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- uses: actions/checkout@v3
17-
- uses: actions/setup-node@v3
18-
with:
19-
node-version: 18
2017
- name: install
2118
run: npm ci || npm install
2219
- name: XO
@@ -26,9 +23,6 @@ jobs:
2623
runs-on: ubuntu-latest
2724
steps:
2825
- uses: actions/checkout@v3
29-
- uses: actions/setup-node@v3
30-
with:
31-
node-version: 18
3226
- name: install
3327
run: npm ci || npm install
3428
- name: build

index.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export const isOrganizationProfile = (): boolean => exists('meta[name="hovercard
185185

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

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

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

215-
export const isDiscussionList = (url: URL | HTMLAnchorElement | Location = location): boolean => getRepo(url)?.path === 'discussions';
216+
export const isDiscussionList = (url: URL | HTMLAnchorElement | Location = location): boolean => getRepo(url)?.path === 'discussions' || getOrg(url)?.path === 'discussions';
216217
addTests('isDiscussionList', [
217218
'https://github.com/tophf/mpiv/discussions',
219+
'https://github.com/orgs/community/discussions',
218220
]);
219221

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

733+
const getOrg = (url: URL | HTMLAnchorElement | Location = location): {name: string; path: string} | undefined => {
734+
const [, orgs, name, ...path] = url.pathname.split('/');
735+
if (orgs === 'orgs' && name) {
736+
return {name, path: path.join('/')};
737+
}
738+
739+
return undefined;
740+
};
741+
731742
export type RepositoryInfo = {
732743
owner: string;
733744
name: string;

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "github-url-detection",
3-
"version": "7.0.0",
3+
"version": "7.0.1-0",
44
"description": "Which GitHub page are you on? Is it an issue? Is it a list? Perfect for your WebExtension or userscript.",
55
"keywords": [
66
"github",

0 commit comments

Comments
 (0)