Skip to content

Allow updating hooks without resending configuration - #3630

Merged
EnricoMi merged 10 commits into
PyGithub:mainfrom
wozhenbang2004:fix/optional-hook-edit-2906
Dec 4, 2026
Merged

EnricoMi merged 10 commits into
PyGithub:mainfrom
wozhenbang2004:fix/optional-hook-edit-2906

Conversation

@wozhenbang2004

@wozhenbang2004 wozhenbang2004 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Hook.edit(active=False) currently raises TypeError unless callers supply name and config. Make both optional with NotSet, so changing webhook status does not require resending its configuration. Existing positional calls still work. name is deprecated for repository webhooks and is still included in requests for compatibility. Organization webhooks continue to accept name.

Add replay coverage for repository and organization hooks and keep None invalid. The previous revision passed 266 Hook, Repository and Organization tests, as well as mypy and pre-commit. A loopback HTTP check confirms that active-only updates send only {"active": false} and that legacy repository calls retain their payload and emit the warning. The new regression verifies that organization updates send an explicit name without a deprecation warning. The replay responses are synthetic. Live webhook secrets were not tested.

Fixes #2906.

@EnricoMi EnricoMi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for fixing this! Looks like the hook name argument has been removed. The name argument should be deprecated. There might be old Github Enterprise versions out there still supporting it.

