From f6f74aa9cb3920226f855e0137eeeca0a7b65685 Mon Sep 17 00:00:00 2001 From: Long Tran Date: Wed, 27 Nov 2024 12:30:11 +1100 Subject: [PATCH 01/31] fix: add remote branches to repo graph --- dist/index.js | 67 ++++++++++++++++++++++++------------------- src/main.ts | 79 +++++++++++++++++++++++++++++---------------------- src/types.ts | 5 ++++ 3 files changed, 87 insertions(+), 64 deletions(-) diff --git a/dist/index.js b/dist/index.js index 03e2208..a8bf417 100644 --- a/dist/index.js +++ b/dist/index.js @@ -42837,53 +42837,36 @@ async function main({ currentPullRequest, pullRequests, mainBranch, + remoteBranches, perennialBranches, skipSingleStacks }) { const repoGraph = new import_graphology.MultiDirectedGraph(); - repoGraph.addNode(mainBranch, { + remoteBranches.forEach((remoteBranch) => { + repoGraph.mergeNode(remoteBranch, { + type: "branch", + ref: remoteBranch + }); + }); + repoGraph.mergeNode(mainBranch, { type: "perennial", ref: mainBranch }); perennialBranches.forEach((perennialBranch) => { - repoGraph.addNode(perennialBranch, { + repoGraph.mergeNode(perennialBranch, { type: "perennial", ref: perennialBranch }); }); pullRequests.forEach((pullRequest) => { - repoGraph.addNode(pullRequest.headRefName, { + repoGraph.mergeNode(pullRequest.headRefName, { type: "pull-request", ...pullRequest }); }); pullRequests.forEach((pullRequest) => { - repoGraph.addDirectedEdge(pullRequest.baseRefName, pullRequest.headRefName); + repoGraph.mergeDirectedEdge(pullRequest.baseRefName, pullRequest.headRefName); }); - const getStackGraph = (pullRequest) => { - const stackGraph2 = repoGraph.copy(); - stackGraph2.setNodeAttribute(pullRequest.headRefName, "isCurrent", true); - (0, import_graphology_traversal.bfsFromNode)( - stackGraph2, - pullRequest.headRefName, - (ref, attributes) => { - stackGraph2.setNodeAttribute(ref, "shouldPrint", true); - return attributes.type === "perennial"; - }, - { - mode: "inbound" - } - ); - (0, import_graphology_traversal.dfsFromNode)( - stackGraph2, - pullRequest.headRefName, - (ref) => { - stackGraph2.setNodeAttribute(ref, "shouldPrint", true); - }, - { mode: "outbound" } - ); - return stackGraph2; - }; const getOutput = (graph) => { const lines = []; const terminatingRefs = [mainBranch, ...perennialBranches]; @@ -42911,7 +42894,7 @@ async function main({ return lines.join("\n"); }; const jobs = []; - const stackGraph = getStackGraph(currentPullRequest); + const stackGraph = getStackGraph(repoGraph, currentPullRequest); const shouldSkip = () => { const neighbors = stackGraph.neighbors(currentPullRequest.headRefName); const allPerennialBranches = stackGraph.filterNodes( @@ -42928,7 +42911,7 @@ async function main({ } jobs.push(async () => { core.info(`Updating stack details for PR #${stackNode.number}`); - const stackGraph2 = getStackGraph(stackNode); + const stackGraph2 = getStackGraph(repoGraph, stackNode); const output = getOutput(stackGraph2); let description = stackNode.body ?? ""; description = updateDescription({ @@ -42944,6 +42927,30 @@ async function main({ }); await Promise.allSettled(jobs.map((job) => job())); } +function getStackGraph(repoGraph, pullRequest) { + const stackGraph = repoGraph.copy(); + stackGraph.setNodeAttribute(pullRequest.headRefName, "isCurrent", true); + (0, import_graphology_traversal.bfsFromNode)( + stackGraph, + pullRequest.headRefName, + (ref, attributes) => { + stackGraph.setNodeAttribute(ref, "shouldPrint", true); + return attributes.type === "perennial"; + }, + { + mode: "inbound" + } + ); + (0, import_graphology_traversal.dfsFromNode)( + stackGraph, + pullRequest.headRefName, + (ref) => { + stackGraph.setNodeAttribute(ref, "shouldPrint", true); + }, + { mode: "outbound" } + ); + return stackGraph; +} function updateDescription({ description, output diff --git a/src/main.ts b/src/main.ts index 698d58e..5cc2151 100644 --- a/src/main.ts +++ b/src/main.ts @@ -10,62 +10,42 @@ export async function main({ currentPullRequest, pullRequests, mainBranch, + remoteBranches, perennialBranches, skipSingleStacks, }: Context) { const repoGraph = new MultiDirectedGraph() - repoGraph.addNode(mainBranch, { + remoteBranches.forEach((remoteBranch) => { + repoGraph.mergeNode(remoteBranch, { + type: 'branch', + ref: remoteBranch, + }) + }) + + repoGraph.mergeNode(mainBranch, { type: 'perennial', ref: mainBranch, }) perennialBranches.forEach((perennialBranch) => { - repoGraph.addNode(perennialBranch, { + repoGraph.mergeNode(perennialBranch, { type: 'perennial', ref: perennialBranch, }) }) pullRequests.forEach((pullRequest) => { - repoGraph.addNode(pullRequest.headRefName, { + repoGraph.mergeNode(pullRequest.headRefName, { type: 'pull-request', ...pullRequest, }) }) pullRequests.forEach((pullRequest) => { - repoGraph.addDirectedEdge(pullRequest.baseRefName, pullRequest.headRefName) + repoGraph.mergeDirectedEdge(pullRequest.baseRefName, pullRequest.headRefName) }) - const getStackGraph = (pullRequest: PullRequest) => { - const stackGraph = repoGraph.copy() as MultiDirectedGraph - stackGraph.setNodeAttribute(pullRequest.headRefName, 'isCurrent', true) - - bfsFromNode( - stackGraph, - pullRequest.headRefName, - (ref, attributes) => { - stackGraph.setNodeAttribute(ref, 'shouldPrint', true) - return attributes.type === 'perennial' - }, - { - mode: 'inbound', - } - ) - - dfsFromNode( - stackGraph, - pullRequest.headRefName, - (ref) => { - stackGraph.setNodeAttribute(ref, 'shouldPrint', true) - }, - { mode: 'outbound' } - ) - - return stackGraph - } - const getOutput = (graph: MultiDirectedGraph) => { const lines: string[] = [] const terminatingRefs = [mainBranch, ...perennialBranches] @@ -102,7 +82,7 @@ export async function main({ const jobs: Array<() => Promise> = [] - const stackGraph = getStackGraph(currentPullRequest) + const stackGraph = getStackGraph(repoGraph, currentPullRequest) const shouldSkip = () => { const neighbors = stackGraph.neighbors(currentPullRequest.headRefName) @@ -129,7 +109,7 @@ export async function main({ jobs.push(async () => { core.info(`Updating stack details for PR #${stackNode.number}`) - const stackGraph = getStackGraph(stackNode) + const stackGraph = getStackGraph(repoGraph, stackNode) const output = getOutput(stackGraph) let description = stackNode.body ?? '' @@ -149,6 +129,37 @@ export async function main({ await Promise.allSettled(jobs.map((job) => job())) } +function getStackGraph( + repoGraph: MultiDirectedGraph, + pullRequest: PullRequest +) { + const stackGraph = repoGraph.copy() as MultiDirectedGraph + stackGraph.setNodeAttribute(pullRequest.headRefName, 'isCurrent', true) + + bfsFromNode( + stackGraph, + pullRequest.headRefName, + (ref, attributes) => { + stackGraph.setNodeAttribute(ref, 'shouldPrint', true) + return attributes.type === 'perennial' + }, + { + mode: 'inbound', + } + ) + + dfsFromNode( + stackGraph, + pullRequest.headRefName, + (ref) => { + stackGraph.setNodeAttribute(ref, 'shouldPrint', true) + }, + { mode: 'outbound' } + ) + + return stackGraph +} + export function updateDescription({ description, output, diff --git a/src/types.ts b/src/types.ts index 59385d3..9ab12e2 100644 --- a/src/types.ts +++ b/src/types.ts @@ -17,11 +17,16 @@ export type Context = { mainBranch: string currentPullRequest: PullRequest pullRequests: PullRequest[] + remoteBranches: string[] perennialBranches: string[] skipSingleStacks: boolean } export type StackNode = + | { + type: 'branch' + ref: string + } | { type: 'perennial' ref: string From 5843fcb3a127bd4ce81b726e5aa993ddbc3eca42 Mon Sep 17 00:00:00 2001 From: Long Tran Date: Wed, 27 Nov 2024 14:25:17 +1100 Subject: [PATCH 02/31] inspect only --- dist/index.js | 401 ++++++++++++++++++++++---------------------------- src/main.ts | 24 +-- 2 files changed, 193 insertions(+), 232 deletions(-) diff --git a/dist/index.js b/dist/index.js index a8bf417..776115e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -4420,18 +4420,18 @@ var require_webidl = __commonJS({ webidl.errors.exception = function(message) { return new TypeError(`${message.header}: ${message.message}`); }; - webidl.errors.conversionFailed = function(context3) { - const plural = context3.types.length === 1 ? "" : " one of"; - const message = `${context3.argument} could not be converted to${plural}: ${context3.types.join(", ")}.`; + webidl.errors.conversionFailed = function(context2) { + const plural = context2.types.length === 1 ? "" : " one of"; + const message = `${context2.argument} could not be converted to${plural}: ${context2.types.join(", ")}.`; return webidl.errors.exception({ - header: context3.prefix, + header: context2.prefix, message }); }; - webidl.errors.invalidArgument = function(context3) { + webidl.errors.invalidArgument = function(context2) { return webidl.errors.exception({ - header: context3.prefix, - message: `"${context3.value}" is an invalid ${context3.type}.` + header: context2.prefix, + message: `"${context2.value}" is an invalid ${context2.type}.` }); }; webidl.brandCheck = function(V, I, opts = void 0) { @@ -9752,15 +9752,15 @@ var require_api_request = __commonJS({ } addSignal(this, signal); } - onConnect(abort, context3) { + onConnect(abort, context2) { if (!this.callback) { throw new RequestAbortedError(); } this.abort = abort; - this.context = context3; + this.context = context2; } onHeaders(statusCode, rawHeaders, resume, statusMessage) { - const { callback, opaque, abort, context: context3, responseHeaders, highWaterMark } = this; + const { callback, opaque, abort, context: context2, responseHeaders, highWaterMark } = this; const headers = responseHeaders === "raw" ? util2.parseRawHeaders(rawHeaders) : util2.parseHeaders(rawHeaders); if (statusCode < 200) { if (this.onInfo) { @@ -9787,7 +9787,7 @@ var require_api_request = __commonJS({ trailers: this.trailers, opaque, body, - context: context3 + context: context2 }); } } @@ -9907,15 +9907,15 @@ var require_api_stream = __commonJS({ } addSignal(this, signal); } - onConnect(abort, context3) { + onConnect(abort, context2) { if (!this.callback) { throw new RequestAbortedError(); } this.abort = abort; - this.context = context3; + this.context = context2; } onHeaders(statusCode, rawHeaders, resume, statusMessage) { - const { factory, opaque, context: context3, callback, responseHeaders } = this; + const { factory, opaque, context: context2, callback, responseHeaders } = this; const headers = responseHeaders === "raw" ? util2.parseRawHeaders(rawHeaders) : util2.parseHeaders(rawHeaders); if (statusCode < 200) { if (this.onInfo) { @@ -9943,7 +9943,7 @@ var require_api_stream = __commonJS({ statusCode, headers, opaque, - context: context3 + context: context2 }); if (!res || typeof res.write !== "function" || typeof res.end !== "function" || typeof res.on !== "function") { throw new InvalidReturnValueError("expected Writable"); @@ -10135,17 +10135,17 @@ var require_api_pipeline = __commonJS({ this.res = null; addSignal(this, signal); } - onConnect(abort, context3) { + onConnect(abort, context2) { const { ret, res } = this; assert(!res, "pipeline cannot be retried"); if (ret.destroyed) { throw new RequestAbortedError(); } this.abort = abort; - this.context = context3; + this.context = context2; } onHeaders(statusCode, rawHeaders, resume) { - const { opaque, handler, context: context3 } = this; + const { opaque, handler, context: context2 } = this; if (statusCode < 200) { if (this.onInfo) { const headers = this.responseHeaders === "raw" ? util2.parseRawHeaders(rawHeaders) : util2.parseHeaders(rawHeaders); @@ -10163,7 +10163,7 @@ var require_api_pipeline = __commonJS({ headers, opaque, body: this.res, - context: context3 + context: context2 }); } catch (err) { this.res.on("error", util2.nop); @@ -10247,7 +10247,7 @@ var require_api_upgrade = __commonJS({ this.context = null; addSignal(this, signal); } - onConnect(abort, context3) { + onConnect(abort, context2) { if (!this.callback) { throw new RequestAbortedError(); } @@ -10258,7 +10258,7 @@ var require_api_upgrade = __commonJS({ throw new SocketError("bad upgrade", null); } onUpgrade(statusCode, rawHeaders, socket) { - const { callback, opaque, context: context3 } = this; + const { callback, opaque, context: context2 } = this; assert.strictEqual(statusCode, 101); removeSignal(this); this.callback = null; @@ -10267,7 +10267,7 @@ var require_api_upgrade = __commonJS({ headers, socket, opaque, - context: context3 + context: context2 }); } onError(err) { @@ -10335,18 +10335,18 @@ var require_api_connect = __commonJS({ this.abort = null; addSignal(this, signal); } - onConnect(abort, context3) { + onConnect(abort, context2) { if (!this.callback) { throw new RequestAbortedError(); } this.abort = abort; - this.context = context3; + this.context = context2; } onHeaders() { throw new SocketError("bad connect", null); } onUpgrade(statusCode, rawHeaders, socket) { - const { callback, opaque, context: context3 } = this; + const { callback, opaque, context: context2 } = this; removeSignal(this); this.callback = null; let headers = rawHeaders; @@ -10358,7 +10358,7 @@ var require_api_connect = __commonJS({ headers, socket, opaque, - context: context3 + context: context2 }); } onError(err) { @@ -19338,8 +19338,8 @@ var require_dist_node2 = __commonJS({ function isKeyOperator(operator) { return operator === ";" || operator === "&" || operator === "?"; } - function getValues(context3, operator, key, modifier) { - var value = context3[key], result = []; + function getValues(context2, operator, key, modifier) { + var value = context2[key], result = []; if (isDefined(value) && value !== "") { if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") { value = value.toString(); @@ -19403,7 +19403,7 @@ var require_dist_node2 = __commonJS({ expand: expand.bind(null, template) }; } - function expand(template, context3) { + function expand(template, context2) { var operators = ["+", "#", ".", "/", ";", "?", "&"]; template = template.replace( /\{([^\{\}]+)\}|([^\{\}]+)/g, @@ -19417,7 +19417,7 @@ var require_dist_node2 = __commonJS({ } expression.split(/,/g).forEach(function(variable) { var tmp = /([^:\*]*)(?::(\d+)|(\*))?/.exec(variable); - values.push(getValues(context3, operator, tmp[1], tmp[2] || tmp[3])); + values.push(getValues(context2, operator, tmp[1], tmp[2] || tmp[3])); }); if (operator && operator !== "+") { var separator = ","; @@ -30535,7 +30535,7 @@ var require_compiler = __commonJS({ var valueAssignments = []; var currentPath = ""; var data = /* @__PURE__ */ Object.create(null); - var context3 = data; + var context2 = data; var arrayMode = false; return reduce(nodes); function reduce(nodes2) { @@ -30573,10 +30573,10 @@ var require_compiler = __commonJS({ } else { fullPath = key; } - if (typeof context3[key] !== "undefined") { + if (typeof context2[key] !== "undefined") { genError("Cannot redefine existing key '" + fullPath + "'.", line, column); } - context3[key] = reduceValueNode(value); + context2[key] = reduceValueNode(value); if (!pathAssigned(fullPath)) { assignedPaths.push(fullPath); valueAssignments.push(fullPath); @@ -30615,7 +30615,7 @@ var require_compiler = __commonJS({ genError("Cannot redefine existing key '" + path2 + "'.", line, column); } assignedPaths.push(quotedPath); - context3 = deepRef(data, path2, /* @__PURE__ */ Object.create(null), line, column); + context2 = deepRef(data, path2, /* @__PURE__ */ Object.create(null), line, column); currentPath = path2; } function addTableArray(node2) { @@ -30630,12 +30630,12 @@ var require_compiler = __commonJS({ return p.indexOf(quotedPath) !== 0; }); assignedPaths.push(quotedPath); - context3 = deepRef(data, path2, [], line, column); + context2 = deepRef(data, path2, [], line, column); currentPath = quotedPath; - if (context3 instanceof Array) { + if (context2 instanceof Array) { var newObj = /* @__PURE__ */ Object.create(null); - context3.push(newObj); - context3 = newObj; + context2.push(newObj); + context2 = newObj; } else { genError("Cannot redefine existing key '" + path2 + "'.", line, column); } @@ -30709,11 +30709,10 @@ var require_toml = __commonJS({ // src/index.ts var core4 = __toESM(require_core()); -var github2 = __toESM(require_github()); +var github = __toESM(require_github()); // src/main.ts var core = __toESM(require_core()); -var github = __toESM(require_github()); var import_graphology = __toESM(require_graphology_cjs()); var import_graphology_traversal = __toESM(require_graphology_traversal()); @@ -33318,13 +33317,13 @@ function classifyCharacter(code3) { } // node_modules/micromark-util-resolve-all/index.js -function resolveAll(constructs2, events, context3) { +function resolveAll(constructs2, events, context2) { const called = []; let index2 = -1; while (++index2 < constructs2.length) { const resolve = constructs2[index2].resolveAll; if (resolve && !called.includes(resolve)) { - events = resolve(events, context3); + events = resolve(events, context2); called.push(resolve); } } @@ -33337,7 +33336,7 @@ var attention = { tokenize: tokenizeAttention, resolveAll: resolveAllAttention }; -function resolveAllAttention(events, context3) { +function resolveAllAttention(events, context2) { let index2 = -1; let open; let group; @@ -33352,7 +33351,7 @@ function resolveAllAttention(events, context3) { open = index2; while (open--) { if (events[open][0] === "exit" && events[open][1].type === "attentionSequence" && events[open][1]._open && // If the markers are the same: - context3.sliceSerialize(events[open][1]).charCodeAt(0) === context3.sliceSerialize(events[index2][1]).charCodeAt(0)) { + context2.sliceSerialize(events[open][1]).charCodeAt(0) === context2.sliceSerialize(events[index2][1]).charCodeAt(0)) { if ((events[open][1]._close || events[index2][1]._open) && (events[index2][1].end.offset - events[index2][1].start.offset) % 3 && !((events[open][1].end.offset - events[open][1].start.offset + events[index2][1].end.offset - events[index2][1].start.offset) % 3)) { continue; } @@ -33386,35 +33385,35 @@ function resolveAllAttention(events, context3) { nextEvents = []; if (events[open][1].end.offset - events[open][1].start.offset) { nextEvents = push(nextEvents, [ - ["enter", events[open][1], context3], - ["exit", events[open][1], context3] + ["enter", events[open][1], context2], + ["exit", events[open][1], context2] ]); } nextEvents = push(nextEvents, [ - ["enter", group, context3], - ["enter", openingSequence, context3], - ["exit", openingSequence, context3], - ["enter", text5, context3] + ["enter", group, context2], + ["enter", openingSequence, context2], + ["exit", openingSequence, context2], + ["enter", text5, context2] ]); nextEvents = push( nextEvents, resolveAll( - context3.parser.constructs.insideSpan.null, + context2.parser.constructs.insideSpan.null, events.slice(open + 1, index2), - context3 + context2 ) ); nextEvents = push(nextEvents, [ - ["exit", text5, context3], - ["enter", closingSequence, context3], - ["exit", closingSequence, context3], - ["exit", group, context3] + ["exit", text5, context2], + ["enter", closingSequence, context2], + ["exit", closingSequence, context2], + ["exit", group, context2] ]); if (events[index2][1].end.offset - events[index2][1].start.offset) { offset = 2; nextEvents = push(nextEvents, [ - ["enter", events[index2][1], context3], - ["exit", events[index2][1], context3] + ["enter", events[index2][1], context2], + ["exit", events[index2][1], context2] ]); } else { offset = 0; @@ -34173,10 +34172,10 @@ function subtokenize(events) { } function subcontent(events, eventIndex) { const token = events[eventIndex][1]; - const context3 = events[eventIndex][2]; + const context2 = events[eventIndex][2]; let startPosition = eventIndex - 1; const startPositions = []; - const tokenizer = token._tokenizer || context3.parser[token.contentType](token.start); + const tokenizer = token._tokenizer || context2.parser[token.contentType](token.start); const childEvents = tokenizer.events; const jumps = []; const gaps = {}; @@ -34192,7 +34191,7 @@ function subcontent(events, eventIndex) { } startPositions.push(startPosition); if (!current._tokenizer) { - stream = context3.sliceStream(current); + stream = context2.sliceStream(current); if (!current.next) { stream.push(null); } @@ -34681,7 +34680,7 @@ var headingAtx = { tokenize: tokenizeHeadingAtx, resolve: resolveHeadingAtx }; -function resolveHeadingAtx(events, context3) { +function resolveHeadingAtx(events, context2) { let contentEnd = events.length - 2; let contentStart = 3; let content3; @@ -34708,10 +34707,10 @@ function resolveHeadingAtx(events, context3) { contentType: "text" }; splice(events, contentStart, contentEnd - contentStart + 1, [ - ["enter", content3, context3], - ["enter", text5, context3], - ["exit", text5, context3], - ["exit", content3, context3] + ["enter", content3, context2], + ["enter", text5, context2], + ["exit", text5, context2], + ["exit", content3, context2] ]); } return events; @@ -35564,7 +35563,7 @@ function resolveAllLabelEnd(events) { } return events; } -function resolveToLabelEnd(events, context3) { +function resolveToLabelEnd(events, context2) { let index2 = events.length; let offset = 0; let token; @@ -35608,27 +35607,27 @@ function resolveToLabelEnd(events, context3) { end: Object.assign({}, events[close - 2][1].start) }; media = [ - ["enter", group, context3], - ["enter", label, context3] + ["enter", group, context2], + ["enter", label, context2] ]; media = push(media, events.slice(open + 1, open + offset + 3)); - media = push(media, [["enter", text5, context3]]); + media = push(media, [["enter", text5, context2]]); media = push( media, resolveAll( - context3.parser.constructs.insideSpan.null, + context2.parser.constructs.insideSpan.null, events.slice(open + offset + 4, close - 3), - context3 + context2 ) ); media = push(media, [ - ["exit", text5, context3], + ["exit", text5, context2], events[close - 2], events[close - 1], - ["exit", label, context3] + ["exit", label, context2] ]); media = push(media, events.slice(close + 1)); - media = push(media, [["exit", group, context3]]); + media = push(media, [["exit", group, context2]]); splice(events, open, events.length, media); return events; } @@ -36072,7 +36071,7 @@ var setextUnderline = { tokenize: tokenizeSetextUnderline, resolveTo: resolveToSetextUnderline }; -function resolveToSetextUnderline(events, context3) { +function resolveToSetextUnderline(events, context2) { let index2 = events.length; let content3; let text5; @@ -36102,13 +36101,13 @@ function resolveToSetextUnderline(events, context3) { }; events[text5][1].type = "setextHeadingText"; if (definition3) { - events.splice(text5, 0, ["enter", heading2, context3]); - events.splice(definition3 + 1, 0, ["exit", events[content3][1], context3]); + events.splice(text5, 0, ["enter", heading2, context2]); + events.splice(definition3 + 1, 0, ["exit", events[content3][1], context2]); events[content3][1].end = Object.assign({}, events[definition3][1].end); } else { events[content3][1] = heading2; } - events.push(["exit", heading2, context3]); + events.push(["exit", heading2, context2]); return events; } function tokenizeSetextUnderline(effects, ok3, nok) { @@ -36260,7 +36259,7 @@ function initializeFactory(field) { } function createResolver(extraResolver) { return resolveAllText; - function resolveAllText(events, context3) { + function resolveAllText(events, context2) { let index2 = -1; let enter; while (++index2 <= events.length) { @@ -36278,15 +36277,15 @@ function createResolver(extraResolver) { enter = void 0; } } - return extraResolver ? extraResolver(events, context3) : events; + return extraResolver ? extraResolver(events, context2) : events; } } -function resolveAllLineSuffixes(events, context3) { +function resolveAllLineSuffixes(events, context2) { let eventIndex = 0; while (++eventIndex <= events.length) { if ((eventIndex === events.length || events[eventIndex][1].type === "lineEnding") && events[eventIndex - 1][1].type === "data") { const data = events[eventIndex - 1][1]; - const chunks = context3.sliceStream(data); + const chunks = context2.sliceStream(data); let index2 = chunks.length; let bufferIndex = -1; let size = 0; @@ -36330,8 +36329,8 @@ function resolveAllLineSuffixes(events, context3) { events.splice( eventIndex, 0, - ["enter", token, context3], - ["exit", token, context3] + ["enter", token, context2], + ["exit", token, context2] ); eventIndex += 2; } @@ -36370,7 +36369,7 @@ function createTokenizer(parser, initialize, from) { interrupt: true }) }; - const context3 = { + const context2 = { previous: null, code: null, containerState: {}, @@ -36382,12 +36381,12 @@ function createTokenizer(parser, initialize, from) { defineSkip, write }; - let state = initialize.tokenize.call(context3, effects); + let state = initialize.tokenize.call(context2, effects); let expectedCode; if (initialize.resolveAll) { resolveAllConstructs.push(initialize); } - return context3; + return context2; function write(slice) { chunks = push(chunks, slice); main2(); @@ -36395,8 +36394,8 @@ function createTokenizer(parser, initialize, from) { return []; } addResult(initialize, 0); - context3.events = resolveAll(resolveAllConstructs, context3.events, context3); - return context3.events; + context2.events = resolveAll(resolveAllConstructs, context2.events, context2); + return context2.events; } function sliceSerialize(token, expandTabs) { return serializeChunks(sliceStream(token), expandTabs); @@ -36459,21 +36458,21 @@ function createTokenizer(parser, initialize, from) { point3._index++; } } - context3.previous = code3; + context2.previous = code3; consumed = true; } function enter(type, fields) { const token = fields || {}; token.type = type; token.start = now(); - context3.events.push(["enter", token, context3]); + context2.events.push(["enter", token, context2]); stack.push(token); return token; } function exit3(type) { const token = stack.pop(); token.end = now(); - context3.events.push(["exit", token, context3]); + context2.events.push(["exit", token, context2]); return token; } function onsuccessfulconstruct(construct, info4) { @@ -36521,16 +36520,16 @@ function createTokenizer(parser, initialize, from) { info4 = store(); currentConstruct = construct; if (!construct.partial) { - context3.currentConstruct = construct; + context2.currentConstruct = construct; } - if (construct.name && context3.parser.constructs.disable.null.includes(construct.name)) { + if (construct.name && context2.parser.constructs.disable.null.includes(construct.name)) { return nok(code3); } return construct.tokenize.call( // If we do have fields, create an object w/ `context` as its // prototype. // This allows a “live binding”, which is needed for `interrupt`. - fields ? Object.assign(Object.create(context3), fields) : context3, + fields ? Object.assign(Object.create(context2), fields) : context2, effects, ok3, nok @@ -36558,21 +36557,21 @@ function createTokenizer(parser, initialize, from) { } if (construct.resolve) { splice( - context3.events, + context2.events, from2, - context3.events.length - from2, - construct.resolve(context3.events.slice(from2), context3) + context2.events.length - from2, + construct.resolve(context2.events.slice(from2), context2) ); } if (construct.resolveTo) { - context3.events = construct.resolveTo(context3.events, context3); + context2.events = construct.resolveTo(context2.events, context2); } } function store() { const startPoint = now(); - const startPrevious = context3.previous; - const startCurrentConstruct = context3.currentConstruct; - const startEventsIndex = context3.events.length; + const startPrevious = context2.previous; + const startCurrentConstruct = context2.currentConstruct; + const startEventsIndex = context2.events.length; const startStack = Array.from(stack); return { restore, @@ -36580,9 +36579,9 @@ function createTokenizer(parser, initialize, from) { }; function restore() { point3 = startPoint; - context3.previous = startPrevious; - context3.currentConstruct = startCurrentConstruct; - context3.events.length = startEventsIndex; + context2.previous = startPrevious; + context2.currentConstruct = startCurrentConstruct; + context2.events.length = startEventsIndex; stack = startStack; accountForPotentialSkip(); } @@ -37014,7 +37013,7 @@ function compiler(options) { type: "root", children: [] }; - const context3 = { + const context2 = { stack: [tree], tokenStack: [], config: config2, @@ -37045,16 +37044,16 @@ function compiler(options) { { sliceSerialize: events[index2][2].sliceSerialize }, - context3 + context2 ), events[index2][1] ); } } - if (context3.tokenStack.length > 0) { - const tail = context3.tokenStack[context3.tokenStack.length - 1]; + if (context2.tokenStack.length > 0) { + const tail = context2.tokenStack[context2.tokenStack.length - 1]; const handler = tail[1] || defaultOnError; - handler.call(context3, void 0, tail[0]); + handler.call(context2, void 0, tail[0]); } tree.position = { start: point2( @@ -37321,14 +37320,14 @@ function compiler(options) { tail.position.end = point2(token.end); } function onexitlineending(token) { - const context3 = this.stack[this.stack.length - 1]; + const context2 = this.stack[this.stack.length - 1]; if (this.data.atHardBreak) { - const tail = context3.children[context3.children.length - 1]; + const tail = context2.children[context2.children.length - 1]; tail.position.end = point2(token.end); this.data.atHardBreak = void 0; return; } - if (!this.data.setextHeadingSlurpLineEnding && config2.canContainEols.includes(context3.type)) { + if (!this.data.setextHeadingSlurpLineEnding && config2.canContainEols.includes(context2.type)) { onenterdata.call(this, token); onexitdata.call(this, token); } @@ -41868,7 +41867,7 @@ function tokenizePotentialGfmFootnoteCall(effects, ok3, nok) { return ok3(code3); } } -function resolveToPotentialGfmFootnoteCall(events, context3) { +function resolveToPotentialGfmFootnoteCall(events, context2) { let index2 = events.length; let labelStart; while (index2--) { @@ -41907,22 +41906,22 @@ function resolveToPotentialGfmFootnoteCall(events, context3) { // Take the `labelImageMarker` (now `data`, the `!`) events[index2 + 1], events[index2 + 2], - ["enter", call, context3], + ["enter", call, context2], // The `[` events[index2 + 3], events[index2 + 4], // The `^`. - ["enter", marker, context3], - ["exit", marker, context3], + ["enter", marker, context2], + ["exit", marker, context2], // Everything in between. - ["enter", string4, context3], - ["enter", chunk, context3], - ["exit", chunk, context3], - ["exit", string4, context3], + ["enter", string4, context2], + ["enter", chunk, context2], + ["exit", chunk, context2], + ["exit", string4, context2], // The ending (`]`, properly parsed and labelled). events[events.length - 2], events[events.length - 1], - ["exit", call, context3] + ["exit", call, context2] ]; events.splice(index2, events.length - index2 + 1, ...replacement); return events; @@ -42111,7 +42110,7 @@ function gfmStrikethrough(options) { null: [126] } }; - function resolveAllStrikethrough(events, context3) { + function resolveAllStrikethrough(events, context2) { let index2 = -1; while (++index2 < events.length) { if (events[index2][0] === "enter" && events[index2][1].type === "strikethroughSequenceTemporary" && events[index2][1]._close) { @@ -42132,25 +42131,25 @@ function gfmStrikethrough(options) { end: Object.assign({}, events[index2][1].start) }; const nextEvents = [ - ["enter", strikethrough, context3], - ["enter", events[open][1], context3], - ["exit", events[open][1], context3], - ["enter", text5, context3] + ["enter", strikethrough, context2], + ["enter", events[open][1], context2], + ["exit", events[open][1], context2], + ["enter", text5, context2] ]; - const insideSpan2 = context3.parser.constructs.insideSpan.null; + const insideSpan2 = context2.parser.constructs.insideSpan.null; if (insideSpan2) { splice( nextEvents, nextEvents.length, 0, - resolveAll(insideSpan2, events.slice(open + 1, index2), context3) + resolveAll(insideSpan2, events.slice(open + 1, index2), context2) ); } splice(nextEvents, nextEvents.length, 0, [ - ["exit", text5, context3], - ["enter", events[index2][1], context3], - ["exit", events[index2][1], context3], - ["exit", strikethrough, context3] + ["exit", text5, context2], + ["enter", events[index2][1], context2], + ["exit", events[index2][1], context2], + ["exit", strikethrough, context2] ]); splice(events, open - 1, index2 - open + 3, nextEvents); index2 = open + nextEvents.length - 2; @@ -42541,7 +42540,7 @@ function tokenizeTable(effects, ok3, nok) { return bodyRowData(code3); } } -function resolveTable(events, context3) { +function resolveTable(events, context2) { let index2 = -1; let inFirstCellAwaitingPipe = true; let rowKind = 0; @@ -42560,7 +42559,7 @@ function resolveTable(events, context3) { if (token.type === "tableHead") { afterHeadAwaitingFirstBodyRow = false; if (lastTableEnd !== 0) { - flushTableEnd(map5, context3, lastTableEnd, currentTable, currentBody); + flushTableEnd(map5, context2, lastTableEnd, currentTable, currentBody); currentBody = void 0; lastTableEnd = 0; } @@ -42570,7 +42569,7 @@ function resolveTable(events, context3) { // Note: correct end is set later. end: Object.assign({}, token.end) }; - map5.add(index2, 0, [["enter", currentTable, context3]]); + map5.add(index2, 0, [["enter", currentTable, context2]]); } else if (token.type === "tableRow" || token.type === "tableDelimiterRow") { inFirstCellAwaitingPipe = true; currentCell = void 0; @@ -42584,7 +42583,7 @@ function resolveTable(events, context3) { // Note: correct end is set later. end: Object.assign({}, token.end) }; - map5.add(index2, 0, [["enter", currentBody, context3]]); + map5.add(index2, 0, [["enter", currentBody, context2]]); } rowKind = token.type === "tableDelimiterRow" ? 2 : currentBody ? 3 : 1; } else if (rowKind && (token.type === "data" || token.type === "tableDelimiterMarker" || token.type === "tableDelimiterFiller")) { @@ -42594,7 +42593,7 @@ function resolveTable(events, context3) { cell[0] = cell[1]; currentCell = flushCell( map5, - context3, + context2, lastCell, rowKind, void 0, @@ -42612,7 +42611,7 @@ function resolveTable(events, context3) { cell[0] = cell[1]; currentCell = flushCell( map5, - context3, + context2, lastCell, rowKind, void 0, @@ -42632,14 +42631,14 @@ function resolveTable(events, context3) { cell[0] = cell[1]; currentCell = flushCell( map5, - context3, + context2, lastCell, rowKind, index2, currentCell ); } else if (cell[1] !== 0) { - currentCell = flushCell(map5, context3, cell, rowKind, index2, currentCell); + currentCell = flushCell(map5, context2, cell, rowKind, index2, currentCell); } rowKind = 0; } else if (rowKind && (token.type === "data" || token.type === "tableDelimiterMarker" || token.type === "tableDelimiterFiller")) { @@ -42647,45 +42646,45 @@ function resolveTable(events, context3) { } } if (lastTableEnd !== 0) { - flushTableEnd(map5, context3, lastTableEnd, currentTable, currentBody); + flushTableEnd(map5, context2, lastTableEnd, currentTable, currentBody); } - map5.consume(context3.events); + map5.consume(context2.events); index2 = -1; - while (++index2 < context3.events.length) { - const event = context3.events[index2]; + while (++index2 < context2.events.length) { + const event = context2.events[index2]; if (event[0] === "enter" && event[1].type === "table") { - event[1]._align = gfmTableAlign(context3.events, index2); + event[1]._align = gfmTableAlign(context2.events, index2); } } return events; } -function flushCell(map5, context3, range, rowKind, rowEnd, previousCell) { +function flushCell(map5, context2, range, rowKind, rowEnd, previousCell) { const groupName = rowKind === 1 ? "tableHeader" : rowKind === 2 ? "tableDelimiter" : "tableData"; const valueName = "tableContent"; if (range[0] !== 0) { - previousCell.end = Object.assign({}, getPoint(context3.events, range[0])); - map5.add(range[0], 0, [["exit", previousCell, context3]]); + previousCell.end = Object.assign({}, getPoint(context2.events, range[0])); + map5.add(range[0], 0, [["exit", previousCell, context2]]); } - const now = getPoint(context3.events, range[1]); + const now = getPoint(context2.events, range[1]); previousCell = { type: groupName, start: Object.assign({}, now), // Note: correct end is set later. end: Object.assign({}, now) }; - map5.add(range[1], 0, [["enter", previousCell, context3]]); + map5.add(range[1], 0, [["enter", previousCell, context2]]); if (range[2] !== 0) { - const relatedStart = getPoint(context3.events, range[2]); - const relatedEnd = getPoint(context3.events, range[3]); + const relatedStart = getPoint(context2.events, range[2]); + const relatedEnd = getPoint(context2.events, range[3]); const valueToken = { type: valueName, start: Object.assign({}, relatedStart), end: Object.assign({}, relatedEnd) }; - map5.add(range[2], 0, [["enter", valueToken, context3]]); + map5.add(range[2], 0, [["enter", valueToken, context2]]); if (rowKind !== 2) { - const start = context3.events[range[2]]; - const end = context3.events[range[3]]; + const start = context2.events[range[2]]; + const end = context2.events[range[3]]; start[1].end = Object.assign({}, end[1].end); start[1].type = "chunkText"; start[1].contentType = "text"; @@ -42695,24 +42694,24 @@ function flushCell(map5, context3, range, rowKind, rowEnd, previousCell) { map5.add(a, b, []); } } - map5.add(range[3] + 1, 0, [["exit", valueToken, context3]]); + map5.add(range[3] + 1, 0, [["exit", valueToken, context2]]); } if (rowEnd !== void 0) { - previousCell.end = Object.assign({}, getPoint(context3.events, rowEnd)); - map5.add(rowEnd, 0, [["exit", previousCell, context3]]); + previousCell.end = Object.assign({}, getPoint(context2.events, rowEnd)); + map5.add(rowEnd, 0, [["exit", previousCell, context2]]); previousCell = void 0; } return previousCell; } -function flushTableEnd(map5, context3, index2, table, tableBody) { +function flushTableEnd(map5, context2, index2, table, tableBody) { const exits = []; - const related = getPoint(context3.events, index2); + const related = getPoint(context2.events, index2); if (tableBody) { tableBody.end = Object.assign({}, related); - exits.push(["exit", tableBody, context3]); + exits.push(["exit", tableBody, context2]); } table.end = Object.assign({}, related); - exits.push(["exit", table, context3]); + exits.push(["exit", table, context2]); map5.add(index2 + 1, 0, exits); } function getPoint(events, index2) { @@ -42913,16 +42912,7 @@ async function main({ core.info(`Updating stack details for PR #${stackNode.number}`); const stackGraph2 = getStackGraph(repoGraph, stackNode); const output = getOutput(stackGraph2); - let description = stackNode.body ?? ""; - description = updateDescription({ - description, - output - }); - await octokit.rest.pulls.update({ - ...github.context.repo, - pull_number: stackNode.number, - body: description - }); + console.log(stackGraph2.inspect()); }); }); await Promise.allSettled(jobs.map((job) => job())); @@ -42951,37 +42941,6 @@ function getStackGraph(repoGraph, pullRequest) { ); return stackGraph; } -function updateDescription({ - description, - output -}) { - const ANCHOR = ""; - const descriptionAst = remark2.parse(description); - const outputAst = remark2.parse(`${ANCHOR} -${output}`); - const anchorIndex = descriptionAst.children.findIndex( - (node2) => node2.type === "html" && node2.value === ANCHOR - ); - const isMissingAnchor = anchorIndex === -1; - if (isMissingAnchor) { - descriptionAst.children.push(...outputAst.children); - return remark2.stringify(descriptionAst); - } - let nearestListIndex = anchorIndex; - for (let i = anchorIndex; i < descriptionAst.children.length; i += 1) { - const node2 = descriptionAst.children[i]; - if (node2?.type === "list") { - nearestListIndex = i; - break; - } - } - descriptionAst.children.splice( - anchorIndex, - nearestListIndex - anchorIndex + 1, - ...outputAst.children - ); - return remark2.stringify(descriptionAst); -} // src/inputs.ts var core2 = __toESM(require_core()); @@ -46850,11 +46809,11 @@ var inputs = { core2.endGroup(); return input; }, - async getMainBranch(octokit, config2, context3) { + async getMainBranch(octokit, config2, context2) { const { data: { default_branch: defaultBranch } } = await octokit.rest.repos.get({ - ...context3.repo + ...context2.repo }); const mainBranchInput = core2.getInput("main-branch", { required: false, @@ -46868,11 +46827,11 @@ var inputs = { mainBranch = mainBranchInput !== "" ? mainBranchInput : mainBranch; return mainBranch; }, - async getRemoteBranches(octokit, context3) { + async getRemoteBranches(octokit, context2) { const remoteBranches = await octokit.paginate( "GET /repos/{owner}/{repo}/branches", { - ...context3.repo, + ...context2.repo, per_page: 100 }, (response) => response.data.map((branch) => branch.name) @@ -46911,9 +46870,9 @@ var inputs = { core2.endGroup(); return [...new Set(perennialBranches)]; }, - getCurrentPullRequest(context3) { + getCurrentPullRequest(context2) { try { - const pullRequest = context3.payload.pull_request; + const pullRequest = context2.payload.pull_request; core2.startGroup("Inputs: Current pull request"); core2.info(JSON.stringify(pullRequest)); core2.endGroup(); @@ -46927,11 +46886,11 @@ var inputs = { throw error; } }, - async getPullRequests(octokit, context3) { + async getPullRequests(octokit, context2) { const openPullRequests = await octokit.paginate( "GET /repos/{owner}/{repo}/pulls", { - ...context3.repo, + ...context2.repo, state: "all", per_page: 100 }, @@ -46987,29 +46946,29 @@ void run(); async function run() { try { const validTriggers = ["pull_request", "pull_request_target"]; - if (!validTriggers.includes(github2.context.eventName)) { + if (!validTriggers.includes(github.context.eventName)) { core4.setFailed( `Action only supports the following triggers: ${validTriggers.map((trigger) => `\`${trigger}\``).join(", ")}` ); return; } - const octokit = github2.getOctokit(inputs.getToken()); + const octokit = github.getOctokit(inputs.getToken()); const [mainBranch, remoteBranches, pullRequests] = await Promise.all([ - inputs.getMainBranch(octokit, config, github2.context), - inputs.getRemoteBranches(octokit, github2.context), - inputs.getPullRequests(octokit, github2.context) + inputs.getMainBranch(octokit, config, github.context), + inputs.getRemoteBranches(octokit, github.context), + inputs.getPullRequests(octokit, github.context) ]); const perennialBranches = await inputs.getPerennialBranches(config, remoteBranches); - const context3 = { + const context2 = { octokit, - currentPullRequest: inputs.getCurrentPullRequest(github2.context), + currentPullRequest: inputs.getCurrentPullRequest(github.context), pullRequests, mainBranch, remoteBranches, perennialBranches, skipSingleStacks: inputs.getSkipSingleStacks() }; - void main(context3); + void main(context2); } catch (error) { if (error instanceof Error) { core4.setFailed(error.message); diff --git a/src/main.ts b/src/main.ts index 5cc2151..5d7dd53 100644 --- a/src/main.ts +++ b/src/main.ts @@ -112,17 +112,19 @@ export async function main({ const stackGraph = getStackGraph(repoGraph, stackNode) const output = getOutput(stackGraph) - let description = stackNode.body ?? '' - description = updateDescription({ - description, - output, - }) - - await octokit.rest.pulls.update({ - ...github.context.repo, - pull_number: stackNode.number, - body: description, - }) + console.log(stackGraph.inspect()) + + // let description = stackNode.body ?? '' + // description = updateDescription({ + // description, + // output, + // }) + + // await octokit.rest.pulls.update({ + // ...github.context.repo, + // pull_number: stackNode.number, + // body: description, + // }) }) }) From 14287813c2f6792abdd3f4bb2305def290d8ebb3 Mon Sep 17 00:00:00 2001 From: Long Tran Date: Wed, 27 Nov 2024 14:42:10 +1100 Subject: [PATCH 03/31] drop unprinted nodes --- dist/index.js | 8 ++++++-- src/main.ts | 10 ++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index 776115e..00b5925 100644 --- a/dist/index.js +++ b/dist/index.js @@ -42911,7 +42911,6 @@ async function main({ jobs.push(async () => { core.info(`Updating stack details for PR #${stackNode.number}`); const stackGraph2 = getStackGraph(repoGraph, stackNode); - const output = getOutput(stackGraph2); console.log(stackGraph2.inspect()); }); }); @@ -42921,7 +42920,7 @@ function getStackGraph(repoGraph, pullRequest) { const stackGraph = repoGraph.copy(); stackGraph.setNodeAttribute(pullRequest.headRefName, "isCurrent", true); (0, import_graphology_traversal.bfsFromNode)( - stackGraph, + repoGraph, pullRequest.headRefName, (ref, attributes) => { stackGraph.setNodeAttribute(ref, "shouldPrint", true); @@ -42939,6 +42938,11 @@ function getStackGraph(repoGraph, pullRequest) { }, { mode: "outbound" } ); + stackGraph.forEachNode((node2, attributes) => { + if (!attributes.shouldPrint) { + stackGraph.dropNode(node2); + } + }); return stackGraph; } diff --git a/src/main.ts b/src/main.ts index 5d7dd53..3fd596e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -110,7 +110,7 @@ export async function main({ core.info(`Updating stack details for PR #${stackNode.number}`) const stackGraph = getStackGraph(repoGraph, stackNode) - const output = getOutput(stackGraph) + // const output = getOutput(stackGraph) console.log(stackGraph.inspect()) @@ -139,7 +139,7 @@ function getStackGraph( stackGraph.setNodeAttribute(pullRequest.headRefName, 'isCurrent', true) bfsFromNode( - stackGraph, + repoGraph, pullRequest.headRefName, (ref, attributes) => { stackGraph.setNodeAttribute(ref, 'shouldPrint', true) @@ -159,6 +159,12 @@ function getStackGraph( { mode: 'outbound' } ) + stackGraph.forEachNode((node, attributes) => { + if (!attributes.shouldPrint) { + stackGraph.dropNode(node) + } + }) + return stackGraph } From cb324e8ec298fd8f8e64bed0b189f10dbf67d80a Mon Sep 17 00:00:00 2001 From: Long Tran Date: Wed, 27 Nov 2024 14:52:38 +1100 Subject: [PATCH 04/31] fixes --- dist/index.js | 32 ++++++++++++++++---------------- src/inputs.ts | 18 ++++-------------- src/main.ts | 12 ++++++------ src/types.ts | 8 ++++++-- 4 files changed, 32 insertions(+), 38 deletions(-) diff --git a/dist/index.js b/dist/index.js index 00b5925..edb3f45 100644 --- a/dist/index.js +++ b/dist/index.js @@ -42858,13 +42858,13 @@ async function main({ }); }); pullRequests.forEach((pullRequest) => { - repoGraph.mergeNode(pullRequest.headRefName, { + repoGraph.mergeNode(pullRequest.head.ref, { type: "pull-request", ...pullRequest }); }); pullRequests.forEach((pullRequest) => { - repoGraph.mergeDirectedEdge(pullRequest.baseRefName, pullRequest.headRefName); + repoGraph.mergeDirectedEdge(pullRequest.base.ref, pullRequest.head.ref); }); const getOutput = (graph) => { const lines = []; @@ -42895,7 +42895,7 @@ async function main({ const jobs = []; const stackGraph = getStackGraph(repoGraph, currentPullRequest); const shouldSkip = () => { - const neighbors = stackGraph.neighbors(currentPullRequest.headRefName); + const neighbors = stackGraph.neighbors(currentPullRequest.head.ref); const allPerennialBranches = stackGraph.filterNodes( (_, nodeAttributes) => nodeAttributes.type === "perennial" ); @@ -42918,10 +42918,10 @@ async function main({ } function getStackGraph(repoGraph, pullRequest) { const stackGraph = repoGraph.copy(); - stackGraph.setNodeAttribute(pullRequest.headRefName, "isCurrent", true); + stackGraph.setNodeAttribute(pullRequest.head.ref, "isCurrent", true); (0, import_graphology_traversal.bfsFromNode)( repoGraph, - pullRequest.headRefName, + pullRequest.head.ref, (ref, attributes) => { stackGraph.setNodeAttribute(ref, "shouldPrint", true); return attributes.type === "perennial"; @@ -42932,7 +42932,7 @@ function getStackGraph(repoGraph, pullRequest) { ); (0, import_graphology_traversal.dfsFromNode)( stackGraph, - pullRequest.headRefName, + pullRequest.head.ref, (ref) => { stackGraph.setNodeAttribute(ref, "shouldPrint", true); }, @@ -46796,8 +46796,12 @@ var z = /* @__PURE__ */ Object.freeze({ // src/types.ts var pullRequestSchema = objectType({ number: numberType(), - baseRefName: stringType(), - headRefName: stringType(), + base: objectType({ + ref: stringType() + }), + head: objectType({ + ref: stringType() + }), body: stringType().optional() }); @@ -46876,15 +46880,11 @@ var inputs = { }, getCurrentPullRequest(context2) { try { - const pullRequest = context2.payload.pull_request; + const pullRequest = pullRequestSchema.parse(context2.payload.pull_request); core2.startGroup("Inputs: Current pull request"); core2.info(JSON.stringify(pullRequest)); core2.endGroup(); - return pullRequestSchema.parse({ - number: pullRequest?.number, - baseRefName: pullRequest?.base?.ref, - headRefName: pullRequest?.head?.ref - }); + return pullRequest; } catch (error) { core2.setFailed(`Unable to determine current pull request from action payload`); throw error; @@ -46901,8 +46901,8 @@ var inputs = { (response) => response.data.map( (item) => ({ number: item.number, - baseRefName: item.base.ref, - headRefName: item.head.ref, + base: item.base, + head: item.head, body: item.body ?? void 0 }) ) diff --git a/src/inputs.ts b/src/inputs.ts index 282dbd2..d967863 100644 --- a/src/inputs.ts +++ b/src/inputs.ts @@ -103,23 +103,13 @@ export const inputs = { getCurrentPullRequest(context: typeof github.context) { try { - const pullRequest: - | { - number: number - base?: { ref?: string } - head?: { ref?: string } - } - | undefined = context.payload.pull_request + const pullRequest = pullRequestSchema.parse(context.payload.pull_request) core.startGroup('Inputs: Current pull request') core.info(JSON.stringify(pullRequest)) core.endGroup() - return pullRequestSchema.parse({ - number: pullRequest?.number, - baseRefName: pullRequest?.base?.ref, - headRefName: pullRequest?.head?.ref, - }) + return pullRequest } catch (error) { core.setFailed(`Unable to determine current pull request from action payload`) throw error @@ -138,8 +128,8 @@ export const inputs = { response.data.map( (item): PullRequest => ({ number: item.number, - baseRefName: item.base.ref, - headRefName: item.head.ref, + base: item.base, + head: item.head, body: item.body ?? undefined, }) ) diff --git a/src/main.ts b/src/main.ts index 3fd596e..c091a30 100644 --- a/src/main.ts +++ b/src/main.ts @@ -36,14 +36,14 @@ export async function main({ }) pullRequests.forEach((pullRequest) => { - repoGraph.mergeNode(pullRequest.headRefName, { + repoGraph.mergeNode(pullRequest.head.ref, { type: 'pull-request', ...pullRequest, }) }) pullRequests.forEach((pullRequest) => { - repoGraph.mergeDirectedEdge(pullRequest.baseRefName, pullRequest.headRefName) + repoGraph.mergeDirectedEdge(pullRequest.base.ref, pullRequest.head.ref) }) const getOutput = (graph: MultiDirectedGraph) => { @@ -85,7 +85,7 @@ export async function main({ const stackGraph = getStackGraph(repoGraph, currentPullRequest) const shouldSkip = () => { - const neighbors = stackGraph.neighbors(currentPullRequest.headRefName) + const neighbors = stackGraph.neighbors(currentPullRequest.head.ref) const allPerennialBranches = stackGraph.filterNodes( (_, nodeAttributes) => nodeAttributes.type === 'perennial' ) @@ -136,11 +136,11 @@ function getStackGraph( pullRequest: PullRequest ) { const stackGraph = repoGraph.copy() as MultiDirectedGraph - stackGraph.setNodeAttribute(pullRequest.headRefName, 'isCurrent', true) + stackGraph.setNodeAttribute(pullRequest.head.ref, 'isCurrent', true) bfsFromNode( repoGraph, - pullRequest.headRefName, + pullRequest.head.ref, (ref, attributes) => { stackGraph.setNodeAttribute(ref, 'shouldPrint', true) return attributes.type === 'perennial' @@ -152,7 +152,7 @@ function getStackGraph( dfsFromNode( stackGraph, - pullRequest.headRefName, + pullRequest.head.ref, (ref) => { stackGraph.setNodeAttribute(ref, 'shouldPrint', true) }, diff --git a/src/types.ts b/src/types.ts index 9ab12e2..d875f16 100644 --- a/src/types.ts +++ b/src/types.ts @@ -6,8 +6,12 @@ export type Octokit = ReturnType export const pullRequestSchema = object({ number: number(), - baseRefName: string(), - headRefName: string(), + base: object({ + ref: string(), + }), + head: object({ + ref: string(), + }), body: string().optional(), }) export type PullRequest = InferType From be37c889dac09b3e01caf07e54d3a5d724ce7ed7 Mon Sep 17 00:00:00 2001 From: Long Tran Date: Wed, 27 Nov 2024 15:17:11 +1100 Subject: [PATCH 05/31] fixes --- src/main.ts | 91 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 51 insertions(+), 40 deletions(-) diff --git a/src/main.ts b/src/main.ts index c091a30..2abc3e7 100644 --- a/src/main.ts +++ b/src/main.ts @@ -46,9 +46,57 @@ export async function main({ repoGraph.mergeDirectedEdge(pullRequest.base.ref, pullRequest.head.ref) }) + const terminatingRefs = [mainBranch, ...perennialBranches] + + const getStackGraph = (anchorPullRequest: PullRequest) => { + const stackGraph = repoGraph.copy() as MultiDirectedGraph + stackGraph.setNodeAttribute(anchorPullRequest.head.ref, 'isCurrent', true) + + bfsFromNode( + repoGraph, + anchorPullRequest.head.ref, + (ref, attributes) => { + if ( + attributes.type === 'pull-request' && + !terminatingRefs.includes(attributes.base.ref) + ) { + stackGraph.setNodeAttribute(ref, 'shouldPrint', true) + stackGraph.setNodeAttribute(attributes.base.ref, 'shouldPrint', true) + + return false + } + + return attributes.type === 'perennial' + }, + { + mode: 'inbound', + } + ) + + dfsFromNode( + stackGraph, + anchorPullRequest.head.ref, + (ref) => { + stackGraph.setNodeAttribute(ref, 'shouldPrint', true) + }, + { mode: 'outbound' } + ) + + stackGraph.forEachNode((node, attributes) => { + if (!attributes.shouldPrint) { + try { + stackGraph.dropNode(node) + } catch { + // Do nothing + } + } + }) + + return stackGraph + } + const getOutput = (graph: MultiDirectedGraph) => { const lines: string[] = [] - const terminatingRefs = [mainBranch, ...perennialBranches] dfs( graph, @@ -82,7 +130,7 @@ export async function main({ const jobs: Array<() => Promise> = [] - const stackGraph = getStackGraph(repoGraph, currentPullRequest) + const stackGraph = getStackGraph(currentPullRequest) const shouldSkip = () => { const neighbors = stackGraph.neighbors(currentPullRequest.head.ref) @@ -109,7 +157,7 @@ export async function main({ jobs.push(async () => { core.info(`Updating stack details for PR #${stackNode.number}`) - const stackGraph = getStackGraph(repoGraph, stackNode) + const stackGraph = getStackGraph(stackNode) // const output = getOutput(stackGraph) console.log(stackGraph.inspect()) @@ -131,43 +179,6 @@ export async function main({ await Promise.allSettled(jobs.map((job) => job())) } -function getStackGraph( - repoGraph: MultiDirectedGraph, - pullRequest: PullRequest -) { - const stackGraph = repoGraph.copy() as MultiDirectedGraph - stackGraph.setNodeAttribute(pullRequest.head.ref, 'isCurrent', true) - - bfsFromNode( - repoGraph, - pullRequest.head.ref, - (ref, attributes) => { - stackGraph.setNodeAttribute(ref, 'shouldPrint', true) - return attributes.type === 'perennial' - }, - { - mode: 'inbound', - } - ) - - dfsFromNode( - stackGraph, - pullRequest.head.ref, - (ref) => { - stackGraph.setNodeAttribute(ref, 'shouldPrint', true) - }, - { mode: 'outbound' } - ) - - stackGraph.forEachNode((node, attributes) => { - if (!attributes.shouldPrint) { - stackGraph.dropNode(node) - } - }) - - return stackGraph -} - export function updateDescription({ description, output, From c9ad1b9b9c325dc227649bdbe4e9c2d2a7ad98c4 Mon Sep 17 00:00:00 2001 From: Long Tran Date: Wed, 27 Nov 2024 16:00:19 +1100 Subject: [PATCH 06/31] fixes --- dist/index.js | 104 +++++++++++++++++++++++++++++++++++--------------- src/main.ts | 16 ++++---- 2 files changed, 82 insertions(+), 38 deletions(-) diff --git a/dist/index.js b/dist/index.js index edb3f45..dfcee3e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -42866,9 +42866,45 @@ async function main({ pullRequests.forEach((pullRequest) => { repoGraph.mergeDirectedEdge(pullRequest.base.ref, pullRequest.head.ref); }); + const terminatingRefs = [mainBranch, ...perennialBranches]; + const getStackGraph = (anchorPullRequest) => { + const stackGraph2 = repoGraph.copy(); + stackGraph2.setNodeAttribute(anchorPullRequest.head.ref, "isCurrent", true); + (0, import_graphology_traversal.bfsFromNode)( + repoGraph, + anchorPullRequest.head.ref, + (ref, attributes) => { + if (attributes.type === "pull-request" && !terminatingRefs.includes(attributes.base.ref)) { + stackGraph2.setNodeAttribute(ref, "shouldPrint", true); + stackGraph2.setNodeAttribute(attributes.base.ref, "shouldPrint", true); + return false; + } + return attributes.type === "perennial"; + }, + { + mode: "inbound" + } + ); + (0, import_graphology_traversal.dfsFromNode)( + stackGraph2, + anchorPullRequest.head.ref, + (ref) => { + stackGraph2.setNodeAttribute(ref, "shouldPrint", true); + }, + { mode: "outbound" } + ); + stackGraph2.forEachNode((node2, attributes) => { + if (!attributes.shouldPrint) { + try { + stackGraph2.dropNode(node2); + } catch { + } + } + }); + return stackGraph2; + }; const getOutput = (graph) => { const lines = []; - const terminatingRefs = [mainBranch, ...perennialBranches]; (0, import_graphology_traversal.dfs)( graph, (_, stackNode, depth) => { @@ -42893,7 +42929,8 @@ async function main({ return lines.join("\n"); }; const jobs = []; - const stackGraph = getStackGraph(repoGraph, currentPullRequest); + const stackGraph = getStackGraph(currentPullRequest); + console.log(stackGraph.inspect()); const shouldSkip = () => { const neighbors = stackGraph.neighbors(currentPullRequest.head.ref); const allPerennialBranches = stackGraph.filterNodes( @@ -42910,40 +42947,47 @@ async function main({ } jobs.push(async () => { core.info(`Updating stack details for PR #${stackNode.number}`); - const stackGraph2 = getStackGraph(repoGraph, stackNode); - console.log(stackGraph2.inspect()); + const stackGraph2 = getStackGraph(stackNode); + const output = getOutput(stackGraph2); + let description = stackNode.body ?? ""; + description = updateDescription({ + description, + output + }); }); }); await Promise.allSettled(jobs.map((job) => job())); } -function getStackGraph(repoGraph, pullRequest) { - const stackGraph = repoGraph.copy(); - stackGraph.setNodeAttribute(pullRequest.head.ref, "isCurrent", true); - (0, import_graphology_traversal.bfsFromNode)( - repoGraph, - pullRequest.head.ref, - (ref, attributes) => { - stackGraph.setNodeAttribute(ref, "shouldPrint", true); - return attributes.type === "perennial"; - }, - { - mode: "inbound" - } - ); - (0, import_graphology_traversal.dfsFromNode)( - stackGraph, - pullRequest.head.ref, - (ref) => { - stackGraph.setNodeAttribute(ref, "shouldPrint", true); - }, - { mode: "outbound" } +function updateDescription({ + description, + output +}) { + const ANCHOR = ""; + const descriptionAst = remark2.parse(description); + const outputAst = remark2.parse(`${ANCHOR} +${output}`); + const anchorIndex = descriptionAst.children.findIndex( + (node2) => node2.type === "html" && node2.value === ANCHOR ); - stackGraph.forEachNode((node2, attributes) => { - if (!attributes.shouldPrint) { - stackGraph.dropNode(node2); + const isMissingAnchor = anchorIndex === -1; + if (isMissingAnchor) { + descriptionAst.children.push(...outputAst.children); + return remark2.stringify(descriptionAst); + } + let nearestListIndex = anchorIndex; + for (let i = anchorIndex; i < descriptionAst.children.length; i += 1) { + const node2 = descriptionAst.children[i]; + if (node2?.type === "list") { + nearestListIndex = i; + break; } - }); - return stackGraph; + } + descriptionAst.children.splice( + anchorIndex, + nearestListIndex - anchorIndex + 1, + ...outputAst.children + ); + return remark2.stringify(descriptionAst); } // src/inputs.ts diff --git a/src/main.ts b/src/main.ts index 2abc3e7..0cd7294 100644 --- a/src/main.ts +++ b/src/main.ts @@ -132,6 +132,8 @@ export async function main({ const stackGraph = getStackGraph(currentPullRequest) + console.log(stackGraph.inspect()) + const shouldSkip = () => { const neighbors = stackGraph.neighbors(currentPullRequest.head.ref) const allPerennialBranches = stackGraph.filterNodes( @@ -158,15 +160,13 @@ export async function main({ core.info(`Updating stack details for PR #${stackNode.number}`) const stackGraph = getStackGraph(stackNode) - // const output = getOutput(stackGraph) - - console.log(stackGraph.inspect()) + const output = getOutput(stackGraph) - // let description = stackNode.body ?? '' - // description = updateDescription({ - // description, - // output, - // }) + let description = stackNode.body ?? '' + description = updateDescription({ + description, + output, + }) // await octokit.rest.pulls.update({ // ...github.context.repo, From d4adc1822d8f5d6d718e4d06d442ec35e71841d3 Mon Sep 17 00:00:00 2001 From: Long Tran Date: Wed, 27 Nov 2024 16:35:30 +1100 Subject: [PATCH 07/31] fixes --- dist/index.js | 14 +++++++++----- src/inputs.ts | 1 + src/main.ts | 14 +++++++------- src/types.ts | 1 + 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/dist/index.js b/dist/index.js index dfcee3e..7fd66b9 100644 --- a/dist/index.js +++ b/dist/index.js @@ -42874,12 +42874,14 @@ async function main({ repoGraph, anchorPullRequest.head.ref, (ref, attributes) => { - if (attributes.type === "pull-request" && !terminatingRefs.includes(attributes.base.ref)) { - stackGraph2.setNodeAttribute(ref, "shouldPrint", true); - stackGraph2.setNodeAttribute(attributes.base.ref, "shouldPrint", true); + if (attributes.type !== "pull-request") { + return attributes.type === "perennial"; + } + if (!attributes.isCurrent && attributes.state !== "open") { return false; } - return attributes.type === "perennial"; + stackGraph2.setNodeAttribute(ref, "shouldPrint", true); + return true; }, { mode: "inbound" @@ -46846,6 +46848,7 @@ var pullRequestSchema = objectType({ head: objectType({ ref: stringType() }), + state: stringType(), body: stringType().optional() }); @@ -46947,7 +46950,8 @@ var inputs = { number: item.number, base: item.base, head: item.head, - body: item.body ?? void 0 + body: item.body ?? void 0, + state: item.state }) ) ); diff --git a/src/inputs.ts b/src/inputs.ts index d967863..52dd3ac 100644 --- a/src/inputs.ts +++ b/src/inputs.ts @@ -131,6 +131,7 @@ export const inputs = { base: item.base, head: item.head, body: item.body ?? undefined, + state: item.state, }) ) ) diff --git a/src/main.ts b/src/main.ts index 0cd7294..edcf666 100644 --- a/src/main.ts +++ b/src/main.ts @@ -56,17 +56,17 @@ export async function main({ repoGraph, anchorPullRequest.head.ref, (ref, attributes) => { - if ( - attributes.type === 'pull-request' && - !terminatingRefs.includes(attributes.base.ref) - ) { - stackGraph.setNodeAttribute(ref, 'shouldPrint', true) - stackGraph.setNodeAttribute(attributes.base.ref, 'shouldPrint', true) + if (attributes.type !== 'pull-request') { + return attributes.type === 'perennial' + } + if (!attributes.isCurrent && attributes.state !== 'open') { return false } - return attributes.type === 'perennial' + stackGraph.setNodeAttribute(ref, 'shouldPrint', true) + + return true }, { mode: 'inbound', diff --git a/src/types.ts b/src/types.ts index d875f16..1306485 100644 --- a/src/types.ts +++ b/src/types.ts @@ -12,6 +12,7 @@ export const pullRequestSchema = object({ head: object({ ref: string(), }), + state: string(), body: string().optional(), }) export type PullRequest = InferType From cf4c008795bc95249b8fe7100926a2498669d8e1 Mon Sep 17 00:00:00 2001 From: Long Tran Date: Wed, 27 Nov 2024 19:06:05 +1100 Subject: [PATCH 08/31] fixes --- src/inputs.ts | 7 ++++--- src/main.ts | 53 ++++++++++++++++++++++++++++++++------------------- src/types.ts | 2 +- 3 files changed, 38 insertions(+), 24 deletions(-) diff --git a/src/inputs.ts b/src/inputs.ts index 52dd3ac..c75bbca 100644 --- a/src/inputs.ts +++ b/src/inputs.ts @@ -117,7 +117,7 @@ export const inputs = { }, async getPullRequests(octokit: Octokit, context: typeof github.context) { - const openPullRequests = await octokit.paginate( + const pullRequests = await octokit.paginate( 'GET /repos/{owner}/{repo}/pulls', { ...context.repo, @@ -135,13 +135,14 @@ export const inputs = { }) ) ) + pullRequests.sort((a, b) => b.number - a.number) core.startGroup('Inputs: Pull requests') core.info( - JSON.stringify(openPullRequests.map(({ body: _, ...pullRequest }) => pullRequest)) + JSON.stringify(pullRequests.map(({ body: _, ...pullRequest }) => pullRequest)) ) core.endGroup() - return openPullRequests + return pullRequests }, } diff --git a/src/main.ts b/src/main.ts index edcf666..d2ed1fc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -16,13 +16,6 @@ export async function main({ }: Context) { const repoGraph = new MultiDirectedGraph() - remoteBranches.forEach((remoteBranch) => { - repoGraph.mergeNode(remoteBranch, { - type: 'branch', - ref: remoteBranch, - }) - }) - repoGraph.mergeNode(mainBranch, { type: 'perennial', ref: mainBranch, @@ -35,14 +28,43 @@ export async function main({ }) }) - pullRequests.forEach((pullRequest) => { + const openPullRequests = pullRequests.filter( + (pullRequest) => pullRequest.state === 'open' + ) + + openPullRequests.forEach((pullRequest) => { repoGraph.mergeNode(pullRequest.head.ref, { type: 'pull-request', ...pullRequest, }) }) - pullRequests.forEach((pullRequest) => { + openPullRequests.forEach((pullRequest) => { + const hasExistingBasePullRequest = repoGraph.hasNode(pullRequest.base.ref) + if (hasExistingBasePullRequest) { + repoGraph.mergeDirectedEdge(pullRequest.base.ref, pullRequest.head.ref) + + return + } + + const basePullRequest = pullRequests.find( + (basePullRequest) => basePullRequest.head.ref === pullRequest.base.ref + ) + + if (basePullRequest?.state === 'closed') { + repoGraph.mergeNode(pullRequest.base.ref, { + type: 'pull-request', + ...basePullRequest, + }) + repoGraph.mergeDirectedEdge(pullRequest.base.ref, pullRequest.head.ref) + + return + } + + repoGraph.mergeNode(pullRequest.base.ref, { + type: 'orphan-branch', + ref: pullRequest.base.ref, + }) repoGraph.mergeDirectedEdge(pullRequest.base.ref, pullRequest.head.ref) }) @@ -56,17 +78,8 @@ export async function main({ repoGraph, anchorPullRequest.head.ref, (ref, attributes) => { - if (attributes.type !== 'pull-request') { - return attributes.type === 'perennial' - } - - if (!attributes.isCurrent && attributes.state !== 'open') { - return false - } - stackGraph.setNodeAttribute(ref, 'shouldPrint', true) - - return true + return attributes.type === 'perennial' || attributes.type === 'orphan-branch' }, { mode: 'inbound', @@ -132,7 +145,7 @@ export async function main({ const stackGraph = getStackGraph(currentPullRequest) - console.log(stackGraph.inspect()) + console.log(stackGraph.inspect().nodes) const shouldSkip = () => { const neighbors = stackGraph.neighbors(currentPullRequest.head.ref) diff --git a/src/types.ts b/src/types.ts index 1306485..9d2fa83 100644 --- a/src/types.ts +++ b/src/types.ts @@ -29,7 +29,7 @@ export type Context = { export type StackNode = | { - type: 'branch' + type: 'orphan-branch' ref: string } | { From 195a242e93120547f317bd932eb2935fd7e79229 Mon Sep 17 00:00:00 2001 From: Long Tran Date: Wed, 27 Nov 2024 21:03:53 +1100 Subject: [PATCH 09/31] fixes --- dist/index.js | 50 +++++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/dist/index.js b/dist/index.js index 7fd66b9..752d70b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -42841,12 +42841,6 @@ async function main({ skipSingleStacks }) { const repoGraph = new import_graphology.MultiDirectedGraph(); - remoteBranches.forEach((remoteBranch) => { - repoGraph.mergeNode(remoteBranch, { - type: "branch", - ref: remoteBranch - }); - }); repoGraph.mergeNode(mainBranch, { type: "perennial", ref: mainBranch @@ -42857,13 +42851,36 @@ async function main({ ref: perennialBranch }); }); - pullRequests.forEach((pullRequest) => { + const openPullRequests = pullRequests.filter( + (pullRequest) => pullRequest.state === "open" + ); + openPullRequests.forEach((pullRequest) => { repoGraph.mergeNode(pullRequest.head.ref, { type: "pull-request", ...pullRequest }); }); - pullRequests.forEach((pullRequest) => { + openPullRequests.forEach((pullRequest) => { + const hasExistingBasePullRequest = repoGraph.hasNode(pullRequest.base.ref); + if (hasExistingBasePullRequest) { + repoGraph.mergeDirectedEdge(pullRequest.base.ref, pullRequest.head.ref); + return; + } + const basePullRequest = pullRequests.find( + (basePullRequest2) => basePullRequest2.head.ref === pullRequest.base.ref + ); + if (basePullRequest?.state === "closed") { + repoGraph.mergeNode(pullRequest.base.ref, { + type: "pull-request", + ...basePullRequest + }); + repoGraph.mergeDirectedEdge(pullRequest.base.ref, pullRequest.head.ref); + return; + } + repoGraph.mergeNode(pullRequest.base.ref, { + type: "orphan-branch", + ref: pullRequest.base.ref + }); repoGraph.mergeDirectedEdge(pullRequest.base.ref, pullRequest.head.ref); }); const terminatingRefs = [mainBranch, ...perennialBranches]; @@ -42874,14 +42891,8 @@ async function main({ repoGraph, anchorPullRequest.head.ref, (ref, attributes) => { - if (attributes.type !== "pull-request") { - return attributes.type === "perennial"; - } - if (!attributes.isCurrent && attributes.state !== "open") { - return false; - } stackGraph2.setNodeAttribute(ref, "shouldPrint", true); - return true; + return attributes.type === "perennial" || attributes.type === "orphan-branch"; }, { mode: "inbound" @@ -42932,7 +42943,7 @@ async function main({ }; const jobs = []; const stackGraph = getStackGraph(currentPullRequest); - console.log(stackGraph.inspect()); + console.log(stackGraph.inspect().nodes); const shouldSkip = () => { const neighbors = stackGraph.neighbors(currentPullRequest.head.ref); const allPerennialBranches = stackGraph.filterNodes( @@ -46938,7 +46949,7 @@ var inputs = { } }, async getPullRequests(octokit, context2) { - const openPullRequests = await octokit.paginate( + const pullRequests = await octokit.paginate( "GET /repos/{owner}/{repo}/pulls", { ...context2.repo, @@ -46955,12 +46966,13 @@ var inputs = { }) ) ); + pullRequests.sort((a, b) => b.number - a.number); core2.startGroup("Inputs: Pull requests"); core2.info( - JSON.stringify(openPullRequests.map(({ body: _, ...pullRequest }) => pullRequest)) + JSON.stringify(pullRequests.map(({ body: _, ...pullRequest }) => pullRequest)) ); core2.endGroup(); - return openPullRequests; + return pullRequests; } }; From de46e0498850b1bc1dce7849ee9899dfdfe043cf Mon Sep 17 00:00:00 2001 From: Long Tran Date: Wed, 27 Nov 2024 21:37:24 +1100 Subject: [PATCH 10/31] fixes --- dist/index.js | 370 ++++++++++++++++++++++++++------------------------ src/main.ts | 22 +-- 2 files changed, 203 insertions(+), 189 deletions(-) diff --git a/dist/index.js b/dist/index.js index 752d70b..d796f4a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -4420,18 +4420,18 @@ var require_webidl = __commonJS({ webidl.errors.exception = function(message) { return new TypeError(`${message.header}: ${message.message}`); }; - webidl.errors.conversionFailed = function(context2) { - const plural = context2.types.length === 1 ? "" : " one of"; - const message = `${context2.argument} could not be converted to${plural}: ${context2.types.join(", ")}.`; + webidl.errors.conversionFailed = function(context3) { + const plural = context3.types.length === 1 ? "" : " one of"; + const message = `${context3.argument} could not be converted to${plural}: ${context3.types.join(", ")}.`; return webidl.errors.exception({ - header: context2.prefix, + header: context3.prefix, message }); }; - webidl.errors.invalidArgument = function(context2) { + webidl.errors.invalidArgument = function(context3) { return webidl.errors.exception({ - header: context2.prefix, - message: `"${context2.value}" is an invalid ${context2.type}.` + header: context3.prefix, + message: `"${context3.value}" is an invalid ${context3.type}.` }); }; webidl.brandCheck = function(V, I, opts = void 0) { @@ -9752,15 +9752,15 @@ var require_api_request = __commonJS({ } addSignal(this, signal); } - onConnect(abort, context2) { + onConnect(abort, context3) { if (!this.callback) { throw new RequestAbortedError(); } this.abort = abort; - this.context = context2; + this.context = context3; } onHeaders(statusCode, rawHeaders, resume, statusMessage) { - const { callback, opaque, abort, context: context2, responseHeaders, highWaterMark } = this; + const { callback, opaque, abort, context: context3, responseHeaders, highWaterMark } = this; const headers = responseHeaders === "raw" ? util2.parseRawHeaders(rawHeaders) : util2.parseHeaders(rawHeaders); if (statusCode < 200) { if (this.onInfo) { @@ -9787,7 +9787,7 @@ var require_api_request = __commonJS({ trailers: this.trailers, opaque, body, - context: context2 + context: context3 }); } } @@ -9907,15 +9907,15 @@ var require_api_stream = __commonJS({ } addSignal(this, signal); } - onConnect(abort, context2) { + onConnect(abort, context3) { if (!this.callback) { throw new RequestAbortedError(); } this.abort = abort; - this.context = context2; + this.context = context3; } onHeaders(statusCode, rawHeaders, resume, statusMessage) { - const { factory, opaque, context: context2, callback, responseHeaders } = this; + const { factory, opaque, context: context3, callback, responseHeaders } = this; const headers = responseHeaders === "raw" ? util2.parseRawHeaders(rawHeaders) : util2.parseHeaders(rawHeaders); if (statusCode < 200) { if (this.onInfo) { @@ -9943,7 +9943,7 @@ var require_api_stream = __commonJS({ statusCode, headers, opaque, - context: context2 + context: context3 }); if (!res || typeof res.write !== "function" || typeof res.end !== "function" || typeof res.on !== "function") { throw new InvalidReturnValueError("expected Writable"); @@ -10135,17 +10135,17 @@ var require_api_pipeline = __commonJS({ this.res = null; addSignal(this, signal); } - onConnect(abort, context2) { + onConnect(abort, context3) { const { ret, res } = this; assert(!res, "pipeline cannot be retried"); if (ret.destroyed) { throw new RequestAbortedError(); } this.abort = abort; - this.context = context2; + this.context = context3; } onHeaders(statusCode, rawHeaders, resume) { - const { opaque, handler, context: context2 } = this; + const { opaque, handler, context: context3 } = this; if (statusCode < 200) { if (this.onInfo) { const headers = this.responseHeaders === "raw" ? util2.parseRawHeaders(rawHeaders) : util2.parseHeaders(rawHeaders); @@ -10163,7 +10163,7 @@ var require_api_pipeline = __commonJS({ headers, opaque, body: this.res, - context: context2 + context: context3 }); } catch (err) { this.res.on("error", util2.nop); @@ -10247,7 +10247,7 @@ var require_api_upgrade = __commonJS({ this.context = null; addSignal(this, signal); } - onConnect(abort, context2) { + onConnect(abort, context3) { if (!this.callback) { throw new RequestAbortedError(); } @@ -10258,7 +10258,7 @@ var require_api_upgrade = __commonJS({ throw new SocketError("bad upgrade", null); } onUpgrade(statusCode, rawHeaders, socket) { - const { callback, opaque, context: context2 } = this; + const { callback, opaque, context: context3 } = this; assert.strictEqual(statusCode, 101); removeSignal(this); this.callback = null; @@ -10267,7 +10267,7 @@ var require_api_upgrade = __commonJS({ headers, socket, opaque, - context: context2 + context: context3 }); } onError(err) { @@ -10335,18 +10335,18 @@ var require_api_connect = __commonJS({ this.abort = null; addSignal(this, signal); } - onConnect(abort, context2) { + onConnect(abort, context3) { if (!this.callback) { throw new RequestAbortedError(); } this.abort = abort; - this.context = context2; + this.context = context3; } onHeaders() { throw new SocketError("bad connect", null); } onUpgrade(statusCode, rawHeaders, socket) { - const { callback, opaque, context: context2 } = this; + const { callback, opaque, context: context3 } = this; removeSignal(this); this.callback = null; let headers = rawHeaders; @@ -10358,7 +10358,7 @@ var require_api_connect = __commonJS({ headers, socket, opaque, - context: context2 + context: context3 }); } onError(err) { @@ -19338,8 +19338,8 @@ var require_dist_node2 = __commonJS({ function isKeyOperator(operator) { return operator === ";" || operator === "&" || operator === "?"; } - function getValues(context2, operator, key, modifier) { - var value = context2[key], result = []; + function getValues(context3, operator, key, modifier) { + var value = context3[key], result = []; if (isDefined(value) && value !== "") { if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") { value = value.toString(); @@ -19403,7 +19403,7 @@ var require_dist_node2 = __commonJS({ expand: expand.bind(null, template) }; } - function expand(template, context2) { + function expand(template, context3) { var operators = ["+", "#", ".", "/", ";", "?", "&"]; template = template.replace( /\{([^\{\}]+)\}|([^\{\}]+)/g, @@ -19417,7 +19417,7 @@ var require_dist_node2 = __commonJS({ } expression.split(/,/g).forEach(function(variable) { var tmp = /([^:\*]*)(?::(\d+)|(\*))?/.exec(variable); - values.push(getValues(context2, operator, tmp[1], tmp[2] || tmp[3])); + values.push(getValues(context3, operator, tmp[1], tmp[2] || tmp[3])); }); if (operator && operator !== "+") { var separator = ","; @@ -30535,7 +30535,7 @@ var require_compiler = __commonJS({ var valueAssignments = []; var currentPath = ""; var data = /* @__PURE__ */ Object.create(null); - var context2 = data; + var context3 = data; var arrayMode = false; return reduce(nodes); function reduce(nodes2) { @@ -30573,10 +30573,10 @@ var require_compiler = __commonJS({ } else { fullPath = key; } - if (typeof context2[key] !== "undefined") { + if (typeof context3[key] !== "undefined") { genError("Cannot redefine existing key '" + fullPath + "'.", line, column); } - context2[key] = reduceValueNode(value); + context3[key] = reduceValueNode(value); if (!pathAssigned(fullPath)) { assignedPaths.push(fullPath); valueAssignments.push(fullPath); @@ -30615,7 +30615,7 @@ var require_compiler = __commonJS({ genError("Cannot redefine existing key '" + path2 + "'.", line, column); } assignedPaths.push(quotedPath); - context2 = deepRef(data, path2, /* @__PURE__ */ Object.create(null), line, column); + context3 = deepRef(data, path2, /* @__PURE__ */ Object.create(null), line, column); currentPath = path2; } function addTableArray(node2) { @@ -30630,12 +30630,12 @@ var require_compiler = __commonJS({ return p.indexOf(quotedPath) !== 0; }); assignedPaths.push(quotedPath); - context2 = deepRef(data, path2, [], line, column); + context3 = deepRef(data, path2, [], line, column); currentPath = quotedPath; - if (context2 instanceof Array) { + if (context3 instanceof Array) { var newObj = /* @__PURE__ */ Object.create(null); - context2.push(newObj); - context2 = newObj; + context3.push(newObj); + context3 = newObj; } else { genError("Cannot redefine existing key '" + path2 + "'.", line, column); } @@ -30709,10 +30709,11 @@ var require_toml = __commonJS({ // src/index.ts var core4 = __toESM(require_core()); -var github = __toESM(require_github()); +var github2 = __toESM(require_github()); // src/main.ts var core = __toESM(require_core()); +var github = __toESM(require_github()); var import_graphology = __toESM(require_graphology_cjs()); var import_graphology_traversal = __toESM(require_graphology_traversal()); @@ -33317,13 +33318,13 @@ function classifyCharacter(code3) { } // node_modules/micromark-util-resolve-all/index.js -function resolveAll(constructs2, events, context2) { +function resolveAll(constructs2, events, context3) { const called = []; let index2 = -1; while (++index2 < constructs2.length) { const resolve = constructs2[index2].resolveAll; if (resolve && !called.includes(resolve)) { - events = resolve(events, context2); + events = resolve(events, context3); called.push(resolve); } } @@ -33336,7 +33337,7 @@ var attention = { tokenize: tokenizeAttention, resolveAll: resolveAllAttention }; -function resolveAllAttention(events, context2) { +function resolveAllAttention(events, context3) { let index2 = -1; let open; let group; @@ -33351,7 +33352,7 @@ function resolveAllAttention(events, context2) { open = index2; while (open--) { if (events[open][0] === "exit" && events[open][1].type === "attentionSequence" && events[open][1]._open && // If the markers are the same: - context2.sliceSerialize(events[open][1]).charCodeAt(0) === context2.sliceSerialize(events[index2][1]).charCodeAt(0)) { + context3.sliceSerialize(events[open][1]).charCodeAt(0) === context3.sliceSerialize(events[index2][1]).charCodeAt(0)) { if ((events[open][1]._close || events[index2][1]._open) && (events[index2][1].end.offset - events[index2][1].start.offset) % 3 && !((events[open][1].end.offset - events[open][1].start.offset + events[index2][1].end.offset - events[index2][1].start.offset) % 3)) { continue; } @@ -33385,35 +33386,35 @@ function resolveAllAttention(events, context2) { nextEvents = []; if (events[open][1].end.offset - events[open][1].start.offset) { nextEvents = push(nextEvents, [ - ["enter", events[open][1], context2], - ["exit", events[open][1], context2] + ["enter", events[open][1], context3], + ["exit", events[open][1], context3] ]); } nextEvents = push(nextEvents, [ - ["enter", group, context2], - ["enter", openingSequence, context2], - ["exit", openingSequence, context2], - ["enter", text5, context2] + ["enter", group, context3], + ["enter", openingSequence, context3], + ["exit", openingSequence, context3], + ["enter", text5, context3] ]); nextEvents = push( nextEvents, resolveAll( - context2.parser.constructs.insideSpan.null, + context3.parser.constructs.insideSpan.null, events.slice(open + 1, index2), - context2 + context3 ) ); nextEvents = push(nextEvents, [ - ["exit", text5, context2], - ["enter", closingSequence, context2], - ["exit", closingSequence, context2], - ["exit", group, context2] + ["exit", text5, context3], + ["enter", closingSequence, context3], + ["exit", closingSequence, context3], + ["exit", group, context3] ]); if (events[index2][1].end.offset - events[index2][1].start.offset) { offset = 2; nextEvents = push(nextEvents, [ - ["enter", events[index2][1], context2], - ["exit", events[index2][1], context2] + ["enter", events[index2][1], context3], + ["exit", events[index2][1], context3] ]); } else { offset = 0; @@ -34172,10 +34173,10 @@ function subtokenize(events) { } function subcontent(events, eventIndex) { const token = events[eventIndex][1]; - const context2 = events[eventIndex][2]; + const context3 = events[eventIndex][2]; let startPosition = eventIndex - 1; const startPositions = []; - const tokenizer = token._tokenizer || context2.parser[token.contentType](token.start); + const tokenizer = token._tokenizer || context3.parser[token.contentType](token.start); const childEvents = tokenizer.events; const jumps = []; const gaps = {}; @@ -34191,7 +34192,7 @@ function subcontent(events, eventIndex) { } startPositions.push(startPosition); if (!current._tokenizer) { - stream = context2.sliceStream(current); + stream = context3.sliceStream(current); if (!current.next) { stream.push(null); } @@ -34680,7 +34681,7 @@ var headingAtx = { tokenize: tokenizeHeadingAtx, resolve: resolveHeadingAtx }; -function resolveHeadingAtx(events, context2) { +function resolveHeadingAtx(events, context3) { let contentEnd = events.length - 2; let contentStart = 3; let content3; @@ -34707,10 +34708,10 @@ function resolveHeadingAtx(events, context2) { contentType: "text" }; splice(events, contentStart, contentEnd - contentStart + 1, [ - ["enter", content3, context2], - ["enter", text5, context2], - ["exit", text5, context2], - ["exit", content3, context2] + ["enter", content3, context3], + ["enter", text5, context3], + ["exit", text5, context3], + ["exit", content3, context3] ]); } return events; @@ -35563,7 +35564,7 @@ function resolveAllLabelEnd(events) { } return events; } -function resolveToLabelEnd(events, context2) { +function resolveToLabelEnd(events, context3) { let index2 = events.length; let offset = 0; let token; @@ -35607,27 +35608,27 @@ function resolveToLabelEnd(events, context2) { end: Object.assign({}, events[close - 2][1].start) }; media = [ - ["enter", group, context2], - ["enter", label, context2] + ["enter", group, context3], + ["enter", label, context3] ]; media = push(media, events.slice(open + 1, open + offset + 3)); - media = push(media, [["enter", text5, context2]]); + media = push(media, [["enter", text5, context3]]); media = push( media, resolveAll( - context2.parser.constructs.insideSpan.null, + context3.parser.constructs.insideSpan.null, events.slice(open + offset + 4, close - 3), - context2 + context3 ) ); media = push(media, [ - ["exit", text5, context2], + ["exit", text5, context3], events[close - 2], events[close - 1], - ["exit", label, context2] + ["exit", label, context3] ]); media = push(media, events.slice(close + 1)); - media = push(media, [["exit", group, context2]]); + media = push(media, [["exit", group, context3]]); splice(events, open, events.length, media); return events; } @@ -36071,7 +36072,7 @@ var setextUnderline = { tokenize: tokenizeSetextUnderline, resolveTo: resolveToSetextUnderline }; -function resolveToSetextUnderline(events, context2) { +function resolveToSetextUnderline(events, context3) { let index2 = events.length; let content3; let text5; @@ -36101,13 +36102,13 @@ function resolveToSetextUnderline(events, context2) { }; events[text5][1].type = "setextHeadingText"; if (definition3) { - events.splice(text5, 0, ["enter", heading2, context2]); - events.splice(definition3 + 1, 0, ["exit", events[content3][1], context2]); + events.splice(text5, 0, ["enter", heading2, context3]); + events.splice(definition3 + 1, 0, ["exit", events[content3][1], context3]); events[content3][1].end = Object.assign({}, events[definition3][1].end); } else { events[content3][1] = heading2; } - events.push(["exit", heading2, context2]); + events.push(["exit", heading2, context3]); return events; } function tokenizeSetextUnderline(effects, ok3, nok) { @@ -36259,7 +36260,7 @@ function initializeFactory(field) { } function createResolver(extraResolver) { return resolveAllText; - function resolveAllText(events, context2) { + function resolveAllText(events, context3) { let index2 = -1; let enter; while (++index2 <= events.length) { @@ -36277,15 +36278,15 @@ function createResolver(extraResolver) { enter = void 0; } } - return extraResolver ? extraResolver(events, context2) : events; + return extraResolver ? extraResolver(events, context3) : events; } } -function resolveAllLineSuffixes(events, context2) { +function resolveAllLineSuffixes(events, context3) { let eventIndex = 0; while (++eventIndex <= events.length) { if ((eventIndex === events.length || events[eventIndex][1].type === "lineEnding") && events[eventIndex - 1][1].type === "data") { const data = events[eventIndex - 1][1]; - const chunks = context2.sliceStream(data); + const chunks = context3.sliceStream(data); let index2 = chunks.length; let bufferIndex = -1; let size = 0; @@ -36329,8 +36330,8 @@ function resolveAllLineSuffixes(events, context2) { events.splice( eventIndex, 0, - ["enter", token, context2], - ["exit", token, context2] + ["enter", token, context3], + ["exit", token, context3] ); eventIndex += 2; } @@ -36369,7 +36370,7 @@ function createTokenizer(parser, initialize, from) { interrupt: true }) }; - const context2 = { + const context3 = { previous: null, code: null, containerState: {}, @@ -36381,12 +36382,12 @@ function createTokenizer(parser, initialize, from) { defineSkip, write }; - let state = initialize.tokenize.call(context2, effects); + let state = initialize.tokenize.call(context3, effects); let expectedCode; if (initialize.resolveAll) { resolveAllConstructs.push(initialize); } - return context2; + return context3; function write(slice) { chunks = push(chunks, slice); main2(); @@ -36394,8 +36395,8 @@ function createTokenizer(parser, initialize, from) { return []; } addResult(initialize, 0); - context2.events = resolveAll(resolveAllConstructs, context2.events, context2); - return context2.events; + context3.events = resolveAll(resolveAllConstructs, context3.events, context3); + return context3.events; } function sliceSerialize(token, expandTabs) { return serializeChunks(sliceStream(token), expandTabs); @@ -36458,21 +36459,21 @@ function createTokenizer(parser, initialize, from) { point3._index++; } } - context2.previous = code3; + context3.previous = code3; consumed = true; } function enter(type, fields) { const token = fields || {}; token.type = type; token.start = now(); - context2.events.push(["enter", token, context2]); + context3.events.push(["enter", token, context3]); stack.push(token); return token; } function exit3(type) { const token = stack.pop(); token.end = now(); - context2.events.push(["exit", token, context2]); + context3.events.push(["exit", token, context3]); return token; } function onsuccessfulconstruct(construct, info4) { @@ -36520,16 +36521,16 @@ function createTokenizer(parser, initialize, from) { info4 = store(); currentConstruct = construct; if (!construct.partial) { - context2.currentConstruct = construct; + context3.currentConstruct = construct; } - if (construct.name && context2.parser.constructs.disable.null.includes(construct.name)) { + if (construct.name && context3.parser.constructs.disable.null.includes(construct.name)) { return nok(code3); } return construct.tokenize.call( // If we do have fields, create an object w/ `context` as its // prototype. // This allows a “live binding”, which is needed for `interrupt`. - fields ? Object.assign(Object.create(context2), fields) : context2, + fields ? Object.assign(Object.create(context3), fields) : context3, effects, ok3, nok @@ -36557,21 +36558,21 @@ function createTokenizer(parser, initialize, from) { } if (construct.resolve) { splice( - context2.events, + context3.events, from2, - context2.events.length - from2, - construct.resolve(context2.events.slice(from2), context2) + context3.events.length - from2, + construct.resolve(context3.events.slice(from2), context3) ); } if (construct.resolveTo) { - context2.events = construct.resolveTo(context2.events, context2); + context3.events = construct.resolveTo(context3.events, context3); } } function store() { const startPoint = now(); - const startPrevious = context2.previous; - const startCurrentConstruct = context2.currentConstruct; - const startEventsIndex = context2.events.length; + const startPrevious = context3.previous; + const startCurrentConstruct = context3.currentConstruct; + const startEventsIndex = context3.events.length; const startStack = Array.from(stack); return { restore, @@ -36579,9 +36580,9 @@ function createTokenizer(parser, initialize, from) { }; function restore() { point3 = startPoint; - context2.previous = startPrevious; - context2.currentConstruct = startCurrentConstruct; - context2.events.length = startEventsIndex; + context3.previous = startPrevious; + context3.currentConstruct = startCurrentConstruct; + context3.events.length = startEventsIndex; stack = startStack; accountForPotentialSkip(); } @@ -37013,7 +37014,7 @@ function compiler(options) { type: "root", children: [] }; - const context2 = { + const context3 = { stack: [tree], tokenStack: [], config: config2, @@ -37044,16 +37045,16 @@ function compiler(options) { { sliceSerialize: events[index2][2].sliceSerialize }, - context2 + context3 ), events[index2][1] ); } } - if (context2.tokenStack.length > 0) { - const tail = context2.tokenStack[context2.tokenStack.length - 1]; + if (context3.tokenStack.length > 0) { + const tail = context3.tokenStack[context3.tokenStack.length - 1]; const handler = tail[1] || defaultOnError; - handler.call(context2, void 0, tail[0]); + handler.call(context3, void 0, tail[0]); } tree.position = { start: point2( @@ -37320,14 +37321,14 @@ function compiler(options) { tail.position.end = point2(token.end); } function onexitlineending(token) { - const context2 = this.stack[this.stack.length - 1]; + const context3 = this.stack[this.stack.length - 1]; if (this.data.atHardBreak) { - const tail = context2.children[context2.children.length - 1]; + const tail = context3.children[context3.children.length - 1]; tail.position.end = point2(token.end); this.data.atHardBreak = void 0; return; } - if (!this.data.setextHeadingSlurpLineEnding && config2.canContainEols.includes(context2.type)) { + if (!this.data.setextHeadingSlurpLineEnding && config2.canContainEols.includes(context3.type)) { onenterdata.call(this, token); onexitdata.call(this, token); } @@ -41867,7 +41868,7 @@ function tokenizePotentialGfmFootnoteCall(effects, ok3, nok) { return ok3(code3); } } -function resolveToPotentialGfmFootnoteCall(events, context2) { +function resolveToPotentialGfmFootnoteCall(events, context3) { let index2 = events.length; let labelStart; while (index2--) { @@ -41906,22 +41907,22 @@ function resolveToPotentialGfmFootnoteCall(events, context2) { // Take the `labelImageMarker` (now `data`, the `!`) events[index2 + 1], events[index2 + 2], - ["enter", call, context2], + ["enter", call, context3], // The `[` events[index2 + 3], events[index2 + 4], // The `^`. - ["enter", marker, context2], - ["exit", marker, context2], + ["enter", marker, context3], + ["exit", marker, context3], // Everything in between. - ["enter", string4, context2], - ["enter", chunk, context2], - ["exit", chunk, context2], - ["exit", string4, context2], + ["enter", string4, context3], + ["enter", chunk, context3], + ["exit", chunk, context3], + ["exit", string4, context3], // The ending (`]`, properly parsed and labelled). events[events.length - 2], events[events.length - 1], - ["exit", call, context2] + ["exit", call, context3] ]; events.splice(index2, events.length - index2 + 1, ...replacement); return events; @@ -42110,7 +42111,7 @@ function gfmStrikethrough(options) { null: [126] } }; - function resolveAllStrikethrough(events, context2) { + function resolveAllStrikethrough(events, context3) { let index2 = -1; while (++index2 < events.length) { if (events[index2][0] === "enter" && events[index2][1].type === "strikethroughSequenceTemporary" && events[index2][1]._close) { @@ -42131,25 +42132,25 @@ function gfmStrikethrough(options) { end: Object.assign({}, events[index2][1].start) }; const nextEvents = [ - ["enter", strikethrough, context2], - ["enter", events[open][1], context2], - ["exit", events[open][1], context2], - ["enter", text5, context2] + ["enter", strikethrough, context3], + ["enter", events[open][1], context3], + ["exit", events[open][1], context3], + ["enter", text5, context3] ]; - const insideSpan2 = context2.parser.constructs.insideSpan.null; + const insideSpan2 = context3.parser.constructs.insideSpan.null; if (insideSpan2) { splice( nextEvents, nextEvents.length, 0, - resolveAll(insideSpan2, events.slice(open + 1, index2), context2) + resolveAll(insideSpan2, events.slice(open + 1, index2), context3) ); } splice(nextEvents, nextEvents.length, 0, [ - ["exit", text5, context2], - ["enter", events[index2][1], context2], - ["exit", events[index2][1], context2], - ["exit", strikethrough, context2] + ["exit", text5, context3], + ["enter", events[index2][1], context3], + ["exit", events[index2][1], context3], + ["exit", strikethrough, context3] ]); splice(events, open - 1, index2 - open + 3, nextEvents); index2 = open + nextEvents.length - 2; @@ -42540,7 +42541,7 @@ function tokenizeTable(effects, ok3, nok) { return bodyRowData(code3); } } -function resolveTable(events, context2) { +function resolveTable(events, context3) { let index2 = -1; let inFirstCellAwaitingPipe = true; let rowKind = 0; @@ -42559,7 +42560,7 @@ function resolveTable(events, context2) { if (token.type === "tableHead") { afterHeadAwaitingFirstBodyRow = false; if (lastTableEnd !== 0) { - flushTableEnd(map5, context2, lastTableEnd, currentTable, currentBody); + flushTableEnd(map5, context3, lastTableEnd, currentTable, currentBody); currentBody = void 0; lastTableEnd = 0; } @@ -42569,7 +42570,7 @@ function resolveTable(events, context2) { // Note: correct end is set later. end: Object.assign({}, token.end) }; - map5.add(index2, 0, [["enter", currentTable, context2]]); + map5.add(index2, 0, [["enter", currentTable, context3]]); } else if (token.type === "tableRow" || token.type === "tableDelimiterRow") { inFirstCellAwaitingPipe = true; currentCell = void 0; @@ -42583,7 +42584,7 @@ function resolveTable(events, context2) { // Note: correct end is set later. end: Object.assign({}, token.end) }; - map5.add(index2, 0, [["enter", currentBody, context2]]); + map5.add(index2, 0, [["enter", currentBody, context3]]); } rowKind = token.type === "tableDelimiterRow" ? 2 : currentBody ? 3 : 1; } else if (rowKind && (token.type === "data" || token.type === "tableDelimiterMarker" || token.type === "tableDelimiterFiller")) { @@ -42593,7 +42594,7 @@ function resolveTable(events, context2) { cell[0] = cell[1]; currentCell = flushCell( map5, - context2, + context3, lastCell, rowKind, void 0, @@ -42611,7 +42612,7 @@ function resolveTable(events, context2) { cell[0] = cell[1]; currentCell = flushCell( map5, - context2, + context3, lastCell, rowKind, void 0, @@ -42631,14 +42632,14 @@ function resolveTable(events, context2) { cell[0] = cell[1]; currentCell = flushCell( map5, - context2, + context3, lastCell, rowKind, index2, currentCell ); } else if (cell[1] !== 0) { - currentCell = flushCell(map5, context2, cell, rowKind, index2, currentCell); + currentCell = flushCell(map5, context3, cell, rowKind, index2, currentCell); } rowKind = 0; } else if (rowKind && (token.type === "data" || token.type === "tableDelimiterMarker" || token.type === "tableDelimiterFiller")) { @@ -42646,45 +42647,45 @@ function resolveTable(events, context2) { } } if (lastTableEnd !== 0) { - flushTableEnd(map5, context2, lastTableEnd, currentTable, currentBody); + flushTableEnd(map5, context3, lastTableEnd, currentTable, currentBody); } - map5.consume(context2.events); + map5.consume(context3.events); index2 = -1; - while (++index2 < context2.events.length) { - const event = context2.events[index2]; + while (++index2 < context3.events.length) { + const event = context3.events[index2]; if (event[0] === "enter" && event[1].type === "table") { - event[1]._align = gfmTableAlign(context2.events, index2); + event[1]._align = gfmTableAlign(context3.events, index2); } } return events; } -function flushCell(map5, context2, range, rowKind, rowEnd, previousCell) { +function flushCell(map5, context3, range, rowKind, rowEnd, previousCell) { const groupName = rowKind === 1 ? "tableHeader" : rowKind === 2 ? "tableDelimiter" : "tableData"; const valueName = "tableContent"; if (range[0] !== 0) { - previousCell.end = Object.assign({}, getPoint(context2.events, range[0])); - map5.add(range[0], 0, [["exit", previousCell, context2]]); + previousCell.end = Object.assign({}, getPoint(context3.events, range[0])); + map5.add(range[0], 0, [["exit", previousCell, context3]]); } - const now = getPoint(context2.events, range[1]); + const now = getPoint(context3.events, range[1]); previousCell = { type: groupName, start: Object.assign({}, now), // Note: correct end is set later. end: Object.assign({}, now) }; - map5.add(range[1], 0, [["enter", previousCell, context2]]); + map5.add(range[1], 0, [["enter", previousCell, context3]]); if (range[2] !== 0) { - const relatedStart = getPoint(context2.events, range[2]); - const relatedEnd = getPoint(context2.events, range[3]); + const relatedStart = getPoint(context3.events, range[2]); + const relatedEnd = getPoint(context3.events, range[3]); const valueToken = { type: valueName, start: Object.assign({}, relatedStart), end: Object.assign({}, relatedEnd) }; - map5.add(range[2], 0, [["enter", valueToken, context2]]); + map5.add(range[2], 0, [["enter", valueToken, context3]]); if (rowKind !== 2) { - const start = context2.events[range[2]]; - const end = context2.events[range[3]]; + const start = context3.events[range[2]]; + const end = context3.events[range[3]]; start[1].end = Object.assign({}, end[1].end); start[1].type = "chunkText"; start[1].contentType = "text"; @@ -42694,24 +42695,24 @@ function flushCell(map5, context2, range, rowKind, rowEnd, previousCell) { map5.add(a, b, []); } } - map5.add(range[3] + 1, 0, [["exit", valueToken, context2]]); + map5.add(range[3] + 1, 0, [["exit", valueToken, context3]]); } if (rowEnd !== void 0) { - previousCell.end = Object.assign({}, getPoint(context2.events, rowEnd)); - map5.add(rowEnd, 0, [["exit", previousCell, context2]]); + previousCell.end = Object.assign({}, getPoint(context3.events, rowEnd)); + map5.add(rowEnd, 0, [["exit", previousCell, context3]]); previousCell = void 0; } return previousCell; } -function flushTableEnd(map5, context2, index2, table, tableBody) { +function flushTableEnd(map5, context3, index2, table, tableBody) { const exits = []; - const related = getPoint(context2.events, index2); + const related = getPoint(context3.events, index2); if (tableBody) { tableBody.end = Object.assign({}, related); - exits.push(["exit", tableBody, context2]); + exits.push(["exit", tableBody, context3]); } table.end = Object.assign({}, related); - exits.push(["exit", table, context2]); + exits.push(["exit", table, context3]); map5.add(index2 + 1, 0, exits); } function getPoint(events, index2) { @@ -42926,6 +42927,9 @@ async function main({ const tabSize = depth * 2; const indentation = new Array(tabSize).fill(" ").join(""); let line = indentation; + if (stackNode.type === "orphan-branch") { + line += `- \`${stackNode.ref}\` - :warning: No PR associated with branch`; + } if (stackNode.type === "perennial" && terminatingRefs.includes(stackNode.ref)) { line += `- \`${stackNode.ref}\``; } @@ -42943,7 +42947,6 @@ async function main({ }; const jobs = []; const stackGraph = getStackGraph(currentPullRequest); - console.log(stackGraph.inspect().nodes); const shouldSkip = () => { const neighbors = stackGraph.neighbors(currentPullRequest.head.ref); const allPerennialBranches = stackGraph.filterNodes( @@ -42955,7 +42958,7 @@ async function main({ return; } stackGraph.forEachNode((_, stackNode) => { - if (stackNode.type !== "pull-request" || !stackNode.shouldPrint) { + if (stackNode.type !== "pull-request" || !stackNode.shouldPrint || !stackNode.isCurrent) { return; } jobs.push(async () => { @@ -42967,6 +42970,11 @@ async function main({ description, output }); + await octokit.rest.pulls.update({ + ...github.context.repo, + pull_number: stackNode.number, + body: description + }); }); }); await Promise.allSettled(jobs.map((job) => job())); @@ -46875,11 +46883,11 @@ var inputs = { core2.endGroup(); return input; }, - async getMainBranch(octokit, config2, context2) { + async getMainBranch(octokit, config2, context3) { const { data: { default_branch: defaultBranch } } = await octokit.rest.repos.get({ - ...context2.repo + ...context3.repo }); const mainBranchInput = core2.getInput("main-branch", { required: false, @@ -46893,11 +46901,11 @@ var inputs = { mainBranch = mainBranchInput !== "" ? mainBranchInput : mainBranch; return mainBranch; }, - async getRemoteBranches(octokit, context2) { + async getRemoteBranches(octokit, context3) { const remoteBranches = await octokit.paginate( "GET /repos/{owner}/{repo}/branches", { - ...context2.repo, + ...context3.repo, per_page: 100 }, (response) => response.data.map((branch) => branch.name) @@ -46936,9 +46944,9 @@ var inputs = { core2.endGroup(); return [...new Set(perennialBranches)]; }, - getCurrentPullRequest(context2) { + getCurrentPullRequest(context3) { try { - const pullRequest = pullRequestSchema.parse(context2.payload.pull_request); + const pullRequest = pullRequestSchema.parse(context3.payload.pull_request); core2.startGroup("Inputs: Current pull request"); core2.info(JSON.stringify(pullRequest)); core2.endGroup(); @@ -46948,11 +46956,11 @@ var inputs = { throw error; } }, - async getPullRequests(octokit, context2) { + async getPullRequests(octokit, context3) { const pullRequests = await octokit.paginate( "GET /repos/{owner}/{repo}/pulls", { - ...context2.repo, + ...context3.repo, state: "all", per_page: 100 }, @@ -47010,29 +47018,29 @@ void run(); async function run() { try { const validTriggers = ["pull_request", "pull_request_target"]; - if (!validTriggers.includes(github.context.eventName)) { + if (!validTriggers.includes(github2.context.eventName)) { core4.setFailed( `Action only supports the following triggers: ${validTriggers.map((trigger) => `\`${trigger}\``).join(", ")}` ); return; } - const octokit = github.getOctokit(inputs.getToken()); + const octokit = github2.getOctokit(inputs.getToken()); const [mainBranch, remoteBranches, pullRequests] = await Promise.all([ - inputs.getMainBranch(octokit, config, github.context), - inputs.getRemoteBranches(octokit, github.context), - inputs.getPullRequests(octokit, github.context) + inputs.getMainBranch(octokit, config, github2.context), + inputs.getRemoteBranches(octokit, github2.context), + inputs.getPullRequests(octokit, github2.context) ]); const perennialBranches = await inputs.getPerennialBranches(config, remoteBranches); - const context2 = { + const context3 = { octokit, - currentPullRequest: inputs.getCurrentPullRequest(github.context), + currentPullRequest: inputs.getCurrentPullRequest(github2.context), pullRequests, mainBranch, remoteBranches, perennialBranches, skipSingleStacks: inputs.getSkipSingleStacks() }; - void main(context2); + void main(context3); } catch (error) { if (error instanceof Error) { core4.setFailed(error.message); diff --git a/src/main.ts b/src/main.ts index d2ed1fc..92345e3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -121,6 +121,10 @@ export async function main({ let line = indentation + if (stackNode.type === 'orphan-branch') { + line += `- \`${stackNode.ref}\` - :warning: No PR associated with branch` + } + if (stackNode.type === 'perennial' && terminatingRefs.includes(stackNode.ref)) { line += `- \`${stackNode.ref}\`` } @@ -145,8 +149,6 @@ export async function main({ const stackGraph = getStackGraph(currentPullRequest) - console.log(stackGraph.inspect().nodes) - const shouldSkip = () => { const neighbors = stackGraph.neighbors(currentPullRequest.head.ref) const allPerennialBranches = stackGraph.filterNodes( @@ -165,7 +167,11 @@ export async function main({ } stackGraph.forEachNode((_, stackNode) => { - if (stackNode.type !== 'pull-request' || !stackNode.shouldPrint) { + if ( + stackNode.type !== 'pull-request' || + !stackNode.shouldPrint || + !stackNode.isCurrent + ) { return } @@ -181,11 +187,11 @@ export async function main({ output, }) - // await octokit.rest.pulls.update({ - // ...github.context.repo, - // pull_number: stackNode.number, - // body: description, - // }) + await octokit.rest.pulls.update({ + ...github.context.repo, + pull_number: stackNode.number, + body: description, + }) }) }) From 15d5339ebb68ef4f49649722b683dadf911042d4 Mon Sep 17 00:00:00 2001 From: Long Tran Date: Wed, 27 Nov 2024 21:46:58 +1100 Subject: [PATCH 11/31] fixes --- dist/index.js | 8 -------- src/main.ts | 10 ---------- 2 files changed, 18 deletions(-) diff --git a/dist/index.js b/dist/index.js index d796f4a..72fc4fd 100644 --- a/dist/index.js +++ b/dist/index.js @@ -42907,14 +42907,6 @@ async function main({ }, { mode: "outbound" } ); - stackGraph2.forEachNode((node2, attributes) => { - if (!attributes.shouldPrint) { - try { - stackGraph2.dropNode(node2); - } catch { - } - } - }); return stackGraph2; }; const getOutput = (graph) => { diff --git a/src/main.ts b/src/main.ts index 92345e3..334ed98 100644 --- a/src/main.ts +++ b/src/main.ts @@ -95,16 +95,6 @@ export async function main({ { mode: 'outbound' } ) - stackGraph.forEachNode((node, attributes) => { - if (!attributes.shouldPrint) { - try { - stackGraph.dropNode(node) - } catch { - // Do nothing - } - } - }) - return stackGraph } From 5166f3add790028f37d0a4f5f613aeb686610fc9 Mon Sep 17 00:00:00 2001 From: Long Tran Date: Wed, 27 Nov 2024 22:07:08 +1100 Subject: [PATCH 12/31] fixes --- dist/index.js | 2 +- src/main.ts | 2 +- src/types.ts | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/dist/index.js b/dist/index.js index 72fc4fd..5b9dcb2 100644 --- a/dist/index.js +++ b/dist/index.js @@ -42837,7 +42837,6 @@ async function main({ currentPullRequest, pullRequests, mainBranch, - remoteBranches, perennialBranches, skipSingleStacks }) { @@ -42956,6 +42955,7 @@ async function main({ jobs.push(async () => { core.info(`Updating stack details for PR #${stackNode.number}`); const stackGraph2 = getStackGraph(stackNode); + console.log(JSON.stringify(stackGraph2.inspect(), null, 2)); const output = getOutput(stackGraph2); let description = stackNode.body ?? ""; description = updateDescription({ diff --git a/src/main.ts b/src/main.ts index 334ed98..e921f30 100644 --- a/src/main.ts +++ b/src/main.ts @@ -10,7 +10,6 @@ export async function main({ currentPullRequest, pullRequests, mainBranch, - remoteBranches, perennialBranches, skipSingleStacks, }: Context) { @@ -169,6 +168,7 @@ export async function main({ core.info(`Updating stack details for PR #${stackNode.number}`) const stackGraph = getStackGraph(stackNode) + console.log(JSON.stringify(stackGraph.inspect(), null, 2)) const output = getOutput(stackGraph) let description = stackNode.body ?? '' diff --git a/src/types.ts b/src/types.ts index 9d2fa83..803db4e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -22,7 +22,6 @@ export type Context = { mainBranch: string currentPullRequest: PullRequest pullRequests: PullRequest[] - remoteBranches: string[] perennialBranches: string[] skipSingleStacks: boolean } From bd2e861d25e4b89474e8cee64ccb5b54b84e908e Mon Sep 17 00:00:00 2001 From: Long Tran Date: Wed, 27 Nov 2024 22:11:43 +1100 Subject: [PATCH 13/31] fixes --- dist/index.js | 4 ++-- src/inputs.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index 5b9dcb2..54634f7 100644 --- a/dist/index.js +++ b/dist/index.js @@ -46959,8 +46959,8 @@ var inputs = { (response) => response.data.map( (item) => ({ number: item.number, - base: item.base, - head: item.head, + base: { ref: item.base.ref }, + head: { ref: item.head.ref }, body: item.body ?? void 0, state: item.state }) diff --git a/src/inputs.ts b/src/inputs.ts index c75bbca..534f33e 100644 --- a/src/inputs.ts +++ b/src/inputs.ts @@ -128,8 +128,8 @@ export const inputs = { response.data.map( (item): PullRequest => ({ number: item.number, - base: item.base, - head: item.head, + base: { ref: item.base.ref }, + head: { ref: item.head.ref }, body: item.body ?? undefined, state: item.state, }) From 1499e566296a7b6c1f12999a9ab214a81b60f877 Mon Sep 17 00:00:00 2001 From: Long Tran Date: Wed, 27 Nov 2024 22:55:07 +1100 Subject: [PATCH 14/31] fixes --- dist/index.js | 38 ++++++++++++++++++-------------------- src/main.ts | 39 ++++++++++++++++++--------------------- 2 files changed, 36 insertions(+), 41 deletions(-) diff --git a/dist/index.js b/dist/index.js index 54634f7..7f4faf9 100644 --- a/dist/index.js +++ b/dist/index.js @@ -42854,53 +42854,51 @@ async function main({ const openPullRequests = pullRequests.filter( (pullRequest) => pullRequest.state === "open" ); - openPullRequests.forEach((pullRequest) => { - repoGraph.mergeNode(pullRequest.head.ref, { + openPullRequests.forEach((openPullRequest) => { + repoGraph.mergeNode(openPullRequest.head.ref, { type: "pull-request", - ...pullRequest + ...openPullRequest }); }); - openPullRequests.forEach((pullRequest) => { - const hasExistingBasePullRequest = repoGraph.hasNode(pullRequest.base.ref); + openPullRequests.forEach((openPullRequest) => { + const hasExistingBasePullRequest = repoGraph.hasNode(openPullRequest.base.ref); if (hasExistingBasePullRequest) { - repoGraph.mergeDirectedEdge(pullRequest.base.ref, pullRequest.head.ref); + repoGraph.mergeDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref); return; } const basePullRequest = pullRequests.find( - (basePullRequest2) => basePullRequest2.head.ref === pullRequest.base.ref + (basePullRequest2) => basePullRequest2.head.ref === openPullRequest.base.ref ); if (basePullRequest?.state === "closed") { - repoGraph.mergeNode(pullRequest.base.ref, { + repoGraph.mergeNode(openPullRequest.base.ref, { type: "pull-request", ...basePullRequest }); - repoGraph.mergeDirectedEdge(pullRequest.base.ref, pullRequest.head.ref); + repoGraph.mergeDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref); return; } - repoGraph.mergeNode(pullRequest.base.ref, { + repoGraph.mergeNode(openPullRequest.base.ref, { type: "orphan-branch", - ref: pullRequest.base.ref + ref: openPullRequest.base.ref }); - repoGraph.mergeDirectedEdge(pullRequest.base.ref, pullRequest.head.ref); + repoGraph.mergeDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref); }); const terminatingRefs = [mainBranch, ...perennialBranches]; - const getStackGraph = (anchorPullRequest) => { + const getStackGraph = (pullRequest) => { const stackGraph2 = repoGraph.copy(); - stackGraph2.setNodeAttribute(anchorPullRequest.head.ref, "isCurrent", true); + stackGraph2.setNodeAttribute(pullRequest.head.ref, "isCurrent", true); (0, import_graphology_traversal.bfsFromNode)( - repoGraph, - anchorPullRequest.head.ref, + stackGraph2, + pullRequest.head.ref, (ref, attributes) => { stackGraph2.setNodeAttribute(ref, "shouldPrint", true); return attributes.type === "perennial" || attributes.type === "orphan-branch"; }, - { - mode: "inbound" - } + { mode: "inbound" } ); (0, import_graphology_traversal.dfsFromNode)( stackGraph2, - anchorPullRequest.head.ref, + pullRequest.head.ref, (ref) => { stackGraph2.setNodeAttribute(ref, "shouldPrint", true); }, diff --git a/src/main.ts b/src/main.ts index e921f30..8e6b62a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -31,63 +31,60 @@ export async function main({ (pullRequest) => pullRequest.state === 'open' ) - openPullRequests.forEach((pullRequest) => { - repoGraph.mergeNode(pullRequest.head.ref, { + openPullRequests.forEach((openPullRequest) => { + repoGraph.mergeNode(openPullRequest.head.ref, { type: 'pull-request', - ...pullRequest, + ...openPullRequest, }) }) - openPullRequests.forEach((pullRequest) => { - const hasExistingBasePullRequest = repoGraph.hasNode(pullRequest.base.ref) + openPullRequests.forEach((openPullRequest) => { + const hasExistingBasePullRequest = repoGraph.hasNode(openPullRequest.base.ref) if (hasExistingBasePullRequest) { - repoGraph.mergeDirectedEdge(pullRequest.base.ref, pullRequest.head.ref) + repoGraph.mergeDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref) return } const basePullRequest = pullRequests.find( - (basePullRequest) => basePullRequest.head.ref === pullRequest.base.ref + (basePullRequest) => basePullRequest.head.ref === openPullRequest.base.ref ) - if (basePullRequest?.state === 'closed') { - repoGraph.mergeNode(pullRequest.base.ref, { + repoGraph.mergeNode(openPullRequest.base.ref, { type: 'pull-request', ...basePullRequest, }) - repoGraph.mergeDirectedEdge(pullRequest.base.ref, pullRequest.head.ref) + repoGraph.mergeDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref) return } - repoGraph.mergeNode(pullRequest.base.ref, { + repoGraph.mergeNode(openPullRequest.base.ref, { type: 'orphan-branch', - ref: pullRequest.base.ref, + ref: openPullRequest.base.ref, }) - repoGraph.mergeDirectedEdge(pullRequest.base.ref, pullRequest.head.ref) + repoGraph.mergeDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref) }) const terminatingRefs = [mainBranch, ...perennialBranches] - const getStackGraph = (anchorPullRequest: PullRequest) => { + const getStackGraph = (pullRequest: PullRequest) => { const stackGraph = repoGraph.copy() as MultiDirectedGraph - stackGraph.setNodeAttribute(anchorPullRequest.head.ref, 'isCurrent', true) + stackGraph.setNodeAttribute(pullRequest.head.ref, 'isCurrent', true) bfsFromNode( - repoGraph, - anchorPullRequest.head.ref, + stackGraph, + pullRequest.head.ref, (ref, attributes) => { stackGraph.setNodeAttribute(ref, 'shouldPrint', true) return attributes.type === 'perennial' || attributes.type === 'orphan-branch' }, - { - mode: 'inbound', - } + { mode: 'inbound' } ) dfsFromNode( stackGraph, - anchorPullRequest.head.ref, + pullRequest.head.ref, (ref) => { stackGraph.setNodeAttribute(ref, 'shouldPrint', true) }, From abf6f3d577fb14941ad046f3e1cd2a177978e2ff Mon Sep 17 00:00:00 2001 From: Long Tran Date: Wed, 27 Nov 2024 23:11:27 +1100 Subject: [PATCH 15/31] fixes --- dist/index.js | 1 + src/main.ts | 2 ++ 2 files changed, 3 insertions(+) diff --git a/dist/index.js b/dist/index.js index 7f4faf9..88e4c78 100644 --- a/dist/index.js +++ b/dist/index.js @@ -42913,6 +42913,7 @@ async function main({ (_, stackNode, depth) => { if (!stackNode.shouldPrint) return; + console.log(stackNode, depth); const tabSize = depth * 2; const indentation = new Array(tabSize).fill(" ").join(""); let line = indentation; diff --git a/src/main.ts b/src/main.ts index 8e6b62a..e4f1bf1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -102,6 +102,8 @@ export async function main({ (_, stackNode, depth) => { if (!stackNode.shouldPrint) return + console.log(stackNode, depth) + const tabSize = depth * 2 const indentation = new Array(tabSize).fill(' ').join('') From 4c6e358531e6bab21c0e83dab8ec8e689276ada8 Mon Sep 17 00:00:00 2001 From: Long Tran Date: Wed, 27 Nov 2024 23:27:15 +1100 Subject: [PATCH 16/31] fixes --- dist/index.js | 4 ++-- src/main.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index 88e4c78..ba0cb8d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -42910,10 +42910,10 @@ async function main({ const lines = []; (0, import_graphology_traversal.dfs)( graph, - (_, stackNode, depth) => { + (ref, stackNode, depth) => { if (!stackNode.shouldPrint) return; - console.log(stackNode, depth); + console.log(ref, stackNode, depth); const tabSize = depth * 2; const indentation = new Array(tabSize).fill(" ").join(""); let line = indentation; diff --git a/src/main.ts b/src/main.ts index e4f1bf1..064d1c2 100644 --- a/src/main.ts +++ b/src/main.ts @@ -99,10 +99,10 @@ export async function main({ dfs( graph, - (_, stackNode, depth) => { + (ref, stackNode, depth) => { if (!stackNode.shouldPrint) return - console.log(stackNode, depth) + console.log(ref, stackNode, depth) const tabSize = depth * 2 const indentation = new Array(tabSize).fill(' ').join('') From 736e6929a0a8f1d6d205aa0a1295511e97a8220c Mon Sep 17 00:00:00 2001 From: Long Tran Date: Wed, 27 Nov 2024 23:30:26 +1100 Subject: [PATCH 17/31] fixes --- dist/index.js | 4 ++-- src/main.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dist/index.js b/dist/index.js index ba0cb8d..16728b9 100644 --- a/dist/index.js +++ b/dist/index.js @@ -42910,10 +42910,10 @@ async function main({ const lines = []; (0, import_graphology_traversal.dfs)( graph, - (ref, stackNode, depth) => { + (_, stackNode, depth) => { + console.log(stackNode, depth); if (!stackNode.shouldPrint) return; - console.log(ref, stackNode, depth); const tabSize = depth * 2; const indentation = new Array(tabSize).fill(" ").join(""); let line = indentation; diff --git a/src/main.ts b/src/main.ts index 064d1c2..eced9c8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -99,10 +99,10 @@ export async function main({ dfs( graph, - (ref, stackNode, depth) => { - if (!stackNode.shouldPrint) return + (_, stackNode, depth) => { + console.log(stackNode, depth) - console.log(ref, stackNode, depth) + if (!stackNode.shouldPrint) return const tabSize = depth * 2 const indentation = new Array(tabSize).fill(' ').join('') From dda876fc825d41132b0259973541f18ec05772a6 Mon Sep 17 00:00:00 2001 From: Long Tran Date: Wed, 27 Nov 2024 23:35:47 +1100 Subject: [PATCH 18/31] fixes --- dist/index.js | 7 +++++-- src/main.ts | 9 ++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/dist/index.js b/dist/index.js index 16728b9..d26f495 100644 --- a/dist/index.js +++ b/dist/index.js @@ -42904,6 +42904,11 @@ async function main({ }, { mode: "outbound" } ); + stackGraph2.forEachNode((ref, stackNode) => { + if (!stackNode.shouldPrint) { + stackGraph2.dropNode(ref); + } + }); return stackGraph2; }; const getOutput = (graph) => { @@ -42911,7 +42916,6 @@ async function main({ (0, import_graphology_traversal.dfs)( graph, (_, stackNode, depth) => { - console.log(stackNode, depth); if (!stackNode.shouldPrint) return; const tabSize = depth * 2; @@ -42954,7 +42958,6 @@ async function main({ jobs.push(async () => { core.info(`Updating stack details for PR #${stackNode.number}`); const stackGraph2 = getStackGraph(stackNode); - console.log(JSON.stringify(stackGraph2.inspect(), null, 2)); const output = getOutput(stackGraph2); let description = stackNode.body ?? ""; description = updateDescription({ diff --git a/src/main.ts b/src/main.ts index eced9c8..5ad177a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -91,6 +91,12 @@ export async function main({ { mode: 'outbound' } ) + stackGraph.forEachNode((ref, stackNode) => { + if (!stackNode.shouldPrint) { + stackGraph.dropNode(ref) + } + }) + return stackGraph } @@ -100,8 +106,6 @@ export async function main({ dfs( graph, (_, stackNode, depth) => { - console.log(stackNode, depth) - if (!stackNode.shouldPrint) return const tabSize = depth * 2 @@ -167,7 +171,6 @@ export async function main({ core.info(`Updating stack details for PR #${stackNode.number}`) const stackGraph = getStackGraph(stackNode) - console.log(JSON.stringify(stackGraph.inspect(), null, 2)) const output = getOutput(stackGraph) let description = stackNode.body ?? '' From 61931f627a3718fd71090a36dce7ac7046e9e80c Mon Sep 17 00:00:00 2001 From: Long Tran Date: Wed, 27 Nov 2024 23:38:10 +1100 Subject: [PATCH 19/31] fixes --- dist/index.js | 1 + src/main.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/dist/index.js b/dist/index.js index d26f495..294e028 100644 --- a/dist/index.js +++ b/dist/index.js @@ -42916,6 +42916,7 @@ async function main({ (0, import_graphology_traversal.dfs)( graph, (_, stackNode, depth) => { + console.log(stackNode, depth); if (!stackNode.shouldPrint) return; const tabSize = depth * 2; diff --git a/src/main.ts b/src/main.ts index 5ad177a..e5f3b05 100644 --- a/src/main.ts +++ b/src/main.ts @@ -106,6 +106,7 @@ export async function main({ dfs( graph, (_, stackNode, depth) => { + console.log(stackNode, depth) if (!stackNode.shouldPrint) return const tabSize = depth * 2 From a6ddf701135a2e279bb8a91574b1d55d048f6e75 Mon Sep 17 00:00:00 2001 From: Long Tran Date: Wed, 27 Nov 2024 23:39:33 +1100 Subject: [PATCH 20/31] fixes --- dist/index.js | 1 + src/main.ts | 2 ++ 2 files changed, 3 insertions(+) diff --git a/dist/index.js b/dist/index.js index 294e028..ffdb7bf 100644 --- a/dist/index.js +++ b/dist/index.js @@ -42913,6 +42913,7 @@ async function main({ }; const getOutput = (graph) => { const lines = []; + console.log(JSON.stringify(graph.inspect(), null, 2)); (0, import_graphology_traversal.dfs)( graph, (_, stackNode, depth) => { diff --git a/src/main.ts b/src/main.ts index e5f3b05..221a412 100644 --- a/src/main.ts +++ b/src/main.ts @@ -103,6 +103,8 @@ export async function main({ const getOutput = (graph: MultiDirectedGraph) => { const lines: string[] = [] + console.log(JSON.stringify(graph.inspect(), null, 2)) + dfs( graph, (_, stackNode, depth) => { From 7858509e9a5d00fceb2de488a01ecec8cbfd7ed2 Mon Sep 17 00:00:00 2001 From: Long Tran Date: Wed, 27 Nov 2024 23:54:14 +1100 Subject: [PATCH 21/31] fixes --- dist/index.js | 27 ++++++++++++++------------- src/main.ts | 34 +++++++++++++++++++++------------- 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/dist/index.js b/dist/index.js index ffdb7bf..928c9f7 100644 --- a/dist/index.js +++ b/dist/index.js @@ -42841,12 +42841,15 @@ async function main({ skipSingleStacks }) { const repoGraph = new import_graphology.MultiDirectedGraph(); - repoGraph.mergeNode(mainBranch, { + repoGraph.addNode(mainBranch, { type: "perennial", ref: mainBranch }); perennialBranches.forEach((perennialBranch) => { - repoGraph.mergeNode(perennialBranch, { + if (repoGraph.hasNode(perennialBranch)) { + return; + } + repoGraph.addNode(perennialBranch, { type: "perennial", ref: perennialBranch }); @@ -42855,7 +42858,10 @@ async function main({ (pullRequest) => pullRequest.state === "open" ); openPullRequests.forEach((openPullRequest) => { - repoGraph.mergeNode(openPullRequest.head.ref, { + if (repoGraph.hasNode(openPullRequest.head.ref)) { + return; + } + repoGraph.addNode(openPullRequest.head.ref, { type: "pull-request", ...openPullRequest }); @@ -42863,25 +42869,25 @@ async function main({ openPullRequests.forEach((openPullRequest) => { const hasExistingBasePullRequest = repoGraph.hasNode(openPullRequest.base.ref); if (hasExistingBasePullRequest) { - repoGraph.mergeDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref); + repoGraph.addDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref); return; } const basePullRequest = pullRequests.find( (basePullRequest2) => basePullRequest2.head.ref === openPullRequest.base.ref ); if (basePullRequest?.state === "closed") { - repoGraph.mergeNode(openPullRequest.base.ref, { + repoGraph.addNode(openPullRequest.base.ref, { type: "pull-request", ...basePullRequest }); - repoGraph.mergeDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref); + repoGraph.addDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref); return; } - repoGraph.mergeNode(openPullRequest.base.ref, { + repoGraph.addNode(openPullRequest.base.ref, { type: "orphan-branch", ref: openPullRequest.base.ref }); - repoGraph.mergeDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref); + repoGraph.addDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref); }); const terminatingRefs = [mainBranch, ...perennialBranches]; const getStackGraph = (pullRequest) => { @@ -42904,11 +42910,6 @@ async function main({ }, { mode: "outbound" } ); - stackGraph2.forEachNode((ref, stackNode) => { - if (!stackNode.shouldPrint) { - stackGraph2.dropNode(ref); - } - }); return stackGraph2; }; const getOutput = (graph) => { diff --git a/src/main.ts b/src/main.ts index 221a412..473da81 100644 --- a/src/main.ts +++ b/src/main.ts @@ -15,13 +15,17 @@ export async function main({ }: Context) { const repoGraph = new MultiDirectedGraph() - repoGraph.mergeNode(mainBranch, { + repoGraph.addNode(mainBranch, { type: 'perennial', ref: mainBranch, }) perennialBranches.forEach((perennialBranch) => { - repoGraph.mergeNode(perennialBranch, { + if (repoGraph.hasNode(perennialBranch)) { + return + } + + repoGraph.addNode(perennialBranch, { type: 'perennial', ref: perennialBranch, }) @@ -32,7 +36,11 @@ export async function main({ ) openPullRequests.forEach((openPullRequest) => { - repoGraph.mergeNode(openPullRequest.head.ref, { + if (repoGraph.hasNode(openPullRequest.head.ref)) { + return + } + + repoGraph.addNode(openPullRequest.head.ref, { type: 'pull-request', ...openPullRequest, }) @@ -41,7 +49,7 @@ export async function main({ openPullRequests.forEach((openPullRequest) => { const hasExistingBasePullRequest = repoGraph.hasNode(openPullRequest.base.ref) if (hasExistingBasePullRequest) { - repoGraph.mergeDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref) + repoGraph.addDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref) return } @@ -50,20 +58,20 @@ export async function main({ (basePullRequest) => basePullRequest.head.ref === openPullRequest.base.ref ) if (basePullRequest?.state === 'closed') { - repoGraph.mergeNode(openPullRequest.base.ref, { + repoGraph.addNode(openPullRequest.base.ref, { type: 'pull-request', ...basePullRequest, }) - repoGraph.mergeDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref) + repoGraph.addDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref) return } - repoGraph.mergeNode(openPullRequest.base.ref, { + repoGraph.addNode(openPullRequest.base.ref, { type: 'orphan-branch', ref: openPullRequest.base.ref, }) - repoGraph.mergeDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref) + repoGraph.addDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref) }) const terminatingRefs = [mainBranch, ...perennialBranches] @@ -91,11 +99,11 @@ export async function main({ { mode: 'outbound' } ) - stackGraph.forEachNode((ref, stackNode) => { - if (!stackNode.shouldPrint) { - stackGraph.dropNode(ref) - } - }) + // stackGraph.forEachNode((ref, stackNode) => { + // if (!stackNode.shouldPrint) { + // stackGraph.dropNode(ref) + // } + // }) return stackGraph } From 5982c044644ce54efeb2b8ea76f3e63834bf7aab Mon Sep 17 00:00:00 2001 From: Long Tran Date: Thu, 28 Nov 2024 00:00:51 +1100 Subject: [PATCH 22/31] fixes --- dist/index.js | 60 ++++++++++++++++++++++++++++--------------- src/main.ts | 70 +++++++++++++++++++++++++++++++-------------------- 2 files changed, 83 insertions(+), 47 deletions(-) diff --git a/dist/index.js b/dist/index.js index 928c9f7..55bcb3c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -42841,15 +42841,12 @@ async function main({ skipSingleStacks }) { const repoGraph = new import_graphology.MultiDirectedGraph(); - repoGraph.addNode(mainBranch, { + repoGraph.mergeNode(mainBranch, { type: "perennial", ref: mainBranch }); perennialBranches.forEach((perennialBranch) => { - if (repoGraph.hasNode(perennialBranch)) { - return; - } - repoGraph.addNode(perennialBranch, { + repoGraph.mergeNode(perennialBranch, { type: "perennial", ref: perennialBranch }); @@ -42858,10 +42855,7 @@ async function main({ (pullRequest) => pullRequest.state === "open" ); openPullRequests.forEach((openPullRequest) => { - if (repoGraph.hasNode(openPullRequest.head.ref)) { - return; - } - repoGraph.addNode(openPullRequest.head.ref, { + repoGraph.mergeNode(openPullRequest.head.ref, { type: "pull-request", ...openPullRequest }); @@ -42869,35 +42863,49 @@ async function main({ openPullRequests.forEach((openPullRequest) => { const hasExistingBasePullRequest = repoGraph.hasNode(openPullRequest.base.ref); if (hasExistingBasePullRequest) { - repoGraph.addDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref); + repoGraph.mergeDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref); return; } const basePullRequest = pullRequests.find( (basePullRequest2) => basePullRequest2.head.ref === openPullRequest.base.ref ); if (basePullRequest?.state === "closed") { - repoGraph.addNode(openPullRequest.base.ref, { + repoGraph.mergeNode(openPullRequest.base.ref, { type: "pull-request", ...basePullRequest }); - repoGraph.addDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref); + repoGraph.mergeDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref); return; } - repoGraph.addNode(openPullRequest.base.ref, { + repoGraph.mergeNode(openPullRequest.base.ref, { type: "orphan-branch", ref: openPullRequest.base.ref }); - repoGraph.addDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref); + repoGraph.mergeDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref); }); const terminatingRefs = [mainBranch, ...perennialBranches]; const getStackGraph = (pullRequest) => { - const stackGraph2 = repoGraph.copy(); - stackGraph2.setNodeAttribute(pullRequest.head.ref, "isCurrent", true); + const stackGraph2 = new import_graphology.MultiDirectedGraph(); + stackGraph2.addNode(pullRequest.head.ref, { + type: "pull-request", + isCurrent: true, + ...pullRequest + }); (0, import_graphology_traversal.bfsFromNode)( - stackGraph2, + repoGraph, pullRequest.head.ref, (ref, attributes) => { - stackGraph2.setNodeAttribute(ref, "shouldPrint", true); + if (attributes.type === "pull-request") { + stackGraph2.addNode(attributes.head.ref, { + ...attributes, + shouldPrint: true + }); + } else { + stackGraph2.addNode(ref, { + ...attributes, + shouldPrint: true + }); + } return attributes.type === "perennial" || attributes.type === "orphan-branch"; }, { mode: "inbound" } @@ -42905,11 +42913,23 @@ async function main({ (0, import_graphology_traversal.dfsFromNode)( stackGraph2, pullRequest.head.ref, - (ref) => { - stackGraph2.setNodeAttribute(ref, "shouldPrint", true); + (_, attributes) => { + if (attributes.type !== "pull-request") { + return false; + } + stackGraph2.addNode(attributes.head.ref, { + ...attributes, + shouldPrint: true + }); + return true; }, { mode: "outbound" } ); + stackGraph2.forEachNode((ref, stackNode) => { + if (!stackNode.shouldPrint) { + stackGraph2.dropNode(ref); + } + }); return stackGraph2; }; const getOutput = (graph) => { diff --git a/src/main.ts b/src/main.ts index 473da81..c0686fa 100644 --- a/src/main.ts +++ b/src/main.ts @@ -15,17 +15,13 @@ export async function main({ }: Context) { const repoGraph = new MultiDirectedGraph() - repoGraph.addNode(mainBranch, { + repoGraph.mergeNode(mainBranch, { type: 'perennial', ref: mainBranch, }) perennialBranches.forEach((perennialBranch) => { - if (repoGraph.hasNode(perennialBranch)) { - return - } - - repoGraph.addNode(perennialBranch, { + repoGraph.mergeNode(perennialBranch, { type: 'perennial', ref: perennialBranch, }) @@ -36,11 +32,7 @@ export async function main({ ) openPullRequests.forEach((openPullRequest) => { - if (repoGraph.hasNode(openPullRequest.head.ref)) { - return - } - - repoGraph.addNode(openPullRequest.head.ref, { + repoGraph.mergeNode(openPullRequest.head.ref, { type: 'pull-request', ...openPullRequest, }) @@ -49,7 +41,7 @@ export async function main({ openPullRequests.forEach((openPullRequest) => { const hasExistingBasePullRequest = repoGraph.hasNode(openPullRequest.base.ref) if (hasExistingBasePullRequest) { - repoGraph.addDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref) + repoGraph.mergeDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref) return } @@ -58,33 +50,48 @@ export async function main({ (basePullRequest) => basePullRequest.head.ref === openPullRequest.base.ref ) if (basePullRequest?.state === 'closed') { - repoGraph.addNode(openPullRequest.base.ref, { + repoGraph.mergeNode(openPullRequest.base.ref, { type: 'pull-request', ...basePullRequest, }) - repoGraph.addDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref) + repoGraph.mergeDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref) return } - repoGraph.addNode(openPullRequest.base.ref, { + repoGraph.mergeNode(openPullRequest.base.ref, { type: 'orphan-branch', ref: openPullRequest.base.ref, }) - repoGraph.addDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref) + repoGraph.mergeDirectedEdge(openPullRequest.base.ref, openPullRequest.head.ref) }) const terminatingRefs = [mainBranch, ...perennialBranches] const getStackGraph = (pullRequest: PullRequest) => { - const stackGraph = repoGraph.copy() as MultiDirectedGraph - stackGraph.setNodeAttribute(pullRequest.head.ref, 'isCurrent', true) + const stackGraph = new MultiDirectedGraph() + stackGraph.addNode(pullRequest.head.ref, { + type: 'pull-request', + isCurrent: true, + ...pullRequest, + }) bfsFromNode( - stackGraph, + repoGraph, pullRequest.head.ref, (ref, attributes) => { - stackGraph.setNodeAttribute(ref, 'shouldPrint', true) + if (attributes.type === 'pull-request') { + stackGraph.addNode(attributes.head.ref, { + ...attributes, + shouldPrint: true, + }) + } else { + stackGraph.addNode(ref, { + ...attributes, + shouldPrint: true, + }) + } + return attributes.type === 'perennial' || attributes.type === 'orphan-branch' }, { mode: 'inbound' } @@ -93,17 +100,26 @@ export async function main({ dfsFromNode( stackGraph, pullRequest.head.ref, - (ref) => { - stackGraph.setNodeAttribute(ref, 'shouldPrint', true) + (_, attributes) => { + if (attributes.type !== 'pull-request') { + return false + } + + stackGraph.addNode(attributes.head.ref, { + ...attributes, + shouldPrint: true, + }) + + return true }, { mode: 'outbound' } ) - // stackGraph.forEachNode((ref, stackNode) => { - // if (!stackNode.shouldPrint) { - // stackGraph.dropNode(ref) - // } - // }) + stackGraph.forEachNode((ref, stackNode) => { + if (!stackNode.shouldPrint) { + stackGraph.dropNode(ref) + } + }) return stackGraph } From f87fea0d85fe28ad279c94c3daae7bc70c8e34e1 Mon Sep 17 00:00:00 2001 From: Long Tran Date: Thu, 28 Nov 2024 00:04:50 +1100 Subject: [PATCH 23/31] fixes --- dist/index.js | 10 +++++----- src/main.ts | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/dist/index.js b/dist/index.js index 55bcb3c..ea313ed 100644 --- a/dist/index.js +++ b/dist/index.js @@ -42886,7 +42886,7 @@ async function main({ const terminatingRefs = [mainBranch, ...perennialBranches]; const getStackGraph = (pullRequest) => { const stackGraph2 = new import_graphology.MultiDirectedGraph(); - stackGraph2.addNode(pullRequest.head.ref, { + stackGraph2.mergeNode(pullRequest.head.ref, { type: "pull-request", isCurrent: true, ...pullRequest @@ -42896,12 +42896,12 @@ async function main({ pullRequest.head.ref, (ref, attributes) => { if (attributes.type === "pull-request") { - stackGraph2.addNode(attributes.head.ref, { + stackGraph2.mergeNode(attributes.head.ref, { ...attributes, shouldPrint: true }); } else { - stackGraph2.addNode(ref, { + stackGraph2.mergeNode(ref, { ...attributes, shouldPrint: true }); @@ -42911,13 +42911,13 @@ async function main({ { mode: "inbound" } ); (0, import_graphology_traversal.dfsFromNode)( - stackGraph2, + repoGraph, pullRequest.head.ref, (_, attributes) => { if (attributes.type !== "pull-request") { return false; } - stackGraph2.addNode(attributes.head.ref, { + stackGraph2.mergeNode(attributes.head.ref, { ...attributes, shouldPrint: true }); diff --git a/src/main.ts b/src/main.ts index c0686fa..62097ab 100644 --- a/src/main.ts +++ b/src/main.ts @@ -70,7 +70,7 @@ export async function main({ const getStackGraph = (pullRequest: PullRequest) => { const stackGraph = new MultiDirectedGraph() - stackGraph.addNode(pullRequest.head.ref, { + stackGraph.mergeNode(pullRequest.head.ref, { type: 'pull-request', isCurrent: true, ...pullRequest, @@ -81,12 +81,12 @@ export async function main({ pullRequest.head.ref, (ref, attributes) => { if (attributes.type === 'pull-request') { - stackGraph.addNode(attributes.head.ref, { + stackGraph.mergeNode(attributes.head.ref, { ...attributes, shouldPrint: true, }) } else { - stackGraph.addNode(ref, { + stackGraph.mergeNode(ref, { ...attributes, shouldPrint: true, }) @@ -98,14 +98,14 @@ export async function main({ ) dfsFromNode( - stackGraph, + repoGraph, pullRequest.head.ref, (_, attributes) => { if (attributes.type !== 'pull-request') { return false } - stackGraph.addNode(attributes.head.ref, { + stackGraph.mergeNode(attributes.head.ref, { ...attributes, shouldPrint: true, }) From b917c0a896d77438cc78f1482e11d31774546b7f Mon Sep 17 00:00:00 2001 From: Long Tran Date: Thu, 28 Nov 2024 00:06:43 +1100 Subject: [PATCH 24/31] fixes --- dist/index.js | 2 ++ src/main.ts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/dist/index.js b/dist/index.js index ea313ed..7df96b5 100644 --- a/dist/index.js +++ b/dist/index.js @@ -42900,6 +42900,7 @@ async function main({ ...attributes, shouldPrint: true }); + stackGraph2.mergeDirectedEdge(attributes.base.ref, attributes.head.ref); } else { stackGraph2.mergeNode(ref, { ...attributes, @@ -42921,6 +42922,7 @@ async function main({ ...attributes, shouldPrint: true }); + stackGraph2.mergeDirectedEdge(attributes.base.ref, attributes.head.ref); return true; }, { mode: "outbound" } diff --git a/src/main.ts b/src/main.ts index 62097ab..17eea29 100644 --- a/src/main.ts +++ b/src/main.ts @@ -85,6 +85,7 @@ export async function main({ ...attributes, shouldPrint: true, }) + stackGraph.mergeDirectedEdge(attributes.base.ref, attributes.head.ref) } else { stackGraph.mergeNode(ref, { ...attributes, @@ -109,6 +110,7 @@ export async function main({ ...attributes, shouldPrint: true, }) + stackGraph.mergeDirectedEdge(attributes.base.ref, attributes.head.ref) return true }, From 3c973399692d290ddafd6ee4aeaf18ca8eb598a0 Mon Sep 17 00:00:00 2001 From: Long Tran Date: Thu, 28 Nov 2024 00:08:30 +1100 Subject: [PATCH 25/31] fixes --- dist/index.js | 37 ++++++++++++++++--------------------- src/main.ts | 44 +++++++++++++++++++------------------------- 2 files changed, 35 insertions(+), 46 deletions(-) diff --git a/dist/index.js b/dist/index.js index 7df96b5..d99fe9f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -42891,6 +42891,22 @@ async function main({ isCurrent: true, ...pullRequest }); + (0, import_graphology_traversal.dfsFromNode)( + repoGraph, + pullRequest.head.ref, + (_, attributes) => { + if (attributes.type !== "pull-request") { + return false; + } + stackGraph2.mergeNode(attributes.head.ref, { + ...attributes, + shouldPrint: true + }); + stackGraph2.mergeDirectedEdge(attributes.base.ref, attributes.head.ref); + return true; + }, + { mode: "outbound" } + ); (0, import_graphology_traversal.bfsFromNode)( repoGraph, pullRequest.head.ref, @@ -42911,27 +42927,6 @@ async function main({ }, { mode: "inbound" } ); - (0, import_graphology_traversal.dfsFromNode)( - repoGraph, - pullRequest.head.ref, - (_, attributes) => { - if (attributes.type !== "pull-request") { - return false; - } - stackGraph2.mergeNode(attributes.head.ref, { - ...attributes, - shouldPrint: true - }); - stackGraph2.mergeDirectedEdge(attributes.base.ref, attributes.head.ref); - return true; - }, - { mode: "outbound" } - ); - stackGraph2.forEachNode((ref, stackNode) => { - if (!stackNode.shouldPrint) { - stackGraph2.dropNode(ref); - } - }); return stackGraph2; }; const getOutput = (graph) => { diff --git a/src/main.ts b/src/main.ts index 17eea29..9e1db08 100644 --- a/src/main.ts +++ b/src/main.ts @@ -76,6 +76,25 @@ export async function main({ ...pullRequest, }) + dfsFromNode( + repoGraph, + pullRequest.head.ref, + (_, attributes) => { + if (attributes.type !== 'pull-request') { + return false + } + + stackGraph.mergeNode(attributes.head.ref, { + ...attributes, + shouldPrint: true, + }) + stackGraph.mergeDirectedEdge(attributes.base.ref, attributes.head.ref) + + return true + }, + { mode: 'outbound' } + ) + bfsFromNode( repoGraph, pullRequest.head.ref, @@ -98,31 +117,6 @@ export async function main({ { mode: 'inbound' } ) - dfsFromNode( - repoGraph, - pullRequest.head.ref, - (_, attributes) => { - if (attributes.type !== 'pull-request') { - return false - } - - stackGraph.mergeNode(attributes.head.ref, { - ...attributes, - shouldPrint: true, - }) - stackGraph.mergeDirectedEdge(attributes.base.ref, attributes.head.ref) - - return true - }, - { mode: 'outbound' } - ) - - stackGraph.forEachNode((ref, stackNode) => { - if (!stackNode.shouldPrint) { - stackGraph.dropNode(ref) - } - }) - return stackGraph } From 07e62ebe31f6ae64dbf88f08afbcb727fcc3399b Mon Sep 17 00:00:00 2001 From: Long Tran Date: Thu, 28 Nov 2024 00:16:37 +1100 Subject: [PATCH 26/31] fixes --- dist/index.js | 54 ++++++++++++++++------------------------------ src/main.ts | 60 +++++++++++++++++---------------------------------- 2 files changed, 38 insertions(+), 76 deletions(-) diff --git a/dist/index.js b/dist/index.js index d99fe9f..cd17ddf 100644 --- a/dist/index.js +++ b/dist/index.js @@ -42885,48 +42885,30 @@ async function main({ }); const terminatingRefs = [mainBranch, ...perennialBranches]; const getStackGraph = (pullRequest) => { - const stackGraph2 = new import_graphology.MultiDirectedGraph(); - stackGraph2.mergeNode(pullRequest.head.ref, { - type: "pull-request", - isCurrent: true, - ...pullRequest - }); - (0, import_graphology_traversal.dfsFromNode)( - repoGraph, - pullRequest.head.ref, - (_, attributes) => { - if (attributes.type !== "pull-request") { - return false; - } - stackGraph2.mergeNode(attributes.head.ref, { - ...attributes, - shouldPrint: true - }); - stackGraph2.mergeDirectedEdge(attributes.base.ref, attributes.head.ref); - return true; - }, - { mode: "outbound" } - ); + const stackGraph2 = repoGraph.copy(); + stackGraph2.setNodeAttribute(pullRequest.head.ref, "isCurrent", true); (0, import_graphology_traversal.bfsFromNode)( - repoGraph, + stackGraph2, pullRequest.head.ref, (ref, attributes) => { - if (attributes.type === "pull-request") { - stackGraph2.mergeNode(attributes.head.ref, { - ...attributes, - shouldPrint: true - }); - stackGraph2.mergeDirectedEdge(attributes.base.ref, attributes.head.ref); - } else { - stackGraph2.mergeNode(ref, { - ...attributes, - shouldPrint: true - }); - } + stackGraph2.setNodeAttribute(ref, "shouldPrint", true); return attributes.type === "perennial" || attributes.type === "orphan-branch"; }, { mode: "inbound" } ); + (0, import_graphology_traversal.dfsFromNode)( + stackGraph2, + pullRequest.head.ref, + (ref) => { + stackGraph2.setNodeAttribute(ref, "shouldPrint", true); + }, + { mode: "outbound" } + ); + stackGraph2.forEachNode((ref, stackNode) => { + if (!stackNode.shouldPrint) { + stackGraph2.dropNode(ref); + } + }); return stackGraph2; }; const getOutput = (graph) => { @@ -42955,7 +42937,7 @@ async function main({ } lines.push(line); }, - { mode: "directed" } + { mode: "outbound" } ); return lines.join("\n"); }; diff --git a/src/main.ts b/src/main.ts index 9e1db08..fef9c24 100644 --- a/src/main.ts +++ b/src/main.ts @@ -69,54 +69,34 @@ export async function main({ const terminatingRefs = [mainBranch, ...perennialBranches] const getStackGraph = (pullRequest: PullRequest) => { - const stackGraph = new MultiDirectedGraph() - stackGraph.mergeNode(pullRequest.head.ref, { - type: 'pull-request', - isCurrent: true, - ...pullRequest, - }) - - dfsFromNode( - repoGraph, - pullRequest.head.ref, - (_, attributes) => { - if (attributes.type !== 'pull-request') { - return false - } - - stackGraph.mergeNode(attributes.head.ref, { - ...attributes, - shouldPrint: true, - }) - stackGraph.mergeDirectedEdge(attributes.base.ref, attributes.head.ref) - - return true - }, - { mode: 'outbound' } - ) + const stackGraph = repoGraph.copy() as MultiDirectedGraph + stackGraph.setNodeAttribute(pullRequest.head.ref, 'isCurrent', true) bfsFromNode( - repoGraph, + stackGraph, pullRequest.head.ref, (ref, attributes) => { - if (attributes.type === 'pull-request') { - stackGraph.mergeNode(attributes.head.ref, { - ...attributes, - shouldPrint: true, - }) - stackGraph.mergeDirectedEdge(attributes.base.ref, attributes.head.ref) - } else { - stackGraph.mergeNode(ref, { - ...attributes, - shouldPrint: true, - }) - } - + stackGraph.setNodeAttribute(ref, 'shouldPrint', true) return attributes.type === 'perennial' || attributes.type === 'orphan-branch' }, { mode: 'inbound' } ) + dfsFromNode( + stackGraph, + pullRequest.head.ref, + (ref) => { + stackGraph.setNodeAttribute(ref, 'shouldPrint', true) + }, + { mode: 'outbound' } + ) + + stackGraph.forEachNode((ref, stackNode) => { + if (!stackNode.shouldPrint) { + stackGraph.dropNode(ref) + } + }) + return stackGraph } @@ -154,7 +134,7 @@ export async function main({ lines.push(line) }, - { mode: 'directed' } + { mode: 'outbound' } ) return lines.join('\n') From 4f09612358570a4248990d5ad1df67eeebe0517f Mon Sep 17 00:00:00 2001 From: Long Tran Date: Thu, 28 Nov 2024 00:19:50 +1100 Subject: [PATCH 27/31] fixes --- dist/index.js | 3 ++- src/main.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index cd17ddf..2175ce5 100644 --- a/dist/index.js +++ b/dist/index.js @@ -42914,8 +42914,9 @@ async function main({ const getOutput = (graph) => { const lines = []; console.log(JSON.stringify(graph.inspect(), null, 2)); - (0, import_graphology_traversal.dfs)( + (0, import_graphology_traversal.dfsFromNode)( graph, + null, (_, stackNode, depth) => { console.log(stackNode, depth); if (!stackNode.shouldPrint) diff --git a/src/main.ts b/src/main.ts index fef9c24..be82795 100644 --- a/src/main.ts +++ b/src/main.ts @@ -105,8 +105,9 @@ export async function main({ console.log(JSON.stringify(graph.inspect(), null, 2)) - dfs( + dfsFromNode( graph, + null, (_, stackNode, depth) => { console.log(stackNode, depth) if (!stackNode.shouldPrint) return From e7d5301d664b4ddb74df52b558408d1d13654ae4 Mon Sep 17 00:00:00 2001 From: Long Tran Date: Thu, 28 Nov 2024 00:22:36 +1100 Subject: [PATCH 28/31] fixes --- dist/index.js | 2 +- src/main.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 2175ce5..634f903 100644 --- a/dist/index.js +++ b/dist/index.js @@ -42938,7 +42938,7 @@ async function main({ } lines.push(line); }, - { mode: "outbound" } + { mode: "directed" } ); return lines.join("\n"); }; diff --git a/src/main.ts b/src/main.ts index be82795..4ff89ad 100644 --- a/src/main.ts +++ b/src/main.ts @@ -135,7 +135,7 @@ export async function main({ lines.push(line) }, - { mode: 'outbound' } + { mode: 'directed' } ) return lines.join('\n') From 691b3b62ba6f8930790a358dcbbbe72fa08a99d3 Mon Sep 17 00:00:00 2001 From: Long Tran Date: Thu, 28 Nov 2024 00:26:13 +1100 Subject: [PATCH 29/31] fixes --- dist/index.js | 26 +++++++++++++------------- src/main.ts | 8 ++++---- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/dist/index.js b/dist/index.js index 634f903..408846c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -26149,9 +26149,9 @@ var require_graphology_cjs = __commonJS({ attachEdgeAttributesMethods(Graph); attachEdgeIterationMethods(Graph); attachNeighborIterationMethods(Graph); - var DirectedGraph = /* @__PURE__ */ function(_Graph) { - _inheritsLoose(DirectedGraph2, _Graph); - function DirectedGraph2(options) { + var DirectedGraph2 = /* @__PURE__ */ function(_Graph) { + _inheritsLoose(DirectedGraph3, _Graph); + function DirectedGraph3(options) { var finalOptions = assign({ type: "directed" }, options); @@ -26161,7 +26161,7 @@ var require_graphology_cjs = __commonJS({ throw new InvalidArgumentsGraphError('DirectedGraph.from: inconsistent "' + finalOptions.type + '" type in given options!'); return _Graph.call(this, finalOptions) || this; } - return DirectedGraph2; + return DirectedGraph3; }(Graph); var UndirectedGraph = /* @__PURE__ */ function(_Graph2) { _inheritsLoose(UndirectedGraph2, _Graph2); @@ -26189,9 +26189,9 @@ var require_graphology_cjs = __commonJS({ } return MultiGraph2; }(Graph); - var MultiDirectedGraph2 = /* @__PURE__ */ function(_Graph4) { - _inheritsLoose(MultiDirectedGraph3, _Graph4); - function MultiDirectedGraph3(options) { + var MultiDirectedGraph = /* @__PURE__ */ function(_Graph4) { + _inheritsLoose(MultiDirectedGraph2, _Graph4); + function MultiDirectedGraph2(options) { var finalOptions = assign({ type: "directed", multi: true @@ -26202,7 +26202,7 @@ var require_graphology_cjs = __commonJS({ throw new InvalidArgumentsGraphError('MultiDirectedGraph.from: inconsistent "' + finalOptions.type + '" type in given options!'); return _Graph4.call(this, finalOptions) || this; } - return MultiDirectedGraph3; + return MultiDirectedGraph2; }(Graph); var MultiUndirectedGraph = /* @__PURE__ */ function(_Graph5) { _inheritsLoose(MultiUndirectedGraph2, _Graph5); @@ -26228,16 +26228,16 @@ var require_graphology_cjs = __commonJS({ }; } attachStaticFromMethod(Graph); - attachStaticFromMethod(DirectedGraph); + attachStaticFromMethod(DirectedGraph2); attachStaticFromMethod(UndirectedGraph); attachStaticFromMethod(MultiGraph); - attachStaticFromMethod(MultiDirectedGraph2); + attachStaticFromMethod(MultiDirectedGraph); attachStaticFromMethod(MultiUndirectedGraph); Graph.Graph = Graph; - Graph.DirectedGraph = DirectedGraph; + Graph.DirectedGraph = DirectedGraph2; Graph.UndirectedGraph = UndirectedGraph; Graph.MultiGraph = MultiGraph; - Graph.MultiDirectedGraph = MultiDirectedGraph2; + Graph.MultiDirectedGraph = MultiDirectedGraph; Graph.MultiUndirectedGraph = MultiUndirectedGraph; Graph.InvalidArgumentsGraphError = InvalidArgumentsGraphError; Graph.NotFoundGraphError = NotFoundGraphError; @@ -42840,7 +42840,7 @@ async function main({ perennialBranches, skipSingleStacks }) { - const repoGraph = new import_graphology.MultiDirectedGraph(); + const repoGraph = new import_graphology.DirectedGraph(); repoGraph.mergeNode(mainBranch, { type: "perennial", ref: mainBranch diff --git a/src/main.ts b/src/main.ts index 4ff89ad..5a30e63 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,6 @@ import * as core from '@actions/core' import * as github from '@actions/github' -import { MultiDirectedGraph } from 'graphology' +import { DirectedGraph } from 'graphology' import { bfsFromNode, dfs, dfsFromNode } from 'graphology-traversal' import type { PullRequest, Context, StackNodeAttributes } from './types' import { remark } from './remark' @@ -13,7 +13,7 @@ export async function main({ perennialBranches, skipSingleStacks, }: Context) { - const repoGraph = new MultiDirectedGraph() + const repoGraph = new DirectedGraph() repoGraph.mergeNode(mainBranch, { type: 'perennial', @@ -69,7 +69,7 @@ export async function main({ const terminatingRefs = [mainBranch, ...perennialBranches] const getStackGraph = (pullRequest: PullRequest) => { - const stackGraph = repoGraph.copy() as MultiDirectedGraph + const stackGraph = repoGraph.copy() as DirectedGraph stackGraph.setNodeAttribute(pullRequest.head.ref, 'isCurrent', true) bfsFromNode( @@ -100,7 +100,7 @@ export async function main({ return stackGraph } - const getOutput = (graph: MultiDirectedGraph) => { + const getOutput = (graph: DirectedGraph) => { const lines: string[] = [] console.log(JSON.stringify(graph.inspect(), null, 2)) From e94cd9e66ebee3ac853fb3beef38c1a83fb681e1 Mon Sep 17 00:00:00 2001 From: Long Tran Date: Thu, 28 Nov 2024 00:32:23 +1100 Subject: [PATCH 30/31] fixes --- dist/index.js | 8 ++++---- src/main.ts | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/dist/index.js b/dist/index.js index 408846c..8b91d61 100644 --- a/dist/index.js +++ b/dist/index.js @@ -42913,12 +42913,12 @@ async function main({ }; const getOutput = (graph) => { const lines = []; - console.log(JSON.stringify(graph.inspect(), null, 2)); - (0, import_graphology_traversal.dfsFromNode)( + graph.someNode((node2, attributes) => { + console.log(node2, attributes); + }); + (0, import_graphology_traversal.dfs)( graph, - null, (_, stackNode, depth) => { - console.log(stackNode, depth); if (!stackNode.shouldPrint) return; const tabSize = depth * 2; diff --git a/src/main.ts b/src/main.ts index 5a30e63..88e2ffc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -103,13 +103,13 @@ export async function main({ const getOutput = (graph: DirectedGraph) => { const lines: string[] = [] - console.log(JSON.stringify(graph.inspect(), null, 2)) + graph.someNode((node, attributes) => { + console.log(node, attributes) + }) - dfsFromNode( + dfs( graph, - null, (_, stackNode, depth) => { - console.log(stackNode, depth) if (!stackNode.shouldPrint) return const tabSize = depth * 2 From fd0ba40d7320320f81b51c5dc8f3a1dc456cb659 Mon Sep 17 00:00:00 2001 From: Long Tran Date: Thu, 28 Nov 2024 09:53:10 +1100 Subject: [PATCH 31/31] fixes --- dist/index.js | 216 ++++++++++++++++++++++++++++++++++++++++++++-- package-lock.json | 13 +++ package.json | 1 + src/main.test.ts | 46 +++++++++- src/main.ts | 25 +++--- 5 files changed, 280 insertions(+), 21 deletions(-) diff --git a/dist/index.js b/dist/index.js index 8b91d61..ab90068 100644 --- a/dist/index.js +++ b/dist/index.js @@ -26871,6 +26871,208 @@ var require_graphology_traversal = __commonJS({ } }); +// node_modules/graphology-dag/has-cycle.js +var require_has_cycle = __commonJS({ + "node_modules/graphology-dag/has-cycle.js"(exports2, module2) { + var isGraph = require_is_graph(); + var WHITE = void 0; + var GREY = 0; + var BLACK = 1; + module2.exports = function hasCycle(graph) { + if (!isGraph(graph)) + throw new Error( + "graphology-dag/has-cycle: the given graph is not a valid graphology instance." + ); + if (graph.size === 0) + return false; + if (graph.selfLoopCount !== 0) + return true; + const labels = {}; + const stack = []; + function neighborCallback(neighbor) { + const neighborLabel = labels[neighbor]; + if (neighborLabel === WHITE) + stack.push(neighbor); + else if (neighborLabel === GREY) + return true; + return false; + } + return graph.someNode((node2) => { + if (labels[node2] === BLACK) + return false; + stack.push(node2); + while (stack.length !== 0) { + const current = stack[stack.length - 1]; + const currentLabel = labels[current]; + if (currentLabel !== GREY) { + labels[current] = GREY; + const shouldStop = graph.someOutboundNeighbor( + current, + neighborCallback + ); + if (shouldStop) + return true; + } else if (currentLabel === GREY) { + stack.pop(); + labels[current] = BLACK; + } + } + return false; + }); + }; + } +}); + +// node_modules/graphology-dag/will-create-cycle.js +var require_will_create_cycle = __commonJS({ + "node_modules/graphology-dag/will-create-cycle.js"(exports2, module2) { + var isGraph = require_is_graph(); + module2.exports = function willCreateCycle(graph, source, target) { + if (!isGraph(graph)) + throw new Error( + "graphology-dag/will-create-cycle: the given graph is not a valid graphology instance." + ); + source = "" + source; + target = "" + target; + if (source === target) + return true; + if (!graph.hasNode(source) || !graph.hasNode(target)) + return false; + if (graph.hasDirectedEdge(source, target)) + return false; + if (graph.hasDirectedEdge(target, source)) + return true; + const stack = graph.outNeighbors(target); + function push2(neighbor) { + stack.push(neighbor); + } + while (stack.length !== 0) { + const node2 = stack.pop(); + if (node2 === source) + return true; + graph.forEachOutNeighbor(node2, push2); + } + return false; + }; + } +}); + +// node_modules/graphology-dag/topological-sort.js +var require_topological_sort = __commonJS({ + "node_modules/graphology-dag/topological-sort.js"(exports2) { + var isGraph = require_is_graph(); + var FixedDeque = require_fixed_deque(); + function simpleInDegree(graph, node2) { + let degree = 0; + graph.forEachInNeighbor(node2, () => { + degree++; + }); + return degree; + } + function forEachNodeInTopologicalOrder(graph, callback) { + if (!isGraph(graph)) + throw new Error( + "graphology-dag/topological-sort: the given graph is not a valid graphology instance." + ); + if (graph.type === "undirected" || graph.undirectedSize !== 0) + throw new Error( + "graphology-dag/topological-sort: cannot work if graph is not directed." + ); + if (graph.order === 0) + return; + const queue = new FixedDeque(Array, graph.order); + const inDegrees = {}; + let total = 0; + graph.forEachNode((node2, attr) => { + const inDegree = graph.multi ? simpleInDegree(graph, node2) : graph.inDegree(node2); + if (inDegree === 0) { + queue.push([node2, attr, 0]); + } else { + inDegrees[node2] = inDegree; + total += inDegree; + } + }); + let currentGeneration = 0; + function neighborCallback(neighbor, attr) { + const neighborInDegree = --inDegrees[neighbor]; + total--; + if (neighborInDegree === 0) + queue.push([neighbor, attr, currentGeneration + 1]); + inDegrees[neighbor] = neighborInDegree; + } + while (queue.size !== 0) { + const [node2, attr, gen] = queue.shift(); + currentGeneration = gen; + callback(node2, attr, gen); + graph.forEachOutNeighbor(node2, neighborCallback); + } + if (total !== 0) + throw new Error( + "graphology-dag/topological-sort: given graph is not acyclic." + ); + } + function topologicalSort2(graph) { + if (!isGraph(graph)) + throw new Error( + "graphology-dag/topological-sort: the given graph is not a valid graphology instance." + ); + const sortedNodes = new Array(graph.order); + let i = 0; + forEachNodeInTopologicalOrder(graph, (node2) => { + sortedNodes[i++] = node2; + }); + return sortedNodes; + } + function forEachTopologicalGeneration(graph, callback) { + if (!isGraph(graph)) + throw new Error( + "graphology-dag/topological-generations: the given graph is not a valid graphology instance." + ); + if (graph.order === 0) + return; + let lastGenLevel = 0; + let lastGen = []; + forEachNodeInTopologicalOrder(graph, (node2, _, gen) => { + if (gen > lastGenLevel) { + callback(lastGen); + lastGenLevel = gen; + lastGen = []; + } + lastGen.push(node2); + }); + callback(lastGen); + } + function topologicalGenerations(graph) { + if (!isGraph(graph)) + throw new Error( + "graphology-dag/topological-generations: the given graph is not a valid graphology instance." + ); + const generations = []; + forEachTopologicalGeneration(graph, (generation) => { + generations.push(generation); + }); + return generations; + } + exports2.topologicalSort = topologicalSort2; + exports2.forEachNodeInTopologicalOrder = forEachNodeInTopologicalOrder; + exports2.topologicalGenerations = topologicalGenerations; + exports2.forEachTopologicalGeneration = forEachTopologicalGeneration; + } +}); + +// node_modules/graphology-dag/index.js +var require_graphology_dag = __commonJS({ + "node_modules/graphology-dag/index.js"(exports2) { + exports2.hasCycle = require_has_cycle(); + exports2.willCreateCycle = require_will_create_cycle(); + var sort = require_topological_sort(); + exports2.forEachNodeInTopologicalOrder = sort.forEachNodeInTopologicalOrder; + exports2.topologicalSort = sort.topologicalSort; + exports2.topologicalGenerations = sort.topologicalGenerations; + exports2.forEachTopologicalGeneration = sort.forEachTopologicalGeneration; + } +}); + // node_modules/extend/index.js var require_extend = __commonJS({ "node_modules/extend/index.js"(exports2, module2) { @@ -30716,6 +30918,7 @@ var core = __toESM(require_core()); var github = __toESM(require_github()); var import_graphology = __toESM(require_graphology_cjs()); var import_graphology_traversal = __toESM(require_graphology_traversal()); +var import_graphology_dag = __toESM(require_graphology_dag()); // node_modules/mdast-util-to-string/lib/index.js var emptyOptions = {}; @@ -42909,15 +43112,14 @@ async function main({ stackGraph2.dropNode(ref); } }); - return stackGraph2; + return import_graphology.DirectedGraph.from(stackGraph2.toJSON()); }; const getOutput = (graph) => { const lines = []; - graph.someNode((node2, attributes) => { - console.log(node2, attributes); - }); - (0, import_graphology_traversal.dfs)( + const rootRef = (0, import_graphology_dag.topologicalSort)(graph)[0]; + (0, import_graphology_traversal.dfsFromNode)( graph, + rootRef, (_, stackNode, depth) => { if (!stackNode.shouldPrint) return; @@ -42942,7 +43144,6 @@ async function main({ ); return lines.join("\n"); }; - const jobs = []; const stackGraph = getStackGraph(currentPullRequest); const shouldSkip = () => { const neighbors = stackGraph.neighbors(currentPullRequest.head.ref); @@ -42954,8 +43155,9 @@ async function main({ if (shouldSkip()) { return; } + const jobs = []; stackGraph.forEachNode((_, stackNode) => { - if (stackNode.type !== "pull-request" || !stackNode.shouldPrint || !stackNode.isCurrent) { + if (stackNode.type !== "pull-request" || !stackNode.shouldPrint) { return; } jobs.push(async () => { diff --git a/package-lock.json b/package-lock.json index 046f19e..1c80b02 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "@actions/exec": "^1.1.1", "@actions/github": "^6.0.0", "graphology": "^0.25.4", + "graphology-dag": "^0.4.1", "graphology-traversal": "^0.3.1", "remark": "^15.0.1", "remark-gfm": "^4.0.0", @@ -4596,6 +4597,18 @@ "graphology-types": ">=0.24.0" } }, + "node_modules/graphology-dag": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/graphology-dag/-/graphology-dag-0.4.1.tgz", + "integrity": "sha512-3ch9oOAnHZDoT043vyg7ukmSkKJ505nFzaHaYOn0IF2PgGo5VtIavyVK4UpbIa4tli3hhGm1ZTdBsubTmaxu/w==", + "dependencies": { + "graphology-utils": "^2.4.1", + "mnemonist": "^0.39.0" + }, + "peerDependencies": { + "graphology-types": ">=0.19.0" + } + }, "node_modules/graphology-indices": { "version": "0.17.0", "resolved": "https://registry.npmjs.org/graphology-indices/-/graphology-indices-0.17.0.tgz", diff --git a/package.json b/package.json index c9f504e..20a810a 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "@actions/exec": "^1.1.1", "@actions/github": "^6.0.0", "graphology": "^0.25.4", + "graphology-dag": "^0.4.1", "graphology-traversal": "^0.3.1", "remark": "^15.0.1", "remark-gfm": "^4.0.0", diff --git a/src/main.test.ts b/src/main.test.ts index 6587973..ee304b2 100644 --- a/src/main.test.ts +++ b/src/main.test.ts @@ -1,5 +1,6 @@ import { describe, it, beforeEach, expect, vi } from 'vitest' -import { updateDescription } from './main' +import { main, updateDescription } from './main' +import type { Octokit } from './types' beforeEach(() => { vi.unstubAllEnvs() @@ -52,3 +53,46 @@ describe('updateDescription', () => { expect(actual).toEqual(expected) }) }) + +describe('main', () => { + it('should work', async () => { + await main({ + octokit: {} as unknown as Octokit, + currentPullRequest: { + number: 361, + head: { + ref: 'test-branch', + }, + base: { + ref: 'document-setup', + }, + state: 'open', + }, + pullRequests: [ + // { + // number: 360, + // head: { + // ref: 'document-setup', + // }, + // base: { + // ref: 'main', + // }, + // state: 'open', + // }, + { + number: 361, + head: { + ref: 'test-branch', + }, + base: { + ref: 'document-setup', + }, + state: 'open', + }, + ], + mainBranch: 'main', + perennialBranches: [], + skipSingleStacks: false, + }) + }) +}) diff --git a/src/main.ts b/src/main.ts index 88e2ffc..3946d1b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,7 +1,8 @@ import * as core from '@actions/core' import * as github from '@actions/github' import { DirectedGraph } from 'graphology' -import { bfsFromNode, dfs, dfsFromNode } from 'graphology-traversal' +import { bfsFromNode,dfsFromNode } from 'graphology-traversal' +import { topologicalSort} from 'graphology-dag' import type { PullRequest, Context, StackNodeAttributes } from './types' import { remark } from './remark' @@ -97,18 +98,20 @@ export async function main({ } }) - return stackGraph + return DirectedGraph.from(stackGraph.toJSON()) } const getOutput = (graph: DirectedGraph) => { const lines: string[] = [] - graph.someNode((node, attributes) => { - console.log(node, attributes) - }) + // `dfs` is bugged and doesn't traverse in topological order. + // `dfsFromNode` does, so we'll do the topological sort ourselves + // start traversal from the root. + const rootRef = topologicalSort(graph)[0] - dfs( + dfsFromNode( graph, + rootRef, (_, stackNode, depth) => { if (!stackNode.shouldPrint) return @@ -141,8 +144,6 @@ export async function main({ return lines.join('\n') } - const jobs: Array<() => Promise> = [] - const stackGraph = getStackGraph(currentPullRequest) const shouldSkip = () => { @@ -162,12 +163,10 @@ export async function main({ return } + const jobs: Array<() => Promise> = [] + stackGraph.forEachNode((_, stackNode) => { - if ( - stackNode.type !== 'pull-request' || - !stackNode.shouldPrint || - !stackNode.isCurrent - ) { + if (stackNode.type !== 'pull-request' || !stackNode.shouldPrint) { return }