Skip to content
This repository was archived by the owner on Jul 1, 2024. It is now read-only.

Commit c302cf6

Browse files
jablkoelibarzilay
authored andcommitted
Make info.now a Date
Slightly stricter than `string`. Consistent with the rest of `PrInfo` (`lastPushDate`, `lastActivityDate`, etc.). Also, use Day.js for `tooEarlyForLabelsOrProjects`. Cosmetic changes, no change in behavior. Update snapshots.
1 parent 05454a8 commit c302cf6

File tree

8 files changed

+16
-17
lines changed

8 files changed

+16
-17
lines changed

src/_tests/fixturedActions.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { readdirSync, readJsonSync } from "fs-extra";
33
import { join } from "path";
44
import { toMatchFile } from "jest-file-snapshot";
55
import { process } from "../compute-pr-actions";
6-
import { deriveStateForPR, BotResult } from "../pr-info";
6+
import { deriveStateForPR } from "../pr-info";
77
import { PR } from "../queries/schema/PR";
88
import { scrubDiagnosticDetails } from "../util/util";
99
import * as cachedQueries from "./cachedQueries.json";
@@ -42,7 +42,7 @@ async function testFixture(dir: string) {
4242
prInfo,
4343
(expr: string) => Promise.resolve(files[expr] as string),
4444
(name: string, _until?: Date) => name in downloads ? downloads[name] : 0,
45-
(readJsonSync(derivedPath) as BotResult).now
45+
new Date(readJsonSync(derivedPath).now)
4646
);
4747

4848
const action = process(derived);

src/_tests/fixtures/43960-post-close/derived.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"type": "remove",
3-
"now": "2020-04-30T12:01:56-07:00",
3+
"now": "2020-04-30T19:01:56.000Z",
44
"pr_number": 43960,
55
"message": "PR is not active",
66
"isDraft": false

src/_tests/fixtures/44105/derived.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"type": "remove",
3-
"now": "2020-04-28T15:49:39-07:00",
3+
"now": "2020-04-28T22:49:39.000Z",
44
"pr_number": 44105,
55
"message": "PR is not active",
66
"isDraft": false

src/_tests/fixtures/44256/derived.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"type": "remove",
3-
"now": "2020-04-30T12:07:55-07:00",
3+
"now": "2020-04-30T19:07:55.000Z",
44
"pr_number": 44256,
55
"message": "PR is not active",
66
"isDraft": false

src/_tests/fixtures/44290/derived.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"type": "remove",
3-
"now": "2020-04-28T12:41:44-04:00",
3+
"now": "2020-04-28T16:41:44.000Z",
44
"pr_number": 44290,
55
"message": "PR is a draft",
66
"isDraft": true

src/commands/create-fixture.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as computeActions from "../compute-pr-actions";
2-
import { deriveStateForPR, BotResult, queryPRInfo } from "../pr-info";
2+
import { deriveStateForPR, queryPRInfo } from "../pr-info";
33
import { ApolloQueryResult } from "@apollo/client/core";
44
import { writeFileSync, mkdirSync, existsSync, readJsonSync } from "fs-extra";
55
import { join } from "path";
@@ -86,7 +86,7 @@ export default async function main(directory: string, overwriteInfo: boolean) {
8686
}
8787

8888
function getTimeFromFile() {
89-
return (readJsonSync(derivedFixturePath) as BotResult).now;
89+
return new Date(readJsonSync(derivedFixturePath).now);
9090
}
9191
}
9292

src/compute-pr-actions.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,15 +361,14 @@ export function process(prInfo: BotResult,
361361
// This bot is faster than CI in coming back to give a response, and so the bot starts flipping between
362362
// a 'where is CI'-ish state and a 'got CI deets' state. To work around this, we wait a
363363
// minute since the last timeline push action before label/project states can be updated
364-
const oneMinute = 60 * 1000;
365-
const tooEarlyForLabelsOrProjects = info.lastPushDate.getTime() + oneMinute < (new Date(prInfo.now)).getTime();
366-
context.shouldUpdateLabels = tooEarlyForLabelsOrProjects;
367-
context.shouldUpdateProjectColumn = tooEarlyForLabelsOrProjects;
364+
const tooEarlyForLabelsOrProjects = dayjs(info.now).diff(info.lastPushDate, "minutes") < 1;
365+
context.shouldUpdateLabels = !tooEarlyForLabelsOrProjects;
366+
context.shouldUpdateProjectColumn = !tooEarlyForLabelsOrProjects;
368367

369368
return context;
370369
}
371370

372-
function makeStaleness(now: string, author: string, otherOwners: string[]) { // curried for convenience
371+
function makeStaleness(now: Date, author: string, otherOwners: string[]) { // curried for convenience
373372
return (kind: StalenessKind, since: Date,
374373
freshDays: number, attnDays: number, nearDays: number,
375374
doneColumn: ColumnName | "CLOSE") => {

src/pr-info.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ export type PopularityLevel =
2929
// Some error found, will be passed to `process` to report in a comment
3030
interface BotError {
3131
readonly type: "error";
32-
readonly now: string;
32+
readonly now: Date;
3333
readonly pr_number: number;
3434
readonly message: string;
3535
readonly author: string | undefined;
3636
}
3737

3838
interface BotEnsureRemovedFromProject {
3939
readonly type: "remove";
40-
readonly now: string;
40+
readonly now: Date;
4141
readonly pr_number: number;
4242
readonly message: string;
4343
readonly isDraft: boolean;
@@ -77,7 +77,7 @@ export interface PrInfo {
7777
readonly type: "info";
7878

7979
/** ISO8601 date string for the time the PR info was created at */
80-
readonly now: string;
80+
readonly now: Date;
8181

8282
readonly pr_number: number;
8383

@@ -183,7 +183,7 @@ export async function deriveStateForPR(
183183
prInfo: PR_repository_pullRequest,
184184
fetchFile = defaultFetchFile,
185185
getDownloads = getMonthlyDownloadCount,
186-
now = new Date().toISOString(),
186+
now = new Date(),
187187
): Promise<BotResult> {
188188
if (prInfo.author == null) return botError(prInfo.number, "PR author does not exist");
189189

0 commit comments

Comments
 (0)