Skip to content

Commit

Permalink
Merge pull request #20 from sshveta/fetch_from_default_url
Browse files Browse the repository at this point in the history
Fetch VSIX from default URL if builtURL gives 404 error
  • Loading branch information
sshveta authored Oct 29, 2024
2 parents f814824 + aea24b8 commit 90bebe9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
VSCODE_EXECUTABLE_PATH='/usr/share/code/code'
VSIX_FILE_PATH='/home/sshveta/Work/kai-ci/'
VSIX_FILE_NAME='konveyor-linux-0.0.1.vsix'
VSIX_DOWNLOAD_URL= 'https://github.com/konveyor/editor-extensions/releases/download/v0.0.1-dev%2B20241017/konveyor-linux-0.0.1.vsix'
VSIX_DOWNLOAD_URL= 'https://github.com/konveyor/editor-extensions/releases/download/v0.0.1-dev%2B20241022/konveyor-linux-0.0.1.vsix'
PLUGIN_URL= 'https://github.com/konveyor/editor-extensions/releases/download/'
PLUGIN_VERSION= 'v0.0.1-dev%2B'

Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ Install the required packages using npm:
Create .env file and copy the content of .env.example into it and provide appropriate values:

VSCODE_EXECUTABLE_PATH='/usr/share/code/code'
VSIX_FILE_PATH='/home/sshveta/Downloads/kai-vscode-plugin-0.0.3.vsix'

# Path to Save the vsix file
VSIX_FILE_PATH="/home/sshveta/Work/kai-ci/"

# URL to download the vsix file, update this if the URL is different.
VSIX_DOWNLOAD_URL= 'https://github.com/konveyor/editor-extensions/releases/download/v0.0.1-dev%2B20241022/konveyor-linux-0.0.1.vsix'


## Running Tests

Expand Down
34 changes: 27 additions & 7 deletions e2e/utilities/download.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,10 @@ import { getKAIPluginPath, getOSInfo, getKAIPluginName } from './utils';
export async function downloadFile(): Promise<void> {
const outputLocationPath = getKAIPluginPath();
const fileUrl = buildDownloadUrl();
const defaultUrl = process.env.VSIX_DOWNLOAD_URL;

const writer = fs.createWriteStream(outputLocationPath);

const response = await axios({
url: fileUrl,
method: 'GET',
responseType: 'stream',
});

const response = await fetchUrl(fileUrl, defaultUrl);
response.data.pipe(writer);

return new Promise((resolve, reject) => {
Expand All @@ -28,6 +23,31 @@ export async function downloadFile(): Promise<void> {
});
}

async function fetchUrl(fileUrl, defaultUrl) {
try {
const response = await axios({
url: fileUrl,
method: 'GET',
responseType: 'stream',
});
return response;
} catch (error) {
// Check if the error is a 404
if (error.response && error.response.status === 404) {
console.log('404 error, using default URL:', defaultUrl);
const response = await axios({
url: defaultUrl,
method: 'GET',
responseType: 'stream',
});
return response;
} else {
console.error('Error fetching URL:', error);
throw error;
}
}
}

export async function downloadLatestKAIPlugin() {
try {
await downloadFile();
Expand Down

0 comments on commit 90bebe9

Please sign in to comment.