@graphql-inspector/action 3.2.0 → 3.3.0

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.
Files changed (3) hide show
  1. package/index.js +13 -7
  2. package/index.mjs +13 -7
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -12437,8 +12437,14 @@ function getCurrentCommitSha() {
12437
12437
  }
12438
12438
  return sha;
12439
12439
  }
12440
+ function getAssociatedPullRequest(octokit, commitSha) {
12441
+ return tslib.__awaiter(this, void 0, void 0, function* () {
12442
+ const result = yield octokit.request('GET /repos/{owner}/{repo}/commits/{commit_sha}/pulls', Object.assign(Object.assign({}, github$1.context.repo), { commit_sha: commitSha }));
12443
+ return result.data.length > 0 ? result.data[0] : null;
12444
+ });
12445
+ }
12440
12446
  function run() {
12441
- var _a, _b, _c;
12447
+ var _a, _b;
12442
12448
  return tslib.__awaiter(this, void 0, void 0, function* () {
12443
12449
  core.info(`GraphQL Inspector started`);
12444
12450
  // env
@@ -12460,6 +12466,8 @@ function run() {
12460
12466
  const octokit = github$1.getOctokit(token);
12461
12467
  // repo
12462
12468
  const { owner, repo } = github$1.context.repo;
12469
+ // pull request
12470
+ const pullRequest = yield getAssociatedPullRequest(octokit, commitSha);
12463
12471
  core.info(`Creating a check named "${checkName}"`);
12464
12472
  const check = yield octokit.checks.create({
12465
12473
  owner,
@@ -12481,11 +12489,11 @@ function run() {
12481
12489
  return core.setFailed('Failed to find `schema` variable');
12482
12490
  }
12483
12491
  let [schemaRef, schemaPath] = schemaPointer.split(':');
12484
- if (useMerge && github$1.context.payload.pull_request) {
12485
- ref = `refs/pull/${github$1.context.payload.pull_request.number}/merge`;
12492
+ if (useMerge && (pullRequest === null || pullRequest === void 0 ? void 0 : pullRequest.state) == 'open') {
12493
+ ref = `refs/pull/${pullRequest.number}/merge`;
12486
12494
  workspace = undefined;
12487
12495
  core.info(`EXPERIMENTAL - Using Pull Request ${ref}`);
12488
- const baseRef = (_b = (_a = github$1.context.payload.pull_request) === null || _a === void 0 ? void 0 : _a.base) === null || _b === void 0 ? void 0 : _b.ref;
12496
+ const baseRef = (_a = pullRequest.base) === null || _a === void 0 ? void 0 : _a.ref;
12489
12497
  if (baseRef) {
12490
12498
  schemaRef = baseRef;
12491
12499
  core.info(`EXPERIMENTAL - Using ${baseRef} as base schema ref`);
@@ -12546,9 +12554,7 @@ function run() {
12546
12554
  const changes = action.changes || [];
12547
12555
  core.setOutput('changes', `${changes.length || 0}`);
12548
12556
  core.info(`Changes: ${changes.length || 0}`);
12549
- const hasApprovedBreakingChangeLabel = github$1.context.payload.pull_request
12550
- ? (_c = github$1.context.payload.pull_request.labels) === null || _c === void 0 ? void 0 : _c.some((label) => label.name === approveLabel)
12551
- : false;
12557
+ const hasApprovedBreakingChangeLabel = (_b = pullRequest === null || pullRequest === void 0 ? void 0 : pullRequest.labels) === null || _b === void 0 ? void 0 : _b.some((label) => label.name === approveLabel);
12552
12558
  // Force Success when failOnBreaking is disabled
12553
12559
  if ((failOnBreaking === false || hasApprovedBreakingChangeLabel) &&
12554
12560
  conclusion === github.CheckConclusion.Failure) {
package/index.mjs CHANGED
@@ -12435,8 +12435,14 @@ function getCurrentCommitSha() {
12435
12435
  }
12436
12436
  return sha;
12437
12437
  }
12438
+ function getAssociatedPullRequest(octokit, commitSha) {
12439
+ return __awaiter(this, void 0, void 0, function* () {
12440
+ const result = yield octokit.request('GET /repos/{owner}/{repo}/commits/{commit_sha}/pulls', Object.assign(Object.assign({}, context.repo), { commit_sha: commitSha }));
12441
+ return result.data.length > 0 ? result.data[0] : null;
12442
+ });
12443
+ }
12438
12444
  function run() {
12439
- var _a, _b, _c;
12445
+ var _a, _b;
12440
12446
  return __awaiter(this, void 0, void 0, function* () {
12441
12447
  info(`GraphQL Inspector started`);
12442
12448
  // env
@@ -12458,6 +12464,8 @@ function run() {
12458
12464
  const octokit = getOctokit(token);
12459
12465
  // repo
12460
12466
  const { owner, repo } = context.repo;
12467
+ // pull request
12468
+ const pullRequest = yield getAssociatedPullRequest(octokit, commitSha);
12461
12469
  info(`Creating a check named "${checkName}"`);
12462
12470
  const check = yield octokit.checks.create({
12463
12471
  owner,
@@ -12479,11 +12487,11 @@ function run() {
12479
12487
  return setFailed('Failed to find `schema` variable');
12480
12488
  }
12481
12489
  let [schemaRef, schemaPath] = schemaPointer.split(':');
12482
- if (useMerge && context.payload.pull_request) {
12483
- ref = `refs/pull/${context.payload.pull_request.number}/merge`;
12490
+ if (useMerge && (pullRequest === null || pullRequest === void 0 ? void 0 : pullRequest.state) == 'open') {
12491
+ ref = `refs/pull/${pullRequest.number}/merge`;
12484
12492
  workspace = undefined;
12485
12493
  info(`EXPERIMENTAL - Using Pull Request ${ref}`);
12486
- const baseRef = (_b = (_a = context.payload.pull_request) === null || _a === void 0 ? void 0 : _a.base) === null || _b === void 0 ? void 0 : _b.ref;
12494
+ const baseRef = (_a = pullRequest.base) === null || _a === void 0 ? void 0 : _a.ref;
12487
12495
  if (baseRef) {
12488
12496
  schemaRef = baseRef;
12489
12497
  info(`EXPERIMENTAL - Using ${baseRef} as base schema ref`);
@@ -12544,9 +12552,7 @@ function run() {
12544
12552
  const changes = action.changes || [];
12545
12553
  setOutput('changes', `${changes.length || 0}`);
12546
12554
  info(`Changes: ${changes.length || 0}`);
12547
- const hasApprovedBreakingChangeLabel = context.payload.pull_request
12548
- ? (_c = context.payload.pull_request.labels) === null || _c === void 0 ? void 0 : _c.some((label) => label.name === approveLabel)
12549
- : false;
12555
+ const hasApprovedBreakingChangeLabel = (_b = pullRequest === null || pullRequest === void 0 ? void 0 : pullRequest.labels) === null || _b === void 0 ? void 0 : _b.some((label) => label.name === approveLabel);
12550
12556
  // Force Success when failOnBreaking is disabled
12551
12557
  if ((failOnBreaking === false || hasApprovedBreakingChangeLabel) &&
12552
12558
  conclusion === CheckConclusion.Failure) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-inspector/action",
3
- "version": "3.2.0",
3
+ "version": "3.3.0",
4
4
  "description": "GraphQL Inspector functionality for GitHub Actions",
5
5
  "sideEffects": false,
6
6
  "dependencies": {