-
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
added documentation, SiteIntegrationAPI #568
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e04eeb9
added documentation, SiteIntegrationAPI
kevinmram 59c4d02
added docstring, rejectIDOLChanges
kevinmram e463082
Merge branch 'main' into si-api-documentation
keverie 1b5e06b
added/edited suggested changes, prettier.
keverie 6b2a126
yarn install, prettier
keverie 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,12 @@ import { PermissionError, BadRequestError } from '../utils/errors'; | |
|
||
require('dotenv').config(); | ||
|
||
/** | ||
* Triggers a dispatch event to pull changes from the IDOL backend. | ||
* @param {IdolMember} user - The user requesting the pull dispatch. | ||
* @returns {Promise<{updated: boolean}>} - A promise that resolves to an object indicating if the update was successful. | ||
* @throws {PermissionError} - If the user lacks permission to trigger the dispatch. | ||
*/ | ||
export const requestIDOLPullDispatch = async (user: IdolMember): Promise<{ updated: boolean }> => { | ||
await checkPermissions(user); | ||
const octokit = new Octokit({ | ||
|
@@ -19,12 +25,24 @@ export const requestIDOLPullDispatch = async (user: IdolMember): Promise<{ updat | |
return { updated: result.status === 204 }; | ||
}; | ||
|
||
/** | ||
* Retrieves the latest Pull Request with changes from the IDOL backend. | ||
* @param {IdolMember} user - The user requesting the pull request details. | ||
* @returns {Promise<{pr: PRResponse}>} - A promise that resolves to an object containing the pull request details. | ||
* @throws {PermissionError} - If the user lacks permission to access the pull request. | ||
*/ | ||
export const getIDOLChangesPR = async (user: IdolMember): Promise<{ pr: PRResponse }> => { | ||
await checkPermissions(user); | ||
const foundPR = await findBotPR(); | ||
return { pr: foundPR }; | ||
}; | ||
|
||
/** | ||
* Accepts and merges the IDOL backend changes pull request. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should mention what happens when the PR is merged (i.e. triggering a deploy). |
||
* @param {IdolMember} user - The user attempting to accept the changes. | ||
* @returns {Promise<{pr: PRResponse; merged: boolean}>} - A promise that resolves to an object containing the pull request details and a boolean indicating if the merge was successful. | ||
* @throws {PermissionError} - If the user lacks permission to merge the pull request. | ||
*/ | ||
export const acceptIDOLChanges = async ( | ||
user: IdolMember | ||
): Promise<{ pr: PRResponse; merged: boolean }> => { | ||
|
@@ -80,6 +98,11 @@ export const rejectIDOLChanges = async ( | |
return { pr: foundPR, closed: closedReview.data.state === 'closed' }; | ||
}; | ||
|
||
/** | ||
* Finds an open pull request created by a bot for updating IDOL backend data. | ||
* @returns {Promise<PRResponse>} - A promise that resolves to the found pull request details. | ||
* @throws {BadRequestError} - If no valid open pull request is found. | ||
*/ | ||
const findBotPR = async (): Promise<PRResponse> => { | ||
const octokit = new Octokit({ | ||
auth: `token ${process.env.BOT_TOKEN}`, | ||
|
@@ -100,6 +123,12 @@ const findBotPR = async (): Promise<PRResponse> => { | |
return foundPR; | ||
}; | ||
|
||
/** | ||
* Checks if the user has permission to deploy the site. | ||
* @param {IdolMember} user - The user whose permissions are being checked. | ||
* @returns {Promise<void>} - A promise that resolves to void. | ||
* @throws {PermissionError} - If the user does not have permission to deploy the site. | ||
*/ | ||
const checkPermissions = async (user: IdolMember): Promise<void> => { | ||
const canEdit = await PermissionsManager.canDeploySite(user); | ||
if (!canEdit) { | ||
|
Oops, something went wrong.
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.
I'd be a little more specific about what this does.
e.g. Triggers a dispatch event for the pull-from-idol GitHub action. This job (blah blah blah brief description of what the job does).