Skip to content

magnlun/pull-request-notifier-for-stash

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pull Request Notifier for Stash Build Status

The original use case was to trigger Jenkins jobs to build pull requests that are created in Stash. The plugin can be configured to trigger different Jenkins jobs for different repositories. It can supply custom parameters to the jenkins job using the variables. It can authenticate with HTTP Basic.

It can, for example, trigger a build in Jenkins. Parameterized Jenkins jobs can be triggered remotely via:

http://server/job/theJob/buildWithParameters?token=TOKEN&PARAMETER=Value

The plugin can trigger any system, not only Jenkins. The plugin can notify any system that can be notified with a URL.

Here is a screenshot of the admin GUI.

Here is a blog post that includes the plugin.

Available in Atlassian Marketplace.

Features

The Pull Request Notifier for Stash can:

  • Invoke any URL, or set of URL:s, when a pull request event happens.
  • With variables available to add necessary parameters.
  • HTTP POST, PUT, GET and DELETE. POST and PUT also supports rendered post content.
  • Be configured to trigger on any pull request event. Including extended events:
  • RESCOPED_FROM, when source branch change
  • RESCOPED_TO, when target branch change
  • BUTTON_TRIGGER, when trigger button in pull request view is pressed
  • Be configured to only trigger if the pull request mathches a filter. A filter text is constructed with any combination of the variables and then a regexp is constructed to match that text.
  • Add buttons to pull request view in Stash. And map those buttons to URL invocations. This can be done by setting the filter string to ${BUTTON_TRIGGER_TITLE} and the filter regexp to title of button.
  • Authenticate with HTTP basic authentication.
  • Send custom HTTP headers
  • Can optionally use proxy to connect
  • Can let users and/or admins do configuration. Or restrict configuration to just system admins. A user will have to browse to the configuration page at http://domain/stash/plugins/servlet/prnfs/admin.

The plugin has its own implementation to create the RESCOPED_FROM and RESCOPED_TO events. RESCOPED is transformed to RESCOPED_TO if target branch changed, RESCOPED_FROM if source branch, or both, changed.

The filter text as well as the URL support variables. These are:

  • ${PULL_REQUEST_ID} Example: 1
  • ${PULL_REQUEST_VERSION} Example: 1
  • ${PULL_REQUEST_COMMENT_TEXT} Example: A comment
  • ${PULL_REQUEST_ACTION} Example: OPENED
  • ${BUTTON_TRIGGER_TITLE} Example: Trigger Notification
  • ${PULL_REQUEST_URL} Example: http://localhost:7990/projects/PROJECT_1/repos/rep_1/pull-requests/1
  • ${PULL_REQUEST_USER_DISPLAY_NAME} Example: Some User
  • ${PULL_REQUEST_USER_EMAIL_ADDRESS} Example: some.user@stash.domain
  • ${PULL_REQUEST_USER_ID} Example: 1
  • ${PULL_REQUEST_USER_NAME} Example: user.name
  • ${PULL_REQUEST_USER_SLUG} Example: user.name
  • ${PULL_REQUEST_AUTHOR_DISPLAY_NAME} Example: Administrator
  • ${PULL_REQUEST_AUTHOR_EMAIL} Example: admin@example.com
  • ${PULL_REQUEST_AUTHOR_ID} Example: 1
  • ${PULL_REQUEST_AUTHOR_NAME} Example: admin
  • ${PULL_REQUEST_AUTHOR_SLUG} Example: admin
  • ${PULL_REQUEST_FROM_SSH_CLONE_URL} Example: ssh://git@localhost:7999/project_1/rep_1
  • ${PULL_REQUEST_FROM_HTTP_CLONE_URL} Example: http://admin@localhost:7990/stash/scm/project_1/rep_1.git
  • ${PULL_REQUEST_FROM_HASH} Example: 6053a1eaa1c009dd11092d09a72f3c41af1b59ad
  • ${PULL_REQUEST_FROM_ID} Example: refs/heads/branchmodmerge
  • ${PULL_REQUEST_FROM_BRANCH} Example: branchmodmerge
  • ${PULL_REQUEST_FROM_REPO_ID} Example: 1
  • ${PULL_REQUEST_FROM_REPO_NAME} Example: rep_1
  • ${PULL_REQUEST_FROM_REPO_PROJECT_ID} Example: 1
  • ${PULL_REQUEST_FROM_REPO_PROJECT_KEY} Example: PROJECT_1
  • ${PULL_REQUEST_FROM_REPO_SLUG} Example: rep_1
  • And same variables for TO, like: ${PULL_REQUEST_TO_HASH}

The ${PULL_REQUEST_USER...} contains information about the user who issued the event. Who commented it, who rejected it, who approved it...

You may want to use Violation Comments to Stash plugin and/or StashNotifier plugin to report results back to Stash.

Developer instructions

Prerequisites:

Generate Eclipse project:

atlas-compile eclipse:eclipse

Package the plugin:

atlas-package

Run Stash, with the plugin, on localhost:

export MAVEN_OPTS=-Dplugin.resource.directories=`pwd`/src/main/resources
atlas-run

Make a release (detailed instructions):

mvn release:prepare
mvn release:perform

About

Stash plugin that invokes a custom URL when a pull request event is triggered.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 96.0%
  • JavaScript 3.6%
  • CSS 0.4%