-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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 ability to access github Release Asset API. #525
Conversation
github/Requester.py
Outdated
if "Content-Type" in headers: | ||
mime_type = headers["Content-Type"] | ||
else: | ||
import mimetypes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not import globally?
github/tests/GitRelease.py
Outdated
"application/zip") | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleanup unused blanklines to avoid introduce new PEP8 failures.
@nhomar I had 3 places where I'd imported locally (with no good reason). I moved all of them and removed the extra whitespace as well. |
@nhomar Is there anything else left on this PR? I'd like to use this functionality for a project I'm working on. Happy to help out if necessary/possible. Thanks for the great work @THEHighlander! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modified per review notes
Am I wrong or are the releases themselves also missing for this module? I try to search for an existing release using the tag id: And then I want to upload release assets to this release or create it if it does not exist yet. But the docs have no result for "release", so is there any doc about this yet? |
@nhomar is there anything else you'd like me to do here? |
@nhomar Can we get this PR accepted? |
@NicoHood Releases are present in some form but it's not documented or at least wasn't as of a couple of months ago. This PR includes additional functionality around the release API as it pertains to assets. This file has been around forever but I agree, it wasn't in the docs: https://github.com/PyGithub/PyGithub/blob/master/github/GitRelease.py |
Maybe this project can help for now: |
@THEHighlander I have problems uploading release assets. Listing works fine, uploading does not. This is my code (excerpt): # Note for github issue: yes, i am verifying the release exists.
self.release = self.githubrepo.get_release(self.config['tag'])
# Upload assets
for asset in self.newassets:
assetpath = os.path.join(self.config['output'], asset)
print(':: Uploading', assetpath)
self.release.upload_asset(assetpath, "Testlabel", "application/x-xz") The error:
|
@NicoHood I'll dig into it after work |
@THEHighlander thanks! Any progress so far? I have no idea what causes this issue. You can find the full sourcecode of my project here: |
@NicoHood So far, I'm unable to reproduce your defect. I made the mistake of first rebasing my local branch off of master and that did introduce a defect (the underlying request code kills off the correct host name for uploads). I'm going to stash these changes and try again with the code as it was during the PR. Edit: I just realized you're using python 3.6 and I'm running locally using 2.7. I'll try that, too. |
@THEHighlander Thanks for testing! I have merged your changes into master and created a new tag: Yes I am using python3 and that is possibly the reason why it crashes (UFT8 changes were made in python3) |
@NicoHood I've found and fixed the encoding issue in python3. there were two issues:
|
@THEHighlander thanks for taking the time. The test now fails:
|
@NicoHood Yeah... I'm working it. One down... |
@NicoHood Ready |
@THEHighlander Thanks for the help. Now I get a different error while using:
I am using a hardcoded label and mimetype. I also have a question about that. Do I need to specify those and to which values does those default to? From what I can see in the source the mime type is auto guessed and the label is left out, am I right with this? Checkout my tool to reproduce the error: |
@NicoHood You're correct on both label & mime type. Label is optional. If you provide one, it just appears as the text in the download link on the release page in github (e.g. <a href='filename.ext'>Label Here</a>, see screenshot above). If you don't provide it, the link just shows the raw file name. The mime type is also technically optional, but it's better to provide it. You noticed that I'm using mimetypes.guess_type(input_file) to try to determine it if it's not provided, then just falling back to application/octet-stream if that fails. I haven't seen the bad content length error in my tests. I'll get it figured out today. |
@THEHighlander Thanks! Its finally working now. Thanks so much for your help and effort! @nhomar Please merge this PR, its tested and really helpful. |
@jayfk Any chance to get a review from your side? |
+1 |
Please merge this if it is ready, it is a really useful stuff. |
def requestBlobAndCheck(self, verb, url, parameters=None, headers=None, input=None): | ||
o = urlparse.urlparse(url) | ||
self.__hostname = o.hostname | ||
return self.__check(*self.requestBlob(verb, url, parameters, headers, input)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldnt we change back the __hostname here? My subsequent api calls failed due to the host name assertion fails in requester..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See fix in #771
@jasonwhite @nhomar Thanks for merging. Can you please tag a new release, so its available on pypi and the linux distros? You might also want to check the comment by @steven-hh-ding , maybe also @THEHighlander can do. |
This functionality remains undocumented in the reference. |
API Documentation found here:
https://developer.github.com/v3/repos/releases/#list-assets-for-a-release
https://developer.github.com/v3/repos/releases/#upload-a-release-asset
https://developer.github.com/v3/repos/releases/#get-a-single-release-asset
https://developer.github.com/v3/repos/releases/#edit-a-release-asset
https://developer.github.com/v3/repos/releases/#delete-a-release-asset