Skip to content

Commit 9a46864

Browse files
Merge branch 'master' into feature/gomory-hu-tree
2 parents f3c544b + f352f81 commit 9a46864

File tree

127 files changed

+8502
-557
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+8502
-557
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
build:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v5
11+
- uses: actions/checkout@v6
1212
- name: Set up JDK
1313
uses: actions/setup-java@v5
1414
with:

.github/workflows/clang-format-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212

1313
steps:
14-
- uses: actions/checkout@v5
14+
- uses: actions/checkout@v6
1515
- uses: DoozyX/[email protected]
1616
with:
1717
source: './src'
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
name: Close stale PRs with failed workflows
2+
3+
on:
4+
schedule:
5+
- cron: '0 3 * * *' # runs daily at 03:00 UTC
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
issues: write
11+
pull-requests: write
12+
13+
jobs:
14+
close-stale:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Close stale PRs
18+
uses: actions/github-script@v8
19+
with:
20+
github-token: ${{ secrets.GITHUB_TOKEN }}
21+
script: |
22+
const mainBranches = ['main', 'master'];
23+
const cutoffDays = 14;
24+
const cutoff = new Date();
25+
cutoff.setDate(cutoff.getDate() - cutoffDays);
26+
27+
console.log(`Checking PRs older than: ${cutoff.toISOString()}`);
28+
29+
try {
30+
const { data: prs } = await github.rest.pulls.list({
31+
owner: context.repo.owner,
32+
repo: context.repo.repo,
33+
state: 'open',
34+
sort: 'updated',
35+
direction: 'asc',
36+
per_page: 100
37+
});
38+
39+
console.log(`Found ${prs.length} open PRs to check`);
40+
41+
for (const pr of prs) {
42+
try {
43+
const updated = new Date(pr.updated_at);
44+
45+
if (updated > cutoff) {
46+
console.log(`⏩ Skipping PR #${pr.number} - updated recently`);
47+
continue;
48+
}
49+
50+
console.log(`🔍 Checking PR #${pr.number}: "${pr.title}"`);
51+
52+
// Get commits
53+
const commits = await github.paginate(github.rest.pulls.listCommits, {
54+
owner: context.repo.owner,
55+
repo: context.repo.repo,
56+
pull_number: pr.number,
57+
per_page: 100
58+
});
59+
60+
const meaningfulCommits = commits.filter(c => {
61+
const msg = c.commit.message.toLowerCase();
62+
const date = new Date(c.commit.committer.date);
63+
const isMergeFromMain = mainBranches.some(branch =>
64+
msg.startsWith(`merge branch '${branch}'`) ||
65+
msg.includes(`merge remote-tracking branch '${branch}'`)
66+
);
67+
68+
return !isMergeFromMain && date > cutoff;
69+
});
70+
71+
// Get checks with error handling
72+
let hasFailedChecks = false;
73+
let allChecksCompleted = false;
74+
let hasChecks = false;
75+
76+
try {
77+
const { data: checks } = await github.rest.checks.listForRef({
78+
owner: context.repo.owner,
79+
repo: context.repo.repo,
80+
ref: pr.head.sha
81+
});
82+
83+
hasChecks = checks.check_runs.length > 0;
84+
hasFailedChecks = checks.check_runs.some(c => c.conclusion === 'failure');
85+
allChecksCompleted = checks.check_runs.every(c =>
86+
c.status === 'completed' || c.status === 'skipped'
87+
);
88+
} catch (error) {
89+
console.log(`⚠️ Could not fetch checks for PR #${pr.number}: ${error.message}`);
90+
}
91+
92+
// Get workflow runs with error handling
93+
let hasFailedWorkflows = false;
94+
let allWorkflowsCompleted = false;
95+
let hasWorkflows = false;
96+
97+
try {
98+
const { data: runs } = await github.rest.actions.listWorkflowRuns({
99+
owner: context.repo.owner,
100+
repo: context.repo.repo,
101+
head_sha: pr.head.sha,
102+
per_page: 50
103+
});
104+
105+
hasWorkflows = runs.workflow_runs.length > 0;
106+
hasFailedWorkflows = runs.workflow_runs.some(r => r.conclusion === 'failure');
107+
allWorkflowsCompleted = runs.workflow_runs.every(r =>
108+
['completed', 'skipped', 'cancelled'].includes(r.status)
109+
);
110+
111+
console.log(`PR #${pr.number}: ${runs.workflow_runs.length} workflow runs found`);
112+
113+
} catch (error) {
114+
console.log(`⚠️ Could not fetch workflow runs for PR #${pr.number}: ${error.message}`);
115+
}
116+
117+
console.log(`PR #${pr.number}: ${meaningfulCommits.length} meaningful commits`);
118+
console.log(`Checks - has: ${hasChecks}, failed: ${hasFailedChecks}, completed: ${allChecksCompleted}`);
119+
console.log(`Workflows - has: ${hasWorkflows}, failed: ${hasFailedWorkflows}, completed: ${allWorkflowsCompleted}`);
120+
121+
// Combine conditions - only consider if we actually have checks/workflows
122+
const hasAnyFailure = (hasChecks && hasFailedChecks) || (hasWorkflows && hasFailedWorkflows);
123+
const allCompleted = (!hasChecks || allChecksCompleted) && (!hasWorkflows || allWorkflowsCompleted);
124+
125+
if (meaningfulCommits.length === 0 && hasAnyFailure && allCompleted) {
126+
console.log(`✅ Closing PR #${pr.number} (${pr.title})`);
127+
128+
await github.rest.issues.createComment({
129+
owner: context.repo.owner,
130+
repo: context.repo.repo,
131+
issue_number: pr.number,
132+
body: `This pull request has been automatically closed because its workflows or checks failed and it has been inactive for more than ${cutoffDays} days. Please fix the workflows and reopen if you'd like to continue. Merging from main/master alone does not count as activity.`
133+
});
134+
135+
await github.rest.pulls.update({
136+
owner: context.repo.owner,
137+
repo: context.repo.repo,
138+
pull_number: pr.number,
139+
state: 'closed'
140+
});
141+
142+
console.log(`✅ Successfully closed PR #${pr.number}`);
143+
} else {
144+
console.log(`⏩ Not closing PR #${pr.number} - conditions not met`);
145+
}
146+
147+
} catch (prError) {
148+
console.error(`❌ Error processing PR #${pr.number}: ${prError.message}`);
149+
continue;
150+
}
151+
}
152+
153+
} catch (error) {
154+
console.error(`❌ Fatal error: ${error.message}`);
155+
throw error;
156+
}

