Skip to content

Commit

Permalink
Merge branch 'main' into rvinnakota/add-update-repo-mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitvinnakota-codecov authored Jun 4, 2024
2 parents 018dd50 + a3a3716 commit d90c2be
Show file tree
Hide file tree
Showing 72 changed files with 932 additions and 325 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cache_cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ jobs:
- name: Cleanup
run: |
gh extension install actions/gh-actions-cache
REPO=${{ github.repository }}
BRANCH="refs/pull/${{ github.event.pull_request.number }}/merge"
echo "Fetching list of cache key"
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH -L 100 | cut -f 1 )
## Setting this to not fail the workflow while deleting cache keys.
## Setting this to not fail the workflow while deleting cache keys.
set +e
echo "Deleting caches..."
for cacheKey in $cacheKeysForPR
Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,26 @@ permissions:
jobs:
lint:
name: Run Lint
uses: codecov/gha-workflows/.github/workflows/[email protected].19
uses: codecov/gha-workflows/.github/workflows/[email protected].20

build:
name: Build API
uses: codecov/gha-workflows/.github/workflows/[email protected].19
uses: codecov/gha-workflows/.github/workflows/[email protected].20
secrets: inherit
with:
repo: ${{ vars.CODECOV_IMAGE_V2 || 'codecov/self-hosted-api' }}

codecovstartup:
name: Codecov Startup
needs: build
uses: codecov/gha-workflows/.github/workflows/[email protected].19
uses: codecov/gha-workflows/.github/workflows/[email protected].20
secrets: inherit

# ats:
# name: ATS
# needs: [build]
# if: ${{ !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov' }}
# uses: codecov/gha-workflows/.github/workflows/[email protected].19
# uses: codecov/gha-workflows/.github/workflows/[email protected].20
# secrets: inherit
# with:
# repo: ${{ vars.CODECOV_IMAGE_V2 || 'codecov/self-hosted-api' }}
Expand All @@ -47,15 +47,15 @@ jobs:
test:
name: Test
needs: [build]
uses: codecov/gha-workflows/.github/workflows/[email protected].19
uses: codecov/gha-workflows/.github/workflows/[email protected].20
secrets: inherit
with:
repo: ${{ vars.CODECOV_IMAGE_V2 || 'codecov/self-hosted-api' }}

build-self-hosted:
name: Build Self Hosted API
needs: [build, test]
uses: codecov/gha-workflows/.github/workflows/[email protected].19
uses: codecov/gha-workflows/.github/workflows/[email protected].20
secrets: inherit
with:
repo: ${{ vars.CODECOV_IMAGE_V2 || 'codecov/self-hosted-api' }}
Expand All @@ -64,7 +64,7 @@ jobs:
name: Push Staging Image
needs: [build, test]
if: ${{ github.event_name == 'push' && github.event.ref == 'refs/heads/staging' && github.repository_owner == 'codecov' }}
uses: codecov/gha-workflows/.github/workflows/[email protected].19
uses: codecov/gha-workflows/.github/workflows/[email protected].20
secrets: inherit
with:
environment: staging
Expand All @@ -74,7 +74,7 @@ jobs:
name: Push Production Image
needs: [build, test]
if: ${{ github.event_name == 'push' && github.event.ref == 'refs/heads/main' && github.repository_owner == 'codecov' }}
uses: codecov/gha-workflows/.github/workflows/[email protected].19
uses: codecov/gha-workflows/.github/workflows/[email protected].20
secrets: inherit
with:
environment: production
Expand All @@ -85,7 +85,7 @@ jobs:
needs: [build-self-hosted, test]
secrets: inherit
if: ${{ github.event_name == 'push' && github.event.ref == 'refs/heads/main' && github.repository_owner == 'codecov' }}
uses: codecov/gha-workflows/.github/workflows/[email protected].19
uses: codecov/gha-workflows/.github/workflows/[email protected].20
with:
push_rolling: true
repo: ${{ vars.CODECOV_IMAGE_V2 || 'codecov/self-hosted-api' }}
2 changes: 1 addition & 1 deletion .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ on:
jobs:
patch-typing-check:
name: Run Patch Type Check
uses: codecov/gha-workflows/.github/workflows/[email protected].19
uses: codecov/gha-workflows/.github/workflows/[email protected].20
2 changes: 1 addition & 1 deletion .github/workflows/self-hosted-release-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ on:
jobs:
create-release-pr:
name: Create PR for Release ${{ github.event.inputs.versionName }}
uses: codecov/gha-workflows/.github/workflows/[email protected].19
uses: codecov/gha-workflows/.github/workflows/[email protected].20
secrets: inherit
4 changes: 2 additions & 2 deletions .github/workflows/self-hosted-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ jobs:
create-release:
name: Tag Release ${{ github.head_ref }} and Push Docker image to Docker Hub
if: ${{ github.event.pull_request.merged == true && startsWith(github.head_ref, 'release/') && github.repository_owner == 'codecov' }}
uses: codecov/gha-workflows/.github/workflows/[email protected].19
uses: codecov/gha-workflows/.github/workflows/[email protected].20
with:
tag_to_prepend: self-hosted-
secrets: inherit

