// Copyright Epic Games, Inc. All Rights Reserved.
"use strict"
function getMergeMethodStyle(mergeMethod) {
switch(mergeMethod) {
case "automerge":
return {color: "black", style: "solid"}
case "initialSubmit":
console.log("Unexpected mergeMethod of initialSubmit")
return {color: "pink", style: "solid"}
case "merge_with_conflict":
return {color: "red", style: "dashed"}
case "manual_merge":
return {color: "darkgray", style: "dashed"}
case "populate":
return {color: "blue", style: "dashed"}
case "transfer":
return {color: "orange", style: "solid"}
}
console.log("UNKNOWN CASE: " + mergeMethod)
return {color: "pink", style: "solid"}
}
function getStreamGraphName(streamDisplayName) {
if (streamDisplayName.endsWith("/Main")) {
return streamDisplayName
}
const match = streamDisplayName.match(/\/\/[^\/]+\/([^\/]+).*/)
return match ? match[1] : streamDisplayName
}
async function getGitHubCommit(cl) {
const timeout = new Promise((resolve, reject) => {
setTimeout(() => reject(new Error('GitSync request took longer than 3 seconds')), 3000)
});
const response = await Promise.race([
$.get(`https://gitsync.devtools.epicgames.com/api/v1/changes/${cl}`),
timeout
]);
return {"commit":response.commit, "commitURL":response.commitURL};
}
async function getGitHubCommits(changes) {
return new Map(await Promise.all(Object.keys(changes).map(async cl => {
try {
const ghCommit = await getGitHubCommit(cl);
return [cl, ghCommit];
} catch(error) {
return [cl, null];
}
})));
}
function formatGitHubCommit(change) {
if (change) {
return `
`
}
return '
'
}
async function generateChangeList(dataObj) {
const gitHubCommits = await getGitHubCommits(dataObj.changes)
let html = '
'
// By default the keys are going to be numerically ordered, but we want changes to appear after their parent
// So go through and build them in a list order we prefer
const orderedChanges = Object.keys(dataObj.changes).map(k => parseInt(k))
const placedChanges = new Set()
for (let i = 0; i < orderedChanges.length; i++) {
const sourceCL = dataObj.changes[orderedChanges[i].toString()].sourceCL
if (sourceCL && !placedChanges.has(sourceCL)) {
let insertPoint = undefined
for (let j = i+1; j < orderedChanges.length; j++) {
if (orderedChanges[j] == sourceCL) {
insertPoint = j
}
else if (insertPoint) {
// Keep the children with lower CL# of a given stream in numerical order
if (orderedChanges[j] < orderedChanges[i]) {
insertPoint = j
} else {
break
}
}
}
if (insertPoint) {
const removedKey = orderedChanges.splice(i, 1)[0]
orderedChanges.splice(insertPoint, 0, removedKey)
i--
continue
}
}
placedChanges.add(orderedChanges[i])
}
for (const cl of orderedChanges) {
const clKey = cl.toString()
const changeDetails = dataObj.changes[clKey]
html += '