Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start using pre-commit in CI #800

Merged
merged 10 commits into from
Dec 12, 2023
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install build dependencies
run: pip install -r docs/requirements.txt
- name: Rendering HTML documentation
Expand Down
22 changes: 0 additions & 22 deletions .github/workflows/lint.yml

This file was deleted.

62 changes: 62 additions & 0 deletions .github/workflows/pre-commit-detect-outdated.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright (c) 2023 Sebastian Pipping <sebastian@pipping.org>
# Licensed under the MIT license

name: Detect outdated pre-commit hooks

on:
schedule:
- cron: '0 16 * * 5' # Every Friday 4pm

# NOTE: This will drop all permissions from GITHUB_TOKEN except metadata read,
# and then (re)add the ones listed below:
permissions:
contents: write
pull-requests: write

jobs:
pre_commit_detect_outdated:
name: Detect outdated pre-commit hooks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: 3.12

- name: Install pre-commit
run: |-
pip install \
--disable-pip-version-check \
--no-warn-script-location \
--user \
pre-commit
echo "PATH=${HOME}/.local/bin:${PATH}" >> "${GITHUB_ENV}"

- name: Check for outdated hooks
run: |-
pre-commit autoupdate
git diff -- .pre-commit-config.yaml

- name: Create pull request from changes (if any)
id: create-pull-request
uses: peter-evans/create-pull-request@v5
with:
author: 'pre-commit <pre-commit@tools.invalid>'
base: master
body: |-
For your consideration.

:warning: Please **CLOSE AND RE-OPEN** this pull request so that [further workflow runs get triggered](https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#triggering-further-workflow-runs) for this pull request.
branch: precommit-autoupdate
commit-message: "pre-commit: Autoupdate"
delete-branch: true
draft: true
labels: enhancement
title: "pre-commit: Autoupdate"

- name: Log pull request URL
if: "${{ steps.create-pull-request.outputs.pull-request-url }}"
run: |
echo "Pull request URL is: ${{ steps.create-pull-request.outputs.pull-request-url }}"
20 changes: 20 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (c) 2023 Sebastian Pipping <sebastian@pipping.org>
# Licensed under the MIT license

name: Run pre-commit

on:
- pull_request
- push
jairhenrique marked this conversation as resolved.
Show resolved Hide resolved
- workflow_dispatch

jobs:
pre-commit:
name: Run pre-commit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.12
- uses: pre-commit/action@v3.0.0
17 changes: 17 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright (c) 2023 Sebastian Pipping <sebastian@pipping.org>
# Licensed under the MIT license

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.7
hooks:
- id: ruff
jairhenrique marked this conversation as resolved.
Show resolved Hide resolved
args: ["--show-source"]
- id: ruff-format
jairhenrique marked this conversation as resolved.
Show resolved Hide resolved

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-merge-conflict
- id: end-of-file-fixer
- id: trailing-whitespace
2 changes: 1 addition & 1 deletion docs/_static/vcr.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions docs/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ a nice addition. Here's an example:
with vcr.use_cassette('fixtures/vcr_cassettes/synopsis.yaml') as cass:
response = urllib2.urlopen('http://www.zombo.com/').read()
# cass should have 1 request inside it
assert len(cass) == 1
assert len(cass) == 1
# the request uri should have been http://www.zombo.com/
assert cass.requests[0].uri == 'http://www.zombo.com/'

Expand Down Expand Up @@ -208,7 +208,7 @@ So these two calls are the same:

# original (still works)
vcr = VCR(filter_headers=['authorization'])

# new
vcr = VCR(filter_headers=[('authorization', None)])

Expand All @@ -218,7 +218,7 @@ Here are two examples of the new functionality:

# replace with a static value (most common)
vcr = VCR(filter_headers=[('authorization', 'XXXXXX')])

# replace with a callable, for example when testing
# lots of different kinds of authorization.
def replace_auth(key, value, request):
Expand Down Expand Up @@ -286,7 +286,7 @@ sensitive data from the response body:
before_record_response=scrub_string(settings.USERNAME, 'username'),
)
with my_vcr.use_cassette('test.yml'):
# your http code here
# your http code here


Decode compressed response
Expand Down
1 change: 0 additions & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,3 @@ All help in providing PRs to close out bug issues is appreciated. Even if that i
- Add support for requests / urllib3
- 0.0.1
- Initial Release

2 changes: 1 addition & 1 deletion runtests.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# https://blog.ionelmc.ro/2015/04/14/tox-tricks-and-patterns/#when-it-inevitably-leads-to-shell-scripts
# If you are getting an INVOCATION ERROR for this script then there is
# If you are getting an INVOCATION ERROR for this script then there is
# a good chance you are running on Windows.
# You can and should use WSL for running tox on Windows when it calls bash scripts.
REQUESTS_CA_BUNDLE=`python3 -m pytest_httpbin.certs` exec pytest "$@"
6 changes: 3 additions & 3 deletions tests/fixtures/migration/new_cassette.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
},
"response": {
"status": {
"message": "OK",
"message": "OK",
"code": 200
},
},
"headers": {
"access-control-allow-origin": ["*"],
"content-type": ["application/json"],
"date": ["Mon, 21 Apr 2014 23:13:40 GMT"],
"server": ["gunicorn/0.17.4"],
"content-length": ["32"],
"connection": ["keep-alive"]
},
},
"body": {
"string": "{\n \"origin\": \"217.122.164.194\"\n}"
}
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/migration/new_cassette.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 1
interactions:
- request:
body: null
headers:
headers:
accept: ['*/*']
accept-encoding: ['gzip, deflate, compress']
user-agent: ['python-requests/2.2.1 CPython/2.6.1 Darwin/10.8.0']
Expand Down
34 changes: 17 additions & 17 deletions tests/fixtures/migration/old_cassette.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
[
{
"request": {
"body": null,
"protocol": "http",
"method": "GET",
"body": null,
"protocol": "http",
"method": "GET",
"headers": {
"accept-encoding": "gzip, deflate, compress",
"accept": "*/*",
"accept-encoding": "gzip, deflate, compress",
"accept": "*/*",
"user-agent": "python-requests/2.2.1 CPython/2.6.1 Darwin/10.8.0"
},
"host": "httpbin.org",
"path": "/ip",
},
"host": "httpbin.org",
"path": "/ip",
"port": 80
},
},
"response": {
"status": {
"message": "OK",
"message": "OK",
"code": 200
},
},
"headers": [
"access-control-allow-origin: *\r\n",
"content-type: application/json\r\n",
"date: Mon, 21 Apr 2014 23:13:40 GMT\r\n",
"server: gunicorn/0.17.4\r\n",
"content-length: 32\r\n",
"access-control-allow-origin: *\r\n",
"content-type: application/json\r\n",
"date: Mon, 21 Apr 2014 23:13:40 GMT\r\n",
"server: gunicorn/0.17.4\r\n",
"content-length: 32\r\n",
"connection: keep-alive\r\n"
],
],
"body": {
"string": "{\n \"origin\": \"217.122.164.194\"\n}"
}
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/wild/domain_redirect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interactions:
uri: http://seomoz.org/
response:
body: {string: ''}
headers:
headers:
Location: ['http://moz.com/']
Server: ['BigIP']
Connection: ['Keep-Alive']
Expand Down