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

Add extra_headers option to get methods #192

Merged
merged 10 commits into from
May 26, 2023

Conversation

basnijholt
Copy link
Contributor

@basnijholt basnijholt commented Apr 12, 2023

This allows to do for example:

async def get_stargazers_with_dates(full_repo_name):
    headers = {"Accept": "application/vnd.github.v3.star+json"}
    async with httpx.AsyncClient() as client:
        gh = gidgethub.httpx.GitHubAPI(client, "basnijholt", oauth_token=token)
        repo_owner, repo_name = full_repo_name.split("/")
        stats_contributors = await gh.getitem(
            f"/repos/{repo_owner}/{repo_name}/stargazers", extra_headers=headers
        )
        return stats_contributors

await get_stargazers_with_dates("basnijholt/adaptive-lighting")

Some more extra headers folks might want to use:

https://github.com/PyGithub/PyGithub/blob/300c5015d41236eb410b9cbe895258294e3500af/github/Consts.py#L58-L133

Closes #193

This allows to do for example:

```python
async def get_stargazers_with_dates(full_repo_name):
    headers = {"Accept": "application/vnd.github.v3.star+json"}
    async with httpx.AsyncClient() as client:
        gh = gidgethub.httpx.GitHubAPI(client, "basnijholt", oauth_token=token)
        repo_owner, repo_name = full_repo_name.split("/")
        stats_contributors = await gh.getitem(
            f"/repos/{repo_owner}/{repo_name}/stargazers", extra_headers=headers
        )
        return stats_contributors

await get_stargazers_with_dates("basnijholt/adaptive-lighting")
```
@brettcannon
Copy link
Collaborator

Would you mind opening a corresponding issue so we can discuss the API proposal there?

@brettcannon
Copy link
Collaborator

And without doing a review, I noticed there are no tests.

@basnijholt
Copy link
Contributor Author

I have opened #193 and I added some tests.

@codecov-commenter
Copy link

codecov-commenter commented Apr 27, 2023

Codecov Report

Merging #192 (06bdcdd) into main (901f057) will not change coverage.
The diff coverage is 100.00%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff            @@
##              main      #192   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            9         9           
  Lines          469       471    +2     
  Branches        86        87    +1     
=========================================
+ Hits           469       471    +2     
Impacted Files Coverage Δ
gidgethub/abc.py 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@basnijholt
Copy link
Contributor Author

I believe the CI failure is unrelated to these changes.

@Mariatta
Copy link
Member

Unrelated but still needs to be fixed before merging this PR. Perhaps we just need to bump the sphinx dependency. It can be done as a separate PR.

@basnijholt
Copy link
Contributor Author

basnijholt commented Apr 27, 2023

I think I have fixed the Sphinx issue in 4cd6ead.

@Mariatta
Copy link
Member

Thank you! Can you also update the changelog

@Mariatta
Copy link
Member

and documentation to document the new extra_headers parameter

@Mariatta
Copy link
Member

Mariatta commented May 4, 2023

Can you update the branch and resolve the conflict?

@basnijholt
Copy link
Contributor Author

@Mariatta, I have

  • fixed the conflicts
  • added documentation
  • updated the changelog

Thanks for reviewing!

@basnijholt
Copy link
Contributor Author

basnijholt commented May 6, 2023

We’re now running into urllib3/urllib3#2168 in the docs build.

Copy link
Member

@Mariatta Mariatta left a comment

Choose a reason for hiding this comment

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

The readthedocs is still failing.

.readthedocs.yaml Outdated Show resolved Hide resolved
@basnijholt
Copy link
Contributor Author

The docs build successfully now 🎉

https://gidgethub--192.org.readthedocs.build/en/192/abc.html

Copy link
Member

@Mariatta Mariatta left a comment

Choose a reason for hiding this comment

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

Thanks!

Copy link
Collaborator

@brettcannon brettcannon left a comment

Choose a reason for hiding this comment

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

I personally would like to set {} as the default value since it isn't modified, but I also know using a mutable default value makes people uncomfortable, so I'm fine with None as a default.

@brettcannon brettcannon merged commit b9fe3c6 into gidgethub:main May 26, 2023
@brettcannon
Copy link
Collaborator

Thanks!

