@microsoft/vscode-azext-github 1.0.7 → 2.0.1

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.
Files changed (79) hide show
  1. package/dist/cjs/src/createOctokitClient.js +24 -0
  2. package/dist/cjs/src/extensionVariables.js +16 -0
  3. package/{out → dist/cjs}/src/index.js +3 -1
  4. package/dist/cjs/src/tree/ActionItem.js +79 -0
  5. package/dist/cjs/src/tree/ActionsItemBase.js +104 -0
  6. package/{out → dist/cjs}/src/tree/JobItem.js +15 -18
  7. package/{out → dist/cjs}/src/tree/StepItem.js +13 -4
  8. package/{out → dist/cjs}/src/utils/actionUtils.js +11 -9
  9. package/dist/cjs/src/utils/getGitHubAccessToken.js +30 -0
  10. package/{out → dist/cjs}/src/utils/gitHubUrlParse.js +4 -5
  11. package/dist/cjs/src/wizard/GitHubBranchListStep.js +60 -0
  12. package/dist/cjs/src/wizard/GitHubOrgListStep.js +39 -0
  13. package/dist/cjs/src/wizard/GitHubRepositoryListStep.js +66 -0
  14. package/dist/cjs/src/wrappers/getActions.js +16 -0
  15. package/dist/cjs/src/wrappers/getAuthenticatedUser.js +16 -0
  16. package/dist/cjs/src/wrappers/getBranches.js +16 -0
  17. package/dist/cjs/src/wrappers/getJobs.js +16 -0
  18. package/dist/cjs/src/wrappers/getOrgs.js +16 -0
  19. package/dist/cjs/src/wrappers/getRepositories.js +24 -0
  20. package/dist/esm/src/GitHubContext.js +6 -0
  21. package/dist/esm/src/constants.js +10 -0
  22. package/{out → dist/esm}/src/createOctokitClient.d.ts +1 -1
  23. package/dist/esm/src/createOctokitClient.js +21 -0
  24. package/dist/esm/src/extensionVariables.d.ts +6 -0
  25. package/dist/esm/src/extensionVariables.js +13 -0
  26. package/{out → dist/esm}/src/index.d.ts +1 -1
  27. package/dist/esm/src/index.js +23 -0
  28. package/{out → dist/esm}/src/tree/ActionItem.d.ts +6 -6
  29. package/dist/esm/src/tree/ActionItem.js +75 -0
  30. package/{out → dist/esm}/src/tree/ActionsItemBase.d.ts +3 -3
  31. package/dist/esm/src/tree/ActionsItemBase.js +100 -0
  32. package/{out → dist/esm}/src/tree/JobItem.d.ts +6 -6
  33. package/dist/esm/src/tree/JobItem.js +44 -0
  34. package/{out → dist/esm}/src/tree/StepItem.d.ts +6 -6
  35. package/dist/esm/src/tree/StepItem.js +38 -0
  36. package/dist/esm/src/utils/actionUtils.js +122 -0
  37. package/dist/esm/src/utils/getGitHubAccessToken.js +27 -0
  38. package/dist/esm/src/utils/gitHubUrlParse.js +19 -0
  39. package/dist/esm/src/wizard/GitHubBranchListStep.js +56 -0
  40. package/dist/esm/src/wizard/GitHubOrgListStep.js +35 -0
  41. package/dist/esm/src/wizard/GitHubRepositoryListStep.js +62 -0
  42. package/dist/esm/src/wrappers/getActions.js +13 -0
  43. package/dist/esm/src/wrappers/getAuthenticatedUser.js +13 -0
  44. package/dist/esm/src/wrappers/getBranches.js +13 -0
  45. package/dist/esm/src/wrappers/getJobs.js +13 -0
  46. package/dist/esm/src/wrappers/getOrgs.js +13 -0
  47. package/dist/esm/src/wrappers/getRepositories.js +20 -0
  48. package/package.json +18 -24
  49. package/out/src/createOctokitClient.js +0 -36
  50. package/out/src/extensionVariables.d.ts +0 -13
  51. package/out/src/extensionVariables.js +0 -43
  52. package/out/src/tree/ActionItem.js +0 -81
  53. package/out/src/tree/ActionsItemBase.js +0 -114
  54. package/out/src/utils/getGitHubAccessToken.js +0 -42
  55. package/out/src/wizard/GitHubBranchListStep.js +0 -71
  56. package/out/src/wizard/GitHubOrgListStep.js +0 -52
  57. package/out/src/wizard/GitHubRepositoryListStep.js +0 -77
  58. package/out/src/wrappers/getActions.js +0 -28
  59. package/out/src/wrappers/getAuthenticatedUser.js +0 -28
  60. package/out/src/wrappers/getBranches.js +0 -28
  61. package/out/src/wrappers/getJobs.js +0 -28
  62. package/out/src/wrappers/getOrgs.js +0 -28
  63. package/out/src/wrappers/getRepositories.js +0 -38
  64. /package/{out → dist/cjs}/src/GitHubContext.js +0 -0
  65. /package/{out → dist/cjs}/src/constants.js +0 -0
  66. /package/{out → dist/esm}/src/GitHubContext.d.ts +0 -0
  67. /package/{out → dist/esm}/src/constants.d.ts +0 -0
  68. /package/{out → dist/esm}/src/utils/actionUtils.d.ts +0 -0
  69. /package/{out → dist/esm}/src/utils/getGitHubAccessToken.d.ts +0 -0
  70. /package/{out → dist/esm}/src/utils/gitHubUrlParse.d.ts +0 -0
  71. /package/{out → dist/esm}/src/wizard/GitHubBranchListStep.d.ts +0 -0
  72. /package/{out → dist/esm}/src/wizard/GitHubOrgListStep.d.ts +0 -0
  73. /package/{out → dist/esm}/src/wizard/GitHubRepositoryListStep.d.ts +0 -0
  74. /package/{out → dist/esm}/src/wrappers/getActions.d.ts +0 -0
  75. /package/{out → dist/esm}/src/wrappers/getAuthenticatedUser.d.ts +0 -0
  76. /package/{out → dist/esm}/src/wrappers/getBranches.d.ts +0 -0
  77. /package/{out → dist/esm}/src/wrappers/getJobs.d.ts +0 -0
  78. /package/{out → dist/esm}/src/wrappers/getOrgs.d.ts +0 -0
  79. /package/{out → dist/esm}/src/wrappers/getRepositories.d.ts +0 -0
