@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.
Files changed (98) hide show
  1. package/dist/cjs/src/createOctokitClient.js +24 -0
  2. package/{out → dist/cjs}/src/extensionVariables.js +3 -5
  3. package/{out → dist/cjs}/src/tree/ActionItem.d.ts +6 -6
  4. package/dist/cjs/src/tree/ActionItem.js +78 -0
  5. package/{out → dist/cjs}/src/tree/ActionsItemBase.d.ts +3 -3
  6. package/dist/cjs/src/tree/ActionsItemBase.js +104 -0
  7. package/{out → dist/cjs}/src/tree/JobItem.d.ts +6 -6
  8. package/{out → dist/cjs}/src/tree/JobItem.js +15 -18
  9. package/{out → dist/cjs}/src/tree/StepItem.d.ts +6 -6
  10. package/{out → dist/cjs}/src/tree/StepItem.js +13 -4
  11. package/{out → dist/cjs}/src/utils/actionUtils.js +11 -8
  12. package/dist/cjs/src/utils/getGitHubAccessToken.js +30 -0
  13. package/{out → dist/cjs}/src/utils/gitHubUrlParse.js +3 -5
  14. package/dist/cjs/src/wizard/GitHubBranchListStep.js +59 -0
  15. package/dist/cjs/src/wizard/GitHubOrgListStep.js +39 -0
  16. package/dist/cjs/src/wizard/GitHubRepositoryListStep.js +64 -0
  17. package/dist/cjs/src/wrappers/getActions.js +16 -0
  18. package/dist/cjs/src/wrappers/getAuthenticatedUser.js +16 -0
  19. package/dist/cjs/src/wrappers/getBranches.js +16 -0
  20. package/dist/cjs/src/wrappers/getJobs.js +16 -0
  21. package/dist/cjs/src/wrappers/getOrgs.js +16 -0
  22. package/dist/cjs/src/wrappers/getRepositories.js +24 -0
  23. package/dist/esm/src/GitHubContext.d.ts +9 -0
  24. package/dist/esm/src/GitHubContext.js +6 -0
  25. package/dist/esm/src/constants.d.ts +4 -0
  26. package/dist/esm/src/constants.js +10 -0
  27. package/dist/esm/src/createOctokitClient.d.ts +9 -0
  28. package/dist/esm/src/createOctokitClient.js +21 -0
  29. package/dist/esm/src/extensionVariables.d.ts +13 -0
  30. package/dist/esm/src/extensionVariables.js +37 -0
  31. package/dist/esm/src/index.d.ts +15 -0
  32. package/dist/esm/src/index.js +23 -0
  33. package/dist/esm/src/tree/ActionItem.d.ts +19 -0
  34. package/dist/esm/src/tree/ActionItem.js +74 -0
  35. package/dist/esm/src/tree/ActionsItemBase.d.ts +59 -0
  36. package/dist/esm/src/tree/ActionsItemBase.js +100 -0
  37. package/dist/esm/src/tree/JobItem.d.ts +16 -0
  38. package/dist/esm/src/tree/JobItem.js +44 -0
  39. package/dist/esm/src/tree/StepItem.d.ts +15 -0
  40. package/dist/esm/src/tree/StepItem.js +38 -0
  41. package/dist/esm/src/utils/actionUtils.d.ts +35 -0
  42. package/dist/esm/src/utils/actionUtils.js +123 -0
  43. package/dist/esm/src/utils/getGitHubAccessToken.d.ts +1 -0
  44. package/dist/esm/src/utils/getGitHubAccessToken.js +27 -0
  45. package/dist/esm/src/utils/gitHubUrlParse.d.ts +23 -0
  46. package/dist/esm/src/utils/gitHubUrlParse.js +18 -0
  47. package/dist/esm/src/wizard/GitHubBranchListStep.d.ts +13 -0
  48. package/dist/esm/src/wizard/GitHubBranchListStep.js +55 -0
  49. package/dist/esm/src/wizard/GitHubOrgListStep.d.ts +11 -0
  50. package/dist/esm/src/wizard/GitHubOrgListStep.js +35 -0
  51. package/dist/esm/src/wizard/GitHubRepositoryListStep.d.ts +13 -0
  52. package/dist/esm/src/wizard/GitHubRepositoryListStep.js +60 -0
  53. package/dist/esm/src/wrappers/getActions.d.ts +9 -0
  54. package/dist/esm/src/wrappers/getActions.js +13 -0
  55. package/dist/esm/src/wrappers/getAuthenticatedUser.d.ts +7 -0
  56. package/dist/esm/src/wrappers/getAuthenticatedUser.js +13 -0
  57. package/dist/esm/src/wrappers/getBranches.d.ts +11 -0
  58. package/dist/esm/src/wrappers/getBranches.js +13 -0
  59. package/dist/esm/src/wrappers/getJobs.d.ts +10 -0
  60. package/dist/esm/src/wrappers/getJobs.js +13 -0
  61. package/dist/esm/src/wrappers/getOrgs.d.ts +7 -0
  62. package/dist/esm/src/wrappers/getOrgs.js +13 -0
  63. package/dist/esm/src/wrappers/getRepositories.d.ts +16 -0
  64. package/dist/esm/src/wrappers/getRepositories.js +20 -0
  65. package/package.json +16 -10
  66. package/out/src/createOctokitClient.js +0 -36
  67. package/out/src/tree/ActionItem.js +0 -81
  68. package/out/src/tree/ActionsItemBase.js +0 -114
  69. package/out/src/utils/getGitHubAccessToken.js +0 -42
  70. package/out/src/wizard/GitHubBranchListStep.js +0 -71
  71. package/out/src/wizard/GitHubOrgListStep.js +0 -52
  72. package/out/src/wizard/GitHubRepositoryListStep.js +0 -77
  73. package/out/src/wrappers/getActions.js +0 -28
  74. package/out/src/wrappers/getAuthenticatedUser.js +0 -28
  75. package/out/src/wrappers/getBranches.js +0 -28
  76. package/out/src/wrappers/getJobs.js +0 -28
  77. package/out/src/wrappers/getOrgs.js +0 -28
  78. package/out/src/wrappers/getRepositories.js +0 -38
  79. /package/{out → dist/cjs}/src/GitHubContext.d.ts +0 -0
  80. /package/{out → dist/cjs}/src/GitHubContext.js +0 -0
  81. /package/{out → dist/cjs}/src/constants.d.ts +0 -0
  82. /package/{out → dist/cjs}/src/constants.js +0 -0
  83. /package/{out → dist/cjs}/src/createOctokitClient.d.ts +0 -0
  84. /package/{out → dist/cjs}/src/extensionVariables.d.ts +0 -0
  85. /package/{out → dist/cjs}/src/index.d.ts +0 -0
  86. /package/{out → dist/cjs}/src/index.js +0 -0
  87. /package/{out → dist/cjs}/src/utils/actionUtils.d.ts +0 -0
  88. /package/{out → dist/cjs}/src/utils/getGitHubAccessToken.d.ts +0 -0
  89. /package/{out → dist/cjs}/src/utils/gitHubUrlParse.d.ts +0 -0
  90. /package/{out → dist/cjs}/src/wizard/GitHubBranchListStep.d.ts +0 -0
  91. /package/{out → dist/cjs}/src/wizard/GitHubOrgListStep.d.ts +0 -0
  92. /package/{out → dist/cjs}/src/wizard/GitHubRepositoryListStep.d.ts +0 -0
  93. /package/{out → dist/cjs}/src/wrappers/getActions.d.ts +0 -0
  94. /package/{out → dist/cjs}/src/wrappers/getAuthenticatedUser.d.ts +0 -0
  95. /package/{out → dist/cjs}/src/wrappers/getBranches.d.ts +0 -0
  96. /package/{out → dist/cjs}/src/wrappers/getJobs.d.ts +0 -0
  97. /package/{out → dist/cjs}/src/wrappers/getOrgs.d.ts +0 -0
  98. /package/{out → dist/cjs}/src/wrappers/getRepositories.d.ts +0 -0