github-actions bot pushed a commit to aio-libs/aiohttp that referenced this pull request Aug 22, 2024
Bumps [gidgethub](https://github.com/brettcannon/gidgethub) from 5.0.1
to 5.3.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/brettcannon/gidgethub/releases">gidgethub's
releases</a>.</em></p>
<blockquote>
<h2>5.3.0</h2>
<ul>
<li>
<p>Add support passing <code>extra_headers</code> when making requests
[PR <a
href="https://redirect.github.com/brettcannon/gidgethub/issues/192">#192</a>](<a
href="https://redirect.github.com/brettcannon/gidgethub/pull/192">brettcannon/gidgethub#192</a>)</p>
</li>
<li>
<p>Add a getstatus() method for APIs that do not return content.
[PR <a
href="https://redirect.github.com/brettcannon/gidgethub/issues/194">#194</a>](<a
href="https://redirect.github.com/brettcannon/gidgethub/pull/194">brettcannon/gidgethub#194</a>)</p>
</li>
</ul>
<h2>5.2.1</h2>
<ul>
<li>
<p>Fix cgi and importlib_resources deprecations.
[PR <a
href="https://redirect.github.com/brettcannon/gidgethub/issues/185">#185</a>](<a
href="https://redirect.github.com/brettcannon/gidgethub/pull/185">brettcannon/gidgethub#185</a>)</p>
</li>
<li>
<p>Add support for Python 3.11 and drop EOL Python 3.6
[PR <a
href="https://redirect.github.com/brettcannon/gidgethub/issues/184">#184</a>](<a
href="https://redirect.github.com/brettcannon/gidgethub/pull/184">brettcannon/gidgethub#184</a>)</p>
</li>
</ul>
<h2>5.2.0</h2>
<ul>
<li>Make the minimum version of PyJWT be v2.4.0.</li>
</ul>
<h2>5.1.0</h2>
<ul>
<li>
<p>Use <code>X-Hub-Signature-256</code> header for webhook validation
when available.
([PR <a
href="https://redirect.github.com/brettcannon/gidgethub/issues/160">#160</a>](<a
href="https://redirect.github.com/brettcannon/gidgethub/pull/160">brettcannon/gidgethub#160</a>)).</p>
</li>
<li>
<p>The documentation is now built using Sphinx v&gt;= 4.0.0.
([Issue <a
href="https://redirect.github.com/brettcannon/gidgethub/issues/143">#143</a>](<a
href="https://redirect.github.com/brettcannon/gidgethub/issues/143">brettcannon/gidgethub#143</a>))</p>
</li>
<li>
<p><code>gidgethub.abc.GitHubAPI.getiter</code> now accepts
<code>iterable_key</code> parameter
in order to support the Checks API.
([Issue <a
href="https://redirect.github.com/brettcannon/gidgethub/issues/164">#164</a>](<a
href="https://redirect.github.com/brettcannon/gidgethub/issues/164">brettcannon/gidgethub#164</a>))</p>
</li>
<li>
<p>Accept HTTP 202 ACCEPTED as successful.
([PR <a
href="https://redirect.github.com/brettcannon/gidgethub/issues/174">#174</a>](<a
href="https://redirect.github.com/brettcannon/gidgethub/pull/174">brettcannon/gidgethub#174</a>))</p>
</li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/gidgethub/gidgethub/blob/main/docs/changelog.rst">gidgethub's
changelog</a>.</em></p>
<blockquote>
<h2>5.3.0</h2>
<ul>
<li>
<p>Add support passing <code>extra_headers</code> when making requests
(<code>PR [#192](gidgethub/gidgethub#192)
&lt;https://github.com/brettcannon/gidgethub/pull/192&gt;</code>_)</p>
</li>
<li>
<p>Add a getstatus() method for APIs that do not return content.
(<code>PR [#194](gidgethub/gidgethub#194)
&lt;https://github.com/brettcannon/gidgethub/pull/194&gt;</code>_)</p>
</li>
</ul>
<h2>5.2.1</h2>
<ul>
<li>
<p>Fix cgi and importlib_resources deprecations.
(<code>PR [#185](gidgethub/gidgethub#185)
&lt;https://github.com/brettcannon/gidgethub/pull/185&gt;</code>_)</p>
</li>
<li>
<p>Add support for Python 3.11 and drop EOL Python 3.6
(<code>PR [#184](gidgethub/gidgethub#184)
&lt;https://github.com/brettcannon/gidgethub/pull/184&gt;</code>_)</p>
</li>
</ul>
<h2>5.2.0</h2>
<ul>
<li>Make the minimum version of PyJWT be v2.4.0.</li>
</ul>
<h2>5.1.0</h2>
<ul>
<li>
<p>Use <code>X-Hub-Signature-256</code> header for webhook validation
when available.
(<code>PR [#160](gidgethub/gidgethub#160)
&lt;https://github.com/brettcannon/gidgethub/pull/160&gt;</code>_).</p>
</li>
<li>
<p>The documentation is now built using Sphinx v&gt;= 4.0.0.
(<code>Issue [#143](gidgethub/gidgethub#143)
&lt;https://github.com/brettcannon/gidgethub/issues/143&gt;</code>_)</p>
</li>
<li>
<p>:meth:<code>gidgethub.abc.GitHubAPI.getiter</code> now accepts
<code>iterable_key</code> parameter
in order to support the Checks API.
(<code>Issue [#164](gidgethub/gidgethub#164)
&lt;https://github.com/brettcannon/gidgethub/issues/164&gt;</code>_)</p>
</li>
<li>
<p>Accept HTTP 202 ACCEPTED as successful.
(<code>PR [#174](gidgethub/gidgethub#174)
&lt;https://github.com/brettcannon/gidgethub/pull/174&gt;</code>_)</p>
</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/gidgethub/gidgethub/commit/dbcdf4bd32de86288495dbbd8c1682399ba53ad1"><code>dbcdf4b</code></a>
Fix the rst markup on the Changelog. (<a
href="https://redirect.github.com/brettcannon/gidgethub/issues/197">#197</a>)</li>
<li><a
href="https://github.com/gidgethub/gidgethub/commit/b9fe3c69030e0960d4ba2dcc1efb921e240c7504"><code>b9fe3c6</code></a>
Add <code>extra_headers</code> option to <code>get</code> methods (<a
href="https://redirect.github.com/brettcannon/gidgethub/issues/192">#192</a>)</li>
<li><a
href="https://github.com/gidgethub/gidgethub/commit/901f0578c00919cdb8c0b120b6d9d9f35eda620e"><code>901f057</code></a>
Add a getstatus() method to gidgethub.abc (<a
href="https://redirect.github.com/brettcannon/gidgethub/issues/194">#194</a>)</li>
<li><a
href="https://github.com/gidgethub/gidgethub/commit/20e861254150b16bfd2fbe26b012cb6736430faf"><code>20e8612</code></a>
Update the intersphinx mapping to 1.0-style (<a
href="https://redirect.github.com/brettcannon/gidgethub/issues/195">#195</a>)</li>
<li><a
href="https://github.com/gidgethub/gidgethub/commit/e1f7baed601914139fc5179fcb8faea210bbf543"><code>e1f7bae</code></a>
Fix lint issues (<a
href="https://redirect.github.com/brettcannon/gidgethub/issues/191">#191</a>)</li>
<li><a
href="https://github.com/gidgethub/gidgethub/commit/b3ae8d16426355f660a2fc2aadeb4d8e61478add"><code>b3ae8d1</code></a>
Replace use of <code>requests</code> in examples with <code>httpx</code>
(<a
href="https://redirect.github.com/brettcannon/gidgethub/issues/190">#190</a>)</li>
<li><a
href="https://github.com/gidgethub/gidgethub/commit/4fe3c04d7c550a5b33fbf00e154810042f7d3edb"><code>4fe3c04</code></a>
Release 5.2.1 (<a
href="https://redirect.github.com/brettcannon/gidgethub/issues/186">#186</a>)</li>
<li><a
href="https://github.com/gidgethub/gidgethub/commit/89ade8859539212e0663e91f0777ad8a39ecf323"><code>89ade88</code></a>
Fix cgi and importlib_resources deprecations (<a
href="https://redirect.github.com/brettcannon/gidgethub/issues/185">#185</a>)</li>
<li><a
href="https://github.com/gidgethub/gidgethub/commit/64888cbe83e3f11af3c6f25294adff26dc2f557a"><code>64888cb</code></a>
Add support for Python 3.11 and drop EOL Python 3.6 (<a
href="https://redirect.github.com/brettcannon/gidgethub/issues/184">#184</a>)</li>
<li><a
href="https://github.com/gidgethub/gidgethub/commit/8c60e56029b7e10b7be9879e64dfbf97bbeda2b8"><code>8c60e56</code></a>
Add variable mapping to fix 'Session tests-3.10-dev skipped: Python
interpret...</li>
<li>Additional commits viewable in <a
href="https://github.com/brettcannon/gidgethub/compare/5.0.1...v5.3.0">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=gidgethub&package-manager=pip&previous-version=5.0.1&new-version=5.3.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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.

Add extra_headers option to HTTP methods in GitHubAPI
4 participants