Use graphql in GitHubClient and misc fixes (#8)

* Use graphql in GitHubClient

* Replace usage of Array.find with _.find
This commit is contained in:
Tanuj Mittal
2020-06-05 12:22:41 -07:00
committed by GitHub
parent e9d3160b57
commit aa8236666e
24 changed files with 761 additions and 657 deletions

View File

@@ -7,6 +7,10 @@ export class GitHubUtils {
// Custom scheme for github content
private static readonly ContentUriPattern = /github:\/\/([^/]*)\/([^/]*)\/([^?]*)\?ref=(.*)/;
// https://github.com/<owner>/<repo>/blob/<branch>/<path>
// We need to support this until we move to newer scheme for quickstarts
private static readonly LegacyContentUriPattern = /https:\/\/github.com\/([^/]*)\/([^/]*)\/blob\/([^/]*)\/([^?]*)/;
public static toRepoFullName(owner: string, repo: string): string {
return `${owner}/${repo}`;
}
@@ -27,7 +31,7 @@ export class GitHubUtils {
public static fromContentUri(
contentUri: string
): undefined | { owner: string; repo: string; branch: string; path: string } {
const matches = contentUri.match(GitHubUtils.ContentUriPattern);
let matches = contentUri.match(GitHubUtils.ContentUriPattern);
if (matches && matches.length > 4) {
return {
owner: matches[1],
@@ -37,6 +41,18 @@ export class GitHubUtils {
};
}
matches = contentUri.match(GitHubUtils.LegacyContentUriPattern);
if (matches && matches.length > 4) {
console.log(`Using legacy github content uri scheme ${contentUri}`);
return {
owner: matches[1],
repo: matches[2],
branch: matches[3],
path: matches[4]
};
}
return undefined;
}