codecov-cli 11.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. codecov_cli/__init__.py +3 -0
  2. codecov_cli/commands/__init__.py +0 -0
  3. codecov_cli/commands/base_picking.py +75 -0
  4. codecov_cli/commands/commit.py +72 -0
  5. codecov_cli/commands/create_report_result.py +41 -0
  6. codecov_cli/commands/empty_upload.py +80 -0
  7. codecov_cli/commands/get_report_results.py +50 -0
  8. codecov_cli/commands/labelanalysis.py +269 -0
  9. codecov_cli/commands/process_test_results.py +273 -0
  10. codecov_cli/commands/report.py +65 -0
  11. codecov_cli/commands/send_notifications.py +46 -0
  12. codecov_cli/commands/staticanalysis.py +62 -0
  13. codecov_cli/commands/upload.py +316 -0
  14. codecov_cli/commands/upload_coverage.py +186 -0
  15. codecov_cli/commands/upload_process.py +133 -0
  16. codecov_cli/fallbacks.py +41 -0
  17. codecov_cli/helpers/__init__.py +0 -0
  18. codecov_cli/helpers/args.py +31 -0
  19. codecov_cli/helpers/ci_adapters/__init__.py +63 -0
  20. codecov_cli/helpers/ci_adapters/appveyor_ci.py +54 -0
  21. codecov_cli/helpers/ci_adapters/azure_pipelines.py +44 -0
  22. codecov_cli/helpers/ci_adapters/base.py +102 -0
  23. codecov_cli/helpers/ci_adapters/bitbucket_ci.py +42 -0
  24. codecov_cli/helpers/ci_adapters/bitrise_ci.py +37 -0
  25. codecov_cli/helpers/ci_adapters/buildkite.py +45 -0
  26. codecov_cli/helpers/ci_adapters/circleci.py +47 -0
  27. codecov_cli/helpers/ci_adapters/cirrus_ci.py +36 -0
  28. codecov_cli/helpers/ci_adapters/cloudbuild.py +70 -0
  29. codecov_cli/helpers/ci_adapters/codebuild.py +49 -0
  30. codecov_cli/helpers/ci_adapters/droneci.py +36 -0
  31. codecov_cli/helpers/ci_adapters/github_actions.py +90 -0
  32. codecov_cli/helpers/ci_adapters/gitlab_ci.py +56 -0
  33. codecov_cli/helpers/ci_adapters/heroku.py +36 -0
  34. codecov_cli/helpers/ci_adapters/jenkins.py +38 -0
  35. codecov_cli/helpers/ci_adapters/local.py +39 -0
  36. codecov_cli/helpers/ci_adapters/teamcity.py +37 -0
  37. codecov_cli/helpers/ci_adapters/travis_ci.py +44 -0
  38. codecov_cli/helpers/ci_adapters/woodpeckerci.py +36 -0
  39. codecov_cli/helpers/config.py +66 -0
  40. codecov_cli/helpers/encoder.py +49 -0
  41. codecov_cli/helpers/folder_searcher.py +114 -0
  42. codecov_cli/helpers/git.py +97 -0
  43. codecov_cli/helpers/git_services/__init__.py +14 -0
  44. codecov_cli/helpers/git_services/github.py +40 -0
  45. codecov_cli/helpers/glob.py +146 -0
  46. codecov_cli/helpers/logging_utils.py +77 -0
  47. codecov_cli/helpers/options.py +51 -0
  48. codecov_cli/helpers/request.py +198 -0
  49. codecov_cli/helpers/upload_type.py +15 -0
  50. codecov_cli/helpers/validators.py +13 -0
  51. codecov_cli/helpers/versioning_systems.py +201 -0
  52. codecov_cli/main.py +99 -0
  53. codecov_cli/opentelemetry.py +26 -0
  54. codecov_cli/plugins/__init__.py +92 -0
  55. codecov_cli/plugins/compress_pycoverage_contexts.py +141 -0
  56. codecov_cli/plugins/gcov.py +69 -0
  57. codecov_cli/plugins/pycoverage.py +134 -0
  58. codecov_cli/plugins/types.py +8 -0
  59. codecov_cli/plugins/xcode.py +117 -0
  60. codecov_cli/runners/__init__.py +80 -0
  61. codecov_cli/runners/dan_runner.py +64 -0
  62. codecov_cli/runners/pytest_standard_runner.py +184 -0
  63. codecov_cli/runners/types.py +33 -0
  64. codecov_cli/services/__init__.py +0 -0
  65. codecov_cli/services/commit/__init__.py +86 -0
  66. codecov_cli/services/commit/base_picking.py +24 -0
  67. codecov_cli/services/empty_upload/__init__.py +42 -0
  68. codecov_cli/services/report/__init__.py +169 -0
  69. codecov_cli/services/upload/__init__.py +169 -0
  70. codecov_cli/services/upload/file_finder.py +320 -0
  71. codecov_cli/services/upload/legacy_upload_sender.py +132 -0
  72. codecov_cli/services/upload/network_finder.py +49 -0
  73. codecov_cli/services/upload/upload_collector.py +198 -0
  74. codecov_cli/services/upload/upload_sender.py +232 -0
  75. codecov_cli/services/upload_completion/__init__.py +38 -0
  76. codecov_cli/services/upload_coverage/__init__.py +93 -0
  77. codecov_cli/types.py +88 -0
  78. codecov_cli-11.0.0.dist-info/METADATA +298 -0
  79. codecov_cli-11.0.0.dist-info/RECORD +83 -0
  80. codecov_cli-11.0.0.dist-info/WHEEL +5 -0
  81. codecov_cli-11.0.0.dist-info/entry_points.txt +3 -0
  82. codecov_cli-11.0.0.dist-info/licenses/LICENSE +201 -0
  83. codecov_cli-11.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,316 @@
