mirror of
https://github.com/graphql-hive/console
synced 2026-05-23 09:08:34 +00:00
Include project name in GH check-run for newly created projects (#2962)
This commit is contained in:
parent
08d51a4043
commit
2d1a5e55ea
8 changed files with 87 additions and 3 deletions
|
|
@ -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;
|
||||
|
|
@ -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,
|
||||
],
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
@ -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<Change>, 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 {
|
||||
|
|
|
|||
|
|
@ -263,6 +263,7 @@ export interface Project {
|
|||
validationUrl?: string | null;
|
||||
gitRepository?: string | null;
|
||||
legacyRegistryModel: boolean;
|
||||
useProjectNameInGithubCheck: boolean;
|
||||
externalComposition: {
|
||||
enabled: boolean;
|
||||
endpoint?: string | null;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue