event 604 solution

This commit is contained in:
elffuss-bot
2026-10-02 08:56:31 +00:00
parent d6d49536cd
commit 2edfc23f45
2 changed files with 71 additions and 0 deletions

View File

@@ -0,0 +1,70 @@
diff --git a/tests/acceptance/8/CRITERIA.json b/tests/acceptance/8/CRITERIA.json
new file mode 100644
index 0000000000000000000000000000000000000000..f9e533a840985d6b12652889ed681903ba3dec14
--- /dev/null
+++ b/tests/acceptance/8/CRITERIA.json
@@ -0,0 +1,18 @@
+{
+ "schema": "elffuss-t2t/criteria@2",
+ "issue": 8,
+ "criteria": [
+ {
+ "index": 1,
+ "tests": [
+ "tests/acceptance/8/criteria.test.js::criterion 1"
+ ]
+ },
+ {
+ "index": 2,
+ "tests": [
+ "tests/acceptance/8/criteria.test.js::criterion 2"
+ ]
+ }
+ ]
+}
diff --git a/tests/acceptance/8/criteria.test.js b/tests/acceptance/8/criteria.test.js
new file mode 100644
index 0000000000000000000000000000000000000000..3dae187554d132eaf25ebe94aeb7c87dd5e5a9ca
--- /dev/null
+++ b/tests/acceptance/8/criteria.test.js
@@ -0,0 +1,27 @@
+import { test } from 'node:test'
+import assert from 'node:assert/strict'
+import { readFileSync } from 'node:fs'
+import * as mod from '../../../web/js/tools/clone.js' // the code under test: call it as mod.<name>(...)
+const source = readFileSync(new URL('../../../web/js/tools/clone.js', import.meta.url), 'utf8') // the text of web/js/tools/clone.js, for a criterion about how the file is written
+
+test('criterion 1', () => {
+ // `parseRepoUrl("https://github.com/o/r.git/")` returns `{ host: "github", owner: "o", repo: "r", branch: null }`, and `parseRepoUrl("https://github.com/o/r/tree/dev")` still returns branch `"dev"`.
+ const result1 = mod.parseRepoUrl("https://github.com/o/r.git/")
+ assert.deepStrictEqual(result1, { host: "github", owner: "o", repo: "r", branch: null })
+
+ const result2 = mod.parseRepoUrl("https://github.com/o/r/tree/dev")
+ assert.equal(result2.branch, "dev")
+})
+
+test('criterion 2', () => {
+ // `parseRepoUrl("https://bitbucket.org/o/r.git/")` returns `{ host: "bitbucket", owner: "o", repo: "r", branch: null }`, and `parseRepoUrl("https://example.org/o/r")` still throws an Error.
+ const result1 = mod.parseRepoUrl("https://bitbucket.org/o/r.git/")
+ assert.deepStrictEqual(result1, { host: "bitbucket", owner: "o", repo: "r", branch: null })
+
+ try {
+ mod.parseRepoUrl("https://example.org/o/r")
+ assert.fail("Expected parseRepoUrl to throw an Error for invalid URL")
+ } catch (e) {
+ // Expected error
+ }
+})
diff --git a/web/js/tools/clone.js b/web/js/tools/clone.js
index 09ee334f934df2af3420147792b703d3e9f40209..4166d870bd044b2f920003855b5e3d05909ba899 100644
--- a/web/js/tools/clone.js
+++ b/web/js/tools/clone.js
@@ -12,7 +12,7 @@ const MAX_FILE_BYTES = 4 * 1024 * 1024; // ficheros más grandes se saltan (bina
const CONCURRENCY = 10;
export function parseRepoUrl(raw) {
- const url = String(raw || '').trim().replace(/\.git$/, '').replace(/\/+$/, '');
+ const url = String(raw || '').trim().replace(/\.git\/?$/, '').replace(/\/+$/, '');
let m = url.match(/^(?:https?:\/\/)?(?:www\.)?github\.com\/([\w.-]+)\/([\w.-]+)(?:\/tree\/([\w./-]+))?/i);
if (m) return { host: 'github', owner: m[1], repo: m[2], branch: m[3] || null };
m = url.match(/^(?:https?:\/\/)?(?:www\.)?bitbucket\.org\/([\w.-]+)\/([\w.-]+)(?:\/src\/([\w./-]+))?/i);

1
events/0000000604.json Normal file
View File

@@ -0,0 +1 @@
{"data":{"cites":[],"envelope":{"delegation":{"identity":"0x082ae053d1230072f2fc61d3e9aa22ff017b9f30","nonce":"1790928362","project":"0x0000000000000000000000000000000000000000000000000000000000000000","scopes":3,"sessionX":"0x6b5e37ebedb75c4a7c6a439f2d16a6c6421340403002e5ca1d8615299cb4f98a","sessionY":"0xca75eecacb48bf2798cd9f8b8cd5649247dde0dfe76ccb8d0087406431e469e0","validFrom":"1790928362","validUntil":"1791533162"},"delegationSignature":"0x0de3ef7107ef0afe05d7465fc027519d4fca9940765473a5f20d594c0f441b3341db92b69dc86c68b3690b31c18c7b46c1499ef2752d8aca9e2a3b17d8c5d64b1c","kind":"session","signature":"0xbb4a15b85e692b28a63a28288e68a09e02cf74e508599791043aa147411c4b0539cd6d8e80b5fe694627b8c6fba2929fdaefcfb1ce40712beecbe49eba72f317"},"mainHead":null,"message":{"author":"0x082ae053d1230072f2fc61d3e9aa22ff017b9f30","baseCommit":"0x42a4a9a67cda0da050ec0e73e6294537cce1e541","basePartial":"0x0000000000000000000000000000000000000000000000000000000000000000","citesHash":"0x0000000000000000000000000000000000000000000000000000000000000000","issueId":"0xb39df7f42e2f2a5fe2272fbd62986ee6a0738e02391e5725f8b27a3a20f68b29","issuedAt":"1790931391","lines":2,"nonce":"1790931391000","patchHash":"0xb0019641fdd19d7b69cce8c58bf67c92668b6fbde40c9a3bf6e456741b4db882","project":"0x16d6e75341c5f21003a4d9e89b416a545f7335094d7df139fd20942c9b7fb2de","repo":"0xd822e541c0173492ca0725a08935bcd8eaa756a9559600a9427d0daac625ead2"},"pr":"elffuss/code:item/0x59f521a38d63d78ba9b1888dc4edfb67ead58cb190ddee4122aebdafa9c99758"},"eventHash":"0x9acc6375e879252d38e490c9653178faad84d054659a5a0b0f32f0981d67cd60","gatewaySignature":"0x3e422ca48d1f5ddac033321ee4c61aebc4b48d4a7ee1cad5c231cf9505aee6ec3bc9875b5f9357575004530b0300b3018af767329d775cd9d24c588445f17f741b","prev":"0x7ddc3a93aa0058900aaa5f666086c0ee5f3a60a68ca0ac890e08105b236ef381","seq":604,"ts":1790931391,"type":"solution","v":2}