Skip to content

Commit

Permalink
Patch GitHub integration organization owner
Browse files Browse the repository at this point in the history
  • Loading branch information
dangtony98 committed Apr 7, 2023
1 parent 00b17d2 commit a3093de
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
11 changes: 7 additions & 4 deletions backend/src/integrations/apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,13 @@ const getAppsGithub = async ({ accessToken }: { accessToken: string }) => {

apps = repos
.filter((a: any) => a.permissions.admin === true)
.map((a: any) => ({
name: a.name,
owner: a.owner.login,
}));
.map((a: any) => {
return ({
appId: a.id,
name: a.name,
owner: a.owner.login,
});
});
} catch (err) {
Sentry.setUser(null);
Sentry.captureException(err);
Expand Down
2 changes: 1 addition & 1 deletion backend/src/integrations/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@ const syncSecretsGitHub = async ({
"GET /repos/{owner}/{repo}/actions/secrets/public-key",
{
owner: integration.owner,
repo: integration.app,
repo: integration.app
}
)
).data;
Expand Down
24 changes: 13 additions & 11 deletions frontend/src/pages/integrations/github/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ export default function GitHubCreateIntegrationPage() {
});

const [selectedSourceEnvironment, setSelectedSourceEnvironment] = useState('');
const [owner, setOwner] = useState<string | null>(null);
const [targetApp, setTargetApp] = useState('');
const [targetAppId, setTargetAppId] = useState('');

const [isLoading, setIsLoading] = useState(false);

Expand All @@ -41,10 +40,9 @@ export default function GitHubCreateIntegrationPage() {
useEffect(() => {
if (integrationAuthApps) {
if (integrationAuthApps.length > 0) {
setTargetApp(integrationAuthApps[0].name);
setOwner(integrationAuthApps[0]?.owner ?? null);
setTargetAppId(integrationAuthApps[0].appId as string);
} else {
setTargetApp('none');
setTargetAppId('none');
}
}
}, [integrationAuthApps]);
Expand All @@ -55,14 +53,18 @@ export default function GitHubCreateIntegrationPage() {

if (!integrationAuth?._id) return;

const targetApp = integrationAuthApps?.find((integrationAuthApp) => integrationAuthApp.appId === targetAppId);

if (!targetApp || !targetApp.owner) return;

await createIntegration({
integrationAuthId: integrationAuth?._id,
isActive: true,
app: targetApp,
app: targetApp.name,
appId: null,
sourceEnvironment: selectedSourceEnvironment,
targetEnvironment: null,
owner,
owner: targetApp.owner,
path: null,
region: null
});
Expand All @@ -76,7 +78,7 @@ export default function GitHubCreateIntegrationPage() {
}
}

return (integrationAuth && workspace && selectedSourceEnvironment && integrationAuthApps && targetApp) ? (
return (integrationAuth && workspace && selectedSourceEnvironment && integrationAuthApps && targetAppId) ? (
<div className="h-full w-full flex justify-center items-center">
<Card className="max-w-md p-8 rounded-md">
<CardTitle className='text-center'>GitHub Integration</CardTitle>
Expand All @@ -101,14 +103,14 @@ export default function GitHubCreateIntegrationPage() {
className='mt-4'
>
<Select
value={targetApp}
onValueChange={(val) => setTargetApp(val)}
value={targetAppId}
onValueChange={(val) => setTargetAppId(val)}
className='w-full border border-mineshaft-500'
isDisabled={integrationAuthApps.length === 0}
>
{integrationAuthApps.length > 0 ? (
integrationAuthApps.map((integrationAuthApp) => (
<SelectItem value={integrationAuthApp.name} key={`github-environment-${integrationAuthApp.name}`}>
<SelectItem value={integrationAuthApp.appId as string} key={`github-repo-${integrationAuthApp.appId}`}>
{integrationAuthApp.name}
</SelectItem>
))
Expand Down

1 comment on commit a3093de

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report for backend

St.
Category Percentage Covered / Total
🟢 Statements 90.53% 86/95
🔴 Branches 25% 2/8
🔴 Functions 50% 3/6
🟢 Lines 92.39% 85/92

Test suite run success

24 tests passing in 2 suites.

Report generated by 🧪jest coverage report action from a3093de

Please sign in to comment.