Overview

stash.js

A javascript framework for customising Atlassian Stash.

Quickstart

  • Install the Atlassian SDK.
  • Run atlas-debug from the directory containing this README.
  • Go to Administration -> Javascript Add-ons

See this video or the examples/ directory in this project to see what is possible.

Bindings

stash.js modules work by allowing you to bind javascript functions to Stash SPI interfaces and events. A set of Stash services are exposed to the javascript context, including:

  • ApplicationPropertiesService
  • ContentService
  • HistoryService
  • I18nService
  • MailService
  • ProjectService
  • RepositoryMetadataService
  • RepositoryService
  • UserService
  • StashAuthenticationContext

See the javadoc for details.

Example: the ancient mystic no-homer script

Script

/* A function that is bound to the RepositoryMergeRequestCheck interface */

exports.check = function(context) {
    // prevent people named "Homer" from performing a merge
    var currentUser = StashAuthenticationContext.getCurrentUser();
    if (currentUser && currentUser.getDisplayName().indexOf("Homer") > -1) {    
        context.getMergeRequest().veto("No Homers", "No Homers");
    }
};

/* A function that is bound to the RepositoryCreationRequestedEvent event */

exports.onRepoCreateRequested = function(event) {        
    var currentUser = StashAuthenticationContext.getCurrentUser();
    if (currentUser && currentUser.getDisplayName().indexOf("Homer") > -1) {    
        event.cancel(I18nService.getKeyedText("no.homers", "No Homers!"));
    }
};

Bindings

{        
    "merge-check": {
        "name": "No Homer",
        "description": "The Ancient Mystic Society of No Homers.",
        "icon": "http://tpettersen.bitbucket.org/assets/no-homer.png"
    },
    "events": {
        "RepositoryCreationRequestedEvent": "onRepoCreateRequested"            
    }
}

Gotchas

If you see an error similar to:

TypeError: [JavaPackage com.atlassian.stash.util.PageRequestImpl] is not a function, it is object.

You may be attempting to use a class that doesn't have OSGi imports declared for it.

Generated Plugin Structure

META-INF/MANIFEST.MF
atlassian-plugin.xml