-
Notifications
You must be signed in to change notification settings - Fork 2
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
Feat/update navigation file on creation of new collection and resource room #80
Merged
alexanderleegs
merged 10 commits into
staging
from
feat/update-navigation-file-on-creation-of-new-collection-and-resource-room
Nov 25, 2020
+121
−10
Merged
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8877256
Feat: create new Navigation class to load navigation file
alexanderleegs 5112f17
Feat: add to navigation on creation of new collection
alexanderleegs 16918ea
feat: add to navigation on creation of resource room
alexanderleegs 71273cb
Fix: remove redundant permalink field in config file
alexanderleegs e9c5760
Fix: use existing File to retrieve navigation instead
alexanderleegs 4a0b24c
Fix: use existing File to retrieve nav file for resourceroom
alexanderleegs a1c294d
Fix: remove unused class
alexanderleegs cc51568
Fix: update nav file when deleting and renaming collectionPages
alexanderleegs 2e79c88
Feat: handle nav changes on deleting and renaming resource room
alexanderleegs fb58d14
Fix: change for loop to filter/map instead
alexanderleegs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
const axios = require('axios'); | ||
const validateStatus = require('../utils/axios-utils') | ||
|
||
// Import logger | ||
const logger = require('../logger/logger'); | ||
|
||
// Import error | ||
const { NotFoundError } = require('../errors/NotFoundError') | ||
|
||
const GITHUB_ORG_NAME = process.env.GITHUB_ORG_NAME | ||
const BRANCH_REF = process.env.BRANCH_REF | ||
|
||
class Navigation { | ||
constructor(accessToken, siteName) { | ||
this.accessToken = accessToken | ||
this.siteName = siteName | ||
} | ||
|
||
async read() { | ||
try { | ||
const endpoint = `https://api.github.com/repos/${GITHUB_ORG_NAME}/${this.siteName}/contents/_data/navigation.yml` | ||
|
||
const params = { | ||
"ref": BRANCH_REF, | ||
} | ||
|
||
const resp = await axios.get(endpoint, { | ||
validateStatus, | ||
params, | ||
headers: { | ||
Authorization: `token ${this.accessToken}`, | ||
"Content-Type": "application/json" | ||
} | ||
}) | ||
|
||
if (resp.status === 404) throw new NotFoundError ('Navigation page does not exist') | ||
|
||
const { content, sha } = resp.data | ||
|
||
return { content, sha } | ||
|
||
} catch (err) { | ||
throw err | ||
} | ||
} | ||
|
||
async update(newContent, sha) { | ||
const endpoint = `https://api.github.com/repos/${GITHUB_ORG_NAME}/${this.siteName}/contents/_data/navigation.yml` | ||
|
||
const params = { | ||
"message": 'Edit navigation', | ||
"content": newContent, | ||
"branch": BRANCH_REF, | ||
"sha": sha | ||
} | ||
|
||
await axios.put(endpoint, params, { | ||
headers: { | ||
Authorization: `token ${this.accessToken}`, | ||
"Content-Type": "application/json" | ||
} | ||
}) | ||
} | ||
} | ||
|
||
module.exports = { Navigation } | ||
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Actually there's no need to create a
Navigation
class, to prevent duplication of code, we can create a newFile
and apply the existingDataType
type to retrieve thenavigation.yml
fileThere 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.
Makes sense, resolved in e9c5760, 4a0b24c, a1c294d