@@ -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.createOctokitClient = createOctokitClient;
8
+ const vscode_azext_utils_1 = require("@microsoft/vscode-azext-utils");
9
+ const rest_1 = require("@octokit/rest");
10
+ const getGitHubAccessToken_1 = require("./utils/getGitHubAccessToken");
11
+ /**
12
+ * Can be used to initialize a new Octokit client.
13
+ *
14
+ * Note: Typically does not need to be called directly by client extensions
15
+ * unless implementing a custom behavior.
16
+ */
17
+ async function createOctokitClient(context) {
18
+ context.gitHubAccessToken ||= await (0, getGitHubAccessToken_1.getGitHubAccessToken)();
19
+ return new rest_1.Octokit({
20
+ userAgent: (0, vscode_azext_utils_1.appendExtensionUserAgent)(),
21
+ auth: context.gitHubAccessToken
22
+ });
23
+ }
24
+ //# sourceMappingURL=createOctokitClient.js.map
@@ -4,13 +4,12 @@
4
4
  * Licensed under the MIT License. See License.txt in the project root for license information.
5
5
  *--------------------------------------------------------------------------------------------*/
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.registerGitHubExtensionVariables = exports.ext = void 0;
7
+ exports.ext = void 0;
8
+ exports.registerGitHubExtensionVariables = registerGitHubExtensionVariables;
8
9
  const vscode_azext_utils_1 = require("@microsoft/vscode-azext-utils");