.github/workflows/codeql.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121

2222
steps:
2323
- name: Checkout repository
24-
uses: actions/checkout@v5
24+
uses: actions/checkout@v6
2525

2626
- name: Set up JDK
2727
uses: actions/setup-java@v5
@@ -52,7 +52,7 @@ jobs:
5252

5353
steps:
5454
- name: Checkout repository
55-
uses: actions/checkout@v5
55+
uses: actions/checkout@v6
5656

5757
- name: Initialize CodeQL
5858
uses: github/codeql-action/init@v4

.github/workflows/infer.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
run_infer:
1616
runs-on: ubuntu-latest
1717
steps:
18-
- uses: actions/checkout@v5
18+
- uses: actions/checkout@v6
1919

2020
- name: Set up JDK
2121
uses: actions/setup-java@v5
@@ -44,7 +44,7 @@ jobs:
4444
cd ..
4545
git clone https://github.com/facebook/infer.git
4646
cd infer
47-
git checkout 01aaa268f9d38723ba69c139e10f9e2a04b40b1c
47+
git checkout 02c2c43b71e4c5110c0be841e66153942fda06c9
4848
./build-infer.sh java
4949
cp -r infer ../Java
5050

.github/workflows/project_structure.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
check_structure:
1616
runs-on: ubuntu-latest
1717
steps:
18-
- uses: actions/checkout@v5
18+
- uses: actions/checkout@v6
1919
- uses: actions/setup-python@v6
2020
with:
2121
python-version: '3.13'

.github/workflows/update-directorymd.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Generate Directory Markdown
1+
name: Generate Directory Markdown
22

33
on:
44
push:
@@ -14,7 +14,9 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- name: Checkout Repository
17-
uses: actions/checkout@v5
17+
uses: actions/checkout@v6
18+
with:
19+
persist-credentials: false
1820

1921
- name: Run Directory Tree Generator
2022
uses: DenizAltunkapan/directory-tree-generator@v2

.inferconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
{
22
"report-block-list-path-regex": [
33
"src/main/java/com/thealgorithms/ciphers/a5/CompositeLFSR.java",
4+
"src/main/java/com/thealgorithms/compression/ArithmeticCoding.java",
5+
"src/main/java/com/thealgorithms/datastructures/caches/FIFOCache.java",
46
"src/main/java/com/thealgorithms/datastructures/crdt/GCounter.java",
57
"src/main/java/com/thealgorithms/datastructures/crdt/PNCounter.java",
68
"src/main/java/com/thealgorithms/datastructures/graphs/KahnsAlgorithm.java",
79
"src/main/java/com/thealgorithms/datastructures/heaps/GenericHeap.java",
810
"src/main/java/com/thealgorithms/datastructures/lists/DoublyLinkedList.java",
911
"src/main/java/com/thealgorithms/datastructures/trees/CreateBinaryTreeFromInorderPreorder.java",
1012
"src/main/java/com/thealgorithms/divideandconquer/ClosestPair.java",
13+
"src/main/java/com/thealgorithms/dynamicprogramming/DamerauLevenshteinDistance.java",
1114
"src/main/java/com/thealgorithms/dynamicprogramming/Fibonacci.java",
1215
"src/main/java/com/thealgorithms/maths/SimpsonIntegration.java",
1316
"src/main/java/com/thealgorithms/others/Dijkstra.java",
1417
"src/main/java/com/thealgorithms/sorts/TopologicalSort.java",
1518
"src/main/java/com/thealgorithms/strings/AhoCorasick.java",
19+
"src/test/java/com/thealgorithms/compression/ShannonFanoTest.java",
1620
"src/test/java/com/thealgorithms/datastructures/caches/LRUCacheTest.java",
1721
"src/test/java/com/thealgorithms/datastructures/lists/SkipListTest.java",
1822
"src/test/java/com/thealgorithms/datastructures/trees/KDTreeTest.java",
1923
"src/test/java/com/thealgorithms/datastructures/trees/LazySegmentTreeTest.java",
24+
"src/test/java/com/thealgorithms/others/HuffmanTest.java",
2025
"src/test/java/com/thealgorithms/searches/QuickSelectTest.java",
2126
"src/test/java/com/thealgorithms/stacks/PostfixToInfixTest.java",
2227
"src/test/java/com/thealgorithms/strings/HorspoolSearchTest.java"

0 commit comments

Comments
 (0)