Skip to content

Commit 47a28f9

Browse files
authored
Fix typecheck in git sync integrations (#615)
1 parent d468628 commit 47a28f9

File tree

2 files changed

+46
-16
lines changed

2 files changed

+46
-16
lines changed

integrations/github/src/sync.ts

+23-8
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,21 @@ export async function triggerImport(
5656
const { api } = context;
5757
const { force = false, updateGitInfo = false, standalone, eventTimestamp } = options;
5858

59+
const spaceId =
60+
typeof spaceInstallation.space === 'string'
61+
? spaceInstallation.space
62+
: spaceInstallation.space.id;
63+
5964
const config = getSpaceConfigOrThrow(spaceInstallation);
6065

6166
if (!config.key) {
62-
logger.info(`No configuration found for space ${spaceInstallation.space}, skipping import`);
67+
logger.info(`No configuration found for space ${spaceId}, skipping import`);
6368
return;
6469
}
6570

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

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

7075
const auth = await getRepositoryAuth(context, config);
7176
const repoTreeURL = getGitTreeURL(config);
@@ -74,7 +79,7 @@ export async function triggerImport(
7479
urlWithAuth.username = auth.username;
7580
urlWithAuth.password = auth.password;
7681

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

121+
const spaceId =
122+
typeof spaceInstallation.space === 'string'
123+
? spaceInstallation.space
124+
: spaceInstallation.space.id;
125+
116126
const config = getSpaceConfigOrThrow(spaceInstallation);
117127

118128
if (!config.key) {
119-
logger.info(`No configuration found for space ${spaceInstallation.space}, skipping export`);
129+
logger.info(`No configuration found for space ${spaceId}, skipping export`);
120130
return;
121131
}
122132

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

125-
logger.info(`Initiating an export from space ${spaceInstallation.space} to GitHub`);
135+
logger.info(`Initiating an export from space ${spaceId} to GitHub`);
126136

127-
const { data: revision } = await api.spaces.getCurrentRevision(spaceInstallation.space);
137+
const { data: revision } = await api.spaces.getCurrentRevision(spaceId);
128138

129139
const auth = await getRepositoryAuth(context, config);
130140
const repoTreeURL = getGitTreeURL(config);
@@ -133,7 +143,7 @@ export async function triggerExport(
133143
urlWithAuth.username = auth.username;
134144
urlWithAuth.password = auth.password;
135145

136-
await api.spaces.exportToGitRepository(spaceInstallation.space, {
146+
await api.spaces.exportToGitRepository(spaceId, {
137147
url: urlWithAuth.toString(),
138148
ref: config.branch,
139149
repoTreeURL,
@@ -160,7 +170,12 @@ export async function updateCommitWithPreviewLinks(
160170
) {
161171
const config = getSpaceConfigOrThrow(spaceInstallation);
162172

163-
const { data: space } = await runtime.api.spaces.getSpaceById(spaceInstallation.space);
173+
const spaceId =
174+
typeof spaceInstallation.space === 'string'
175+
? spaceInstallation.space
176+
: spaceInstallation.space.id;
177+
178+
const { data: space } = await runtime.api.spaces.getSpaceById(spaceId);
164179

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

integrations/gitlab/src/sync.ts

+23-8
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,21 @@ export async function triggerImport(
5656
const { api } = context;
5757
const { force = false, updateGitInfo = false, standalone, eventTimestamp } = options;
5858

59+
const spaceId =
60+
typeof spaceInstallation.space === 'string'
61+
? spaceInstallation.space
62+
: spaceInstallation.space.id;
63+
5964
const config = getSpaceConfigOrThrow(spaceInstallation);
6065

6166
if (!config.key) {
62-
logger.info(`No configuration found for space ${spaceInstallation.space}, skipping import`);
67+
logger.info(`No configuration found for space ${spaceId}, skipping import`);
6368
return;
6469
}
6570

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

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

7075
const repoTreeURL = getGitTreeURL(config);
7176
const auth = await getRepositoryAuth(config);
@@ -74,7 +79,7 @@ export async function triggerImport(
7479
urlWithAuth.username = auth.username;
7580
urlWithAuth.password = auth.password;
7681

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

121+
const spaceId =
122+
typeof spaceInstallation.space === 'string'
123+
? spaceInstallation.space
124+
: spaceInstallation.space.id;
125+
116126
const config = getSpaceConfigOrThrow(spaceInstallation);
117127

118128
if (!config.key) {
119-
logger.info(`No configuration found for space ${spaceInstallation.space}, skipping export`);
129+
logger.info(`No configuration found for space ${spaceId}, skipping export`);
120130
return;
121131
}
122132

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

125-
logger.info(`Initiating an export from space ${spaceInstallation.space} to GitLab`);
135+
logger.info(`Initiating an export from space ${spaceId} to GitLab`);
126136

127-
const { data: revision } = await api.spaces.getCurrentRevision(spaceInstallation.space);
137+
const { data: revision } = await api.spaces.getCurrentRevision(spaceId);
128138

129139
const auth = await getRepositoryAuth(config);
130140
const repoTreeURL = getGitTreeURL(config);
@@ -133,7 +143,7 @@ export async function triggerExport(
133143
urlWithAuth.username = auth.username;
134144
urlWithAuth.password = auth.password;
135145

136-
await api.spaces.exportToGitRepository(spaceInstallation.space, {
146+
await api.spaces.exportToGitRepository(spaceId, {
137147
url: urlWithAuth.toString(),
138148
ref: config.branch,
139149
repoTreeURL,
@@ -160,7 +170,12 @@ export async function updateCommitWithPreviewLinks(
160170
) {
161171
const config = getSpaceConfigOrThrow(spaceInstallation);
162172

163-
const { data: space } = await runtime.api.spaces.getSpaceById(spaceInstallation.space);
173+
const spaceId =
174+
typeof spaceInstallation.space === 'string'
175+
? spaceInstallation.space
176+
: spaceInstallation.space.id;
177+
178+
const { data: space } = await runtime.api.spaces.getSpaceById(spaceId);
164179

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

0 commit comments

Comments
 (0)