-
Notifications
You must be signed in to change notification settings - Fork 738
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/member-organization-affiliation-sett…
…ings
- Loading branch information
Showing
341 changed files
with
8,127 additions
and
7,470 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import Permissions from '../../../security/permissions' | ||
import IntegrationService from '../../../services/integrationService' | ||
import PermissionChecker from '../../../services/user/permissionChecker' | ||
|
||
export default async (req, res) => { | ||
new PermissionChecker(req).validateHas(Permissions.values.tenantEdit) | ||
const payload = await new IntegrationService(req).connectGithub( | ||
req.params.code, | ||
req.body.installId, | ||
req.body.setupAction, | ||
) | ||
await req.responseHandler.success(req, res, payload) | ||
} |
9 changes: 9 additions & 0 deletions
9
backend/src/api/integration/helpers/githubConnectInstallation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Permissions from '../../../security/permissions' | ||
import IntegrationService from '../../../services/integrationService' | ||
import PermissionChecker from '../../../services/user/permissionChecker' | ||
|
||
export default async (req, res) => { | ||
new PermissionChecker(req).validateHas(Permissions.values.tenantEdit) | ||
const payload = await new IntegrationService(req).connectGithubInstallation(req.body.installId) | ||
await req.responseHandler.success(req, res, payload) | ||
} |
9 changes: 9 additions & 0 deletions
9
backend/src/api/integration/helpers/githubGetInstallations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Permissions from '../../../security/permissions' | ||
import IntegrationService from '../../../services/integrationService' | ||
import PermissionChecker from '../../../services/user/permissionChecker' | ||
|
||
export default async (req, res) => { | ||
new PermissionChecker(req).validateHas(Permissions.values.tenantEdit) | ||
const payload = await new IntegrationService(req).getGithubInstallations() | ||
await req.responseHandler.success(req, res, payload) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,27 @@ | ||
import { GITHUB_CONFIG } from '@/conf' | ||
|
||
import Permissions from '../../../security/permissions' | ||
import IntegrationService from '../../../services/integrationService' | ||
import PermissionChecker from '../../../services/user/permissionChecker' | ||
|
||
const isSnowflakeEnabled = GITHUB_CONFIG.isSnowflakeEnabled === 'true' | ||
|
||
export default async (req, res) => { | ||
new PermissionChecker(req).validateHas(Permissions.values.tenantEdit) | ||
const payload = await new IntegrationService(req).mapGithubRepos( | ||
req.params.id, | ||
req.body.mapping, | ||
true, | ||
req.body?.isUpdateTransaction ?? false, | ||
) | ||
let payload | ||
if (isSnowflakeEnabled) { | ||
payload = await new IntegrationService(req).mapGithubReposSnowflake( | ||
req.params.id, | ||
req.body.mapping, | ||
true, | ||
req.body?.isUpdateTransaction ?? false, | ||
) | ||
} else { | ||
payload = await new IntegrationService(req).mapGithubRepos( | ||
req.params.id, | ||
req.body.mapping, | ||
true, | ||
) | ||
} | ||
await req.responseHandler.success(req, res, payload) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
backend/src/serverless/integrations/usecases/github/rest/getInstalledRepositories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import axios, { AxiosRequestConfig } from 'axios' | ||
|
||
import { getServiceChildLogger } from '@crowd/logging' | ||
|
||
import { Repos } from '../../../types/regularTypes' | ||
|
||
const log = getServiceChildLogger('getInstalledRepositories') | ||
|
||
const getRepositoriesFromGH = async (page: number, installToken: string): Promise<any> => { | ||
const REPOS_PER_PAGE = 100 | ||
|
||
const requestConfig = { | ||
method: 'get', | ||
url: `https://api.github.com/installation/repositories?page=${page}&per_page=${REPOS_PER_PAGE}`, | ||
headers: { | ||
Authorization: `Bearer ${installToken}`, | ||
}, | ||
} as AxiosRequestConfig | ||
|
||
const response = await axios(requestConfig) | ||
return response.data | ||
} | ||
|
||
const parseRepos = (repositories: any): Repos => { | ||
const repos: Repos = [] | ||
|
||
for (const repo of repositories) { | ||
repos.push({ | ||
url: repo.html_url, | ||
owner: repo.owner.login, | ||
createdAt: repo.created_at, | ||
name: repo.name, | ||
fork: repo.fork, | ||
private: repo.private, | ||
cloneUrl: repo.clone_url, | ||
}) | ||
} | ||
|
||
return repos | ||
} | ||
|
||
export const getInstalledRepositories = async (installToken: string): Promise<Repos> => { | ||
try { | ||
let page = 1 | ||
let hasMorePages = true | ||
|
||
const repos: Repos = [] | ||
|
||
while (hasMorePages) { | ||
const data = await getRepositoriesFromGH(page, installToken) | ||
|
||
if (data.repositories) { | ||
repos.push(...parseRepos(data.repositories)) | ||
} | ||
|
||
hasMorePages = data.total_count && data.total_count > 0 && data.total_count > repos.length | ||
page += 1 | ||
} | ||
return repos.filter((repo) => !repo.private && !repo.fork) | ||
} catch (err: any) { | ||
log.error(err, 'Error fetching installed repositories!') | ||
throw err | ||
} | ||
} |
Oops, something went wrong.