9
10
  const vscode_1 = require("vscode");
10
11
  class UninitializedExtensionVariables {
11
- constructor() {
12
- this._error = new Error(vscode_1.l10n.t('"registerGitHubExtensionVariables" must be called before using the vscode-azext-github package.'));
13
- }
12
+ _error = new Error(vscode_1.l10n.t('"registerGitHubExtensionVariables" must be called before using the vscode-azext-github package.'));
14
13
  get context() {
15
14
  throw this._error;
16
15
  }
@@ -39,5 +38,4 @@ function registerGitHubExtensionVariables(extVars) {
39
38
  exports.ext = extVars;
40
39
  (0, vscode_azext_utils_1.registerUIExtensionVariables)(extVars);
41
40
  }
42
- exports.registerGitHubExtensionVariables = registerGitHubExtensionVariables;
43
41
  //# sourceMappingURL=extensionVariables.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,78 @@
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.ActionItem = void 0;
8
+ const vscode_azext_utils_1 = require("@microsoft/vscode-azext-utils");
9
+ const vscode_1 = require("vscode");
10
+ const actionUtils_1 = require("../utils/actionUtils");
11
+ const gitHubUrlParse_1 = require("../utils/gitHubUrlParse");
12
+ const getJobs_1 = require("../wrappers/getJobs");
13
+ const JobItem_1 = require("./JobItem");
14
+ class ActionItem {
15
+ parentResourceId;
16
+ extensionPrefixContextValue;
17
+ actionWorkflowRuns;
18
+ static contextValueSuffix = 'ActionItem';
19
+ static completedContextValue = 'actionState:completed';
20
+ static inProgressContextValue = 'actionState:inProgress';
21
+ constructor(parentResourceId, extensionPrefixContextValue, actionWorkflowRuns) {
22
+ this.parentResourceId = parentResourceId;
23
+ this.extensionPrefixContextValue = extensionPrefixContextValue;
24
+ this.actionWorkflowRuns = actionWorkflowRuns;
25
+ }
26
+ get id() {
27
+ return `${this.parentResourceId}/${this.actionWorkflowRuns.id}`;
28
+ }
29
+ get label() {
30
+ return this.actionWorkflowRuns.head_commit?.message || this.actionWorkflowRuns.head_sha;
31
+ }
32
+ get viewProperties() {
33
+ return {
34
+ data: this.actionWorkflowRuns,
35
+ label: this.label,
36
+ };
37
+ }
38
+ get contextValue() {
39
+ const actionTreeItemContextValue = `${this.extensionPrefixContextValue}${ActionItem.contextValueSuffix}`;
40
+ const values = [actionTreeItemContextValue];
41
+ if ((0, vscode_azext_utils_1.nonNullProp)(this.actionWorkflowRuns, 'status') === actionUtils_1.Status.Completed) {
42
+ values.push(ActionItem.completedContextValue);
43
+ }
44
+ else {
45
+ values.push(ActionItem.inProgressContextValue);
46
+ }
47
+ return (0, vscode_azext_utils_1.createContextValue)(values);
48
+ }
49
+ getTreeItem() {
50
+ return {
51
+ id: this.id,
52
+ label: this.label,
53
+ description: this.actionWorkflowRuns.event,
54
+ iconPath: (0, actionUtils_1.getActionBasedIconPath)(this.actionWorkflowRuns),
55
+ contextValue: this.contextValue,
56
+ collapsibleState: vscode_1.TreeItemCollapsibleState.Collapsed
57
+ };
58
+ }
59
+ async getChildren() {
60
+ const jobsData = await (0, vscode_azext_utils_1.callWithTelemetryAndErrorHandling)('getActionChildren', async (context) => {
61
+ const { ownerOrOrganization, repositoryName } = (0, gitHubUrlParse_1.gitHubUrlParse)(this.actionWorkflowRuns.repository.html_url);
62
+ const getJobsParams = {
63
+ owner: (0, vscode_azext_utils_1.nonNullValue)(ownerOrOrganization),
64
+ repo: (0, vscode_azext_utils_1.nonNullValue)(repositoryName),
65
+ run_id: this.actionWorkflowRuns.id
66
+ };
67
+ return await (0, getJobs_1.getJobs)(context, getJobsParams);
68
+ });
69
+ if (jobsData?.total_count) {
70
+ return jobsData.jobs.map((job) => new JobItem_1.JobItem(this.id, this.extensionPrefixContextValue, job));
71
+ }
72
+ else {
73
+ return [];
74
+ }
75
+ }
76
+ }
77
+ exports.ActionItem = ActionItem;
78
+ //# 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,104 @@
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.ActionsItemBase = void 0;
8
+ const vscode_azext_utils_1 = require("@microsoft/vscode-azext-utils");
9
+ const vscode_1 = require("vscode");
10
+ const gitHubUrlParse_1 = require("../utils/gitHubUrlParse");
11
+ const getActions_1 = require("../wrappers/getActions");
12
+ const ActionItem_1 = require("./ActionItem");
13
+ /**
14
+ * Base tree node for setting up and tracking GitHub Actions in the tree view.
15
+ * Branching children will be automatically setup and included to track actions, jobs, and steps.
16
+ */
17
+ class ActionsItemBase {
18
+ parentId;
19
+ contextValueExtensionPrefix;
20
+ static contextValueSuffix = 'ActionsItem';
21
+ static connectedContextValue = 'actionsConnected:true';
22
+ static unconnectedContextValue = 'actionsConnected:false';
23
+ static idSuffix = 'actions';
24
+ /**
25
+ * @param parentId A unique identifier corresponding to the id of the parent tree node
26
+ * @param contextValueExtensionPrefix The extension prefix used in constructing context values for the 'ActionsItem'
27
+ * and its children. Passing 'containerApps' becomes `containerApps${ActionsItemBase.contextValueSuffix}`.
28
+ */
29
+ constructor(parentId, contextValueExtensionPrefix) {
30
+ this.parentId = parentId;
31
+ this.contextValueExtensionPrefix = contextValueExtensionPrefix;
32
+ }
33
+ /**
34
+ * Constructed using the format: `${this.parentId}/${ActionsTreeItemBase.idSuffix}`
35
+ */
36
+ get id() {
37
+ return `${this.parentId}/${ActionsItemBase.idSuffix}`;
38
+ }
39
+ label = 'Actions';
40
+ getContextValue(isConnected) {
41
+ const actionsTreeItemContextValue = `${this.contextValueExtensionPrefix}${ActionsItemBase.contextValueSuffix}`;
42
+ const values = [actionsTreeItemContextValue];
43
+ values.push(isConnected ? ActionsItemBase.connectedContextValue : ActionsItemBase.unconnectedContextValue);
44
+ return (0, vscode_azext_utils_1.createContextValue)(values);
45
+ }
46
+ async getTreeItem() {
47
+ const isConnected = !!await this.getSourceControl();
48
+ return {
49
+ id: this.id,
50
+ label: this.label,
51
+ description: isConnected ? vscode_1.l10n.t('Connected') : '',
52
+ iconPath: new vscode_1.ThemeIcon('github-inverted'),
53
+ contextValue: this.getContextValue(isConnected),
54
+ collapsibleState: vscode_1.TreeItemCollapsibleState.Collapsed,
55
+ };
56
+ }
57
+ async getChildren() {
58
+ const sourceControl = await this.getSourceControl();
59
+ const actionsListWorkflowRuns = await (0, vscode_azext_utils_1.callWithTelemetryAndErrorHandling)('getActionsChildren', async (context) => {
60
+ if (!sourceControl) {
61
+ return undefined;
62
+ }
63
+ const { ownerOrOrganization, repositoryName } = (0, gitHubUrlParse_1.gitHubUrlParse)(sourceControl.repoUrl);
64
+ const actionWorkflowRunsParams = {
65
+ owner: (0, vscode_azext_utils_1.nonNullValue)(ownerOrOrganization),
66
+ repo: (0, vscode_azext_utils_1.nonNullValue)(repositoryName),
67
+ branch: sourceControl.repoBranch ?? 'main',
68
+ page: 1,
69
+ };
70
+ context.errorHandling.suppressDisplay = true;
71
+ return await (0, getActions_1.getActions)(context, actionWorkflowRunsParams);
72
+ });
73
+ if (actionsListWorkflowRuns?.total_count) {
74
+ return actionsListWorkflowRuns.workflow_runs.map((awr) => new ActionItem_1.ActionItem(this.id, this.contextValueExtensionPrefix, awr));
75
+ }
76
+ else if (sourceControl) {
77
+ // If we are able to detect a connection but fail to retrieve a list of actions
78
+ return [
79
+ (0, vscode_azext_utils_1.createGenericElement)({
80
+ contextValue: 'noActionsDetected',
81
+ id: `${this.parentId}/noActionsDetected`,
82
+ label: vscode_1.l10n.t('No actions detected'),
83
+ })
84
+ ];
85
+ }
86
+ else {
87
+ let command;
88
+ if (this.getConnectToGitHubCommand) {
89
+ command = await this.getConnectToGitHubCommand();
90
+ }
91
+ return [
92
+ (0, vscode_azext_utils_1.createGenericElement)({
93
+ contextValue: 'connectToGitHub',
94
+ id: `${this.parentId}/connectToGitHub`,
95
+ label: vscode_1.l10n.t('Connect to a GitHub Repository...'),
96
+ commandId: command?.commandId,
97
+ commandArgs: command?.commandArgs
98
+ })
99
+ ];
100
+ }
101
+ }
102
+ }
103
+ exports.ActionsItemBase = ActionsItemBase;
104
+ //# 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
  }
