@graphql-inspector/action 3.4.4 → 3.4.6-alpha-20230227143331-c118a93f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/checks.d.ts +4 -0
- package/files.d.ts +10 -0
- package/git.d.ts +3 -0
- package/index.js +150 -106
- package/index.mjs +153 -109
- package/package.json +3 -2
- package/types.d.ts +2 -0
- package/utils.d.ts +8 -0
package/checks.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { OctokitInstance } from './types';
|
|
2
|
+
declare type UpdateCheckRunOptions = Required<Pick<NonNullable<Parameters<OctokitInstance['checks']['update']>[0]>, 'conclusion' | 'output'>>;
|
|
3
|
+
export declare function updateCheckRun(octokit: OctokitInstance, checkId: number, { conclusion, output }: UpdateCheckRunOptions): Promise<void>;
|
|
4
|
+
export {};
|
package/files.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { OctokitInstance } from './types';
|
|
2
|
+
export declare function fileLoader({ octokit, owner, repo, }: {
|
|
3
|
+
octokit: OctokitInstance;
|
|
4
|
+
owner: string;
|
|
5
|
+
repo: string;
|
|
6
|
+
}): (file: {
|
|
7
|
+
ref: string;
|
|
8
|
+
path: string;
|
|
9
|
+
workspace?: string;
|
|
10
|
+
}) => Promise<string>;
|
package/git.d.ts
ADDED
package/index.js
CHANGED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
const core = require('@actions/core');
|
|
4
4
|
const tslib = require('tslib');
|
|
5
|
-
const child_process = require('child_process');
|
|
6
|
-
const fs = require('fs');
|
|
7
5
|
const path = require('path');
|
|
8
6
|
const github = require('@actions/github');
|
|
9
7
|
const github$1 = require('@graphql-inspector/github');
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const commands = require('@graphql-inspector/commands');
|
|
10
|
+
const core$1 = require('@graphql-inspector/core');
|
|
11
|
+
const child_process = require('child_process');
|
|
10
12
|
|
|
11
13
|
function devAssert(condition, message) {
|
|
12
14
|
const booleanCondition = Boolean(condition);
|
|
@@ -12708,8 +12710,123 @@ function batch(items, limit) {
|
|
|
12708
12710
|
}
|
|
12709
12711
|
return batches;
|
|
12710
12712
|
}
|
|
12713
|
+
/**
|
|
12714
|
+
* Treats non-falsy value as true
|
|
12715
|
+
*/
|
|
12716
|
+
function castToBoolean(value, defaultValue) {
|
|
12717
|
+
if (typeof value === 'boolean') {
|
|
12718
|
+
return value;
|
|
12719
|
+
}
|
|
12720
|
+
if (value === 'true' || value === 'false') {
|
|
12721
|
+
return value === 'true';
|
|
12722
|
+
}
|
|
12723
|
+
if (typeof defaultValue === 'boolean') {
|
|
12724
|
+
return defaultValue;
|
|
12725
|
+
}
|
|
12726
|
+
return true;
|
|
12727
|
+
}
|
|
12728
|
+
function getInputAsArray(name, options) {
|
|
12729
|
+
return core.getInput(name, options)
|
|
12730
|
+
.split('\n')
|
|
12731
|
+
.map(s => s.trim())
|
|
12732
|
+
.filter(x => x !== '');
|
|
12733
|
+
}
|
|
12734
|
+
function resolveRule(name) {
|
|
12735
|
+
const filepath = commands.ensureAbsolute(name);
|
|
12736
|
+
if (fs.existsSync(filepath)) {
|
|
12737
|
+
return require(filepath);
|
|
12738
|
+
}
|
|
12739
|
+
return core$1.DiffRule[name];
|
|
12740
|
+
}
|
|
12741
|
+
|
|
12742
|
+
function updateCheckRun(octokit, checkId, { conclusion, output }) {
|
|
12743
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
12744
|
+
core.info(`Updating check: ${checkId}`);
|
|
12745
|
+
const { title, summary, annotations = [] } = output;
|
|
12746
|
+
const batches = batch(annotations, 50);
|
|
12747
|
+
core.info(`annotations to be sent: ${annotations.length}`);
|
|
12748
|
+
yield octokit.checks.update(Object.assign(Object.assign({ check_run_id: checkId, completed_at: new Date().toISOString(), status: 'completed' }, github.context.repo), { conclusion, output: {
|
|
12749
|
+
title,
|
|
12750
|
+
summary,
|
|
12751
|
+
} }));
|
|
12752
|
+
try {
|
|
12753
|
+
yield Promise.all(batches.map((chunk) => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
12754
|
+
yield octokit.checks.update(Object.assign(Object.assign({ check_run_id: checkId }, github.context.repo), { output: {
|
|
12755
|
+
title,
|
|
12756
|
+
summary,
|
|
12757
|
+
annotations: chunk,
|
|
12758
|
+
} }));
|
|
12759
|
+
core.info(`annotations sent (${chunk.length})`);
|
|
12760
|
+
})));
|
|
12761
|
+
}
|
|
12762
|
+
catch (error) {
|
|
12763
|
+
core.error(`failed to send annotations: ${error}`);
|
|
12764
|
+
throw error;
|
|
12765
|
+
}
|
|
12766
|
+
// Fail
|
|
12767
|
+
if (conclusion === github$1.CheckConclusion.Failure) {
|
|
12768
|
+
return core.setFailed(output.title);
|
|
12769
|
+
}
|
|
12770
|
+
// Success or Neutral
|
|
12771
|
+
});
|
|
12772
|
+
}
|
|
12773
|
+
|
|
12774
|
+
function fileLoader({ octokit, owner, repo, }) {
|
|
12775
|
+
const query = /* GraphQL */ `
|
|
12776
|
+
query GetFile($repo: String!, $owner: String!, $expression: String!) {
|
|
12777
|
+
repository(name: $repo, owner: $owner) {
|
|
12778
|
+
object(expression: $expression) {
|
|
12779
|
+
... on Blob {
|
|
12780
|
+
isTruncated
|
|
12781
|
+
oid
|
|
12782
|
+
text
|
|
12783
|
+
}
|
|
12784
|
+
}
|
|
12785
|
+
}
|
|
12786
|
+
}
|
|
12787
|
+
`;
|
|
12788
|
+
return function loadFile(file) {
|
|
12789
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
12790
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
12791
|
+
if (file.workspace) {
|
|
12792
|
+
return fs.readFileSync(path.resolve(file.workspace, file.path), 'utf8');
|
|
12793
|
+
}
|
|
12794
|
+
const result = yield octokit.graphql(query, {
|
|
12795
|
+
repo,
|
|
12796
|
+
owner,
|
|
12797
|
+
expression: `${file.ref}:${file.path}`,
|
|
12798
|
+
});
|
|
12799
|
+
core.info(`Query ${file.ref}:${file.path} from ${owner}/${repo}`);
|
|
12800
|
+
try {
|
|
12801
|
+
if (((_b = (_a = result === null || result === void 0 ? void 0 : result.repository) === null || _a === void 0 ? void 0 : _a.object) === null || _b === void 0 ? void 0 : _b.oid) && ((_d = (_c = result === null || result === void 0 ? void 0 : result.repository) === null || _c === void 0 ? void 0 : _c.object) === null || _d === void 0 ? void 0 : _d.isTruncated)) {
|
|
12802
|
+
const oid = (_f = (_e = result === null || result === void 0 ? void 0 : result.repository) === null || _e === void 0 ? void 0 : _e.object) === null || _f === void 0 ? void 0 : _f.oid;
|
|
12803
|
+
const getBlobResponse = yield octokit.git.getBlob({
|
|
12804
|
+
owner,
|
|
12805
|
+
repo,
|
|
12806
|
+
file_sha: oid,
|
|
12807
|
+
});
|
|
12808
|
+
if ((_g = getBlobResponse === null || getBlobResponse === void 0 ? void 0 : getBlobResponse.data) === null || _g === void 0 ? void 0 : _g.content) {
|
|
12809
|
+
return Buffer.from((_h = getBlobResponse === null || getBlobResponse === void 0 ? void 0 : getBlobResponse.data) === null || _h === void 0 ? void 0 : _h.content, 'base64').toString('utf-8');
|
|
12810
|
+
}
|
|
12811
|
+
throw new Error('getBlobResponse.data.content is null');
|
|
12812
|
+
}
|
|
12813
|
+
if ((_k = (_j = result === null || result === void 0 ? void 0 : result.repository) === null || _j === void 0 ? void 0 : _j.object) === null || _k === void 0 ? void 0 : _k.text) {
|
|
12814
|
+
if (((_m = (_l = result === null || result === void 0 ? void 0 : result.repository) === null || _l === void 0 ? void 0 : _l.object) === null || _m === void 0 ? void 0 : _m.isTruncated) === false) {
|
|
12815
|
+
return result.repository.object.text;
|
|
12816
|
+
}
|
|
12817
|
+
throw new Error('result.repository.object.text is truncated and oid is null');
|
|
12818
|
+
}
|
|
12819
|
+
throw new Error('result.repository.object.text is null');
|
|
12820
|
+
}
|
|
12821
|
+
catch (error) {
|
|
12822
|
+
console.log(result);
|
|
12823
|
+
console.error(error);
|
|
12824
|
+
throw new Error(`Failed to load '${file.path}' (ref: ${file.ref})`);
|
|
12825
|
+
}
|
|
12826
|
+
});
|
|
12827
|
+
};
|
|
12828
|
+
}
|
|
12711
12829
|
|
|
12712
|
-
const CHECK_NAME = 'GraphQL Inspector';
|
|
12713
12830
|
function getCurrentCommitSha() {
|
|
12714
12831
|
const sha = child_process.execSync(`git rev-parse HEAD`).toString().trim();
|
|
12715
12832
|
try {
|
|
@@ -12736,6 +12853,8 @@ function getAssociatedPullRequest(octokit, commitSha) {
|
|
|
12736
12853
|
return result.data.length > 0 ? result.data[0] : null;
|
|
12737
12854
|
});
|
|
12738
12855
|
}
|
|
12856
|
+
|
|
12857
|
+
const CHECK_NAME = 'GraphQL Inspector';
|
|
12739
12858
|
function run() {
|
|
12740
12859
|
var _a, _b;
|
|
12741
12860
|
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
@@ -12756,6 +12875,8 @@ function run() {
|
|
|
12756
12875
|
const failOnBreaking = castToBoolean(core.getInput('fail-on-breaking'));
|
|
12757
12876
|
const endpoint = core.getInput('endpoint');
|
|
12758
12877
|
const approveLabel = core.getInput('approve-label') || 'approved-breaking-change';
|
|
12878
|
+
const rulesList = getInputAsArray('rules') || [];
|
|
12879
|
+
const onUsage = core.getInput('getUsage');
|
|
12759
12880
|
const octokit = github.getOctokit(token);
|
|
12760
12881
|
// repo
|
|
12761
12882
|
const { owner, repo } = github.context.repo;
|
|
@@ -12781,6 +12902,28 @@ function run() {
|
|
|
12781
12902
|
core.error('No `schema` variable');
|
|
12782
12903
|
return core.setFailed('Failed to find `schema` variable');
|
|
12783
12904
|
}
|
|
12905
|
+
const rules = rulesList
|
|
12906
|
+
.map(r => {
|
|
12907
|
+
const rule = resolveRule(r);
|
|
12908
|
+
if (!rule) {
|
|
12909
|
+
core.error(`Rule ${r} is invalid. Did you specify the correct path?`);
|
|
12910
|
+
}
|
|
12911
|
+
return rule;
|
|
12912
|
+
})
|
|
12913
|
+
.filter(Boolean);
|
|
12914
|
+
// Different lengths mean some rules were resolved to undefined
|
|
12915
|
+
if (rules.length !== rulesList.length) {
|
|
12916
|
+
return core.setFailed("Some rules weren't recognised");
|
|
12917
|
+
}
|
|
12918
|
+
let config;
|
|
12919
|
+
if (onUsage) {
|
|
12920
|
+
const checkUsage = require(onUsage);
|
|
12921
|
+
if (checkUsage) {
|
|
12922
|
+
config = {
|
|
12923
|
+
checkUsage,
|
|
12924
|
+
};
|
|
12925
|
+
}
|
|
12926
|
+
}
|
|
12784
12927
|
let [schemaRef, schemaPath] = schemaPointer.split(':');
|
|
12785
12928
|
if (useMerge && (pullRequest === null || pullRequest === void 0 ? void 0 : pullRequest.state) == 'open') {
|
|
12786
12929
|
ref = `refs/pull/${pullRequest.number}/merge`;
|
|
@@ -12815,7 +12958,7 @@ function run() {
|
|
|
12815
12958
|
let oldSchema;
|
|
12816
12959
|
let newSchema;
|
|
12817
12960
|
let sources;
|
|
12818
|
-
if (path.extname(schemaPath.toLowerCase()) ===
|
|
12961
|
+
if (path.extname(schemaPath.toLowerCase()) === '.json') {
|
|
12819
12962
|
oldSchema = endpoint ? buildSchema(oldFile) : buildClientSchema(JSON.parse(oldFile));
|
|
12820
12963
|
newSchema = buildClientSchema(JSON.parse(newFile));
|
|
12821
12964
|
sources = {
|
|
@@ -12841,6 +12984,8 @@ function run() {
|
|
|
12841
12984
|
path: schemaPath,
|
|
12842
12985
|
schemas,
|
|
12843
12986
|
sources,
|
|
12987
|
+
rules,
|
|
12988
|
+
config,
|
|
12844
12989
|
});
|
|
12845
12990
|
let conclusion = action.conclusion;
|
|
12846
12991
|
let annotations = action.annotations || [];
|
|
@@ -12881,108 +13026,7 @@ function run() {
|
|
|
12881
13026
|
}
|
|
12882
13027
|
});
|
|
12883
13028
|
}
|
|
12884
|
-
function fileLoader({ octokit, owner, repo, }) {
|
|
12885
|
-
const query = /* GraphQL */ `
|
|
12886
|
-
query GetFile($repo: String!, $owner: String!, $expression: String!) {
|
|
12887
|
-
repository(name: $repo, owner: $owner) {
|
|
12888
|
-
object(expression: $expression) {
|
|
12889
|
-
... on Blob {
|
|
12890
|
-
isTruncated
|
|
12891
|
-
oid
|
|
12892
|
-
text
|
|
12893
|
-
}
|
|
12894
|
-
}
|
|
12895
|
-
}
|
|
12896
|
-
}
|
|
12897
|
-
`;
|
|
12898
|
-
return function loadFile(file) {
|
|
12899
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
12900
|
-
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
12901
|
-
if (file.workspace) {
|
|
12902
|
-
return fs.readFileSync(path.resolve(file.workspace, file.path), 'utf8');
|
|
12903
|
-
}
|
|
12904
|
-
const result = yield octokit.graphql(query, {
|
|
12905
|
-
repo,
|
|
12906
|
-
owner,
|
|
12907
|
-
expression: `${file.ref}:${file.path}`,
|
|
12908
|
-
});
|
|
12909
|
-
core.info(`Query ${file.ref}:${file.path} from ${owner}/${repo}`);
|
|
12910
|
-
try {
|
|
12911
|
-
if (((_b = (_a = result === null || result === void 0 ? void 0 : result.repository) === null || _a === void 0 ? void 0 : _a.object) === null || _b === void 0 ? void 0 : _b.oid) && ((_d = (_c = result === null || result === void 0 ? void 0 : result.repository) === null || _c === void 0 ? void 0 : _c.object) === null || _d === void 0 ? void 0 : _d.isTruncated)) {
|
|
12912
|
-
const oid = (_f = (_e = result === null || result === void 0 ? void 0 : result.repository) === null || _e === void 0 ? void 0 : _e.object) === null || _f === void 0 ? void 0 : _f.oid;
|
|
12913
|
-
const getBlobResponse = yield octokit.git.getBlob({
|
|
12914
|
-
owner,
|
|
12915
|
-
repo,
|
|
12916
|
-
file_sha: oid,
|
|
12917
|
-
});
|
|
12918
|
-
if ((_g = getBlobResponse === null || getBlobResponse === void 0 ? void 0 : getBlobResponse.data) === null || _g === void 0 ? void 0 : _g.content) {
|
|
12919
|
-
return Buffer.from((_h = getBlobResponse === null || getBlobResponse === void 0 ? void 0 : getBlobResponse.data) === null || _h === void 0 ? void 0 : _h.content, 'base64').toString('utf-8');
|
|
12920
|
-
}
|
|
12921
|
-
throw new Error('getBlobResponse.data.content is null');
|
|
12922
|
-
}
|
|
12923
|
-
if ((_k = (_j = result === null || result === void 0 ? void 0 : result.repository) === null || _j === void 0 ? void 0 : _j.object) === null || _k === void 0 ? void 0 : _k.text) {
|
|
12924
|
-
if (((_m = (_l = result === null || result === void 0 ? void 0 : result.repository) === null || _l === void 0 ? void 0 : _l.object) === null || _m === void 0 ? void 0 : _m.isTruncated) === false) {
|
|
12925
|
-
return result.repository.object.text;
|
|
12926
|
-
}
|
|
12927
|
-
throw new Error('result.repository.object.text is truncated and oid is null');
|
|
12928
|
-
}
|
|
12929
|
-
throw new Error('result.repository.object.text is null');
|
|
12930
|
-
}
|
|
12931
|
-
catch (error) {
|
|
12932
|
-
console.log(result);
|
|
12933
|
-
console.error(error);
|
|
12934
|
-
throw new Error(`Failed to load '${file.path}' (ref: ${file.ref})`);
|
|
12935
|
-
}
|
|
12936
|
-
});
|
|
12937
|
-
};
|
|
12938
|
-
}
|
|
12939
|
-
function updateCheckRun(octokit, checkId, { conclusion, output }) {
|
|
12940
|
-
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
12941
|
-
core.info(`Updating check: ${checkId}`);
|
|
12942
|
-
const { title, summary, annotations = [] } = output;
|
|
12943
|
-
const batches = batch(annotations, 50);
|
|
12944
|
-
core.info(`annotations to be sent: ${annotations.length}`);
|
|
12945
|
-
yield octokit.checks.update(Object.assign(Object.assign({ check_run_id: checkId, completed_at: new Date().toISOString(), status: 'completed' }, github.context.repo), { conclusion, output: {
|
|
12946
|
-
title,
|
|
12947
|
-
summary,
|
|
12948
|
-
} }));
|
|
12949
|
-
try {
|
|
12950
|
-
yield Promise.all(batches.map((chunk) => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
12951
|
-
yield octokit.checks.update(Object.assign(Object.assign({ check_run_id: checkId }, github.context.repo), { output: {
|
|
12952
|
-
title,
|
|
12953
|
-
summary,
|
|
12954
|
-
annotations: chunk,
|
|
12955
|
-
} }));
|
|
12956
|
-
core.info(`annotations sent (${chunk.length})`);
|
|
12957
|
-
})));
|
|
12958
|
-
}
|
|
12959
|
-
catch (error) {
|
|
12960
|
-
core.error(`failed to send annotations: ${error}`);
|
|
12961
|
-
throw error;
|
|
12962
|
-
}
|
|
12963
|
-
// Fail
|
|
12964
|
-
if (conclusion === github$1.CheckConclusion.Failure) {
|
|
12965
|
-
return core.setFailed(output.title);
|
|
12966
|
-
}
|
|
12967
|
-
// Success or Neutral
|
|
12968
|
-
});
|
|
12969
|
-
}
|
|
12970
|
-
/**
|
|
12971
|
-
* Treats non-falsy value as true
|
|
12972
|
-
*/
|
|
12973
|
-
function castToBoolean(value, defaultValue) {
|
|
12974
|
-
if (typeof value === 'boolean') {
|
|
12975
|
-
return value;
|
|
12976
|
-
}
|
|
12977
|
-
if (value === 'true' || value === 'false') {
|
|
12978
|
-
return value === 'true';
|
|
12979
|
-
}
|
|
12980
|
-
if (typeof defaultValue === 'boolean') {
|
|
12981
|
-
return defaultValue;
|
|
12982
|
-
}
|
|
12983
|
-
return true;
|
|
12984
|
-
}
|
|
12985
13029
|
|
|
12986
|
-
run().catch(
|
|
13030
|
+
run().catch(e => {
|
|
12987
13031
|
core.setFailed(e.message || e);
|
|
12988
13032
|
});
|
package/index.mjs
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { info,
|
|
1
|
+
import { getInput, info, error, setFailed, setOutput } from '@actions/core';
|
|
2
2
|
import { __awaiter } from 'tslib';
|
|
3
|
-
import { execSync } from 'child_process';
|
|
4
|
-
import { readFileSync } from 'fs';
|
|
5
3
|
import { resolve, extname } from 'path';
|
|
6
|
-
import {
|
|
7
|
-
import { printSchemaFromEndpoint, produceSchema, diff,
|
|
4
|
+
import { context, getOctokit } from '@actions/github';
|
|
5
|
+
import { CheckConclusion, printSchemaFromEndpoint, produceSchema, diff, createSummary } from '@graphql-inspector/github';
|
|
6
|
+
import { existsSync, readFileSync } from 'fs';
|
|
7
|
+
import { ensureAbsolute } from '@graphql-inspector/commands';
|
|
8
|
+
import { DiffRule } from '@graphql-inspector/core';
|
|
9
|
+
import { execSync } from 'child_process';
|
|
8
10
|
|
|
9
11
|
function devAssert(condition, message) {
|
|
10
12
|
const booleanCondition = Boolean(condition);
|
|
@@ -12706,8 +12708,123 @@ function batch(items, limit) {
|
|
|
12706
12708
|
}
|
|
12707
12709
|
return batches;
|
|
12708
12710
|
}
|
|
12711
|
+
/**
|
|
12712
|
+
* Treats non-falsy value as true
|
|
12713
|
+
*/
|
|
12714
|
+
function castToBoolean(value, defaultValue) {
|
|
12715
|
+
if (typeof value === 'boolean') {
|
|
12716
|
+
return value;
|
|
12717
|
+
}
|
|
12718
|
+
if (value === 'true' || value === 'false') {
|
|
12719
|
+
return value === 'true';
|
|
12720
|
+
}
|
|
12721
|
+
if (typeof defaultValue === 'boolean') {
|
|
12722
|
+
return defaultValue;
|
|
12723
|
+
}
|
|
12724
|
+
return true;
|
|
12725
|
+
}
|
|
12726
|
+
function getInputAsArray(name, options) {
|
|
12727
|
+
return getInput(name, options)
|
|
12728
|
+
.split('\n')
|
|
12729
|
+
.map(s => s.trim())
|
|
12730
|
+
.filter(x => x !== '');
|
|
12731
|
+
}
|
|
12732
|
+
function resolveRule(name) {
|
|
12733
|
+
const filepath = ensureAbsolute(name);
|
|
12734
|
+
if (existsSync(filepath)) {
|
|
12735
|
+
return require(filepath);
|
|
12736
|
+
}
|
|
12737
|
+
return DiffRule[name];
|
|
12738
|
+
}
|
|
12739
|
+
|
|
12740
|
+
function updateCheckRun(octokit, checkId, { conclusion, output }) {
|
|
12741
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
12742
|
+
info(`Updating check: ${checkId}`);
|
|
12743
|
+
const { title, summary, annotations = [] } = output;
|
|
12744
|
+
const batches = batch(annotations, 50);
|
|
12745
|
+
info(`annotations to be sent: ${annotations.length}`);
|
|
12746
|
+
yield octokit.checks.update(Object.assign(Object.assign({ check_run_id: checkId, completed_at: new Date().toISOString(), status: 'completed' }, context.repo), { conclusion, output: {
|
|
12747
|
+
title,
|
|
12748
|
+
summary,
|
|
12749
|
+
} }));
|
|
12750
|
+
try {
|
|
12751
|
+
yield Promise.all(batches.map((chunk) => __awaiter(this, void 0, void 0, function* () {
|
|
12752
|
+
yield octokit.checks.update(Object.assign(Object.assign({ check_run_id: checkId }, context.repo), { output: {
|
|
12753
|
+
title,
|
|
12754
|
+
summary,
|
|
12755
|
+
annotations: chunk,
|
|
12756
|
+
} }));
|
|
12757
|
+
info(`annotations sent (${chunk.length})`);
|
|
12758
|
+
})));
|
|
12759
|
+
}
|
|
12760
|
+
catch (error$1) {
|
|
12761
|
+
error(`failed to send annotations: ${error$1}`);
|
|
12762
|
+
throw error$1;
|
|
12763
|
+
}
|
|
12764
|
+
// Fail
|
|
12765
|
+
if (conclusion === CheckConclusion.Failure) {
|
|
12766
|
+
return setFailed(output.title);
|
|
12767
|
+
}
|
|
12768
|
+
// Success or Neutral
|
|
12769
|
+
});
|
|
12770
|
+
}
|
|
12771
|
+
|
|
12772
|
+
function fileLoader({ octokit, owner, repo, }) {
|
|
12773
|
+
const query = /* GraphQL */ `
|
|
12774
|
+
query GetFile($repo: String!, $owner: String!, $expression: String!) {
|
|
12775
|
+
repository(name: $repo, owner: $owner) {
|
|
12776
|
+
object(expression: $expression) {
|
|
12777
|
+
... on Blob {
|
|
12778
|
+
isTruncated
|
|
12779
|
+
oid
|
|
12780
|
+
text
|
|
12781
|
+
}
|
|
12782
|
+
}
|
|
12783
|
+
}
|
|
12784
|
+
}
|
|
12785
|
+
`;
|
|
12786
|
+
return function loadFile(file) {
|
|
12787
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
12788
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
12789
|
+
if (file.workspace) {
|
|
12790
|
+
return readFileSync(resolve(file.workspace, file.path), 'utf8');
|
|
12791
|
+
}
|
|
12792
|
+
const result = yield octokit.graphql(query, {
|
|
12793
|
+
repo,
|
|
12794
|
+
owner,
|
|
12795
|
+
expression: `${file.ref}:${file.path}`,
|
|
12796
|
+
});
|
|
12797
|
+
info(`Query ${file.ref}:${file.path} from ${owner}/${repo}`);
|
|
12798
|
+
try {
|
|
12799
|
+
if (((_b = (_a = result === null || result === void 0 ? void 0 : result.repository) === null || _a === void 0 ? void 0 : _a.object) === null || _b === void 0 ? void 0 : _b.oid) && ((_d = (_c = result === null || result === void 0 ? void 0 : result.repository) === null || _c === void 0 ? void 0 : _c.object) === null || _d === void 0 ? void 0 : _d.isTruncated)) {
|
|
12800
|
+
const oid = (_f = (_e = result === null || result === void 0 ? void 0 : result.repository) === null || _e === void 0 ? void 0 : _e.object) === null || _f === void 0 ? void 0 : _f.oid;
|
|
12801
|
+
const getBlobResponse = yield octokit.git.getBlob({
|
|
12802
|
+
owner,
|
|
12803
|
+
repo,
|
|
12804
|
+
file_sha: oid,
|
|
12805
|
+
});
|
|
12806
|
+
if ((_g = getBlobResponse === null || getBlobResponse === void 0 ? void 0 : getBlobResponse.data) === null || _g === void 0 ? void 0 : _g.content) {
|
|
12807
|
+
return Buffer.from((_h = getBlobResponse === null || getBlobResponse === void 0 ? void 0 : getBlobResponse.data) === null || _h === void 0 ? void 0 : _h.content, 'base64').toString('utf-8');
|
|
12808
|
+
}
|
|
12809
|
+
throw new Error('getBlobResponse.data.content is null');
|
|
12810
|
+
}
|
|
12811
|
+
if ((_k = (_j = result === null || result === void 0 ? void 0 : result.repository) === null || _j === void 0 ? void 0 : _j.object) === null || _k === void 0 ? void 0 : _k.text) {
|
|
12812
|
+
if (((_m = (_l = result === null || result === void 0 ? void 0 : result.repository) === null || _l === void 0 ? void 0 : _l.object) === null || _m === void 0 ? void 0 : _m.isTruncated) === false) {
|
|
12813
|
+
return result.repository.object.text;
|
|
12814
|
+
}
|
|
12815
|
+
throw new Error('result.repository.object.text is truncated and oid is null');
|
|
12816
|
+
}
|
|
12817
|
+
throw new Error('result.repository.object.text is null');
|
|
12818
|
+
}
|
|
12819
|
+
catch (error) {
|
|
12820
|
+
console.log(result);
|
|
12821
|
+
console.error(error);
|
|
12822
|
+
throw new Error(`Failed to load '${file.path}' (ref: ${file.ref})`);
|
|
12823
|
+
}
|
|
12824
|
+
});
|
|
12825
|
+
};
|
|
12826
|
+
}
|
|
12709
12827
|
|
|
12710
|
-
const CHECK_NAME = 'GraphQL Inspector';
|
|
12711
12828
|
function getCurrentCommitSha() {
|
|
12712
12829
|
const sha = execSync(`git rev-parse HEAD`).toString().trim();
|
|
12713
12830
|
try {
|
|
@@ -12734,6 +12851,8 @@ function getAssociatedPullRequest(octokit, commitSha) {
|
|
|
12734
12851
|
return result.data.length > 0 ? result.data[0] : null;
|
|
12735
12852
|
});
|
|
12736
12853
|
}
|
|
12854
|
+
|
|
12855
|
+
const CHECK_NAME = 'GraphQL Inspector';
|
|
12737
12856
|
function run() {
|
|
12738
12857
|
var _a, _b;
|
|
12739
12858
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -12754,6 +12873,8 @@ function run() {
|
|
|
12754
12873
|
const failOnBreaking = castToBoolean(getInput('fail-on-breaking'));
|
|
12755
12874
|
const endpoint = getInput('endpoint');
|
|
12756
12875
|
const approveLabel = getInput('approve-label') || 'approved-breaking-change';
|
|
12876
|
+
const rulesList = getInputAsArray('rules') || [];
|
|
12877
|
+
const onUsage = getInput('getUsage');
|
|
12757
12878
|
const octokit = getOctokit(token);
|
|
12758
12879
|
// repo
|
|
12759
12880
|
const { owner, repo } = context.repo;
|
|
@@ -12779,6 +12900,28 @@ function run() {
|
|
|
12779
12900
|
error('No `schema` variable');
|
|
12780
12901
|
return setFailed('Failed to find `schema` variable');
|
|
12781
12902
|
}
|
|
12903
|
+
const rules = rulesList
|
|
12904
|
+
.map(r => {
|
|
12905
|
+
const rule = resolveRule(r);
|
|
12906
|
+
if (!rule) {
|
|
12907
|
+
error(`Rule ${r} is invalid. Did you specify the correct path?`);
|
|
12908
|
+
}
|
|
12909
|
+
return rule;
|
|
12910
|
+
})
|
|
12911
|
+
.filter(Boolean);
|
|
12912
|
+
// Different lengths mean some rules were resolved to undefined
|
|
12913
|
+
if (rules.length !== rulesList.length) {
|
|
12914
|
+
return setFailed("Some rules weren't recognised");
|
|
12915
|
+
}
|
|
12916
|
+
let config;
|
|
12917
|
+
if (onUsage) {
|
|
12918
|
+
const checkUsage = require(onUsage);
|
|
12919
|
+
if (checkUsage) {
|
|
12920
|
+
config = {
|
|
12921
|
+
checkUsage,
|
|
12922
|
+
};
|
|
12923
|
+
}
|
|
12924
|
+
}
|
|
12782
12925
|
let [schemaRef, schemaPath] = schemaPointer.split(':');
|
|
12783
12926
|
if (useMerge && (pullRequest === null || pullRequest === void 0 ? void 0 : pullRequest.state) == 'open') {
|
|
12784
12927
|
ref = `refs/pull/${pullRequest.number}/merge`;
|
|
@@ -12813,7 +12956,7 @@ function run() {
|
|
|
12813
12956
|
let oldSchema;
|
|
12814
12957
|
let newSchema;
|
|
12815
12958
|
let sources;
|
|
12816
|
-
if (extname(schemaPath.toLowerCase()) ===
|
|
12959
|
+
if (extname(schemaPath.toLowerCase()) === '.json') {
|
|
12817
12960
|
oldSchema = endpoint ? buildSchema(oldFile) : buildClientSchema(JSON.parse(oldFile));
|
|
12818
12961
|
newSchema = buildClientSchema(JSON.parse(newFile));
|
|
12819
12962
|
sources = {
|
|
@@ -12839,6 +12982,8 @@ function run() {
|
|
|
12839
12982
|
path: schemaPath,
|
|
12840
12983
|
schemas,
|
|
12841
12984
|
sources,
|
|
12985
|
+
rules,
|
|
12986
|
+
config,
|
|
12842
12987
|
});
|
|
12843
12988
|
let conclusion = action.conclusion;
|
|
12844
12989
|
let annotations = action.annotations || [];
|
|
@@ -12879,108 +13024,7 @@ function run() {
|
|
|
12879
13024
|
}
|
|
12880
13025
|
});
|
|
12881
13026
|
}
|
|
12882
|
-
function fileLoader({ octokit, owner, repo, }) {
|
|
12883
|
-
const query = /* GraphQL */ `
|
|
12884
|
-
query GetFile($repo: String!, $owner: String!, $expression: String!) {
|
|
12885
|
-
repository(name: $repo, owner: $owner) {
|
|
12886
|
-
object(expression: $expression) {
|
|
12887
|
-
... on Blob {
|
|
12888
|
-
isTruncated
|
|
12889
|
-
oid
|
|
12890
|
-
text
|
|
12891
|
-
}
|
|
12892
|
-
}
|
|
12893
|
-
}
|
|
12894
|
-
}
|
|
12895
|
-
`;
|
|
12896
|
-
return function loadFile(file) {
|
|
12897
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
12898
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
12899
|
-
if (file.workspace) {
|
|
12900
|
-
return readFileSync(resolve(file.workspace, file.path), 'utf8');
|
|
12901
|
-
}
|
|
12902
|
-
const result = yield octokit.graphql(query, {
|
|
12903
|
-
repo,
|
|
12904
|
-
owner,
|
|
12905
|
-
expression: `${file.ref}:${file.path}`,
|
|
12906
|
-
});
|
|
12907
|
-
info(`Query ${file.ref}:${file.path} from ${owner}/${repo}`);
|
|
12908
|
-
try {
|
|
12909
|
-
if (((_b = (_a = result === null || result === void 0 ? void 0 : result.repository) === null || _a === void 0 ? void 0 : _a.object) === null || _b === void 0 ? void 0 : _b.oid) && ((_d = (_c = result === null || result === void 0 ? void 0 : result.repository) === null || _c === void 0 ? void 0 : _c.object) === null || _d === void 0 ? void 0 : _d.isTruncated)) {
|
|
12910
|
-
const oid = (_f = (_e = result === null || result === void 0 ? void 0 : result.repository) === null || _e === void 0 ? void 0 : _e.object) === null || _f === void 0 ? void 0 : _f.oid;
|
|
12911
|
-
const getBlobResponse = yield octokit.git.getBlob({
|
|
12912
|
-
owner,
|
|
12913
|
-
repo,
|
|
12914
|
-
file_sha: oid,
|
|
12915
|
-
});
|
|
12916
|
-
if ((_g = getBlobResponse === null || getBlobResponse === void 0 ? void 0 : getBlobResponse.data) === null || _g === void 0 ? void 0 : _g.content) {
|
|
12917
|
-
return Buffer.from((_h = getBlobResponse === null || getBlobResponse === void 0 ? void 0 : getBlobResponse.data) === null || _h === void 0 ? void 0 : _h.content, 'base64').toString('utf-8');
|
|
12918
|
-
}
|
|
12919
|
-
throw new Error('getBlobResponse.data.content is null');
|
|
12920
|
-
}
|
|
12921
|
-
if ((_k = (_j = result === null || result === void 0 ? void 0 : result.repository) === null || _j === void 0 ? void 0 : _j.object) === null || _k === void 0 ? void 0 : _k.text) {
|
|
12922
|
-
if (((_m = (_l = result === null || result === void 0 ? void 0 : result.repository) === null || _l === void 0 ? void 0 : _l.object) === null || _m === void 0 ? void 0 : _m.isTruncated) === false) {
|
|
12923
|
-
return result.repository.object.text;
|
|
12924
|
-
}
|
|
12925
|
-
throw new Error('result.repository.object.text is truncated and oid is null');
|
|
12926
|
-
}
|
|
12927
|
-
throw new Error('result.repository.object.text is null');
|
|
12928
|
-
}
|
|
12929
|
-
catch (error) {
|
|
12930
|
-
console.log(result);
|
|
12931
|
-
console.error(error);
|
|
12932
|
-
throw new Error(`Failed to load '${file.path}' (ref: ${file.ref})`);
|
|
12933
|
-
}
|
|
12934
|
-
});
|
|
12935
|
-
};
|
|
12936
|
-
}
|
|
12937
|
-
function updateCheckRun(octokit, checkId, { conclusion, output }) {
|
|
12938
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
12939
|
-
info(`Updating check: ${checkId}`);
|
|
12940
|
-
const { title, summary, annotations = [] } = output;
|
|
12941
|
-
const batches = batch(annotations, 50);
|
|
12942
|
-
info(`annotations to be sent: ${annotations.length}`);
|
|
12943
|
-
yield octokit.checks.update(Object.assign(Object.assign({ check_run_id: checkId, completed_at: new Date().toISOString(), status: 'completed' }, context.repo), { conclusion, output: {
|
|
12944
|
-
title,
|
|
12945
|
-
summary,
|
|
12946
|
-
} }));
|
|
12947
|
-
try {
|
|
12948
|
-
yield Promise.all(batches.map((chunk) => __awaiter(this, void 0, void 0, function* () {
|
|
12949
|
-
yield octokit.checks.update(Object.assign(Object.assign({ check_run_id: checkId }, context.repo), { output: {
|
|
12950
|
-
title,
|
|
12951
|
-
summary,
|
|
12952
|
-
annotations: chunk,
|
|
12953
|
-
} }));
|
|
12954
|
-
info(`annotations sent (${chunk.length})`);
|
|
12955
|
-
})));
|
|
12956
|
-
}
|
|
12957
|
-
catch (error$1) {
|
|
12958
|
-
error(`failed to send annotations: ${error$1}`);
|
|
12959
|
-
throw error$1;
|
|
12960
|
-
}
|
|
12961
|
-
// Fail
|
|
12962
|
-
if (conclusion === CheckConclusion.Failure) {
|
|
12963
|
-
return setFailed(output.title);
|
|
12964
|
-
}
|
|
12965
|
-
// Success or Neutral
|
|
12966
|
-
});
|
|
12967
|
-
}
|
|
12968
|
-
/**
|
|
12969
|
-
* Treats non-falsy value as true
|
|
12970
|
-
*/
|
|
12971
|
-
function castToBoolean(value, defaultValue) {
|
|
12972
|
-
if (typeof value === 'boolean') {
|
|
12973
|
-
return value;
|
|
12974
|
-
}
|
|
12975
|
-
if (value === 'true' || value === 'false') {
|
|
12976
|
-
return value === 'true';
|
|
12977
|
-
}
|
|
12978
|
-
if (typeof defaultValue === 'boolean') {
|
|
12979
|
-
return defaultValue;
|
|
12980
|
-
}
|
|
12981
|
-
return true;
|
|
12982
|
-
}
|
|
12983
13027
|
|
|
12984
|
-
run().catch(
|
|
13028
|
+
run().catch(e => {
|
|
12985
13029
|
setFailed(e.message || e);
|
|
12986
13030
|
});
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-inspector/action",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.6-alpha-20230227143331-c118a93f",
|
|
4
4
|
"description": "GraphQL Inspector functionality for GitHub Actions",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"dependencies": {
|
|
7
|
+
"js-yaml": "4.1.0",
|
|
7
8
|
"probot": "12.3.0"
|
|
8
9
|
},
|
|
9
10
|
"repository": {
|
|
@@ -45,4 +46,4 @@
|
|
|
45
46
|
"bin": {
|
|
46
47
|
"graphql-inspector-github": "./index.js"
|
|
47
48
|
}
|
|
48
|
-
}
|
|
49
|
+
}
|
package/types.d.ts
ADDED
package/utils.d.ts
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
+
import * as core from '@actions/core';
|
|
2
|
+
import { Rule } from '@graphql-inspector/core';
|
|
1
3
|
export declare function batch<T>(items: T[], limit: number): T[][];
|
|
4
|
+
/**
|
|
5
|
+
* Treats non-falsy value as true
|
|
6
|
+
*/
|
|
7
|
+
export declare function castToBoolean(value: string | boolean, defaultValue?: boolean): boolean;
|
|
8
|
+
export declare function getInputAsArray(name: string, options?: core.InputOptions): string[];
|
|
9
|
+
export declare function resolveRule(name: string): Rule | undefined;
|