Skip to content

Commit

Permalink
Build action
Browse files Browse the repository at this point in the history
  • Loading branch information
zegl committed Sep 12, 2022
1 parent 25f0b7e commit 102067b
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 45 deletions.
83 changes: 66 additions & 17 deletions dist/approver/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21714,17 +21714,67 @@ const github_1 = __nccwpck_require__(8216);
const track_1 = __nccwpck_require__(4154);
const messages_1 = __nccwpck_require__(7616);
const jobID = (0, lib_1.optional)('codeball-job-id');
const shouldApprove = (0, lib_1.required)('approve') === 'true';
const githubToken = (0, lib_1.required)('GITHUB_TOKEN');
const octokit = new lib_1.Octokit({ auth: githubToken });
const approvalMessage = (0, lib_1.required)('message');
const defaultMessages = [
(0, lib_1.required)('message'),
`> [[dashboard](https://codeball.ai/${process.env.GITHUB_REPOSITORY})]`
];
const getServerSideMessages = (jobId) => (0, messages_1.list)(jobId).then(messages => [
(0, lib_1.required)('message'),
...messages.map(message => message.text)
]);
const getMessages = (jobId) => jobId
? getServerSideMessages(jobId).catch(() => defaultMessages)
: defaultMessages;
const getMessages = (jobId) => __awaiter(void 0, void 0, void 0, function* () {
const messages = jobId
? yield getServerSideMessages(jobId).catch(() => defaultMessages)
: defaultMessages;
return shouldApprove ? [approvalMessage, ...messages] : messages;
});
const apporveFromActions = (params) => __awaiter(void 0, void 0, void 0, function* () {
const existingReviews = yield octokit.pulls
.listReviews({
owner: params.owner,
repo: params.repo,
pull_number: params.pull_number
})
.catch(e => {
throw new Error(`failed to current existing reviews ${e}`);
})
.then(r => r.data);
const previousReviews = existingReviews
.filter(r => { var _a; return ((_a = r.user) === null || _a === void 0 ? void 0 : _a.type) === 'Bot'; })
.sort((a, b) => {
var _a, _b;
return new Date((_a = a.submitted_at) !== null && _a !== void 0 ? _a : 0).getTime() -
new Date((_b = b.submitted_at) !== null && _b !== void 0 ? _b : 0).getTime();
});
const latestReview = previousReviews.slice(-1).at(0);
const latestReviewExists = latestReview !== undefined;
const latestReviewIsApproval = (latestReview === null || latestReview === void 0 ? void 0 : latestReview.state) === 'APPROVED';
if (latestReviewExists && shouldApprove) {
yield octokit.pulls.createReview(params).catch(e => {
throw new Error(`failed to create review ${e}`);
});
}
else if (latestReviewExists && !shouldApprove && latestReviewIsApproval) {
yield octokit.pulls
.dismissReview({
review_id: latestReview.id,
owner: params.owner,
repo: params.repo,
pull_number: params.pull_number,
message: params.body
})
.catch(e => {
throw new Error(`failed to dismiss review ${e}`);
});
}
else if (!latestReviewExists && shouldApprove) {
yield octokit.pulls.createReview(params).catch(e => {
throw new Error(`failed to create review ${e}`);
});
}
});
function run() {
var _a, _b, _c, _d, _e, _f, _g, _h;
return __awaiter(this, void 0, void 0, function* () {
Expand All @@ -21743,8 +21793,6 @@ function run() {
const repoName = (_g = github.context.payload.repository) === null || _g === void 0 ? void 0 : _g.name;
if (!repoName)
throw new Error('No repo name found');
const githubToken = (0, lib_1.required)('GITHUB_TOKEN');
const octokit = new lib_1.Octokit({ auth: githubToken });
const reviewMessage = (yield getMessages(jobID)).join('\n\n');
const pr = yield octokit.pulls
.get({
Expand All @@ -21761,23 +21809,23 @@ function run() {
core.error('Unable to run this action as the feature is not available for your organization. Please upgrade your Codeball plan, or contact [email protected]');
return;
}
yield octokit.pulls
.createReview({
yield apporveFromActions({
owner: repoOwner,
repo: repoName,
pull_number: pullRequestNumber,
commit_id: commitId,
body: reviewMessage,
event: feats.approve ? 'APPROVE' : 'COMMENT'
})
.catch((error) => __awaiter(this, void 0, void 0, function* () {
}).catch((error) => __awaiter(this, void 0, void 0, function* () {
core.error(error);
if (error instanceof Error &&
error.message === 'Resource not accessible by integration') {
// If the token is not allowed to create reviews (for example it's a pull request from a public fork),
// we can try to approve the pull request from the backend with the app token.
return (0, github_1.approve)({
link: pullRequestURL,
message: reviewMessage
message: reviewMessage,
approve: shouldApprove
}).catch(error => {
if (error.name === api_1.ForbiddenError.name) {
throw new Error(!isPrivate && isFromFork && !isToFork
Expand Down Expand Up @@ -22077,8 +22125,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.suggest = exports.label = exports.approve = void 0;
const api_1 = __nccwpck_require__(9095);
const approve = ({ link, message }) => __awaiter(void 0, void 0, void 0, function* () {
const body = message ? { link, message } : { link };
const approve = ({ link, message, approve }) => __awaiter(void 0, void 0, void 0, function* () {
const body = message ? { link, message, approve } : { link };
return (0, api_1.post)('/github/pulls/approve', body);
});
exports.approve = approve;
Expand Down Expand Up @@ -22144,7 +22192,7 @@ exports.list = exports.create = exports.get = void 0;
const api_1 = __nccwpck_require__(9095);
const get = (id) => (0, api_1.get)(`/jobs/${id}`);
exports.get = get;
const create = ({ url, access_token }) => (0, api_1.post)('/jobs', { url, access_token });
const create = ({ url, access_token, thresholds }) => (0, api_1.post)('/jobs', { url, access_token, thresholds });
exports.create = create;
const list = (params) => (0, api_1.get)('/jobs', new URLSearchParams(params));
exports.list = list;
Expand Down Expand Up @@ -22306,11 +22354,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.track = void 0;
const api_1 = __nccwpck_require__(9095);
const track = ({ jobID, actionName, error }) => __awaiter(void 0, void 0, void 0, function* () {
const track = ({ jobID, actionName, error, data }) => __awaiter(void 0, void 0, void 0, function* () {
return (0, api_1.post)('/track', {
job_id: jobID !== null && jobID !== void 0 ? jobID : null,
name: actionName,
error: error !== null && error !== void 0 ? error : null
error: error !== null && error !== void 0 ? error : null,
data: data !== null && data !== void 0 ? data : null
}).catch(error => console.warn(error));
});
exports.track = track;
Expand Down
2 changes: 1 addition & 1 deletion dist/approver/index.js.map

Large diffs are not rendered by default.

19 changes: 13 additions & 6 deletions dist/baller/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21723,10 +21723,16 @@ function run() {
core.info(`Found contribution: ${pullRequestURL}`);
if (commentURL)
core.info(`Found comment: ${commentURL}`);
const approve = parseFloat((0, lib_1.optional)('approveThreshold') || '0.935');
const carefulReview = parseFloat((0, lib_1.optional)('carefulReviewThreshold') || '0.300');
const job = yield (0, lib_1.create)({
// if commentURL is present, we are in the context of a comment action, so trigger that.
url: commentURL !== null && commentURL !== void 0 ? commentURL : pullRequestURL,
access_token: githubToken
access_token: githubToken,
thresholds: {
approve,
careful_review: carefulReview
}
});
core.info(`Job created: ${job.id}`);
return { jobId: job.id };
Expand Down Expand Up @@ -22022,8 +22028,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.suggest = exports.label = exports.approve = void 0;
const api_1 = __nccwpck_require__(9095);
const approve = ({ link, message }) => __awaiter(void 0, void 0, void 0, function* () {
const body = message ? { link, message } : { link };
const approve = ({ link, message, approve }) => __awaiter(void 0, void 0, void 0, function* () {
const body = message ? { link, message, approve } : { link };
return (0, api_1.post)('/github/pulls/approve', body);
});
exports.approve = approve;
Expand Down Expand Up @@ -22089,7 +22095,7 @@ exports.list = exports.create = exports.get = void 0;
const api_1 = __nccwpck_require__(9095);
const get = (id) => (0, api_1.get)(`/jobs/${id}`);
exports.get = get;
const create = ({ url, access_token }) => (0, api_1.post)('/jobs', { url, access_token });
const create = ({ url, access_token, thresholds }) => (0, api_1.post)('/jobs', { url, access_token, thresholds });
exports.create = create;
const list = (params) => (0, api_1.get)('/jobs', new URLSearchParams(params));
exports.list = list;
Expand Down Expand Up @@ -22201,11 +22207,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.track = void 0;
const api_1 = __nccwpck_require__(9095);
const track = ({ jobID, actionName, error }) => __awaiter(void 0, void 0, void 0, function* () {
const track = ({ jobID, actionName, error, data }) => __awaiter(void 0, void 0, void 0, function* () {
return (0, api_1.post)('/track', {
job_id: jobID !== null && jobID !== void 0 ? jobID : null,
name: actionName,
error: error !== null && error !== void 0 ? error : null
error: error !== null && error !== void 0 ? error : null,
data: data !== null && data !== void 0 ? data : null
}).catch(error => console.warn(error));
});
exports.track = track;
Expand Down
2 changes: 1 addition & 1 deletion dist/baller/index.js.map

Large diffs are not rendered by default.

25 changes: 18 additions & 7 deletions dist/labeler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21839,10 +21839,20 @@ const run = () => __awaiter(void 0, void 0, void 0, function* () {
}));
});
run()
.then(() => __awaiter(void 0, void 0, void 0, function* () { return yield (0, track_1.track)({ jobID, actionName: 'labeler' }); }))
.then(() => __awaiter(void 0, void 0, void 0, function* () {
return yield (0, track_1.track)({
jobID,
actionName: 'labeler',
data: { labelName: (0, lib_1.required)('name') }
});
}))
.catch((error) => __awaiter(void 0, void 0, void 0, function* () {
if (error instanceof Error) {
yield (0, track_1.track)({ jobID, actionName: 'labeler', error: error.message });
yield (0, track_1.track)({
jobID,
actionName: 'labeler',
error: error.message
});
core.setFailed(error.message);
}
}));
Expand Down Expand Up @@ -22122,8 +22132,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.suggest = exports.label = exports.approve = void 0;
const api_1 = __nccwpck_require__(9095);
const approve = ({ link, message }) => __awaiter(void 0, void 0, void 0, function* () {
const body = message ? { link, message } : { link };
const approve = ({ link, message, approve }) => __awaiter(void 0, void 0, void 0, function* () {
const body = message ? { link, message, approve } : { link };
return (0, api_1.post)('/github/pulls/approve', body);
});
exports.approve = approve;
Expand Down Expand Up @@ -22189,7 +22199,7 @@ exports.list = exports.create = exports.get = void 0;
const api_1 = __nccwpck_require__(9095);
const get = (id) => (0, api_1.get)(`/jobs/${id}`);
exports.get = get;
const create = ({ url, access_token }) => (0, api_1.post)('/jobs', { url, access_token });
const create = ({ url, access_token, thresholds }) => (0, api_1.post)('/jobs', { url, access_token, thresholds });
exports.create = create;
const list = (params) => (0, api_1.get)('/jobs', new URLSearchParams(params));
exports.list = list;
Expand Down Expand Up @@ -22301,11 +22311,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.track = void 0;
const api_1 = __nccwpck_require__(9095);
const track = ({ jobID, actionName, error }) => __awaiter(void 0, void 0, void 0, function* () {
const track = ({ jobID, actionName, error, data }) => __awaiter(void 0, void 0, void 0, function* () {
return (0, api_1.post)('/track', {
job_id: jobID !== null && jobID !== void 0 ? jobID : null,
name: actionName,
error: error !== null && error !== void 0 ? error : null
error: error !== null && error !== void 0 ? error : null,
data: data !== null && data !== void 0 ? data : null
}).catch(error => console.warn(error));
});
exports.track = track;
Expand Down
2 changes: 1 addition & 1 deletion dist/labeler/index.js.map

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions dist/status/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17724,8 +17724,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.suggest = exports.label = exports.approve = void 0;
const api_1 = __nccwpck_require__(9095);
const approve = ({ link, message }) => __awaiter(void 0, void 0, void 0, function* () {
const body = message ? { link, message } : { link };
const approve = ({ link, message, approve }) => __awaiter(void 0, void 0, void 0, function* () {
const body = message ? { link, message, approve } : { link };
return (0, api_1.post)('/github/pulls/approve', body);
});
exports.approve = approve;
Expand Down Expand Up @@ -17791,7 +17791,7 @@ exports.list = exports.create = exports.get = void 0;
const api_1 = __nccwpck_require__(9095);
const get = (id) => (0, api_1.get)(`/jobs/${id}`);
exports.get = get;
const create = ({ url, access_token }) => (0, api_1.post)('/jobs', { url, access_token });
const create = ({ url, access_token, thresholds }) => (0, api_1.post)('/jobs', { url, access_token, thresholds });
exports.create = create;
const list = (params) => (0, api_1.get)('/jobs', new URLSearchParams(params));
exports.list = list;
Expand Down Expand Up @@ -17903,11 +17903,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.track = void 0;
const api_1 = __nccwpck_require__(9095);
const track = ({ jobID, actionName, error }) => __awaiter(void 0, void 0, void 0, function* () {
const track = ({ jobID, actionName, error, data }) => __awaiter(void 0, void 0, void 0, function* () {
return (0, api_1.post)('/track', {
job_id: jobID !== null && jobID !== void 0 ? jobID : null,
name: actionName,
error: error !== null && error !== void 0 ? error : null
error: error !== null && error !== void 0 ? error : null,
data: data !== null && data !== void 0 ? data : null
}).catch(error => console.warn(error));
});
exports.track = track;
Expand Down
2 changes: 1 addition & 1 deletion dist/status/index.js.map

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions dist/suggester/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21940,8 +21940,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.suggest = exports.label = exports.approve = void 0;
const api_1 = __nccwpck_require__(9095);
const approve = ({ link, message }) => __awaiter(void 0, void 0, void 0, function* () {
const body = message ? { link, message } : { link };
const approve = ({ link, message, approve }) => __awaiter(void 0, void 0, void 0, function* () {
const body = message ? { link, message, approve } : { link };
return (0, api_1.post)('/github/pulls/approve', body);
});
exports.approve = approve;
Expand Down Expand Up @@ -22007,7 +22007,7 @@ exports.list = exports.create = exports.get = void 0;
const api_1 = __nccwpck_require__(9095);
const get = (id) => (0, api_1.get)(`/jobs/${id}`);
exports.get = get;
const create = ({ url, access_token }) => (0, api_1.post)('/jobs', { url, access_token });
const create = ({ url, access_token, thresholds }) => (0, api_1.post)('/jobs', { url, access_token, thresholds });
exports.create = create;
const list = (params) => (0, api_1.get)('/jobs', new URLSearchParams(params));
exports.list = list;
Expand Down Expand Up @@ -22119,11 +22119,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.track = void 0;
const api_1 = __nccwpck_require__(9095);
const track = ({ jobID, actionName, error }) => __awaiter(void 0, void 0, void 0, function* () {
const track = ({ jobID, actionName, error, data }) => __awaiter(void 0, void 0, void 0, function* () {
return (0, api_1.post)('/track', {
job_id: jobID !== null && jobID !== void 0 ? jobID : null,
name: actionName,
error: error !== null && error !== void 0 ? error : null
error: error !== null && error !== void 0 ? error : null,
data: data !== null && data !== void 0 ? data : null
}).catch(error => console.warn(error));
});
exports.track = track;
Expand Down
2 changes: 1 addition & 1 deletion dist/suggester/index.js.map

Large diffs are not rendered by default.

0 comments on commit 102067b

Please sign in to comment.