Remove enableGallery feature flag (#68)

* Remove enableGallery feature flag

* Fix bugs

* Add tests to increase coverage

* Move favorites functionality behind feature.enableGalleryPublish flag

* Show code cells in NotebookViewer

* Use cosmos db logo as persona image for sample notebook gallery cards

* Update gallery card snapshot to fix test
This commit is contained in:
Tanuj Mittal
2020-07-06 12:10:26 -07:00
committed by GitHub
parent 27024ef75c
commit 84ea3796ec
29 changed files with 594 additions and 445 deletions

View File

@@ -1,110 +0,0 @@
import { HttpStatusCodes } from "../Common/Constants";
import { GitHubClient, IGitHubFile } from "./GitHubClient";
import { SamplesRepo, SamplesBranch, SamplesContentsQueryResponse } from "../Explorer/Notebook/NotebookSamples";
const invalidTokenCallback = jest.fn();
// Use a dummy token to get around API rate limit (something which doesn't affect the API quota for AZURESAMPLESCOSMOSDBPAT in Config.ts)
const gitHubClient = new GitHubClient("cd1906b9534362fab6ce45d6db6c76b59e55bc50", invalidTokenCallback);
const validateGitHubFile = (file: IGitHubFile) => {
expect(file.branch).toEqual(SamplesBranch);
expect(file.commit).toBeDefined();
expect(file.name).toBeDefined();
expect(file.path).toBeDefined();
expect(file.repo).toEqual(SamplesRepo);
expect(file.type).toBeDefined();
switch (file.type) {
case "blob":
expect(file.sha).toBeDefined();
expect(file.size).toBeDefined();
break;
case "tree":
expect(file.sha).toBeUndefined();
expect(file.size).toBeUndefined();
break;
default:
throw new Error(`Unsupported github file type: ${file.type}`);
}
};
describe("GitHubClient", () => {
it("getRepoAsync returns valid repo", async () => {
const response = await gitHubClient.getRepoAsync(SamplesRepo.owner, SamplesRepo.name);
expect(response).toEqual({
status: HttpStatusCodes.OK,
data: SamplesRepo
});
});
it("getReposAsync returns repos for authenticated user", async () => {
const response = await gitHubClient.getReposAsync(1);
expect(response.status).toBe(HttpStatusCodes.OK);
expect(response.data).toBeDefined();
expect(response.data.length).toBe(1);
expect(response.pageInfo).toBeDefined();
});
it("getBranchesAsync returns branches for a repo", async () => {
const response = await gitHubClient.getBranchesAsync(SamplesRepo.owner, SamplesRepo.name, 1);
expect(response.status).toBe(HttpStatusCodes.OK);
expect(response.data).toEqual([SamplesBranch]);
expect(response.pageInfo).toBeDefined();
});
it("getContentsAsync returns files in the repo", async () => {
const response = await gitHubClient.getContentsAsync(SamplesRepo.owner, SamplesRepo.name, SamplesBranch.name);
expect(response.status).toBe(HttpStatusCodes.OK);
expect(response.data).toBeDefined();
const data = response.data as IGitHubFile[];
expect(data.length).toBeGreaterThan(0);
data.forEach(content => validateGitHubFile(content));
});
it("getContentsAsync returns files in a dir", async () => {
const samplesDir = SamplesContentsQueryResponse.repository.object.entries.find(file => file.type === "tree");
const response = await gitHubClient.getContentsAsync(
SamplesRepo.owner,
SamplesRepo.name,
SamplesBranch.name,
samplesDir.name
);
expect(response.status).toBe(HttpStatusCodes.OK);
expect(response.data).toBeDefined();
const data = response.data as IGitHubFile[];
expect(data.length).toBeGreaterThan(0);
data.forEach(content => validateGitHubFile(content));
});
it("getContentsAsync returns a file", async () => {
const samplesFile = SamplesContentsQueryResponse.repository.object.entries.find(file => file.type === "blob");
const response = await gitHubClient.getContentsAsync(
SamplesRepo.owner,
SamplesRepo.name,
SamplesBranch.name,
samplesFile.name
);
expect(response.status).toBe(HttpStatusCodes.OK);
expect(response.data).toBeDefined();
const file = response.data as IGitHubFile;
expect(file.type).toBe("blob");
validateGitHubFile(file);
expect(file.content).toBeUndefined();
});
it("getBlobAsync returns file content", async () => {
const samplesFile = SamplesContentsQueryResponse.repository.object.entries.find(file => file.type === "blob");
const response = await gitHubClient.getBlobAsync(SamplesRepo.owner, SamplesRepo.name, samplesFile.object.oid);
expect(response.status).toBe(HttpStatusCodes.OK);
expect(response.data).toBeDefined();
expect(typeof response.data).toBe("string");
});
});

View File

@@ -2,7 +2,6 @@ import { Octokit } from "@octokit/rest";
import { HttpStatusCodes } from "../Common/Constants";
import * as Logger from "../Common/Logger";
import UrlUtility from "../Common/UrlUtility";
import { isSamplesCall, SamplesContentsQueryResponse } from "../Explorer/Notebook/NotebookSamples";
import { NotebookUtil } from "../Explorer/Notebook/NotebookUtil";
export interface IGitHubPageInfo {
@@ -225,8 +224,8 @@ export class GitHubClient {
private static readonly SelfErrorCode = 599;
private ocktokit: Octokit;
constructor(token: string, private errorCallback: (error: any) => void) {
this.initOctokit(token);
constructor(private errorCallback: (error: any) => void) {
this.initOctokit();
}
public setToken(token: string): void {
@@ -310,18 +309,13 @@ export class GitHubClient {
path?: string
): Promise<IGitHubResponse<IGitHubFile | IGitHubFile[]>> {
try {
let response: ContentsQueryResponse;
if (isSamplesCall(owner, repo, branch) && !path) {
response = SamplesContentsQueryResponse;
} else {
response = (await this.ocktokit.graphql(contentsQuery, {
owner,
repo,
ref: `refs/heads/${branch}`,
path: path || undefined,
objectExpression: `refs/heads/${branch}:${path || ""}`
} as ContentsQueryParams)) as ContentsQueryResponse;
}
const response = (await this.ocktokit.graphql(contentsQuery, {
owner,
repo,
ref: `refs/heads/${branch}`,
path: path || undefined,
objectExpression: `refs/heads/${branch}:${path || ""}`
} as ContentsQueryParams)) as ContentsQueryResponse;
let data: IGitHubFile | IGitHubFile[];
const entries = response.repository.object.entries;
@@ -495,7 +489,7 @@ export class GitHubClient {
return { status: response.status, data: <string>(<unknown>response.data) };
}
private async initOctokit(token: string) {
private async initOctokit(token?: string) {
this.ocktokit = new Octokit({
auth: token,
log: {

View File

@@ -5,7 +5,7 @@ import { GitHubClient, IGitHubCommit, IGitHubFile } from "./GitHubClient";
import { GitHubContentProvider } from "./GitHubContentProvider";
import * as GitHubUtils from "../Utils/GitHubUtils";
const gitHubClient = new GitHubClient("token", () => {});
const gitHubClient = new GitHubClient(() => {});
const gitHubContentProvider = new GitHubContentProvider({
gitHubClient,
promptForCommitMsg: () => Promise.resolve("commit msg")