Skip to content

Commit

Permalink
normalize github url
Browse files Browse the repository at this point in the history
  • Loading branch information
yesoreyeram committed May 25, 2021
1 parent d40f60c commit 9f2eec4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/app/InfinityProvider.ts
Original file line number Diff line number Diff line change
@@ -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) {}
Expand All @@ -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);
})
Expand Down
12 changes: 12 additions & 0 deletions src/app/utils.ts
Original file line number Diff line number Diff line change
@@ -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;
};

0 comments on commit 9f2eec4

Please sign in to comment.