-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⭐ Adjust code as submodule of its front-end counterpart (#84)
* Major adjustment to make this code base fit with its front-end counterpart * However, no new features were added
- Loading branch information
1 parent
aa16ff7
commit 8948338
Showing
36 changed files
with
276 additions
and
356 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
export { makeApiCallToList, makeApiCallToCopy, makeApiCallToCreate } from './src/core'; | ||
|
||
export { | ||
makeApiCallToList, | ||
makeApiCallToCopy, | ||
makeApiCallToCreate, | ||
generateDefaultLabel, | ||
generateDefaultMilestone, | ||
} from './src/core/defaultEntries'; | ||
} from './src/core'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,14 @@ | ||
import { getLoginInfo } from '../../loginInfo'; | ||
|
||
export const buildAcceptHeaderForHttpRequest = () => 'application/vnd.github.v3+json'; | ||
|
||
export const buildAuthorizationHeaderForHttpRequest = () => { | ||
const { token } = getLoginInfo(); | ||
|
||
export const buildAuthorizationHeaderForHttpRequest = (loginInfo) => { | ||
const { token } = loginInfo; | ||
return `token ${token}`; | ||
}; | ||
|
||
export const buildHttpRequestHeader = () => { | ||
export const buildHttpRequestHeader = (loginInfo) => { | ||
const headers = { | ||
Accept: buildAcceptHeaderForHttpRequest(), | ||
Authorization: buildAuthorizationHeaderForHttpRequest(), | ||
Authorization: buildAuthorizationHeaderForHttpRequest(loginInfo), | ||
}; | ||
|
||
return headers; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,48 @@ | ||
import { getRepoOwnerAndRepoName } from '../../loginInfo'; | ||
|
||
export const getBaseApiUri = () => 'https://api.github.com'; | ||
|
||
export const getBaseApiUriSlashRepos = () => `${getBaseApiUri()}/repos`; | ||
|
||
export const getApiPaginationLimit = () => 100; | ||
|
||
export const appendPaginationToUri = (uri) => | ||
`${uri}?per_page=${getApiPaginationLimit()}&page=1`; | ||
|
||
export const buildUriToListLabels = (uri) => uri; | ||
|
||
export const buildUriToListMilestones = (uri) => `${uri}&state=all`; | ||
|
||
export const getUriBuilderOfListing = (entryType) => { | ||
const uriBuilders = { | ||
labels: (uri) => buildUriToListLabels(uri), | ||
milestones: (uri) => buildUriToListMilestones(uri), | ||
labels: (uri) => uri, | ||
milestones: (uri) => `${uri}&state=all`, | ||
}; | ||
|
||
return uriBuilders[entryType]; | ||
}; | ||
|
||
export const buildUriToList = (uri) => { | ||
export const buildUriToList = (uri, entryType) => { | ||
const appendPaginationToUri = (uri1) => { | ||
const apiPaginationLimit = 100; | ||
return `${uri1}?per_page=${apiPaginationLimit}&page=1`; | ||
}; | ||
const uriWithParams = appendPaginationToUri(uri); | ||
|
||
const regex = /\/(?<entryType>labels|milestones)$/; | ||
const { entryType } = uri.match(regex).groups; | ||
|
||
const buildUri = getUriBuilderOfListing(entryType); | ||
|
||
return buildUri(uriWithParams); | ||
}; | ||
|
||
export const buildUriToCreate = (uri) => uri; | ||
|
||
export const getUriBuilderOfAction = (action) => { | ||
const uriBuilderFunctions = { | ||
list: (uri) => buildUriToList(uri), | ||
copy: (uri) => buildUriToList(uri), | ||
list: (uri, entryType) => buildUriToList(uri, entryType), | ||
copy: (uri, entryType) => buildUriToList(uri, entryType), | ||
create: (uri) => buildUriToCreate(uri), | ||
}; | ||
|
||
return uriBuilderFunctions[action]; | ||
const buildFunc = uriBuilderFunctions[action]; | ||
return buildFunc; | ||
}; | ||
|
||
export const buildUriForHttpRequest = (entryType, action, entryIdentifier = null) => { | ||
const { repoOwner, repoName } = getRepoOwnerAndRepoName(action); | ||
export const getBaseApiUri = () => 'https://api.github.com'; | ||
|
||
export const getBaseApiUriSlashRepos = () => `${getBaseApiUri()}/repos`; | ||
|
||
export const buildUriForHttpRequest = (loginInfo, entryType, action) => { | ||
const { repoOwner, repoName } = getRepoOwnerAndRepoName(loginInfo, action); | ||
const uri = `${getBaseApiUriSlashRepos()}/${repoOwner}/${repoName}/${entryType}`; | ||
const buildUri = getUriBuilderOfAction(action); | ||
|
||
return buildUri(uri, entryIdentifier); | ||
return buildUri(uri, entryType); | ||
}; | ||
|
||
export const buildUriForHttpRequestGET = (entryType, action) => | ||
buildUriForHttpRequest(entryType, action); | ||
export const buildUriForHttpRequestGET = (loginInfo, entryType, action) => | ||
buildUriForHttpRequest(loginInfo, entryType, action); | ||
|
||
export const buildUriForHttpRequestPOST = (entryType) => | ||
buildUriForHttpRequest(entryType, 'create'); | ||
export const buildUriForHttpRequestPOST = (loginInfo, entryType) => | ||
buildUriForHttpRequest(loginInfo, entryType, 'create'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,13 @@ | ||
import { getApiResponseOfListing, getApiResponseOfCreating } from './apiCalls'; | ||
import { validateEntryTypeOrThrow } from './validations'; | ||
|
||
export const makeApiCallToList = async (entryType) => { | ||
validateEntryTypeOrThrow(entryType); | ||
|
||
return getApiResponseOfListing(entryType, 'list'); | ||
export const makeApiCallToList = async (loginInfo, entryType) => { | ||
return getApiResponseOfListing(loginInfo, entryType, 'list'); | ||
}; | ||
|
||
export const makeApiCallToCopy = async (entryType) => { | ||
validateEntryTypeOrThrow(entryType); | ||
|
||
return getApiResponseOfListing(entryType, 'copy'); | ||
export const makeApiCallToCopy = async (loginInfo, entryType) => { | ||
return getApiResponseOfListing(loginInfo, entryType, 'copy'); | ||
}; | ||
|
||
export const makeApiCallToCreate = async (entryType, body) => { | ||
validateEntryTypeOrThrow(entryType); | ||
|
||
return getApiResponseOfCreating(entryType, body); | ||
export const makeApiCallToCreate = async (loginInfo, entryType, body) => { | ||
return getApiResponseOfCreating(loginInfo, entryType, body); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.