Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add custom context to subgraph checks #1252

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion cli/src/commands/subgraph/commands/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { readFile } from 'node:fs/promises';
import { Command, program } from 'commander';
import { resolve } from 'pathe';
import pc from 'picocolors';
import { getBaseHeaders } from '../../../core/config.js';
import { CustomCheckContext } from '@wundergraph/cosmo-connect/dist/platform/v1/platform_pb';
import { config, getBaseHeaders } from '../../../core/config.js';
import { BaseCommandOptions } from '../../../core/types/types.js';
import { verifyGitHubIntegration } from '../../../github.js';
import { handleCheckResult } from '../../../handle-check-result.js';
Expand Down Expand Up @@ -39,6 +40,15 @@ export default (opts: BaseCommandOptions) => {
}

const { gitInfo, ignoreErrorsDueToGitHubIntegration } = await verifyGitHubIntegration(opts.client);
let customContext: CustomCheckContext | undefined;

if (config.checkAuthor || config.checkCommitSha || config.checkBranch) {
StarpTech marked this conversation as resolved.
Show resolved Hide resolved
customContext = new CustomCheckContext({
author: config.checkAuthor,
commitSha: config.checkCommitSha,
branch: config.checkBranch,
});
}

// submit an empty schema in case of a delete check
const schema = schemaFile ? await readFile(schemaFile) : Buffer.from('');
Expand All @@ -51,6 +61,7 @@ export default (opts: BaseCommandOptions) => {
gitInfo,
delete: options.delete,
skipTrafficCheck: options.skipTrafficCheck,
customContext,
},
{
headers: getBaseHeaders(),
Expand Down
3 changes: 3 additions & 0 deletions cli/src/core/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export const config = {
cdnURL: process.env.CDN_URL || 'https://cosmo-cdn.wundergraph.com',
version: info.version,
disableUpdateCheck: process.env.DISABLE_UPDATE_CHECK || 'false',
checkAuthor: process.env.COSMO_VCS_AUTHOR || '',
checkCommitSha: process.env.COSMO_VCS_COMMIT || '',
checkBranch: process.env.COSMO_VCS_BRANCH || '',
};

export const getBaseHeaders = (): HeadersInit => {
Expand Down
14,107 changes: 7,110 additions & 6,997 deletions connect-go/gen/proto/wg/cosmo/platform/v1/platform.pb.go

Large diffs are not rendered by default.

61 changes: 61 additions & 0 deletions connect/src/wg/cosmo/platform/v1/platform_pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,55 @@ export class GitInfo extends Message<GitInfo> {
}
}

/**
* @generated from message wg.cosmo.platform.v1.CustomCheckContext
*/
export class CustomCheckContext extends Message<CustomCheckContext> {
StarpTech marked this conversation as resolved.
Show resolved Hide resolved
/**
* @generated from field: string author = 1;
*/
author = "";

/**
* @generated from field: string commit_sha = 2;
*/
commitSha = "";

/**
* @generated from field: string branch = 3;
*/
branch = "";

constructor(data?: PartialMessage<CustomCheckContext>) {
super();
proto3.util.initPartial(data, this);
}

static readonly runtime: typeof proto3 = proto3;
static readonly typeName = "wg.cosmo.platform.v1.CustomCheckContext";
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: "author", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 2, name: "commit_sha", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 3, name: "branch", kind: "scalar", T: 9 /* ScalarType.STRING */ },
]);

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): CustomCheckContext {
return new CustomCheckContext().fromBinary(bytes, options);
}

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): CustomCheckContext {
return new CustomCheckContext().fromJson(jsonValue, options);
}

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): CustomCheckContext {
return new CustomCheckContext().fromJsonString(jsonString, options);
}

static equals(a: CustomCheckContext | PlainMessage<CustomCheckContext> | undefined, b: CustomCheckContext | PlainMessage<CustomCheckContext> | undefined): boolean {
return proto3.util.equals(CustomCheckContext, a, b);
}
}

/**
* @generated from message wg.cosmo.platform.v1.CheckSubgraphSchemaRequest
*/
Expand Down Expand Up @@ -814,6 +863,11 @@ export class CheckSubgraphSchemaRequest extends Message<CheckSubgraphSchemaReque
*/
skipTrafficCheck?: boolean;

/**
* @generated from field: optional wg.cosmo.platform.v1.CustomCheckContext customContext = 7;
*/
customContext?: CustomCheckContext;

constructor(data?: PartialMessage<CheckSubgraphSchemaRequest>) {
super();
proto3.util.initPartial(data, this);
Expand All @@ -828,6 +882,7 @@ export class CheckSubgraphSchemaRequest extends Message<CheckSubgraphSchemaReque
{ no: 4, name: "delete", kind: "scalar", T: 8 /* ScalarType.BOOL */, opt: true },
{ no: 5, name: "namespace", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 6, name: "skip_traffic_check", kind: "scalar", T: 8 /* ScalarType.BOOL */, opt: true },
{ no: 7, name: "customContext", kind: "message", T: CustomCheckContext, opt: true },
]);

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): CheckSubgraphSchemaRequest {
Expand Down Expand Up @@ -3426,6 +3481,11 @@ export class SchemaCheck extends Message<SchemaCheck> {
*/
graphPruningSkipped = false;

/**
* @generated from field: optional wg.cosmo.platform.v1.CustomCheckContext customContext = 16;
*/
customContext?: CustomCheckContext;

constructor(data?: PartialMessage<SchemaCheck>) {
super();
proto3.util.initPartial(data, this);
Expand All @@ -3449,6 +3509,7 @@ export class SchemaCheck extends Message<SchemaCheck> {
{ no: 13, name: "client_traffic_check_skipped", kind: "scalar", T: 8 /* ScalarType.BOOL */ },
{ no: 14, name: "lint_skipped", kind: "scalar", T: 8 /* ScalarType.BOOL */ },
{ no: 15, name: "graph_pruning_skipped", kind: "scalar", T: 8 /* ScalarType.BOOL */ },
{ no: 16, name: "customContext", kind: "message", T: CustomCheckContext, opt: true },
]);

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): SchemaCheck {
Expand Down
1 change: 1 addition & 0 deletions controlplane/migrations/0101_easy_pride.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "schema_checks" ADD COLUMN "custom_context" json;
Loading
Loading