Skip to content

Commit

Permalink
Fix typecheck in git sync integrations (#615)
Browse files Browse the repository at this point in the history
  • Loading branch information
taranvohra authored Nov 14, 2024
1 parent d468628 commit 47a28f9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 16 deletions.
31 changes: 23 additions & 8 deletions integrations/github/src/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,21 @@ export async function triggerImport(
const { api } = context;
const { force = false, updateGitInfo = false, standalone, eventTimestamp } = options;

const spaceId =
typeof spaceInstallation.space === 'string'
? spaceInstallation.space
: spaceInstallation.space.id;

const config = getSpaceConfigOrThrow(spaceInstallation);

if (!config.key) {
logger.info(`No configuration found for space ${spaceInstallation.space}, skipping import`);
logger.info(`No configuration found for space ${spaceId}, skipping import`);
return;
}

assertIsDefined(config.branch, { label: 'config.branch' });

logger.info(`Initiating an import from GitHub to GitBook space ${spaceInstallation.space}`);
logger.info(`Initiating an import from GitHub to GitBook space ${spaceId}`);

const auth = await getRepositoryAuth(context, config);
const repoTreeURL = getGitTreeURL(config);
Expand All @@ -74,7 +79,7 @@ export async function triggerImport(
urlWithAuth.username = auth.username;
urlWithAuth.password = auth.password;

await api.spaces.importGitRepository(spaceInstallation.space, {
await api.spaces.importGitRepository(spaceId, {
url: urlWithAuth.toString(),
ref: standalone?.ref || config.branch,
repoTreeURL,
Expand Down Expand Up @@ -113,18 +118,23 @@ export async function triggerExport(
const { api } = context;
const { force = false, updateGitInfo = false, eventTimestamp } = options;

const spaceId =
typeof spaceInstallation.space === 'string'
? spaceInstallation.space
: spaceInstallation.space.id;

const config = getSpaceConfigOrThrow(spaceInstallation);

if (!config.key) {
logger.info(`No configuration found for space ${spaceInstallation.space}, skipping export`);
logger.info(`No configuration found for space ${spaceId}, skipping export`);
return;
}

assertIsDefined(config.branch, { label: 'config.branch' });

logger.info(`Initiating an export from space ${spaceInstallation.space} to GitHub`);
logger.info(`Initiating an export from space ${spaceId} to GitHub`);

const { data: revision } = await api.spaces.getCurrentRevision(spaceInstallation.space);
const { data: revision } = await api.spaces.getCurrentRevision(spaceId);

const auth = await getRepositoryAuth(context, config);
const repoTreeURL = getGitTreeURL(config);
Expand All @@ -133,7 +143,7 @@ export async function triggerExport(
urlWithAuth.username = auth.username;
urlWithAuth.password = auth.password;

await api.spaces.exportToGitRepository(spaceInstallation.space, {
await api.spaces.exportToGitRepository(spaceId, {
url: urlWithAuth.toString(),
ref: config.branch,
repoTreeURL,
Expand All @@ -160,7 +170,12 @@ export async function updateCommitWithPreviewLinks(
) {
const config = getSpaceConfigOrThrow(spaceInstallation);

const { data: space } = await runtime.api.spaces.getSpaceById(spaceInstallation.space);
const spaceId =
typeof spaceInstallation.space === 'string'
? spaceInstallation.space
: spaceInstallation.space.id;

const { data: space } = await runtime.api.spaces.getSpaceById(spaceId);

const context = `GitBook${config.projectDirectory ? ` (${config.projectDirectory})` : ''}`;

Expand Down
31 changes: 23 additions & 8 deletions integrations/gitlab/src/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,21 @@ export async function triggerImport(
const { api } = context;
const { force = false, updateGitInfo = false, standalone, eventTimestamp } = options;

const spaceId =
typeof spaceInstallation.space === 'string'
? spaceInstallation.space
: spaceInstallation.space.id;

const config = getSpaceConfigOrThrow(spaceInstallation);

if (!config.key) {
logger.info(`No configuration found for space ${spaceInstallation.space}, skipping import`);
logger.info(`No configuration found for space ${spaceId}, skipping import`);
return;
}

assertIsDefined(config.branch, { label: 'config.branch' });

logger.info(`Initiating an import from GitLab to GitBook space ${spaceInstallation.space}`);
logger.info(`Initiating an import from GitLab to GitBook space ${spaceId}`);

const repoTreeURL = getGitTreeURL(config);
const auth = await getRepositoryAuth(config);
Expand All @@ -74,7 +79,7 @@ export async function triggerImport(
urlWithAuth.username = auth.username;
urlWithAuth.password = auth.password;

await api.spaces.importGitRepository(spaceInstallation.space, {
await api.spaces.importGitRepository(spaceId, {
url: urlWithAuth.toString(),
ref: standalone?.ref || config.branch,
repoTreeURL,
Expand Down Expand Up @@ -113,18 +118,23 @@ export async function triggerExport(
const { api } = context;
const { force = false, updateGitInfo = false, eventTimestamp } = options;

const spaceId =
typeof spaceInstallation.space === 'string'
? spaceInstallation.space
: spaceInstallation.space.id;

const config = getSpaceConfigOrThrow(spaceInstallation);

if (!config.key) {
logger.info(`No configuration found for space ${spaceInstallation.space}, skipping export`);
logger.info(`No configuration found for space ${spaceId}, skipping export`);
return;
}

assertIsDefined(config.branch, { label: 'config.branch' });

logger.info(`Initiating an export from space ${spaceInstallation.space} to GitLab`);
logger.info(`Initiating an export from space ${spaceId} to GitLab`);

const { data: revision } = await api.spaces.getCurrentRevision(spaceInstallation.space);
const { data: revision } = await api.spaces.getCurrentRevision(spaceId);

const auth = await getRepositoryAuth(config);
const repoTreeURL = getGitTreeURL(config);
Expand All @@ -133,7 +143,7 @@ export async function triggerExport(
urlWithAuth.username = auth.username;
urlWithAuth.password = auth.password;

await api.spaces.exportToGitRepository(spaceInstallation.space, {
await api.spaces.exportToGitRepository(spaceId, {
url: urlWithAuth.toString(),
ref: config.branch,
repoTreeURL,
Expand All @@ -160,7 +170,12 @@ export async function updateCommitWithPreviewLinks(
) {
const config = getSpaceConfigOrThrow(spaceInstallation);

const { data: space } = await runtime.api.spaces.getSpaceById(spaceInstallation.space);
const spaceId =
typeof spaceInstallation.space === 'string'
? spaceInstallation.space
: spaceInstallation.space.id;

const { data: space } = await runtime.api.spaces.getSpaceById(spaceId);

const context = `GitBook${config.projectDirectory ? ` (${config.projectDirectory})` : ''}`;

Expand Down

0 comments on commit 47a28f9

Please sign in to comment.