Skip to content

Commit 8f68c30

Browse files
committed
Build action
1 parent be130ac commit 8f68c30

File tree

8 files changed

+447
-85
lines changed

8 files changed

+447
-85
lines changed

dist/approver/index.js

Lines changed: 121 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63624,10 +63624,12 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
6362463624
const core = __importStar(__nccwpck_require__(2186));
6362563625
const github = __importStar(__nccwpck_require__(5438));
6362663626
const lib_1 = __nccwpck_require__(6791);
63627-
const track_1 = __nccwpck_require__(1263);
63627+
const api_1 = __nccwpck_require__(9095);
63628+
const github_1 = __nccwpck_require__(8216);
63629+
const track_1 = __nccwpck_require__(4154);
6362863630
const jobID = (0, lib_1.optional)('codeball-job-id');
6362963631
function run() {
63630-
var _a, _b, _c, _d, _e, _f, _g;
63632+
var _a, _b, _c, _d, _e, _f, _g, _h;
6363163633
return __awaiter(this, void 0, void 0, function* () {
6363263634
const pullRequestURL = (_b = (_a = github.context.payload) === null || _a === void 0 ? void 0 : _a.pull_request) === null || _b === void 0 ? void 0 : _b.html_url;
6363363635
if (!pullRequestURL)
@@ -63649,27 +63651,54 @@ function run() {
6364963651
const octokit = new lib_1.Octokit({ auth: githubToken });
6365063652
const dashboardLink = `[dashboard](https://codeball.ai/${process.env.GITHUB_REPOSITORY})`;
6365163653
const reviewMessage = `${message} ${dashboardLink}`;
63652-
yield octokit.pulls.createReview({
63654+
const pr = yield octokit.pulls
63655+
.get({
63656+
owner: repoOwner,
63657+
repo: repoName,
63658+
pull_number: pullRequestNumber
63659+
})
63660+
.then(r => r.data);
63661+
const isPrivate = pr.base.repo.private;
63662+
const isFromFork = (_h = pr.head.repo) === null || _h === void 0 ? void 0 : _h.fork;
63663+
const isToFork = pr.base.repo.fork;
63664+
yield octokit.pulls
63665+
.createReview({
6365363666
owner: repoOwner,
6365463667
repo: repoName,
6365563668
pull_number: pullRequestNumber,
6365663669
commit_id: commitId,
6365763670
body: reviewMessage,
6365863671
event: 'APPROVE'
63659-
});
63672+
})
63673+
.catch((error) => __awaiter(this, void 0, void 0, function* () {
63674+
if (error instanceof Error &&
63675+
error.message === 'Resource not accessible by integration') {
63676+
// If the token is not allowed to create reviews (for example it's a pull request from a public fork),
63677+
// we can try to approve the pull request from the backend with the app token.
63678+
return (0, github_1.approve)({
63679+
link: pullRequestURL,
63680+
message: reviewMessage
63681+
}).catch(error => {
63682+
if (error.name === api_1.ForbiddenError.name) {
63683+
throw new Error(!isPrivate && isFromFork && !isToFork
63684+
? 'Codeball Approver failed to access GitHub. Install https://github.com/apps/codeball-ai-writer to the base repository to give Codeball permission to approve Pull Requests.'
63685+
: 'Codeball Approver failed to access GitHub. Check the "GITHUB_TOKEN Permissions" of this job and make sure that the job has WRITE permissions to Pull Requests.');
63686+
}
63687+
throw error;
63688+
});
63689+
}
63690+
else {
63691+
throw error;
63692+
}
63693+
}));
6366063694
});
6366163695
}
6366263696
run()
6366363697
.then(() => __awaiter(void 0, void 0, void 0, function* () { return yield (0, track_1.track)({ jobID, actionName: 'approver' }); }))
6366463698
.catch((error) => __awaiter(void 0, void 0, void 0, function* () {
6366563699
if (error instanceof Error) {
6366663700
yield (0, track_1.track)({ jobID, actionName: 'approver', error: error.message });
63667-
if (error.message === 'Resource not accessible by integration') {
63668-
core.setFailed('Codeball Approver failed to access GitHub. Check the "GITHUB_TOKEN Permissions" of this job and make sure that the job has WRITE permissions to Pull Requests.');
63669-
}
63670-
else {
63671-
core.setFailed(error.message);
63672-
}
63701+
core.setFailed(error.message);
6367363702
}
6367463703
}));
6367563704

@@ -63761,19 +63790,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
6376163790
return (mod && mod.__esModule) ? mod : { "default": mod };
6376263791
};
6376363792
Object.defineProperty(exports, "__esModule", ({ value: true }));
63764-
exports.post = exports.get = exports.NotFoundError = exports.BadRequestError = void 0;
63793+
exports.post = exports.get = exports.NotFoundError = exports.BadRequestError = exports.ForbiddenError = void 0;
6376563794
const node_fetch_1 = __importDefault(__nccwpck_require__(4429));
6376663795
const BASE_URL = process.env.CODEBALL_API_HOST || 'https://api.codeball.ai';
63796+
class ForbiddenError extends Error {
63797+
constructor(message) {
63798+
super(message || 'Forbidden');
63799+
this.name = 'ForbiddenError';
63800+
}
63801+
}
63802+
exports.ForbiddenError = ForbiddenError;
6376763803
class BadRequestError extends Error {
6376863804
constructor(message) {
63769-
super(message);
63805+
super(message || 'Bad Request');
6377063806
this.name = 'BadRequestError';
6377163807
}
6377263808
}
6377363809
exports.BadRequestError = BadRequestError;
6377463810
class NotFoundError extends Error {
63775-
constructor() {
63776-
super('Not found');
63811+
constructor(message) {
63812+
super(message || 'Not Found');
6377763813
this.name = 'NotFoundError';
6377863814
}
6377963815
}
@@ -63788,16 +63824,19 @@ const handleResponse = (response) => __awaiter(void 0, void 0, void 0, function*
6378863824
else if (response.status === 400) {
6378963825
throw new BadRequestError(yield response.text());
6379063826
}
63827+
else if (response.status === 403) {
63828+
throw new ForbiddenError(yield response.text());
63829+
}
6379163830
else {
6379263831
throw new Error(yield response.text());
6379363832
}
6379463833
});
6379563834
const get = (path) => __awaiter(void 0, void 0, void 0, function* () {
6379663835
return (0, node_fetch_1.default)(new URL(path, BASE_URL).toString(), {
6379763836
headers: {
63798-
'User-Agent': 'github-actions',
63837+
'User-Agent': 'github-actions'
6379963838
},
63800-
redirect: 'follow',
63839+
redirect: 'follow'
6380163840
}).then(handleResponse);
6380263841
});
6380363842
exports.get = get;
@@ -63809,12 +63848,73 @@ const post = (path, body) => __awaiter(void 0, void 0, void 0, function* () {
6380963848
'User-Agent': 'github-actions',
6381063849
'Content-Type': 'application/json'
6381163850
},
63812-
redirect: 'follow',
63851+
redirect: 'follow'
6381363852
}).then(handleResponse);
6381463853
});
6381563854
exports.post = post;
6381663855