Comment thread github/Hook.py Outdated
@@ -169,10 +169,10 @@
"""
:calls: `PATCH /repos/{owner}/{repo}/hooks/{hook_id} <https://docs.github.com/en/rest/reference/repos#webhooks>`_

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
:calls: `PATCH /repos/{owner}/{repo}/hooks/{hook_id} <https://docs.github.com/en/rest/reference/repos#webhooks>`_
:calls: `PATCH /repos/{owner}/{repo}/hooks/{hook_id} <https://docs.github.com/en/rest/repos/webhooks#update-a-repository-webhook>`_

Comment thread github/Hook.py
assert is_optional_list(add_events, str), add_events
assert is_optional_list(remove_events, str), remove_events
assert is_optional(active, bool), active
post_parameters = NotSet.remove_unset_items(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Deprecate name

Suggested change
if is_defined(name):
warnings.warn(
"Arguments name is deprecated, the name of a hook cannot be changed",
category=DeprecationWarning,
)
post_parameters = NotSet.remove_unset_items(

You may need to catch the deprecation warning in tests for them not to fail:

        with self.assertWarns(DeprecationWarning) as warning:
            hook.edit("name")
        self.assertWarning(
            warning,
            "Arguments name is deprecated, the name of a hook cannot be changed",
        )

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is the name argument ignored (name does not change) or do we get an error when attempting to change / provide the name? Maybe we should use this warning instead

"Arguments name is deprecated, the name of a hook cannot be changed and is ignored"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Kept name in the request for older Enterprise versions and added DeprecationWarning. The current update documentation no longer lists it, but I haven't verified whether a live server ignores or rejects it. I used Argument name is deprecated without claiming either behavior. The tests check the warning and preserve the legacy payload.

Also updated the endpoint link and removed request capture from the two new tests; their replay files contain the expected requests.

Comment thread tests/Hook.py Outdated
Comment on lines +115 to +118
self.assertEqual(len(requests), 1)
self.assertEqual(requests[0].verb, "PATCH")
self.assertEqual(requests[0].url, "/orgs/example/hooks/42")
self.assertEqual(json.loads(requests[0].input), {"active": False})

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

No need to capture the requests, we usually inspect the replay data file. That should be sufficient here. Same for testEditActiveOnly.

@EnricoMi EnricoMi added this to the Version 2.11.0 milestone Nov 20, 2026
@codecov

codecov Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.11%. Comparing base (7de2644) to head (bb1fda4).
⚠️ Report is 104 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3630      +/-   ##
==========================================
+ Coverage   97.00%   97.11%   +0.11%     
==========================================
  Files         172      182      +10     
  Lines       18934    20628    +1694     
==========================================
+ Hits        18366    20032    +1666     
- Misses        568      596      +28     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Test Results

    10 files  ±  0      10 suites  ±0   9m 22s ⏱️ + 1m 0s
 1 280 tests + 23   1 280 ✅ + 23  0 💤 ±0  0 ❌ ±0 
17 669 runs  +195  17 668 ✅ +195  1 💤 ±0  0 ❌ ±0 

Results for commit bb1fda4. ± Comparison against base commit afdd9d8.

This pull request removes 1 and adds 24 tests. Note that renamed tests count towards both.
tests.Hook.Hook ‑ testEditWithMinimalParameters
openapi.Cli.Cli ‑ test_0090-create-class-secret-scan-alert-instance
openapi.Cli.Cli ‑ test_0091-create-class-secret-scan-alert
openapi.Cli.Cli ‑ test_0100-create-method-repository-get-stargazers
openapi.Cli.Cli ‑ test_0110-create-class-interaction-limit
openapi.Cli.Cli ‑ test_0111-create-method-repository-get-interaction-limits
openapi.Cli.Cli ‑ test_0120-create-class-issue-field-value
tests.ActionsRepositoryPermissions.ActionsRepositoryPermissions ‑ testAttributes
tests.ActionsRepositoryPermissions.ActionsRepositoryPermissions ‑ testEdit
tests.Enterprise.Enterprise ‑ testDownloadReleaseAssetFile
tests.Enterprise.Enterprise ‑ testDownloadReleaseAssetRejectsOtherLocations
…

♻️ This comment has been updated with latest results.

@cvas22

cvas22 commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Small thing, the org webhook update docs still list name as a body param, so the new deprecation warning also fires for org hooks where it's valid. Maybe only warn for repo hooks, or say in the message it only applies there?

@wozhenbang2004

Copy link
Copy Markdown
Contributor Author

@cvas22 Thanks for catching this. The deprecation warning now only applies to repository webhooks. Organization hooks still send name without a warning. The regression test in 72b313b checks the PATCH payload as well.

@cvas22

cvas22 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Checked it, org hooks don't warn anymore and repo hooks still do. @EnricoMi looks good to me, thx.

@EnricoMi
EnricoMi force-pushed the fix/optional-hook-edit-2906 branch from 1c5c9be to cc65df2 Compare December 3, 2026 16:52
@EnricoMi

EnricoMi commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

I have restructured tests and recorded test data. Also rephrased the is-repo-hook check.

@EnricoMi EnricoMi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM! Thanks!

@EnricoMi
EnricoMi enabled auto-merge December 4, 2026 14:22
@EnricoMi
EnricoMi added this pull request to the merge queue Dec 4, 2026
Merged via the queue into PyGithub:main with commit de8f541 Dec 4, 2026
26 of 27 checks passed
EnricoMi added a commit that referenced this pull request Dec 4, 2026
Replay data recently added to main does not match the requests the
code sends, which request header and body matching now detect:

- Issue134.testGetOAuthScopes{FetchedOnAccess,UnknownWithoutScopeHeader}
  mask the token as '***' instead of 'token private_token_removed'.
- Hook.testCreate records an Accept header that create_hook does not
  send.
- Hook.testEditWithMinimalParametersRepositoryHook records the name
  argument, which edit(config=...) no longer sends since name became
  optional (#3630).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lettuce-bot Bot added a commit to lettuce-financial/github-bot-signed-commit that referenced this pull request Dec 6, 2026
This PR contains the following updates:

| Package | Change |
[Age](https://docs.renovatebot.com/merge-confidence/) |
[Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [PyGithub](https://redirect.github.com/pygithub/pygithub) | `==2.10.0`
→ `==2.11.0` |
![age](https://developer.mend.io/api/mc/badges/age/pypi/pygithub/2.11.0?slim=true)
|
![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/pygithub/2.10.0/2.11.0?slim=true)
|

---

### Release Notes

<details>
<summary>pygithub/pygithub (PyGithub)</summary>

###
[`v2.11.0`](https://redirect.github.com/PyGithub/PyGithub/releases/tag/v2.11.0)

[Compare
Source](https://redirect.github.com/pygithub/pygithub/compare/v2.10.0...v2.11.0)

#### What's Changed

##### New Features

- Add deployment branch policies to `Environment` by
[@&#8203;cvas22](https://redirect.github.com/cvas22) in
[PyGithub/PyGithub#3612](https://redirect.github.com/PyGithub/PyGithub/pull/3612)
- Add support for branch rulesets by
[@&#8203;EnricoMi](https://redirect.github.com/EnricoMi) in
[PyGithub/PyGithub#3617](https://redirect.github.com/PyGithub/PyGithub/pull/3617)
- Allow iterating `PaginatedList` by pages by
[@&#8203;EnricoMi](https://redirect.github.com/EnricoMi) in
[PyGithub/PyGithub#3603](https://redirect.github.com/PyGithub/PyGithub/pull/3603)
- Add `Organization.get_failed_invitations` by
[@&#8203;cvas22](https://redirect.github.com/cvas22) in
[PyGithub/PyGithub#3608](https://redirect.github.com/PyGithub/PyGithub/pull/3608)
- Add `Issue.transfer` to move an issue to another repository by
[@&#8203;cvas22](https://redirect.github.com/cvas22) in
[PyGithub/PyGithub#3631](https://redirect.github.com/PyGithub/PyGithub/pull/3631)
- Add `Repository.get_actions_permissions` and
`ActionsRepositoryPermissions.edit` by
[@&#8203;andrewfish0](https://redirect.github.com/andrewfish0) in
[PyGithub/PyGithub#3583](https://redirect.github.com/PyGithub/PyGithub/pull/3583)

##### Improvements

- Apply schema to `SecretScanAlert` by
[@&#8203;EnricoMi](https://redirect.github.com/EnricoMi) in
[PyGithub/PyGithub#3573](https://redirect.github.com/PyGithub/PyGithub/pull/3573)
- Respect application logging configuration by default by
[@&#8203;vzer200](https://redirect.github.com/vzer200) in
[PyGithub/PyGithub#3572](https://redirect.github.com/PyGithub/PyGithub/pull/3572)
- Update classes using OpenAPI spec by
[@&#8203;EnricoMi](https://redirect.github.com/EnricoMi) in
[PyGithub/PyGithub#3606](https://redirect.github.com/PyGithub/PyGithub/pull/3606)
- Rework rate limit support by
[@&#8203;EnricoMi](https://redirect.github.com/EnricoMi) in
[PyGithub/PyGithub#3602](https://redirect.github.com/PyGithub/PyGithub/pull/3602)
- Add rate limit information to `PaginatedList` pages by
[@&#8203;EnricoMi](https://redirect.github.com/EnricoMi) in
[PyGithub/PyGithub#3605](https://redirect.github.com/PyGithub/PyGithub/pull/3605)
- Derive `Commit.repository` from the commit url by
[@&#8203;b84330808](https://redirect.github.com/b84330808) in
[PyGithub/PyGithub#3599](https://redirect.github.com/PyGithub/PyGithub/pull/3599)
- Updating pyproject.toml by
[@&#8203;EnricoMi](https://redirect.github.com/EnricoMi) in
[PyGithub/PyGithub#3623](https://redirect.github.com/PyGithub/PyGithub/pull/3623)
- Fix `creator` type hint in `Repository.get_issues`
([#&#8203;3084](https://redirect.github.com/pygithub/pygithub/issues/3084))
by [@&#8203;zxc1031408077](https://redirect.github.com/zxc1031408077) in
[PyGithub/PyGithub#3598](https://redirect.github.com/PyGithub/PyGithub/pull/3598)
- Fetch `Github.oauth_scopes` on access when the scopes are not known
yet by
[@&#8203;StrikeRougeAgent](https://redirect.github.com/StrikeRougeAgent)
in
[PyGithub/PyGithub#3633](https://redirect.github.com/PyGithub/PyGithub/pull/3633)
- Reject a zero step slice in `PaginatedList` by
[@&#8203;yuefdev](https://redirect.github.com/yuefdev) in
[PyGithub/PyGithub#3597](https://redirect.github.com/PyGithub/PyGithub/pull/3597)

##### Bug Fixes

- Remove commit ref support from `Workflow.create_dispatch` by
[@&#8203;laysauchoa](https://redirect.github.com/laysauchoa) in
[PyGithub/PyGithub#2931](https://redirect.github.com/PyGithub/PyGithub/pull/2931)
- Fix listing installation repositories with user authentication by
[@&#8203;hansu650](https://redirect.github.com/hansu650) in
[PyGithub/PyGithub#3571](https://redirect.github.com/PyGithub/PyGithub/pull/3571)
- Fix `openapi.py` and `sort_class.py` for `_useAttributes` with custom
if statements by
[@&#8203;EnricoMi](https://redirect.github.com/EnricoMi) in
[PyGithub/PyGithub#3619](https://redirect.github.com/PyGithub/PyGithub/pull/3619)
- Keep query string when following 301 redirects by
[@&#8203;Enesuygurs](https://redirect.github.com/Enesuygurs) in
[PyGithub/PyGithub#3600](https://redirect.github.com/PyGithub/PyGithub/pull/3600)
- Allow Enterprise release asset download redirects to
`/storage/releases/` by
[@&#8203;wozhenbang2004](https://redirect.github.com/wozhenbang2004) in
[PyGithub/PyGithub#3629](https://redirect.github.com/PyGithub/PyGithub/pull/3629)
- Allow updating hooks without resending configuration by
[@&#8203;wozhenbang2004](https://redirect.github.com/wozhenbang2004) in
[PyGithub/PyGithub#3630](https://redirect.github.com/PyGithub/PyGithub/pull/3630)
- Fix `PaginatedList.total_count` for custom `toal_count_item` by
[@&#8203;EnricoMi](https://redirect.github.com/EnricoMi) in
[PyGithub/PyGithub#3648](https://redirect.github.com/PyGithub/PyGithub/pull/3648)

##### Maintenance

- Generate a GraphQL API reference from method annotations by
[@&#8203;lzyrtxtp](https://redirect.github.com/lzyrtxtp) in
[PyGithub/PyGithub#3585](https://redirect.github.com/PyGithub/PyGithub/pull/3585)
- Replace `black`, `pyupgrade`, and `docformatter` with `ruff` by
[@&#8203;EnricoMi](https://redirect.github.com/EnricoMi) in
[PyGithub/PyGithub#3592](https://redirect.github.com/PyGithub/PyGithub/pull/3592)
- Add ruff reformat commit to .git-blame-ignore-revs by
[@&#8203;EnricoMi](https://redirect.github.com/EnricoMi) in
[PyGithub/PyGithub#3593](https://redirect.github.com/PyGithub/PyGithub/pull/3593)
- Fix logging tests by
[@&#8203;EnricoMi](https://redirect.github.com/EnricoMi) in
[PyGithub/PyGithub#3594](https://redirect.github.com/PyGithub/PyGithub/pull/3594)
- Replace responses with vcrpy by
[@&#8203;EnricoMi](https://redirect.github.com/EnricoMi) in
[PyGithub/PyGithub#3563](https://redirect.github.com/PyGithub/PyGithub/pull/3563)
- Restrict workflow permissions by
[@&#8203;EnricoMi](https://redirect.github.com/EnricoMi) in
[PyGithub/PyGithub#3611](https://redirect.github.com/PyGithub/PyGithub/pull/3611)
- Fix syntax error in code scanning alert example by
[@&#8203;puhupwasbind301](https://redirect.github.com/puhupwasbind301)
in
[PyGithub/PyGithub#3607](https://redirect.github.com/PyGithub/PyGithub/pull/3607)
- Clarify that Repository.get_commit accepts any ref by
[@&#8203;cvas22](https://redirect.github.com/cvas22) in
[PyGithub/PyGithub#3609](https://redirect.github.com/PyGithub/PyGithub/pull/3609)
- Document refreshing cached objects with update by
[@&#8203;yuefdev](https://redirect.github.com/yuefdev) in
[PyGithub/PyGithub#3596](https://redirect.github.com/PyGithub/PyGithub/pull/3596)
- Pin tox below 4.67.14 in CI by
[@&#8203;EnricoMi](https://redirect.github.com/EnricoMi) in
[PyGithub/PyGithub#3620](https://redirect.github.com/PyGithub/PyGithub/pull/3620)
- Test built whl package in CI by
[@&#8203;EnricoMi](https://redirect.github.com/EnricoMi) in
[PyGithub/PyGithub#3624](https://redirect.github.com/PyGithub/PyGithub/pull/3624)
- Document GitHub App client IDs for AppAuth by
[@&#8203;akoroderdeniteenfeld-sudo](https://redirect.github.com/akoroderdeniteenfeld-sudo)
in
[PyGithub/PyGithub#3637](https://redirect.github.com/PyGithub/PyGithub/pull/3637)
- Show how to read an annotated tag message by
[@&#8203;akoroderdeniteenfeld-sudo](https://redirect.github.com/akoroderdeniteenfeld-sudo)
in
[PyGithub/PyGithub#3643](https://redirect.github.com/PyGithub/PyGithub/pull/3643)
- Clarify which object cancels an organization invitation by
[@&#8203;akoroderdeniteenfeld-sudo](https://redirect.github.com/akoroderdeniteenfeld-sudo)
in
[PyGithub/PyGithub#3645](https://redirect.github.com/PyGithub/PyGithub/pull/3645)
- Obfuscate OpenAPI test diff line context by
[@&#8203;EnricoMi](https://redirect.github.com/EnricoMi) in
[PyGithub/PyGithub#3647](https://redirect.github.com/PyGithub/PyGithub/pull/3647)
- Add OpenAPI script tests around anyof by
[@&#8203;EnricoMi](https://redirect.github.com/EnricoMi) in
[PyGithub/PyGithub#3613](https://redirect.github.com/PyGithub/PyGithub/pull/3613)
- Fixing rst and md formatting issues by
[@&#8203;EnricoMi](https://redirect.github.com/EnricoMi) in
[PyGithub/PyGithub#3622](https://redirect.github.com/PyGithub/PyGithub/pull/3622)
- Fix VCR replay matching by
[@&#8203;EnricoMi](https://redirect.github.com/EnricoMi) in
[PyGithub/PyGithub#3646](https://redirect.github.com/PyGithub/PyGithub/pull/3646)
- Add `noRecord()` to reuse replay data when recording by
[@&#8203;cvas22](https://redirect.github.com/cvas22) in
[PyGithub/PyGithub#3618](https://redirect.github.com/PyGithub/PyGithub/pull/3618)

**Full Changelog**:
<PyGithub/PyGithub@v2.10.0...v2.11.0>

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/).
View the [repository job
log](https://developer.mend.io/github/lettuce-financial/github-bot-signed-commit).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NS4xMi4wIiwidXBkYXRlZEluVmVyIjoiNDUuMTIuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How to omit webhook secret update (config) when change webhook status active/inactive

3 participants