Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tranhl committed Nov 27, 2024
1 parent e94cd9e commit fd0ba40
Show file tree
Hide file tree
Showing 5 changed files with 280 additions and 21 deletions.
216 changes: 209 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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 () => {
Expand Down
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
46 changes: 45 additions & 1 deletion src/main.test.ts
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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,
})
})
})
Loading

0 comments on commit fd0ba40

Please sign in to comment.