sigmavirus24 / github3.py

Hi, I'm a library for interacting with GItHub's REST API in a convenient and ergonomic way. I work on Python 3.6+.
https://github3.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.21k stars 404 forks source link

Project card creation not working for GithubEnterprise #1094

Open k3boxers opened 2 years ago

k3boxers commented 2 years ago

When trying to create a card in a Github Enterprise repository the url that is built isn't for the Enterprise server, but for api.github.com.

Creating a project and columns worked fine, trying to read columns however had the same issue.

Since it is going to the github, where my project doesn't exist and I'm not authenticated I get the following error:

/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py:1013: InsecureRequestWarning: Unverified HTTPS request is being made to host 'api.github.com'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/site-packages/github3/structs.py", line 120, in next
    return self.__next__()
  File "/usr/local/lib/python3.9/site-packages/github3/structs.py", line 106, in __next__
    return next(self.__i__)
  File "/usr/local/lib/python3.9/site-packages/github3/structs.py", line 76, in __iter__
    json = self._get_json(response)
  File "/usr/local/lib/python3.9/site-packages/github3/structs.py", line 109, in _get_json
    return self._json(response, 200)
  File "/usr/local/lib/python3.9/site-packages/github3/models.py", line 156, in _json
    raise exceptions.error_for(response)
github3.exceptions.AuthenticationFailed: 401 Bad credentials

I believe it is because it is referencing self._github_url rather than self._api in projects.py, but I was unable to fix in the python debugger.

253     def create_card_with_content_id(self, content_id, content_type):
254         """Create a content card in this project column.
255 
256         :param int content_id:
257             (required), the ID of the content
258         :param str content_type:
259             (required), the type of the content
260         :returns:
261             the created card
262         :rtype:
263             :class:`~github3.projects.ProjectCard`
264         """
265         if not content_id or not content_type:
266             return None
267 
268         url = self._build_url(
269             'projects/columns',
270             str(self.id),
271             'cards',
272             base_url=self._github_url
273         )
274         json = None
275         data = {'content_id': content_id, 'content_type': content_type}
276         json = self._json(self._post(
277             url, data=data, headers=Project.CUSTOM_HEADERS), 201)
278         return self._instance_or_null(ProjectCard, json)
k3boxers commented 2 years ago

I verified the issue is with the ._github_url. If I change that to point to my enterprise server col._github_url = 'https://api.github.[MYHOST] it works. I would do a pull request, but I don't know what the best way to fix it is, since I don't think it is a direct replacement with col._api.