Skip to content

Commit

Permalink
Update after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorelli committed Jan 4, 2024
1 parent d1184a1 commit 1fe13e1
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 2 deletions.
3 changes: 2 additions & 1 deletion integrations/github/src/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export async function handleImportDispatchForSpaces(
context: GithubRuntimeContext,
payload: IntegrationTaskImportSpaces['payload']
): Promise<number | undefined> {
const { configQuery, page, standaloneRef } = payload;
const { configQuery, page, standaloneRef, eventTimestamp } = payload;

logger.debug(`handling import dispatch for spaces with payload: ${JSON.stringify(payload)}`);

Expand Down Expand Up @@ -92,6 +92,7 @@ export async function handleImportDispatchForSpaces(
ref: standaloneRef,
}
: undefined,
eventTimestamp,
});
} catch (error) {
logger.error(
Expand Down
7 changes: 7 additions & 0 deletions integrations/github/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ export type IntegrationTaskImportSpaces = BaseIntegrationTask<
configQuery: string;
page?: string;
standaloneRef?: string;
/**
* The timestamp of the event that triggers the export.
*
* This is to help ensures that Git sync import and export operations are executed
* in the same order on GitBook and on the remote repository.
*/
eventTimestamp?: Date;
}
>;

Expand Down
3 changes: 3 additions & 0 deletions integrations/github/src/webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ export async function handlePushEvent(

const total = await handleImportDispatchForSpaces(context, {
configQuery: queryKey,
eventTimestamp: payload.head_commit?.timestamp
? new Date(payload.head_commit?.timestamp)
: undefined,
});

logger.debug(`${total} space configurations are affected`);
Expand Down
3 changes: 2 additions & 1 deletion integrations/gitlab/src/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export async function handleImportDispatchForSpaces(
context: GitLabRuntimeContext,
payload: IntegrationTaskImportSpaces['payload']
): Promise<number | undefined> {
const { configQuery, page, standaloneRef } = payload;
const { configQuery, page, standaloneRef, eventTimestamp } = payload;

logger.debug(`handling import dispatch for spaces with payload: ${JSON.stringify(payload)}`);

Expand Down Expand Up @@ -92,6 +92,7 @@ export async function handleImportDispatchForSpaces(
ref: standaloneRef,
}
: undefined,
eventTimestamp,
});
} catch (error) {
logger.error(
Expand Down
7 changes: 7 additions & 0 deletions integrations/gitlab/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ export type IntegrationTaskImportSpaces = BaseIntegrationTask<
configQuery: string;
page?: string;
standaloneRef?: string;
/**
* The timestamp of the event that triggers the export.
*
* This is to help ensures that Git sync import and export operations are executed
* in the same order on GitBook and on the remote repository.
*/
eventTimestamp?: Date;
}
>;

Expand Down
7 changes: 7 additions & 0 deletions integrations/gitlab/src/webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,15 @@ export async function handlePushEvent(context: GitLabRuntimeContext, payload: Gi

const queryKey = computeConfigQueryKey(gitlabProjectId, gitlabRef);

// Gitlab push events do not include a head_commit property so we need to get it from
// the commits attribute which should contains the newest 20 commits:
// https://docs.gitlab.com/ee/user/project/integrations/webhook_events.html#push-events
const headCommitSha = payload.after;
const headCommit = payload.commits.find((commit) => commit.id === headCommitSha);

const total = await handleImportDispatchForSpaces(context, {
configQuery: queryKey,
eventTimestamp: headCommit ? new Date(headCommit.timestamp) : undefined,
});

logger.debug(`${total} space configurations are affected`);
Expand Down

0 comments on commit 1fe13e1

Please sign in to comment.