Skip to content

Commit

Permalink
Remove pr comment function in favor of using issue commenter
Browse files Browse the repository at this point in the history
  • Loading branch information
rpsu committed Sep 24, 2021
1 parent ad3cd63 commit d95fbcc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 87 deletions.
45 changes: 7 additions & 38 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.addPullRequestComment = exports.addIssueComment = void 0;
exports.addIssueComment = void 0;
const github = __importStar(__nccwpck_require__(2165));
const debug = process.env.GITHUB_API_DEBUG || true;
const githubToken = process.env.GITHUB_TOKEN;
const octokit = githubToken && github.getOctokit(githubToken);
/**
* Add comment to issue discussion (link to trello board)
* Add comment to issue discussion (link to trello board).
*
* PRs do not have their own endpoint for the same feature but this one is used for them as well.
* @see https://octokit.github.io/rest.js/v18#issues-create-comment
* @see https://octokit.github.io/rest.js/v18#pulls-create-review-comment
*
*/
const addIssueComment = ({ comment, issueNumber, repoOwner, repoName, }) => __awaiter(void 0, void 0, void 0, function* () {
if (!octokit) {
Expand Down Expand Up @@ -70,42 +75,6 @@ const addIssueComment = ({ comment, issueNumber, repoOwner, repoName, }) => __aw
return true;
});
exports.addIssueComment = addIssueComment;
/**
* Add comment to PR discussion (link to trello board)
*/
const addPullRequestComment = ({ comment, pullNumber, repoOwner, repoName, }) => __awaiter(void 0, void 0, void 0, function* () {
if (!octokit) {
console.error('Octokit is not defined.');
!githubToken && console.error('GITHUB_TOKEN is falsy.');
return false;
}
if (debug) {
console.debug('GH api / addPullRequestComment', {
pullNumber: pullNumber,
repoOwner: repoOwner,
repoName: repoName,
});
}
const commentData = {
body: comment,
pull_number: pullNumber,
owner: repoOwner,
repo: repoName,
};
if (debug) {
console.log('commentData:', JSON.stringify(commentData, undefined, 2));
}
const response = yield octokit.rest.pulls.createReviewComment(commentData);
if (debug) {
console.log('response: ', typeof response, ' ', JSON.stringify(response, undefined, 2));
}
if (!response) {
console.error(`Octokit addPullRequestComment() error with this issue. Data used:`, commentData);
return false;
}
return true;
});
exports.addPullRequestComment = addPullRequestComment;
//# sourceMappingURL=api-github.js.map

/***/ }),
Expand Down
55 changes: 7 additions & 48 deletions src/api-github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ const githubToken: string | undefined = process.env.GITHUB_TOKEN;
const octokit = githubToken && github.getOctokit(githubToken);

/**
* Add comment to issue discussion (link to trello board)
* Add comment to issue discussion (link to trello board).
*
* PRs do not have their own endpoint for the same feature but this one is used for them as well.
* @see https://octokit.github.io/rest.js/v18#issues-create-comment
* @see https://octokit.github.io/rest.js/v18#pulls-create-review-comment
*
*/
const addIssueComment = async ({
comment,
Expand Down Expand Up @@ -45,50 +50,4 @@ const addIssueComment = async ({
return true;
};

/**
* Add comment to PR discussion (link to trello board)
*/
const addPullRequestComment = async ({
comment,
pullNumber,
repoOwner,
repoName,
}: ghPullRequestCommentData): Promise<boolean> => {
if (!octokit) {
console.error('Octokit is not defined.');
!githubToken && console.error('GITHUB_TOKEN is falsy.');
return false;
}
if (debug) {
console.debug('GH api / addPullRequestComment', {
pullNumber: pullNumber,
repoOwner: repoOwner,
repoName: repoName,
});
}

const commentData = {
body: comment,
pull_number: pullNumber,
owner: repoOwner,
repo: repoName,
};

if (debug) {
console.log('commentData:', JSON.stringify(commentData, undefined, 2));
}

const response = await octokit.rest.pulls.createReviewComment(commentData);

if (debug) {
console.log('response: ', typeof response, ' ', JSON.stringify(response, undefined, 2));
}
if (!response) {
console.error(`Octokit addPullRequestComment() error with this issue. Data used:`, commentData);
return false;
}

return true;
};

export { addIssueComment, addPullRequestComment };
export { addIssueComment };
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as core from '@actions/core';
import * as github from '@actions/github';
import { debug } from 'console';
import { addIssueComment, addPullRequestComment } from './api-github';
import { addIssueComment } from './api-github';

import {
getLabelsOfBoard,
Expand Down

0 comments on commit d95fbcc

Please sign in to comment.