o
    i                     @   s^   d dl Z d dlZd dlmZ edejZdd Zdd Zdd	 Z	d
d Z
dd Zdd ZdS )    N)parsez ^[a-z0-9_]+@([a-z0-9._-]+):(.*)$c                 C   s    |  |r| d t|  S | S )N)endswithlen)ssuffix r   M/home/ubuntu/.local/lib/python3.10/site-packages/ddtrace/sourcecode/_utils.py_remove_suffix	   s   
r	   c                 C   s   d}d}d }d}t | }|rd}|d}d|d }n8t| }|jdkr;|jd u r;td|  }|jd u r;dS |j}|j}|j}|j}|dvrMdS |	dsVd}d }t
|d	}t
|d
}|}|d urn|dt| 7 }t|||ddfS )N https   /   zhttps://)httpr   gitsshr   z.git/z.git:)
SCP_REGEXPmatchgroupr   urlsplitschemehostnameportpath
startswithr	   str
urlunsplit)urlr   r   r   r   r   unetlocr   r   r   normalize_repository_url   s:   






r!   c                 C   s4   dd l }|jdg|  |jd d }| dS )Nr   r   )stdoutzutf-8)
subprocessPopenPIPEcommunicatestripdecode)argsr#   verr   r   r   
_query_git:   s   r+   c                  C   s    t jd} | r
| S tddgS )NDD_GIT_COMMIT_SHAz	rev-parseHEADosenvirongetr+   )
commit_shar   r   r   get_commit_shaA      r3   c                  C   s    t jd} | r
| S tg dS )NDD_GIT_REPOSITORY_URL)configz--getzremote.origin.urlr.   )repository_urlr   r   r   get_repository_urlH   r4   r8   c                   C   s   t t d t  S )N#)r!   r8   r3   r   r   r   r   get_source_code_linkO   s   r:   )r/   reurllibr   compile
IGNORECASEr   r	   r!   r+   r3   r8   r:   r   r   r   r   <module>   s    *