push-image:
needs: [create-release]
if: ${{ github.event.pull_request.merged == true && startsWith(github.head_ref, 'release/') && github.repository_owner == 'codecov' }}
uses: codecov/gha-workflows/.github/workflows/[email protected].19
uses: codecov/gha-workflows/.github/workflows/[email protected].20
secrets: inherit
with:
push_release: true
Expand Down
10 changes: 5 additions & 5 deletions api/internal/tests/views/test_account_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ def setUp(self):
"invoice_pdf": "https://pay.stripe.com/invoice/acct_1032D82eZvKYlo2C/invst_a7KV10HpLw2QxrihgVyuOkOjMZ/pdf",
"line_items": [
{
"description": "(10) users-inappm",
"description": "(10) users-pr-inappm",
"amount": 120,
"currency": "usd",
"plan_name": "users-inappm",
"plan_name": "users-pr-inappm",
"quantity": 1,
"period": {"end": 1521326190, "start": 1518906990},
}
Expand Down Expand Up @@ -480,13 +480,13 @@ def test_account_with_free_user_plan(self):
}

def test_account_with_paid_user_plan_billed_monthly(self):
self.current_owner.plan = "users-inappm"
self.current_owner.plan = "users-pr-inappm"
self.current_owner.save()
response = self._retrieve()
assert response.status_code == status.HTTP_200_OK
assert response.data["plan"] == {
"marketing_name": "Pro",
"value": "users-inappm",
"value": "users-pr-inappm",
"billing_rate": "monthly",
"base_unit_price": 12,
"benefits": [
Expand Down Expand Up @@ -1239,7 +1239,7 @@ def test_update_apply_cancellation_discount(
):
coupon_create_mock.return_value = MagicMock(id="test-coupon-id")

self.current_owner.plan = "users-inappm"
self.current_owner.plan = "users-pr-inappm"
self.current_owner.stripe_customer_id = "flsoe"
self.current_owner.stripe_subscription_id = "djfos"
self.current_owner.save()
Expand Down
4 changes: 2 additions & 2 deletions api/internal/tests/views/test_invoice_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ def setUp(self):
"invoice_pdf": "https://pay.stripe.com/invoice/acct_1032D82eZvKYlo2C/invst_a7KV10HpLw2QxrihgVyuOkOjMZ/pdf",
"line_items": [
{
"description": "(10) users-inappm",
"description": "(10) users-pr-inappm",
"amount": 120,
"quantity": 1,
"currency": "usd",
"plan_name": "users-inappm",
"plan_name": "users-pr-inappm",
"period": {"end": 1521326190, "start": 1518906990},
}
],
Expand Down
2 changes: 1 addition & 1 deletion api/shared/repo/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class RepositoryViewSetMixin(
OwnerPropertyMixin,
viewsets.GenericViewSet,
):
lookup_value_regex = "[\w\.@\:\-~]+"
lookup_value_regex = r"[\w\.@\:\-~]+"
lookup_field = "repo_name"
accessors = RepoAccessors()

Expand Down
2 changes: 1 addition & 1 deletion codecov_auth/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def log(objects, message, user, action_flag=None, add_traceback=False):
if action_flag is None:
action_flag = CHANGE

if type(objects) is not list:
if not isinstance(objects, list):
objects = [objects]

if add_traceback:
Expand Down
25 changes: 23 additions & 2 deletions codecov_auth/tests/unit/views/test_logout.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class LogoutViewTest(TransactionTestCase):
def _get(self, url):
return self.client.get(url, content_type="application/json")

def _post(self, url):
return self.client.post(url, content_type="application/json")

def _is_authenticated(self):
response = self.client.post(
"/graphql/gh",
Expand All @@ -20,10 +23,28 @@ def _is_authenticated(self):
return response.json()["data"]["me"] is not None

def test_logout_when_unauthenticated(self):
res = self._post("/logout")
assert res.status_code == 401

def test_logout_when_authenticated(self):
owner = OwnerFactory()
self.client = Client()
self.client.force_login_owner(owner)

res = self._post("/graphql/gh/")
self.assertEqual(self._is_authenticated(), True)

res = self._post("/logout")
self.assertEqual(res.status_code, 205)

res = self._get("/graphql/gh/")
self.assertEqual(self._is_authenticated(), False)

def test_get_logout_when_unauthenticated(self):
res = self._get("/logout/gh")
assert res.status_code == 302

def test_logout_when_authenticated(self):
def test_get_logout_when_authenticated(self):
owner = OwnerFactory()
self.client = Client()
self.client.force_login_owner(owner)
Expand All @@ -38,7 +59,7 @@ def test_logout_when_authenticated(self):
res = self._get("/graphql/gh/")
self.assertEqual(self._is_authenticated(), False)

def test_logout_when_authenticated_with_redirect(self):
def test_get_logout_when_authenticated_with_redirect(self):
owner = OwnerFactory()
self.client = Client()
self.client.force_login_owner(owner)
Expand Down
2 changes: 1 addition & 1 deletion codecov_auth/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class StateMixin(object):

def __init__(self, *args, **kwargs):
self.redis = get_redis_connection()
return super().__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def _session_key(self) -> str:
return f"{self.service}_oauth_state"
Expand Down
18 changes: 14 additions & 4 deletions codecov_auth/views/logout.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
from django.conf import settings
from django.contrib.auth import logout
from django.shortcuts import redirect
from django.http import HttpRequest
from django.shortcuts import HttpResponse, redirect
from rest_framework.decorators import api_view
from rest_framework.response import Response


def logout_view(request, **kwargs):
redirect_url = settings.CODECOV_DASHBOARD_URL
response = redirect(redirect_url)
@api_view(["GET", "POST"])
def logout_view(request: HttpRequest, **kwargs: str) -> HttpResponse:
if request.method == "POST":
response = Response(status=205)
else:
# Preserving GET logouts until Gazebo is moved off of it.
redirect_url = settings.CODECOV_DASHBOARD_URL
response = redirect(redirect_url)

logout(request)
kwargs_cookie = dict(
domain=settings.COOKIES_DOMAIN, samesite=settings.COOKIE_SAME_SITE
Expand All @@ -16,4 +25,5 @@ def logout_view(request, **kwargs):
# So we need delete in both samesite Strict / Lax for a little while
kwargs_cookie = dict(domain=settings.COOKIES_DOMAIN, samesite="Strict")
response.delete_cookie("staff_user", **kwargs_cookie)

return response
2 changes: 1 addition & 1 deletion core/commands/commit/interactors/get_file_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async def get_file_from_service(self, commit, path):

# When a file received from GH that is larger than 1MB the result will be
# pre-decoded and of string type; no need to decode again in that case
if type(content.get("content")) == str:
if isinstance(content.get("content"), str):
return content.get("content")
return content.get("content").decode("utf-8")
# TODO raise this to the API so we can handle it.
Expand Down
2 changes: 1 addition & 1 deletion core/migrations/0026_auto_20230605_1134.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Migration(migrations.Migration):
operations = [
migrations.RunSQL(
"""
ALTER TYPE notifications ADD VALUE IF NOT exists 'codecov_slack_app';
ALTER TYPE notifications ADD VALUE IF NOT exists 'codecov_slack_app';
"""
),
]
2 changes: 1 addition & 1 deletion graphql_api/dataloader/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def key(cls, commit):

def __init__(self, info, repository_id, *args, **kwargs):
self.repository_id = repository_id
return super().__init__(info, *args, **kwargs)
super().__init__(info, *args, **kwargs)

def batch_queryset(self, keys):
# We don't select the `report` or `files_array` columns here b/c then can be
Expand Down
2 changes: 1 addition & 1 deletion graphql_api/dataloader/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def key(cls, commit_comparison):

def __init__(self, info, repository_id, *args, **kwargs):
self.repository_id = repository_id
return super().__init__(info, *args, **kwargs)
super().__init__(info, *args, **kwargs)

def batch_queryset(self, keys):
return CommitComparisonService.fetch_precomputed(self.repository_id, keys)
Expand Down
38 changes: 38 additions & 0 deletions graphql_api/tests/mutation/test_cancel_trial.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from django.test import TransactionTestCase
from prometheus_client import REGISTRY

from codecov_auth.tests.factories import OwnerFactory
from graphql_api.tests.helper import GraphQLTestHelper
from graphql_api.views import GQL_ERROR_COUNTER, GQL_HIT_COUNTER, GQL_REQUEST_LATENCIES
from plan.constants import PlanName, TrialStatus

query = """
Expand Down Expand Up @@ -37,6 +39,27 @@ def test_unauthenticated(self):
}

def test_authenticated(self):
GQL_HIT_COUNTER.labels(
operation_type="mutation", operation_name="CancelTrialInput"
)
GQL_ERROR_COUNTER.labels(
operation_type="mutation", operation_name="CancelTrialInput"
)
GQL_REQUEST_LATENCIES.labels(
operation_type="mutation", operation_name="CancelTrialInput"
)
before = REGISTRY.get_sample_value(
"api_gql_counts_hits_total",
labels={"operation_type": "mutation", "operation_name": "CancelTrialInput"},
)
errors_before = REGISTRY.get_sample_value(
"api_gql_counts_errors_total",
labels={"operation_type": "mutation", "operation_name": "CancelTrialInput"},
)
timer_before = REGISTRY.get_sample_value(
"api_gql_timers_full_runtime_seconds_count",
labels={"operation_type": "mutation", "operation_name": "CancelTrialInput"},
)
trial_status = TrialStatus.ONGOING.value
owner = OwnerFactory(
trial_status=trial_status, plan=PlanName.TRIAL_PLAN_NAME.value
Expand All @@ -45,3 +68,18 @@ def test_authenticated(self):
assert self._request(owner=owner, org_username=owner.username) == {
"cancelTrial": None
}
after = REGISTRY.get_sample_value(
"api_gql_counts_hits_total",
labels={"operation_type": "mutation", "operation_name": "CancelTrialInput"},
)
errors_after = REGISTRY.get_sample_value(
"api_gql_counts_errors_total",
labels={"operation_type": "mutation", "operation_name": "CancelTrialInput"},
)
timer_after = REGISTRY.get_sample_value(
"api_gql_timers_full_runtime_seconds_count",
labels={"operation_type": "mutation", "operation_name": "CancelTrialInput"},
)
assert after - before == 1
assert errors_after - errors_before == 0
assert timer_after - timer_before == 1
Loading

0 comments on commit d90c2be

Please sign in to comment.