-
Notifications
You must be signed in to change notification settings - Fork 150
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
[MM-350] Fix issue in create issue modal and attach issue modal #761
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #761 +/- ##
==========================================
- Coverage 16.16% 16.15% -0.01%
==========================================
Files 17 17
Lines 6021 6022 +1
==========================================
Hits 973 973
- Misses 5003 5004 +1
Partials 45 45 ☔ View full report in Codecov by Sentry. |
@@ -806,6 +806,7 @@ func (p *Plugin) searchIssues(c *UserContext, w http.ResponseWriter, r *http.Req | |||
result, _, err := githubClient.Search.Issues(c.Ctx, query, &github.SearchOptions{}) | |||
if err != nil { | |||
c.Log.WithError(err).With(logger.LogContext{"query": query}).Warnf("Failed to search for issues") | |||
p.writeJSON(w, make([]*github.Issue, 0)) |
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.
There are a lot of other endpoints that don't return valid JSON in the error case. Should we update the webapp to not expect JSON if the status code indicates an error?
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.
@hanzei We were thinking of updating the plugin API response for each API where we are not returning anything in case we get any errors from the GitHub API.
For example: At this line, we can return an error something like p.writeAPIError(w, &APIErrorResponse{Message: "Failed to search for issues", StatusCode: http.StatusInternalServerError})
and handle the error similarly at the webapp side.
What are your thoughts on this?
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.
If githubClient.Search.Issues
finds nothing that matches the search, does it return an error
?
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.
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.
We def want to avoid showing this Unexpected end of JSON input
error in all cases
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.
I see the value in consistently returning a JSON payload for calls the webapp makes. Should this be addressed holistically as part of this PR?
I suggest we update the signature of API methods like searchIssue
from (c *UserContext, w http.ResponseWriter, r *http.Request)
to (c *UserContext, r *http.Request) (any, int)
and let a wrapper handle deal with writing the returned payload and status code. That way we ensure that all of these endpoint return valid JSON.
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.
@hanzei Should we create a new issue to update the structure of the APIs and merge this PR to resolve the issue mentioned in the description?
Also, there were two ways we were thinking of fixing the response of the API:
- Create a wrapper and update API methods from
(c *UserContext, w http.ResponseWriter, r *http.Request)
to(c *UserContext, r *http.Request) (any, int)
as stated by you. We can also include a field oferror
with the data and the status code. In the wrapper, we can check for errors and data. If the error is returned, we can returnp.writeAPIError(w, &APIErrorResponse{Message: "ErrorMessage", StatusCode: statusCode})
and handle similarly on webapp and if there is no error we can return data or an empty list if data is also empty. - In this way, we can directly update the API to simply return
p.writeAPIError(w, &APIErrorResponse{Message: "ErrorMessage", StatusCode: statusCode})
in case of error. We can avoid making a wrapper in this case.
What are your thoughts on this? Please let me know if I missed something here.
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.
Either one sounds good to me. Which one is less complicated in your opinion @ayusht2810? Have you tried implemented one of them to see if it fits well?
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.
@mickmister We are thinking to proceed with the second method.
we can do this it in this PR or we can create a new PR and merge this so that the issue is fixed
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.
@Kshitij-Katiyar Sure separate PR sounds good 👍
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.
LGTM, upon resolving @hanzei comment.
webapp/src/actions/index.js
Outdated
dispatch({ | ||
type: ActionTypes.RECEIVED_REPOSITORIES, | ||
data: [], | ||
}); |
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.
What should the UI show/do in this case?
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.
@mickmister Currently, we have the screenshot present here #761 (comment). I think instead of this, we should just show dropdown with no options present, which is currently done in this PR
Should we move forward with the approach mentioned in the #761 (comment) or should we just return an empty list from the backend to avoid the Unexpected end of JSON input
error?
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.
If there is an error from GitHub, we should show a useful error to the user. If we simply fetched no values with no error, then the backend should return an empty array and show no error
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.
@mickmister I have created a new issue on Github to return proper json arrays from APIs. Maybe we can proceed further with this PR and handle the error case as part of the new issue. Please let me know your thoughts on this.
@@ -806,6 +806,7 @@ func (p *Plugin) searchIssues(c *UserContext, w http.ResponseWriter, r *http.Req | |||
result, _, err := githubClient.Search.Issues(c.Ctx, query, &github.SearchOptions{}) | |||
if err != nil { | |||
c.Log.WithError(err).With(logger.LogContext{"query": query}).Warnf("Failed to search for issues") | |||
p.writeJSON(w, make([]*github.Issue, 0)) |
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.
I see the value in consistently returning a JSON payload for calls the webapp makes. Should this be addressed holistically as part of this PR?
I suggest we update the signature of API methods like searchIssue
from (c *UserContext, w http.ResponseWriter, r *http.Request)
to (c *UserContext, r *http.Request) (any, int)
and let a wrapper handle deal with writing the returned payload and status code. That way we ensure that all of these endpoint return valid JSON.
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.
LGTM 👍
There's a follow up ticket to address similar issues in other endpoints #794
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.
The above PR has been tested for the following scenarios:
- Tested the dropdown values for repository present in the Create GitHub Issue modal
- Tested the dropdown values for github issue present in the Attach to GitHub Issue modal
The PR was working fine for both the conditions, LGTM. Approved
@wiggin77 This is ready for merge 👍 |
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.
I'm fine with moving the discussion from #761 (comment) to a separate endpoint
Summary
Create GitHub Issue
modalunexpected json
when openingAttach to GitHub Issue
modal for the above-mentioned caseTicket Link
Fixes #557
Checklist
make test
Ran test cases and ensured they are passingmake check-style
Ran style check and ensured both webapp and server pass the checksWhat to test?
Create GitHub Issue
modalAttach to GitHub Issue
modalHow to test?
GitHub Organisation
in the system console settingsGitHub Organisation
again in the system console settings by adding some incorrect value