Skip to content

Commit

Permalink
fix(api): Implement and use Accept FULL for comments (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
machour authored and Houssein Djirdeh committed Oct 1, 2017
1 parent 101eb54 commit fede55a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
29 changes: 27 additions & 2 deletions src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const ACCEPT = {
HTML: 'application/vnd.github.v3.html+json',
DIFF: 'application/vnd.github.v3.diff+json',
RAW: 'application/vnd.github.v3.raw+json',
FULL: 'application/vnd.github.v3.full+json',
};

const METHOD = {
Expand Down Expand Up @@ -107,6 +108,14 @@ export const v3 = {

return response.text();
},
getFull: async (url, accessToken) => {
const response = await v3.call(
url,
v3.parameters(accessToken, METHOD.GET, ACCEPT.FULL)
);

return response.json();
},
getJson: async (url, accessToken) => {
const response = await v3.call(url, v3.parameters(accessToken));

Expand Down Expand Up @@ -136,6 +145,14 @@ export const v3 = {

return response;
},
patchFull: async (url, accessToken, body = {}) => {
const response = await v3.call(
url,
v3.parameters(accessToken, METHOD.PATCH, ACCEPT.FULL, body)
);

return response.json();
},
postJson: async (url, accessToken, body = {}) => {
const response = await v3.call(
url,
Expand All @@ -152,6 +169,14 @@ export const v3 = {

return response.text();
},
postFull: async (url, accessToken, body = {}) => {
const response = await v3.call(
url,
v3.parameters(accessToken, METHOD.POST, ACCEPT.FULL, body)
);

return response.json();
},
post: async (url, accessToken, body = {}) => {
const response = await v3.call(
url,
Expand Down Expand Up @@ -200,7 +225,7 @@ export const fetchPostIssueComment = (
issueNum,
accessToken
) =>
v3.postHtml(
v3.postFull(
`/repos/${owner}/${repoName}/issues/${issueNum}/comments`,
accessToken,
{ body }
Expand All @@ -224,7 +249,7 @@ export const fetchEditIssueComment = (
editParams: any,
accessToken: string
) =>
v3.patch(
v3.patchFull(
`/repos/${owner}/${repoName}/issues/comments/${issueCommentId}`,
accessToken,
editParams
Expand Down
8 changes: 4 additions & 4 deletions src/issue/issue.action.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const getIssueComments = issueCommentsURL => {
dispatch({ type: GET_ISSUE_COMMENTS.PENDING });

return v3
.getHtml(`${issueCommentsURL}?per_page=100`, accessToken)
.getFull(`${issueCommentsURL}?per_page=100`, accessToken)
.then(data => {
dispatch({
type: GET_ISSUE_COMMENTS.SUCCESS,
Expand All @@ -110,7 +110,7 @@ export const postIssueComment = (body, owner, repoName, issueNum) => {
.then(data => {
dispatch({
type: POST_ISSUE_COMMENT.SUCCESS,
payload: JSON.parse(data),
payload: data,
});
})
.catch(error => {
Expand Down Expand Up @@ -157,10 +157,10 @@ export const editIssueComment = (issueCommentId, owner, repoName, body) => {
{ body },
accessToken
)
.then(() => {
.then(data => {
dispatch({
type: EDIT_ISSUE_COMMENT.SUCCESS,
payload: { id: issueCommentId, body },
payload: data,
});
})
.catch(error => {
Expand Down
8 changes: 6 additions & 2 deletions src/issue/issue.reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const issueReducer = (state = initialState, action = {}) => {
case GET_ISSUE_COMMENTS.SUCCESS:
return {
...state,
comments: JSON.parse(action.payload),
comments: action.payload,
isPendingComments: false,
};
case GET_ISSUE_COMMENTS.ERROR:
Expand Down Expand Up @@ -97,7 +97,11 @@ export const issueReducer = (state = initialState, action = {}) => {
comments: state.comments.map(
comment =>
comment.id === action.payload.id
? { ...comment, body: action.payload.body }
? {
...comment,
body: action.payload.body,
body_html: action.payload.body_html,
}
: comment
),
isEditingComment: false,
Expand Down

0 comments on commit fede55a

Please sign in to comment.