@@ -3,28 +3,29 @@
3
3
  * Copyright (c) Microsoft Corporation. All rights reserved.
4
4
  * Licensed under the MIT License. See License.txt in the project root for license information.
5
5
  *--------------------------------------------------------------------------------------------*/
6
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8
- return new (P || (P = Promise))(function (resolve, reject) {
9
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
10
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
12
- step((generator = generator.apply(thisArg, _arguments || [])).next());
13
- });
14
- };
15
6
  Object.defineProperty(exports, "__esModule", { value: true });
16
7
  exports.JobItem = void 0;
17
8
  const vscode_1 = require("vscode");
18
9
  const actionUtils_1 = require("../utils/actionUtils");
19
10
  const StepItem_1 = require("./StepItem");
20
11
  class JobItem {
12
+ parentResourceId;
13
+ extensionPrefixContextValue;
14
+ job;
15
+ static contextValueSuffix = 'JobItem';
21
16
  constructor(parentResourceId, extensionPrefixContextValue, job) {
22
17
  this.parentResourceId = parentResourceId;
23
18
  this.extensionPrefixContextValue = extensionPrefixContextValue;
24
19
  this.job = job;
25
- this.id = `${this.parentResourceId}/jobs/${this.job.id}`;
26
- this.label = this.job.name || this.id;
27
- this.viewProperties = {
20
+ }
21
+ get id() {
22
+ return `${this.parentResourceId}/jobs/${this.job.id}`;
23
+ }
24
+ get label() {
25
+ return this.job.name || this.id;
26
+ }
27
+ get viewProperties() {
28
+ return {
28
29
  data: this.job,
29
30
  label: this.label,
30
31
  };
@@ -39,13 +40,9 @@ class JobItem {
39
40
  collapsibleState: vscode_1.TreeItemCollapsibleState.Collapsed,
40
41
  };
41
42
  }
42
- getChildren() {
43
- var _a, _b;
44
- return __awaiter(this, void 0, void 0, function* () {
45
- return (_b = (_a = this.job.steps) === null || _a === void 0 ? void 0 : _a.map((step) => new StepItem_1.StepItem(this.id, this.extensionPrefixContextValue, step))) !== null && _b !== void 0 ? _b : [];
46
- });
43
+ async getChildren() {
44
+ return this.job.steps?.map((step) => new StepItem_1.StepItem(this.id, this.extensionPrefixContextValue, step)) ?? [];
47
45
  }
48
46
  }
49
47
  exports.JobItem = JobItem;
50
- JobItem.contextValueSuffix = 'JobItem';
51
48
  //# 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
  }
@@ -7,13 +7,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.StepItem = void 0;
8
8
  const actionUtils_1 = require("../utils/actionUtils");
9
9
  class StepItem {
10
+ parentResourceId;
11
+ extensionPrefixContextValue;
12
+ step;
13
+ static contextValueSuffix = 'StepItem';
10
14
  constructor(parentResourceId, extensionPrefixContextValue, step) {
11
15
  this.parentResourceId = parentResourceId;
12
16
  this.extensionPrefixContextValue = extensionPrefixContextValue;
13
17
  this.step = step;
14
- this.id = `${this.parentResourceId}/steps/${this.step.number}`;
15
- this.label = this.step.name;
16
- this.viewProperties = {
18
+ }
19
+ get id() {
20
+ return `${this.parentResourceId}/steps/${this.step.number}`;
21
+ }
22
+ get label() {
23
+ return this.step.name;
24
+ }
25
+ get viewProperties() {
26
+ return {
17
27
  data: this.step,
18
28
  label: this.step.name,
19
29
  };
@@ -29,5 +39,4 @@ class StepItem {
29
39
  }
30
40
  }
31
41
  exports.StepItem = StepItem;
32
- StepItem.contextValueSuffix = 'StepItem';
33
42
  //# sourceMappingURL=StepItem.js.map
@@ -3,14 +3,19 @@
3
3
  * Copyright (c) Microsoft Corporation. All rights reserved.
4
4
  * Licensed under the MIT License. See License.txt in the project root for license information.
5
5
  *--------------------------------------------------------------------------------------------*/
6
+ var __importDefault = (this && this.__importDefault) || function (mod) {
7
+ return (mod && mod.__esModule) ? mod : { "default": mod };
8
+ };
6
9
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.getActionBasedIconPath = exports.getJobBasedDescription = exports.Status = exports.Conclusion = void 0;
10
+ exports.Status = exports.Conclusion = void 0;
11
+ exports.getJobBasedDescription = getJobBasedDescription;
12
+ exports.getActionBasedIconPath = getActionBasedIconPath;
8
13
  const vscode_azext_utils_1 = require("@microsoft/vscode-azext-utils");
9
- const dayjs = require("dayjs");
14
+ const dayjs_1 = __importDefault(require("dayjs"));
10
15
  // eslint-disable-next-line import/no-internal-modules
11
- const relativeTime = require("dayjs/plugin/relativeTime");
16
+ const relativeTime_1 = __importDefault(require("dayjs/plugin/relativeTime"));
12
17
  const vscode_1 = require("vscode");
13
- dayjs.extend(relativeTime);
18
+ dayjs_1.default.extend(relativeTime_1.default);
14
19
  /**
15
20
  * GitHub 'Check Run' - final conclusion of the check
16
21
  * https://developer.github.com/v3/checks/runs/#parameters
@@ -40,16 +45,15 @@ var Status;
40
45
  function getJobBasedDescription(data) {
41
46
  if (data.conclusion !== null) {
42
47
  const conclusion = convertConclusionToVerb((0, vscode_azext_utils_1.nonNullProp)(data, 'conclusion'));
43
- const completedAt = dayjs(data.completed_at).fromNow();
48
+ const completedAt = (0, dayjs_1.default)(data.completed_at).fromNow();
44
49
  return `${conclusion} ${completedAt}`;
45
50
  }
46
51
  else {
47
52
  const status = convertStatusToVerb((0, vscode_azext_utils_1.nonNullProp)(data, 'status'));
48
- const startedAt = !data.started_at ? vscode_1.l10n.t('now') : dayjs(data.started_at).fromNow();
53
+ const startedAt = !data.started_at ? vscode_1.l10n.t('now') : (0, dayjs_1.default)(data.started_at).fromNow();
49
54
  return `${status} ${startedAt}`;
50
55
  }
51
56
  }
52
- exports.getJobBasedDescription = getJobBasedDescription;
53
57
  /**
54
58
  * Select an icon based on its Action-related status.
55
59
  *
@@ -97,7 +101,6 @@ function getActionBasedIconPath(data) {
97
101
  }
98
102
  return new vscode_1.ThemeIcon(id, colorId ? new vscode_1.ThemeColor(colorId) : undefined);
99
103
  }
100
- exports.getActionBasedIconPath = getActionBasedIconPath;
101
104
  // Helpers...
102
105
  function convertConclusionToVerb(conclusion) {
103
106
  switch (conclusion) {
@@ -0,0 +1,30 @@
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.getGitHubAccessToken = getGitHubAccessToken;
8
+ const vscode_azext_utils_1 = require("@microsoft/vscode-azext-utils");
9
+ const vscode_1 = require("vscode");
10
+ const constants_1 = require("../constants");
11
+ async function getGitHubAccessToken() {
12
+ try {
13
+ const token = (await vscode_1.authentication.getSession(constants_1.gitHubAuthProviderId, constants_1.gitHubScopes, { createIfNone: true })).accessToken;
14
+ // Workaround for VS Code returning a different token when connected to a CodeSpace in a browser
15
+ // see https://github.com/microsoft/vscode-azurestaticwebapps/issues/827#issuecomment-1597881084 for details
16
+ if (token.startsWith('ghu_')) {
17
+ // Request a fake scope to force VS Code to give us a token of the right type
18
+ return (await vscode_1.authentication.getSession(constants_1.gitHubAuthProviderId, [...constants_1.gitHubScopes, 'x-AzToolsScope'], { createIfNone: true })).accessToken;
19
+ }
20
+ return token;
21
+ }
22
+ catch (error) {
23
+ // The error message is "User did not consent to login"
24
+ if (/did not consent/i.test((0, vscode_azext_utils_1.parseError)(error).message)) {
25
+ throw new vscode_azext_utils_1.UserCancelledError('getGitHubToken');
26
+ }
27
+ throw error;
28
+ }
29
+ }
30
+ //# sourceMappingURL=getGitHubAccessToken.js.map
@@ -4,20 +4,18 @@
4
4
  * Licensed under the MIT License. See License.txt in the project root for license information.
5
5
  *--------------------------------------------------------------------------------------------*/
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.gitHubUrlParse = void 0;
7
+ exports.gitHubUrlParse = gitHubUrlParse;
8
8
  /**
9
9
  * A minimal utility function for parsing a full GitHub URL into its constituent parts
10
10
  * @params url A complete GitHub repository URL
11
11
  * @example 'https://github.com/microsoft/foo-bar'
12
12
  */
13
13
  function gitHubUrlParse(url) {
14
- var _a, _b;
15
14
  const match = url.match(/github\.com\/(?<ownerOrOrganization>[^/]+)\/(?<repositoryName>[^/]+)/i);
16
15
  return {
17
16
  urlReference: url,
18
- ownerOrOrganization: (_a = match === null || match === void 0 ? void 0 : match.groups) === null || _a === void 0 ? void 0 : _a.ownerOrOrganization,
19
- repositoryName: (_b = match === null || match === void 0 ? void 0 : match.groups) === null || _b === void 0 ? void 0 : _b.repositoryName
17
+ ownerOrOrganization: match?.groups?.ownerOrOrganization,
18
+ repositoryName: match?.groups?.repositoryName
20
19
  };
21
20
  }
22
- exports.gitHubUrlParse = gitHubUrlParse;
23
21
  //# sourceMappingURL=gitHubUrlParse.js.map
@@ -0,0 +1,59 @@
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.GitHubBranchListStep = 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 getBranches_1 = require("../wrappers/getBranches");
12
+ /**
13
+ * Used to prompt the user for the GitHub repository branch
14
+ * @prerequisites gitHubRepository, gitHubRepositoryOwner
15
+ * @populates gitHubBranch
16
+ */
17
+ class GitHubBranchListStep 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 branch');
23
+ let page = 0;
24
+ while (!context.gitHubBranch) {
25
+ page++;
26
+ context.gitHubBranch = (await context.ui.showQuickPick(this.getPicks(context, page), { placeHolder })).data;
27
+ }
28
+ context.valuesToMask.push(context.gitHubBranch);
29
+ }
30
+ shouldPrompt(context) {
31
+ return !context.gitHubBranch;
32
+ }
33
+ async getPicks(context, page) {
34
+ const perPage = 50;
35
+ const branchParams = {
36
+ owner: (0, vscode_azext_utils_1.nonNullProp)(context, 'gitHubRepositoryOwner'),
37
+ repo: (0, vscode_azext_utils_1.nonNullProp)(context, 'gitHubRepository'),
38
+ per_page: perPage,
39
+ page
40
+ };
41
+ const branches = await (0, getBranches_1.getBranches)(context, branchParams);
42
+ this.picks.push(...branches.map((branch) => { return { label: branch.name, data: branch.name }; }));
43
+ this.picks.sort((a, b) => {
44
+ if (a.label === 'main' || a.label === 'master') {
45
+ return -1;
46
+ }
47
+ else if (b.label === 'main' || b.label === 'master') {
48
+ return 1;
49
+ }
50
+ else {
51
+ return a.label.localeCompare(b.label);
52
+ }
53
+ });
54
+ const maxAvailablePicks = perPage * page;
55
+ return maxAvailablePicks === this.picks.length ? [...this.picks, constants_1.loadMoreQp] : this.picks;
56
+ }
57
+ }
58
+ exports.GitHubBranchListStep = GitHubBranchListStep;
59
+ //# sourceMappingURL=GitHubBranchListStep.js.map
@@ -0,0 +1,39 @@
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.GitHubOrgListStep = void 0;
8
+ const vscode_azext_utils_1 = require("@microsoft/vscode-azext-utils");
9
+ const vscode_1 = require("vscode");
10
+ const getAuthenticatedUser_1 = require("../wrappers/getAuthenticatedUser");
11
+ const getOrgs_1 = require("../wrappers/getOrgs");
12
+ /**
13
+ * Used to prompt the user for the repository's GitHub organization
14
+ * @populates gitHubOrg
15
+ */
16
+ class GitHubOrgListStep extends vscode_azext_utils_1.AzureWizardPromptStep {
17
+ async prompt(context) {
18
+ const placeHolder = vscode_1.l10n.t('Select an organization');
19
+ context.gitHubOrg = (await context.ui.showQuickPick(this.getPicks(context), { placeHolder })).data;
20
+ if (context.gitHubOrg) {
21
+ context.valuesToMask.push(context.gitHubOrg);
22
+ }
23
+ }
24
+ shouldPrompt(context) {
25
+ return !context.gitHubOrg;
26
+ }
27
+ async getPicks(context) {
28
+ const user = await (0, getAuthenticatedUser_1.getAuthenticatedUser)(context);
29
+ const orgs = await (0, getOrgs_1.getOrgs)(context);
30
+ return [
31
+ { label: user.login, data: undefined },
32
+ ...orgs.map((org) => {
33
+ return { label: org.login, data: org.login };
34
+ })
35
+ ];
36
+ }
37
+ }
38
+ exports.GitHubOrgListStep = GitHubOrgListStep;
39
+ //# sourceMappingURL=GitHubOrgListStep.js.map