From 9f2eec4336f860771e564a31fb924870a944e3b3 Mon Sep 17 00:00:00 2001 From: Sriram Date: Wed, 26 May 2021 00:18:49 +0100 Subject: [PATCH] normalize github url --- src/app/InfinityProvider.ts | 7 +++++-- src/app/utils.ts | 12 ++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 src/app/utils.ts diff --git a/src/app/InfinityProvider.ts b/src/app/InfinityProvider.ts index c161926f..18dcb28f 100644 --- a/src/app/InfinityProvider.ts +++ b/src/app/InfinityProvider.ts @@ -1,7 +1,8 @@ +import { getTemplateSrv } from '@grafana/runtime'; import { CSVParser, JSONParser, XMLParser, HTMLParser } from './parsers'; import { InfinityQuery, InfinityQuerySources, InfinityQueryType } from '../types'; import { Datasource } from './../datasource'; -import { getTemplateSrv } from '@grafana/runtime'; +import { normalizeURL } from './utils'; export class InfinityProvider { constructor(private target: InfinityQuery, private datasource: Datasource) {} @@ -25,8 +26,10 @@ export class InfinityProvider { } private fetchResults() { return new Promise((resolve, reject) => { + const target = this.target; + target.url = normalizeURL(target.url); this.datasource - .postResource('proxy', this.target) + .postResource('proxy', target) .then(res => { resolve(res); }) diff --git a/src/app/utils.ts b/src/app/utils.ts new file mode 100644 index 00000000..ba252e94 --- /dev/null +++ b/src/app/utils.ts @@ -0,0 +1,12 @@ +export const normalizeURL = (url: string): string => { + if (url.startsWith('https://github.com')) { + return url + .replace('https://github.com', 'https://raw.githubusercontent.com') + .split('/') + .filter((item, index) => { + return !(item === 'blob' && index === 5); + }) + .join('/'); + } + return url; +};