Merge pull request #1544 from Infisical/railway-integration

Update Railway integration get services query, make services optional
This commit is contained in:
BlackMagiq
2024-03-08 14:25:14 -08:00
committed by GitHub
3 changed files with 29 additions and 53 deletions

View File

@@ -649,33 +649,21 @@ export const integrationAuthServiceFactory = ({
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.Integrations); ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.Integrations);
const botKey = await projectBotService.getBotKey(integrationAuth.projectId); const botKey = await projectBotService.getBotKey(integrationAuth.projectId);
const { accessToken } = await getIntegrationAccessToken(integrationAuth, botKey); const { accessToken } = await getIntegrationAccessToken(integrationAuth, botKey);
if (appId) {
if (appId && appId !== "") {
const query = ` const query = `
query project($id: String!) { query project($id: String!) {
project(id: $id) { project(id: $id) {
createdAt services {
deletedAt edges {
id node {
description id
expiredAt name
isPublic }
isTempProject }
isUpdatable }
name }
prDeploys
teamId
updatedAt
upstreamUrl
services {
edges {
node {
id
name
}
}
}
} }
}
`; `;
const variables = { const variables = {
@@ -711,6 +699,7 @@ export const integrationAuthServiceFactory = ({
); );
return edges.map(({ node: { name, id: serviceId } }) => ({ name, serviceId })); return edges.map(({ node: { name, id: serviceId } }) => ({ name, serviceId }));
} }
return []; return [];
}; };

View File

@@ -1204,21 +1204,21 @@ const syncSecretsRailway = async ({
} }
`; `;
const input = { const variables = {
projectId: integration.appId, input: {
environmentId: integration.targetEnvironmentId, projectId: integration.appId,
...(integration.targetServiceId ? { serviceId: integration.targetServiceId } : {}), environmentId: integration.targetEnvironmentId,
replace: true, ...(integration.targetServiceId ? { serviceId: integration.targetServiceId } : {}),
variables: getSecretKeyValuePair(secrets) replace: true,
variables: getSecretKeyValuePair(secrets)
}
}; };
await request.post( await request.post(
IntegrationUrls.RAILWAY_API_URL, IntegrationUrls.RAILWAY_API_URL,
{ {
query, query,
variables: { variables
input
}
}, },
{ {
headers: { headers: {

View File

@@ -74,16 +74,6 @@ export default function RailwayCreateIntegrationPage() {
} }
}, [targetEnvironments]); }, [targetEnvironments]);
useEffect(() => {
if (targetServices) {
if (targetServices.length > 0) {
setTargetServiceId(targetServices[0].serviceId);
} else {
setTargetServiceId("none");
}
}
}, [targetServices]);
const handleButtonClick = async () => { const handleButtonClick = async () => {
try { try {
setIsLoading(true); setIsLoading(true);
@@ -124,11 +114,14 @@ export default function RailwayCreateIntegrationPage() {
} }
}; };
const filteredTargetServices = targetServices ? [ { name: "", serviceId: "none" }, ...targetServices ] : [ { name: "", serviceId: "none" } ];
return workspace && return workspace &&
selectedSourceEnvironment && selectedSourceEnvironment &&
integrationAuthApps && integrationAuthApps &&
targetEnvironments && targetEnvironments &&
targetServices ? ( targetServices &&
filteredTargetServices ? (
<div className="flex h-full w-full items-center justify-center"> <div className="flex h-full w-full items-center justify-center">
<Card className="max-w-md rounded-md p-8"> <Card className="max-w-md rounded-md p-8">
<CardTitle className="text-center">Railway Integration</CardTitle> <CardTitle className="text-center">Railway Integration</CardTitle>
@@ -208,20 +201,14 @@ export default function RailwayCreateIntegrationPage() {
className="w-full border border-mineshaft-500" className="w-full border border-mineshaft-500"
isDisabled={targetServices.length === 0} isDisabled={targetServices.length === 0}
> >
{targetServices.length > 0 ? ( {filteredTargetServices.map((targetService) => (
targetServices.map((targetService) => (
<SelectItem <SelectItem
value={targetService.serviceId as string} value={targetService.serviceId as string}
key={`target-service-${targetService.serviceId as string}`} key={`target-service-${targetService.serviceId as string}`}
> >
{targetService.name} {targetService.name}
</SelectItem> </SelectItem>
)) ))}
) : (
<SelectItem value="none" key="target-service-none">
No services found
</SelectItem>
)}
</Select> </Select>
</FormControl> </FormControl>
<Button <Button