Skip to content

Commit

Permalink
Adapt the code to run on the review webhook (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
namelivia authored Jul 2, 2020
1 parent acd6e42 commit 5e39677
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
11 changes: 6 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1383,13 +1383,14 @@ exports.getRulesForLabels = async (issuesListLabelsOnIssueParams, client, rules)
exports.getMaxReviewNumber = (rules) => rules.reduce((acc, rule) => (rule.reviews > acc ? rule.reviews : acc), 0);
// Returns the repository information using provided gitHubEventPath
exports.findRepositoryInformation = (gitHubEventPath, log, exit) => {
var _a;
const payload = require(gitHubEventPath);
if (payload.number === undefined) {
exit.neutral('Action not triggered by a PullRequest action. PR ID is missing');
if (((_a = payload.pull_request) === null || _a === void 0 ? void 0 : _a.number) === undefined) {
exit.neutral('Action not triggered by a PullRequest review action. PR ID is missing');
}
log.info(`Checking files list for PR#${payload.number}`);
log.info(`Checking labels for PR#${payload.pull_request.number}`);
return {
issue_number: payload.number,
issue_number: payload.pull_request.number,
owner: payload.repository.owner.login,
repo: payload.repository.name,
};
Expand Down Expand Up @@ -25477,7 +25478,7 @@ const args = {
'pull_request.ready_for_review',
'pull_request_review.submitted',
'pull_request_review.edited',
'pull_request_review.dismissed',
'pull_request_review.dismissed'
],
secrets: ['GITHUB_TOKEN'],
};
Expand Down
5 changes: 1 addition & 4 deletions src/entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ import {

const args: ToolkitOptions = {
event: [
'pull_request.labeled',
'pull_request.unlabeled',
'pull_request.ready_for_review',
'pull_request_review.submitted',
'pull_request_review.edited',
'pull_request_review.dismissed'
'pull_request_review.dismissed',
],
secrets: ['GITHUB_TOKEN'],
}
Expand Down
8 changes: 4 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ export const findRepositoryInformation = (
exit: Exit
): IssuesListLabelsOnIssueParams => {
const payload: WebhookPayloadWithRepository = require(gitHubEventPath)
if (payload.number === undefined) {
if (payload.pull_request?.number === undefined) {
exit.neutral(
'Action not triggered by a PullRequest action. PR ID is missing'
'Action not triggered by a PullRequest review action. PR ID is missing'
)
}
log.info(`Checking files list for PR#${payload.number}`)
log.info(`Checking labels for PR#${payload.pull_request.number}`)
return {
issue_number: payload.number,
issue_number: payload.pull_request.number,
owner: payload.repository.owner.login,
repo: payload.repository.name,
}
Expand Down

0 comments on commit 5e39677

Please sign in to comment.