Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/ambv/black
rev: 24.4.2
rev: 26.3.1
hooks:
- id: black
language_version: python3.13
Expand Down
27 changes: 18 additions & 9 deletions jf_agent/data_manifests/git/adapters/github.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from dateutil import parser as datetime_parser
from typing import Generator

from dateutil import parser as datetime_parser

from jf_agent.data_manifests.git.adapters.manifest_adapter import ManifestAdapter
from jf_agent.data_manifests.git.manifest import (
GitBranchManifest,
Expand All @@ -15,11 +16,17 @@
# TODO: Expand or generalize this to work with things other than github (BBCloud, Gitlab, etc)
class GithubManifestGenerator(ManifestAdapter):
'''
Basic client for probing a GH instance.
Basic client for probing a GH instance.
'''

def __init__(
self, token: str, base_url: str, company: str, org: str, instance: str, verify=True,
self,
token: str,
base_url: str,
company: str,
org: str,
instance: str,
verify=True,

Check warning on line 29 in jf_agent/data_manifests/git/adapters/github.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add a type hint to this function parameter.

See more on https://sonarcloud.io/project/issues?id=Jellyfish-AI_jf_agent&issues=AZ3VfnvFnlOhHId1Zf66&open=AZ3VfnvFnlOhHId1Zf66&pullRequest=449
) -> None:
# Super class fields
self.company = company
Expand Down Expand Up @@ -50,12 +57,14 @@
user_count=repo['users']['totalCount'],
pull_request_count=repo['prs']['totalCount'],
branch_count=repo['branches']['totalCount'],
commits_on_default_branch=repo['defaultBranch']['target']['history']['totalCount']
if repo['defaultBranch']
else 0,
default_branch_name=repo['defaultBranch']['name']
if repo['defaultBranch']
else None,
commits_on_default_branch=(
repo['defaultBranch']['target']['history']['totalCount']
if repo['defaultBranch']
else 0
),
default_branch_name=(
repo['defaultBranch']['name'] if repo['defaultBranch'] else None
),
)

def get_all_user_data(self) -> Generator[GitUserManifest, None, None]:
Expand Down
1 change: 1 addition & 0 deletions jf_agent/data_manifests/git/adapters/manifest_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
GitUserManifest,
)


# TODO: Expand or generalize this to work with things other than github (BBCloud, Gitlab, etc)
@dataclass
class ManifestAdapter(ABC):
Expand Down
19 changes: 9 additions & 10 deletions jf_agent/data_manifests/git/generator.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import logging
from jf_agent.config_file_reader import GitConfig

from jf_agent.data_manifests.git.adapters.manifest_adapter import ManifestAdapter
from jf_ingest import logging_helper

from jf_agent.data_manifests.git.manifest import (
GitDataManifest,
GitRepoManifest,
GitUserManifest,
)
from jf_agent.config_file_reader import GitConfig
from jf_agent.data_manifests.git.adapters.github import GithubManifestGenerator
from jf_agent.data_manifests.git.adapters.manifest_adapter import ManifestAdapter
from jf_agent.data_manifests.git.manifest import GitDataManifest, GitRepoManifest, GitUserManifest
from jf_agent.data_manifests.manifest import ManifestSource

