diff --git a/packages/migrations/src/actions/2023.09.25T15.23.00.github-check-with-project-name.ts b/packages/migrations/src/actions/2023.09.25T15.23.00.github-check-with-project-name.ts new file mode 100644 index 000000000..b376765fc --- /dev/null +++ b/packages/migrations/src/actions/2023.09.25T15.23.00.github-check-with-project-name.ts @@ -0,0 +1,12 @@ +import { type MigrationExecutor } from '../pg-migrator'; + +export default { + name: '2023.09.25T15.23.00.github-check-with-project-name.ts', + run: ({ sql }) => sql` + ALTER TABLE "public"."projects" ADD COLUMN "github_check_with_project_name" BOOLEAN; + UPDATE "public"."projects" SET "github_check_with_project_name" = FALSE WHERE "github_check_with_project_name" IS NULL; + ALTER TABLE "public"."projects" + ALTER COLUMN "github_check_with_project_name" SET NOT NULL, + ALTER COLUMN "github_check_with_project_name" SET DEFAULT TRUE; + `, +} satisfies MigrationExecutor; diff --git a/packages/migrations/src/run-pg-migrations.ts b/packages/migrations/src/run-pg-migrations.ts index 7d587feee..ad54d2ceb 100644 --- a/packages/migrations/src/run-pg-migrations.ts +++ b/packages/migrations/src/run-pg-migrations.ts @@ -51,6 +51,7 @@ import migration_2023_06_06T11_26_04_schema_checks from './actions/2023.06.06T11 import migration_2023_07_10T11_26_04_schema_checks_manual_approval from './actions/2023.07.10T11.26.04.schema-checks-manual-approval'; import migration_2023_08_01T11_44_36_schema_checks_expires_at from './actions/2023.08.01T11.44.36.schema-checks-expires-at'; import migration_2023_09_01T09_54_00_zendesk_support from './actions/2023.09.01T09.54.00.zendesk-support'; +import migration_2023_09_25T15_23_00_github_check_with_project_name from './actions/2023.09.25T15.23.00.github-check-with-project-name'; import { runMigrations } from './pg-migrator'; export const runPGMigrations = (args: { slonik: DatabasePool; runTo?: string }) => @@ -110,5 +111,6 @@ export const runPGMigrations = (args: { slonik: DatabasePool; runTo?: string }) migration_2023_07_27T11_44_36_graphql_endpoint, migration_2023_08_01T11_44_36_schema_checks_expires_at, migration_2023_09_01T09_54_00_zendesk_support, + migration_2023_09_25T15_23_00_github_check_with_project_name, ], }); diff --git a/packages/migrations/test/drop-personal-org.test.ts b/packages/migrations/test/2023.02.22T09.27.02.delete-personal-org.test.ts.ts similarity index 100% rename from packages/migrations/test/drop-personal-org.test.ts rename to packages/migrations/test/2023.02.22T09.27.02.delete-personal-org.test.ts.ts diff --git a/packages/migrations/test/2023.09.25T15.23.00.github-check-with-project-name.test.ts b/packages/migrations/test/2023.09.25T15.23.00.github-check-with-project-name.test.ts new file mode 100644 index 000000000..90ef0d74e --- /dev/null +++ b/packages/migrations/test/2023.09.25T15.23.00.github-check-with-project-name.test.ts @@ -0,0 +1,51 @@ +import assert from 'node:assert'; +import { describe, test } from 'node:test'; +import { sql } from 'slonik'; +import { initMigrationTestingEnvironment } from './utils/testkit'; + +describe('migration: github-check-with-project-name', async () => { + await test('should use FALSE for existing projects and TRUE for new', async () => { + const { db, runTo, complete, done, seed } = await initMigrationTestingEnvironment(); + + try { + // Run migrations all the way to the point before the one we are testing + await runTo('2023.09.01T09.54.00.zendesk-support.ts'); + + // Seed the DB with orgs + const user = await seed.user(); + const org = await db.one<{ + id: string; + }>( + sql`INSERT INTO public.organizations (clean_id, name, user_id) VALUES ('org-1', 'org-1', ${user.id}) RETURNING id;`, + ); + const oldProject = await db.one( + sql`INSERT INTO public.projects (clean_id, name, type, org_id) VALUES ('proj-1', 'proj-1', 'SINGLE', ${org.id}) RETURNING id;`, + ); + + // Run the additional remaining migrations + await complete(); + + const newProject = await db.one( + sql`INSERT INTO public.projects (clean_id, name, type, org_id) VALUES ('proj-2', 'proj-2', 'SINGLE', ${org.id}) RETURNING id;`, + ); + + // Check that the old project has github_check_with_project_name = FALSE + assert.equal( + await db.oneFirst( + sql`SELECT github_check_with_project_name FROM public.projects WHERE id = ${oldProject.id}`, + ), + false, + ); + + // Check that the new project has github_check_with_project_name = TRUE + assert.equal( + await db.oneFirst( + sql`SELECT github_check_with_project_name FROM public.projects WHERE id = ${newProject.id}`, + ), + true, + ); + } finally { + await done(); + } + }); +}); diff --git a/packages/services/api/src/modules/schema/providers/schema-publisher.ts b/packages/services/api/src/modules/schema/providers/schema-publisher.ts index 083b723df..764defa2c 100644 --- a/packages/services/api/src/modules/schema/providers/schema-publisher.ts +++ b/packages/services/api/src/modules/schema/providers/schema-publisher.ts @@ -1173,7 +1173,12 @@ export class SchemaPublisher { } const checkRun = await this.gitHubIntegrationManager.createCheckRun({ - name: buildGitHubActionCheckName(target.name, serviceName ?? null), + name: buildGitHubActionCheckName({ + projectName: project.name, + targetName: target.name, + serviceName, + includeProjectName: project.useProjectNameInGithubCheck, + }), conclusion: conclusion === SchemaCheckConclusion.Success ? 'success' : 'failure', sha, organization: project.orgId, @@ -1514,8 +1519,19 @@ function writeChanges(type: string, changes: ReadonlyArray, lines: strin } } -function buildGitHubActionCheckName(target: string, service: string | null) { - return `GraphQL Hive > schema:check > ${target}` + (service ? ` > ${service}` : ''); +function buildGitHubActionCheckName(input: { + targetName: string; + projectName: string; + serviceName: string | null; + includeProjectName: boolean; +}) { + const path = [ + input.includeProjectName ? input.projectName : null, + input.targetName, + input.serviceName, + ].filter((val): val is string => typeof val === 'string'); + + return `GraphQL Hive > schema:check > ${path.join(' > ')}`; } function tryPrettifySDL(sdl: string): string { diff --git a/packages/services/api/src/shared/entities.ts b/packages/services/api/src/shared/entities.ts index f9894751b..74e2582d0 100644 --- a/packages/services/api/src/shared/entities.ts +++ b/packages/services/api/src/shared/entities.ts @@ -263,6 +263,7 @@ export interface Project { validationUrl?: string | null; gitRepository?: string | null; legacyRegistryModel: boolean; + useProjectNameInGithubCheck: boolean; externalComposition: { enabled: boolean; endpoint?: string | null; diff --git a/packages/services/storage/src/db/types.ts b/packages/services/storage/src/db/types.ts index 047a4d4ec..37bbc4c18 100644 --- a/packages/services/storage/src/db/types.ts +++ b/packages/services/storage/src/db/types.ts @@ -158,6 +158,7 @@ export interface projects { external_composition_endpoint: string | null; external_composition_secret: string | null; git_repository: string | null; + github_check_with_project_name: boolean; id: string; legacy_registry_model: boolean; name: string; diff --git a/packages/services/storage/src/index.ts b/packages/services/storage/src/index.ts index eff949af4..35fb44d88 100644 --- a/packages/services/storage/src/index.ts +++ b/packages/services/storage/src/index.ts @@ -206,6 +206,7 @@ export async function createStorage(connection: string, maximumPoolSize: number) validationUrl: project.validation_url, gitRepository: project.git_repository, legacyRegistryModel: project.legacy_registry_model, + useProjectNameInGithubCheck: project.github_check_with_project_name === true, externalComposition: { enabled: project.external_composition_enabled, endpoint: project.external_composition_endpoint,