Skip to content

Commit 886cb27

Browse files
wip
1 parent 563fbc1 commit 886cb27

File tree

5 files changed

+141
-6
lines changed

5 files changed

+141
-6
lines changed

cli/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
],
2121
"dependencies": {
2222
"@reduxjs/toolkit": "^2.2.3",
23+
"axios": "0.26.1",
24+
"axios-hooks": "^3.0.1",
25+
"axios-retry": "^3.8.1",
2326
"dockerode": "^4.0.2",
2427
"dockerode-compose": "^1.4.0",
2528
"ink": "^4.4.1",

cli/source/app.tsx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,20 @@ import { useSelector, store, useDispatch } from './store/index.js';
2121
import { getLineLimit } from './utils/line-limit.js';
2222
import { runCommand } from './utils/run-command.js';
2323
import CircularBuffer from './utils/circularBuffer.js';
24+
import { isLocalBranchBehindRemote } from './utils/version_checker.js';
2425

2526
const CliUi = () => {
2627
const dispatch = useDispatch();
2728

29+
console.log("HELLO BHAI")
2830
const logSource = useSelector((state) => state.app.logSource);
2931
const logsStream = useSelector((state) => state.app.logsStream);
3032
const readyServices = useSelector((state) => state.app.readyServices);
3133
const appState = useSelector((state) => state.app.appState);
3234
useLogsFromAllSources();
3335

3436
const [retryToggle, setRetryToggle] = useState<Boolean>(false);
37+
const [isUpdateAvailable, setIsUpdateAvailable] = useState<Boolean>(false);
3538

3639
const { exit } = useApp();
3740

@@ -90,6 +93,12 @@ const CliUi = () => {
9093
}, 200);
9194
}, [dispatch, runCommandOpts]);
9295

