fix: fork pr previews
This commit is contained in:
parent
755eeda364
commit
9a67cf7355
@ -44,7 +44,7 @@ export function getAPIUrl() {
|
|||||||
if (process.env.CODESANDBOX_HOST) {
|
if (process.env.CODESANDBOX_HOST) {
|
||||||
return `https://${process.env.CODESANDBOX_HOST.replace(/\$PORT/, '3001')}`;
|
return `https://${process.env.CODESANDBOX_HOST.replace(/\$PORT/, '3001')}`;
|
||||||
}
|
}
|
||||||
return isDev ? 'http://host.docker.internal:3001' : 'http://localhost:3000';
|
return isDev ? 'http://localhost:3001' : 'http://localhost:3000';
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getUIUrl() {
|
export function getUIUrl() {
|
||||||
|
@ -23,6 +23,7 @@ export interface GitHubEvents {
|
|||||||
ref: string,
|
ref: string,
|
||||||
repo: {
|
repo: {
|
||||||
id: string,
|
id: string,
|
||||||
|
full_name: string,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,9 +39,7 @@ export async function configureGitLabApp(request: FastifyRequest<ConfigureGitLab
|
|||||||
export async function gitLabEvents(request: FastifyRequest<GitLabEvents>) {
|
export async function gitLabEvents(request: FastifyRequest<GitLabEvents>) {
|
||||||
const { object_kind: objectKind, ref, project_id } = request.body
|
const { object_kind: objectKind, ref, project_id } = request.body
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const allowedActions = ['opened', 'reopen', 'close', 'open', 'update'];
|
const allowedActions = ['opened', 'reopen', 'close', 'open', 'update'];
|
||||||
|
|
||||||
const webhookToken = request.headers['x-gitlab-token'];
|
const webhookToken = request.headers['x-gitlab-token'];
|
||||||
if (!webhookToken && !isDev) {
|
if (!webhookToken && !isDev) {
|
||||||
throw { status: 500, message: 'Invalid webhookToken.' }
|
throw { status: 500, message: 'Invalid webhookToken.' }
|
||||||
@ -91,7 +89,7 @@ export async function gitLabEvents(request: FastifyRequest<GitLabEvents>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (objectKind === 'merge_request') {
|
} else if (objectKind === 'merge_request') {
|
||||||
const { object_attributes: { work_in_progress: isDraft, action, source_branch: sourceBranch, target_branch: targetBranch }, project: { id } } = request.body
|
const { object_attributes: { work_in_progress: isDraft, action, source_branch: sourceBranch, target_branch: targetBranch, source: { path_with_namespace: sourceRepository } }, project: { id } } = request.body
|
||||||
const pullmergeRequestId = request.body.object_attributes.iid.toString();
|
const pullmergeRequestId = request.body.object_attributes.iid.toString();
|
||||||
const projectId = Number(id);
|
const projectId = Number(id);
|
||||||
if (!allowedActions.includes(action)) {
|
if (!allowedActions.includes(action)) {
|
||||||
@ -100,7 +98,6 @@ export async function gitLabEvents(request: FastifyRequest<GitLabEvents>) {
|
|||||||
if (isDraft) {
|
if (isDraft) {
|
||||||
throw { status: 500, message: 'Draft MR, do nothing.' }
|
throw { status: 500, message: 'Draft MR, do nothing.' }
|
||||||
}
|
}
|
||||||
|
|
||||||
const applicationsFound = await getApplicationFromDBWebhook(projectId, targetBranch);
|
const applicationsFound = await getApplicationFromDBWebhook(projectId, targetBranch);
|
||||||
if (applicationsFound && applicationsFound.length > 0) {
|
if (applicationsFound && applicationsFound.length > 0) {
|
||||||
for (const application of applicationsFound) {
|
for (const application of applicationsFound) {
|
||||||
@ -153,6 +150,7 @@ export async function gitLabEvents(request: FastifyRequest<GitLabEvents>) {
|
|||||||
id: buildId,
|
id: buildId,
|
||||||
pullmergeRequestId,
|
pullmergeRequestId,
|
||||||
previewApplicationId,
|
previewApplicationId,
|
||||||
|
sourceRepository,
|
||||||
sourceBranch,
|
sourceBranch,
|
||||||
applicationId: application.id,
|
applicationId: application.id,
|
||||||
destinationDockerId: application.destinationDocker.id,
|
destinationDockerId: application.destinationDocker.id,
|
||||||
|
@ -8,6 +8,9 @@ export interface GitLabEvents {
|
|||||||
Body: {
|
Body: {
|
||||||
object_attributes: {
|
object_attributes: {
|
||||||
work_in_progress: string
|
work_in_progress: string
|
||||||
|
source: {
|
||||||
|
path_with_namespace: string
|
||||||
|
}
|
||||||
isDraft: string
|
isDraft: string
|
||||||
action: string
|
action: string
|
||||||
source_branch: string
|
source_branch: string
|
||||||
|
@ -184,10 +184,10 @@
|
|||||||
</div>
|
</div>
|
||||||
{:else if application.previewApplication.length > 0}
|
{:else if application.previewApplication.length > 0}
|
||||||
<div
|
<div
|
||||||
class="grid grid-col gap-4 auto-cols-max grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4"
|
class="grid grid-col gap-4 auto-cols-max grid-cols-1 md:grid-cols-2 lg:grid-cols-2 px-6"
|
||||||
>
|
>
|
||||||
{#each application.previewApplication as preview}
|
{#each application.previewApplication as preview}
|
||||||
<div class="no-underline mb-5 w-full lg:w-96">
|
<div class="no-underline mb-5 w-full">
|
||||||
<div class="w-full rounded p-5 bg-coolgray-200 indicator">
|
<div class="w-full rounded p-5 bg-coolgray-200 indicator">
|
||||||
{#await getStatus(preview)}
|
{#await getStatus(preview)}
|
||||||
<span class="indicator-item badge bg-yellow-500 badge-sm" />
|
<span class="indicator-item badge bg-yellow-500 badge-sm" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user