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

Commit 96873ca

Browse files
committed
Move the sha256 bit to util/util.ts
1 parent 0a00fae commit 96873ca

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

src/comments.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import crypto = require("crypto");
1+
import { sha256 } from "./util/util";
22

33
export type Comment = { tag: string, status: string };
44

@@ -65,7 +65,7 @@ ${names.map(n => `${n}`).join(" ")}
6565
});
6666

6767
export const PingStaleReviewer = (reviewedAbbrOid: string, reviewers: string[]) => ({
68-
tag: `stale-ping-${tinyHash(reviewers.join("-"))}-${reviewedAbbrOid}`,
68+
tag: `stale-ping-${sha256(reviewers.join("-")).substr(0, 6)}-${reviewedAbbrOid}`,
6969
status: `@${reviewers.join(", @")} Thank you for reviewing this PR! The author has pushed new commits since your last review. Could you take another look and submit a fresh review?`
7070
});
7171

@@ -91,7 +91,3 @@ I can't [accept a merge request](${uri}) until the PR has a green CI and was app
9191
9292
Thanks, and happy typing!`
9393
});
94-
95-
function tinyHash(s: string): string {
96-
return crypto.createHash("sha256").update(s).digest("hex").substr(0, 6);
97-
}

src/compute-pr-actions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import * as Comments from "./comments";
22
import { PrInfo, BotError, BotEnsureRemovedFromProject, BotNoPackages, FileInfo } from "./pr-info";
33
import { CIResult } from "./util/CIResult";
44
import { ReviewInfo } from "./pr-info";
5-
import { noNulls, flatten, unique, sameUser, daysSince } from "./util/util";
6-
import * as crypto from "crypto";
5+
import { noNulls, flatten, unique, sameUser, daysSince, sha256 } from "./util/util";
76

87
type ColumnName =
98
| "Needs Maintainer Action"
@@ -496,7 +495,8 @@ function createWelcomeComment(info: ExtendedPrInfo) {
496495

497496
const approved = emoji(info.approved);
498497
const reviewLink = (f: FileInfo) =>
499-
`[\`${f.path.replace(/^types\/(.*\/)/, "$1")}\`](${uriForReview(info.pr_number)}/${info.headCommitOid}#diff-${crypto.createHash("sha256").update(f.path).digest("hex")})`;
498+
`[\`${f.path.replace(/^types\/(.*\/)/, "$1")}\`](${
499+
uriForReview(info.pr_number)}/${info.headCommitOid}#diff-${sha256(f.path)})`;
500500

501501
if (info.hasNewPackages) {
502502
display(` * ${approved} Only ${requiredApprover} can approve changes when there are new packages added`);

src/util/util.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import moment = require("moment");
1+
import * as crypto from "crypto";
2+
import * as moment from "moment";
23

34
export function noNulls<T>(arr: ReadonlyArray<T | null | undefined> | null | undefined): T[] {
45
if (arr == null) return [];
@@ -75,3 +76,7 @@ export function authorNotBot(node: { login: string } | { author?: { login: strin
7576
export function scrubDiagnosticDetails(s: string) {
7677
return s.replace(/<details><summary>Diagnostic Information.*?<\/summary>(?:\\n)+```json\\n{.*?\\n}\\n```(?:\\n)+<\/details>/sg, "... diagnostics scrubbed ...");
7778
}
79+
80+
export function sha256(s: string) {
81+
return crypto.createHash("sha256").update(s).digest("hex")
82+
}

0 commit comments

Comments
 (0)