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

fix #3114 - Fix excessive labels assignment #3606

Merged
merged 4 commits into from
Jul 21, 2021
Merged

Conversation

karlcow
Copy link
Member

@karlcow karlcow commented Jul 21, 2021

This PR fixes issue #3114

Proposed PR background

This switches the strategy for assigning labels.
We will control a bit more what is done.

@karlcow
Copy link
Member Author

karlcow commented Jul 21, 2021

Do not merge. Just pushing for the PR to run the tests.

@karlcow karlcow requested a review from ksy36 July 21, 2021 03:22
@karlcow karlcow linked an issue Jul 21, 2021 that may be closed by this pull request
@ksy36 ksy36 merged commit e5dbd1c into webcompat:main Jul 21, 2021
@ksy36
Copy link
Contributor

ksy36 commented Jul 21, 2021

Thanks, looks good!

@ksy36
Copy link
Contributor

ksy36 commented Jul 21, 2021

There is an error when editing labels/milestone for users with write access (however the change is applied):

  File "/Users/ksenia/Documents/projects/webcompat.com/webcompat/api/endpoints.py", line 69, in edit_issue
    print(edit.status_code, 'test')
AttributeError: 'tuple' object has no attribute 'status_code'

I'll create a PR with a fix

@karlcow
Copy link
Member Author

karlcow commented Jul 22, 2021

ok. I think I understand the issue.
So we replaced proxy_request by api_request, but this too doesn't return a regular object (bad design, we need to fix this, but probably in a separate bug).

@mockable_response
def api_request(method, path, params=None, data=None, mime_type=JSON_MIME):
"""Handle communication with the GitHub API.
This method handles both logged-in and proxied requests.
This returns a tuple for the convenience of being able to do:
`return api_request('get', path, params=params)` directly from a view
function. Flask will turn a tuple of the format
(content, status_code, response_headers) into a Response object.
"""
request_headers = get_request_headers(g.request_headers, mime_type)
if g.user:
request_method = github.raw_request
else:
request_method = proxy_request
resource = request_method(method, path, headers=request_headers,
params=params, data=data)
if resource.status_code != 404:
return (resource.content, resource.status_code,
get_response_headers(resource))
else:
abort(404)

@mockable_response
def proxy_request(method, path, params=None, headers=None, data=None):
"""Make a GitHub API request with a bot's OAuth token.
Necessary for non-logged in users.
* `path` will be appended to the end of the API_URI.
* Optionally pass in POST data via the `data` arg.
* Optionally point to a different URI via the `uri` arg.
* Optionally pass in HTTP headers to forward.
"""
# Merge passed in headers with AUTH_HEADERS, and add the etag of the
# request, if it exists, to be sent back to GitHub.
auth_headers = AUTH_HEADERS.copy()
if headers:
auth_headers.update(headers)
# Grab the correct Requests request method
req = getattr(requests, method)
# It's expected that path *won't* start with a leading /
# https://api.github.com/repos/{0}
resource_uri = API_URI + path
return req(resource_uri, data=data, params=params, headers=auth_headers)

so when we reach, the object is not working

edit = api_request('patch', path, data=request.data)
return (edit.content, edit.status_code,
{'content-type': JSON_MIME_HTML})

The request has been correctly sent but the answers is not in the format we expect.

This is the shape of the content we receive once going through api_request, a tuple with 3 values.

Capture d’écran 2021-07-22 à 09 17 14

While the edit.content, edit.status_code is trying to access properties of an object, this can be fixed with a quick hack testing the nature, the type of edit, but probably we need to make it more regular and that would require another bug.

@karlcow
Copy link
Member Author

karlcow commented Jul 22, 2021

I created a new issue for fixing this issue in #3607

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.

Investigate and fix excessive label assigning
2 participants