mirror of
https://codeberg.org/keyoxide/doipjs.git
synced 2024-12-22 14:39:28 -07:00
fix: add support for different branch names (default to main)
This commit is contained in:
parent
002865f4c0
commit
65ca35f197
1 changed files with 7 additions and 16 deletions
|
@ -25,7 +25,7 @@ limitations under the License.
|
||||||
import * as E from '../enums.js'
|
import * as E from '../enums.js'
|
||||||
import { ServiceProvider } from '../serviceProvider.js'
|
import { ServiceProvider } from '../serviceProvider.js'
|
||||||
|
|
||||||
export const reURI = /^https:\/\/git\.sr\.ht\/~([^~/]*)\/([^/]*)\/?$/
|
export const reURI = /^https:\/\/git\.sr\.ht\/~([^~/]*)\/([^/]*)(\/tree\/([^/]*))?\/?/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @function
|
* @function
|
||||||
|
@ -33,7 +33,7 @@ export const reURI = /^https:\/\/git\.sr\.ht\/~([^~/]*)\/([^/]*)\/?$/
|
||||||
* @returns {ServiceProvider} The service provider information based on the claim URI
|
* @returns {ServiceProvider} The service provider information based on the claim URI
|
||||||
*/
|
*/
|
||||||
export function processURI (uri) {
|
export function processURI (uri) {
|
||||||
const match = uri.match(reURI)
|
const [, username, repo, , branch] = uri.match(reURI)
|
||||||
|
|
||||||
return new ServiceProvider({
|
return new ServiceProvider({
|
||||||
about: {
|
about: {
|
||||||
|
@ -42,8 +42,8 @@ export function processURI (uri) {
|
||||||
homepage: 'https://sourcehut.org'
|
homepage: 'https://sourcehut.org'
|
||||||
},
|
},
|
||||||
profile: {
|
profile: {
|
||||||
display: match[1],
|
display: username,
|
||||||
uri: `https://sr.ht/~${match[1]}`,
|
uri: `https://sr.ht/~${username}`,
|
||||||
qr: null
|
qr: null
|
||||||
},
|
},
|
||||||
claim: {
|
claim: {
|
||||||
|
@ -56,8 +56,7 @@ export function processURI (uri) {
|
||||||
fetcher: E.Fetcher.HTTP,
|
fetcher: E.Fetcher.HTTP,
|
||||||
accessRestriction: E.ProofAccessRestriction.NONE,
|
accessRestriction: E.ProofAccessRestriction.NONE,
|
||||||
data: {
|
data: {
|
||||||
// explicitly matching for `main` branch
|
url: `https://git.sr.ht/~${username}/${repo}/blob/${branch}/proof.md`,
|
||||||
url: `https://git.sr.ht/~${match[1]}/${match[2]}/blob/main/proof.md`,
|
|
||||||
format: E.ProofFormat.TEXT
|
format: E.ProofFormat.TEXT
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -85,20 +84,12 @@ export const tests = [
|
||||||
uri: 'https://git.sr.ht/~alice/keyoxide_proof/',
|
uri: 'https://git.sr.ht/~alice/keyoxide_proof/',
|
||||||
shouldMatch: true
|
shouldMatch: true
|
||||||
},
|
},
|
||||||
{
|
|
||||||
uri: 'https://domain.org/alice/keyoxide_proof',
|
|
||||||
shouldMatch: false
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
uri: 'https://git.sr.ht/~alice/proof_repo/tree/master',
|
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',
|
uri: 'https://domain.org/alice/keyoxide_proof',
|
||||||
shouldMatch: false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
uri: 'https://git.sr.ht/~alice/proof_repo/blob/main/proof.md',
|
|
||||||
shouldMatch: false
|
shouldMatch: false
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in a new issue