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 🙏

© 2024 – Pkg Stats / Ryan Hefner

bitbucket-server-utils-cli

v1.18.0

Published

[![NPM](https://img.shields.io/npm/v/bitbucket-server-utils-cli.svg?style=flat-square)](https://www.npmjs.com/package/bitbucket-server-utils-cli)

Downloads

34

Readme

Bitbucket Server Utils CLI

NPM

Bitbucket Server utilities packaged as a standalone command line tool. Can be used in CI pipelines and similar things.

Using Bitbucket Server REST API

Usage

You will need to create a token: https://bitbucket-server/plugins/servlet/access-tokens/manage

The CLI can be run from this repo with:

npm run start -- \
  -at asd...asd \
  -u http://localhost:8080/rest/api/latest \
  -p PROJ_1

Or standalone with:

npx bitbucket-server-utils-cli \
  -at asd...asd \
  -u http://localhost:8080/rest/api/latest \
  -p PROJ_1

Gather state

Gather state and store it in a file. This allows other features to quickly have access to the state. You may, for example, want to have this state file versioned in a Git repository to have access to it in CI pipelines.

npx bitbucket-server-utils-cli \
  --gather-state \
  --url http://localhost:8080/rest/api/latest \
  --access-token asd...asd \
  --projects PROJ_1 \
  --state-file /tmp/some-file.json

Format string

Format a string by rendering a Handlebars-template with the state as context.

template=$(cat <<-END
 {{#each pullRequests}}
   <p>
     <b>Last updated:</b> <i>{{lastUpdated}}</i>
   </p>
 {{/each}}
END
)
renderedString=$(npx bitbucket-server-utils-cli \
  --format-string \
  --state-file /tmp/some-file.json \
  --template "$template")
echo "The rendered string is: $renderedString"

Or get the template from a file with --template "$(</tmp/template.hbs)".

Now the $renderedString can perhaps be used as a comment, or maby it is rendered HTML that you want to write to a file.

Comment pull-request

Comment a pull-request:

npx bitbucket-server-utils-cli \
  --post-pull-request-comment "this is the comment" \
  --url http://localhost:8080/rest/api/latest \
  --access-token asd...asd \
  --projects PROJ_1 \
  --repository-slug repo_1 \
  --pull-request 461 \
  --severity BLOCKER \
  --comment-key somethingunique

Delete comment in pull-request by id

Delete comment in pull-request:

npx bitbucket-server-utils-cli \
  --delete-pull-request-comment \
  --url http://localhost:8080/rest/api/latest \
  --access-token asd...asd \
  --projects PROJ_1 \
  --repository-slug repo_1 \
  --pull-request 461 \
  --pull-request-comment-id 999

Delete comment in pull-request by comment key

Delete any comments in pull-request if they contain the comment key:

npx bitbucket-server-utils-cli \
  --delete-pull-request-comment \
  --url http://localhost:8080/rest/api/latest \
  --access-token asd...asd \
  --projects PROJ_1 \
  --repository-slug repo_1 \
  --pull-request 461 \
  --comment-key somethingunique

Comment any pull-request where the author has pull-requests to review

A comment with specific message to authors who has other pull-requests to review. The context contains the author and the pull-requests.

template=$(cat <<-END
You, **{{authorPullRequest.author}}**, have pull-requests that are waiting for your feedback:
{{#each pullRequests}}
  - [{{title}}](http://bitbucket-server/projects/{{repository.projectSlug}}/repos/{{repository.repoSlug}}/pull-requests/{{id}}/)
{{/each}}
END
)
npx bitbucket-server-utils-cli \
  --post-pull-request-comment-if-open-pull-requests \
  --pull-request-title-filter ^\(?\!WIP:\).*
  --url http://localhost:8080/rest/api/latest \
  --access-token asd...asd \
  --state-file /tmp/some-file.json \
  --severity BLOCKER \
  --ignore-authors-slug optional,list,of,slugs,to,ignore \
  --template "$template"

Command line arguments

Options:
  -at, --access-token <token>                                   Bitbucket Server access token
  -u, --username <username>                                     Bitbucket Server username
  -p, --password <password>                                     Bitbucket Server password
  -u, --url <url>                                               Bitbucket Server to use for REST integration
                                                                (https://bitbucket-server/rest/api/latest)
  -p, --projects <projects>                                     Bitbucket Server projects. Example: PROJ_1,PROJ_2,PROJ_3
  -rs, --repository-slug <rs>
  -prid, --pull-request <prid>
  -prtf, --pull-request-title-filter <id>                       Only include pull requests with title matching this regexp. (default: ".*")
  -prcid, --pull-request-comment-id <id>
  -prcv, --pull-request-comment-version <version>
  -sf, --state-file <filename>                                  File to read, and write, state to.
  -t, --template <string>                                       String containing Handlebars template.
  -sev, --severity <rs>                                         BLOCKER or NORMAL (default: "NORMAL")
  -ck, --comment-key <rs>                                       Some string that identifies the comment. Will ensure same comment is not
                                                                re-posted if unchanged and replaced if changed.
  --log-level <level>                                           Log level DEBUG, INFO or ERROR (default: "INFO")
  -s, --sleep-time <milliseconds>                               Milliseconds to sleep between HTTP requests. (default: "300")
  -dr, --dry-run                                                Dry run, no POST/PUT/DELETE requests. (default: false)
  -ias, --ignore-authors-slug <authors>                         Ignore authors by slug. Example: abc,def,fgh (default: [])
  -gs, --gather-state                                           Gather state from Bitbucket Server and store it in a file.
  -fc, --format-string                                          Format a string by rendering a Handlebars-template with the state as
                                                                context.
  -pprc, --post-pull-request-comment <comment>                  Post a pull-request comment
  -pprciopr, --post-pull-request-comment-if-open-pull-requests  Post pull-request comment if author has open pull-requests to review
  -dprc, --delete-pull-request-comment                          Delete pull-request comment with given ID
  -h, --help                                                    display help for command