6381763856

63857+
/***/ }),
63858+
63859+
/***/ 8216:
63860+
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
63861+
63862+
"use strict";
63863+
63864+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
63865+
if (k2 === undefined) k2 = k;
63866+
var desc = Object.getOwnPropertyDescriptor(m, k);
63867+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
63868+
desc = { enumerable: true, get: function() { return m[k]; } };
63869+
}
63870+
Object.defineProperty(o, k2, desc);
63871+
}) : (function(o, m, k, k2) {
63872+
if (k2 === undefined) k2 = k;
63873+
o[k2] = m[k];
63874+
}));
63875+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
63876+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
63877+
};
63878+
Object.defineProperty(exports, "__esModule", ({ value: true }));
63879+
__exportStar(__nccwpck_require__(7571), exports);
63880+
63881+
63882+
/***/ }),
63883+
63884+
/***/ 7571:
63885+
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
63886+
63887+
"use strict";
63888+
63889+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
63890+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
63891+
return new (P || (P = Promise))(function (resolve, reject) {
63892+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
63893+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
63894+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
63895+
step((generator = generator.apply(thisArg, _arguments || [])).next());
63896+
});
63897+
};
63898+
Object.defineProperty(exports, "__esModule", ({ value: true }));
63899+
exports.label = exports.approve = void 0;
63900+
const api_1 = __nccwpck_require__(9095);
63901+
const approve = ({ link, message }) => __awaiter(void 0, void 0, void 0, function* () {
63902+
const body = message ? { link, message } : { link };
63903+
return (0, api_1.post)('/github/pulls/approve', body);
63904+
});
63905+
exports.approve = approve;
63906+
const label = (params) => __awaiter(void 0, void 0, void 0, function* () {
63907+
const body = Object.entries(params)
63908+
.filter(([_, value]) => value)
63909+
.reduce((acc, [key, value]) => {
63910+
acc[key] = value;
63911+
return acc;
63912+
}, {});
63913+
return (0, api_1.post)('/github/pulls/label', body);
63914+
});
63915+
exports.label = label;
63916+
63917+
6381863918
/***/ }),
6381963919

