Skip to content

Commit 6bd53da

Browse files
authored
chore: github integration sync (CM-710) (#3572)
Signed-off-by: Uroš Marolt <uros@marolt.me>
1 parent 310c5e1 commit 6bd53da

File tree

27 files changed

+545
-212
lines changed

27 files changed

+545
-212
lines changed

backend/src/api/integration/helpers/githubOrgRepos.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { GithubIntegrationService } from '@crowd/common_services'
2+
13
import Permissions from '@/security/permissions'
2-
import GithubIntegrationService from '@/services/githubIntegrationService'
34
import PermissionChecker from '@/services/user/permissionChecker'
45

56
export default async (req, res) => {

backend/src/api/integration/helpers/githubSearchOrgs.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { GithubIntegrationService } from '@crowd/common_services'
2+
13
import Permissions from '@/security/permissions'
2-
import GithubIntegrationService from '@/services/githubIntegrationService'
34
import PermissionChecker from '@/services/user/permissionChecker'
45

56
export default async (req, res) => {

backend/src/api/integration/helpers/githubSearchRepos.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import { GithubIntegrationService } from '@crowd/common_services'
2+
13
import Permissions from '@/security/permissions'
2-
import GithubIntegrationService from '@/services/githubIntegrationService'
34
import PermissionChecker from '@/services/user/permissionChecker'
45

56
export default async (req, res) => {
67
new PermissionChecker(req).validateHas(Permissions.values.integrationEdit)
78

8-
const payload = await new GithubIntegrationService(req).findGithubRepos(
9+
const payload = await new GithubIntegrationService(req.log).findGithubRepos(
910
req.query.query,
1011
req.query.limit,
1112
req.query.offset,

backend/src/bin/jobs/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import autoImportGroups from './autoImportGroupsioGroups'
44
import checkStuckIntegrationRuns from './checkStuckIntegrationRuns'
55
import cleanUp from './cleanUp'
66
import integrationTicks from './integrationTicks'
7-
// import refreshGithubRepoSettingsJob from './refreshGithubRepoSettings'
7+
import refreshGithubRepoSettingsJob from './refreshGithubRepoSettings'
88
import refreshGitlabToken from './refreshGitlabToken'
99
import refreshGroupsioToken from './refreshGroupsioToken'
1010
import refreshMaterializedViews from './refreshMaterializedViews'
@@ -16,7 +16,7 @@ const jobs: CrowdJob[] = [
1616
checkStuckIntegrationRuns,
1717
refreshGroupsioToken,
1818
refreshGitlabToken,
19-
// refreshGithubRepoSettingsJob,
19+
refreshGithubRepoSettingsJob,
2020
autoImportGroups,
2121
]
2222

backend/src/bin/jobs/refreshGithubRepoSettings.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable no-continue */
22
import cronGenerator from 'cron-time-generator'
33

4-
import { timeout } from '@crowd/common'
4+
import { IS_DEV_ENV, timeout } from '@crowd/common'
55
import { getServiceChildLogger } from '@crowd/logging'
66

77
import SequelizeRepository from '../../database/repositories/sequelizeRepository'
@@ -59,7 +59,7 @@ export const refreshGithubRepoSettings = async () => {
5959
const job: CrowdJob = {
6060
name: 'Refresh Github repo settings',
6161
// every day
62-
cronTime: cronGenerator.every(1).days(),
62+
cronTime: IS_DEV_ENV ? cronGenerator.every(5).minutes() : cronGenerator.every(1).days(),
6363
onTrigger: async () => {
6464
await refreshGithubRepoSettings()
6565
},

backend/src/database/migrations/U1762508771__autobackup-integrations.sql

Whitespace-only changes.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
create table "integrationsHistory" as
2+
select *
3+
from "integrations"
4+
where 1 = 2;
5+
6+
alter table "integrationsHistory"
7+
add column "historyCreatedAt" timestamptz not null default now();
8+
9+
create index if not exists ix_integration_history_integration_id on "integrationsHistory" ("id");
10+
11+
create function log_integrations_changes()
12+
returns trigger as
13+
$$
14+
begin
15+
insert into "integrationsHistory" select old.*;
16+
17+
if (tg_op = 'DELETE') then
18+
return old;
19+
else
20+
return new;
21+
end if;
22+
end;
23+
$$ language plpgsql;
24+
25+
create trigger integrations_audit_trigger
26+
after update or delete
27+
on integrations
28+
for each row
29+
execute function log_integrations_changes();

backend/src/segment/track.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getServiceChildLogger } from '@crowd/logging'
22
import { Edition } from '@crowd/types'
33

4-
import { API_CONFIG, IS_TEST_ENV, SEGMENT_CONFIG } from '../conf'
4+
import { API_CONFIG, IS_DEV_ENV, IS_TEST_ENV, SEGMENT_CONFIG } from '../conf'
55
import SequelizeRepository from '../database/repositories/sequelizeRepository'
66

77
import { CROWD_ANALYTICS_PLATORM_NAME } from './addProductDataToCrowdTenant'
@@ -21,6 +21,7 @@ export default async function identify(
2121
}).email
2222
if (
2323
!IS_TEST_ENV &&
24+
!IS_DEV_ENV &&
2425
SEGMENT_CONFIG.writeKey &&
2526
// This is only for events in the hosted version. Self-hosted has less telemetry.
2627
(API_CONFIG.edition === Edition.CROWD_HOSTED || API_CONFIG.edition === Edition.LFX) &&
@@ -41,6 +42,10 @@ export default async function identify(
4142

4243
const { userIdOut, tenantIdOut } = getTenatUser(userId, options)
4344

45+
if (!userIdOut) {
46+
return
47+
}
48+
4449
const payload = {
4550
userId: userIdOut,
4651
event,

backend/src/services/collectionService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { uniq } from 'lodash'
22

33
import { getCleanString } from '@crowd/common'
4+
import { GithubIntegrationService } from '@crowd/common_services'
45
import { OrganizationField, QueryExecutor, findOrgById, queryOrgs } from '@crowd/data-access-layer'
56
import { listCategoriesByIds } from '@crowd/data-access-layer/src/categories'
67
import {
@@ -49,7 +50,6 @@ import SequelizeRepository from '@/database/repositories/sequelizeRepository'
4950
import { IGithubInsights } from '@/types/githubTypes'
5051

5152
import { IServiceOptions } from './IServiceOptions'
52-
import GithubIntegrationService from './githubIntegrationService'
5353

5454
export class CollectionService extends LoggerBase {
5555
options: IServiceOptions

backend/src/services/helpers/githubToken.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)