Skip to content

Commit 8e80106

Browse files
Add documentation
1 parent 697a004 commit 8e80106

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed
Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
11
import * as Octokit from "@octokit/rest";
22

3+
/**
4+
* An interface providing methods for obtaining access tokens
5+
* or an octokit instance for making HTTP requests.
6+
*/
37
export interface Credentials {
48
/**
5-
* Creates or returns an instance of Octokit.
9+
* Returns an authenticated instance of Octokit.
10+
* May prompt the user to log in and grant permission to use their
11+
* token, if they have not already done so.
612
*
713
* @returns An instance of Octokit.
814
*/
915
getOctokit(): Promise<Octokit.Octokit>;
1016

17+
/**
18+
* Returns an OAuth access token.
19+
* May prompt the user to log in and grant permission to use their
20+
* token, if they have not already done so.
21+
*
22+
* @returns An OAuth access token.
23+
*/
1124
getAccessToken(): Promise<string>;
1225

26+
/**
27+
* Returns an OAuth access token if one is available.
28+
* If a token is not available this will return undefined and
29+
* will not prompt the user to log in.
30+
*
31+
* @returns An OAuth access token, or undefined.
32+
*/
1333
getExistingAccessToken(): Promise<string | undefined>;
1434
}

extensions/ql-vscode/test/factories/authentication.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ function makeTestOctokit(octokit: Octokit.Octokit): Credentials {
1818
};
1919
}
2020

21+
/**
22+
* Get a Credentials instance that calls a stub function instead
23+
* of making real HTTP requests.
24+
*/
2125
export function testCredentialsWithStub(
2226
requestSpy?: jest.SpyInstance<RequestInterface<object>>,
2327
): Credentials {
@@ -29,6 +33,10 @@ export function testCredentialsWithStub(
2933
return makeTestOctokit({ request } as any);
3034
}
3135

36+
/**
37+
* Get a Credentials instance that returns a real octokit instance,
38+
* optionally authenticated with a given token.
39+
*/
3240
export function testCredentialsWithRealOctokit(token?: string): Credentials {
3341
return makeTestOctokit(new Octokit.Octokit({ auth: token, retry }));
3442
}

0 commit comments

Comments
 (0)