# How GitHub Usernames Are Extracted from Resume Profiles in the Hiring Agent

> Discover how the hiring agent extracts GitHub usernames from resumes using regex to parse URLs in network entries. Learn the technical process behind this resume analysis.

- Repository: [HackerRank/hiring-agent](https://github.com/interviewstreet/hiring-agent)
- Tags: how-to-guide
- Published: 2026-07-14

---

**The interviewstreet/hiring-agent extracts GitHub usernames by scanning resume profile objects for network entries labeled "github", then parsing the URL with regex patterns in [`github.py`](https://github.com/interviewstreet/hiring-agent/blob/main/github.py) to isolate the username before writing it to a CSV field.**

The **interviewstreet/hiring-agent** repository processes JSON Resume files to automate technical candidate screening. A critical step in this pipeline involves identifying GitHub profile URLs within the resume's *profiles* section and extracting clean usernames for downstream analysis. This process relies on coordinated logic between [`transform.py`](https://github.com/interviewstreet/hiring-agent/blob/main/transform.py) and [`github.py`](https://github.com/interviewstreet/hiring-agent/blob/main/github.py) to normalize URLs and apply pattern matching.

## Profile Discovery in transform.py

The extraction pipeline begins in [`transform.py`](https://github.com/interviewstreet/hiring-agent/blob/main/transform.py) where the `fetch_profile` helper function traverses the list of profile objects from the resume's `basics.profiles` section. Each profile contains a `network` name and a `url`. When the function identifies a profile whose `network` field matches "github", it triggers the extraction workflow.

At lines 544-545, the resolved username is assigned to the CSV output row:

```python
csv_row["github_username"] = (
    github_profile.username if github_profile.username else ""
)

```

This ensures that downstream evaluation modules receive a standardized string value, defaulting to empty if no username is found.

## Username Extraction Logic in github.py

The actual parsing occurs in [`github.py`](https://github.com/interviewstreet/hiring-agent/blob/main/github.py) within the `extract_github_username` function (lines 124-129). This utility first sanitizes the input URL by removing whitespace, then iterates through two regex patterns to locate the username segment.

```python
def extract_github_username(github_url: str) -> Optional[str]:
    if not github_url:
        return None
    github_url = github_url.replace(" ", "").strip()
    patterns = [
        r"https?://github\.com/([^/]+)",
        r"github\.com/([^/]+)",
    ]
    for pattern in patterns:
        match = re.search(pattern, github_url)
        if match:
            return match.group(1)
    return None

```

The function returns the first captured group from the matching pattern, or `None` if the URL format is unrecognized.

## Regex Pattern Analysis

The extraction logic employs two complementary patterns to handle URL variations:

- **`r"https?://github\.com/([^/]+)"`** — Matches standard URLs with optional HTTP or HTTPS protocols, capturing the first path segment as the username.
- **`r"github\.com/([^/]+)"`** — Matches domain-only references without protocol prefixes.

Both patterns use `re.search` to locate the match and `([^/]+)` to capture the username while stopping at the next forward slash. This prevents trailing paths (such as `/repos` or `/projects`) from polluting the extracted value.

## Summary

- **Profile Scanning**: The `fetch_profile` function in [`transform.py`](https://github.com/interviewstreet/hiring-agent/blob/main/transform.py) identifies GitHub entries by matching the `network` field against "github".
- **URL Normalization**: `extract_github_username` strips all whitespace and applies `.strip()` before regex evaluation.
- **Regex Extraction**: Two patterns handle both protocol-prefixed (`https://`) and bare domain URLs, capturing only the first path segment as the username.
- **CSV Output**: The extracted value is stored in the `github_username` column, with empty strings used for failed extractions.

## Frequently Asked Questions

### What happens if a resume lists multiple GitHub profiles?

The `fetch_profile` function processes the first profile entry where the `network` field matches "github". Subsequent GitHub URLs in the same resume are ignored, ensuring only one username is extracted per candidate.

### How does the extractor handle HTTP versus HTTPS URLs?

The regex pattern `r"https?://github\.com/([^/]+)"` uses the optional quantifier `?` to match both protocols. This ensures extraction succeeds whether the resume contains `http://github.com/username` or `https://github.com/username`.

### What if the GitHub URL contains additional path segments?

The regex `([^/]+)` captures only the first path segment after `github.com/` and stops at the next forward slash. For example, `https://github.com/jane-doe/repos` correctly extracts only "jane-doe", ignoring the `/repos` suffix.

### Where is the extracted username stored in the output?

According to [`transform.py`](https://github.com/interviewstreet/hiring-agent/blob/main/transform.py) lines 544-545, the username is written to the `github_username` column in the generated CSV row. If extraction fails or returns `None`, the field is populated with an empty string.