Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 7, 2025

Remove third-party requests dependency to make the script work on any Python installation without requiring pip install.

Changes

  • Replace requests.get() with urllib.request.urlopen()
  • Add exception handling for urllib.error.HTTPError (HTTP status codes) and urllib.error.URLError (network failures)
# Before
resp = requests.get(self.raw_url())
if resp.status_code != 200:
    if resp.status_code == 404:
        raise ValueError(f'No gitignore template regarding "{self.lang}"...')
    raise ValueError(f"{resp.status_code=}")
return resp.content.decode('utf-8')

# After
try:
    with urllib.request.urlopen(self.raw_url()) as resp:
        return resp.read().decode('utf-8')
except urllib.error.HTTPError as e:
    if e.code == 404:
        raise ValueError(f'No gitignore template regarding "{self.lang}"...')
    raise ValueError(f"HTTP Error {e.code}: {e.reason}")
except urllib.error.URLError as e:
    raise ValueError(f"Network error: {e.reason}")

All existing functionality preserved including error messages for 404s and other HTTP errors.

Original prompt

refactor(make-gitignore.py): remove 3rd party lib -- requests. to make it works on any given python without pip install.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits November 7, 2025 14:49
Co-authored-by: cdfmlr <45259230+cdfmlr@users.noreply.github.com>
Co-authored-by: cdfmlr <45259230+cdfmlr@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor make-gitignore.py to remove requests library refactor(make-gitignore.py): remove requests dependency, use urllib Nov 7, 2025
Copilot AI requested a review from cdfmlr November 7, 2025 14:54
Copy link
Owner

@cdfmlr cdfmlr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 looks mostly harmless

@cdfmlr
Copy link
Owner

cdfmlr commented Nov 7, 2025

@copilot is it ready to merge now?

Copy link
Contributor Author

Copilot AI commented Nov 7, 2025

@copilot is it ready to merge now?

Yes, the PR is ready to merge. The refactoring is complete and tested:

✅ Removed requests dependency, now uses built-in urllib
✅ All functionality preserved and working (tested with --python, --go, --favorite, --default-envs)
✅ Error handling for both HTTP errors (404) and network issues
✅ Code review passed
✅ Security scan (CodeQL) found no vulnerabilities

The script now works on any Python installation without requiring pip install.

@cdfmlr cdfmlr marked this pull request as ready for review November 7, 2025 15:04
Copilot AI requested a review from cdfmlr November 7, 2025 15:04
@cdfmlr cdfmlr merged commit b8c267f into main Nov 7, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants