new workshop()
The Workshop store module is responsible for managing GitHub repositories. At any one time there will be zero or more repositories loaded in the module state. Up to one of these will be designated as the main repository. The main repository is the repository that is being edited in the Workshop Builder Tool. Other repositories are loaded so that their files can be copied into the main repository.
This module also handles files, which are the markdown files in the relevant GitHub repository and the _config.yml configuration file for the repository.
This module is the primary GitHub interface: most calls to the GitHub API come from this module (via the lambda functions in githubAPI.js).
Requires:
- module:yaml
- module:query-string
- module:js-base64
Requires
- module:yaml
- module:query-string
- module:js-base64
Members
-
static Getters :Object
-
Name Returns Type Returns State Property Description Filefunction filesReturns a function to retrieve a File specified by a URL. Returnsfunction a function to retrieve all Files matching the specified Array.filter function. Repositoryfunction repositoriesReturns a function to retrieve a Repository specified by a URL. If no URL is supplied, returns the current main repository. Returnsfunction a function to retrieve all Repositories matching the specified Array.filter function. isBusyfunction busyFlagsReturns a function to determine whether a busy flag has been set on the item with the specified URL. hasChangedfunction Returns a function to determine whether the file with the specified URL has changed from its GitHub representation. lastErrorError errorsReturn the most recent error encountered. listConfigErrorsObject Return the configuration errors detected in a the main repository config file. isConfigValidfunction Return a function to determine whether a specified configuration file is valid. -
static Mutations :Object
-
Name Accepts Type Mutates State Property Description setItemObject files|repositoriesChange an item in the repositories or files state arrays. removeItemObject files|repositoriesRemove an item from the repositories or files state arrays. setBusyFlagObject busyFlagsSet or unset a busy flag by item URL. setMainRepositoryObject repositoriesSet the repository with the specified URL as the main repository. addErrorObject errorsAdd an error to the list of encountered errors. -
static State :Object
-
The Workshop state object.
Properties:
Name Type Description repositoriesArray.<Repository> The Repositories loaded from GitHub. filesArray.<File> Files loaded from GitHub. templatesArray.<Template> Template repositories loaded from GitHub. errorsArray.<Error> Errors encountered. busyFlagsArray.<string> URLs marked as currently busy.
Methods
-
action addFile(nsContext, file) → {void}
-
Add a file to the store.
Vuex Action => Mutates state propertyfilesParameters:
Name Type Description nsContextStoreContext fileFile File to add. If overwriting an existing file, File.overwrite must be set to true. Returns:
void -
action addRepository(nsContext, repository) → {void}
-
Add a repository to the store.
Vuex Action => Mutates state propertyrepositoriesParameters:
Name Type Description nsContextStoreContext repositoryRepository The repository to add to the store. Returns:
void -
action createRepository(nsContext, payload) → {Promise.<(Repository|null)>}
-
Create a repository (as the main repository).
Vuex Action => Mutates state propertyrepositoriesParameters:
Name Type Description nsContextStoreContext payloadObject Repository template to create under given name. Returns:
Promise.<(Repository|null)> - Newly create Repository. -
action deleteFile(nsContext, payload) → {Promise.<{deleted: Array.<{fileName: string, deleted: boolean, skipped: boolean}>, failed: Array.<{fileName: string, deleted: boolean, skipped: boolean}>, skipped: Array.<{fileName: string, deleted: boolean, skipped: boolean}>}>}
-
Delete a file from the main repository.
Vuex Action => Mutates state propertyfilesParameters:
Name Type Description nsContextStoreContext payloadObject Properties
Name Type Attributes Default Description urlstring URL of the file to delete. deleteDependenciesboolean <optional>
true Whether or not to delete the file's dependencies. Deleting dependencies will preserve any dependencies that are also dependencies of other files. Returns:
Promise.<{deleted: Array.<{fileName: string, deleted: boolean, skipped: boolean}>, failed: Array.<{fileName: string, deleted: boolean, skipped: boolean}>, skipped: Array.<{fileName: string, deleted: boolean, skipped: boolean}>}> - The results of the delete operation: which files were successfully deleted, which were skipped, and which failed. -
action duplicateFile(nsContext, File) → {Promise.<File>}
-
Duplicate a file.
Vuex Action => Mutates state propertyfilesParameters:
Name Type Description nsContextStoreContext FileFile to copy. Returns:
Promise.<File> - The newly created copy. -
static fileInRepository(fileURL, repositoryURL) → {boolean}
-
All repository files' URLs begin with the URL of their repository, meaning repository URL is always a substring of file URL. This property is used to check membership.
Parameters:
Name Type Description fileURLstring The URL of the file. repositoryURLstring The URL of the repository. Returns:
boolean - Whether the file is in the repository. -
static findFileDependencies(File) → {Array.<String>}
-
Scrape a markdown file to identify image files that are embedded in it. Handles both direct inclusion and the Workshop Builder's own
{% include installedFile.lqd path="..." }approach.Parameters:
Name Type Description FileFile Markdown file to scrape. Returns:
Array.<String> - List of paths to required files. -
action findRepositories(nsContext, payload) → {Promise.<(Array.<Repository>|null)>}
-
Load repositories matching search terms from GitHub. Returns a list of the new repositories. This will never overwrite the main repository.
Vuex Action => Mutates state propertyrepositoriesParameters:
Name Type Description nsContextStoreContext payloadObject Search parameters to use in the GitHub search. Returns:
Promise.<(Array.<Repository>|null)> -
action findRepositoryFiles(nsContext, payload) → {Promise.<(Repository|null)>}
-
Find files for a repository and return the repository with new files pulled.
Vuex Action => Mutates state propertyfilesParameters:
Name Type Description nsContextStoreContext payloadObject Properties
Name Type Attributes Default Description urlstring URL of the Repository whose files should be retrieved from GitHub.. includeEpisodesboolean <optional>
true Whether to search episode files. includeExtraFilesboolean <optional>
true Whether to search config files. overwriteboolean <optional>
true Whether to overwrite existing files. Returns:
Promise.<(Repository|null)> - The repository with its newly-fetched files. -
action findTemplates(nsContext)
-
Fetch a list of available templates from GitHub.
Vuex Action => Mutates state propertytemplatesParameters:
Name Type Description nsContextStoreContext -
static getRepoIntroFile(files, topic) → {null|File}
-
Each repository has template introduction files for each of the possible topics. The introduction actually used by the repository is determined by the repository's topic. This function filters the repository's files to retrieve the introduction actually used by the repository.
Parameters:
Name Type Description filesArray.<File> Repository's files. topicstring The topic of the repository. -
action installDependencies(nsContext, payload) → {Promise.<File>}
-
Install the dependencies for a file.
Vuex Action => Mutates state propertyfilesParameters:
Name Type Description nsContextStoreContext payloadObject URL of the file whose dependencies should be installed Returns:
Promise.<File> - File with updated dependency information. -
action installFile(nsContext, payload) → {Promise.<(File|null)>}
-
Install a copy of a remote file from GitHub.
Vuex Action => Mutates state propertyfilesParameters:
Name Type Description nsContextStoreContext payloadObject URL of the file to install on the original GitHub repository. Returns:
Promise.<(File|null)> - Local copy of the file as installed in the main repository on GitHub. -
action loadRepository(nsContext, payload) → {Promise.<(Repository|null)>}
-
Load a repository from GitHub.
Vuex Action => Mutates state propertyrepositoriesParameters:
Name Type Description nsContextStoreContext payloadObject URL of the repository to fetch from GitHub. Returns:
Promise.<(Repository|null)> - The local repository object corresponding to the retrieved repository. -
static parseYAML(content) → {Object}
-
Parse a YAML-headed file into YAML key-value and body.
Parameters:
Name Type Description contentstring File content to be parsed. Requires:
- module:yaml
Returns:
Object -
action pullURL(nsContext, payload) → {Promise.<(object|null)>}
-
Pull a URL from GitHub and return the result directly.
Vuex Action => Mutates state propertyundefinedParameters:
Name Type Description nsContextStoreContext payloadurl:string Object with a target URL to pull from GitHub. Returns:
Promise.<(object|null)> -
action pushFile(nsContext, file) → {Promise.<(File|null)>}
-
Push a file to its remote repository and replace the current file with the remote version on success (keeps files sync'd with remote). Returns the newly sync'd file.
Vuex Action => Mutates state propertyfilesParameters:
Name Type Description nsContextStoreContext fileFile File to push to GitHub. Returns:
Promise.<(File|null)> - The file, or null on error. -
action rewriteEpisodeOrders(nsContext, payload) → {Promise.<void>}
-
Reassign episode order numbers to keep the same order but add distance for inserting other episodes between them.
Vuex Action => Mutates state propertyfilesParameters:
Name Type Description nsContextStoreContext payloadObject Properties
Name Type Description dayIdnumber Day whose episodes should have their order numbers adjusted. ignore_episodesArray.<string> URLs of episodes to ignore. Returns:
Promise.<void> -
action saveRepositoryChanges(nsContext) → {Promise.<{failures: number, successes: number}>}
-
Save all changed files in the main Repository.
Vuex Action => Mutates state propertyundefinedParameters:
Name Type Description nsContextStoreContext Returns:
Promise.<{failures: number, successes: number}> - The numbers of requests that succeeded and failed. -
action setFileContent(nsContext, file) → {Promise.<File>}
-
Set a file's content.
Vuex Action => Mutates state propertyfilesParameters:
Name Type Description nsContextStoreContext fileFile Updated file with content to set. Returns:
Promise.<File> - The updated file. -
action setFileContentFromYAML(nsContext, file) → {Promise.<File>}
-
Set a file's content by specifying YAML + body.
Vuex Action => Mutates state propertyfilesParameters:
Name Type Description nsContextStoreContext fileFile Updated file with yaml and body set. Returns:
Promise.<File> - The updated file. -
action setTopics(nsContext, payload) → {Promise.<(null|Array.<Repository>)>}
-
Set the Open Research topics of a repository.
Vuex Action => Mutates state propertyrepositoriesParameters:
Name Type Description nsContextStoreContext payloadObject A list of Open Science topics. Should be a subset of the topics in the root store topic list. Returns:
Promise.<(null|Array.<Repository>)> - Repositories matching the newly-specified topics. -
action uploadImage(nsContext, payload) → {Promise.<(string|boolean)>}
-
Upload an image file to GitHub.
Vuex Action => Mutates state propertyundefinedParameters:
Name Type Description nsContextStoreContext payloadObject Returns:
Promise.<(string|boolean)> - sha of overwritten file or true on success, or false on failure