Skip to content

Commit 8ea1b96

Browse files
committed
Update code
1 parent 69c7ece commit 8ea1b96

File tree

3 files changed

+21
-50
lines changed

3 files changed

+21
-50
lines changed

src/commands/update.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const UpdateCommand =
88
class GithubUpdatecommand extends UpdateCommand {
99
async run() {
1010
const { printTable } = await import('@oclif/table');
11-
const { args, flags } = await this.parse(UpdateCommand);
11+
const { flags } = await this.parse(UpdateCommand);
1212
const updater = new GitHubUpdater(this.config);
1313
if (flags.available) {
1414
const index = await updater.fetchVersionIndex();
@@ -30,12 +30,7 @@ class GithubUpdatecommand extends UpdateCommand {
3030
return;
3131
}
3232

33-
if (args.channel && flags.version) {
34-
this.error('You cannot specify both a version and a channel.');
35-
}
36-
3733
updater.runUpdate({
38-
channel: args.channel,
3934
autoUpdate: flags.autoupdate,
4035
force: flags.force,
4136
version: flags.interactive

src/github-updater.js

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,15 @@ const { Updater } = require('@oclif/plugin-update/lib/update');
77
const debug = makeDebug('oclif:update:github');
88

99
let octokitInstance = null;
10-
let octokitClass = null;
11-
12-
async function loadOctokit() {
13-
if (!octokitClass) {
14-
const { Octokit } = await import('@octokit/rest');
15-
octokitClass = Octokit;
16-
}
17-
return octokitClass;
18-
}
1910

2011
async function getOctokit() {
2112
if (!octokitInstance) {
22-
octokitClass = await loadOctokit();
23-
return new octokitClass({
13+
const { Octokit } = await import('@octokit/rest');
14+
octokitInstance = new Octokit({
2415
auth: process.env.GITHUB_TOKEN || process.env.GH_TOKEN,
2516
});
2617
}
18+
return octokitInstance;
2719
}
2820

2921
function checkGitHubConfig(config) {
@@ -90,8 +82,7 @@ class GitHubUpdater extends Updater {
9082
return;
9183
}
9284

93-
const channel =
94-
options.channel || (await this.determineChannel(version));
85+
const channel = 'stable';
9586
const current = await this.determineCurrentVersion();
9687

9788
if (version) {
@@ -138,7 +129,7 @@ class GitHubUpdater extends Updater {
138129
`Updating to a specific version will not update the channel. If autoupdate is enabled, the CLI will eventually be updated back to ${channel}.`
139130
);
140131
} else {
141-
const manifest = await this.fetchGitHubChannelManifest(channel);
132+
const manifest = await this.fetchGitHubManifest();
142133
const updated = manifest.sha
143134
? `${manifest.version}-${manifest.sha}`
144135
: manifest.version;
@@ -210,32 +201,19 @@ class GitHubUpdater extends Updater {
210201
}
211202
}
212203

213-
// GitHub-specific channel manifest fetching
214-
async fetchGitHubChannelManifest(channel) {
204+
// GitHub-specific manifest fetching (always fetches latest stable release)
205+
async fetchGitHubManifest() {
215206
await this.ensureOctokit();
216207
ux.action.status = 'fetching manifest from GitHub';
217208

218209
const { owner, repo } = this.githubConfig;
219210

220211
try {
221-
let release;
222-
223-
if (channel === 'stable') {
224-
debug(`Fetching latest release for ${owner}/${repo}`);
225-
const { data } = await this.octokit.repos.getLatestRelease({
226-
owner,
227-
repo,
228-
});
229-
release = data;
230-
} else {
231-
debug(`Fetching release ${channel} for ${owner}/${repo}`);
232-
const { data } = await this.octokit.repos.getReleaseByTag({
233-
owner,
234-
repo,
235-
tag: channel,
236-
});
237-
release = data;
238-
}
212+
debug(`Fetching latest release for ${owner}/${repo}`);
213+
const { data: release } = await this.octokit.repos.getLatestRelease({
214+
owner,
215+
repo,
216+
});
239217

240218
const version = release.tag_name.replace(/^v/u, '');
241219
const assetName = this.determineAssetName(version);
@@ -257,7 +235,7 @@ class GitHubUpdater extends Updater {
257235
const statusCode = error.status;
258236
if (statusCode === 404) {
259237
throw new Error(
260-
`Release not found for channel "${channel}" in ${owner}/${repo}`
238+
`Release not found in ${owner}/${repo}`
261239
);
262240
}
263241

test/github-updater.test.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,8 @@ describe('GitHubUpdater', function () {
562562
});
563563
});
564564

565-
describe('fetchGitHubChannelManifest', function () {
566-
it('should fetch latest release manifest for stable channel', async function () {
565+
describe('fetchGitHubManifest', function () {
566+
it('should fetch latest release manifest', async function () {
567567
const mockConfig = createMockConfig({
568568
pjson: {
569569
oclif: {
@@ -591,8 +591,7 @@ describe('GitHubUpdater', function () {
591591
};
592592
updater.octokit = mockOctokit;
593593

594-
const manifest =
595-
await updater.fetchGitHubChannelManifest('stable');
594+
const manifest = await updater.fetchGitHubManifest();
596595

597596
assert.isObject(manifest);
598597
assert.equal(manifest.version, '4.4.1');
@@ -602,7 +601,7 @@ describe('GitHubUpdater', function () {
602601
);
603602
});
604603

605-
it('should fetch specific tag release manifest', async function () {
604+
it('should fetch correct asset for different architectures', async function () {
606605
const mockConfig = createMockConfig({
607606
pjson: {
608607
oclif: {
@@ -623,15 +622,14 @@ describe('GitHubUpdater', function () {
623622

624623
const mockOctokit = {
625624
repos: {
626-
getReleaseByTag: sinon
625+
getLatestRelease: sinon
627626
.stub()
628627
.resolves({ data: mockReleaseData[0] }),
629628
},
630629
};
631630
updater.octokit = mockOctokit;
632631

633-
const manifest =
634-
await updater.fetchGitHubChannelManifest('v4.4.1');
632+
const manifest = await updater.fetchGitHubManifest();
635633

636634
assert.isObject(manifest);
637635
assert.equal(manifest.version, '4.4.1');
@@ -670,7 +668,7 @@ describe('GitHubUpdater', function () {
670668
updater.octokit = mockOctokit;
671669

672670
try {
673-
await updater.fetchGitHubChannelManifest('stable');
671+
await updater.fetchGitHubManifest();
674672
assert.fail('Should have thrown an error');
675673
} catch (error) {
676674
assert.include(error.message, 'No suitable asset found');

0 commit comments

Comments
 (0)