Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9401,18 +9401,15 @@ function run(context) {
console.error('Can\'t find the bot comment where the voting is taking place');
return;
}
const deadlineMatch = (_a = voteComment.body) === null || _a === void 0 ? void 0 : _a.match(/<!-- ##bot-vote-deadline## (\S+) -->/);
if (deadlineMatch) {
const deadline = new Date(deadlineMatch[1]);
if (deadline > new Date()) {
yield octokit_1.default.issues.createComment({
owner,
repo,
issue_number: number,
body: `The vote is still open until ${deadline.toUTCString()}.`,
});
return;
}
const deadline = (0, voteSync_1.resolveDeadline)((_a = voteComment.body) !== null && _a !== void 0 ? _a : '', voteComment.created_at);
if (deadline > new Date()) {
yield octokit_1.default.issues.createComment({
owner,
repo,
issue_number: number,
body: `The vote is still open until ${deadline.toUTCString()}.`,
});
return;
}
yield (0, voteSync_1.syncIssueVoteLog)(owner, repo, number);
const reactions = yield octokit_1.default.reactions.listForIssueComment({
Expand Down Expand Up @@ -9558,10 +9555,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.syncIssueVoteLog = exports.buildUpdatedComment = exports.diffVotes = exports.parseStateMarker = void 0;
exports.syncIssueVoteLog = exports.buildUpdatedComment = exports.diffVotes = exports.parseStateMarker = exports.resolveDeadline = void 0;
const config_1 = __nccwpck_require__(6373);
const octokit_1 = __importDefault(__nccwpck_require__(6161));
const STATE_MARKER_RE = /<!-- ##bot-vote-log-state## ({.*?}) -->/;
const DEADLINE_MARKER_RE = /<!-- ##bot-vote-deadline## (\S+) -->/;
function resolveDeadline(body, commentCreatedAt) {
const match = body.match(DEADLINE_MARKER_RE);
if (match)
return new Date(match[1]);
const deadline = new Date(commentCreatedAt);
deadline.setDate(deadline.getDate() + config_1.VOTE_PERIOD_DAYS);
return deadline;
}
exports.resolveDeadline = resolveDeadline;
function parseStateMarker(body) {
const match = body.match(STATE_MARKER_RE);
if (!match || !match[1])
Expand Down Expand Up @@ -9646,8 +9653,7 @@ function syncIssueVoteLog(owner, repo, issueNumber, members) {
}));
const body = (_a = voteComment.body) !== null && _a !== void 0 ? _a : '';
const state = parseStateMarker(body);
const deadlineMatch = body.match(/<!-- ##bot-vote-deadline## (\S+) -->/);
const deadline = deadlineMatch ? new Date(deadlineMatch[1]) : null;
const deadline = resolveDeadline(body, voteComment.created_at);
const now = new Date();
const newLines = diffVotes(state, liveReactions, deadline, now);
if (newLines.length === 0)
Expand Down
24 changes: 10 additions & 14 deletions src/commands/voteEnd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { BOT_USERNAME, MAINTAINERS_TEAM } from '../config';
import {
reactToComment, commentToIssue, addLabels, removeLabel, hasLabel,
} from '../bot';
import { syncIssueVoteLog } from './voteSync';
import { syncIssueVoteLog, resolveDeadline } from './voteSync';
import { LabelName } from '../labels';
import octokit from '../octokit';

Expand Down Expand Up @@ -116,19 +116,15 @@ export default async function run(context: Context) {
return;
}

const deadlineMatch = voteComment.body?.match(/<!-- ##bot-vote-deadline## (\S+) -->/);
if (deadlineMatch) {
const deadline = new Date(deadlineMatch[1]!);
if (deadline > new Date()) {
await octokit.issues.createComment({
owner,
repo,
issue_number: number,
body: `The vote is still open until ${deadline.toUTCString()}.`,
});

return;
}
const deadline = resolveDeadline(voteComment.body ?? '', voteComment.created_at);
if (deadline > new Date()) {
await octokit.issues.createComment({
owner,
repo,
issue_number: number,
body: `The vote is still open until ${deadline.toUTCString()}.`,
});
return;
}

await syncIssueVoteLog(owner, repo, number);
Expand Down
15 changes: 14 additions & 1 deletion src/commands/voteSync.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
import { parseStateMarker, diffVotes, buildUpdatedComment } from './voteSync';
import {
parseStateMarker, diffVotes, buildUpdatedComment, resolveDeadline,
} from './voteSync';

test('resolveDeadline reads the marker when present', () => {
const body = 'body\n\n<!-- ##bot-vote-deadline## 2026-06-25T07:00:00.000Z -->';
expect(resolveDeadline(body, '2026-06-11T07:00:00Z'))
.toEqual(new Date('2026-06-25T07:00:00.000Z'));
});

test('resolveDeadline falls back to comment date plus the vote period', () => {
expect(resolveDeadline('no marker here', '2026-06-11T07:00:00Z'))
.toEqual(new Date('2026-06-25T07:00:00Z'));
});

test('parseStateMarker returns empty object when marker is absent', () => {
expect(parseStateMarker('<!-- ##bot-voting-marker## -->\nsome body')).toEqual({});
Expand Down
15 changes: 12 additions & 3 deletions src/commands/voteSync.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GetResponseDataTypeFromEndpointMethod } from '@octokit/types';
import { BOT_USERNAME } from '../config';
import { BOT_USERNAME, VOTE_PERIOD_DAYS } from '../config';
import octokit from '../octokit';

type Comment = GetResponseDataTypeFromEndpointMethod<
Expand All @@ -15,6 +15,16 @@ export interface LiveReaction {
}

const STATE_MARKER_RE = /<!-- ##bot-vote-log-state## ({.*?}) -->/;
const DEADLINE_MARKER_RE = /<!-- ##bot-vote-deadline## (\S+) -->/;

export function resolveDeadline(body: string, commentCreatedAt: string): Date {
const match = body.match(DEADLINE_MARKER_RE);
if (match) return new Date(match[1]!);

const deadline = new Date(commentCreatedAt);
deadline.setDate(deadline.getDate() + VOTE_PERIOD_DAYS);
return deadline;
}

export function parseStateMarker(body: string): VoteState {
const match = body.match(STATE_MARKER_RE);
Expand Down Expand Up @@ -128,8 +138,7 @@ export async function syncIssueVoteLog(
const body = voteComment.body ?? '';
const state = parseStateMarker(body);

const deadlineMatch = body.match(/<!-- ##bot-vote-deadline## (\S+) -->/);
const deadline = deadlineMatch ? new Date(deadlineMatch[1]!) : null;
const deadline = resolveDeadline(body, voteComment.created_at);

const now = new Date();
const newLines = diffVotes(state, liveReactions, deadline, now);
Expand Down