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 File
function files
Returns a function to retrieve a File specified by a URL. Returns
function a function to retrieve all Files matching the specified Array.filter function. Repository
function repositories
Returns a function to retrieve a Repository specified by a URL. If no URL is supplied, returns the current main repository. Returns
function a function to retrieve all Repositories matching the specified Array.filter function. isBusy
function busyFlags
Returns a function to determine whether a busy flag has been set on the item with the specified URL. hasChanged
function Returns a function to determine whether the file with the specified URL has changed from its GitHub representation. lastError
Error errors
Return the most recent error encountered. listConfigErrors
Object Return the configuration errors detected in a the main repository config file. isConfigValid
function Return a function to determine whether a specified configuration file is valid. -
static Mutations :Object
-
Name Accepts Type Mutates State Property Description setItem
Object files|repositories
Change an item in the repositories or files state arrays. removeItem
Object files|repositories
Remove an item from the repositories or files state arrays. setBusyFlag
Object busyFlags
Set or unset a busy flag by item URL. setMainRepository
Object repositories
Set the repository with the specified URL as the main repository. addError
Object errors
Add an error to the list of encountered errors. -
static State :Object
-
The Workshop state object.
Properties:
Name Type Description repositories
Array.<Repository> The Repositories loaded from GitHub. files
Array.<File> Files loaded from GitHub. templates
Array.<Template> Template repositories loaded from GitHub. errors
Array.<Error> Errors encountered. busyFlags
Array.<string> URLs marked as currently busy.
Methods
-
action addFile(nsContext, file) → {void}
-
Add a file to the store.
Vuex Action => Mutates state propertyfiles
Parameters:
Name Type Description nsContext
StoreContext file
File 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 propertyrepositories
Parameters:
Name Type Description nsContext
StoreContext repository
Repository 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 propertyrepositories
Parameters:
Name Type Description nsContext
StoreContext payload
Object 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 propertyfiles
Parameters:
Name Type Description nsContext
StoreContext payload
Object Properties
Name Type Attributes Default Description url
string URL of the file to delete. deleteDependencies
boolean <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 propertyfiles
Parameters:
Name Type Description nsContext
StoreContext File
File 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 fileURL
string The URL of the file. repositoryURL
string 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 File
File 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 propertyrepositories
Parameters:
Name Type Description nsContext
StoreContext payload
Object 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 propertyfiles
Parameters:
Name Type Description nsContext
StoreContext payload
Object Properties
Name Type Attributes Default Description url
string URL of the Repository whose files should be retrieved from GitHub.. includeEpisodes
boolean <optional>
true Whether to search episode files. includeExtraFiles
boolean <optional>
true Whether to search config files. overwrite
boolean <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 propertytemplates
Parameters:
Name Type Description nsContext
StoreContext -
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 files
Array.<File> Repository's files. topic
string The topic of the repository. -
action installDependencies(nsContext, payload) → {Promise.<File>}
-
Install the dependencies for a file.
Vuex Action => Mutates state propertyfiles
Parameters:
Name Type Description nsContext
StoreContext payload
Object 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 propertyfiles
Parameters:
Name Type Description nsContext
StoreContext payload
Object 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 propertyrepositories
Parameters:
Name Type Description nsContext
StoreContext payload
Object 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 content
string 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 propertyundefined
Parameters:
Name Type Description nsContext
StoreContext payload
url: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 propertyfiles
Parameters:
Name Type Description nsContext
StoreContext file
File 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 propertyfiles
Parameters:
Name Type Description nsContext
StoreContext payload
Object Properties
Name Type Description dayId
number Day whose episodes should have their order numbers adjusted. ignore_episodes
Array.<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 propertyundefined
Parameters:
Name Type Description nsContext
StoreContext 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 propertyfiles
Parameters:
Name Type Description nsContext
StoreContext file
File 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 propertyfiles
Parameters:
Name Type Description nsContext
StoreContext file
File 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 propertyrepositories
Parameters:
Name Type Description nsContext
StoreContext payload
Object 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 propertyundefined
Parameters:
Name Type Description nsContext
StoreContext payload
Object Returns:
Promise.<(string|boolean)> - sha of overwritten file or true on success, or false on failure