Skip to content
Merged
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
15 changes: 14 additions & 1 deletion src/pages/api/projects/[projectName]/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ export const POST: APIRoute = async ({

const repo: FullRepository = await resp.json();

// Two-step visibility change for GitHub EMU organizations: the template
// generation API does not support `visibility: 'internal'`, so the repo
// is first created as private (above) and then patched to internal here.
if (repoVisibility === 'internal') {
const visibilityResp = await changeRepoVisibility(
token?.value as string,
Expand Down Expand Up @@ -464,11 +467,21 @@ export const PUT: APIRoute = async ({ cookies, params, request, redirect }) => {

// Has repo visibility changed?
if (projectConfig.project.is_private !== body.is_private) {
// For GitHub EMU organizations, repos can only be private or internal (not
// public). Sending `private: false` to the API would attempt a public
// visibility change which would fail for EMU orgs. Use `'internal'`
// instead so the PATCH sets visibility explicitly.
const isEnterprise =
isEnterpriseGitHubOrg(slugContents.org) ||
cookies.get('auth-provider')?.value === 'utexas';
const targetVisibility: boolean | 'internal' =
!body.is_private && isEnterprise ? 'internal' : body.is_private;

const visResponse = await changeRepoVisibility(
info?.token as string,
slugContents.org,
slugContents.repo,
body.is_private
targetVisibility
);

if (!visResponse.ok) {
Expand Down