@microsoft/vscode-azext-github 1.0.6 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/src/createOctokitClient.js +24 -0
- package/{out → dist/cjs}/src/extensionVariables.js +3 -5
- package/{out → dist/cjs}/src/tree/ActionItem.d.ts +6 -6
- package/dist/cjs/src/tree/ActionItem.js +78 -0
- package/{out → dist/cjs}/src/tree/ActionsItemBase.d.ts +3 -3
- package/dist/cjs/src/tree/ActionsItemBase.js +104 -0
- package/{out → dist/cjs}/src/tree/JobItem.d.ts +6 -6
- package/{out → dist/cjs}/src/tree/JobItem.js +15 -18
- package/{out → dist/cjs}/src/tree/StepItem.d.ts +6 -6
- package/{out → dist/cjs}/src/tree/StepItem.js +13 -4
- package/{out → dist/cjs}/src/utils/actionUtils.js +11 -8
- package/dist/cjs/src/utils/getGitHubAccessToken.js +30 -0
- package/{out → dist/cjs}/src/utils/gitHubUrlParse.js +3 -5
- package/dist/cjs/src/wizard/GitHubBranchListStep.js +59 -0
- package/dist/cjs/src/wizard/GitHubOrgListStep.js +39 -0
- package/dist/cjs/src/wizard/GitHubRepositoryListStep.js +64 -0
- package/dist/cjs/src/wrappers/getActions.js +16 -0
- package/dist/cjs/src/wrappers/getAuthenticatedUser.js +16 -0
- package/dist/cjs/src/wrappers/getBranches.js +16 -0
- package/dist/cjs/src/wrappers/getJobs.js +16 -0
- package/dist/cjs/src/wrappers/getOrgs.js +16 -0
- package/dist/cjs/src/wrappers/getRepositories.js +24 -0
- package/dist/esm/src/GitHubContext.d.ts +9 -0
- package/dist/esm/src/GitHubContext.js +6 -0
- package/dist/esm/src/constants.d.ts +4 -0
- package/dist/esm/src/constants.js +10 -0
- package/dist/esm/src/createOctokitClient.d.ts +9 -0
- package/dist/esm/src/createOctokitClient.js +21 -0
- package/dist/esm/src/extensionVariables.d.ts +13 -0
- package/dist/esm/src/extensionVariables.js +37 -0
- package/dist/esm/src/index.d.ts +15 -0
- package/dist/esm/src/index.js +23 -0
- package/dist/esm/src/tree/ActionItem.d.ts +19 -0
- package/dist/esm/src/tree/ActionItem.js +74 -0
- package/dist/esm/src/tree/ActionsItemBase.d.ts +59 -0
- package/dist/esm/src/tree/ActionsItemBase.js +100 -0
- package/dist/esm/src/tree/JobItem.d.ts +16 -0
- package/dist/esm/src/tree/JobItem.js +44 -0
- package/dist/esm/src/tree/StepItem.d.ts +15 -0
- package/dist/esm/src/tree/StepItem.js +38 -0
- package/dist/esm/src/utils/actionUtils.d.ts +35 -0
- package/dist/esm/src/utils/actionUtils.js +123 -0
- package/dist/esm/src/utils/getGitHubAccessToken.d.ts +1 -0
- package/dist/esm/src/utils/getGitHubAccessToken.js +27 -0
- package/dist/esm/src/utils/gitHubUrlParse.d.ts +23 -0
- package/dist/esm/src/utils/gitHubUrlParse.js +18 -0
- package/dist/esm/src/wizard/GitHubBranchListStep.d.ts +13 -0
- package/dist/esm/src/wizard/GitHubBranchListStep.js +55 -0
- package/dist/esm/src/wizard/GitHubOrgListStep.d.ts +11 -0
- package/dist/esm/src/wizard/GitHubOrgListStep.js +35 -0
- package/dist/esm/src/wizard/GitHubRepositoryListStep.d.ts +13 -0
- package/dist/esm/src/wizard/GitHubRepositoryListStep.js +60 -0
- package/dist/esm/src/wrappers/getActions.d.ts +9 -0
- package/dist/esm/src/wrappers/getActions.js +13 -0
- package/dist/esm/src/wrappers/getAuthenticatedUser.d.ts +7 -0
- package/dist/esm/src/wrappers/getAuthenticatedUser.js +13 -0
- package/dist/esm/src/wrappers/getBranches.d.ts +11 -0
- package/dist/esm/src/wrappers/getBranches.js +13 -0
- package/dist/esm/src/wrappers/getJobs.d.ts +10 -0
- package/dist/esm/src/wrappers/getJobs.js +13 -0
- package/dist/esm/src/wrappers/getOrgs.d.ts +7 -0
- package/dist/esm/src/wrappers/getOrgs.js +13 -0
- package/dist/esm/src/wrappers/getRepositories.d.ts +16 -0
- package/dist/esm/src/wrappers/getRepositories.js +20 -0
- package/package.json +16 -10
- package/out/src/createOctokitClient.js +0 -36
- package/out/src/tree/ActionItem.js +0 -81
- package/out/src/tree/ActionsItemBase.js +0 -114
- package/out/src/utils/getGitHubAccessToken.js +0 -42
- package/out/src/wizard/GitHubBranchListStep.js +0 -71
- package/out/src/wizard/GitHubOrgListStep.js +0 -52
- package/out/src/wizard/GitHubRepositoryListStep.js +0 -77
- package/out/src/wrappers/getActions.js +0 -28
- package/out/src/wrappers/getAuthenticatedUser.js +0 -28
- package/out/src/wrappers/getBranches.js +0 -28
- package/out/src/wrappers/getJobs.js +0 -28
- package/out/src/wrappers/getOrgs.js +0 -28
- package/out/src/wrappers/getRepositories.js +0 -38
- /package/{out → dist/cjs}/src/GitHubContext.d.ts +0 -0
- /package/{out → dist/cjs}/src/GitHubContext.js +0 -0
- /package/{out → dist/cjs}/src/constants.d.ts +0 -0
- /package/{out → dist/cjs}/src/constants.js +0 -0
- /package/{out → dist/cjs}/src/createOctokitClient.d.ts +0 -0
- /package/{out → dist/cjs}/src/extensionVariables.d.ts +0 -0
- /package/{out → dist/cjs}/src/index.d.ts +0 -0
- /package/{out → dist/cjs}/src/index.js +0 -0
- /package/{out → dist/cjs}/src/utils/actionUtils.d.ts +0 -0
- /package/{out → dist/cjs}/src/utils/getGitHubAccessToken.d.ts +0 -0
- /package/{out → dist/cjs}/src/utils/gitHubUrlParse.d.ts +0 -0
- /package/{out → dist/cjs}/src/wizard/GitHubBranchListStep.d.ts +0 -0
- /package/{out → dist/cjs}/src/wizard/GitHubOrgListStep.d.ts +0 -0
- /package/{out → dist/cjs}/src/wizard/GitHubRepositoryListStep.d.ts +0 -0
- /package/{out → dist/cjs}/src/wrappers/getActions.d.ts +0 -0
- /package/{out → dist/cjs}/src/wrappers/getAuthenticatedUser.d.ts +0 -0
- /package/{out → dist/cjs}/src/wrappers/getBranches.d.ts +0 -0
- /package/{out → dist/cjs}/src/wrappers/getJobs.d.ts +0 -0
- /package/{out → dist/cjs}/src/wrappers/getOrgs.d.ts +0 -0
- /package/{out → dist/cjs}/src/wrappers/getRepositories.d.ts +0 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.GitHubRepositoryListStep = void 0;
|
|
8
|
+
const vscode_azext_utils_1 = require("@microsoft/vscode-azext-utils");
|
|
9
|
+
const vscode_1 = require("vscode");
|
|
10
|
+
const constants_1 = require("../constants");
|
|
11
|
+
const getRepositories_1 = require("../wrappers/getRepositories");
|
|
12
|
+
/**
|
|
13
|
+
* Used to prompt the user for the GitHub repository
|
|
14
|
+
* @prerequisites gitHubOrg
|
|
15
|
+
* @populates gitHubRepository, gitHubRepositoryOwner, gitHubRepositoryUrl
|
|
16
|
+
*/
|
|
17
|
+
class GitHubRepositoryListStep extends vscode_azext_utils_1.AzureWizardPromptStep {
|
|
18
|
+
picks;
|
|
19
|
+
async prompt(context) {
|
|
20
|
+
// We always want fresh picks before prompting in case the user has pressed the back button
|
|
21
|
+
this.picks = [];
|
|
22
|
+
const placeHolder = vscode_1.l10n.t('Select a repository');
|
|
23
|
+
let page = 0;
|
|
24
|
+
let repositoryData;
|
|
25
|
+
while (!repositoryData) {
|
|
26
|
+
page++;
|
|
27
|
+
repositoryData = (await context.ui.showQuickPick(this.getPicks(context, page), { placeHolder })).data;
|
|
28
|
+
}
|
|
29
|
+
context.gitHubRepository = repositoryData.repo;
|
|
30
|
+
context.gitHubRepositoryOwner = repositoryData.owner;
|
|
31
|
+
context.gitHubRepositoryUrl = repositoryData.url;
|
|
32
|
+
context.valuesToMask.push(context.gitHubRepository);
|
|
33
|
+
context.valuesToMask.push(context.gitHubRepositoryOwner);
|
|
34
|
+
context.valuesToMask.push(context.gitHubRepositoryUrl);
|
|
35
|
+
}
|
|
36
|
+
shouldPrompt(context) {
|
|
37
|
+
return !context.gitHubRepository || !context.gitHubRepositoryOwner;
|
|
38
|
+
}
|
|
39
|
+
async getPicks(context, page) {
|
|
40
|
+
const perPage = 50;
|
|
41
|
+
const userRepoParams = {
|
|
42
|
+
affiliation: 'owner',
|
|
43
|
+
visibility: 'all',
|
|
44
|
+
per_page: perPage,
|
|
45
|
+
page
|
|
46
|
+
};
|
|
47
|
+
const orgRepoParams = {
|
|
48
|
+
// Doesn't matter if context.gitHubOrg is undefined; that just means we will end up calling 'getRepositoriesByUser' instead
|
|
49
|
+
org: context.gitHubOrg ?? '',
|
|
50
|
+
type: 'all',
|
|
51
|
+
per_page: perPage,
|
|
52
|
+
page
|
|
53
|
+
};
|
|
54
|
+
// Intentionally use the same map callback on two lines below to force TypeScript to infer the proper repo type
|
|
55
|
+
this.picks.push(...(context.gitHubOrg ?
|
|
56
|
+
(await (0, getRepositories_1.getRepositoriesByOrg)(context, orgRepoParams)).map((repo) => { return { label: repo.name, data: { owner: repo.owner.login, repo: repo.name, url: repo.html_url } }; }) :
|
|
57
|
+
(await (0, getRepositories_1.getRepositoriesByUser)(context, userRepoParams)).map((repo) => { return { label: repo.name, data: { owner: repo.owner.login, repo: repo.name, url: repo.html_url } }; })));
|
|
58
|
+
this.picks.sort((a, b) => a.label.localeCompare(b.label));
|
|
59
|
+
const maxPicksAvailable = perPage * page;
|
|
60
|
+
return (maxPicksAvailable === this.picks.length) ? [...this.picks, constants_1.loadMoreQp] : this.picks;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.GitHubRepositoryListStep = GitHubRepositoryListStep;
|
|
64
|
+
//# sourceMappingURL=GitHubRepositoryListStep.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.getActions = getActions;
|
|
8
|
+
const createOctokitClient_1 = require("../createOctokitClient");
|
|
9
|
+
/**
|
|
10
|
+
* A wrapper for Octokit's: `client.actions.listWorkflowRunsForRepo`
|
|
11
|
+
*/
|
|
12
|
+
async function getActions(context, params) {
|
|
13
|
+
const client = await (0, createOctokitClient_1.createOctokitClient)(context);
|
|
14
|
+
return (await client.actions.listWorkflowRunsForRepo(params)).data;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=getActions.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.getAuthenticatedUser = getAuthenticatedUser;
|
|
8
|
+
const createOctokitClient_1 = require("../createOctokitClient");
|
|
9
|
+
/**
|
|
10
|
+
* A wrapper for Octokit's: `client.users.getAuthenticated`
|
|
11
|
+
*/
|
|
12
|
+
async function getAuthenticatedUser(context) {
|
|
13
|
+
const client = await (0, createOctokitClient_1.createOctokitClient)(context);
|
|
14
|
+
return (await client.users.getAuthenticated()).data;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=getAuthenticatedUser.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.getBranches = getBranches;
|
|
8
|
+
const createOctokitClient_1 = require("../createOctokitClient");
|
|
9
|
+
/**
|
|
10
|
+
* A wrapper for Octokit's: `client.repos.listBranches`
|
|
11
|
+
*/
|
|
12
|
+
async function getBranches(context, reqParams) {
|
|
13
|
+
const client = await (0, createOctokitClient_1.createOctokitClient)(context);
|
|
14
|
+
return (await client.repos.listBranches(reqParams)).data;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=getBranches.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.getJobs = getJobs;
|
|
8
|
+
const createOctokitClient_1 = require("../createOctokitClient");
|
|
9
|
+
/**
|
|
10
|
+
* A wrapper for Octokit's: `client.actions.listJobsForWorkflowRun`
|
|
11
|
+
*/
|
|
12
|
+
async function getJobs(context, params) {
|
|
13
|
+
const client = await (0, createOctokitClient_1.createOctokitClient)(context);
|
|
14
|
+
return (await client.actions.listJobsForWorkflowRun(params)).data;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=getJobs.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.getOrgs = getOrgs;
|
|
8
|
+
const createOctokitClient_1 = require("../createOctokitClient");
|
|
9
|
+
/**
|
|
10
|
+
* A wrapper for Octokit's: `client.orgs.listForAuthenticatedUser`
|
|
11
|
+
*/
|
|
12
|
+
async function getOrgs(context) {
|
|
13
|
+
const client = await (0, createOctokitClient_1.createOctokitClient)(context);
|
|
14
|
+
return (await client.orgs.listForAuthenticatedUser()).data;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=getOrgs.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.getRepositoriesByUser = getRepositoriesByUser;
|
|
8
|
+
exports.getRepositoriesByOrg = getRepositoriesByOrg;
|
|
9
|
+
const createOctokitClient_1 = require("../createOctokitClient");
|
|
10
|
+
/**
|
|
11
|
+
* A wrapper for Octokit's: `client.repos.listForAuthenticatedUser`
|
|
12
|
+
*/
|
|
13
|
+
async function getRepositoriesByUser(context, reqParams) {
|
|
14
|
+
const client = await (0, createOctokitClient_1.createOctokitClient)(context);
|
|
15
|
+
return (await client.repos.listForAuthenticatedUser(reqParams)).data;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A wrapper for Octokit's: `client.repos.listForOrg`
|
|
19
|
+
*/
|
|
20
|
+
async function getRepositoriesByOrg(context, reqParams) {
|
|
21
|
+
const client = await (0, createOctokitClient_1.createOctokitClient)(context);
|
|
22
|
+
return (await client.repos.listForOrg(reqParams)).data;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=getRepositories.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IActionContext } from "@microsoft/vscode-azext-utils";
|
|
2
|
+
export interface GitHubContext extends IActionContext {
|
|
3
|
+
gitHubAccessToken?: string;
|
|
4
|
+
gitHubOrg?: string;
|
|
5
|
+
gitHubRepository?: string;
|
|
6
|
+
gitHubRepositoryOwner?: string;
|
|
7
|
+
gitHubRepositoryUrl?: string;
|
|
8
|
+
gitHubBranch?: string;
|
|
9
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
export {};
|
|
6
|
+
//# sourceMappingURL=GitHubContext.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
import { l10n } from "vscode";
|
|
6
|
+
export const gitHubAuthProviderId = 'github';
|
|
7
|
+
// Provide same scopes as the GitHub extension so we don't have to prompt for auth again
|
|
8
|
+
export const gitHubScopes = ['repo', 'workflow', 'user:email', 'read:user'];
|
|
9
|
+
export const loadMoreQp = { label: l10n.t('$(sync) Load More'), data: undefined, suppressPersistence: true };
|
|
10
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Octokit } from "@octokit/rest";
|
|
2
|
+
import type { GitHubContext } from "./GitHubContext";
|
|
3
|
+
/**
|
|
4
|
+
* Can be used to initialize a new Octokit client.
|
|
5
|
+
*
|
|
6
|
+
* Note: Typically does not need to be called directly by client extensions
|
|
7
|
+
* unless implementing a custom behavior.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createOctokitClient(context: GitHubContext): Promise<Octokit>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
import { appendExtensionUserAgent } from "@microsoft/vscode-azext-utils";
|
|
6
|
+
import { Octokit } from "@octokit/rest";
|
|
7
|
+
import { getGitHubAccessToken } from "./utils/getGitHubAccessToken";
|
|
8
|
+
/**
|
|
9
|
+
* Can be used to initialize a new Octokit client.
|
|
10
|
+
*
|
|
11
|
+
* Note: Typically does not need to be called directly by client extensions
|
|
12
|
+
* unless implementing a custom behavior.
|
|
13
|
+
*/
|
|
14
|
+
export async function createOctokitClient(context) {
|
|
15
|
+
context.gitHubAccessToken ||= await getGitHubAccessToken();
|
|
16
|
+
return new Octokit({
|
|
17
|
+
userAgent: appendExtensionUserAgent(),
|
|
18
|
+
auth: context.gitHubAccessToken
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=createOctokitClient.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { UIExtensionVariables } from '@microsoft/vscode-azext-utils';
|
|
2
|
+
interface IAzureUtilsExtensionVariables extends UIExtensionVariables {
|
|
3
|
+
prefix: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Container for common extension variables used throughout the github package. They must be initialized with `registerGitHubExtensionVariables`
|
|
7
|
+
*/
|
|
8
|
+
export declare let ext: IAzureUtilsExtensionVariables;
|
|
9
|
+
/**
|
|
10
|
+
* Call this to register common variables used throughout the github package.
|
|
11
|
+
*/
|
|
12
|
+
export declare function registerGitHubExtensionVariables(extVars: IAzureUtilsExtensionVariables): void;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
import { registerUIExtensionVariables } from '@microsoft/vscode-azext-utils';
|
|
6
|
+
import { l10n } from "vscode";
|
|
7
|
+
class UninitializedExtensionVariables {
|
|
8
|
+
_error = new Error(l10n.t('"registerGitHubExtensionVariables" must be called before using the vscode-azext-github package.'));
|
|
9
|
+
get context() {
|
|
10
|
+
throw this._error;
|
|
11
|
+
}
|
|
12
|
+
get outputChannel() {
|
|
13
|
+
throw this._error;
|
|
14
|
+
}
|
|
15
|
+
get ui() {
|
|
16
|
+
throw this._error;
|
|
17
|
+
}
|
|
18
|
+
get prefix() {
|
|
19
|
+
throw this._error;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Container for common extension variables used throughout the github package. They must be initialized with `registerGitHubExtensionVariables`
|
|
24
|
+
*/
|
|
25
|
+
export let ext = new UninitializedExtensionVariables();
|
|
26
|
+
/**
|
|
27
|
+
* Call this to register common variables used throughout the github package.
|
|
28
|
+
*/
|
|
29
|
+
export function registerGitHubExtensionVariables(extVars) {
|
|
30
|
+
if (ext === extVars) {
|
|
31
|
+
// already registered
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
ext = extVars;
|
|
35
|
+
registerUIExtensionVariables(extVars);
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=extensionVariables.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from './extensionVariables';
|
|
2
|
+
export * from './GitHubContext';
|
|
3
|
+
export * from './createOctokitClient';
|
|
4
|
+
export * from './utils/getGitHubAccessToken';
|
|
5
|
+
export * from './utils/gitHubUrlParse';
|
|
6
|
+
export * from './tree/ActionsItemBase';
|
|
7
|
+
export * from './wizard/GitHubBranchListStep';
|
|
8
|
+
export * from './wizard/GitHubOrgListStep';
|
|
9
|
+
export * from './wizard/GitHubRepositoryListStep';
|
|
10
|
+
export * from './wrappers/getActions';
|
|
11
|
+
export * from './wrappers/getAuthenticatedUser';
|
|
12
|
+
export * from './wrappers/getBranches';
|
|
13
|
+
export * from './wrappers/getJobs';
|
|
14
|
+
export * from './wrappers/getOrgs';
|
|
15
|
+
export * from './wrappers/getRepositories';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
export * from './extensionVariables';
|
|
6
|
+
export * from './GitHubContext';
|
|
7
|
+
export * from './createOctokitClient';
|
|
8
|
+
export * from './utils/getGitHubAccessToken';
|
|
9
|
+
export * from './utils/gitHubUrlParse';
|
|
10
|
+
// Tree Items
|
|
11
|
+
export * from './tree/ActionsItemBase';
|
|
12
|
+
// Wizard Steps
|
|
13
|
+
export * from './wizard/GitHubBranchListStep';
|
|
14
|
+
export * from './wizard/GitHubOrgListStep';
|
|
15
|
+
export * from './wizard/GitHubRepositoryListStep';
|
|
16
|
+
// Octokit Wrappers
|
|
17
|
+
export * from './wrappers/getActions';
|
|
18
|
+
export * from './wrappers/getAuthenticatedUser';
|
|
19
|
+
export * from './wrappers/getBranches';
|
|
20
|
+
export * from './wrappers/getJobs';
|
|
21
|
+
export * from './wrappers/getOrgs';
|
|
22
|
+
export * from './wrappers/getRepositories';
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { TreeElementBase } from "@microsoft/vscode-azext-utils";
|
|
2
|
+
import type { ViewPropertiesModel } from "@microsoft/vscode-azureresources-api";
|
|
3
|
+
import { TreeItem } from "vscode";
|
|
4
|
+
import { ActionWorkflowRuns } from "../wrappers/getActions";
|
|
5
|
+
export declare class ActionItem implements TreeElementBase {
|
|
6
|
+
private readonly parentResourceId;
|
|
7
|
+
private readonly extensionPrefixContextValue;
|
|
8
|
+
private readonly actionWorkflowRuns;
|
|
9
|
+
static readonly contextValueSuffix: string;
|
|
10
|
+
static readonly completedContextValue: string;
|
|
11
|
+
static readonly inProgressContextValue: string;
|
|
12
|
+
constructor(parentResourceId: string, extensionPrefixContextValue: string, actionWorkflowRuns: ActionWorkflowRuns);
|
|
13
|
+
get id(): string;
|
|
14
|
+
get label(): string;
|
|
15
|
+
get viewProperties(): ViewPropertiesModel;
|
|
16
|
+
private get contextValue();
|
|
17
|
+
getTreeItem(): TreeItem;
|
|
18
|
+
getChildren(): Promise<TreeElementBase[]>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
import { callWithTelemetryAndErrorHandling, createContextValue, nonNullProp, nonNullValue } from "@microsoft/vscode-azext-utils";
|
|
6
|
+
import { TreeItemCollapsibleState } from "vscode";
|
|
7
|
+
import { Status, getActionBasedIconPath } from "../utils/actionUtils";
|
|
8
|
+
import { gitHubUrlParse } from "../utils/gitHubUrlParse";
|
|
9
|
+
import { getJobs } from "../wrappers/getJobs";
|
|
10
|
+
import { JobItem } from "./JobItem";
|
|
11
|
+
export class ActionItem {
|
|
12
|
+
parentResourceId;
|
|
13
|
+
extensionPrefixContextValue;
|
|
14
|
+
actionWorkflowRuns;
|
|
15
|
+
static contextValueSuffix = 'ActionItem';
|
|
16
|
+
static completedContextValue = 'actionState:completed';
|
|
17
|
+
static inProgressContextValue = 'actionState:inProgress';
|
|
18
|
+
constructor(parentResourceId, extensionPrefixContextValue, actionWorkflowRuns) {
|
|
19
|
+
this.parentResourceId = parentResourceId;
|
|
20
|
+
this.extensionPrefixContextValue = extensionPrefixContextValue;
|
|
21
|
+
this.actionWorkflowRuns = actionWorkflowRuns;
|
|
22
|
+
}
|
|
23
|
+
get id() {
|
|
24
|
+
return `${this.parentResourceId}/${this.actionWorkflowRuns.id}`;
|
|
25
|
+
}
|
|
26
|
+
get label() {
|
|
27
|
+
return this.actionWorkflowRuns.head_commit?.message || this.actionWorkflowRuns.head_sha;
|
|
28
|
+
}
|
|
29
|
+
get viewProperties() {
|
|
30
|
+
return {
|
|
31
|
+
data: this.actionWorkflowRuns,
|
|
32
|
+
label: this.label,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
get contextValue() {
|
|
36
|
+
const actionTreeItemContextValue = `${this.extensionPrefixContextValue}${ActionItem.contextValueSuffix}`;
|
|
37
|
+
const values = [actionTreeItemContextValue];
|
|
38
|
+
if (nonNullProp(this.actionWorkflowRuns, 'status') === Status.Completed) {
|
|
39
|
+
values.push(ActionItem.completedContextValue);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
values.push(ActionItem.inProgressContextValue);
|
|
43
|
+
}
|
|
44
|
+
return createContextValue(values);
|
|
45
|
+
}
|
|
46
|
+
getTreeItem() {
|
|
47
|
+
return {
|
|
48
|
+
id: this.id,
|
|
49
|
+
label: this.label,
|
|
50
|
+
description: this.actionWorkflowRuns.event,
|
|
51
|
+
iconPath: getActionBasedIconPath(this.actionWorkflowRuns),
|
|
52
|
+
contextValue: this.contextValue,
|
|
53
|
+
collapsibleState: TreeItemCollapsibleState.Collapsed
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
async getChildren() {
|
|
57
|
+
const jobsData = await callWithTelemetryAndErrorHandling('getActionChildren', async (context) => {
|
|
58
|
+
const { ownerOrOrganization, repositoryName } = gitHubUrlParse(this.actionWorkflowRuns.repository.html_url);
|
|
59
|
+
const getJobsParams = {
|
|
60
|
+
owner: nonNullValue(ownerOrOrganization),
|
|
61
|
+
repo: nonNullValue(repositoryName),
|
|
62
|
+
run_id: this.actionWorkflowRuns.id
|
|
63
|
+
};
|
|
64
|
+
return await getJobs(context, getJobsParams);
|
|
65
|
+
});
|
|
66
|
+
if (jobsData?.total_count) {
|
|
67
|
+
return jobsData.jobs.map((job) => new JobItem(this.id, this.extensionPrefixContextValue, job));
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=ActionItem.js.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { TreeElementBase } from "@microsoft/vscode-azext-utils";
|
|
2
|
+
import { TreeItem } from "vscode";
|
|
3
|
+
export interface GitHubSourceControl {
|
|
4
|
+
repoUrl: string;
|
|
5
|
+
repoBranch?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ConnectToGitHubCommand {
|
|
8
|
+
/**
|
|
9
|
+
* The command id to call for initiating the setup of source control for the client extension.
|
|
10
|
+
* The client extension should provide its own connect implementation to call.
|
|
11
|
+
*
|
|
12
|
+
* @example 'containerApps.connectToGitHub'
|
|
13
|
+
*/
|
|
14
|
+
commandId: string;
|
|
15
|
+
/**
|
|
16
|
+
* The list of corresponding args to provide when the command is called
|
|
17
|
+
*/
|
|
18
|
+
commandArgs: unknown[] | undefined;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Base tree node for setting up and tracking GitHub Actions in the tree view.
|
|
22
|
+
* Branching children will be automatically setup and included to track actions, jobs, and steps.
|
|
23
|
+
*/
|
|
24
|
+
export declare abstract class ActionsItemBase implements TreeElementBase {
|
|
25
|
+
private readonly parentId;
|
|
26
|
+
private readonly contextValueExtensionPrefix;
|
|
27
|
+
static readonly contextValueSuffix: string;
|
|
28
|
+
static readonly connectedContextValue: string;
|
|
29
|
+
static readonly unconnectedContextValue: string;
|
|
30
|
+
static readonly idSuffix: string;
|
|
31
|
+
/**
|
|
32
|
+
* @param parentId A unique identifier corresponding to the id of the parent tree node
|
|
33
|
+
* @param contextValueExtensionPrefix The extension prefix used in constructing context values for the 'ActionsItem'
|
|
34
|
+
* and its children. Passing 'containerApps' becomes `containerApps${ActionsItemBase.contextValueSuffix}`.
|
|
35
|
+
*/
|
|
36
|
+
constructor(parentId: string, contextValueExtensionPrefix: string);
|
|
37
|
+
/**
|
|
38
|
+
* Constructed using the format: `${this.parentId}/${ActionsTreeItemBase.idSuffix}`
|
|
39
|
+
*/
|
|
40
|
+
get id(): string;
|
|
41
|
+
readonly label: string;
|
|
42
|
+
private getContextValue;
|
|
43
|
+
getTreeItem(): Promise<TreeItem>;
|
|
44
|
+
getChildren(): Promise<TreeElementBase[]>;
|
|
45
|
+
/**
|
|
46
|
+
* An optional method that the client extension may provide to initiate connection to a GitHub repository.
|
|
47
|
+
*
|
|
48
|
+
* The 'ActionsTreeItem' will display a generic tree item when no connection is detected (e.g. 'Connect to a GitHub Repository...').
|
|
49
|
+
* This tree item becomes an entrypoint for initiating a source control connection.
|
|
50
|
+
*
|
|
51
|
+
* When no method is supplied, clicking on the generic tree item does nothing.
|
|
52
|
+
*/
|
|
53
|
+
getConnectToGitHubCommand?(): Promise<ConnectToGitHubCommand>;
|
|
54
|
+
/**
|
|
55
|
+
* A required method for obtaining the connected GitHub repository's data.
|
|
56
|
+
* If no repository is connected, return undefined.
|
|
57
|
+
*/
|
|
58
|
+
abstract getSourceControl(): Promise<GitHubSourceControl | undefined>;
|
|
59
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
import { callWithTelemetryAndErrorHandling, createContextValue, createGenericElement, nonNullValue } from "@microsoft/vscode-azext-utils";
|
|
6
|
+
import { ThemeIcon, TreeItemCollapsibleState, l10n } from "vscode";
|
|
7
|
+
import { gitHubUrlParse } from "../utils/gitHubUrlParse";
|
|
8
|
+
import { getActions } from "../wrappers/getActions";
|
|
9
|
+
import { ActionItem } from "./ActionItem";
|
|
10
|
+
/**
|
|
11
|
+
* Base tree node for setting up and tracking GitHub Actions in the tree view.
|
|
12
|
+
* Branching children will be automatically setup and included to track actions, jobs, and steps.
|
|
13
|
+
*/
|
|
14
|
+
export class ActionsItemBase {
|
|
15
|
+
parentId;
|
|
16
|
+
contextValueExtensionPrefix;
|
|
17
|
+
static contextValueSuffix = 'ActionsItem';
|
|
18
|
+
static connectedContextValue = 'actionsConnected:true';
|
|
19
|
+
static unconnectedContextValue = 'actionsConnected:false';
|
|
20
|
+
static idSuffix = 'actions';
|
|
21
|
+
/**
|
|
22
|
+
* @param parentId A unique identifier corresponding to the id of the parent tree node
|
|
23
|
+
* @param contextValueExtensionPrefix The extension prefix used in constructing context values for the 'ActionsItem'
|
|
24
|
+
* and its children. Passing 'containerApps' becomes `containerApps${ActionsItemBase.contextValueSuffix}`.
|
|
25
|
+
*/
|
|
26
|
+
constructor(parentId, contextValueExtensionPrefix) {
|
|
27
|
+
this.parentId = parentId;
|
|
28
|
+
this.contextValueExtensionPrefix = contextValueExtensionPrefix;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Constructed using the format: `${this.parentId}/${ActionsTreeItemBase.idSuffix}`
|
|
32
|
+
*/
|
|
33
|
+
get id() {
|
|
34
|
+
return `${this.parentId}/${ActionsItemBase.idSuffix}`;
|
|
35
|
+
}
|
|
36
|
+
label = 'Actions';
|
|
37
|
+
getContextValue(isConnected) {
|
|
38
|
+
const actionsTreeItemContextValue = `${this.contextValueExtensionPrefix}${ActionsItemBase.contextValueSuffix}`;
|
|
39
|
+
const values = [actionsTreeItemContextValue];
|
|
40
|
+
values.push(isConnected ? ActionsItemBase.connectedContextValue : ActionsItemBase.unconnectedContextValue);
|
|
41
|
+
return createContextValue(values);
|
|
42
|
+
}
|
|
43
|
+
async getTreeItem() {
|
|
44
|
+
const isConnected = !!await this.getSourceControl();
|
|
45
|
+
return {
|
|
46
|
+
id: this.id,
|
|
47
|
+
label: this.label,
|
|
48
|
+
description: isConnected ? l10n.t('Connected') : '',
|
|
49
|
+
iconPath: new ThemeIcon('github-inverted'),
|
|
50
|
+
contextValue: this.getContextValue(isConnected),
|
|
51
|
+
collapsibleState: TreeItemCollapsibleState.Collapsed,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
async getChildren() {
|
|
55
|
+
const sourceControl = await this.getSourceControl();
|
|
56
|
+
const actionsListWorkflowRuns = await callWithTelemetryAndErrorHandling('getActionsChildren', async (context) => {
|
|
57
|
+
if (!sourceControl) {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
const { ownerOrOrganization, repositoryName } = gitHubUrlParse(sourceControl.repoUrl);
|
|
61
|
+
const actionWorkflowRunsParams = {
|
|
62
|
+
owner: nonNullValue(ownerOrOrganization),
|
|
63
|
+
repo: nonNullValue(repositoryName),
|
|
64
|
+
branch: sourceControl.repoBranch ?? 'main',
|
|
65
|
+
page: 1,
|
|
66
|
+
};
|
|
67
|
+
context.errorHandling.suppressDisplay = true;
|
|
68
|
+
return await getActions(context, actionWorkflowRunsParams);
|
|
69
|
+
});
|
|
70
|
+
if (actionsListWorkflowRuns?.total_count) {
|
|
71
|
+
return actionsListWorkflowRuns.workflow_runs.map((awr) => new ActionItem(this.id, this.contextValueExtensionPrefix, awr));
|
|
72
|
+
}
|
|
73
|
+
else if (sourceControl) {
|
|
74
|
+
// If we are able to detect a connection but fail to retrieve a list of actions
|
|
75
|
+
return [
|
|
76
|
+
createGenericElement({
|
|
77
|
+
contextValue: 'noActionsDetected',
|
|
78
|
+
id: `${this.parentId}/noActionsDetected`,
|
|
79
|
+
label: l10n.t('No actions detected'),
|
|
80
|
+
})
|
|
81
|
+
];
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
let command;
|
|
85
|
+
if (this.getConnectToGitHubCommand) {
|
|
86
|
+
command = await this.getConnectToGitHubCommand();
|
|
87
|
+
}
|
|
88
|
+
return [
|
|
89
|
+
createGenericElement({
|
|
90
|
+
contextValue: 'connectToGitHub',
|
|
91
|
+
id: `${this.parentId}/connectToGitHub`,
|
|
92
|
+
label: l10n.t('Connect to a GitHub Repository...'),
|
|
93
|
+
commandId: command?.commandId,
|
|
94
|
+
commandArgs: command?.commandArgs
|
|
95
|
+
})
|
|
96
|
+
];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=ActionsItemBase.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { TreeElementBase } from "@microsoft/vscode-azext-utils";
|
|
2
|
+
import type { ViewPropertiesModel } from "@microsoft/vscode-azureresources-api";
|
|
3
|
+
import { TreeItem } from "vscode";
|
|
4
|
+
import { Job } from "../wrappers/getJobs";
|
|
5
|
+
export declare class JobItem implements TreeElementBase {
|
|
6
|
+
private readonly parentResourceId;
|
|
7
|
+
private readonly extensionPrefixContextValue;
|
|
8
|
+
private readonly job;
|
|
9
|
+
static contextValueSuffix: string;
|
|
10
|
+
constructor(parentResourceId: string, extensionPrefixContextValue: string, job: Job);
|
|
11
|
+
get id(): string;
|
|
12
|
+
get label(): string;
|
|
13
|
+
get viewProperties(): ViewPropertiesModel;
|
|
14
|
+
getTreeItem(): TreeItem;
|
|
15
|
+
getChildren(): Promise<TreeElementBase[]>;
|
|
16
|
+
}
|