Add authorDate tracking to Git commits (#1153)

Modifies the Git plugin so that we now track commit author dates.
Similar to in #1152, they are encoded in MsSinceEpoch.

Test plan: `yarn test --full` passes, except for the pre-existing
failure discussed in #1151.

Thanks to @s-ben for a conversation which motivated these changes.
This commit is contained in:
Dandelion Mané 2019-05-21 06:56:57 +03:00 committed by GitHub
parent d51c0b6715
commit da5bce255e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 4 deletions

View File

@ -1 +1 @@
{"commitToRepoId":{"0a223346b4e6dec0127b1e6aa892c4ee0424b66a":{"sourcecred/example-github":true},"6bd1b4c0b719c22c688a74863be07a699b7b9b34":{"sourcecred/example-github":true},"6d5b3aa31ebb68a06ceb46bbd6cf49b6ccd6f5e6":{"sourcecred/example-github":true},"c430bd74455105f77215ece51945094ceeee6c86":{"sourcecred/example-github":true},"ec91adb718a6045b492303f00d8e8beb957dc780":{"sourcecred/example-github":true},"ecc889dc94cf6da17ae6eab5bb7b7155f577519d":{"sourcecred/example-github":true}},"commits":{"0a223346b4e6dec0127b1e6aa892c4ee0424b66a":{"hash":"0a223346b4e6dec0127b1e6aa892c4ee0424b66a","parentHashes":["ec91adb718a6045b492303f00d8e8beb957dc780","ecc889dc94cf6da17ae6eab5bb7b7155f577519d"],"shortHash":"0a22334","summary":"Merge pull request #3 from sourcecred/add-readme"},"6bd1b4c0b719c22c688a74863be07a699b7b9b34":{"hash":"6bd1b4c0b719c22c688a74863be07a699b7b9b34","parentHashes":["c430bd74455105f77215ece51945094ceeee6c86"],"shortHash":"6bd1b4c","summary":"A commit from someone with no GitHub account"},"6d5b3aa31ebb68a06ceb46bbd6cf49b6ccd6f5e6":{"hash":"6d5b3aa31ebb68a06ceb46bbd6cf49b6ccd6f5e6","parentHashes":["0a223346b4e6dec0127b1e6aa892c4ee0424b66a"],"shortHash":"6d5b3aa","summary":"This pull request will be more contentious. I can feel it... (#5)"},"c430bd74455105f77215ece51945094ceeee6c86":{"hash":"c430bd74455105f77215ece51945094ceeee6c86","parentHashes":["6d5b3aa31ebb68a06ceb46bbd6cf49b6ccd6f5e6"],"shortHash":"c430bd7","summary":"Hello from credbot!"},"ec91adb718a6045b492303f00d8e8beb957dc780":{"hash":"ec91adb718a6045b492303f00d8e8beb957dc780","parentHashes":[],"shortHash":"ec91adb","summary":"Commit without pull request."},"ecc889dc94cf6da17ae6eab5bb7b7155f577519d":{"hash":"ecc889dc94cf6da17ae6eab5bb7b7155f577519d","parentHashes":["ec91adb718a6045b492303f00d8e8beb957dc780"],"shortHash":"ecc889d","summary":"Add README, merge via PR."}}}
{"commitToRepoId":{"0a223346b4e6dec0127b1e6aa892c4ee0424b66a":{"sourcecred/example-github":true},"6bd1b4c0b719c22c688a74863be07a699b7b9b34":{"sourcecred/example-github":true},"6d5b3aa31ebb68a06ceb46bbd6cf49b6ccd6f5e6":{"sourcecred/example-github":true},"c430bd74455105f77215ece51945094ceeee6c86":{"sourcecred/example-github":true},"ec91adb718a6045b492303f00d8e8beb957dc780":{"sourcecred/example-github":true},"ecc889dc94cf6da17ae6eab5bb7b7155f577519d":{"sourcecred/example-github":true}},"commits":{"0a223346b4e6dec0127b1e6aa892c4ee0424b66a":{"authorDate":1519807427000,"hash":"0a223346b4e6dec0127b1e6aa892c4ee0424b66a","parentHashes":["ec91adb718a6045b492303f00d8e8beb957dc780","ecc889dc94cf6da17ae6eab5bb7b7155f577519d"],"shortHash":"0a22334","summary":"Merge pull request #3 from sourcecred/add-readme"},"6bd1b4c0b719c22c688a74863be07a699b7b9b34":{"authorDate":1536806901000,"hash":"6bd1b4c0b719c22c688a74863be07a699b7b9b34","parentHashes":["c430bd74455105f77215ece51945094ceeee6c86"],"shortHash":"6bd1b4c","summary":"A commit from someone with no GitHub account"},"6d5b3aa31ebb68a06ceb46bbd6cf49b6ccd6f5e6":{"authorDate":1519878354000,"hash":"6d5b3aa31ebb68a06ceb46bbd6cf49b6ccd6f5e6","parentHashes":["0a223346b4e6dec0127b1e6aa892c4ee0424b66a"],"shortHash":"6d5b3aa","summary":"This pull request will be more contentious. I can feel it... (#5)"},"c430bd74455105f77215ece51945094ceeee6c86":{"authorDate":1536788634000,"hash":"c430bd74455105f77215ece51945094ceeee6c86","parentHashes":["6d5b3aa31ebb68a06ceb46bbd6cf49b6ccd6f5e6"],"shortHash":"c430bd7","summary":"Hello from credbot!"},"ec91adb718a6045b492303f00d8e8beb957dc780":{"authorDate":1519807271000,"hash":"ec91adb718a6045b492303f00d8e8beb957dc780","parentHashes":[],"shortHash":"ec91adb","summary":"Commit without pull request."},"ecc889dc94cf6da17ae6eab5bb7b7155f577519d":{"authorDate":1519807329000,"hash":"ecc889dc94cf6da17ae6eab5bb7b7155f577519d","parentHashes":["ec91adb718a6045b492303f00d8e8beb957dc780"],"shortHash":"ecc889d","summary":"Add README, merge via PR."}}}

View File

@ -27,6 +27,7 @@
},
"commits": {
"3715ddfb8d4c4fd2a6f6af75488c82f84c92ec2f": {
"createdAt": 981173106000,
"hash": "3715ddfb8d4c4fd2a6f6af75488c82f84c92ec2f",
"parentHashes": [
"69c5aad50eec8f2a0a07c988c3b283a6490eb45b"
@ -35,6 +36,7 @@
"summary": "Clean up TODOS"
},
"69c5aad50eec8f2a0a07c988c3b283a6490eb45b": {
"createdAt": 981173106000,
"hash": "69c5aad50eec8f2a0a07c988c3b283a6490eb45b",
"parentHashes": [
"e8b7a8f19701cd5a25e4a097d513ead60e5f8bcc"
@ -43,6 +45,7 @@
"summary": "Solve quantum gravity"
},
"8d287c3bfbf8455ef30187bf5153ffc1b6eef268": {
"createdAt": 981173106000,
"hash": "8d287c3bfbf8455ef30187bf5153ffc1b6eef268",
"parentHashes": [
"c08ee3a4edea384d5291ffcbf06724a13ed72325"
@ -51,6 +54,7 @@
"summary": "Add gravity defiance module"
},
"c08ee3a4edea384d5291ffcbf06724a13ed72325": {
"createdAt": 981173106000,
"hash": "c08ee3a4edea384d5291ffcbf06724a13ed72325",
"parentHashes": [
"c2b51945e7457546912a8ce158ed9d294558d294"
@ -59,12 +63,14 @@
"summary": "Add repository description"
},
"c2b51945e7457546912a8ce158ed9d294558d294": {
"createdAt": 981173106000,
"hash": "c2b51945e7457546912a8ce158ed9d294558d294",
"parentHashes": [],
"shortHash": "c2b5194",
"summary": "Initial commit"
},
"c90f6424017f787bbbaf22e4082a01355546f7e3": {
"createdAt": 981173106000,
"hash": "c90f6424017f787bbbaf22e4082a01355546f7e3",
"parentHashes": [
"3715ddfb8d4c4fd2a6f6af75488c82f84c92ec2f"
@ -73,6 +79,7 @@
"summary": " This | has leading whitespace."
},
"d160cca97611e9dfed642522ad44408d0292e8ea": {
"createdAt": 981173106000,
"hash": "d160cca97611e9dfed642522ad44408d0292e8ea",
"parentHashes": [
"8d287c3bfbf8455ef30187bf5153ffc1b6eef268"
@ -81,6 +88,7 @@
"summary": "Discover gravity"
},
"e8b7a8f19701cd5a25e4a097d513ead60e5f8bcc": {
"createdAt": 981173106000,
"hash": "e8b7a8f19701cd5a25e4a097d513ead60e5f8bcc",
"parentHashes": [
"d160cca97611e9dfed642522ad44408d0292e8ea"

View File

@ -54,14 +54,15 @@ export function loadRepository(
}
function findCommits(git: GitDriver, rootRef: string): Commit[] {
return git(["log", "--format=%H %h %P|%s", rootRef])
return git(["log", "--format=%H %h %at %P|%s", rootRef])
.split("\n")
.filter((line) => line.length > 0)
.map((line) => {
const pipeLocation = line.indexOf("|");
const first = line.slice(0, pipeLocation).trim();
const summary = line.slice(pipeLocation + 1);
const [hash, shortHash, ...parentHashes] = first.split(" ");
return {hash, shortHash, summary, parentHashes};
const [hash, shortHash, authorDate, ...parentHashes] = first.split(" ");
const createdAt = +authorDate * 1000;
return {hash, shortHash, createdAt, summary, parentHashes};
});
}

View File

@ -15,12 +15,14 @@ describe("plugins/git/mergeRepository", () => {
hash: "commit1",
shortHash: "commit1",
summary: "a commit",
createdAt: 123456789,
parentHashes: [],
},
commit2: {
hash: "commit2",
shortHash: "commit2",
summary: "another commit",
createdAt: 123456789,
parentHashes: ["commit1"],
},
},
@ -35,12 +37,14 @@ describe("plugins/git/mergeRepository", () => {
hash: "commit1",
shortHash: "commit1",
summary: "a commit",
createdAt: 123456789,
parentHashes: [],
},
commit3: {
hash: "commit3",
shortHash: "commit3",
summary: "a third commit",
createdAt: 123456789,
parentHashes: ["commit1"],
},
},
@ -91,6 +95,7 @@ describe("plugins/git/mergeRepository", () => {
hash: "commit1",
shortHash: "commit1",
summary: "a conflicting commit",
createdAt: 123456789,
parentHashes: ["commit0"],
},
},

View File

@ -17,30 +17,35 @@ describe("plugins/git/render", () => {
hash: "singleRepoCommit",
shortHash: "singleRepo",
summary: "A simple example commit",
createdAt: 123456789,
parentHashes: [],
};
const twoRepoCommit = {
hash: "twoRepoCommit",
shortHash: "twoRepo",
summary: "Two repos claim dominion over this commit",
createdAt: 123456789,
parentHashes: [],
};
const noRepoCommit = {
hash: "noRepoCommit",
shortHash: "noRepo",
summary: "commitToRepoId has no memory of this commit ",
createdAt: 123456789,
parentHashes: [],
};
const zeroRepoCommit = {
hash: "zeroRepoCommit",
shortHash: "zeroRepo",
summary: "This commit has exactly zero repoIds matching",
createdAt: 123456789,
parentHashes: [],
};
const unregisteredCommit = {
hash: "unregisteredCommit",
shortHash: "unregistered",
summary: "This commit isn't in the Repository",
createdAt: 123456789,
parentHashes: [],
};
const exampleRepository: Repository = Object.freeze({

View File

@ -8,6 +8,7 @@ export type Repository = {|
// containing this commit.
+commitToRepoId: {[Hash]: {+[RepoIdString]: true}},
|};
export type MsSinceEpoch = number;
export type Hash = string;
export type Commit = {|
+hash: Hash,
@ -15,5 +16,9 @@ export type Commit = {|
// a shorter version of the hash;
// shortHash is not guaranteed unique.
+shortHash: string,
// The author date, not the committer date.
// Rationale: the committer date can change e.g. when a commit is rebased,
// so the author date better represents when the commit was actually created.
+createdAt: MsSinceEpoch,
+summary: string, // Oneline commit summary
|};