@@ -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,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
@@ -1,4 +1,4 @@
1
- import { Octokit } from "@octokit/rest";
1
+ import type { Octokit } from "@octokit/rest";
2
2
  import type { GitHubContext } from "./GitHubContext";
3
3
  /**
4
4
  * Can be used to initialize a new Octokit client.
@@ -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 { getGitHubAccessToken } from "./utils/getGitHubAccessToken";
7
+ /**
8
+ * Can be used to initialize a new Octokit client.
9
+ *
10
+ * Note: Typically does not need to be called directly by client extensions
11
+ * unless implementing a custom behavior.
12
+ */
13
+ export async function createOctokitClient(context) {
14
+ const { Octokit } = await import('@octokit/rest');
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,6 @@
1
+ import { UIExtensionVariables } from '@microsoft/vscode-azext-utils';
2
+ /**
3
+ * Call this to register common variables used throughout the github package.
4
+ * @deprecated This method is no longer necessary and will be removed in a future release. You can safely remove any calls to this method.
5
+ */
6
+ export declare function registerGitHubExtensionVariables(extVars: UIExtensionVariables): void;
@@ -0,0 +1,13 @@
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
+ /**
7
+ * Call this to register common variables used throughout the github package.
8
+ * @deprecated This method is no longer necessary and will be removed in a future release. You can safely remove any calls to this method.
9
+ */
10
+ export function registerGitHubExtensionVariables(extVars) {
11
+ registerUIExtensionVariables(extVars);
12
+ }
13
+ //# sourceMappingURL=extensionVariables.js.map
@@ -1,4 +1,4 @@
1
- export * from './extensionVariables';
1
+ export { registerGitHubExtensionVariables } from './extensionVariables';
2
2
  export * from './GitHubContext';
3
3
  export * from './createOctokitClient';
4
4
  export * from './utils/getGitHubAccessToken';
@@ -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 { registerGitHubExtensionVariables } 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
@@ -3,16 +3,16 @@ import type { ViewPropertiesModel } from "@microsoft/vscode-azureresources-api";
3
3
  import { TreeItem } from "vscode";
4
4
  import { ActionWorkflowRuns } from "../wrappers/getActions";
5
5
  export declare class ActionItem implements TreeElementBase {
6
- readonly parentResourceId: string;
7
- readonly extensionPrefixContextValue: string;
8
- readonly actionWorkflowRuns: ActionWorkflowRuns;
6
+ private readonly parentResourceId;
7
+ private readonly extensionPrefixContextValue;
8
+ private readonly actionWorkflowRuns;
9
9
  static readonly contextValueSuffix: string;
10
10
  static readonly completedContextValue: string;
11
11
  static readonly inProgressContextValue: string;
12
12
  constructor(parentResourceId: string, extensionPrefixContextValue: string, actionWorkflowRuns: ActionWorkflowRuns);
13
- id: string;
14
- label: string;
15
- viewProperties: ViewPropertiesModel;
13
+ get id(): string;
14
+ get label(): string;
15
+ get viewProperties(): ViewPropertiesModel;
16
16
  private get contextValue();
17
17
  getTreeItem(): TreeItem;
18
18
  getChildren(): Promise<TreeElementBase[]>;
@@ -0,0 +1,75 @@
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
+ // eslint-disable-next-line @typescript-eslint/naming-convention
63
+ run_id: this.actionWorkflowRuns.id
64
+ };
65
+ return await getJobs(context, getJobsParams);
66
+ });
67
+ if (jobsData?.total_count) {
68
+ return jobsData.jobs.map((job) => new JobItem(this.id, this.extensionPrefixContextValue, job));
69
+ }
70
+ else {
71
+ return [];
72
+ }
73
+ }
74
+ }
75
+ //# sourceMappingURL=ActionItem.js.map
@@ -22,8 +22,8 @@ export interface ConnectToGitHubCommand {
22
22
  * Branching children will be automatically setup and included to track actions, jobs, and steps.
23
23
  */
24
24
  export declare abstract class ActionsItemBase implements TreeElementBase {
25
- readonly parentId: string;
26
- readonly contextValueExtensionPrefix: string;
25
+ private readonly parentId;
26
+ private readonly contextValueExtensionPrefix;
27
27
  static readonly contextValueSuffix: string;
28
28
  static readonly connectedContextValue: string;
29
29
  static readonly unconnectedContextValue: string;
@@ -37,7 +37,7 @@ export declare abstract class ActionsItemBase implements TreeElementBase {
37
37
  /**
38
38
  * Constructed using the format: `${this.parentId}/${ActionsTreeItemBase.idSuffix}`
39
39
  */
40
- readonly id: string;
40
+ get id(): string;
41
41
  readonly label: string;
42
42
  private getContextValue;
43
43
  getTreeItem(): Promise<TreeItem>;
@@ -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
@@ -3,14 +3,14 @@ import type { ViewPropertiesModel } from "@microsoft/vscode-azureresources-api";
3
3
  import { TreeItem } from "vscode";
4
4
  import { Job } from "../wrappers/getJobs";
5
5
  export declare class JobItem implements TreeElementBase {
6
- readonly parentResourceId: string;
7
- readonly extensionPrefixContextValue: string;
8
- readonly job: Job;
6
+ private readonly parentResourceId;
7
+ private readonly extensionPrefixContextValue;
8
+ private readonly job;
9
9
  static contextValueSuffix: string;
10
10
  constructor(parentResourceId: string, extensionPrefixContextValue: string, job: Job);
11
- id: string;
12
- label: string;
13
- viewProperties: ViewPropertiesModel;
11
+ get id(): string;
12
+ get label(): string;
13
+ get viewProperties(): ViewPropertiesModel;
14
14
  getTreeItem(): TreeItem;
15
15
  getChildren(): Promise<TreeElementBase[]>;
16
16
  }
@@ -0,0 +1,44 @@
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 { TreeItemCollapsibleState } from "vscode";
6
+ import { getActionBasedIconPath, getJobBasedDescription } from "../utils/actionUtils";
7
+ import { StepItem } from "./StepItem";
8
+ export class JobItem {
9
+ parentResourceId;
10
+ extensionPrefixContextValue;
11
+ job;
12
+ static contextValueSuffix = 'JobItem';
13
+ constructor(parentResourceId, extensionPrefixContextValue, job) {
14
+ this.parentResourceId = parentResourceId;
15
+ this.extensionPrefixContextValue = extensionPrefixContextValue;
16
+ this.job = job;
17
+ }
18
+ get id() {
19
+ return `${this.parentResourceId}/jobs/${this.job.id}`;
20
+ }
21
+ get label() {
22
+ return this.job.name || this.id;
23
+ }
24
+ get viewProperties() {
25
+ return {
26
+ data: this.job,
27
+ label: this.label,
28
+ };
29
+ }
30
+ getTreeItem() {
31
+ return {
32
+ id: this.id,
33
+ label: this.label,
34
+ description: getJobBasedDescription(this.job),
35
+ iconPath: getActionBasedIconPath(this.job),
36
+ contextValue: `${this.extensionPrefixContextValue}${JobItem.contextValueSuffix}`,
37
+ collapsibleState: TreeItemCollapsibleState.Collapsed,
38
+ };
39
+ }
40
+ async getChildren() {
41
+ return Promise.resolve(this.job.steps?.map((step) => new StepItem(this.id, this.extensionPrefixContextValue, step)) ?? []);
42
+ }
43
+ }
44
+ //# sourceMappingURL=JobItem.js.map
@@ -3,13 +3,13 @@ import type { ViewPropertiesModel } from "@microsoft/vscode-azureresources-api";
3
3
  import { TreeItem } from "vscode";
4
4
  import { JobStep } from "../wrappers/getJobs";
5
5
  export declare class StepItem implements TreeElementBase {
6
- readonly parentResourceId: string;
7
- readonly extensionPrefixContextValue: string;
8
- readonly step: JobStep;
6
+ private readonly parentResourceId;
7
+ private readonly extensionPrefixContextValue;
8
+ private readonly step;
9
9
  static contextValueSuffix: string;
10
10
  constructor(parentResourceId: string, extensionPrefixContextValue: string, step: JobStep);
11
- id: string;
12
- label: string;
13
- viewProperties: ViewPropertiesModel;
11
+ get id(): string;
12
+ get label(): string;
13
+ get viewProperties(): ViewPropertiesModel;
14
14
  getTreeItem(): TreeItem;
15
15
  }
@@ -0,0 +1,38 @@
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 { getActionBasedIconPath, getJobBasedDescription } from "../utils/actionUtils";
6
+ export class StepItem {
7
+ parentResourceId;
8
+ extensionPrefixContextValue;
9
+ step;
10
+ static contextValueSuffix = 'StepItem';
11
+ constructor(parentResourceId, extensionPrefixContextValue, step) {
12
+ this.parentResourceId = parentResourceId;
13
+ this.extensionPrefixContextValue = extensionPrefixContextValue;
14
+ this.step = step;
15
+ }
16
+ get id() {
17
+ return `${this.parentResourceId}/steps/${this.step.number}`;
18
+ }
19
+ get label() {
20
+ return this.step.name;
21
+ }
22
+ get viewProperties() {
23
+ return {
24
+ data: this.step,
25
+ label: this.step.name,
26
+ };
27
+ }
28
+ getTreeItem() {
29
+ return {
30
+ id: this.id,
31
+ label: this.label,
32
+ description: getJobBasedDescription(this.step),
33
+ iconPath: getActionBasedIconPath(this.step),
34
+ contextValue: `${this.extensionPrefixContextValue}${StepItem.contextValueSuffix}`
35
+ };
36
+ }
37
+ }
38
+ //# sourceMappingURL=StepItem.js.map
@@ -0,0 +1,122 @@
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 { nonNullProp } from "@microsoft/vscode-azext-utils";
6
+ import dayjs from "dayjs";
7
+ import relativeTime from 'dayjs/plugin/relativeTime';
8
+ import { ThemeColor, ThemeIcon, l10n } from "vscode";
9
+ dayjs.extend(relativeTime);
10
+ /**
11
+ * GitHub 'Check Run' - final conclusion of the check
12
+ * https://developer.github.com/v3/checks/runs/#parameters
13
+ */
14
+ export var Conclusion;
15
+ (function (Conclusion) {
16
+ Conclusion["Success"] = "success";
17
+ Conclusion["Failure"] = "failure";
18
+ Conclusion["Skipped"] = "skipped";
19
+ Conclusion["Cancelled"] = "cancelled";
20
+ })(Conclusion || (Conclusion = {}));
21
+ /**
22
+ * GitHub 'Check Run' - current status of the check
23
+ */
24
+ export var Status;
25
+ (function (Status) {
26
+ Status["Queued"] = "queued";
27
+ Status["InProgress"] = "in_progress";
28
+ Status["Completed"] = "completed";
29
+ })(Status || (Status = {}));
30
+ /**
31
+ * Get a tree item description based on its Job-related status.
32
+ *
33
+ * Note: Typically does not need to be called directly by client extensions
34
+ * unless implementing a custom experience.
35
+ */
36
+ export function getJobBasedDescription(data) {
37
+ if (data.conclusion !== null) {
38
+ const conclusion = convertConclusionToVerb(nonNullProp(data, 'conclusion'));
39
+ const completedAt = dayjs(data.completed_at).fromNow();
40
+ return `${conclusion} ${completedAt}`;
41
+ }
42
+ else {
43
+ const status = convertStatusToVerb(nonNullProp(data, 'status'));
44
+ const startedAt = !data.started_at ? l10n.t('now') : dayjs(data.started_at).fromNow();
45
+ return `${status} ${startedAt}`;
46
+ }
47
+ }
48
+ /**
49
+ * Select an icon based on its Action-related status.
50
+ *
51
+ * Note: Typically does not need to be called directly by client extensions
52
+ * unless implementing a custom experience.
53
+ */
54
+ export function getActionBasedIconPath(data) {
55
+ let id;
56
+ let colorId;
57
+ if (data.conclusion !== null) {
58
+ switch (nonNullProp(data, 'conclusion')) {
59
+ case Conclusion.Cancelled:
60
+ id = 'circle-slash';
61
+ colorId = 'testing.iconUnset';
62
+ break;
63
+ case Conclusion.Failure:
64
+ id = 'error';
65
+ colorId = 'testing.iconFailed';
66
+ break;
67
+ case Conclusion.Skipped:
68
+ id = 'debug-step-over';
69
+ colorId = 'testing.iconSkipped';
70
+ break;
71
+ case Conclusion.Success:
72
+ id = 'pass';
73
+ colorId = 'testing.iconPassed';
74
+ break;
75
+ }
76
+ }
77
+ else {
78
+ switch (nonNullProp(data, 'status')) {
79
+ case Status.Queued:
80
+ id = 'clock';
81
+ colorId = 'testing.iconQueued';
82
+ break;
83
+ case Status.InProgress:
84
+ id = 'play-circle';
85
+ colorId = 'testing.iconUnset';
86
+ break;
87
+ case Status.Completed:
88
+ id = 'pass';
89
+ colorId = 'testing.iconPassed';
90
+ break;
91
+ }
92
+ }
93
+ return new ThemeIcon(id, colorId ? new ThemeColor(colorId) : undefined);
94
+ }
95
+ // Helpers...
96
+ function convertConclusionToVerb(conclusion) {
97
+ switch (conclusion) {
98
+ case Conclusion.Success:
99
+ return l10n.t('succeeded');
100
+ case Conclusion.Cancelled:
101
+ return l10n.t('cancelled');
102
+ case Conclusion.Failure:
103
+ return l10n.t('failed');
104
+ case Conclusion.Skipped:
105
+ return l10n.t('skipped');
106
+ default:
107
+ return '';
108
+ }
109
+ }
110
+ function convertStatusToVerb(status) {
111
+ switch (status) {
112
+ case Status.InProgress:
113
+ return l10n.t('started');
114
+ case Status.Queued:
115
+ return l10n.t('queued');
116
+ case Status.Completed:
117
+ return l10n.t('completed');
118
+ default:
119
+ return '';
120
+ }
121
+ }
122
+ //# sourceMappingURL=actionUtils.js.map