Skip to content

Commit

Permalink
Delete outdated comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rehlma committed Apr 16, 2024
1 parent 010b36c commit 014cdb1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
20 changes: 14 additions & 6 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29410,25 +29410,33 @@ function getTodoIfFound(line) {
}
function commentPr(octokit, prNumber, botName, todos) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c;
var _a, _b;
const { owner, repo } = github.context.repo;
const issueNumber = (_a = github.context.payload.pull_request) === null || _a === void 0 ? void 0 : _a.number;
const headSha = (_b = github.context.payload.pull_request) === null || _b === void 0 ? void 0 : _b.head.sha;
if (!issueNumber)
throw new Error('Issue number not found');
// Get all comments on the pull request
const { data: comments } = yield octokit.rest.pulls.listReviewComments({
const { data: allComments } = yield octokit.rest.pulls.listReviewComments({
owner,
repo,
pull_number: prNumber
});
const botComments = allComments.filter(comment => { var _a; return ((_a = comment.user) === null || _a === void 0 ? void 0 : _a.login) === botName; });
const addedTodos = todos.filter(todo => todo.isNew);
const existingTodosWithComment = [];
for (const comment of comments) {
for (const comment of botComments) {
// If position is null or undefined, the comment is outdated and should be deleted
if (comment.position === null || comment.position === undefined) {
yield octokit.rest.pulls.deleteReviewComment({
owner,
repo,
comment_id: comment.id
});
continue;
}
for (const todo of addedTodos) {
if (comment.path === todo.filename &&
comment.line === todo.line &&
((_c = comment.user) === null || _c === void 0 ? void 0 : _c.login) === botName) {
if (comment.path === todo.filename && comment.line === todo.line) {
existingTodosWithComment.push(todo);
}
}
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

24 changes: 17 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,22 +144,32 @@ async function commentPr(
if (!issueNumber) throw new Error('Issue number not found')

// Get all comments on the pull request
const { data: comments } = await octokit.rest.pulls.listReviewComments({
const { data: allComments } = await octokit.rest.pulls.listReviewComments({
owner,
repo,
pull_number: prNumber
})

const botComments = allComments.filter(
comment => comment.user?.login === botName
)

const addedTodos = todos.filter(todo => todo.isNew)

const existingTodosWithComment: TodoItem[] = []
for (const comment of comments) {
for (const comment of botComments) {
// If position is null or undefined, the comment is outdated and should be deleted
if (comment.position === null || comment.position === undefined) {
await octokit.rest.pulls.deleteReviewComment({
owner,
repo,
comment_id: comment.id
})
continue
}

for (const todo of addedTodos) {
if (
comment.path === todo.filename &&
comment.line === todo.line &&
comment.user?.login === botName
) {
if (comment.path === todo.filename && comment.line === todo.line) {
existingTodosWithComment.push(todo)
}
}
Expand Down

0 comments on commit 014cdb1

Please sign in to comment.