Skip to content

Commit 102067b

Browse files
committed
Build action
1 parent 25f0b7e commit 102067b

File tree

10 files changed

+114
-45
lines changed

10 files changed

+114
-45
lines changed

dist/approver/index.js

Lines changed: 66 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21714,17 +21714,67 @@ const github_1 = __nccwpck_require__(8216);
2171421714
const track_1 = __nccwpck_require__(4154);
2171521715
const messages_1 = __nccwpck_require__(7616);
2171621716
const jobID = (0, lib_1.optional)('codeball-job-id');
21717+
const shouldApprove = (0, lib_1.required)('approve') === 'true';
21718+
const githubToken = (0, lib_1.required)('GITHUB_TOKEN');
21719+
const octokit = new lib_1.Octokit({ auth: githubToken });
21720+
const approvalMessage = (0, lib_1.required)('message');
2171721721
const defaultMessages = [
21718-
(0, lib_1.required)('message'),
2171921722
`> [[dashboard](https://codeball.ai/${process.env.GITHUB_REPOSITORY})]`
2172021723
];
2172121724
const getServerSideMessages = (jobId) => (0, messages_1.list)(jobId).then(messages => [
21722-
(0, lib_1.required)('message'),
2172321725
...messages.map(message => message.text)
2172421726
]);
21725-
const getMessages = (jobId) => jobId
21726-
? getServerSideMessages(jobId).catch(() => defaultMessages)
21727-
: defaultMessages;
21727+
const getMessages = (jobId) => __awaiter(void 0, void 0, void 0, function* () {
21728+
const messages = jobId
21729+
? yield getServerSideMessages(jobId).catch(() => defaultMessages)
21730+
: defaultMessages;
21731+
return shouldApprove ? [approvalMessage, ...messages] : messages;
21732+
});
21733+
const apporveFromActions = (params) => __awaiter(void 0, void 0, void 0, function* () {
21734+
const existingReviews = yield octokit.pulls
21735+
.listReviews({
21736+
owner: params.owner,
21737+
repo: params.repo,
21738+
pull_number: params.pull_number
21739+
})
21740+
.catch(e => {
21741+
throw new Error(`failed to current existing reviews ${e}`);
21742+
})
21743+
.then(r => r.data);
21744+
const previousReviews = existingReviews
21745+
.filter(r => { var _a; return ((_a = r.user) === null || _a === void 0 ? void 0 : _a.type) === 'Bot'; })
21746+
.sort((a, b) => {
21747+
var _a, _b;
21748+
return new Date((_a = a.submitted_at) !== null && _a !== void 0 ? _a : 0).getTime() -
21749+
new Date((_b = b.submitted_at) !== null && _b !== void 0 ? _b : 0).getTime();
21750+
});
21751+
const latestReview = previousReviews.slice(-1).at(0);
21752+
const latestReviewExists = latestReview !== undefined;
21753+
const latestReviewIsApproval = (latestReview === null || latestReview === void 0 ? void 0 : latestReview.state) === 'APPROVED';
21754+
if (latestReviewExists && shouldApprove) {
21755+
yield octokit.pulls.createReview(params).catch(e => {
21756+
throw new Error(`failed to create review ${e}`);
21757+
});
21758+
}
21759+
else if (latestReviewExists && !shouldApprove && latestReviewIsApproval) {
21760+
yield octokit.pulls
21761+
.dismissReview({
21762+
review_id: latestReview.id,
21763+
owner: params.owner,
21764+
repo: params.repo,
21765+
pull_number: params.pull_number,
21766+
message: params.body
21767+
})
21768+
.catch(e => {
21769+
throw new Error(`failed to dismiss review ${e}`);
21770+
});
21771+
}
21772+
else if (!latestReviewExists && shouldApprove) {
21773+
yield octokit.pulls.createReview(params).catch(e => {
21774+
throw new Error(`failed to create review ${e}`);
21775+
});
21776+
}
21777+
});
2172821778
function run() {
2172921779
var _a, _b, _c, _d, _e, _f, _g, _h;
2173021780
return __awaiter(this, void 0, void 0, function* () {
@@ -21743,8 +21793,6 @@ function run() {
2174321793
const repoName = (_g = github.context.payload.repository) === null || _g === void 0 ? void 0 : _g.name;
2174421794
if (!repoName)
2174521795
throw new Error('No repo name found');
21746-
const githubToken = (0, lib_1.required)('GITHUB_TOKEN');
21747-
const octokit = new lib_1.Octokit({ auth: githubToken });
2174821796
const reviewMessage = (yield getMessages(jobID)).join('\n\n');
2174921797
const pr = yield octokit.pulls
2175021798
.get({
@@ -21761,23 +21809,23 @@ function run() {
2176121809
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]');
2176221810
return;
2176321811
}
21764-
yield octokit.pulls
21765-
.createReview({
21812+
yield apporveFromActions({
2176621813
owner: repoOwner,
2176721814
repo: repoName,
2176821815
pull_number: pullRequestNumber,
2176921816
commit_id: commitId,
2177021817
body: reviewMessage,
2177121818
event: feats.approve ? 'APPROVE' : 'COMMENT'
21772-
})
21773-
.catch((error) => __awaiter(this, void 0, void 0, function* () {
21819+
}).catch((error) => __awaiter(this, void 0, void 0, function* () {
21820+
core.error(error);
2177421821
if (error instanceof Error &&
2177521822
error.message === 'Resource not accessible by integration') {
2177621823
// If the token is not allowed to create reviews (for example it's a pull request from a public fork),
2177721824
// we can try to approve the pull request from the backend with the app token.
2177821825
return (0, github_1.approve)({
2177921826
link: pullRequestURL,
21780-
message: reviewMessage
21827+
message: reviewMessage,
21828+
approve: shouldApprove
2178121829
}).catch(error => {
2178221830
if (error.name === api_1.ForbiddenError.name) {
2178321831
throw new Error(!isPrivate && isFromFork && !isToFork
@@ -22077,8 +22125,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
2207722125
Object.defineProperty(exports, "__esModule", ({ value: true }));
2207822126
exports.suggest = exports.label = exports.approve = void 0;
2207922127
const api_1 = __nccwpck_require__(9095);
22080-
const approve = ({ link, message }) => __awaiter(void 0, void 0, void 0, function* () {
22081-
const body = message ? { link, message } : { link };
22128+
const approve = ({ link, message, approve }) => __awaiter(void 0, void 0, void 0, function* () {
22129+
const body = message ? { link, message, approve } : { link };
2208222130
return (0, api_1.post)('/github/pulls/approve', body);
2208322131
});
2208422132
exports.approve = approve;
@@ -22144,7 +22192,7 @@ exports.list = exports.create = exports.get = void 0;
2214422192
const api_1 = __nccwpck_require__(9095);
2214522193
const get = (id) => (0, api_1.get)(`/jobs/${id}`);
2214622194
exports.get = get;
22147-
const create = ({ url, access_token }) => (0, api_1.post)('/jobs', { url, access_token });
22195+
const create = ({ url, access_token, thresholds }) => (0, api_1.post)('/jobs', { url, access_token, thresholds });
2214822196
exports.create = create;
2214922197
const list = (params) => (0, api_1.get)('/jobs', new URLSearchParams(params));
2215022198
exports.list = list;
@@ -22306,11 +22354,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
2230622354
Object.defineProperty(exports, "__esModule", ({ value: true }));
2230722355
exports.track = void 0;
2230822356
const api_1 = __nccwpck_require__(9095);
22309-
const track = ({ jobID, actionName, error }) => __awaiter(void 0, void 0, void 0, function* () {
22357+
const track = ({ jobID, actionName, error, data }) => __awaiter(void 0, void 0, void 0, function* () {
2231022358
return (0, api_1.post)('/track', {
2231122359
job_id: jobID !== null && jobID !== void 0 ? jobID : null,
2231222360
name: actionName,
22313-
error: error !== null && error !== void 0 ? error : null
22361+
error: error !== null && error !== void 0 ? error : null,
22362+
data: data !== null && data !== void 0 ? data : null
2231422363
}).catch(error => console.warn(error));
2231522364
});
2231622365
exports.track = track;

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: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21723,10 +21723,16 @@ function run() {
2172321723
core.info(`Found contribution: ${pullRequestURL}`);
2172421724
if (commentURL)
2172521725
core.info(`Found comment: ${commentURL}`);
21726+
const approve = parseFloat((0, lib_1.optional)('approveThreshold') || '0.935');
21727+
const carefulReview = parseFloat((0, lib_1.optional)('carefulReviewThreshold') || '0.300');
2172621728
const job = yield (0, lib_1.create)({
2172721729
// if commentURL is present, we are in the context of a comment action, so trigger that.
2172821730
url: commentURL !== null && commentURL !== void 0 ? commentURL : pullRequestURL,
21729-
access_token: githubToken
21731+
access_token: githubToken,
21732+
thresholds: {
21733+
approve,
21734+
careful_review: carefulReview
21735+
}
2173021736
});
2173121737
core.info(`Job created: ${job.id}`);
2173221738
return { jobId: job.id };
@@ -22022,8 +22028,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
2202222028
Object.defineProperty(exports, "__esModule", ({ value: true }));
2202322029
exports.suggest = exports.label = exports.approve = void 0;
2202422030
const api_1 = __nccwpck_require__(9095);
22025-
const approve = ({ link, message }) => __awaiter(void 0, void 0, void 0, function* () {
22026-
const body = message ? { link, message } : { link };
22031+
const approve = ({ link, message, approve }) => __awaiter(void 0, void 0, void 0, function* () {
22032+
const body = message ? { link, message, approve } : { link };
2202722033
return (0, api_1.post)('/github/pulls/approve', body);
2202822034
});
2202922035
exports.approve = approve;
@@ -22089,7 +22095,7 @@ exports.list = exports.create = exports.get = void 0;
2208922095
const api_1 = __nccwpck_require__(9095);
2209022096
const get = (id) => (0, api_1.get)(`/jobs/${id}`);
2209122097
exports.get = get;
22092-
const create = ({ url, access_token }) => (0, api_1.post)('/jobs', { url, access_token });
22098+
const create = ({ url, access_token, thresholds }) => (0, api_1.post)('/jobs', { url, access_token, thresholds });
2209322099
exports.create = create;
2209422100
const list = (params) => (0, api_1.get)('/jobs', new URLSearchParams(params));
2209522101
exports.list = list;
@@ -22201,11 +22207,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
2220122207
Object.defineProperty(exports, "__esModule", ({ value: true }));
2220222208
exports.track = void 0;
2220322209
const api_1 = __nccwpck_require__(9095);
22204-
const track = ({ jobID, actionName, error }) => __awaiter(void 0, void 0, void 0, function* () {
22210+
const track = ({ jobID, actionName, error, data }) => __awaiter(void 0, void 0, void 0, function* () {
2220522211
return (0, api_1.post)('/track', {
2220622212
job_id: jobID !== null && jobID !== void 0 ? jobID : null,
2220722213
name: actionName,
22208-
error: error !== null && error !== void 0 ? error : null
22214+
error: error !== null && error !== void 0 ? error : null,
22215+
data: data !== null && data !== void 0 ? data : null
2220922216
}).catch(error => console.warn(error));
2221022217
});
2221122218
exports.track = track;

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.

dist/labeler/index.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21839,10 +21839,20 @@ const run = () => __awaiter(void 0, void 0, void 0, function* () {
2183921839
}));
2184021840
});
2184121841
run()
21842-
.then(() => __awaiter(void 0, void 0, void 0, function* () { return yield (0, track_1.track)({ jobID, actionName: 'labeler' }); }))
21842+
.then(() => __awaiter(void 0, void 0, void 0, function* () {
21843+
return yield (0, track_1.track)({
21844+
jobID,
21845+
actionName: 'labeler',
21846+
data: { labelName: (0, lib_1.required)('name') }
21847+
});
21848+
}))
2184321849
.catch((error) => __awaiter(void 0, void 0, void 0, function* () {
2184421850
if (error instanceof Error) {
21845-
yield (0, track_1.track)({ jobID, actionName: 'labeler', error: error.message });
21851+
yield (0, track_1.track)({
21852+
jobID,
21853+
actionName: 'labeler',
21854+
error: error.message
21855+
});
2184621856
core.setFailed(error.message);
2184721857
}
2184821858
}));
@@ -22122,8 +22132,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
2212222132
Object.defineProperty(exports, "__esModule", ({ value: true }));
2212322133
exports.suggest = exports.label = exports.approve = void 0;
2212422134
const api_1 = __nccwpck_require__(9095);
22125-
const approve = ({ link, message }) => __awaiter(void 0, void 0, void 0, function* () {
22126-
const body = message ? { link, message } : { link };
22135+
const approve = ({ link, message, approve }) => __awaiter(void 0, void 0, void 0, function* () {
22136+
const body = message ? { link, message, approve } : { link };
2212722137
return (0, api_1.post)('/github/pulls/approve', body);
2212822138
});
2212922139
exports.approve = approve;
@@ -22189,7 +22199,7 @@ exports.list = exports.create = exports.get = void 0;
2218922199
const api_1 = __nccwpck_require__(9095);
2219022200
const get = (id) => (0, api_1.get)(`/jobs/${id}`);
2219122201
exports.get = get;
22192-
const create = ({ url, access_token }) => (0, api_1.post)('/jobs', { url, access_token });
22202+
const create = ({ url, access_token, thresholds }) => (0, api_1.post)('/jobs', { url, access_token, thresholds });
2219322203
exports.create = create;
2219422204
const list = (params) => (0, api_1.get)('/jobs', new URLSearchParams(params));
2219522205
exports.list = list;
@@ -22301,11 +22311,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
2230122311
Object.defineProperty(exports, "__esModule", ({ value: true }));
2230222312
exports.track = void 0;
2230322313
const api_1 = __nccwpck_require__(9095);
22304-
const track = ({ jobID, actionName, error }) => __awaiter(void 0, void 0, void 0, function* () {
22314+
const track = ({ jobID, actionName, error, data }) => __awaiter(void 0, void 0, void 0, function* () {
2230522315
return (0, api_1.post)('/track', {
2230622316
job_id: jobID !== null && jobID !== void 0 ? jobID : null,
2230722317
name: actionName,
22308-
error: error !== null && error !== void 0 ? error : null
22318+
error: error !== null && error !== void 0 ? error : null,
22319+
data: data !== null && data !== void 0 ? data : null
2230922320
}).catch(error => console.warn(error));
2231022321
});
2231122322
exports.track = track;

dist/labeler/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/status/index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17724,8 +17724,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
1772417724
Object.defineProperty(exports, "__esModule", ({ value: true }));
1772517725
exports.suggest = exports.label = exports.approve = void 0;
1772617726
const api_1 = __nccwpck_require__(9095);
17727-
const approve = ({ link, message }) => __awaiter(void 0, void 0, void 0, function* () {
17728-
const body = message ? { link, message } : { link };
17727+
const approve = ({ link, message, approve }) => __awaiter(void 0, void 0, void 0, function* () {
17728+
const body = message ? { link, message, approve } : { link };
1772917729
return (0, api_1.post)('/github/pulls/approve', body);
1773017730
});
1773117731
exports.approve = approve;
@@ -17791,7 +17791,7 @@ exports.list = exports.create = exports.get = void 0;
1779117791
const api_1 = __nccwpck_require__(9095);
1779217792
const get = (id) => (0, api_1.get)(`/jobs/${id}`);
1779317793
exports.get = get;
17794-
const create = ({ url, access_token }) => (0, api_1.post)('/jobs', { url, access_token });
17794+
const create = ({ url, access_token, thresholds }) => (0, api_1.post)('/jobs', { url, access_token, thresholds });
1779517795
exports.create = create;
1779617796
const list = (params) => (0, api_1.get)('/jobs', new URLSearchParams(params));
1779717797
exports.list = list;
@@ -17903,11 +17903,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
1790317903
Object.defineProperty(exports, "__esModule", ({ value: true }));
1790417904
exports.track = void 0;
1790517905
const api_1 = __nccwpck_require__(9095);
17906-
const track = ({ jobID, actionName, error }) => __awaiter(void 0, void 0, void 0, function* () {
17906+
const track = ({ jobID, actionName, error, data }) => __awaiter(void 0, void 0, void 0, function* () {
1790717907
return (0, api_1.post)('/track', {
1790817908
job_id: jobID !== null && jobID !== void 0 ? jobID : null,
1790917909
name: actionName,
17910-
error: error !== null && error !== void 0 ? error : null
17910+
error: error !== null && error !== void 0 ? error : null,
17911+
data: data !== null && data !== void 0 ? data : null
1791117912
}).catch(error => console.warn(error));
1791217913
});
1791317914
exports.track = track;

dist/status/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/suggester/index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21940,8 +21940,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
2194021940
Object.defineProperty(exports, "__esModule", ({ value: true }));
2194121941
exports.suggest = exports.label = exports.approve = void 0;
2194221942
const api_1 = __nccwpck_require__(9095);
21943-
const approve = ({ link, message }) => __awaiter(void 0, void 0, void 0, function* () {
21944-
const body = message ? { link, message } : { link };
21943+
const approve = ({ link, message, approve }) => __awaiter(void 0, void 0, void 0, function* () {
21944+
const body = message ? { link, message, approve } : { link };
2194521945
return (0, api_1.post)('/github/pulls/approve', body);
2194621946
});
2194721947
exports.approve = approve;
@@ -22007,7 +22007,7 @@ exports.list = exports.create = exports.get = void 0;
2200722007
const api_1 = __nccwpck_require__(9095);
2200822008
const get = (id) => (0, api_1.get)(`/jobs/${id}`);
2200922009
exports.get = get;
22010-
const create = ({ url, access_token }) => (0, api_1.post)('/jobs', { url, access_token });
22010+
const create = ({ url, access_token, thresholds }) => (0, api_1.post)('/jobs', { url, access_token, thresholds });
2201122011
exports.create = create;
2201222012
const list = (params) => (0, api_1.get)('/jobs', new URLSearchParams(params));
2201322013
exports.list = list;
@@ -22119,11 +22119,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
2211922119
Object.defineProperty(exports, "__esModule", ({ value: true }));
2212022120
exports.track = void 0;
2212122121
const api_1 = __nccwpck_require__(9095);
22122-
const track = ({ jobID, actionName, error }) => __awaiter(void 0, void 0, void 0, function* () {
22122+
const track = ({ jobID, actionName, error, data }) => __awaiter(void 0, void 0, void 0, function* () {
2212322123
return (0, api_1.post)('/track', {
2212422124
job_id: jobID !== null && jobID !== void 0 ? jobID : null,
2212522125
name: actionName,
22126-
error: error !== null && error !== void 0 ? error : null
22126+
error: error !== null && error !== void 0 ? error : null,
22127+
data: data !== null && data !== void 0 ? data : null
2212722128
}).catch(error => console.warn(error));
2212822129
});
2212922130
exports.track = track;

dist/suggester/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)