6382063920
/***/ 6791:
@@ -63840,6 +63940,8 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
6384063940
__exportStar(__nccwpck_require__(7527), exports);
6384163941
__exportStar(__nccwpck_require__(6518), exports);
6384263942
__exportStar(__nccwpck_require__(3769), exports);
63943+
__exportStar(__nccwpck_require__(4154), exports);
63944+
__exportStar(__nccwpck_require__(8216), exports);
6384363945

6384463946

6384563947
/***/ }),
@@ -63941,7 +64043,7 @@ function getApiBaseUrl() {
6394164043

6394264044
/***/ }),
6394364045

63944-
/***/ 1263:
64046+
/***/ 4154:
6394564047
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
6394664048

6394764049
"use strict";
@@ -63959,7 +64061,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
6395964061
exports.track = void 0;
6396064062
const api_1 = __nccwpck_require__(9095);
6396164063
const track = ({ jobID, actionName, error }) => __awaiter(void 0, void 0, void 0, function* () {
63962-
return (0, api_1.post)("/track", {
64064+
return (0, api_1.post)('/track', {
6396364065
job_id: jobID !== null && jobID !== void 0 ? jobID : null,
6396464066
name: actionName,
6396564067
error: error !== null && error !== void 0 ? error : null

dist/approver/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/baller/index.js

Lines changed: 83 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63624,7 +63624,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
6362463624
const core = __importStar(__nccwpck_require__(2186));
6362563625
const github = __importStar(__nccwpck_require__(5438));
6362663626
const lib_1 = __nccwpck_require__(6791);
63627-
const track_1 = __nccwpck_require__(1263);
63627+
const track_1 = __nccwpck_require__(4154);
6362863628
function run() {
6362963629
var _a, _b;
6363063630
return __awaiter(this, void 0, void 0, function* () {
@@ -63746,19 +63746,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
6374663746
return (mod && mod.__esModule) ? mod : { "default": mod };
6374763747
};
6374863748
Object.defineProperty(exports, "__esModule", ({ value: true }));
63749-
exports.post = exports.get = exports.NotFoundError = exports.BadRequestError = void 0;
63749+
exports.post = exports.get = exports.NotFoundError = exports.BadRequestError = exports.ForbiddenError = void 0;
6375063750
const node_fetch_1 = __importDefault(__nccwpck_require__(4429));
6375163751
const BASE_URL = process.env.CODEBALL_API_HOST || 'https://api.codeball.ai';
63752+
class ForbiddenError extends Error {
63753+
constructor(message) {
63754+
super(message || 'Forbidden');
63755+
this.name = 'ForbiddenError';
63756+
}
63757+
}
63758+
exports.ForbiddenError = ForbiddenError;
6375263759
class BadRequestError extends Error {
6375363760
constructor(message) {
63754-
super(message);
63761+
super(message || 'Bad Request');
6375563762
this.name = 'BadRequestError';
6375663763
}
6375763764
}
6375863765
exports.BadRequestError = BadRequestError;
6375963766
class NotFoundError extends Error {
63760-
constructor() {
63761-
super('Not found');
63767+
constructor(message) {
63768+
super(message || 'Not Found');
6376263769
this.name = 'NotFoundError';
6376363770
}
6376463771
}
@@ -63773,16 +63780,19 @@ const handleResponse = (response) => __awaiter(void 0, void 0, void 0, function*
6377363780
else if (response.status === 400) {
6377463781
throw new BadRequestError(yield response.text());
6377563782
}
63783+
else if (response.status === 403) {
63784+
throw new ForbiddenError(yield response.text());
63785+
}
6377663786
else {
6377763787
throw new Error(yield response.text());
6377863788
}
6377963789
});
6378063790
const get = (path) => __awaiter(void 0, void 0, void 0, function* () {
6378163791
return (0, node_fetch_1.default)(new URL(path, BASE_URL).toString(), {
6378263792
headers: {
63783-
'User-Agent': 'github-actions',
63793+
'User-Agent': 'github-actions'
6378463794
},
63785-
redirect: 'follow',
63795+
redirect: 'follow'
6378663796
}).then(handleResponse);
6378763797
});
6378863798
exports.get = get;
@@ -63794,12 +63804,73 @@ const post = (path, body) => __awaiter(void 0, void 0, void 0, function* () {
6379463804
'User-Agent': 'github-actions',
6379563805
'Content-Type': 'application/json'
6379663806
},
63797-
redirect: 'follow',
63807+
redirect: 'follow'
6379863808
}).then(handleResponse);
6379963809
});
6380063810
exports.post = post;
6380163811

6380263812

63813+
/***/ }),
63814+
63815+
/***/ 8216:
63816+
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
63817+
63818+
"use strict";
63819+
63820+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
63821+
if (k2 === undefined) k2 = k;
63822+
var desc = Object.getOwnPropertyDescriptor(m, k);
63823+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
63824+
desc = { enumerable: true, get: function() { return m[k]; } };
63825+
}
63826+
Object.defineProperty(o, k2, desc);
63827+
}) : (function(o, m, k, k2) {
63828+
if (k2 === undefined) k2 = k;
63829+
o[k2] = m[k];
63830+
}));
63831+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
63832+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
63833+
};
63834+
Object.defineProperty(exports, "__esModule", ({ value: true }));
63835+
__exportStar(__nccwpck_require__(7571), exports);
63836+
63837+
63838+
/***/ }),
63839+
63840+
/***/ 7571:
63841+
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
63842+
63843+
"use strict";
63844+
63845+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
63846+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
63847+
return new (P || (P = Promise))(function (resolve, reject) {
63848+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
63849+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
63850+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
63851+
step((generator = generator.apply(thisArg, _arguments || [])).next());
63852+
});
63853+
};
63854+
Object.defineProperty(exports, "__esModule", ({ value: true }));
63855+
exports.label = exports.approve = void 0;
63856+
const api_1 = __nccwpck_require__(9095);
63857+
const approve = ({ link, message }) => __awaiter(void 0, void 0, void 0, function* () {
63858+
const body = message ? { link, message } : { link };
63859+
return (0, api_1.post)('/github/pulls/approve', body);
63860+
});
63861+
exports.approve = approve;
63862+
const label = (params) => __awaiter(void 0, void 0, void 0, function* () {
63863+
const body = Object.entries(params)
63864+
.filter(([_, value]) => value)
63865+
.reduce((acc, [key, value]) => {
63866+
acc[key] = value;
63867+
return acc;
63868+
}, {});
63869+
return (0, api_1.post)('/github/pulls/label', body);
63870+
});
63871+
exports.label = label;
63872+
63873+
6380363874
/***/ }),
6380463875

