-
-
Notifications
You must be signed in to change notification settings - Fork 240
feat(code-mappings): Add code-mappings upload command scaffold
#3207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+217
−0
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
029aeaf
feat(cli): Add `code-mappings upload` command scaffold with file parsing
romtsn 072fa6b
fix(test): Update help snapshots with code-mappings subcommand
romtsn 8acfdbe
fix(code-mappings): Address PR feedback on help text and unwrap usage
romtsn 1015af1
fix(code-mappings): Update top-level help snapshot for new description
romtsn 811bb94
fix(code-mappings): Update Windows help snapshot for new description
romtsn 387d605
ref(code-mappings): Remove unused Serialize derive from CodeMapping
romtsn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| use anyhow::Result; | ||
| use clap::{ArgMatches, Command}; | ||
|
|
||
| use crate::utils::args::ArgExt as _; | ||
|
|
||
| pub mod upload; | ||
|
|
||
| macro_rules! each_subcommand { | ||
| ($mac:ident) => { | ||
| $mac!(upload); | ||
| }; | ||
| } | ||
|
|
||
| pub fn make_command(mut command: Command) -> Command { | ||
| macro_rules! add_subcommand { | ||
| ($name:ident) => {{ | ||
| command = command.subcommand(crate::commands::code_mappings::$name::make_command( | ||
| Command::new(stringify!($name).replace('_', "-")), | ||
| )); | ||
| }}; | ||
| } | ||
|
|
||
| command = command | ||
| .about("Manage code mappings for Sentry. Code mappings link stack trace paths to source code paths in your repository, enabling source context and code linking in Sentry.") | ||
| .subcommand_required(true) | ||
| .arg_required_else_help(true) | ||
| .org_arg() | ||
| .project_arg(false); | ||
| each_subcommand!(add_subcommand); | ||
| command | ||
| } | ||
|
|
||
| pub fn execute(matches: &ArgMatches) -> Result<()> { | ||
| macro_rules! execute_subcommand { | ||
| ($name:ident) => {{ | ||
| if let Some(sub_matches) = | ||
| matches.subcommand_matches(&stringify!($name).replace('_', "-")) | ||
| { | ||
| return crate::commands::code_mappings::$name::execute(&sub_matches); | ||
| } | ||
| }}; | ||
| } | ||
| each_subcommand!(execute_subcommand); | ||
| unreachable!(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| use std::fs; | ||
|
|
||
| use anyhow::{bail, Context as _, Result}; | ||
| use clap::{Arg, ArgMatches, Command}; | ||
| use serde::Deserialize; | ||
|
|
||
| #[derive(Debug, Deserialize)] | ||
| #[serde(rename_all = "camelCase")] | ||
| struct CodeMapping { | ||
| stack_root: String, | ||
| source_root: String, | ||
| } | ||
|
|
||
| pub fn make_command(command: Command) -> Command { | ||
| command | ||
| .about("Upload code mappings for a project from a JSON file. Each mapping pairs a stack trace root (e.g. com/example/module) with the corresponding source path in your repository (e.g. modules/module/src/main/java/com/example/module).") | ||
| .arg( | ||
| Arg::new("path") | ||
| .value_name("PATH") | ||
| .required(true) | ||
| .help("Path to a JSON file containing code mappings."), | ||
| ) | ||
| .arg( | ||
| Arg::new("repo") | ||
| .long("repo") | ||
| .value_name("REPO") | ||
| .help("The repository name (e.g. owner/repo). Defaults to the git remote."), | ||
| ) | ||
| .arg( | ||
| Arg::new("default_branch") | ||
| .long("default-branch") | ||
| .value_name("BRANCH") | ||
| .default_value("main") | ||
| .help("The default branch name."), | ||
| ) | ||
| } | ||
|
|
||
| pub fn execute(matches: &ArgMatches) -> Result<()> { | ||
| let path = matches | ||
| .get_one::<String>("path") | ||
| .expect("path is a required argument"); | ||
| let data = fs::read(path).with_context(|| format!("Failed to read mappings file '{path}'"))?; | ||
|
|
||
| let mappings: Vec<CodeMapping> = | ||
| serde_json::from_slice(&data).context("Failed to parse mappings JSON")?; | ||
|
|
||
| if mappings.is_empty() { | ||
| bail!("Mappings file contains an empty array. Nothing to upload."); | ||
| } | ||
|
|
||
| for (i, mapping) in mappings.iter().enumerate() { | ||
| if mapping.stack_root.is_empty() { | ||
| bail!("Mapping at index {i} has an empty stackRoot."); | ||
| } | ||
| if mapping.source_root.is_empty() { | ||
| bail!("Mapping at index {i} has an empty sourceRoot."); | ||
| } | ||
| } | ||
|
|
||
| println!("Found {} code mapping(s) in {path}", mappings.len()); | ||
|
|
||
| Ok(()) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
tests/integration/_cases/code_mappings/code-mappings-help.trycmd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| ``` | ||
| $ sentry-cli code-mappings --help | ||
| ? success | ||
| Manage code mappings for Sentry. Code mappings link stack trace paths to source code paths in your | ||
| repository, enabling source context and code linking in Sentry. | ||
|
|
||
| Usage: sentry-cli[EXE] code-mappings [OPTIONS] <COMMAND> | ||
|
|
||
| Commands: | ||
| upload Upload code mappings for a project from a JSON file. Each mapping pairs a stack trace root | ||
| (e.g. com/example/module) with the corresponding source path in your repository (e.g. | ||
| modules/module/src/main/java/com/example/module). | ||
| help Print this message or the help of the given subcommand(s) | ||
|
|
||
| Options: | ||
| -o, --org <ORG> The organization ID or slug. | ||
| --header <KEY:VALUE> Custom headers that should be attached to all requests | ||
| in key:value format. | ||
| -p, --project <PROJECT> The project ID or slug. | ||
| --auth-token <AUTH_TOKEN> Use the given Sentry auth token. | ||
| --log-level <LOG_LEVEL> Set the log output verbosity. [possible values: trace, debug, info, | ||
| warn, error] | ||
| --quiet Do not print any output while preserving correct exit code. This | ||
| flag is currently implemented only for selected subcommands. | ||
| [aliases: --silent] | ||
| -h, --help Print help | ||
|
|
||
| ``` |
28 changes: 28 additions & 0 deletions
28
tests/integration/_cases/code_mappings/code-mappings-no-subcommand.trycmd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| ``` | ||
| $ sentry-cli code-mappings | ||
| ? failed | ||
| Manage code mappings for Sentry. Code mappings link stack trace paths to source code paths in your | ||
| repository, enabling source context and code linking in Sentry. | ||
|
|
||
| Usage: sentry-cli[EXE] code-mappings [OPTIONS] <COMMAND> | ||
|
|
||
| Commands: | ||
| upload Upload code mappings for a project from a JSON file. Each mapping pairs a stack trace root | ||
| (e.g. com/example/module) with the corresponding source path in your repository (e.g. | ||
| modules/module/src/main/java/com/example/module). | ||
| help Print this message or the help of the given subcommand(s) | ||
|
|
||
| Options: | ||
| -o, --org <ORG> The organization ID or slug. | ||
| --header <KEY:VALUE> Custom headers that should be attached to all requests | ||
| in key:value format. | ||
| -p, --project <PROJECT> The project ID or slug. | ||
| --auth-token <AUTH_TOKEN> Use the given Sentry auth token. | ||
| --log-level <LOG_LEVEL> Set the log output verbosity. [possible values: trace, debug, info, | ||
| warn, error] | ||
| --quiet Do not print any output while preserving correct exit code. This | ||
| flag is currently implemented only for selected subcommands. | ||
| [aliases: --silent] | ||
| -h, --help Print help | ||
|
|
||
| ``` |
28 changes: 28 additions & 0 deletions
28
tests/integration/_cases/code_mappings/code-mappings-upload-help.trycmd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| ``` | ||
| $ sentry-cli code-mappings upload --help | ||
| ? success | ||
| Upload code mappings for a project from a JSON file. Each mapping pairs a stack trace root (e.g. | ||
| com/example/module) with the corresponding source path in your repository (e.g. | ||
| modules/module/src/main/java/com/example/module). | ||
|
|
||
| Usage: sentry-cli[EXE] code-mappings upload [OPTIONS] <PATH> | ||
|
|
||
| Arguments: | ||
| <PATH> Path to a JSON file containing code mappings. | ||
|
|
||
| Options: | ||
| -o, --org <ORG> The organization ID or slug. | ||
| --repo <REPO> The repository name (e.g. owner/repo). Defaults to the git remote. | ||
| --default-branch <BRANCH> The default branch name. [default: main] | ||
| --header <KEY:VALUE> Custom headers that should be attached to all requests | ||
| in key:value format. | ||
| -p, --project <PROJECT> The project ID or slug. | ||
| --auth-token <AUTH_TOKEN> Use the given Sentry auth token. | ||
| --log-level <LOG_LEVEL> Set the log output verbosity. [possible values: trace, debug, info, | ||
| warn, error] | ||
| --quiet Do not print any output while preserving correct exit code. This | ||
| flag is currently implemented only for selected subcommands. | ||
| [aliases: --silent] | ||
| -h, --help Print help | ||
|
|
||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| use crate::integration::TestManager; | ||
|
|
||
| #[test] | ||
| fn command_code_mappings_help() { | ||
| TestManager::new().register_trycmd_test("code_mappings/code-mappings-help.trycmd"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn command_code_mappings_no_subcommand() { | ||
| TestManager::new().register_trycmd_test("code_mappings/code-mappings-no-subcommand.trycmd"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn command_code_mappings_upload_help() { | ||
| TestManager::new().register_trycmd_test("code_mappings/code-mappings-upload-help.trycmd"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| mod bash_hook; | ||
| mod build; | ||
| mod code_mappings; | ||
| mod debug_files; | ||
| mod deploys; | ||
| mod events; | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.