Skip to content

Commit aecc098

Browse files
Merge pull request #53 from bit-tasks/dev
checking lane exist
2 parents d81081f + b7f9e49 commit aecc098

4 files changed

Lines changed: 88 additions & 1 deletion

File tree

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ jobs:
2727
- name: Add remote scope
2828
run: cd test-data && bit remote add http://localhost:4000
2929
- name: Bit Pull Request
30-
uses: bit-tasks/pull-request@main
30+
uses: bit-tasks/pull-request@dev
3131
- name: Bit Lanes
3232
run: cd test-data && bit lane list --details

dist/index.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10908,6 +10908,40 @@ catch (error) {
1090810908
}
1090910909

1091010910

10911+
/***/ }),
10912+
10913+
/***/ 8946:
10914+
/***/ ((__unused_webpack_module, exports) => {
10915+
10916+
"use strict";
10917+
10918+
Object.defineProperty(exports, "__esModule", ({ value: true }));
10919+
exports.scopeQuery = void 0;
10920+
const GRAPHQL_ENDPOINT = 'https://api.v2.bit.cloud/graphql';
10921+
const scopeQuery = (id, token) => {
10922+
const query = `
10923+
query GET_SCOPE($scopeId: String!) {
10924+
getScope(id: $scopeId) {
10925+
id
10926+
}
10927+
}
10928+
`;
10929+
const variables = { scopeId: id };
10930+
return fetch(GRAPHQL_ENDPOINT, {
10931+
method: 'POST',
10932+
headers: {
10933+
'Content-Type': 'application/json',
10934+
Authorization: `Bearer ${token}`,
10935+
},
10936+
body: JSON.stringify({
10937+
query,
10938+
variables,
10939+
}),
10940+
}).then(response => response.json());
10941+
};
10942+
exports.scopeQuery = scopeQuery;
10943+
10944+
1091110945
/***/ }),
1091210946

1091310947
/***/ 595:
@@ -10951,6 +10985,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
1095110985
const exec_1 = __nccwpck_require__(1514);
1095210986
const github_1 = __nccwpck_require__(5438);
1095310987
const core = __importStar(__nccwpck_require__(2186));
10988+
const graphql_1 = __nccwpck_require__(8946);
1095410989
const createSnapMessageText = (githubToken, repo, owner, prNumber) => __awaiter(void 0, void 0, void 0, function* () {
1095510990
const octokit = (0, github_1.getOctokit)(githubToken);
1095610991
let messageText = "CI";
@@ -11099,10 +11134,23 @@ const createVersionLabels = (githubToken, repo, owner, prNumber, status, version
1109911134
}
1110011135
});
1110111136
function run(githubToken, repo, owner, prNumber, laneName, versionLabel, versionLabelsColors, wsDir, args) {
11137+
var _a, _b;
1110211138
return __awaiter(this, void 0, void 0, function* () {
1110311139
const org = process.env.ORG;
1110411140
const scope = process.env.SCOPE;
11141+
const token = process.env.BIT_CONFIG_USER_TOKEN || "";
1110511142
let statusRaw = "";
11143+
const scopeErrorMessage = `Scope: ${org}.${scope} does not exist or you don't have access to it`;
11144+
try {
11145+
const jsonData = yield (0, graphql_1.scopeQuery)(`${org}.${scope}`, token);
11146+
if (!((_b = (_a = jsonData === null || jsonData === void 0 ? void 0 : jsonData.data) === null || _a === void 0 ? void 0 : _a.getScope) === null || _b === void 0 ? void 0 : _b.id)) {
11147+
throw new Error(scopeErrorMessage);
11148+
}
11149+
}
11150+
catch (error) {
11151+
console.log(error);
11152+
throw new Error(scopeErrorMessage);
11153+
}
1110611154
yield (0, exec_1.exec)("bit", ["status", "--json"], {
1110711155
cwd: wsDir,
1110811156
listeners: {

scripts/graphql.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const GRAPHQL_ENDPOINT = 'https://api.v2.bit.cloud/graphql';
2+
3+
export const scopeQuery = (id: string, token: string) => {
4+
const query = `
5+
query GET_SCOPE($scopeId: String!) {
6+
getScope(id: $scopeId) {
7+
id
8+
}
9+
}
10+
`;
11+
12+
const variables = { scopeId: id };
13+
14+
return fetch(GRAPHQL_ENDPOINT, {
15+
method: 'POST',
16+
headers: {
17+
'Content-Type': 'application/json',
18+
Authorization: `Bearer ${token}`,
19+
},
20+
body: JSON.stringify({
21+
query,
22+
variables,
23+
}),
24+
}).then(response => response.json());
25+
};

scripts/pull-request.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { exec } from "@actions/exec";
22
import { getOctokit } from "@actions/github";
33
import * as core from "@actions/core";
4+
import { scopeQuery } from "./graphql";
45

56
const createSnapMessageText = async (
67
githubToken: string,
@@ -220,8 +221,21 @@ export default async function run(
220221
) {
221222
const org = process.env.ORG;
222223
const scope = process.env.SCOPE;
224+
const token = process.env.BIT_CONFIG_USER_TOKEN || "";
223225

224226
let statusRaw = "";
227+
const scopeErrorMessage = `Scope: ${org}.${scope} does not exist or you don't have access to it`;
228+
229+
try {
230+
const jsonData = await scopeQuery(`${org}.${scope}`, token);
231+
232+
if (!jsonData?.data?.getScope?.id) {
233+
throw new Error(scopeErrorMessage);
234+
}
235+
} catch (error) {
236+
console.log(error);
237+
throw new Error(scopeErrorMessage);
238+
}
225239

226240
await exec("bit", ["status", "--json"], {
227241
cwd: wsDir,

0 commit comments

Comments
 (0)