6380563876
/***/ 6791:
@@ -63825,6 +63896,8 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
6382563896
__exportStar(__nccwpck_require__(7527), exports);
6382663897
__exportStar(__nccwpck_require__(6518), exports);
6382763898
__exportStar(__nccwpck_require__(3769), exports);
63899+
__exportStar(__nccwpck_require__(4154), exports);
63900+
__exportStar(__nccwpck_require__(8216), exports);
6382863901

6382963902

6383063903
/***/ }),
@@ -63926,7 +63999,7 @@ function getApiBaseUrl() {
6392663999

6392764000
/***/ }),
6392864001

63929-
/***/ 1263:
64002+
/***/ 4154:
6393064003
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
6393164004

6393264005
"use strict";
@@ -63944,7 +64017,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
6394464017
exports.track = void 0;
6394564018
const api_1 = __nccwpck_require__(9095);
6394664019
const track = ({ jobID, actionName, error }) => __awaiter(void 0, void 0, void 0, function* () {
63947-
return (0, api_1.post)("/track", {
64020+
return (0, api_1.post)('/track', {
6394864021
job_id: jobID !== null && jobID !== void 0 ? jobID : null,
6394964022
name: actionName,
6395064023
error: error !== null && error !== void 0 ? error : null

dist/baller/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)