Skip to content

Commit a18eb84

Browse files
authored
Merge pull request #4 from getsentry/spalmurray/update-cccli
Update codecov-cli with upstream
2 parents 675be6c + 56ede56 commit a18eb84

File tree

12 files changed

+19
-923
lines changed

12 files changed

+19
-923
lines changed

codecov-cli/README.md

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,9 @@ CodecovCLI is a new way for users to interact with Codecov directly from the use
1717
- [create-commit](#create-commit)
1818
- [create-report](#create-report)
1919
- [do-upload](#do-upload)
20-
- [create-report-results](#create-report-results)
21-
- [get-report-results](#get-report-results)
2220
- [pr-base-picking](#pr-base-picking)
2321
- [send-notifications](#send-notifications)
2422
- [empty-upload](#empty-upload)
25-
- [How to Use Local Upload](#how-to-use-local-upload)
2623
- [Work in Progress Features](#work-in-progress-features)
2724
- [Plugin System](#plugin-system)
2825
- [Static Analysis](#static-analysis)
@@ -123,8 +120,6 @@ Codecov-cli supports user input. These inputs, along with their descriptions and
123120
| `create-commit` | Saves the commit's metadata in codecov, it's only necessary to run this once per commit
124121
| `create-report` | Creates an empty report in codecov with initial data e.g. report name, report's commit
125122
| `do-upload` | Searches for and uploads coverage data to codecov
126-
| `create-report-results` | Used for local upload. It tells codecov that you finished local uploading and want it to calculate the results for you to get them locally.
127-
| `get-report-results` | Used for local upload. It asks codecov to provide you the report results you calculated with the previous command.
128123
| `pr-base-picking` | Tells codecov that you want to explicitly define a base for your PR
129124
| `upload-process` | A wrapper for 3 commands. Create-commit, create-report and do-upload. You can use this command to upload to codecov instead of using the previously mentioned commands.
130125
| `send-notifications` | A command that tells Codecov that you finished uploading and you want to be sent notifications. To disable automatically sent notifications please consider adding manual_trigger to your codecov.yml, so it will look like codecov: notify: manual_trigger: true.
@@ -156,7 +151,6 @@ Codecov-cli supports user input. These inputs, along with their descriptions and
156151
|-r, --slug | owner/repo slug used instead of the private repo token in Self-hosted | Required
157152
|-t, --token | Codecov upload token | Required
158153
|--git-service | Git Provider. Options: github, gitlab, bitbucket, github_enterprise, gitlab_enterprise, bitbucket_server | Required
159-
|--code| The code of the report. This is used in local uploading to isolate local reports from regular or cloud reports uploaded to codecov so they don't get merged. It's basically a name you give to your report e.g. local-report. | Optional
160154
|-h, --help | Shows usage, and command options
161155

162156
## do-upload
@@ -165,7 +159,6 @@ Codecov-cli supports user input. These inputs, along with their descriptions and
165159
| Option | Description | Usage
166160
| :---: | :---: | :---: |
167161
|-C, --sha, --commit-sha| Commit SHA (with 40 chars) | Required
168-
|--report-code | The code of the report defined when creating the report. If unsure, leave default | Optional
169162
|--network-root-folder | Root folder from which to consider paths on the network section default: (Current working directory) | Optional
170163
|-s, --dir, --coverage-files-search-root-folder | Folder where to search for coverage files default: (Current Working Directory) | Optional
171164
|--exclude, --coverage-files-search-exclude-folder | Folders to exclude from search | Optional
@@ -189,30 +182,6 @@ Codecov-cli supports user input. These inputs, along with their descriptions and
189182
|--git-service | Git Provider. Options: github, gitlab, bitbucket, github_enterprise, gitlab_enterprise, bitbucket_server | Required
190183
|-h, --help | Shows usage, and command options
191184

192-
## create-report-results
193-
`codecovcli create-report-results [OPTIONS]`
194-
195-
| Option | Description | Usage
196-
| :---: | :---: | :---: |
197-
|--commit-sha | Commit SHA (with 40 chars) | Required
198-
|--code | The code of the report. If unsure, leave default | Required
199-
|--slug | owner/repo slug | Required
200-
|--git-service | Git provider. Options: github, gitlab, bitbucket, github_enterprise, gitlab_enterprise, bitbucket_server | Optional
201-
|-t, --token | Codecov upload token | Required
202-
|-h, --help | Shows usage, and command options
203-
204-
## get-report-results
205-
`codecovcli get-report-results [OPTIONS]`
206-
207-
| Option | Description | Usage
208-
| :---: | :---: | :---: |
209-
|--commit-sha | Commit SHA (with 40 chars) | Required
210-
|--code | The code of the report. If unsure, leave default | Required
211-
|--slug | owner/repo slug | Required
212-
|--git-service | Git provider. Options: github, gitlab, bitbucket, github_enterprise, gitlab_enterprise, bitbucket_server | Optional
213-
|-t, --token | Codecov upload token | Required
214-
|-h, --help | Shows usage, and command options
215-
216185
## pr-base-picking
217186
`codecovcli pr-base-picking [OPTIONS]`
218187

@@ -254,25 +223,6 @@ are ignored by codecov (including README and configuration files)
254223
| --git-service | Options: github, gitlab, bitbucket, github_enterprise, gitlab_enterprise, bitbucket_server | Optional |
255224
| -h, --help | Show this message and exit. | Optional |
256225

257-
# How to Use Local Upload
258-
259-
The CLI also supports "dry run" local uploading. This is useful if you prefer to see Codecov status checks and coverage reporting locally, in your terminal, as opposed to opening a PR and waiting for your full CI to run. Local uploads do not interfere with regular uploads made from your CI for any given commit / Pull Request.
260-
261-
Local Upload is accomplished as follows:
262-
263-
```
264-
pip install codecov-cli
265-
codecovcli create-commit
266-
codecovcli create-report --code <CODE>
267-
codecovcli do-upload --report-code <CODE>
268-
codecovcli create-report-results --code <CODE>
269-
codecovcli get-report-results --code <CODE>
270-
```
271-
272-
Codecov will calculate the coverage results, and return them in your terminal, telling you whether your PR will fail or pass the coverage check.
273-
274-
Note: In order for Local Upload to work, it must be used against a commit on the origin repository. Local Upload does not work for arbitrary diffs or uncommitted changes on your local machine.
275-
276226
# Work in Progress Features
277227

278228
The following features are somewhat implemented in code, but are not yet meant for use. These features will be documented once they are fully implemented in the CLI.
@@ -281,10 +231,6 @@ The following features are somewhat implemented in code, but are not yet meant f
281231

282232
To provide extensibility to some of its commands, the CLI makes use of a plugin system. For most cases, the default commands are sufficient. But in some cases, having some custom logic specific to your use case can be beneficial. Note that full documentation of the plugin system is pending, as the feature is still heavily a work in progress.
283233

284-
## Static Analysis
285-
286-
The CLI can perform basic static analysis on Python code today. This static analysis is meant to power more future looking Codecov features and, as such, is not required or in active use today. As more functionality dependent on static analysis becomes available for use, we will document static analysis in detail here.
287-
288234
# Contributions
289235

290236
This repository, like all of Codecov's repositories, strives to follow our general [Contributing guidelines](https://github.com/codecov/contributing). If you're considering making a contribution to this repository, we encourage review of our Contributing guidelines first.

codecov-cli/codecov_cli/commands/create_report_result.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
logger = logging.getLogger("codecovcli")
1212

1313

14-
@click.command()
14+
@click.command(hidden=True, deprecated=True)
1515
@click.option(
1616
"--code", help="The code of the report. If unsure, leave default", default="default"
1717
)

codecov-cli/codecov_cli/commands/get_report_results.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
import click
44
import sentry_sdk
55

6-
from codecov_cli.fallbacks import CodecovOption, FallbackFieldEnum
76
from codecov_cli.helpers.args import get_cli_args
87
from codecov_cli.helpers.encoder import encode_slug
9-
from codecov_cli.helpers.git import GitService
108
from codecov_cli.helpers.options import global_options
119
from codecov_cli.services.report import send_reports_result_get_request
1210
from codecov_cli.types import CommandContext
@@ -15,7 +13,7 @@
1513
logger = logging.getLogger("codecovcli")
1614

1715

18-
@click.command()
16+
@click.command(hidden=True, deprecated=True)
1917
@click.option(
2018
"--code", help="The code of the report. If unsure, leave default", default="default"
2119
)

codecov-cli/codecov_cli/commands/labelanalysis.py

Lines changed: 8 additions & 205 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
import json
22
import logging
33
import pathlib
4-
import time
54
from typing import Dict, List, Optional
65

76
import click
8-
import requests
97
import sentry_sdk
108

119
from codecov_cli.fallbacks import CodecovOption, FallbackFieldEnum
12-
from codecov_cli.helpers import request
1310
from codecov_cli.helpers.args import get_cli_args
14-
from codecov_cli.helpers.config import CODECOV_API_URL
1511
from codecov_cli.helpers.validators import validate_commit_sha
1612
from codecov_cli.runners import get_runner
1713
from codecov_cli.runners.types import (
@@ -92,7 +88,6 @@ def label_analysis(
9288
):
9389
with sentry_sdk.start_transaction(op="task", name="Label Analysis"):
9490
with sentry_sdk.start_span(name="labelanalysis"):
95-
enterprise_url = ctx.obj.get("enterprise_url")
9691
args = get_cli_args(ctx)
9792
logger.debug(
9893
"Starting label analysis",
@@ -124,18 +119,6 @@ def label_analysis(
124119
extra=dict(extra_log_attributes=dict(config=runner.params)),
125120
)
126121

127-
upload_url = enterprise_url or CODECOV_API_URL
128-
url = f"{upload_url}/labels/labels-analysis"
129-
token_header = f"Repotoken {token}"
130-
payload = {
131-
"base_commit": base_commit_sha,
132-
"head_commit": head_commit_sha,
133-
"requested_labels": None,
134-
}
135-
# Send the initial label analysis request without labels
136-
# Because labels might take a long time to collect
137-
eid = _send_labelanalysis_request(payload, url, token_header)
138-
139122
logger.info("Collecting labels...")
140123
requested_labels = runner.collect_tests()
141124
logger.info(f"Collected {len(requested_labels)} test labels")
@@ -145,98 +128,15 @@ def label_analysis(
145128
extra_log_attributes=dict(labels_collected=requested_labels)
146129
),
147130
)
148-
payload["requested_labels"] = requested_labels
149-
150-
if eid:
151-
# Initial request with no labels was successful
152-
# Now we PATCH the labels in
153-
patch_url = f"{upload_url}/labels/labels-analysis/{eid}"
154-
_patch_labels(payload, patch_url, token_header)
155-
else:
156-
# Initial request with no labels failed
157-
# Retry it
158-
eid = _send_labelanalysis_request(payload, url, token_header)
159-
if eid is None:
160-
_fallback_to_collected_labels(
161-
requested_labels,
162-
runner,
163-
dry_run=dry_run,
164-
dry_run_format=dry_run_format,
165-
fallback_reason="codecov_unavailable",
166-
)
167-
return
168131

169-
has_result = False
170-
logger.info("Waiting for list of tests to run...")
171-
start_wait = time.monotonic()
172-
time.sleep(1)
173-
while not has_result:
174-
resp_data = request.get(
175-
f"{upload_url}/labels/labels-analysis/{eid}",
176-
headers={"Authorization": token_header},
177-
)
178-
resp_json = resp_data.json()
179-
if resp_json["state"] == "finished":
180-
logger.info(
181-
"Received list of tests from Codecov",
182-
extra=dict(
183-
extra_log_attributes=dict(
184-
processing_errors=resp_json.get("errors", [])
185-
)
186-
),
187-
)
188-
request_result = _potentially_calculate_absent_labels(
189-
resp_json["result"], requested_labels
190-
)
191-
if not dry_run:
192-
runner.process_labelanalysis_result(request_result)
193-
else:
194-
_dry_run_output(
195-
LabelAnalysisRequestResult(request_result),
196-
runner,
197-
dry_run_format,
198-
# It's possible that the task had processing errors and fallback to all tests
199-
# Even though it's marked as FINISHED (not ERROR) it's not a true success
200-
fallback_reason=(
201-
"test_list_processing_errors"
202-
if resp_json.get("errors", None)
203-
else None
204-
),
205-
)
206-
return
207-
if resp_json["state"] == "error":
208-
logger.error(
209-
"Request had problems calculating",
210-
extra=dict(
211-
extra_log_attributes=dict(
212-
base_commit=resp_json["base_commit"],
213-
head_commit=resp_json["head_commit"],
214-
external_id=resp_json["external_id"],
215-
)
216-
),
217-
)
218-
_fallback_to_collected_labels(
219-
collected_labels=requested_labels,
220-
runner=runner,
221-
dry_run=dry_run,
222-
dry_run_format=dry_run_format,
223-
fallback_reason="test_list_processing_failed",
224-
)
225-
return
226-
if max_wait_time and (time.monotonic() - start_wait) > max_wait_time:
227-
logger.error(
228-
f"Exceeded max waiting time of {max_wait_time} seconds. Running all tests.",
229-
)
230-
_fallback_to_collected_labels(
231-
collected_labels=requested_labels,
232-
runner=runner,
233-
dry_run=dry_run,
234-
dry_run_format=dry_run_format,
235-
fallback_reason="max_wait_time_exceeded",
236-
)
237-
return
238-
logger.info("Waiting more time for result...")
239-
time.sleep(5)
132+
_fallback_to_collected_labels(
133+
requested_labels,
134+
runner,
135+
dry_run=dry_run,
136+
dry_run_format=dry_run_format,
137+
fallback_reason="codecov_unavailable",
138+
)
139+
return
240140

241141

242142
def _parse_runner_params(runner_params: List[str]) -> Dict[str, str]:
@@ -271,103 +171,6 @@ def _parse_runner_params(runner_params: List[str]) -> Dict[str, str]:
271171
return final_params
272172

273173

274-
def _potentially_calculate_absent_labels(
275-
request_result, requested_labels
276-
) -> LabelAnalysisRequestResult:
277-
if request_result["absent_labels"]:
278-
# This means that Codecov already calculated everything for us
279-
final_result = LabelAnalysisRequestResult(request_result)
280-
else:
281-
# Here we have to calculate the absent labels
282-
# And also remove labels that maybe don't exist anymore from the set of labels to test
283-
# Because codecov didn't have this info previously
284-
requested_labels_set = set(requested_labels)
285-
present_diff_labels_set = set(request_result.get("present_diff_labels", []))
286-
present_report_labels_set = set(request_result.get("present_report_labels", []))
287-
global_level_labels_set = set(request_result.get("global_level_labels", []))
288-
final_result = LabelAnalysisRequestResult(
289-
{
290-
"present_report_labels": sorted(
291-
present_report_labels_set & requested_labels_set
292-
),
293-
"present_diff_labels": sorted(
294-
present_diff_labels_set & requested_labels_set
295-
),
296-
"absent_labels": sorted(
297-
requested_labels_set - present_report_labels_set
298-
),
299-
"global_level_labels": sorted(
300-
global_level_labels_set & requested_labels_set
301-
),
302-
}
303-
)
304-
logger.info(
305-
"Received information about tests to run",
306-
extra=dict(
307-
extra_log_attributes=dict(
308-
absent_labels=len(final_result.absent_labels),
309-
present_diff_labels=len(final_result.present_diff_labels),
310-
global_level_labels=len(final_result.global_level_labels),
311-
present_report_labels=len(final_result.present_report_labels),
312-
)
313-
),
314-
)
315-
return final_result
316-
317-
318-
def _patch_labels(payload, url, token_header):
319-
logger.info("Sending collected labels to Codecov...")
320-
try:
321-
response = request.patch(
322-
url, json=payload, headers={"Authorization": token_header}
323-
)
324-
if response.status_code < 300:
325-
logger.info("Labels successfully sent to Codecov")
326-
except requests.RequestException:
327-
raise click.ClickException(click.style("Unable to reach Codecov", fg="red"))
328-
329-
330-
def _send_labelanalysis_request(payload, url, token_header):
331-
logger.info(
332-
"Requesting set of labels to run...",
333-
extra=dict(
334-
extra_log_attributes=dict(
335-
with_labels=(payload["requested_labels"] is not None)
336-
)
337-
),
338-
)
339-
try:
340-
response = request.post(
341-
url, data=payload, headers={"Authorization": token_header}
342-
)
343-
if response.status_code >= 500:
344-
logger.warning(
345-
"Sorry. Codecov is having problems",
346-
extra=dict(extra_log_attributes=dict(status_code=response.status_code)),
347-
)
348-
return None
349-
if response.status_code >= 400:
350-
logger.warning(
351-
"Got a 4XX status code back from Codecov",
352-
extra=dict(
353-
extra_log_attributes=dict(
354-
status_code=response.status_code, response_json=response.json()
355-
)
356-
),
357-
)
358-
raise click.ClickException(
359-
"There is some problem with the submitted information"
360-
)
361-
except requests.RequestException:
362-
raise click.ClickException(click.style("Unable to reach Codecov", fg="red"))
363-
eid = response.json()["external_id"]
364-
logger.info(
365-
"Label Analysis request successful",
366-
extra=dict(extra_log_attributes=dict(request_id=eid)),
367-
)
368-
return eid
369-
370-
371174
def _dry_run_json_output(
372175
labels_to_run: set,
373176
labels_to_skip: set,

codecov-cli/codecov_cli/commands/report.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
@click.command()
1616
@click.option(
17-
"--code", help="The code of the report. If unsure, leave default", default="default"
17+
"--code", help="The code of the report. If unsure, leave default", default="default", hidden=True
1818
)
1919
@click.option(
2020
"-P",

0 commit comments

Comments
 (0)