From 49ab8cc61e49ffb6d3cefe0df0b5eecb9a859d79 Mon Sep 17 00:00:00 2001 From: Carlos McEvilly <12955+carlosmcevilly@users.noreply.github.com> Date: Fri, 10 Jan 2025 16:58:45 -0800 Subject: [PATCH] Feature/demrum 440 dsyms list command (#61) * DEMRUM-439: add initial iOSInputValidations * DEMRUM-439: implement iOS dSYMs upload * DEMRUM-440: implement list command * DEMRUM-440: restore listdSYMsDescription * DEMRUM-439: remove unused validations * DEMRUM-439: remove unused fields * DEMRUM-440: restore axios import * DEMRUM-440: fix missing semicolon * DEMRUM-440: remove now-unused iOSInputValidations.ts * DEMRUM-440: add basic iOS unit test * DEMRUM-440: remove misplaced iOSCommand.parse() call * DEMRUM: 440: restore debug option --- src/commands/ios.ts | 37 +++++++++++++++++++++++++++++++------ test/commands/ios.test.ts | 23 +++++++++++++++++++++++ 2 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 test/commands/ios.test.ts diff --git a/src/commands/ios.ts b/src/commands/ios.ts index a369bfa..a0c5ee3 100644 --- a/src/commands/ios.ts +++ b/src/commands/ios.ts @@ -21,6 +21,7 @@ import { } from '../utils/inputValidations'; import { UserFriendlyError } from '../utils/userFriendlyErrors'; import { createLogger, LogLevel } from '../utils/logger'; +import axios from 'axios'; import { uploadFile } from '../utils/httpUtils'; // Constants @@ -35,10 +36,9 @@ export const iOSCommand = new Command('iOS'); const iOSUploadDescription = `This subcommand uploads the specified zipped dSYMs file. `; -interface UploadiOSOptions { - 'file': string, - 'debug'?: boolean -} +const listdSYMsDescription = `This command retrieves and shows a list of the uploaded dSYM files. +By default, it returns the last 100 dSYM files uploaded, sorted in reverse chronological order based on the upload timestamp. +`; const generateUrl = (): string => { const realm = process.env.O11Y_REALM || DEFAULT_REALM; @@ -49,6 +49,11 @@ iOSCommand .name('ios') .description('Upload and list zipped iOS symbolication files (dSYMs)'); +interface UploadiOSOptions { + file: string; + debug?: boolean; +} + iOSCommand .command('upload') .showHelpAfterError(true) @@ -75,9 +80,7 @@ iOSCommand }; const url = generateUrl(); - logger.info(`url: ${url}`); - logger.info(`Preparing to upload dSYMs file: ${options.file}`); await uploadFile({ @@ -98,3 +101,25 @@ iOSCommand } } }); + + +iOSCommand + .command('list') + .summary('Retrieves list of metadata of all uploaded dSYM files') + .showHelpAfterError(true) + .description(listdSYMsDescription) + .option('--debug', 'Enable debug logs') + .action(async (options) => { + const logger = createLogger(options.debug ? LogLevel.DEBUG : LogLevel.INFO); + const url = `${API_BASE_URL}/${API_VERSION_STRING}/${API_PATH}`; + + try { + logger.info('Fetching dSYM file data'); + const response = await axios.get(url); + logger.info('Raw Response Data:', JSON.stringify(response.data, null, 2)); + } catch (error) { + logger.error('Failed to fetch the list of uploaded files'); + throw error; + } + }); + diff --git a/test/commands/ios.test.ts b/test/commands/ios.test.ts new file mode 100644 index 0000000..292f9f6 --- /dev/null +++ b/test/commands/ios.test.ts @@ -0,0 +1,23 @@ +/* + * Copyright Splunk Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +import { iOSCommand } from '../../src/commands/ios'; + +describe('ios command', () => { + test('has multiple sub-commands', () => { + expect(iOSCommand.commands.length).toBe(2); + }); +});