PyGithub / PyGithub/PyGithub

404 and other errors when calling `delete()` method on `Github.Secret.Secret` and `GitHub.Variable.Variable`

未關閉
#2,834 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

主要語言
Python
星號
7.8k
分支
1.9k
平均合併
17 分鐘
30 天內合併 PR
2

描述

Methods called on Secret and Variable model methods are not requesting the correct GitHub REST API endpoint URLs. Invoking these methods causes 404 errors.

  • For Variable, there is a bug that appends additional incorrect parts to the variable's REST API endpoint URL, resulting in 404 errors for delete (HTTP DELETE) and edit (HTTP PATCH).
    • Example:
      • Expected: /repos/{owner}/{repo}/actions/variables/{name}
      • Actual: /repos/{owner}/{repo}/actions/variables/{name}/actions/variables/{name}
  • For both Variable and Secret, fetching a PaginatedList of either from the Repository model's get_variables or get_secrets methods fails to correctly set the _url attribute on the paginated list of models. Therefore, calling such methods will also fail.

Below are some examples for how to reproduce the unexpected behavior. Please substitute "AndrewJDawes/PyGithub" with the owner/name of a repository to which you have access.

# Setup
repo = self.g.get_repo("AndrewJDawes/PyGithub")
variable = repo.create_variable("VARIABLE_NAME", "VARIABLE_VALUE")
repo = self.g.get_repo("AndrewJDawes/PyGithub")
variable = repo.get_variable("VARIABLE_NAME")


# Issue
variable.delete() # github.GithubException.UnknownObjectException: 404 {"message": "Not Found", "documentation_url": "https://docs.github.com/rest"}
repo = self.g.get_repo("AndrewJDawes/PyGithub")
repo.create_variable("VARIABLE_ONE_NAME", "VARIABLE_ONE_VALUE")
repo.create_variable("VARIABLE_TWO_NAME", "VARIABLE_TWO_VALUE")
repo = self.g.get_repo("AndrewJDawes/PyGithub")
variables = repo.get_variables()
for variable in variables:
    if variable.name in ["VARIABLE_ONE_NAME", "VARIABLE_TWO_NAME"] and variable.value in ["VARIABLE_ONE_VALUE", "VARIABLE_TWO_VALUE"]:
        variable.delete() # Fails to delete Variable
  repo = self.g.get_repo("AndrewJDawes/PyGithub")
  repo.create_secret("SECRET_ONE_NAME", "SECRET_ONE_VALUE")
  repo.create_secret("SECRET_TWO_NAME", "SECRET_TWO_VALUE")
  repo = self.g.get_repo("AndrewJDawes/PyGithub")
  secrets = repo.get_secrets()
  for secret in secrets:
      if secret.name in ["SECRET_ONE_NAME", "SECRET_TWO_NAME"]:
          secret.delete() # AttributeError: 'NoneType' object has no attribute 'startswith'

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從 Secret 和 Variable 模型方法以及 Repository.get_variables 和 get_secrets 進入點開始。重現列出的刪除和編輯失敗,然後將產生的 REST URL 以及分頁模型的 _url 值與預期端點進行比較。當這些操作對個別和分頁的 Secret 與 Variable 物件都有效時,即表示完成。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
github, python
領域
api
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
描述清楚
新手友好度
45/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。