[PR #218] [MERGED] fix: gracefully handle SAML-protected orgs during GitHub import #1845

Closed
opened 2026-04-27 19:13:02 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/RayLabsHQ/gitea-mirror/pull/218
Author: @arunavo4
Created: 3/6/2026
Status: Merged
Merged: 3/7/2026
Merged by: @arunavo4

Base: mainHead: fix/graceful-saml-org-import


📝 Commits (1)

  • 8f76f33 fix: gracefully handle SAML-protected orgs during GitHub import (#217)

📊 Changes

4 files changed (+151 additions, -43 deletions)

View changed files

📝 src/components/config/ConfigTabs.tsx (+21 -9)
📝 src/components/organizations/OrganizationsList.tsx (+17 -5)
📝 src/lib/github.ts (+38 -21)
📝 src/pages/api/sync/index.ts (+75 -8)

📄 Description

Summary

Closes #217

  • Previously: If a user belonged to any GitHub org with SAML/SSO enforcement, the entire "Import GitHub Data" operation failed with a 403 error — no repos or orgs were imported.
  • Now: SAML-protected orgs that return 403 are saved to the database with status: "failed" and the actual GitHub error message, while the rest of the import (repos, starred repos, other orgs) proceeds normally.

Changes

  • src/lib/github.tsgetGithubOrganizations catches 403 errors per-org instead of failing entirely. Returns both successful orgs and failed orgs with the GitHub error message.
  • src/pages/api/sync/index.ts — Inserts failed orgs into DB with status: "failed" + errorMessage. On re-import, recovers previously failed orgs that now succeed. Only updates error message for orgs already in failed state (never overwrites "mirrored" or other good states).
  • src/components/config/ConfigTabs.tsx — Shows toast warnings for failed orgs ("2 orgs failed to import…") and success toasts for recovered orgs on re-import.
  • src/components/organizations/OrganizationsList.tsx — Displays the GitHub error message on failed org cards. Shows "Re-import from Settings" button for import-failed orgs (vs existing "Retry Mirror" for mirror-failed orgs). Users can also ignore or delete failed orgs via the existing dropdown menu.

User flow

  1. User imports GitHub data → SAML-protected orgs fail with a toast warning
  2. Failed orgs appear in the Organizations tab with the error message and a "Failed" badge
  3. User can either:
    • Ignore/Delete the org if they don't want it
    • Grant PAT SAML access on GitHub, then re-import → org recovers to "imported" status

Test plan

  • All 163 existing tests pass
  • Verify import works when user has no SAML-protected orgs (no regression)
  • Verify import completes with warning toast when SAML-protected orgs exist
  • Verify failed orgs show in Organizations tab with error message
  • Verify "Ignore" and "Delete" work on failed orgs
  • Verify re-import recovers failed orgs after granting PAT access
  • Verify re-import does not overwrite already-mirrored orgs if they later fail

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/RayLabsHQ/gitea-mirror/pull/218 **Author:** [@arunavo4](https://github.com/arunavo4) **Created:** 3/6/2026 **Status:** ✅ Merged **Merged:** 3/7/2026 **Merged by:** [@arunavo4](https://github.com/arunavo4) **Base:** `main` ← **Head:** `fix/graceful-saml-org-import` --- ### 📝 Commits (1) - [`8f76f33`](https://github.com/RayLabsHQ/gitea-mirror/commit/8f76f332f198740d6f64cf553ef65913f4208558) fix: gracefully handle SAML-protected orgs during GitHub import (#217) ### 📊 Changes **4 files changed** (+151 additions, -43 deletions) <details> <summary>View changed files</summary> 📝 `src/components/config/ConfigTabs.tsx` (+21 -9) 📝 `src/components/organizations/OrganizationsList.tsx` (+17 -5) 📝 `src/lib/github.ts` (+38 -21) 📝 `src/pages/api/sync/index.ts` (+75 -8) </details> ### 📄 Description ## Summary Closes #217 - **Previously:** If a user belonged to any GitHub org with SAML/SSO enforcement, the entire "Import GitHub Data" operation failed with a 403 error — no repos or orgs were imported. - **Now:** SAML-protected orgs that return 403 are saved to the database with `status: "failed"` and the actual GitHub error message, while the rest of the import (repos, starred repos, other orgs) proceeds normally. ### Changes - **`src/lib/github.ts`** — `getGithubOrganizations` catches 403 errors per-org instead of failing entirely. Returns both successful orgs and failed orgs with the GitHub error message. - **`src/pages/api/sync/index.ts`** — Inserts failed orgs into DB with `status: "failed"` + `errorMessage`. On re-import, recovers previously failed orgs that now succeed. Only updates error message for orgs already in failed state (never overwrites `"mirrored"` or other good states). - **`src/components/config/ConfigTabs.tsx`** — Shows toast warnings for failed orgs ("2 orgs failed to import…") and success toasts for recovered orgs on re-import. - **`src/components/organizations/OrganizationsList.tsx`** — Displays the GitHub error message on failed org cards. Shows "Re-import from Settings" button for import-failed orgs (vs existing "Retry Mirror" for mirror-failed orgs). Users can also ignore or delete failed orgs via the existing dropdown menu. ### User flow 1. User imports GitHub data → SAML-protected orgs fail with a toast warning 2. Failed orgs appear in the Organizations tab with the error message and a "Failed" badge 3. User can either: - **Ignore/Delete** the org if they don't want it - **Grant PAT SAML access** on GitHub, then re-import → org recovers to "imported" status ## Test plan - [x] All 163 existing tests pass - [ ] Verify import works when user has no SAML-protected orgs (no regression) - [ ] Verify import completes with warning toast when SAML-protected orgs exist - [ ] Verify failed orgs show in Organizations tab with error message - [ ] Verify "Ignore" and "Delete" work on failed orgs - [ ] Verify re-import recovers failed orgs after granting PAT access - [ ] Verify re-import does not overwrite already-mirrored orgs if they later fail --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-27 19:13:02 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea-mirror#1845