-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from dolthub/taylor/pulls
Add pull requests tab
- Loading branch information
Showing
106 changed files
with
2,756 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export const doltLogsQuery = `SELECT * FROM DOLT_LOG(?, '--parents') LIMIT ? OFFSET ?`; | ||
|
||
export const twoDotDoltLogsQuery = `SELECT * FROM DOLT_LOG(?, '--parents')`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { format } from "timeago.js"; | ||
import { Commit } from "../commits/commit.model"; | ||
import { PullSummary } from "../pullSummaries/pullSummary.model"; | ||
import { | ||
PullDetailCommit, | ||
PullDetails, | ||
PullDetailSummary, | ||
PullDetailUnion, | ||
} from "./pullDetail.model"; | ||
|
||
type PullDetail = typeof PullDetailUnion; | ||
|
||
export default function getPullDetails(summary?: PullSummary): PullDetails { | ||
const details: PullDetails = []; | ||
if (!summary) { | ||
return details; | ||
} | ||
// Add commits to details | ||
summary.commits.list.forEach(c => details.push(getCommit(c))); | ||
// Get commit summaries from sorted commits | ||
const sorted = details.sort(sortByTimestampDesc); | ||
const summaries = getSummaries(sorted); | ||
return sorted.concat(summaries).sort(sortByTimestampDesc) as PullDetails; | ||
} | ||
|
||
function sortByTimestampDesc(a: PullDetail, b: PullDetail) { | ||
return a.createdAt.valueOf() - b.createdAt.valueOf(); | ||
} | ||
|
||
function getCommit(c: Commit): PullDetailCommit { | ||
const parentCommitId = c.parents.length ? c.parents[0] : undefined; | ||
return { | ||
...c, | ||
username: c.committer.username ?? c.committer.displayName, | ||
createdAt: c.committedAt, | ||
parentCommitId, | ||
}; | ||
} | ||
|
||
const initialSummary: PullDetailSummary = { | ||
_id: "", | ||
username: "", | ||
createdAt: new Date(0), | ||
numCommits: 0, | ||
}; | ||
|
||
function getSummaries(sorted: PullDetail[]): PullDetailSummary[] { | ||
const summaries: PullDetailSummary[] = []; | ||
let summary = { ...initialSummary }; | ||
|
||
sorted.forEach(d => { | ||
// Only update summary for commits | ||
if ("commitId" in d) { | ||
const timeagosEqual = format(d.createdAt) === format(summary.createdAt); | ||
const needToUpdate = d.username !== summary.username || !timeagosEqual; | ||
|
||
if (needToUpdate) { | ||
// Push last summary if it has commit info | ||
if (summary.numCommits > 0) { | ||
summaries.push({ ...summary }); | ||
} | ||
// Update summary with changed information | ||
summary = { | ||
...summary, | ||
_id: `${d.username}/${d.createdAt.valueOf()}`, | ||
username: d.username, | ||
numCommits: 0, | ||
// Ensure that the summary shows up before first commit | ||
createdAt: new Date(d.createdAt.valueOf() - 1), | ||
}; | ||
} | ||
// Update number of commits every time | ||
summary.numCommits += 1; | ||
} else { | ||
// If not commit, push last summary | ||
if (summary.numCommits > 0) { | ||
summaries.push({ ...summary }); | ||
} | ||
// And start fresh | ||
summary = { ...initialSummary }; | ||
} | ||
}); | ||
|
||
// If last summary not pushed yet, push | ||
if (summary.numCommits > 0) { | ||
summaries.push({ ...summary }); | ||
} | ||
|
||
return summaries; | ||
} |
60 changes: 60 additions & 0 deletions
60
packages/graphql-server/src/pullDetails/pullDetail.model.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { | ||
Field, | ||
GraphQLTimestamp, | ||
ID, | ||
ObjectType, | ||
createUnionType, | ||
} from "@nestjs/graphql"; | ||
|
||
@ObjectType() | ||
export class PullDetailCommit { | ||
@Field(_type => ID) | ||
_id: string; | ||
|
||
@Field() | ||
username: string; | ||
|
||
@Field() | ||
message: string; | ||
|
||
@Field(_type => GraphQLTimestamp) | ||
createdAt: Date; | ||
|
||
@Field() | ||
commitId: string; | ||
|
||
@Field({ nullable: true }) | ||
parentCommitId?: string; | ||
} | ||
|
||
@ObjectType() | ||
export class PullDetailSummary { | ||
@Field(_type => ID) | ||
_id: string; | ||
|
||
@Field() | ||
username: string; | ||
|
||
@Field(_type => GraphQLTimestamp) | ||
createdAt: Date; | ||
|
||
@Field() | ||
numCommits: number; | ||
} | ||
|
||
export const PullDetailUnion = createUnionType({ | ||
name: "PullDetails", | ||
types: () => [PullDetailSummary, PullDetailCommit], | ||
resolveType: value => { | ||
if ("commitId" in value) { | ||
return PullDetailCommit; | ||
} | ||
if ("numCommits" in value) { | ||
return PullDetailSummary; | ||
} | ||
return undefined; | ||
}, | ||
}); | ||
|
||
export type PullDetail = typeof PullDetailUnion; | ||
export type PullDetails = PullDetail[]; |
21 changes: 21 additions & 0 deletions
21
packages/graphql-server/src/pullSummaries/pullSummary.model.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Field, ID, ObjectType } from "@nestjs/graphql"; | ||
import * as commit from "../commits/commit.model"; | ||
|
||
@ObjectType() | ||
export class PullSummary { | ||
@Field(_type => ID) | ||
_id: string; | ||
|
||
@Field(_type => commit.CommitList) | ||
commits: commit.CommitList; | ||
} | ||
|
||
export function fromAPISummary( | ||
_pullId: string, | ||
commits: commit.Commit[], | ||
): PullSummary { | ||
return { | ||
_id: `${_pullId}/summary`, | ||
commits: { list: commits }, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { registerEnumType } from "@nestjs/graphql"; | ||
|
||
export enum PullState { | ||
Open, | ||
Merged, | ||
Unspecified, | ||
} | ||
|
||
registerEnumType(PullState, { name: "PullState" }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Field, ID, ObjectType } from "@nestjs/graphql"; | ||
import { Commit } from "../commits/commit.model"; | ||
import getPullDetails from "../pullDetails/getPullDetails"; | ||
import { PullDetailUnion, PullDetails } from "../pullDetails/pullDetail.model"; | ||
import { | ||
PullSummary, | ||
fromAPISummary, | ||
} from "../pullSummaries/pullSummary.model"; | ||
import { PullState } from "./pull.enums"; | ||
|
||
@ObjectType() | ||
export class PullWithDetails { | ||
@Field(_type => ID) | ||
_id: string; | ||
|
||
@Field(_type => PullState) | ||
state: PullState; | ||
|
||
@Field(_type => PullSummary, { nullable: true }) | ||
summary?: PullSummary; | ||
|
||
@Field(_type => [PullDetailUnion], { nullable: true }) | ||
details?: PullDetails; | ||
} | ||
|
||
export function fromAPIModelPullWithDetails( | ||
pullId: string, | ||
commits: Commit[] = [], | ||
): PullWithDetails { | ||
const summary = fromAPISummary(pullId, commits); | ||
return { | ||
_id: `${pullId}/pullWithDetails`, | ||
state: commits.length ? PullState.Open : PullState.Merged, | ||
summary, | ||
details: getPullDetails(summary), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const callMerge = `CALL DOLT_MERGE(?, "--no-ff", "-m", ?)`; |
Oops, something went wrong.