From 770aa731927285108ea3bb11c892626c76cfaee5 Mon Sep 17 00:00:00 2001 From: Juri Leino Date: Tue, 17 Oct 2023 15:26:20 +0200 Subject: [PATCH] feat(package): add commit info to raw list output `xst package list --raw` output has a new entry for each package. `commit` is either `null` or, when repo:meta/@commit-id is found an object with - **id**: the value of @commit-id, the hash from which this XAR was built - **time**: the value of @commit-time --- modules/list-packages.xq | 11 +++++++++++ spec/fixtures/test-app.xar | Bin 1145 -> 1207 bytes spec/tests/package/list.js | 21 ++++++++++++++++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/modules/list-packages.xq b/modules/list-packages.xq index 0edd1d7..e8baf16 100644 --- a/modules/list-packages.xq +++ b/modules/list-packages.xq @@ -84,6 +84,7 @@ function local:repo($package-uri as xs:string) as map(*) { return map { + "commit": local:commit-info($repo/repo:meta), "website": $repo//repo:website/text(), "description": $repo//repo:description/text(), "license": $repo//repo:license/text(), @@ -94,6 +95,16 @@ function local:repo($package-uri as xs:string) as map(*) { } }; +declare +function local:commit-info ($meta as element(repo:meta)) as map(*)? { + if (exists($meta/@commit-id)) then ( + map { + "id": $meta/@commit-id/string(), + "time": $meta/@commit-time/string() + } + ) else () +}; + declare function local:get-deployment-date ($expath, $repo) { let $doc := diff --git a/spec/fixtures/test-app.xar b/spec/fixtures/test-app.xar index cfeed2630d7f20ea6e220c6f8520ae59cd54dcf3..b0bb4566fd582ca205f3c57fd89e7270e2bfef11 100644 GIT binary patch delta 499 zcmey#v7M7Qz?+#xgn@y9gTbb)dm^t2$CP5zl&L^G(ek7wP$(?%-4w?#pn^=WA{mCv zyp+@my^6xn5KabWkm6}Tyjh!(g|U8dSz!2irSo%t1C{P#1eqzrP?TDbuUC-$=+$A71Nt>5lA$#<5WMSHivPm_NiIh9ay;NJZ>7tKl$xvRHy!nVq8YWvQoVaby3kQePxrn8ybI+kZc z{N?vu?R=JgeQT$`xPGo$GGNnR3GSx+0B=SnIc9hiOg3gVVgUu~>|Ns42J)~U4t#|J0$BCD_KFBq=NvBq?EweK*xW~>V%#u{U|De;-#b*`P z@<$k1M@w(q7w%p);j@q9VW-VsJwvxR{m_rp*vq@QtzY|ljOMk2pXPKgofUg(&0>?9 z&vzzDe4Y5A$S(7Th~(9I%M)gYeMpN@;axp}H_6Gl>9tY!h6|mX^~?58 p.abbrev === 'test-app') + st.equal(filtered.length, 1) + const packageInfo = filtered.pop() + st.ok(packageInfo.commit) + st.equal(packageInfo.commit.id, 'e039b2e12f9882375701c7cfd58f5ee32fd7bbd4') + st.equal(packageInfo.commit.time, '1674564361') + st.end() + }) + t.teardown(cleanup) }) @@ -211,7 +228,9 @@ test('error', async function (t) { const { stderr, stdout } = await run('xst', ['pkg', 'ls', '-a', '-l'], asAdmin) if (stdout) { t.fail(stdout) + t.end() return } - t.ok(stderr, stderr) + t.equal(stderr, 'Arguments a and l are mutually exclusive\n') + t.end() })