fix: add support for different branch names (default to main)

This commit is contained in:
quaff 2024-10-16 00:48:10 -07:00
parent 002865f4c0
commit 65ca35f197
No known key found for this signature in database
GPG key ID: E1BF1FDE24A291D4

View file

@ -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
}
]