From 65ca35f19721cbb5bf7bb3fd052e672f7ddff426 Mon Sep 17 00:00:00 2001 From: quaff Date: Wed, 16 Oct 2024 00:48:10 -0700 Subject: [PATCH] fix: add support for different branch names (default to main) --- src/serviceProviders/sourcehut.js | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/serviceProviders/sourcehut.js b/src/serviceProviders/sourcehut.js index 612ee85..a2f8610 100644 --- a/src/serviceProviders/sourcehut.js +++ b/src/serviceProviders/sourcehut.js @@ -25,7 +25,7 @@ limitations under the License. import * as E from '../enums.js' import { ServiceProvider } from '../serviceProvider.js' -export const reURI = /^https:\/\/git\.sr\.ht\/~([^~/]*)\/([^/]*)\/?$/ +export const reURI = /^https:\/\/git\.sr\.ht\/~([^~/]*)\/([^/]*)(\/tree\/([^/]*))?\/?/ /** * @function @@ -33,7 +33,7 @@ export const reURI = /^https:\/\/git\.sr\.ht\/~([^~/]*)\/([^/]*)\/?$/ * @returns {ServiceProvider} The service provider information based on the claim URI */ export function processURI (uri) { - const match = uri.match(reURI) + const [, username, repo, , branch] = uri.match(reURI) return new ServiceProvider({ about: { @@ -42,8 +42,8 @@ export function processURI (uri) { homepage: 'https://sourcehut.org' }, profile: { - display: match[1], - uri: `https://sr.ht/~${match[1]}`, + display: username, + uri: `https://sr.ht/~${username}`, qr: null }, claim: { @@ -56,8 +56,7 @@ export function processURI (uri) { fetcher: E.Fetcher.HTTP, accessRestriction: E.ProofAccessRestriction.NONE, data: { - // explicitly matching for `main` branch - url: `https://git.sr.ht/~${match[1]}/${match[2]}/blob/main/proof.md`, + url: `https://git.sr.ht/~${username}/${repo}/blob/${branch}/proof.md`, format: E.ProofFormat.TEXT } }, @@ -85,20 +84,12 @@ export const tests = [ uri: 'https://git.sr.ht/~alice/keyoxide_proof/', shouldMatch: true }, - { - uri: 'https://domain.org/alice/keyoxide_proof', - shouldMatch: false - }, { uri: 'https://git.sr.ht/~alice/proof_repo/tree/master', - shouldMatch: false + shouldMatch: true }, { - uri: 'https://git.sr.ht/~alice/proof_repo/blob/master/proof.md', - shouldMatch: false - }, - { - uri: 'https://git.sr.ht/~alice/proof_repo/blob/main/proof.md', + uri: 'https://domain.org/alice/keyoxide_proof', shouldMatch: false } ]