from jf_ingest import logging_helper

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -145,7 +140,11 @@ def create_manifests(


def get_manifest_adapter(
company_slug: str, git_creds: dict, git_config: GitConfig, instance: str, org: str,
company_slug: str,
git_creds: dict,
git_config: GitConfig,
instance: str,
org: str,
):
if git_config.git_provider != 'github':
raise UnsupportedGitProvider(
Expand Down
2 changes: 1 addition & 1 deletion jf_agent/data_manifests/git/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

from jf_agent.data_manifests.manifest import Manifest, ManifestSource


IGitDataManifest = TypeVar('IGitDataManifest', bound='GitDataManifest')
IGitRepoManifest = TypeVar('IGitRepoManifest', bound='GitRepoManifest')
IGitUserManifest = TypeVar('IGitUserManifest', bound='GitUserManifest')
IGitPullRequestManifest = TypeVar('IGitPullRequestManifest', bound='GitPullRequestManifest')


# This is the parent class for all GitManifest type classes. It inherits
# from manifests, but ensures that all 'GitManifests' have an instance
@dataclass
Expand Down
7 changes: 3 additions & 4 deletions jf_agent/data_manifests/jira/generator.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from concurrent.futures import ThreadPoolExecutor
import logging
from concurrent.futures import ThreadPoolExecutor

from jf_agent.data_manifests.jira.adapter import JiraCloudManifestAdapter
from jira import JIRAError

from jf_agent.data_manifests.jira.adapter import JiraCloudManifestAdapter
from jf_agent.data_manifests.jira.manifest import JiraDataManifest, JiraProjectManifest
from jf_agent.data_manifests.manifest import ManifestSource
from jira import JIRAError


logger = logging.getLogger(__name__)

Expand Down
8 changes: 4 additions & 4 deletions jf_agent/data_manifests/manifest.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import gzip
import json
import logging
from abc import ABC, abstractmethod
from dataclasses import dataclass, field
from datetime import datetime
from enum import Enum
import json
from typing import Optional, TypeVar

import requests

from jf_ingest import logging_helper


logger = logging.getLogger(__name__)

IManifest = TypeVar('IManifest', bound='Manifest')
Expand Down Expand Up @@ -102,7 +100,9 @@ def to_local_file(
with open(file_name, 'w') as f:
f.write(self.to_json_str())

def upload_to_s3(self, jellyfish_api_base: str, jellyfish_api_token: str, skip_ssl_verification: bool = False) -> None:
def upload_to_s3(
self, jellyfish_api_base: str, jellyfish_api_token: str, skip_ssl_verification: bool = False
) -> None:
headers = {'Jellyfish-API-Token': jellyfish_api_token, 'content-encoding': 'gzip'}

logger.info(f'Attempting to upload {self.get_unique_key()} manifest to s3...')
Expand Down
6 changes: 3 additions & 3 deletions jf_agent/git/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,9 @@ def load_and_dump_git(
else:
from jf_agent.git.gitlab_adapter import GitLabAdapter

GitLabAdapter(config, outdir, compress_output_files, git_connection).load_and_dump_git(
endpoint_git_instance_info
)
GitLabAdapter(
config, outdir, compress_output_files, git_connection
).load_and_dump_git(endpoint_git_instance_info)
elif config.git_provider == ADO_PROVIDER:
for jf_ingest_git_config in jf_ingest_config.git_configs:
if jf_ingest_git_config.instance_slug == instance_slug:
Expand Down
76 changes: 52 additions & 24 deletions jf_agent/git/bitbucket_cloud_adapter.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
from jf_agent.git.utils import get_branches_for_standardized_repo
from tqdm import tqdm
import logging
import re
from dateutil import parser
from typing import List
import logging

import requests
from dateutil import parser
from jf_ingest import diagnostics, logging_helper
from tqdm import tqdm

from jf_agent.config_file_reader import GitConfig
from jf_agent.git import (
GitAdapter,
StandardizedUser,
StandardizedProject,
StandardizedBranch,
StandardizedRepository,
StandardizedCommit,
StandardizedProject,
StandardizedPullRequest,
StandardizedPullRequestComment,
StandardizedPullRequestReview,
StandardizedRepository,
StandardizedShortRepository,
StandardizedUser,
pull_since_date_for_repo,
)
from jf_agent.git.bitbucket_cloud_client import BitbucketCloudClient

from jf_agent.git.utils import get_branches_for_standardized_repo
from jf_agent.name_redactor import NameRedactor, sanitize_text
from jf_agent.config_file_reader import GitConfig
from jf_ingest import diagnostics, logging_helper

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -68,7 +68,8 @@
@diagnostics.capture_timing()
@logging_helper.log_entry_exit(logger)
def get_repos(
self, standardized_projects: List[StandardizedProject],
self,
standardized_projects: List[StandardizedProject],
) -> List[StandardizedRepository]:
logger.info('downloading bitbucket repos...')

Expand Down Expand Up @@ -195,7 +196,9 @@
@diagnostics.capture_timing()
@logging_helper.log_entry_exit(logger)
def get_pull_requests(
self, standardized_repos: List[StandardizedRepository], server_git_instance_info,
self,
standardized_repos: List[StandardizedRepository],
server_git_instance_info,

Check warning on line 201 in jf_agent/git/bitbucket_cloud_adapter.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add a type hint to this function parameter.

See more on https://sonarcloud.io/project/issues?id=Jellyfish-AI_jf_agent&issues=AZ3VfnqVnlOhHId1Zf6y&open=AZ3VfnqVnlOhHId1Zf6y&pullRequest=449
) -> List[StandardizedPullRequest]:
logger.info('downloading bitbucket prs...')
for i, repo in enumerate(
Expand Down Expand Up @@ -225,7 +228,9 @@
or not api_pr['destination']['repository']
):
logging_helper.log_standard_error(
logging.WARNING, msg_args=[api_pr['id']], error_code=3030,
logging.WARNING,
msg_args=[api_pr['id']],
error_code=3030,
)
continue

Expand Down Expand Up @@ -257,7 +262,10 @@
except Exception:
# if something happens when pulling PRs for a repo, just keep going.
logging_helper.log_standard_error(
logging.ERROR, msg_args=[repo.id], error_code=3021, exc_info=True,
logging.ERROR,
msg_args=[repo.id],
error_code=3021,
exc_info=True,
)

logger.info('Done downloading PRs!')
Expand Down Expand Up @@ -345,9 +353,9 @@
message=sanitize_text(api_commit['message'], strip_text_content),
is_merge=len(api_commit['parents']) > 1,
repo=standardized_repo.short(), # use short form of repo
branch_name=branch_name
if not redact_names_and_urls
else _branch_redactor.redact_name(branch_name),
branch_name=(
branch_name if not redact_names_and_urls else _branch_redactor.redact_name(branch_name)
),
)


Expand All @@ -372,13 +380,26 @@
username, email = m.groups()
username = username.strip()
email = email.strip()
return StandardizedUser(id=raw_name, login=email, name=username, email=email,)
return StandardizedUser(
id=raw_name,
login=email,
name=username,
email=email,
)

return StandardizedUser(id=raw_name, name=raw_name, login=raw_name,)
return StandardizedUser(
id=raw_name,
name=raw_name,
login=raw_name,
)


def _standardize_pr(
client, repo, api_pr, strip_text_content: bool, redact_names_and_urls: bool,
client,

Check warning on line 398 in jf_agent/git/bitbucket_cloud_adapter.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add a type hint to this function parameter.

See more on https://sonarcloud.io/project/issues?id=Jellyfish-AI_jf_agent&issues=AZ3VfnqVnlOhHId1Zf6z&open=AZ3VfnqVnlOhHId1Zf6z&pullRequest=449
repo,

Check warning on line 399 in jf_agent/git/bitbucket_cloud_adapter.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add a type hint to this function parameter.

See more on https://sonarcloud.io/project/issues?id=Jellyfish-AI_jf_agent&issues=AZ3VfnqVnlOhHId1Zf60&open=AZ3VfnqVnlOhHId1Zf60&pullRequest=449
api_pr,

Check warning on line 400 in jf_agent/git/bitbucket_cloud_adapter.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add a type hint to this function parameter.

See more on https://sonarcloud.io/project/issues?id=Jellyfish-AI_jf_agent&issues=AZ3VfnqVnlOhHId1Zf61&open=AZ3VfnqVnlOhHId1Zf61&pullRequest=449
strip_text_content: bool,
redact_names_and_urls: bool,
):
# Process the PR's diff to get additions, deletions, changed_files
additions, deletions, changed_files = None, None, None
Expand All @@ -387,7 +408,9 @@
additions, deletions, changed_files = _calculate_diff_counts(diff_str)
if additions is None:
logging_helper.log_standard_error(
logging.WARNING, msg_args=[api_pr["id"], repo.id], error_code=3031,
logging.WARNING,
msg_args=[api_pr["id"], repo.id],
error_code=3031,
)
except requests.exceptions.RetryError:
# Server threw a 500 on the request for the diff and we started retrying;
Expand All @@ -401,15 +424,19 @@
elif e.response.status_code == 401:
# Server threw a 401 on the request for the diff; not sure why this would be, but it seems rare
logging_helper.log_standard_error(
logging.WARNING, msg_args=[api_pr["id"], repo.id], error_code=3041,
logging.WARNING,
msg_args=[api_pr["id"], repo.id],
error_code=3041,
)
else:
# Some other HTTP error happened; Re-raise
raise
except UnicodeDecodeError:
# Occasional diffs seem to be invalid UTF-8
logging_helper.log_standard_error(
logging.WARNING, msg_args=[api_pr["id"], repo.id], error_code=3051,
logging.WARNING,
msg_args=[api_pr["id"], repo.id],
error_code=3051,
)

# Comments
Expand All @@ -436,7 +463,8 @@
review_state='APPROVED',
)
for i, approval in enumerate(
(a['approval'] for a in activity if 'approval' in a), start=1,
(a['approval'] for a in activity if 'approval' in a),
start=1,
)
]

Expand Down
10 changes: 6 additions & 4 deletions jf_agent/git/bitbucket_cloud_client.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from collections import deque
from datetime import datetime, timedelta
import logging
import time
from collections import deque
from datetime import datetime, timedelta
from typing import Optional

import requests
from jf_ingest import logging_helper
from requests.utils import default_user_agent

from jf_agent.ratelimit import RateLimiter, RateLimitRealmConfig
from jf_ingest import logging_helper

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -146,7 +146,9 @@ def get_all_pages(self, url, rate_limit_realm=None, ignore404=False):
except requests.exceptions.HTTPError as e:
if e.response.status_code == 404 and ignore404:
# URLs are potentially sensitive data, so print instead of log!
print(f'Caught a 404 for {url} - ignoring',)
print(
f'Caught a 404 for {url} - ignoring',
)
return
raise

Expand Down
Loading
Loading