96+
const handleVersionUpdates = useCallback(async () => {
97+
await isLocalBranchBehindRemote().then((res) => {
98+
setIsUpdateAvailable(res);
99+
});
100+
}, [setIsUpdateAvailable]);
101+
93102
useEffect(() => {
94103
if (appState !== AppStates.TERMINATED) return;
95104
exit();
@@ -118,7 +127,12 @@ const CliUi = () => {
118127
handleExit();
119128
}
120129
});
121-
130+
console.log("SAMADS ESHAAN 1")
131+
useEffect(() => {
132+
handleVersionUpdates();
133+
console.log("SAMADS ESHAAN 2")
134+
}, [handleVersionUpdates]);
135+
console.log("SAMADS ESHAAN 3")
122136
useEffect(() => {
123137
const { process, promise } = runCommand(
124138
'docker-compose',
@@ -198,6 +212,8 @@ const CliUi = () => {
198212
() => logsStream.map((l) => transformLogToNode(l)),
199213
[logsStream]
200214
);
215+
216+
201217
return (
202218
<>
203219
<Static items={logsStreamNodes} style={{ flexDirection: 'column' }}>
@@ -345,8 +361,16 @@ const CliUi = () => {
345361
<Text bold color="red">
346362
[x]
347363
</Text>{' '}
348-
exit
364+
ma chudalo
349365
</Text>
366+
{isUpdateAvailable && (
367+
<>
368+
<Newline />
369+
<Text bold color="yellow">
370+
⚠️ masti main branch is behind remote. pull and rebase
371+
</Text>
372+
</>
373+
)}
350374
</Box>
351375
);
352376
case AppStates.TEARDOWN:
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import axios from 'axios';
2+
import { execSync } from 'child_process';
3+
4+
const githubOrgName = 'middlewarehq';
5+
const githubRepoName = 'middleware';
6+
7+
type GitHubCommit = {
8+
sha: string;
9+
commit: {
10+
author: {
11+
name: string;
12+
email: string;
13+
date: string;
14+
};
15+
message: string;
16+
};
17+
};
18+
19+
const getLatestCommitTimestamp = () => {
20+
const commitSHA = execSync('git rev-parse main').toString().trim();
21+
const commitTimestamp = execSync(`git show -s --format=%cI ${commitSHA}`)
22+
.toString()
23+
.trim();
24+
return commitTimestamp;
25+
};
26+
27+
async function fetchLatestGitHubCommit(): Promise<GitHubCommit> {
28+
const apiUrl = `https://api.github.com/repos/${githubOrgName}/${githubRepoName}/commits`;
29+
const response = await axios.get<GitHubCommit[]>(apiUrl);
30+
const latestCommit = response.data[0];
31+
return latestCommit as GitHubCommit;
32+
}
33+
34+
export async function isLocalBranchBehindRemote(): Promise<Boolean> {
35+
const commitTimestamp = getLatestCommitTimestamp();
36+
const latestGithubCommit = await fetchLatestGitHubCommit();
37+
38+
const localCommitTimestamp = new Date(commitTimestamp);
39+
const latestRemoteCommitDate = new Date(
40+
latestGithubCommit.commit.author.date
41+
);
42+
43+
console.log('samads logs', { latestRemoteCommitDate, localCommitTimestamp });
44+
return latestRemoteCommitDate > localCommitTimestamp;
45+
}

cli/tsconfig.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"allowJs": true,
55
"allowSyntheticDefaultImports": true,
66
"jsx": "react-jsx",
7-
"module": "Node16",
8-
"moduleResolution": "Node16",
7+
"module": "esnext",
8+
"moduleResolution": "node",
99
"moduleDetection": "force",
1010
"target": "ES2022",
1111
"lib": [
@@ -28,7 +28,7 @@
2828
"useDefineForClassFields": true,
2929
"forceConsistentCasingInFileNames": true,
3030
"skipLibCheck": true,
31-
"strictNullChecks": true
31+
"strictNullChecks": true,
3232
},
3333
"include": ["source"],
3434
}

cli/yarn.lock

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@
3838
js-tokens "^4.0.0"
3939
picocolors "^1.0.0"
4040

41+
42+
version "7.18.9"
43+
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.18.9.tgz#b4fcfce55db3d2e5e080d2490f608a3b9f407f4a"
44+
integrity sha512-lkqXDcvlFT5rvEjiu6+QYO+1GXrEHRo2LOtS7E4GtX5ESIZOgepqsZBVIj6Pv+a6zqsya9VCgiK1KAK4BvJDAw==
45+
dependencies:
46+
regenerator-runtime "^0.13.4"
47+
48+
"@babel/runtime@^7.15.4":
49+
version "7.24.7"
50+
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.24.7.tgz#f4f0d5530e8dbdf59b3451b9b3e594b6ba082e12"
51+
integrity sha512-UwgBRMjJP+xv857DCngvqXI3Iq6J4v0wXmwc6sapg+zyhbwmQX67LUEFrkK5tbyJ30jGuG3ZvWpBiB9LCy1kWw==
52+
dependencies:
53+
regenerator-runtime "^0.14.0"
54+
4155
"@balena/dockerignore@^1.0.2":
4256
version "1.0.2"
4357
resolved "https://registry.yarnpkg.com/@balena/dockerignore/-/dockerignore-1.0.2.tgz#9ffe4726915251e8eb69f44ef3547e0da2c03e0d"
@@ -660,6 +674,30 @@ available-typed-arrays@^1.0.7:
660674
dependencies:
661675
possible-typed-array-names "^1.0.0"
662676

677+
axios-hooks@^3.0.1:
678+
version "3.1.5"
679+
resolved "https://registry.yarnpkg.com/axios-hooks/-/axios-hooks-3.1.5.tgz#f1747244379c209567a5f2b73b4b5c59d7199bf2"
680+
integrity sha512-mU4WZ9c6YiOTxgTIKbswoHvb/b9fWXa2FxNFKI/hVcfD9Qemz1r9KLfRSVZf1GZg8nFry7oTM5gxNmPSn5PG0Q==
681+
dependencies:
682+
"@babel/runtime" "7.18.9"
683+
dequal "2.0.3"
684+
lru-cache "6.0.0"
685+
686+
axios-retry@^3.8.1:
687+
version "3.9.1"
688+
resolved "https://registry.yarnpkg.com/axios-retry/-/axios-retry-3.9.1.tgz#c8924a8781c8e0a2c5244abf773deb7566b3830d"
689+
integrity sha512-8PJDLJv7qTTMMwdnbMvrLYuvB47M81wRtxQmEdV5w4rgbTXTt+vtPkXwajOfOdSyv/wZICJOC+/UhXH4aQ/R+w==
690+
dependencies:
691+
"@babel/runtime" "^7.15.4"
692+
is-retry-allowed "^2.2.0"
693+
694+
695+
version "0.26.1"
696+
resolved "https://registry.yarnpkg.com/axios/-/axios-0.26.1.tgz#1ede41c51fcf51bbbd6fd43669caaa4f0495aaa9"
697+
integrity sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==
698+
dependencies:
699+
follow-redirects "^1.14.8"
700+
663701
balanced-match@^1.0.0:
664702
version "1.0.2"
665703
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee"
@@ -1060,6 +1098,11 @@ define-properties@^1.1.3, define-properties@^1.2.0, define-properties@^1.2.1:
10601098
has-property-descriptors "^1.0.0"
10611099
object-keys "^1.1.1"
10621100

1101+
1102+
version "2.0.3"
1103+
resolved "https://registry.yarnpkg.com/dequal/-/dequal-2.0.3.tgz#2644214f1997d39ed0ee0ece72335490a7ac67be"
1104+
integrity sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==
1105+
10631106
diff@^4.0.1:
10641107
version "4.0.2"
10651108
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
@@ -1562,6 +1605,11 @@ flatted@^3.2.9:
15621605
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.3.1.tgz#21db470729a6734d4997002f439cb308987f567a"
15631606
integrity sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==
15641607

1608+
follow-redirects@^1.14.8:
1609+
version "1.15.6"
1610+
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.6.tgz#7f815c0cda4249c74ff09e95ef97c23b5fd0399b"
1611+
integrity sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==
1612+
15651613
for-each@^0.3.3:
15661614
version "0.3.3"
15671615
resolved "https://registry.yarnpkg.com/for-each/-/for-each-0.3.3.tgz#69b447e88a0a5d32c3e7084f3f1710034b21376e"
@@ -2050,6 +2098,11 @@ is-regex@^1.1.4:
20502098
call-bind "^1.0.2"
20512099
has-tostringtag "^1.0.0"
20522100

2101+
is-retry-allowed@^2.2.0:
2102+
version "2.2.0"
2103+
resolved "https://registry.yarnpkg.com/is-retry-allowed/-/is-retry-allowed-2.2.0.tgz#88f34cbd236e043e71b6932d09b0c65fb7b4d71d"
2104+
integrity sha512-XVm7LOeLpTW4jV19QSH38vkswxoLud8sQ57YwJVTPWdiaI9I8keEhGFpBlslyVsgdQy4Opg8QOLb8YRgsyZiQg==
2105+
20532106
is-set@^2.0.3:
20542107
version "2.0.3"
20552108
resolved "https://registry.yarnpkg.com/is-set/-/is-set-2.0.3.tgz#8ab209ea424608141372ded6e0cb200ef1d9d01d"
@@ -2259,7 +2312,7 @@ loose-envify@^1.1.0, loose-envify@^1.4.0:
22592312
dependencies:
22602313
js-tokens "^3.0.0 || ^4.0.0"
22612314

2262-
lru-cache@^6.0.0:
2315+
lru-cache@6.0.0, lru-cache@^6.0.0:
22632316
version "6.0.0"
22642317
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-6.0.0.tgz#6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94"
22652318
integrity sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==
@@ -2835,6 +2888,16 @@ reflect.getprototypeof@^1.0.4:
28352888
globalthis "^1.0.3"
28362889
which-builtin-type "^1.1.3"
28372890

2891+
regenerator-runtime@^0.13.4:
2892+
version "0.13.11"
2893+
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz#f6dca3e7ceec20590d07ada785636a90cdca17f9"
2894+
integrity sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==
2895+
2896+
regenerator-runtime@^0.14.0:
2897+
version "0.14.1"
2898+
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz#356ade10263f685dda125100cd862c1db895327f"
2899+
integrity sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==
2900+
28382901
regexp.prototype.flags@^1.5.2:
28392902
version "1.5.2"
28402903
resolved "https://registry.yarnpkg.com/regexp.prototype.flags/-/regexp.prototype.flags-1.5.2.tgz#138f644a3350f981a858c44f6bb1a61ff59be334"

0 commit comments

Comments
 (0)