Skip to content

Commit 9e9b3ec

Browse files
committed
Support new authentication API
1 parent 6d6cddb commit 9e9b3ec

File tree

9 files changed

+13086
-75
lines changed

9 files changed

+13086
-75
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
All notable changes to the "vscode-github-actions" extension will be documented in this file.
44

5+
## [v0.5.0]
6+
- Support the VS Code authentication API. This replaces the previous, manual PAT-based authentication flow.
7+
58
## [v0.4.1]
69
- Add inline run button to workflow list
710

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Simple, **unofficial** extension to interact with GitHub Actions from within VS
88

99
1. Install extension
1010
2. Open a repository with a `github.com` origin
11-
3. When prompted, enter a PAT with `repo` scope to authenticate against the API
11+
3. When prompted, allow `GitHub Actions` to access your `github` account
1212

1313
## Features
1414

package.json

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,24 @@
77
"url": "https://github.com/cschleiden/vscode-github-actions"
88
},
99
"description": "See GitHub Actions workflows and runs for github.com hosted repositories in VS Code",
10-
"version": "0.4.1",
10+
"version": "0.5.0",
1111
"engines": {
1212
"vscode": "^1.44.0"
1313
},
1414
"categories": [
1515
"Other"
1616
],
1717
"activationEvents": [
18-
"onCommand:auth.login",
1918
"onView:workflows",
2019
"onView:settings",
2120
"workspaceContains:**/.github/workflows/**"
2221
],
2322
"main": "./dist/extension",
2423
"extensionDependencies": [
25-
"vscode.git"
24+
"vscode.git",
25+
"vscode.github-authentication"
2626
],
27+
"enableProposedApi": true,
2728
"contributes": {
2829
"configuration": {
2930
"title": "GitHub Actions",
@@ -48,11 +49,6 @@
4849
}
4950
},
5051
"commands": [
51-
{
52-
"command": "auth.login",
53-
"title": "Login",
54-
"category": "GitHub Actions"
55-
},
5652
{
5753
"command": "explorer.refresh",
5854
"title": "Refresh",
@@ -252,7 +248,7 @@
252248
"clean": "rimraf ./dist ./out",
253249
"compile": "tsc -p ./",
254250
"watch": "tsc -watch -p ./",
255-
"package": "npm run clean && npm version patch --no-git-tag-version && vsce package",
251+
"package": "npm run clean && vsce package",
256252
"vscode:prepublish": "webpack --mode production",
257253
"webpack": "webpack --mode development",
258254
"webpack-dev": "webpack --mode development --watch",

src/auth/pat.ts

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,29 @@
1-
import * as keytarType from "keytar";
2-
import { env } from "vscode";
1+
import * as vscode from "vscode";
32

4-
declare const __webpack_require__: typeof require;
5-
declare const __non_webpack_require__: typeof require;
6-
function getNodeModule<T>(moduleName: string): T | undefined {
7-
const r =
8-
typeof __webpack_require__ === "function"
9-
? __non_webpack_require__
10-
: require;
11-
try {
12-
return r(`${env.appRoot}/node_modules.asar/${moduleName}`);
13-
} catch (err) {
14-
// Not in ASAR.
15-
}
16-
try {
17-
return r(`${env.appRoot}/node_modules/${moduleName}`);
18-
} catch (err) {
19-
// Not available.
20-
}
21-
return undefined;
22-
}
23-
24-
function getKeytar(): typeof keytarType {
25-
const keytar = getNodeModule<typeof keytarType>("keytar");
26-
if (!keytar) {
27-
throw new Error("Keytar module for secure token storage not found");
28-
}
3+
const AUTH_PROVIDER_ID = "github";
4+
const SCOPES = ["repo", "workflows"];
295

30-
return keytar;
31-
}
32-
33-
const ServiceName = "VS Code GitHub Actions";
6+
let token: Promise<string> | undefined;
347

358
export async function getPAT(): Promise<string | null> {
36-
return getKeytar().getPassword(ServiceName, "pat");
37-
}
9+
if (token) {
10+
return token;
11+
}
12+
13+
return (token = new Promise(async (resolve) => {
14+
const existingSessions = await vscode.authentication.getSessions(
15+
AUTH_PROVIDER_ID,
16+
SCOPES
17+
);
3818

39-
export async function setPAT(token: string): Promise<void> {
40-
return getKeytar().setPassword(ServiceName, "pat", token);
19+
if (existingSessions.length) {
20+
resolve(await existingSessions[0].getAccessToken());
21+
} else {
22+
const session = await vscode.authentication.login(
23+
AUTH_PROVIDER_ID,
24+
SCOPES
25+
);
26+
resolve(await session.getAccessToken());
27+
}
28+
}));
4129
}

src/extension.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Octokit } from "@octokit/rest";
22
import * as vscode from "vscode";
3-
import { setPAT } from "./auth/pat";
43
import { getClient } from "./client/client";
54
import { initConfiguration } from "./configuration/configuration";
65
import { Protocol } from "./external/protocol";
@@ -146,29 +145,6 @@ export function activate(context: vscode.ExtensionContext) {
146145
})
147146
);
148147

149-
context.subscriptions.push(
150-
vscode.commands.registerCommand("auth.login", async () => {
151-
// Disable this until service setup
152-
// const selection = await vscode.window.showQuickPick([
153-
// "Enter PAT",
154-
// "Use OAuth flow (coming soon)"
155-
// ]);
156-
157-
const selection = "Enter PAT";
158-
switch (selection) {
159-
case "Enter PAT":
160-
const token = await vscode.window.showInputBox({
161-
prompt: "Enter a GitHub PAT with `workflow` and `repo` scope:",
162-
});
163-
if (token) {
164-
await setPAT(token);
165-
workflowTreeProvider.refresh();
166-
}
167-
break;
168-
}
169-
})
170-
);
171-
172148
context.subscriptions.push(
173149
vscode.commands.registerCommand("workflow.run.open", async (args) => {
174150
const run: WorkflowRun = args.run;

src/treeViews/settings.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,11 @@ type SettingsExplorerNode = SelfHostedRunnersNode | SecretsNode | SecretNode;
6464

6565
export class SettingsTreeProvider
6666
implements vscode.TreeDataProvider<SettingsExplorerNode> {
67-
private _onDidChangeTreeData = new vscode.EventEmitter<
68-
SettingsExplorerNode
69-
>();
67+
private _onDidChangeTreeData = new vscode.EventEmitter<SettingsExplorerNode | null>();
7068
readonly onDidChangeTreeData = this._onDidChangeTreeData.event;
7169

7270
refresh(): void {
73-
this._onDidChangeTreeData.fire();
71+
this._onDidChangeTreeData.fire(null);
7472
}
7573

7674
getTreeItem(

src/treeViews/workflows.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,11 @@ type ActionsExplorerNode =
203203

204204
export class ActionsExplorerProvider
205205
implements vscode.TreeDataProvider<ActionsExplorerNode> {
206-
private _onDidChangeTreeData = new vscode.EventEmitter<ActionsExplorerNode>();
206+
private _onDidChangeTreeData = new vscode.EventEmitter<ActionsExplorerNode | null>();
207207
readonly onDidChangeTreeData = this._onDidChangeTreeData.event;
208208

209209
refresh(): void {
210-
this._onDidChangeTreeData.fire();
210+
this._onDidChangeTreeData.fire(null);
211211
}
212212

213213
getTreeItem(

0 commit comments

Comments
 (0)