mirror of
https://github.com/status-im/sourcecred.git
synced 2025-01-13 22:25:47 +00:00
GitHub entities expose timestampMs
(#1184)
Every GitHub entity from `RelationalView` now has a `timestampMs` method. This replaces the standalone `createdAt` method. Test plan: Snapshots look good.
This commit is contained in:
parent
1ec3945cdb
commit
b03f824e7d
@ -10,8 +10,6 @@ Array [
|
||||
|
||||
exports[`plugins/github/relationalView Comment has body 1`] = `"seems a bit capricious"`;
|
||||
|
||||
exports[`plugins/github/relationalView Comment has createdAt 1`] = `1519878210000`;
|
||||
|
||||
exports[`plugins/github/relationalView Comment has parent 1`] = `
|
||||
Object {
|
||||
"url": "https://github.com/sourcecred/example-github/pull/5#pullrequestreview-100313899",
|
||||
@ -119,6 +117,8 @@ Array [
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`plugins/github/relationalView Comment has timestampMs 1`] = `1519878210000`;
|
||||
|
||||
exports[`plugins/github/relationalView Comment has url 1`] = `"https://github.com/sourcecred/example-github/pull/5#discussion_r171460198"`;
|
||||
|
||||
exports[`plugins/github/relationalView Commit authors has expected number of authors 1`] = `1`;
|
||||
@ -135,6 +135,8 @@ exports[`plugins/github/relationalView Commit has message 1`] = `
|
||||
Add README, merge via PR."
|
||||
`;
|
||||
|
||||
exports[`plugins/github/relationalView Commit has timestampMs 1`] = `1519807427000`;
|
||||
|
||||
exports[`plugins/github/relationalView Commit has url 1`] = `"https://github.com/sourcecred/example-github/commit/0a223346b4e6dec0127b1e6aa892c4ee0424b66a"`;
|
||||
|
||||
exports[`plugins/github/relationalView Issue authors has expected number of authors 1`] = `1`;
|
||||
@ -162,8 +164,6 @@ Array [
|
||||
|
||||
exports[`plugins/github/relationalView Issue has body 1`] = `"This issue references another issue, namely #1"`;
|
||||
|
||||
exports[`plugins/github/relationalView Issue has createdAt 1`] = `1519807129000`;
|
||||
|
||||
exports[`plugins/github/relationalView Issue has number 1`] = `"2"`;
|
||||
|
||||
exports[`plugins/github/relationalView Issue has parent 1`] = `
|
||||
@ -174,6 +174,8 @@ Object {
|
||||
|
||||
exports[`plugins/github/relationalView Issue has reactions 1`] = `Array []`;
|
||||
|
||||
exports[`plugins/github/relationalView Issue has timestampMs 1`] = `1519807129000`;
|
||||
|
||||
exports[`plugins/github/relationalView Issue has title 1`] = `"A referencing issue."`;
|
||||
|
||||
exports[`plugins/github/relationalView Issue has url 1`] = `"https://github.com/sourcecred/example-github/issues/2"`;
|
||||
@ -204,8 +206,6 @@ exports[`plugins/github/relationalView Pull has body 1`] = `
|
||||
- then approve the pr"
|
||||
`;
|
||||
|
||||
exports[`plugins/github/relationalView Pull has createdAt 1`] = `1519807636000`;
|
||||
|
||||
exports[`plugins/github/relationalView Pull has deletions 1`] = `0`;
|
||||
|
||||
exports[`plugins/github/relationalView Pull has mergedAs 1`] = `
|
||||
@ -225,6 +225,8 @@ Object {
|
||||
|
||||
exports[`plugins/github/relationalView Pull has reactions 1`] = `Array []`;
|
||||
|
||||
exports[`plugins/github/relationalView Pull has timestampMs 1`] = `1519807636000`;
|
||||
|
||||
exports[`plugins/github/relationalView Pull has title 1`] = `"This pull request will be more contentious. I can feel it..."`;
|
||||
|
||||
exports[`plugins/github/relationalView Pull has url 1`] = `"https://github.com/sourcecred/example-github/pull/5"`;
|
||||
@ -331,12 +333,12 @@ Array [
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`plugins/github/relationalView Repo has createdAt 1`] = `1519807034000`;
|
||||
|
||||
exports[`plugins/github/relationalView Repo has name 1`] = `"example-github"`;
|
||||
|
||||
exports[`plugins/github/relationalView Repo has owner 1`] = `"sourcecred"`;
|
||||
|
||||
exports[`plugins/github/relationalView Repo has timestampMs 1`] = `1519807034000`;
|
||||
|
||||
exports[`plugins/github/relationalView Repo has url 1`] = `"https://github.com/sourcecred/example-github"`;
|
||||
|
||||
exports[`plugins/github/relationalView Repo issues has expected number of issues 1`] = `10`;
|
||||
@ -384,8 +386,6 @@ Array [
|
||||
|
||||
exports[`plugins/github/relationalView Review has body 1`] = `"hmmm.jpg"`;
|
||||
|
||||
exports[`plugins/github/relationalView Review has createdAt 1`] = `1519878210000`;
|
||||
|
||||
exports[`plugins/github/relationalView Review has parent 1`] = `
|
||||
Object {
|
||||
"url": "https://github.com/sourcecred/example-github/pull/5",
|
||||
@ -394,10 +394,14 @@ Object {
|
||||
|
||||
exports[`plugins/github/relationalView Review has state 1`] = `"CHANGES_REQUESTED"`;
|
||||
|
||||
exports[`plugins/github/relationalView Review has timestampMs 1`] = `1519878210000`;
|
||||
|
||||
exports[`plugins/github/relationalView Review has url 1`] = `"https://github.com/sourcecred/example-github/pull/5#pullrequestreview-100313899"`;
|
||||
|
||||
exports[`plugins/github/relationalView Userlike has login 1`] = `"wchargin"`;
|
||||
|
||||
exports[`plugins/github/relationalView Userlike has timestampMs 1`] = `null`;
|
||||
|
||||
exports[`plugins/github/relationalView Userlike has url 1`] = `"https://github.com/wchargin"`;
|
||||
|
||||
exports[`plugins/github/relationalView reaction detection set of all reactions matches snapshot 1`] = `
|
||||
|
@ -1,17 +0,0 @@
|
||||
// @flow
|
||||
|
||||
import * as R from "./relationalView";
|
||||
export type MsSinceEpoch = number;
|
||||
|
||||
export function createdAt(e: R.Entity): MsSinceEpoch | null {
|
||||
const handlers = {
|
||||
repo: () => null,
|
||||
issue: (x) => x.createdAt(),
|
||||
pull: (x) => x.createdAt(),
|
||||
review: (x) => x.createdAt(),
|
||||
comment: (x) => x.createdAt(),
|
||||
commit: () => null,
|
||||
userlike: () => null,
|
||||
};
|
||||
return R.match(handlers, e);
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
// @flow
|
||||
|
||||
import {exampleEntities} from "./example/example";
|
||||
import {createdAt} from "./createdAt";
|
||||
|
||||
describe("plugins/github/createdAt", () => {
|
||||
it("provides timestamps", () => {
|
||||
const results = {};
|
||||
const examples = exampleEntities();
|
||||
for (const name of Object.keys(examples)) {
|
||||
const entity = examples[name];
|
||||
results[name] = createdAt(entity);
|
||||
}
|
||||
expect(results).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"comment": 1519878210000,
|
||||
"commit": null,
|
||||
"issue": 1519807129000,
|
||||
"pull": 1519807636000,
|
||||
"repo": null,
|
||||
"review": 1519878210000,
|
||||
"userlike": null,
|
||||
}
|
||||
`);
|
||||
});
|
||||
});
|
@ -28,8 +28,6 @@ import {
|
||||
reviewCommentUrlToId,
|
||||
} from "./urlIdParse";
|
||||
|
||||
export type MsSinceEpoch = number;
|
||||
|
||||
const COMPAT_INFO = {
|
||||
type: "sourcecred/github/relationalView",
|
||||
version: "0.3.0",
|
||||
@ -300,7 +298,7 @@ export class RelationalView {
|
||||
pulls: expectAllNonNull(json, "pullRequests", json.pullRequests).map(
|
||||
(x) => this._addPull(address, x)
|
||||
),
|
||||
createdAt: +new Date(json.createdAt),
|
||||
timestampMs: +new Date(json.createdAt),
|
||||
};
|
||||
const raw = N.toRaw(address);
|
||||
this._repos.set(raw, entry);
|
||||
@ -342,7 +340,7 @@ export class RelationalView {
|
||||
reactions: expectAllNonNull(json, "reactions", json.reactions).map((x) =>
|
||||
this._addReaction(x)
|
||||
),
|
||||
createdAt: +new Date(json.createdAt),
|
||||
timestampMs: +new Date(json.createdAt),
|
||||
};
|
||||
this._issues.set(N.toRaw(address), entry);
|
||||
return address;
|
||||
@ -389,6 +387,7 @@ export class RelationalView {
|
||||
authors,
|
||||
message: json.message,
|
||||
hash: json.oid,
|
||||
timestampMs: +new Date(json.authoredDate),
|
||||
};
|
||||
this._commits.set(N.toRaw(address), entry);
|
||||
for (const parent of json.parents) {
|
||||
@ -426,7 +425,7 @@ export class RelationalView {
|
||||
reactions: expectAllNonNull(json, "reactions", json.reactions).map((x) =>
|
||||
this._addReaction(x)
|
||||
),
|
||||
createdAt: +new Date(json.createdAt),
|
||||
timestampMs: +new Date(json.createdAt),
|
||||
};
|
||||
this._pulls.set(N.toRaw(address), entry);
|
||||
return address;
|
||||
@ -447,7 +446,7 @@ export class RelationalView {
|
||||
),
|
||||
body: json.body,
|
||||
authors: this._addNullableAuthor(json.author),
|
||||
createdAt: +new Date(json.createdAt),
|
||||
timestampMs: +new Date(json.createdAt),
|
||||
};
|
||||
this._reviews.set(N.toRaw(address), entry);
|
||||
return address;
|
||||
@ -480,7 +479,7 @@ export class RelationalView {
|
||||
reactions: expectAllNonNull(json, "reactions", json.reactions).map((x) =>
|
||||
this._addReaction(x)
|
||||
),
|
||||
createdAt: +new Date(json.createdAt),
|
||||
timestampMs: +new Date(json.createdAt),
|
||||
};
|
||||
this._comments.set(N.toRaw(address), entry);
|
||||
return address;
|
||||
@ -720,6 +719,9 @@ export class _Entity<+T: Entry> {
|
||||
url(): string {
|
||||
return this._entry.url;
|
||||
}
|
||||
timestampMs(): number | null {
|
||||
throw new Error("Not implemented.");
|
||||
}
|
||||
}
|
||||
|
||||
type RepoEntry = {|
|
||||
@ -727,7 +729,7 @@ type RepoEntry = {|
|
||||
+url: string,
|
||||
+issues: IssueAddress[],
|
||||
+pulls: PullAddress[],
|
||||
+createdAt: MsSinceEpoch,
|
||||
+timestampMs: number,
|
||||
|};
|
||||
|
||||
export class Repo extends _Entity<RepoEntry> {
|
||||
@ -755,8 +757,8 @@ export class Repo extends _Entity<RepoEntry> {
|
||||
referencedBy(): Iterator<TextContentEntity> {
|
||||
return this._view._referencedBy(this);
|
||||
}
|
||||
createdAt(): MsSinceEpoch {
|
||||
return this._entry.createdAt;
|
||||
timestampMs(): number {
|
||||
return this._entry.timestampMs;
|
||||
}
|
||||
}
|
||||
|
||||
@ -768,7 +770,7 @@ type IssueEntry = {|
|
||||
+comments: CommentAddress[],
|
||||
+authors: UserlikeAddress[],
|
||||
+reactions: ReactionRecord[],
|
||||
+createdAt: MsSinceEpoch,
|
||||
+timestampMs: number,
|
||||
|};
|
||||
|
||||
export class Issue extends _Entity<IssueEntry> {
|
||||
@ -789,8 +791,8 @@ export class Issue extends _Entity<IssueEntry> {
|
||||
body(): string {
|
||||
return this._entry.body;
|
||||
}
|
||||
createdAt(): MsSinceEpoch {
|
||||
return this._entry.createdAt;
|
||||
timestampMs(): number {
|
||||
return this._entry.timestampMs;
|
||||
}
|
||||
*comments(): Iterator<Comment> {
|
||||
for (const address of this._entry.comments) {
|
||||
@ -824,7 +826,7 @@ type PullEntry = {|
|
||||
+deletions: number,
|
||||
+authors: UserlikeAddress[],
|
||||
+reactions: ReactionRecord[],
|
||||
+createdAt: MsSinceEpoch,
|
||||
+timestampMs: number,
|
||||
|};
|
||||
|
||||
export class Pull extends _Entity<PullEntry> {
|
||||
@ -854,8 +856,8 @@ export class Pull extends _Entity<PullEntry> {
|
||||
mergedAs(): ?CommitAddress {
|
||||
return this._entry.mergedAs;
|
||||
}
|
||||
createdAt(): MsSinceEpoch {
|
||||
return this._entry.createdAt;
|
||||
timestampMs(): number {
|
||||
return this._entry.timestampMs;
|
||||
}
|
||||
*reviews(): Iterator<Review> {
|
||||
for (const address of this._entry.reviews) {
|
||||
@ -890,7 +892,7 @@ type ReviewEntry = {|
|
||||
+comments: CommentAddress[],
|
||||
+state: T.PullRequestReviewState,
|
||||
+authors: UserlikeAddress[],
|
||||
+createdAt: MsSinceEpoch,
|
||||
+timestampMs: number,
|
||||
|};
|
||||
|
||||
export class Review extends _Entity<ReviewEntry> {
|
||||
@ -917,8 +919,8 @@ export class Review extends _Entity<ReviewEntry> {
|
||||
authors(): Iterator<Userlike> {
|
||||
return getAuthors(this._view, this._entry);
|
||||
}
|
||||
createdAt(): MsSinceEpoch {
|
||||
return this._entry.createdAt;
|
||||
timestampMs(): number {
|
||||
return this._entry.timestampMs;
|
||||
}
|
||||
references(): Iterator<ReferentEntity> {
|
||||
return this._view._references(this);
|
||||
@ -934,7 +936,7 @@ type CommentEntry = {|
|
||||
+url: string,
|
||||
+authors: UserlikeAddress[],
|
||||
+reactions: ReactionRecord[],
|
||||
+createdAt: MsSinceEpoch,
|
||||
+timestampMs: number,
|
||||
|};
|
||||
|
||||
export class Comment extends _Entity<CommentEntry> {
|
||||
@ -962,8 +964,8 @@ export class Comment extends _Entity<CommentEntry> {
|
||||
body(): string {
|
||||
return this._entry.body;
|
||||
}
|
||||
createdAt(): MsSinceEpoch {
|
||||
return this._entry.createdAt;
|
||||
timestampMs(): number {
|
||||
return this._entry.timestampMs;
|
||||
}
|
||||
authors(): Iterator<Userlike> {
|
||||
return getAuthors(this._view, this._entry);
|
||||
@ -985,6 +987,7 @@ type CommitEntry = {|
|
||||
+hash: string,
|
||||
+authors: UserlikeAddress[],
|
||||
+message: string,
|
||||
+timestampMs: number,
|
||||
|};
|
||||
|
||||
export class Commit extends _Entity<CommitEntry> {
|
||||
@ -1006,6 +1009,9 @@ export class Commit extends _Entity<CommitEntry> {
|
||||
hash(): string {
|
||||
return this._entry.hash;
|
||||
}
|
||||
timestampMs(): number {
|
||||
return this._entry.timestampMs;
|
||||
}
|
||||
}
|
||||
|
||||
type UserlikeEntry = {|
|
||||
@ -1023,6 +1029,9 @@ export class Userlike extends _Entity<UserlikeEntry> {
|
||||
referencedBy(): Iterator<TextContentEntity> {
|
||||
return this._view._referencedBy(this);
|
||||
}
|
||||
timestampMs(): null {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function assertExists<T>(item: ?T, address: N.StructuredAddress): T {
|
||||
|
@ -83,7 +83,7 @@ describe("plugins/github/relationalView", () => {
|
||||
has("owner", () => entity.owner());
|
||||
has("name", () => entity.name());
|
||||
has("url", () => entity.url());
|
||||
has("createdAt", () => entity.createdAt());
|
||||
has("timestampMs", () => entity.timestampMs());
|
||||
hasEntities("issues", () => entity.issues());
|
||||
hasEntities("pulls", () => entity.pulls());
|
||||
});
|
||||
@ -96,7 +96,7 @@ describe("plugins/github/relationalView", () => {
|
||||
has("title", () => entity.title());
|
||||
has("url", () => entity.url());
|
||||
has("parent", () => entity.parent());
|
||||
has("createdAt", () => entity.createdAt());
|
||||
has("timestampMs", () => entity.timestampMs());
|
||||
hasEntities("comments", () => entity.comments());
|
||||
hasEntities("authors", () => entity.authors());
|
||||
has("reactions", () => entity.reactions());
|
||||
@ -117,7 +117,7 @@ describe("plugins/github/relationalView", () => {
|
||||
hasEntities("comments", () => entity.comments());
|
||||
hasEntities("authors", () => entity.authors());
|
||||
has("reactions", () => entity.reactions());
|
||||
has("createdAt", () => entity.createdAt());
|
||||
has("timestampMs", () => entity.timestampMs());
|
||||
});
|
||||
|
||||
const review = Array.from(pull.reviews())[0];
|
||||
@ -129,7 +129,7 @@ describe("plugins/github/relationalView", () => {
|
||||
has("parent", () => entity.parent());
|
||||
hasEntities("comments", () => entity.comments());
|
||||
hasEntities("authors", () => entity.authors());
|
||||
has("createdAt", () => entity.createdAt());
|
||||
has("timestampMs", () => entity.timestampMs());
|
||||
});
|
||||
|
||||
const comment = Array.from(review.comments())[0];
|
||||
@ -140,7 +140,7 @@ describe("plugins/github/relationalView", () => {
|
||||
has("parent", () => entity.parent());
|
||||
hasEntities("authors", () => entity.authors());
|
||||
has("reactions", () => entity.reactions());
|
||||
has("createdAt", () => entity.createdAt());
|
||||
has("timestampMs", () => entity.timestampMs());
|
||||
});
|
||||
|
||||
const commit = Array.from(view.commits())[0];
|
||||
@ -149,6 +149,7 @@ describe("plugins/github/relationalView", () => {
|
||||
has("url", () => entity.url());
|
||||
has("message", () => entity.message());
|
||||
hasEntities("authors", () => entity.authors());
|
||||
has("timestampMs", () => entity.timestampMs());
|
||||
});
|
||||
|
||||
const userlike = Array.from(review.authors())[0];
|
||||
@ -156,6 +157,7 @@ describe("plugins/github/relationalView", () => {
|
||||
const entity = userlike;
|
||||
has("login", () => entity.login());
|
||||
has("url", () => entity.url());
|
||||
has("timestampMs", () => entity.timestampMs());
|
||||
});
|
||||
|
||||
describe("entity", () => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user