npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@jupiterone/bitbucket-pr-detector

v1.0.5

Published

Perform configurable actions when new pull requests of interest are opened

Downloads

69

Readme

Bitbucket PullRequest Detector

Pull Requests increasingly dominate our technical workflows, yet ensuring that the right people review them, or that we have a centralized place to configure automation side-effects in response to new Pull Requests, can be challenging.

This module, intended to be run periodically, checks to see if new pull requests have been opened in one or more target bitbucket repositories.

If those PRs contain changes matching a certain pattern, this script will perform actions, e.g. sending a slack message to a configured channel.

Configuration and Usage

Import and execute the module via:

import { processPullRequestsAsync, PRDetectorConfig } from '@jupiterone/bitbucket-pr-detector';

const config: PRDetectorConfig = {
  ...
};

await processPullRequestsAsync(config);

Where config satisfies the interface:

export interface PRDetectorConfig {
    bitbucketOrg: string       // required, organization name
    bitbucketRepo: string      // required, repository name
    bitbucketUsername: string  // required, bitbucket user name
    bitbucketPassword: string  // required, bitbucket password
    bitbucketPRQuery?: string  // if given, will override bitbucket API filter
    slackWebhookUrl?: string   // if given, will alert to Slack
    slackAuthor?: string       // alert author
    slackAlertTitle?: string   // alert title
    detectPath?: string        // required if using default detectionFilter(), which
                               // returns true if any PR modified paths match string
    detectionFilter?: (config: PRDetectorConfig, diffStats: any[]) => boolean
    checkPRSeenAsync?: (config: PRDetectorConfig, input: PRSeenInput) => Promise<boolean>
    savePRSeenAsync?: (config: PRDetectorConfig, input: PRSaveInput) => Promise<void>
    processPRAsync?: (config: PRDetectorConfig, pr: any) => Promise<void>
    logger?: any
}

Detection filtering

Unless detectionFilter() is overridden, the module will search for Pull Requests which contain changed files whose path includes a substring specified by the detectPath config attribute. For instance, if you have a wiki repository, and it contains RFCs organized under a docs/RFCs folder, then specifying detectPath: 'docs/RFCs' will detect new Pull Requests that contain RFC documentation.

The detectionFilter function receives the config object, the Pull Request Object, and an array of Bitbucket API DiffStat objects for that PR.

See:

The function should return true if that PR is considered novel or worth alerting on.

Alerting to Slack

If you'd like the module to alert to a Slack channel whenever a novel Pull Request is detected, configure the slackWebhookUrl with the custom integration webhook URL for a channel of your choice. You'll also want to configure slackAuthor and slackAlertTitle appropriately.

For instance, continuing the example above, we might specify:

{
  slackWebhookUrl: process.env.SLACK_WEBHOOK_RFCS_CHANNEL,
  slackAuthor: 'new-rfc-notifier',
  slackAlertTitle: 'New RFC Pull Request found in wiki repository'
}

If you'd rather not alert to Slack, omit the slackWebhookUrl attribute.

Persistence / Alert Deduping

Since this is intended to run periodically, a persistence store should be made available to cache previously seen Pull Requests, to prevent duplicate alerts/actions for the same triggering Pull Request. A key-value store like Redis or DynamoDB is ideal, but any persistence mechanism which satisfies the checkPRSeenAsync()/savePRSeenAsync() function interfaces will work. The module will complain if you have not overridden the default persistence functions.

Additional Processing

If you'd like to take other actions on new Pull Requests which satisfy the detectionFilter(), override the processPRAsync() attribute with a custom function.