1
+ import logging
2
+ import os
3
+ import pathlib
4
+ import typing
5
+ import click
6
+ import sentry_sdk
7
+
8
+ from codecov_cli.fallbacks import CodecovOption, FallbackFieldEnum
9
+ from codecov_cli.helpers.args import get_cli_args
10
+ from codecov_cli.helpers.options import global_options
11
+ from codecov_cli.services.upload import do_upload_logic
12
+ from codecov_cli.types import CommandContext
13
+ from codecov_cli.helpers.upload_type import report_type_from_str, ReportType
14
+
15
+ logger = logging.getLogger("codecovcli")
16
+
17
+
18
+ def _turn_env_vars_into_dict(ctx, params, value):
19
+ return dict((v, os.getenv(v, None)) for v in value)
20
+
21
+
22
+ _global_upload_options = [
23
+ click.option(
24
+ "--code",
25
+ "--report-code",
26
+ "report_code",
27
+ help="The code of the report. If unsure, leave default",
28
+ default="default",
29
+ hidden=True,
30
+ ),
31
+ click.option(
32
+ "--network-root-folder",
33
+ help="Root folder from which to consider paths on the network section",
34
+ type=click.Path(path_type=pathlib.Path),
35
+ default=pathlib.Path.cwd,
36
+ show_default="Current working directory",
37
+ ),
38
+ click.option(
39
+ "-s",
40
+ "--dir",
41
+ "--coverage-files-search-root-folder",
42
+ "--files-search-root-folder",
43
+ "files_search_root_folder",
44
+ help="Folder where to search for coverage files",
45
+ type=click.Path(path_type=pathlib.Path),
46
+ default=pathlib.Path.cwd,
47
+ show_default="Current Working Directory",
48
+ ),
49
+ click.option(
50
+ "--exclude",
51
+ "--coverage-files-search-exclude-folder",
52
+ "--files-search-exclude-folder",
53
+ "files_search_exclude_folders",
54
+ help="Folders to exclude from search",
55
+ type=click.Path(path_type=pathlib.Path),
56
+ multiple=True,
57
+ default=[],
58
+ ),
59
+ click.option(
60
+ "-f",
61
+ "--file",
62
+ "--coverage-files-search-direct-file",
63
+ "--files-search-direct-file",
64
+ "files_search_explicitly_listed_files",
65
+ help="Explicit files to upload. These will be added to the coverage files found for upload. If you wish to only upload the specified files, please consider using --disable-search to disable uploading other files.",
66
+ type=click.Path(path_type=pathlib.Path),
67
+ multiple=True,
68
+ default=[],
69
+ ),
70
+ click.option(
71
+ "--recurse-submodules",
72
+ help="Whether to enumerate files inside of submodules for path-fixing purposes. Off by default.",
73
+ is_flag=True,
74
+ default=False,
75
+ ),
76
+ click.option(
77
+ "--disable-search",
78
+ help="Disable search for coverage files. This is helpful when specifying what files you want to upload with the --file option.",
79
+ is_flag=True,
80
+ default=False,
81
+ ),
82
+ click.option(
83
+ "--disable-file-fixes",
84
+ help="Disable file fixes to ignore common lines from coverage (e.g. blank lines or empty brackets)",
85
+ is_flag=True,
86
+ default=False,
87
+ ),
88
+ click.option(
89
+ "-b",
90
+ "--build",
91
+ "--build-code",
92
+ "build_code",
93
+ cls=CodecovOption,
94
+ help="Specify the build number manually",
95
+ fallback_field=FallbackFieldEnum.build_code,
96
+ ),
97
+ click.option(
98
+ "--build-url",
99
+ "build_url",
100
+ cls=CodecovOption,
101
+ help="The URL of the build where this is running",
102
+ fallback_field=FallbackFieldEnum.build_url,
103
+ ),
104
+ click.option(
105
+ "--job-code",
106
+ cls=CodecovOption,
107
+ fallback_field=FallbackFieldEnum.job_code,
108
+ ),
109
+ click.option(
110
+ "-n",
111
+ "--name",
112
+ help="Custom defined name of the upload. Visible in Codecov UI",
113
+ cls=CodecovOption,
114
+ fallback_field=FallbackFieldEnum.build_code,
115
+ ),
116
+ click.option(
117
+ "-B",
118
+ "--branch",
119
+ help="Branch to which this commit belongs to",
120
+ cls=CodecovOption,
121
+ fallback_field=FallbackFieldEnum.branch,
122
+ ),
123
+ click.option(
124
+ "-P",
125
+ "--pr",
126
+ "--pull-request-number",
127
+ "pull_request_number",
128
+ help="Specify the pull request number manually. Used to override pre-existing CI environment variables",
129
+ cls=CodecovOption,
130
+ fallback_field=FallbackFieldEnum.pull_request_number,
131
+ ),
132
+ click.option(
133
+ "-e",
134
+ "--env",
135
+ "--env-var",
136
+ "env_vars",
137
+ multiple=True,
138
+ callback=_turn_env_vars_into_dict,
139
+ help="Specify environment variables to be included with this build.",
140
+ ),
141
+ click.option(
142
+ "-F",
143
+ "--flag",
144
+ "flags",
145
+ multiple=True,
146
+ default=[],
147
+ help="Flag the upload to group coverage metrics. Multiple flags allowed.",
148
+ ),
149
+ click.option(
150
+ "--plugin",
151
+ "plugin_names",
152
+ multiple=True,
153
+ default=["xcode", "gcov", "pycoverage"],
154
+ ),
155
+ click.option(
156
+ "-d",
157
+ "--dry-run",
158
+ "dry_run",
159
+ is_flag=True,
160
+ help="Don't upload files to Codecov",
161
+ ),
162
+ click.option(
163
+ "--legacy",
164
+ "--use-legacy-uploader",
165
+ "use_legacy_uploader",
166
+ is_flag=True,
167
+ help="Use the legacy upload endpoint",
168
+ ),
169
+ click.option(
170
+ "--handle-no-reports-found",
171
+ "handle_no_reports_found",
172
+ is_flag=True,
173
+ help="Raise no exceptions when no coverage reports found.",
174
+ ),
175
+ click.option(
176
+ "--report-type",
177
+ "report_type_str",
178
+ help="The type of the file to upload, coverage by default. Possible values are: testing, coverage.",
179
+ default="coverage",
180
+ type=click.Choice(["coverage", "test_results"]),
181
+ ),
182
+ click.option(
183
+ "--network-filter",
184
+ help="Specify a filter on the files listed in the network section of the Codecov report. This will only add files whose path begin with the specified filter. Useful for upload-specific path fixing",
185
+ ),
186
+ click.option(
187
+ "--network-prefix",
188
+ help="Specify a prefix on files listed in the network section of the Codecov report. Useful to help resolve path fixing",
189
+ ),
190
+ click.option(
191
+ "--gcov-args",
192
+ help="Extra arguments to pass to gcov",
193
+ ),
194
+ click.option(
195
+ "--gcov-ignore",
196
+ help="Paths to ignore during gcov gathering",
197
+ ),
198
+ click.option(
199
+ "--gcov-include",
200
+ help="Paths to include during gcov gathering",
201
+ ),
202
+ click.option(
203
+ "--gcov-executable",
204
+ help="gcov executable to run. Defaults to 'gcov'",
205
+ ),
206
+ click.option(
207
+ "--swift-project",
208
+ help="Specify the swift project",
209
+ ),
210
+ ]
211
+
212
+
213
+ def global_upload_options(func):
214
+ for option in reversed(_global_upload_options):
215
+ func = option(func)
216
+ return func
217
+
218
+
219
+ @click.command()
220
+ @global_upload_options
221
+ @global_options
222
+ @click.pass_context
223
+ def do_upload(
224
+ ctx: CommandContext,
225
+ commit_sha: str,
226
+ report_code: str,
227
+ branch: typing.Optional[str],
228
+ build_code: typing.Optional[str],
229
+ build_url: typing.Optional[str],
230
+ disable_file_fixes: bool,
231
+ disable_search: bool,
232
+ dry_run: bool,
233
+ env_vars: typing.Dict[str, str],
234
+ fail_on_error: bool,
235
+ files_search_exclude_folders: typing.List[pathlib.Path],
236
+ files_search_explicitly_listed_files: typing.List[pathlib.Path],
237
+ files_search_root_folder: pathlib.Path,
238
+ flags: typing.List[str],
239
+ gcov_args: typing.Optional[str],
240
+ gcov_executable: typing.Optional[str],
241
+ gcov_ignore: typing.Optional[str],
242
+ gcov_include: typing.Optional[str],
243
+ git_service: typing.Optional[str],
244
+ handle_no_reports_found: bool,
245
+ job_code: typing.Optional[str],
246
+ name: typing.Optional[str],
247
+ network_filter: typing.Optional[str],
248
+ network_prefix: typing.Optional[str],
249
+ network_root_folder: pathlib.Path,
250
+ plugin_names: typing.List[str],
251
+ pull_request_number: typing.Optional[str],
252
+ recurse_submodules: bool,
253
+ report_type_str: str,
254
+ slug: typing.Optional[str],
255
+ swift_project: typing.Optional[str],
256
+ token: typing.Optional[str],
257
+ use_legacy_uploader: bool,
258
+ ):
259
+ with sentry_sdk.start_transaction(op="task", name="Do Upload"):
260
+ with sentry_sdk.start_span(name="do_upload"):
261
+ versioning_system = ctx.obj["versioning_system"]
262
+ codecov_yaml = ctx.obj["codecov_yaml"] or {}
263
+ cli_config = codecov_yaml.get("cli", {})
264
+ ci_adapter = ctx.obj.get("ci_adapter")
265
+ enterprise_url = ctx.obj.get("enterprise_url")
266
+ args = get_cli_args(ctx)
267
+ logger.debug(
268
+ "Starting upload processing",
269
+ extra=dict(
270
+ extra_log_attributes=args,
271
+ ),
272
+ )
273
+
274
+ report_type: ReportType = report_type_from_str(report_type_str)
275
+ do_upload_logic(
276
+ cli_config,
277
+ versioning_system,
278
+ ci_adapter,
279
+ branch=branch,
280
+ build_code=build_code,
281
+ build_url=build_url,
282
+ commit_sha=commit_sha,
283
+ disable_file_fixes=disable_file_fixes,
284
+ disable_search=disable_search,
285
+ dry_run=dry_run,
286
+ enterprise_url=enterprise_url,
287
+ env_vars=env_vars,
288
+ fail_on_error=fail_on_error,
289
+ files_search_exclude_folders=list(files_search_exclude_folders),
290
+ files_search_explicitly_listed_files=list(
291
+ files_search_explicitly_listed_files
292
+ ),
293
+ files_search_root_folder=files_search_root_folder,
294
+ flags=flags,
295
+ gcov_args=gcov_args,
296
+ gcov_executable=gcov_executable,
297
+ gcov_ignore=gcov_ignore,
298
+ gcov_include=gcov_include,
299
+ git_service=git_service,
300
+ handle_no_reports_found=handle_no_reports_found,
301
+ job_code=job_code,
302
+ name=name,
303
+ network_filter=network_filter,
304
+ network_prefix=network_prefix,
305
+ network_root_folder=network_root_folder,
306
+ plugin_names=plugin_names,
307
+ pull_request_number=pull_request_number,
308
+ recurse_submodules=recurse_submodules,
309
+ report_code=report_code,
310
+ slug=slug,
311
+ swift_project=swift_project,
312
+ token=token,
313
+ report_type=report_type,
314
+ use_legacy_uploader=use_legacy_uploader,
315
+ args=args,
316
+ )
@@ -0,0 +1,186 @@
1
+ import logging
2
+ import pathlib
3
+ import typing
4
+
5
+ import click
6
+ import sentry_sdk
7
+
8
+ from codecov_cli.commands.commit import create_commit
9
+ from codecov_cli.commands.report import create_report
10
+ from codecov_cli.commands.upload import do_upload, global_upload_options
11
+ from codecov_cli.helpers.args import get_cli_args
12
+ from codecov_cli.helpers.options import global_options
13
+ from codecov_cli.opentelemetry import close_telem
14
+ from codecov_cli.helpers.upload_type import report_type_from_str, ReportType
15
+ from codecov_cli.services.upload_coverage import upload_coverage_logic
16
+ from codecov_cli.types import CommandContext
17
+
18
+ logger = logging.getLogger("codecovcli")
19
+
20
+
21
+ # These options are the combined options of commit, report and upload commands
22
+ @click.command()
23
+ @global_options
24
+ @global_upload_options
25
+ @click.option(
26
+ "--parent-sha",
27
+ help="SHA (with 40 chars) of what should be the parent of this commit",
28
+ )
29
+ @click.pass_context
30
+ def upload_coverage(
31
+ ctx: CommandContext,
32
+ branch: typing.Optional[str],
33
+ build_code: typing.Optional[str],
34
+ build_url: typing.Optional[str],
35
+ commit_sha: str,
36
+ disable_file_fixes: bool,
37
+ disable_search: bool,
38
+ dry_run: bool,
39
+ env_vars: typing.Dict[str, str],
40
+ fail_on_error: bool,
41
+ files_search_exclude_folders: typing.List[pathlib.Path],
42
+ files_search_explicitly_listed_files: typing.List[pathlib.Path],
43
+ files_search_root_folder: pathlib.Path,
44
+ flags: typing.List[str],
45
+ gcov_args: typing.Optional[str],
46
+ gcov_executable: typing.Optional[str],
47
+ gcov_ignore: typing.Optional[str],
48
+ gcov_include: typing.Optional[str],
49
+ git_service: typing.Optional[str],
50
+ handle_no_reports_found: bool,
51
+ job_code: typing.Optional[str],
52
+ name: typing.Optional[str],
53
+ network_filter: typing.Optional[str],
54
+ network_prefix: typing.Optional[str],
55
+ network_root_folder: pathlib.Path,
56
+ parent_sha: typing.Optional[str],
57
+ plugin_names: typing.List[str],
58
+ pull_request_number: typing.Optional[str],
59
+ recurse_submodules: bool,
60
+ report_code: str,
61
+ report_type_str: str,
62
+ slug: typing.Optional[str],
63
+ swift_project: typing.Optional[str],
64
+ token: typing.Optional[str],
65
+ use_legacy_uploader: bool,
66
+ ):
67
+ with sentry_sdk.start_transaction(op="task", name="Upload Coverage"):
68
+ with sentry_sdk.start_span(name="upload_coverage"):
69
+ args = get_cli_args(ctx)
70
+ logger.debug(
71
+ "Starting upload coverage",
72
+ extra=dict(
73
+ extra_log_attributes=args,
74
+ ),
75
+ )
76
+
77
+ report_type = report_type_from_str(report_type_str)
78
+
79
+ if not use_legacy_uploader and report_type == ReportType.COVERAGE:
80
+ versioning_system = ctx.obj["versioning_system"]
81
+ codecov_yaml = ctx.obj["codecov_yaml"] or {}
82
+ cli_config = codecov_yaml.get("cli", {})
83
+ ci_adapter = ctx.obj.get("ci_adapter")
84
+ enterprise_url = ctx.obj.get("enterprise_url")
85
+ args = get_cli_args(ctx)
86
+ ctx.invoke(
87
+ upload_coverage_logic,
88
+ cli_config,
89
+ versioning_system,
90
+ ci_adapter,
91
+ branch=branch,
92
+ build_code=build_code,
93
+ build_url=build_url,
94
+ commit_sha=commit_sha,
95
+ disable_file_fixes=disable_file_fixes,
96
+ disable_search=disable_search,
97
+ dry_run=dry_run,
98
+ enterprise_url=enterprise_url,
99
+ env_vars=env_vars,
100
+ fail_on_error=fail_on_error,
101
+ files_search_exclude_folders=files_search_exclude_folders,
102
+ files_search_explicitly_listed_files=files_search_explicitly_listed_files,
103
+ files_search_root_folder=files_search_root_folder,
104
+ flags=flags,
105
+ gcov_args=gcov_args,
106
+ gcov_executable=gcov_executable,
107
+ gcov_ignore=gcov_ignore,
108
+ gcov_include=gcov_include,
109
+ git_service=git_service,
110
+ handle_no_reports_found=handle_no_reports_found,
111
+ job_code=job_code,
112
+ name=name,
113
+ network_filter=network_filter,
114
+ network_prefix=network_prefix,
115
+ network_root_folder=network_root_folder,
116
+ parent_sha=parent_sha,
117
+ plugin_names=plugin_names,
118
+ pull_request_number=pull_request_number,
119
+ recurse_submodules=recurse_submodules,
120
+ report_code=report_code,
121
+ slug=slug,
122
+ swift_project=swift_project,
123
+ token=token,
124
+ report_type=report_type,
125
+ use_legacy_uploader=use_legacy_uploader,
126
+ args=args,
127
+ )
128
+ else:
129
+ ctx.invoke(
130
+ create_commit,
131
+ commit_sha=commit_sha,
132
+ parent_sha=parent_sha,
133
+ pull_request_number=pull_request_number,
134
+ branch=branch,
135
+ slug=slug,
136
+ token=token,
137
+ git_service=git_service,
138
+ fail_on_error=True,
139
+ )
140
+ if report_type == ReportType.COVERAGE:
141
+ ctx.invoke(
142
+ create_report,
143
+ token=token,
144
+ code=report_code,
145
+ fail_on_error=True,
146
+ commit_sha=commit_sha,
147
+ slug=slug,
148
+ git_service=git_service,
149
+ )
150
+ ctx.invoke(
151
+ do_upload,
152
+ branch=branch,
153
+ build_code=build_code,
154
+ build_url=build_url,
155
+ commit_sha=commit_sha,
156
+ disable_file_fixes=disable_file_fixes,
157
+ disable_search=disable_search,
158
+ dry_run=dry_run,
159
+ env_vars=env_vars,
160
+ fail_on_error=fail_on_error,
161
+ files_search_exclude_folders=files_search_exclude_folders,
162
+ files_search_explicitly_listed_files=files_search_explicitly_listed_files,
163
+ files_search_root_folder=files_search_root_folder,
164
+ flags=flags,
165
+ gcov_args=gcov_args,
166
+ gcov_executable=gcov_executable,
167
+ gcov_ignore=gcov_ignore,
168
+ gcov_include=gcov_include,
169
+ git_service=git_service,
170
+ handle_no_reports_found=handle_no_reports_found,
171
+ job_code=job_code,
172
+ name=name,
173
+ network_filter=network_filter,
174
+ network_prefix=network_prefix,
175
+ network_root_folder=network_root_folder,
176
+ plugin_names=plugin_names,
177
+ pull_request_number=pull_request_number,
178
+ recurse_submodules=recurse_submodules,
179
+ report_code=report_code,
180
+ report_type_str=report_type_str,
181
+ slug=slug,
182
+ swift_project=swift_project,
183
+ token=token,
184
+ use_legacy_uploader=use_legacy_uploader,
185
+ )
186
+ close_telem()
@@ -0,0 +1,133 @@
1
+ import logging
2
+ import pathlib
3
+ import typing
4
+
5
+ import click
6
+ import sentry_sdk
7
+
8
+ from codecov_cli.commands.commit import create_commit
9
+ from codecov_cli.commands.report import create_report
10
+ from codecov_cli.commands.upload import do_upload, global_upload_options
11
+ from codecov_cli.helpers.args import get_cli_args
12
+ from codecov_cli.helpers.options import global_options
13
+ from codecov_cli.helpers.upload_type import report_type_from_str, ReportType
14
+ from codecov_cli.types import CommandContext
15
+
16
+ logger = logging.getLogger("codecovcli")
17
+
18
+
19
+ # These options are the combined options of commit, report and upload commands
20
+ @click.command()
21
+ @global_options
22
+ @global_upload_options
23
+ @click.option(
24
+ "--parent-sha",
25
+ help="SHA (with 40 chars) of what should be the parent of this commit",
26
+ )
27
+ @click.pass_context
28
+ def upload_process(
29
+ ctx: CommandContext,
30
+ branch: typing.Optional[str],
31
+ build_code: typing.Optional[str],
32
+ build_url: typing.Optional[str],
33
+ commit_sha: str,
34
+ disable_file_fixes: bool,
35
+ disable_search: bool,
36
+ dry_run: bool,
37
+ env_vars: typing.Dict[str, str],
38
+ fail_on_error: bool,
39
+ files_search_exclude_folders: typing.List[pathlib.Path],
40
+ files_search_explicitly_listed_files: typing.List[pathlib.Path],
41
+ files_search_root_folder: pathlib.Path,
42
+ flags: typing.List[str],
43
+ gcov_args: typing.Optional[str],
44
+ gcov_executable: typing.Optional[str],
45
+ gcov_ignore: typing.Optional[str],
46
+ gcov_include: typing.Optional[str],
47
+ git_service: typing.Optional[str],
48
+ handle_no_reports_found: bool,
49
+ job_code: typing.Optional[str],
50
+ name: typing.Optional[str],
51
+ network_filter: typing.Optional[str],
52
+ network_prefix: typing.Optional[str],
53
+ network_root_folder: pathlib.Path,
54
+ parent_sha: typing.Optional[str],
55
+ plugin_names: typing.List[str],
56
+ pull_request_number: typing.Optional[str],
57
+ recurse_submodules: bool,
58
+ report_code: str,
59
+ report_type_str: str,
60
+ slug: typing.Optional[str],
61
+ swift_project: typing.Optional[str],
62
+ token: typing.Optional[str],
63
+ use_legacy_uploader: bool,
64
+ ):
65
+ with sentry_sdk.start_transaction(op="task", name="Upload Process"):
66
+ with sentry_sdk.start_span(name="upload_process"):
67
+ args = get_cli_args(ctx)
68
+ logger.debug(
69
+ "Starting upload process",
70
+ extra=dict(
71
+ extra_log_attributes=args,
72
+ ),
73
+ )
74
+
75
+ ctx.invoke(
76
+ create_commit,
77
+ commit_sha=commit_sha,
78
+ parent_sha=parent_sha,
79
+ pull_request_number=pull_request_number,
80
+ branch=branch,
81
+ slug=slug,
82
+ token=token,
83
+ git_service=git_service,
84
+ fail_on_error=True,
85
+ )
86
+
87
+ report_type = report_type_from_str(report_type_str)
88
+ if report_type == ReportType.COVERAGE:
89
+ ctx.invoke(
90
+ create_report,
91
+ token=token,
92
+ code=report_code,
93
+ fail_on_error=True,
94
+ commit_sha=commit_sha,
95
+ slug=slug,
96
+ git_service=git_service,
97
+ )
98
+ ctx.invoke(
99
+ do_upload,
100
+ branch=branch,
101
+ build_code=build_code,
102
+ build_url=build_url,
103
+ commit_sha=commit_sha,
104
+ disable_file_fixes=disable_file_fixes,
105
+ disable_search=disable_search,
106
+ dry_run=dry_run,
107
+ env_vars=env_vars,
108
+ fail_on_error=fail_on_error,
109
+ files_search_exclude_folders=files_search_exclude_folders,
110
+ files_search_explicitly_listed_files=files_search_explicitly_listed_files,
111
+ files_search_root_folder=files_search_root_folder,
112
+ flags=flags,
113
+ gcov_args=gcov_args,
114
+ gcov_executable=gcov_executable,
115
+ gcov_ignore=gcov_ignore,
116
+ gcov_include=gcov_include,
117
+ git_service=git_service,
118
+ handle_no_reports_found=handle_no_reports_found,
119
+ job_code=job_code,
120
+ name=name,
121
+ network_filter=network_filter,
122
+ network_prefix=network_prefix,
123
+ network_root_folder=network_root_folder,
124
+ plugin_names=plugin_names,
125
+ pull_request_number=pull_request_number,
126
+ recurse_submodules=recurse_submodules,
127
+ report_code=report_code,
128
+ report_type_str=report_type_str,
129
+ slug=slug,
130
+ swift_project=swift_project,
131
+ token=token,
132
+ use_legacy_uploader=use_legacy_uploader,
133
+ )
@@ -0,0 +1,41 @@
1
+ import typing
2
+ from enum import Enum, auto
3
+
4
+ import click
5
+
6
+
7
+ class FallbackFieldEnum(Enum):
8
+ branch = auto()
9
+ build_code = auto()
10
+ build_url = auto()
11
+ commit_sha = auto()
12
+ git_service = auto()
13
+ job_code = auto()
14
+ pull_request_number = auto()
15
+ service = auto()
16
+ slug = auto()
17
+
18
+
19
+ class CodecovOption(click.Option):
20
+ def __init__(self, *args, **kwargs):
21
+ self.fallback_field = kwargs.pop("fallback_field", None)
22
+ super().__init__(*args, **kwargs)
23
+
24
+ def get_default(
25
+ self, ctx: click.Context, call: bool = True
26
+ ) -> typing.Optional[typing.Union[typing.Any, typing.Callable[[], typing.Any]]]:
27
+ res = super().get_default(ctx, call=call)
28
+ if res is not None:
29
+ return res
30
+ if self.fallback_field is not None:
31
+ if ctx.obj.get("ci_adapter") is not None:
32
+ res = ctx.obj.get("ci_adapter").get_fallback_value(self.fallback_field)
33
+ if res is not None:
34
+ return res
35
+ if ctx.obj.get("versioning_system") is not None:
36
+ res = ctx.obj.get("versioning_system").get_fallback_value(
37
+ self.fallback_field
38
+ )
39
+ if res is not None:
40
+ return res
41
+ return None
File without changes