Skip to content

Commit

Permalink
Call static analysis finish endpoint after uploading files
Browse files Browse the repository at this point in the history
This commit changes the static-analysis command in the CLI,
such that it calls the staticanalysis/analyses/<external_id>/finish
endpoint in the API after it uploads the necessary files.
This endpoint schedules the static analysis task on the worker
immediately.

Fixes: #66
  • Loading branch information
joseph-sentry committed Jun 19, 2023
1 parent 1776cc4 commit 6b53bb4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
25 changes: 25 additions & 0 deletions codecov_cli/services/staticanalysis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,31 @@ async def run_analysis_entrypoint(
)
else:
logger.info("All files are already uploaded!")
try:
external_id = response_json["external_id"]
logger.debug(
"Sending finish signal to let API know to schedule static analysis task",
extra=dict(extra_log_attributes=dict(external_id=external_id)),
)
upload_url = enterprise_url or CODECOV_API_URL
response = requests.post(
f"{upload_url}/staticanalysis/analyses/{external_id}/finish",
headers={"Authorization": f"Repotoken {token}"},
)
if response.status_code >= 500:
raise click.ClickException("Sorry. Codecov is having problems")
if response.status_code >= 400:
raise click.ClickException(
f"There is some problem with the submitted information.\n{response_json.get('detail')}"
)
except requests.RequestException:
raise click.ClickException(click.style("Unable to reach Codecov", fg="red"))
logger.info(
"Received response from server",
extra=dict(
extra_log_attributes=dict(time_taken=response.elapsed.total_seconds())
),
)


async def send_single_upload_put(client, all_data, el):
Expand Down
19 changes: 19 additions & 0 deletions tests/services/static_analysis/test_static_analysis_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ async def side_effect(*args, **kwargs):
responses.POST,
"https://api.codecov.io/staticanalysis/analyses",
json={
"external_id": "externalid",
"filepaths": [
{
"state": "created",
Expand All @@ -55,6 +56,15 @@ async def side_effect(*args, **kwargs):
matchers.header_matcher({"Authorization": "Repotoken STATIC_TOKEN"})
],
)
rsps.add(
responses.POST,
"https://api.codecov.io/staticanalysis/analyses/externalid/finish",
status=204,
match=[
matchers.header_matcher({"Authorization": "Repotoken STATIC_TOKEN"})
],
)

await run_analysis_entrypoint(
config={},
folder=".",
Expand Down Expand Up @@ -103,6 +113,7 @@ async def side_effect(*args, **kwargs):
responses.POST,
"https://api.codecov.io/staticanalysis/analyses",
json={
"external_id": "externalid",
"filepaths": [
{
"state": "created",
Expand All @@ -121,6 +132,14 @@ async def side_effect(*args, **kwargs):
matchers.header_matcher({"Authorization": "Repotoken STATIC_TOKEN"})
],
)
rsps.add(
responses.POST,
"https://api.codecov.io/staticanalysis/analyses/externalid/finish",
status=204,
match=[
matchers.header_matcher({"Authorization": "Repotoken STATIC_TOKEN"})
],
)
await run_analysis_entrypoint(
config={},
folder=".",
Expand Down

0 comments on commit 6b53bb4

Please sign in to comment.