-
Notifications
You must be signed in to change notification settings - Fork 285
feat: multi-forge support — adapter pattern + Gitea #2842
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
Open
afonsojramos
wants to merge
26
commits into
main
Choose a base branch
from
multi-platform-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
20ce142
docs(contributing): replace github-only stance with multi-forge policy
afonsojramos 8ab2764
feat(types): add Forge type and required Account.forge field with mig…
afonsojramos a43767b
feat(forges): add ForgeAdapter interface, registry, and GitHub adapter
afonsojramos 2078d85
refactor(forges): route notifications, features, and auth through ada…
afonsojramos 9e56554
test(notifications): expect mark-as-done to fall back to mark-as-read…
afonsojramos c1b68fa
refactor(login): route PAT login through forge adapter
afonsojramos 188c023
refactor(login): render login methods from forge adapter registry
afonsojramos 6ddac7c
feat(forges/gitea): add Gitea adapter and login flow
afonsojramos 8834c83
refactor(links): route developer settings URL through forge adapter
afonsojramos 7591e7b
fix(forges): preserve refresh response shape and limit gitea scope sh…
afonsojramos e4ef3ed
refactor(forges/github): relocate GitHub modules into forges/github
afonsojramos ebad481
fix(forges/github): point graphql codegen output and import paths at …
afonsojramos db282cc
fix(auth): coerce missing enterprise version header to null
afonsojramos 29a6c5e
test(settings): drop obsolete snapshot for go-back test
afonsojramos 05ebcae
test(forges): cover registry dispatch and unknown-forge errors
afonsojramos f52c75c
test(forges/gitea): cover client request paths and pagination
afonsojramos f7668b1
test(forges/gitea): cover adapter dispatch and capabilities
afonsojramos eac24ad
test(forges/github): cover adapter dispatch and login fields
afonsojramos f032863
test(forges/github): cover raw notification transform
afonsojramos 4d9e45f
style(forges): apply biome formatter to new test files
afonsojramos ff936a5
fix(test): widen latest_comment_url cast to allow null in transform test
afonsojramos ba011e6
chore(codeowners): route forge adapters to their maintainers
afonsojramos dda29d1
docs(readme): add forge adapter support matrix
afonsojramos 36fdcf7
docs(readme): document forge status symbols (experimental, in progress)
afonsojramos 9a654d7
docs(readme): drop Bitbucket Data Center from forge matrix (EOL)
afonsojramos 2e1d93f
refactor(forges): move OAuth scope checks onto the adapter
afonsojramos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,5 @@ | ||
| * @afonsojramos @bmulholland @setchy | ||
|
|
||
| # Forge adapters — see MAINTAINERS.md | ||
| /src/renderer/utils/forges/github/ @afonsojramos @setchy | ||
| /src/renderer/utils/forges/gitea/ @afonsojramos @bircni |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # Maintainers | ||
|
setchy marked this conversation as resolved.
|
||
|
|
||
| Gitify is maintained by a small team. Each forge adapter has at least one designated maintainer responsible for triage, review, and CI for that adapter. | ||
|
|
||
| ## Core maintainers | ||
|
|
||
| - [@setchy](https://github.com/setchy) | ||
| - [@afonsojramos](https://github.com/afonsojramos) | ||
|
|
||
| ## Forge adapter maintainers | ||
|
|
||
| | Forge | Maintainer | Source | | ||
| | ------ | --------------------------------------------------- | --------------------------------------- | | ||
| | GitHub | [@setchy](https://github.com/setchy), [@afonsojramos](https://github.com/afonsojramos) | `src/renderer/utils/forges/github/` | | ||
| | Gitea | [@bircni](https://github.com/bircni), [@afonsojramos](https://github.com/afonsojramos) | `src/renderer/utils/forges/gitea/` | | ||
|
|
||
| ## Adding a new forge | ||
|
|
||
| See [`CONTRIBUTING.md`](./CONTRIBUTING.md#multi-forge-support) for the policy. In short: | ||
|
|
||
| 1. Open an issue proposing the forge and volunteering as its maintainer. | ||
| 2. Implement the forge behind the `ForgeAdapter` interface in `src/renderer/utils/forges/<forge-id>/`. | ||
| 3. Register the adapter in `src/renderer/utils/forges/registry.ts`. | ||
| 4. Add yourself to the table above and to `CODEOWNERS` for the adapter directory. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ import type { | |
| Account, | ||
| AccountNotifications, | ||
| AuthState, | ||
| Forge, | ||
| GitifyError, | ||
| GitifyNotification, | ||
| Hostname, | ||
|
|
@@ -36,8 +37,6 @@ import type { | |
| LoginPersonalAccessTokenOptions, | ||
| } from '../utils/auth/types'; | ||
|
|
||
| import { fetchAuthenticatedUserDetails } from '../utils/api/client'; | ||
| import { clearOctokitClientCache } from '../utils/api/octokit'; | ||
| import { | ||
| exchangeAuthCodeForAccessToken, | ||
| performGitHubWebOAuth, | ||
|
|
@@ -52,6 +51,8 @@ import { | |
| removeAccount, | ||
| } from '../utils/auth/utils'; | ||
| import { clearState, loadState, saveState } from '../utils/core/storage'; | ||
| import { clearOctokitClientCache } from '../utils/forges/github/octokit'; | ||
| import { getAdapterById } from '../utils/forges/registry'; | ||
| import { | ||
| applyKeyboardShortcut, | ||
| decryptValue, | ||
|
|
@@ -72,6 +73,17 @@ import { | |
| import { zoomLevelToPercentage, zoomPercentageToLevel } from '../utils/ui/zoom'; | ||
| import { defaultAuth, defaultSettings } from './defaults'; | ||
|
|
||
| /** | ||
| * Backfill the `forge` field on accounts persisted before multi-forge support. | ||
| * Legacy accounts default to GitHub. | ||
| */ | ||
| function migrateLegacyAuthState(auth: AuthState): AuthState { | ||
| return { | ||
| ...auth, | ||
| accounts: auth.accounts.map((a) => ({ ...a, forge: a.forge ?? 'github' })), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ?? only covers undefined/null. A persisted account with forge: '' or forge: 'GitHub' (case mismatch) will pass through |
||
| }; | ||
| } | ||
|
|
||
| export interface AppContextState { | ||
| auth: AuthState; | ||
| isLoggedIn: boolean; | ||
|
|
@@ -130,7 +142,7 @@ export const AppProvider = ({ children }: { children: ReactNode }) => { | |
|
|
||
| const [auth, setAuth] = useState<AuthState>( | ||
| existingState.auth | ||
| ? { ...defaultAuth, ...existingState.auth } | ||
| ? migrateLegacyAuthState({ ...defaultAuth, ...existingState.auth }) | ||
| : defaultAuth, | ||
| ); | ||
|
|
||
|
|
@@ -470,7 +482,13 @@ export const AppProvider = ({ children }: { children: ReactNode }) => { | |
| await removeAccountNotifications(existingAccount); | ||
| } | ||
|
|
||
| const updatedAuth = await addAccount(auth, 'GitHub App', token, hostname); | ||
| const updatedAuth = await addAccount( | ||
| auth, | ||
| 'GitHub App', | ||
| token, | ||
| hostname, | ||
| 'github', | ||
| ); | ||
|
|
||
| persistAuth(updatedAuth); | ||
| await fetchNotifications({ auth: updatedAuth, settings }); | ||
|
|
@@ -504,6 +522,7 @@ export const AppProvider = ({ children }: { children: ReactNode }) => { | |
| 'OAuth App', | ||
| token, | ||
| authOptions.hostname, | ||
| 'github', | ||
| ); | ||
|
|
||
| persistAuth(updatedAuth); | ||
|
|
@@ -522,15 +541,20 @@ export const AppProvider = ({ children }: { children: ReactNode }) => { | |
| * Login with Personal Access Token (PAT). | ||
| */ | ||
| const loginWithPersonalAccessToken = useCallback( | ||
| async ({ token, hostname }: LoginPersonalAccessTokenOptions) => { | ||
| async ({ token, hostname, forge }: LoginPersonalAccessTokenOptions) => { | ||
| const resolvedForge: Forge = forge ?? 'github'; | ||
| const encryptedToken = (await encryptValue(token)) as Token; | ||
| await fetchAuthenticatedUserDetails({ | ||
| await getAdapterById(resolvedForge).fetchAuthenticatedUser({ | ||
| forge: resolvedForge, | ||
| hostname, | ||
| token: encryptedToken, | ||
| } as Account); | ||
|
|
||
| const existingAccount = auth.accounts.find( | ||
| (a) => a.hostname === hostname && a.method === 'Personal Access Token', | ||
| (a) => | ||
| a.hostname === hostname && | ||
| a.method === 'Personal Access Token' && | ||
| a.forge === resolvedForge, | ||
| ); | ||
| if (existingAccount) { | ||
| await removeAccountNotifications(existingAccount); | ||
|
|
@@ -541,6 +565,7 @@ export const AppProvider = ({ children }: { children: ReactNode }) => { | |
| 'Personal Access Token', | ||
| token, | ||
| hostname, | ||
| resolvedForge, | ||
| ); | ||
|
|
||
| persistAuth(updatedAuth); | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gitea missing?